Changeset 11289


Ignore:
Timestamp:
07/08/11 06:35:18 (14 years ago)
Author:
ogrimm
Message:
Fixed bug when changing active boards just before a run is started
Location:
fact/FADctrl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • fact/FADctrl/FAD.cc

    r11259 r11289  
    2828   {"sclk", &FAD::cmd_sclk, true, 1, "<on|off>", "Set SCLK"},
    2929   {"trigger", &FAD::cmd_trigger, false, 0, "[n|cont [rate]|stop|enable|disable]", "Issue software triggers"},
    30    {"drsreset", &FAD::cmd_drsreset, true, 1, "<low|high>", "set DRS reset line"},
     30   {"drsreset", &FAD::cmd_drsreset, true, 1, "<low|high>", "Set DRS reset line"},
    3131   {"reset", &FAD::cmd_reset, true, 0, "", "Reset internal trigger counter"},
    3232   {"runnumber", &FAD::cmd_runnumber, true, 1, "<n>", "Set runnumber"},
     
    6262  Mode = idle;
    6363  Datafile = -1;
    64   EventUpdateDelay = atof(GetConfig("EventUpdateDelay", "0.5").c_str());
    65   TimeForDIMUpdate = 0;
     64  EventUpdateDelay = atof(GetConfig("EventUpdateDelay", "2").c_str());
    6665
    6766  // Create pipe for data exchange
     
    106105
    107106  int Ret;
     107
     108  ExitRequest = true;
     109
     110  // Stop run if in progress
     111  if (Mode != idle) cmd_stop();
    108112
    109113  // Close pipe (will make read() on pipe in DIM service thread return)
     
    214218
    215219  for (unsigned int i=0; i<Boards.size(); i++) {
    216         if (Match(Parameter[1],"low")) Boards[i]->Send(CMD_DRS_RST_LOW);
    217         else if (Match(Parameter[1],"high")) Boards[i]->Send(CMD_DRS_RST_HIGH);
     220        if (Match(Parameter[1], "low")) Boards[i]->Send(CMD_DRS_RST_LOW);
     221        else if (Match(Parameter[1], "high")) Boards[i]->Send(CMD_DRS_RST_HIGH);
    218222        else {
    219223          PrintUsage();
     
    223227}
    224228
    225 
    226229//
    227230// Execute: Confirm new ROI, DAC or what ever settings
    228231//
    229 
    230232void FAD::cmd_execute() {
    231233
    232234  for (unsigned int i=0; i<Boards.size(); i++) Boards[i]->Send(CMD_Execute);
    233235}
    234 
    235236
    236237//
     
    259260//
    260261// Switch socket mode
    261 // "com" - command mode (only socket 0 is used)
     262// "com" - command mode (only socket 0 is used for event data transmission)
    262263// "daq" - daq mode (only sockets 1 - 7 are used)
    263 //
    264 //      Note that socket 0 is always used to issue commands
    265 //
    266264void FAD::cmd_socketmode() {
    267265
     
    652650        else if (Mode == acalib) PrintMessage("Current mode is ACALIB (3x%d events, slowest board %d has %d events)\n", NumEventsRequested, SlowestBoard, MinCount);
    653651        else if (Mode == datarun) PrintMessage("Current mode is DATARUN (%d events requested, %d events taken)\n", NumEventsRequested, NumEvents);
    654         PrintMessage("Execution time of last DIM event update %d seconds\n", TimeForDIMUpdate);
    655652        return;
    656653  }   
     
    808805void FAD::cmd_exit() {
    809806
    810   if (Mode != idle) cmd_stop();
    811 
    812807  ExitRequest = true;
    813 
    814   // Wait to allow console input to arrive at readline()
    815   usleep(10000);
    816808  pthread_kill(MainThread, SIGTERM);
    817809}
     
    889881  DimService FileSizeService(SERVER_NAME"/FileSizeMB", FileSizeMB);
    890882
    891   // Calculate pointers to EventData array (will be updated when active number of boards changes)
     883  // Set/allocate pointers
    892884  RunHeader *RHeader = (RunHeader *) EventData;
    893885  BoardStructure **BStruct = new BoardStructure * [Boards.size()];
    894 
    895   for (unsigned int i=0; i<Boards.size(); i++) BStruct[i] = ((BoardStructure *) (RHeader + 1)) + i;
    896   EventHeader *EHeader = (EventHeader *) ((char *) (RHeader + 1) + Boards.size()*sizeof(BoardStructure));
    897   int *TriggerCell = (int *) (EHeader + 1);
    898   short *Data = (short *) (TriggerCell + NChips*Boards.size());
     886  EventHeader *EHeader;
     887  int *TriggerCell;
     888  short *Data;
    899889
    900890  // Fill fixed entries in M0 RunHeader
     
    933923        IDString.append(string(Buffer, Ret));
    934924
    935         // Active boards for DIM and data taking must only change when idle
    936         if (Mode == idle) {
     925        // Active boards must not change during data taking
     926        if (Mode != datarun || NumEvents == 0) {
    937927          ActiveBoards.clear();
    938           for (unsigned int i=0; i<Boards.size(); i++) if (Boards[i]->Active) ActiveBoards.push_back(Boards[i]);
     928          for (unsigned int i=0; i<Boards.size(); i++) {
     929                if (Boards[i]->Active) ActiveBoards.push_back(Boards[i]);
     930          }
    939931          RHeader->NBoards = ActiveBoards.size();
     932        }
    940933         
    941           // Calculate updated pointers to EventData array
    942           for (unsigned int i=0; i<ActiveBoards.size(); i++) BStruct[i] = ((BoardStructure *) (RHeader + 1)) + i;
    943           EHeader = (EventHeader *) ((char *) (RHeader + 1) + ActiveBoards.size()*sizeof(BoardStructure));
    944           TriggerCell = (int *) (EHeader + 1);
    945           Data = (short *) (TriggerCell + NChips*ActiveBoards.size());
    946         }
     934        // Calculate pointers to EventData array
     935        for (unsigned int i=0; i<ActiveBoards.size(); i++) BStruct[i] = ((BoardStructure *) (RHeader + 1)) + i;
     936        EHeader = (EventHeader *) ((char *) (RHeader + 1) + ActiveBoards.size()*sizeof(BoardStructure));
     937        TriggerCell = (int *) (EHeader + 1);
     938        Data = (short *) (TriggerCell + NChips*ActiveBoards.size());
    947939
    948940        // If amplitude calibration mode, check if all boards finished procedure
     
    993985          for(unsigned int i=0; i<NChips; i++) TriggerCell[Brd*NChips+i] = (int) S.TriggerCell[i];
    994986
    995           // Write channel data (12 bit signed two's complement with out-of-range-bit and leading zeroes)
     987          // Write channel data
    996988          int Count = Brd*NChips*NChannels*NBins;
    997989          memset(Data+Count, 0, NChips*NChannels*NBins*sizeof(short));
     
    10241016        }
    10251017
    1026         // Check if DIM service should be updated (delay between updates at least 10xtime to update)
    1027         if ((Time.tv_sec-LastUpdate.tv_sec)*1e6 + Time.tv_usec-LastUpdate.tv_usec > max(10*TimeForDIMUpdate, EventUpdateDelay)*1e6) {
     1018        // Check if DIM service should be updated
     1019        if ((Time.tv_sec-LastUpdate.tv_sec)*1e6 + Time.tv_usec-LastUpdate.tv_usec >  EventUpdateDelay*1e6) {
    10281020          gettimeofday(&LastUpdate, NULL);
    10291021
     
    10311023          EventNumService.updateService();
    10321024
    1033           TimeForDIMUpdate = time(NULL) - LastUpdate.tv_sec;
    10341025          if (Mode == datarun) FileSizeService.updateService();
    10351026        }
     
    11101101          // Close data file and terminate run
    11111102          if(close(Datafile) == -1) Message(ERROR, "Could not close data file (%s)", strerror(errno));
    1112           else PrintMessage("Data file closed (size %.1f MByte, %d events).\n", FileSizeMB, NumEvents);
     1103          else PrintMessage("Data file closed (size %.1f MByte, rate %.1f MByte/s, %d events).\n", FileSizeMB, FileSizeMB/(FileRHeader.EndSecond-FileRHeader.StartSecond+(FileRHeader.EndMicrosecond-FileRHeader.StartMicrosecond)/1000000.0), NumEvents);
    11131104
    11141105          Datafile = -1;
  • fact/FADctrl/FAD.h

    r11232 r11289  
    4747        static void LaunchEventThread(class FAD *);
    4848        pthread_t Thread;
    49         float TimeForDIMUpdate;
    5049
    5150    int Datafile;
  • fact/FADctrl/FADctrl.cc

    r11205 r11289  
    4949    if (Command == NULL) continue;
    5050
     51        // Process exit request for reasons of responsiveness here
     52        if (strcmp(Command, "exit") == 0) break;
     53       
    5154        // Add command to history
    5255    if(strlen(Command) > 0 && LastHist != Command) {
  • fact/FADctrl/History.txt

    r11178 r11289  
    343421/6/2011       Command 'boards' takes 'none as argument
    353524/6/2011       PLL lock status published as DIM service
     367/7/2011        Fixed error in setting the active boards in EventThread()
Note: See TracChangeset for help on using the changeset viewer.