Changeset 269 for drsdaq/DAQReadout.cc


Ignore:
Timestamp:
07/29/10 07:32:58 (14 years ago)
Author:
ogrimm
Message:
First commit of separated Feedback program
File:
1 edited

Legend:

Unmodified
Added
Removed
  • drsdaq/DAQReadout.cc

    r254 r269  
    4747   {"update", &DAQReadout::cmd_update, false, "<sec>", "Minimum delay between updates to DIM event service"},             
    4848   {"exit", &DAQReadout::cmd_exit, false, "", "Exit program"},
    49    {"fmode", &DAQReadout::cmd_fmode, false, "[off|active|targ]", "Set or get feedback mode"},
    50    {"faverage", &DAQReadout::cmd_faverage, false, "[n]", "Set ot get number of averages for feedback"},
    51    {"fgain", &DAQReadout::cmd_fgain, false, "[gain]", "Set ot get feedback gain"},
    52    {"ftarget", &DAQReadout::cmd_ftarget, false, "[brd chip chan]", "Set or get target value (also 'all' supported)"},
    53    {"fresponse", &DAQReadout::cmd_fresponse, false, "[voltage]", "Start response measurement with given voltage difference"},
    54    {"fconfig", &DAQReadout::cmd_fconfig, false, "", "Print feedback configuration"},
    5549   {"help", &DAQReadout::cmd_help, false, "", "Print help"}};
    5650
     
    9690  fDefaultFrequency = atof(GetConfig("DefaultFrequency").c_str());
    9791
     92  fLedTrigBoard = atoi(GetConfig("TrigBoard").c_str());
     93  fLedTrigChannel = atoi(GetConfig("TrigChannel").c_str());
     94  fLedTrigChip = atoi(GetConfig("TrigChip").c_str());
     95  fLedTrigSample = atoi(GetConfig("TrigSample").c_str());
     96  fLedTrigThreshold = atoi(GetConfig("TrigThreshold").c_str());
     97  fLedSignalSample = atoi(GetConfig("SignalSample").c_str());
     98  fLedBaselineSample = atoi(GetConfig("BaselineSample").c_str());
     99  fIntHalfWidth = atoi(GetConfig("IntHalfWidth").c_str());
     100
    98101  if (fFirstSample < 0 || fFirstSample > kNumberOfBins || fSamples > kNumberOfBins) {
    99102    PrintMessage("Warning: Sample range in configuration beyond limits, setting to full range\n");
     
    140143  EventService = new DimService (SERVER_NAME"/EventData", (char *) "C", DIMEventData, 0);
    141144                                                   
    142   // Create instance of HV feedback (must be called after board detection)
    143   HVFB    = new HVFeedback(this); 
    144 
    145145  // Install DIM command (after all initialized)
    146146  Command = new DimCommand((char *) SERVER_NAME"/Command", (char *) "C", this);
     
    157157  delete EventService;  delete[] DIMEventData;
    158158  delete RHeader;               delete EHeader;
    159   delete HVFB;                  delete[] ACalibTemp;
     159  delete[] ACalibTemp;
    160160  delete[] ACalib;              delete[] TCalib;
    161161  delete[] DRSFreq;     delete[] BStruct;
     
    220220// Print DAQ configuration
    221221void DAQReadout::cmd_config() {
    222   PrintConfig();
     222
     223  PrintMessage("RawDataPath: %s\n"
     224                "DefaultFrequency: %.2f\tFirstSample: %d\tSamples: %u\n"
     225                "MinDiskSpaceMB: %u\tMaxFileSizeMB: %d\n"
     226                "CalibDataPath: %s\n\n"
     227                "LedTrigBoard: %d\t\tLedTrigChip: %d\t\tLedTrigChannel: %d\n"
     228        "LedTrigSample: %d\tLedTrigThreshold: %.2f\n"
     229        "LedSignalSample: %d\tLedBaselineSample: %d\tIntHalfWidth:%u\n",
     230    fRawDataPath,fDefaultFrequency,fFirstSample,fSamples,fMinDiskSpaceMB,
     231    fMaxFileSizeMB,fCalibDataPath,
     232    fLedTrigBoard, fLedTrigChip, fLedTrigChannel, fLedTrigSample,
     233    fLedTrigThreshold, fLedSignalSample, fLedBaselineSample, fIntHalfWidth);
    223234}
    224235
     
    755766}
    756767
    757 // Set/get mode of feedback
    758 void DAQReadout::cmd_fmode() {
    759 
    760   if(Match(Param[1],"off")) HVFB->SetFBMode(FB_Off);
    761   else if(Match(Param[1],"active")) HVFB->SetFBMode(FB_Active);
    762   else if(Match(Param[1],"targets")) HVFB->SetFBMode(FB_Targets);
    763   else HVFB->GetFBMode();
    764 }
    765 
    766 // Set/get current number of events
    767 void DAQReadout::cmd_faverage() {
    768 
    769   if(NParam==1) PrintMessage("Current number of feedback events: %u   (acting when %u events are reached)\n",
    770                        HVFB->GetCurrentCount(), HVFB->GetNumAverages());
    771   else if(atoi(Param[1])>=0) HVFB->SetNumAverages(atoi(Param[1]));
    772   else PrintUsage();
    773 }
    774 
    775 // Set/get feedback gain
    776 void DAQReadout::cmd_fgain() {
    777 
    778   if(NParam==2) HVFB->SetGain(atof(Param[1]));
    779   PrintMessage("Feedback gain is %.2f\n", HVFB->GetGain());
    780 }
    781 
    782 // Set/get target value
    783 void DAQReadout::cmd_ftarget() {
    784 
    785   if(NParam==1) HVFB->GetTargets();
    786   else if(NParam!=5) PrintUsage();
    787   else for (int i=FirstBoard; i<=LastBoard; i++)
    788          for (int j=0; j<GetBoard(i)->GetNumberOfChips(); j++)
    789            for (int k=0; k<GetBoard(i)->GetNumberOfChannels(); k++)
    790              if ((atoi(Param[1])==i || Match(Param[1],"all")) &&
    791                  (atoi(Param[2])==j || Match(Param[2],"all")) &&
    792                  (atoi(Param[3])==k || Match(Param[3],"all")))
    793               HVFB->SetTarget(i,j,k,atof(Param[4]));
    794 }
    795 
    796 // Start response measurement
    797 void DAQReadout::cmd_fresponse() {
    798 
    799   if(NParam==1) HVFB->GetResponse();
    800   else if(atof(Param[1])) HVFB->MeasureResponse(atof(Param[1]));
    801   else PrintUsage();
    802 }
    803 
    804 // Print feedback configuration
    805 void DAQReadout::cmd_fconfig() {
    806 
    807   HVFB->PrintConfig();
    808 }
    809768
    810769// ----------------------------------------------
     
    11561115}
    11571116
    1158 // Print configuration to target
    1159 void DAQReadout::PrintConfig() {
    1160   PrintMessage("RawDataPath: %s\n"
    1161                "DefaultFrequency: %.2f\tFirstSample: %d\tSamples: %u\n"
    1162                "MinDiskSpaceMB: %u\tMaxFileSizeMB: %d\n"
    1163                            "CalibDataPath: %s\n",
    1164     fRawDataPath,fDefaultFrequency,fFirstSample,fSamples,fMinDiskSpaceMB,
    1165     fMaxFileSizeMB,fCalibDataPath);
    1166 }
    1167 
    11681117// Print usage text for command
    11691118void DAQReadout::PrintUsage() {
     
    12491198  int DIMSize;
    12501199
     1200  // Initialize run
    12511201  NumEvents = 0;
    12521202  FileNumber = 0;
    1253   HVFB->ClearAverages();   
     1203  DimClient::sendCommandNB("Feedback/Command", "clear");
     1204   
    12541205  gettimeofday(&StartTime, NULL);
    12551206  PrintMessage("\rStarting run #%d (%s) with %u event(s)\n", RunNumber, daq_runtype_str[daq_runtype], NumEventsRequested);
     
    13031254      }
    13041255
    1305       // Call feedback to process event
    1306       HVFB->ProcessEvent();
     1256          // Check for LED trigger
     1257          if (WaveForm[fLedTrigBoard][fLedTrigChip][fLedTrigChannel][fLedTrigSample] > fLedTrigThreshold) {
     1258                std::stringstream Cmd;
     1259                float Integral;
     1260
     1261                // Calculate feedback signal
     1262                for (int i=FirstBoard; i<=LastBoard; i++) {
     1263                  for (unsigned int j=0; j<RHeader->NChips; j++) {
     1264                        for (unsigned int k=0; k<RHeader->NChannels; k++) {
     1265                          Integral = 0.0;
     1266                          for (int q=-fIntHalfWidth; q<=(int) fIntHalfWidth; q++) {
     1267                        Integral += (WaveForm[i][j][k][fLedSignalSample+q] - WaveForm[i][j][k][fLedBaselineSample+q])*GetBoard(i)->GetPrecision();
     1268                          }
     1269                  Integral /= 2*fIntHalfWidth+1;
     1270                          Cmd << Integral << " ";
     1271                }
     1272                  }
     1273                }
     1274
     1275                // Send data to feedback
     1276                DimClient::sendCommandNB("Feedback/Command", (char *) ("data "+Cmd.str()).c_str());
     1277          }
    13071278
    13081279      // Call routine to update DIM service (update rate is limited)
Note: See TracChangeset for help on using the changeset viewer.