System part of the Analyzer code. More...
Functions | |
bool | UpdateDetectorBankNameMap (TSetupData *gSetup) |
static void | catastrophe (int signum) |
INT | analyzer_init () |
INT | analyzer_exit () |
INT | ana_begin_of_run (INT run_number, char *error) |
INT | ana_end_of_run (INT run_number, char *error) |
INT | ana_pause_run (INT run_number, char *error) |
INT | ana_resume_run (INT run_number, char *error) |
INT | analyzer_loop () |
static TSetupData * | TSetupData::Instance () |
(Quasi-)Singleton interface | |
static TGlobalData * | TGlobalData::Instance () |
Variables | |
char * | analyzer_name = "Analyzer" |
INT | analyzer_loop_period = 0 |
INT | odb_size = DEFAULT_ODB_SIZE |
TGlobalData * | gData |
Object to hold data used and produced by modules throughout alcapana stage of analysis. | |
TSetupData * | gSetup |
Hardware information about digitizers and detectors to be used during alcapana stage of analysis. | |
TVacuumData * | gVacuum |
Vacuum data slow control. | |
BANK_LIST | ana_trigger_bank_list [] |
BANK_LIST | ana_vacuum_bank_list [] |
ANA_MODULE | MVacuumHisto_module |
ANA_MODULE * | Vacuum_module [] |
ANALYZE_REQUEST | analyze_request [] |
System part of the Analyzer code.
INT ana_begin_of_run | ( | INT | run_number, | |
char * | error | |||
) |
Definition at line 233 of file analyzer.cpp.
INT ana_end_of_run | ( | INT | run_number, | |
char * | error | |||
) |
Definition at line 241 of file analyzer.cpp.
INT ana_pause_run | ( | INT | run_number, | |
char * | error | |||
) |
Definition at line 249 of file analyzer.cpp.
INT ana_resume_run | ( | INT | run_number, | |
char * | error | |||
) |
Definition at line 256 of file analyzer.cpp.
INT analyzer_exit | ( | ) |
Definition at line 211 of file analyzer.cpp.
INT analyzer_init | ( | ) |
Definition at line 177 of file analyzer.cpp.
References catastrophe(), and UpdateDetectorBankNameMap().
00178 { 00179 bool ret; 00180 00181 // Initialize gData 00182 gData = new TGlobalData(); 00183 00184 // Initialize gSetup 00185 gSetup = new TSetupData(); 00186 ret = UpdateDetectorBankNameMap(gSetup); 00187 if (!ret) { 00188 printf("THERE WAS AN ERROR!\n"); 00189 return 0; 00190 } 00191 // Override ROOT's handling of signals 00192 signal(SIGHUP , catastrophe); 00193 signal(SIGINT , catastrophe); 00194 signal(SIGQUIT , catastrophe); 00195 signal(SIGILL , catastrophe); 00196 signal(SIGABRT , catastrophe); 00197 signal(SIGFPE , catastrophe); 00198 signal(SIGKILL , catastrophe); 00199 signal(SIGSEGV , catastrophe); 00200 signal(SIGPIPE , catastrophe); 00201 signal(SIGTERM , catastrophe); 00202 00203 // Initialize gVacuum 00204 gVacuum = new TVacuumData(); 00205 00206 return SUCCESS; 00207 }
INT analyzer_loop | ( | ) |
Definition at line 263 of file analyzer.cpp.
static void catastrophe | ( | int | signum | ) | [static] |
Definition at line 154 of file analyzer.cpp.
Referenced by analyzer_init().
00155 { 00156 #if 0 00157 static bool previously_caught_signal = false; 00158 #endif 00159 00160 printf("Caught signal %d, exiting...", signum); 00161 00162 #if 0 00163 if(!previously_caught_signal) { 00164 previously_caught_signal = true; 00165 00166 #ifdef HAVE_ROOT 00167 printf("Attempting to save histograms...\n"); 00168 extern void CloseRootOutputFile(); 00169 CloseRootOutputFile(); 00170 #endif 00171 } 00172 #endif 00173 00174 exit(-signum); 00175 }
TGlobalData * TGlobalData::Instance | ( | ) | [static, inherited] |
Definition at line 90 of file analyzer.cpp.
00091 { 00092 return gData; 00093 }
TSetupData * TSetupData::Instance | ( | ) | [static, inherited] |
(Quasi-)Singleton interface
Definition at line 85 of file analyzer.cpp.
Referenced by TemplateCreator::BeforeFirstEntry(), PulseCandidateFinder::CheckDigitiserOverflow(), PulseCandidateFinder::FillParameterHistogram(), TemplateFitter::FitPulseToTemplate(), TPulseIsland::GetAmplitude(), TPulseIsland::GetClockTickInNs(), PlotAmpVsMuScTDiff::GetHistogram(), TPulseIsland::GetPedestal(), GetTime(), TPulseIsland::GetTriggerPolarity(), TemplateCreator::HasPulseOverflowed(), functions::InterpolatePulse(), isValid(), MDQ_muScTDiff(), MDQ_Thresholds_eor(), PlotAmpVsTDiff::PlotAmpVsTDiff(), TemplateCreator::ProcessEntry(), PulseCandidateFinder_InvestigateParameters::ProcessEntry(), PlotTPI_PedestalAndNoise::ProcessEntry(), and GeSpectrum::ProcessEntry().
00086 { 00087 return gSetup; 00088 }
bool UpdateDetectorBankNameMap | ( | TSetupData * | gSetup | ) |
Definition at line 271 of file analyzer.cpp.
References hDB, TSetupData::IsBostonCAEN(), TSetupData::IsFADC(), TSetupData::IsHoustonCAEN(), TSetupData::SetADCOffsetCalib(), TSetupData::SetADCSlopeCalib(), TSetupData::SetClockTick(), TSetupData::SetDetectorName(), TSetupData::SetEnableBit(), TSetupData::SetNBits(), TSetupData::SetPedestal(), TSetupData::SetTimeShift(), and TSetupData::SetTriggerPolarity().
Referenced by analyzer_init().
00271 { 00272 // Want to go through the /Analyzer/WireMap and map bank names and detector names 00273 bool ret = true; 00274 HNDLE hDB, hKey; 00275 char keyName[200]; 00276 00277 if(cm_get_experiment_database(&hDB, NULL) != CM_SUCCESS){ 00278 printf("Warning: Could not connect to ODB database!\n"); 00279 return false; 00280 } 00281 00282 sprintf(keyName, "/Analyzer/WireMap/BankName"); 00283 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){ 00284 printf("Warning: Could not find key %s\n", keyName); 00285 return false; 00286 } 00287 KEY bk_key; 00288 if(db_get_key(hDB, hKey, &bk_key) != DB_SUCCESS){ 00289 printf("Warning: Could not find key %s\n", keyName); 00290 return false; 00291 } 00292 char BankNames[bk_key.num_values][bk_key.item_size]; 00293 int size = sizeof(BankNames); 00294 if(db_get_value(hDB, 0, keyName , BankNames, &size, TID_STRING, 0) != DB_SUCCESS){ 00295 printf("Warning: Could not retrieve values for key %s\n", keyName); 00296 ret = false; 00297 } 00298 00299 sprintf(keyName, "/Analyzer/WireMap/DetectorName"); 00300 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){ 00301 printf("Warning: Could not find key %s\n", keyName); 00302 return false; 00303 } 00304 KEY det_key; 00305 if(db_get_key(hDB, hKey, &det_key) != DB_SUCCESS){ 00306 printf("Warning: Could not find key %s\n", keyName); 00307 return false; 00308 } 00309 char DetectorNames[det_key.num_values][det_key.item_size]; 00310 size = sizeof(DetectorNames); 00311 if(db_get_value(hDB, 0, keyName , DetectorNames, &size, TID_STRING, 0) != DB_SUCCESS){ 00312 printf("Warning: Could not retrieve values for key %s\n", keyName); 00313 ret = false; 00314 } 00315 00316 sprintf(keyName, "/Analyzer/WireMap/TimeShift"); 00317 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){ 00318 printf("Warning: Could not find key %s\n", keyName); 00319 return false; 00320 } 00321 KEY timeshift_key; 00322 if(db_get_key(hDB, hKey, ×hift_key) != DB_SUCCESS){ 00323 printf("Warning: Could not find key %s\n", keyName); 00324 return false; 00325 } 00326 float TimeShifts[timeshift_key.num_values]; 00327 size = sizeof(TimeShifts); 00328 if(db_get_value(hDB, 0, keyName, TimeShifts, &size, TID_FLOAT, 0) != DB_SUCCESS){ 00329 printf("Warning: Could not retrieve values for key %s\n", keyName); 00330 ret = false; 00331 } 00332 00333 sprintf(keyName, "/Analyzer/WireMap/Enabled"); 00334 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){ 00335 printf("Warning: Could not find key %s\n", keyName); 00336 return false; 00337 } 00338 KEY enablebit_key; 00339 if (db_get_key(hDB, hKey, &enablebit_key) != DB_SUCCESS) 00340 { 00341 printf("Warning: Could not find key %s\n", keyName); 00342 return false; 00343 } 00344 int EnableBitsBuffer[enablebit_key.num_values]; 00345 size = sizeof(EnableBitsBuffer); 00346 //printf("sizeof EnableBitsBuffer %d\n", size); 00347 if(db_get_value(hDB, 0, keyName , EnableBitsBuffer, &size, TID_BOOL, 0) != DB_SUCCESS){ 00348 printf("Warning: Could not retrieve values for key %s\n", keyName); 00349 ret = false; 00350 } 00351 00352 bool EnableBits[enablebit_key.num_values]; 00353 00354 int jj = 0; 00355 for (jj = 0; jj < enablebit_key.num_values; ++jj) 00356 { 00357 EnableBits[jj] = EnableBitsBuffer[jj] == 1 ? 1:0; 00358 //printf("jj %d: %d %d\n", jj, EnableBitsBuffer[jj], EnableBits[jj]); 00359 }/* code */ 00360 00361 00362 sprintf(keyName, "/Analyzer/WireMap/TriggerPolarity"); 00363 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){ 00364 printf("Warning: Could not find key %s\n", keyName); 00365 return false; 00366 } 00367 KEY pol_key; 00368 if(db_get_key(hDB, hKey, &pol_key) != DB_SUCCESS){ 00369 printf("Warning: Could not find key %s\n", keyName); 00370 return false; 00371 } 00372 int TriggerPolarities[pol_key.num_values]; 00373 size = sizeof(TriggerPolarities); 00374 if(db_get_value(hDB, 0, keyName , TriggerPolarities, &size, TID_INT, 0) != DB_SUCCESS){ 00375 printf("Warning: Could not retrieve values for key %s\n", keyName); 00376 ret = false; 00377 } 00378 00379 sprintf(keyName, "/Analyzer/WireMap/Pedestal"); 00380 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){ 00381 printf("Warning: Could not find key %s\n", keyName); 00382 return false; 00383 } 00384 KEY ped_key; 00385 if(db_get_key(hDB, hKey, &ped_key) != DB_SUCCESS){ 00386 printf("Warning: Could not find key %s\n", keyName); 00387 return false; 00388 } 00389 int Pedestals[ped_key.num_values]; 00390 size = sizeof(Pedestals); 00391 if(db_get_value(hDB, 0, keyName , Pedestals, &size, TID_INT, 0) != DB_SUCCESS){ 00392 printf("Warning: Could not retrieve values for key %s\n", keyName); 00393 ret = false; 00394 } 00395 00396 if(det_key.num_values != bk_key.num_values){ 00397 printf("Warning: Key sizes are not equal for banks and detectors in /Analyzer/WireMap/\n"); 00398 ret = false; 00399 } 00400 else printf("sizes are %d\n", det_key.num_values); 00401 00402 std::vector<bool> duplicate_dets(det_key.num_values, false); // Keep track of duplicate detector names, and check later if they'll be a problem 00403 for(int i=0; i<det_key.num_values; i++){ 00404 if(strcmp(BankNames[i], "") == 0) { 00405 printf("Found bank name that is empty! (Index %d)\n", i); 00406 ret = false; 00407 continue; 00408 } 00409 if(strcmp(DetectorNames[i], "") == 0) printf("Warning: No detector name associated with bank %s!\n", BankNames[i]); 00411 // Add the detector names to TSetupData 00412 // Should be a bidirectional map. Lacking that functionality 00413 // we simply check if the value detector exists 00414 std::string bank_name(BankNames[i]), detector(DetectorNames[i]); 00415 if(detector != "blank" && !(gSetup->SetDetectorName(bank_name,detector))) { 00416 printf("WARNING: Detector %s listed multiple times in ODB! (Duplicate index %d)\n", detector.c_str(), i); 00417 duplicate_dets.at(i) = true; 00418 } 00419 gSetup->SetTriggerPolarity(bank_name,TriggerPolarities[i]); 00420 gSetup->SetPedestal(bank_name,Pedestals[i]); 00421 gSetup->SetTimeShift(bank_name,TimeShifts[i]); 00422 gSetup->SetEnableBit(bank_name,EnableBits[i]); 00423 //printf("%s: %d\n", bank_name.c_str(), gSetup->GetEnableBit(bank_name)); 00424 00426 // Calculate and the add the clock ticks to TSetupData 00427 int DCMPhase = 1; // assume DCMPhase = 1 for most digitizers (it's only applicable to the FADCs) 00428 if(TSetupData::IsFADC(bank_name)){ 00429 int iChn = (int)(bank_name[1] - 97); 00430 std::string iAddr = bank_name.substr(2, 2); 00431 00432 sprintf(keyName, "/Equipment/Crate 9/Settings/NFADC %s/Channel %d/DCM phase", iAddr.c_str(), iChn); 00433 if(db_find_key(hDB,0,keyName, &hKey) == SUCCESS){ 00434 db_get_key(hDB, hKey, &bk_key); 00435 00436 int size = sizeof(DCMPhase); 00437 if(db_get_value(hDB, 0, keyName , &DCMPhase, &size, TID_INT, 0) == DB_SUCCESS){ 00438 // printf("Found the DCM Phase!\n"); 00439 } 00440 } 00441 // 00443 // Get the sampling frequency of the different digitizers 00444 sprintf(keyName, "/Analyzer/WireMap/SamplingFrequency"); 00445 if(db_find_key(hDB, 0, keyName, &hKey) == SUCCESS){ 00446 std::string bank_name(BankNames[i]); 00447 float frequency = 170E6 / DCMPhase; 00448 int size = sizeof(float); 00449 db_set_data_index(hDB, hKey, &frequency, size, i, TID_FLOAT); 00450 } 00451 } 00452 00453 sprintf(keyName, "/Analyzer/WireMap/SamplingFrequency"); 00454 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){ 00455 printf("Warning: Could not find key %s\n", keyName); 00456 return false; 00457 } 00458 KEY freq_key; 00459 if(db_get_key(hDB, hKey, &freq_key) != DB_SUCCESS){ 00460 printf("Warning: Could not find key %s\n", keyName); 00461 return false; 00462 } 00463 float SamplingFrequencies[freq_key.num_values]; 00464 size = sizeof(SamplingFrequencies); 00465 if(db_get_value(hDB, 0, keyName , SamplingFrequencies, &size, TID_FLOAT, 0) != DB_SUCCESS){ 00466 printf("Warning: Could not retrieve values for key %s\n", keyName); 00467 ret = false; 00468 } 00469 00470 double clockTickInNs = (1/SamplingFrequencies[i]) * 1e9; 00471 // printf("Bank %s: f = %f, clockTick = %f\n", bank_name.c_str(), true_frequency, clockTickInNs); 00472 gSetup->SetClockTick(bank_name,clockTickInNs); 00473 00475 // ADC calibration constants 00476 sprintf(keyName, "/Analyzer/WireMap/ADCSlopeCalib"); 00477 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){ 00478 printf("Warning: Could not find key %s\n", keyName); 00479 return false; 00480 } 00481 KEY adc_slope_calib_key; 00482 if(db_get_key(hDB, hKey, &adc_slope_calib_key) != DB_SUCCESS){ 00483 printf("Warning: Could not find key %s\n", keyName); 00484 return false; 00485 } 00486 float ADCSlopeCalibs[adc_slope_calib_key.num_values]; 00487 size = sizeof(ADCSlopeCalibs); 00488 if(db_get_value(hDB, 0, keyName , ADCSlopeCalibs, &size, TID_FLOAT, 0) != DB_SUCCESS){ 00489 printf("Warning: Could not retrieve values for key %s\n", keyName); 00490 ret = false; 00491 } 00492 00493 sprintf(keyName, "/Analyzer/WireMap/ADCOffsetCalib"); 00494 if(db_find_key(hDB,0,keyName, &hKey) != SUCCESS){ 00495 printf("Warning: Could not find key %s\n", keyName); 00496 return false; 00497 } 00498 KEY adc_offset_calib_key; 00499 if(db_get_key(hDB, hKey, &adc_offset_calib_key) != DB_SUCCESS){ 00500 printf("Warning: Could not find key %s\n", keyName); 00501 return false; 00502 } 00503 float ADCOffsetCalibs[adc_offset_calib_key.num_values]; 00504 size = sizeof(ADCOffsetCalibs); 00505 if(db_get_value(hDB, 0, keyName , ADCOffsetCalibs, &size, TID_FLOAT, 0) != DB_SUCCESS){ 00506 printf("Warning: Could not retrieve values for key %s\n", keyName); 00507 ret = false; 00508 } 00509 00510 00511 float adcSlopeValue = ADCSlopeCalibs[i]; 00512 float adcOffsetValue = ADCOffsetCalibs[i]; 00513 gSetup->SetADCSlopeCalib(bank_name,adcSlopeValue); 00514 gSetup->SetADCOffsetCalib(bank_name,adcOffsetValue); 00515 00517 // Add the number of bits for each digitizer 00518 if(TSetupData::IsFADC(bank_name )) {// FADC banks 00519 gSetup->SetNBits(bank_name,12); 00520 } 00521 else if(TSetupData::IsHoustonCAEN(bank_name)) { // UH CAEN banks 00522 gSetup->SetNBits(bank_name,14); 00523 } 00524 else if (TSetupData::IsBostonCAEN(bank_name)) { // UH CAEN banks 00525 gSetup->SetNBits(bank_name,12); 00526 } else if (bank_name == "ZZZZ") { 00527 gSetup->SetNBits(bank_name, 0); 00528 } else { 00529 printf("Cannot determine digitizer type of bank %s!\n", bank_name.c_str()); 00530 ret = false; 00531 } 00532 00534 // Check to see if the bank is enabled 00535 if(TSetupData::IsFADC(bank_name)) { // FADC banks 00536 std::string iAddr(bank_name); 00537 int iChn = (int)(iAddr[1] - 97); 00538 iAddr = iAddr.substr(2, 2); 00539 00540 char wireKey[100]; 00541 BOOL enabled = false; 00542 int size = sizeof(enabled); 00543 sprintf(wireKey, "/Analyzer/WireMap/Enabled"); 00544 if(db_find_key(hDB,0,wireKey, &hKey) == SUCCESS){ 00545 // Let's first reset /Analyzer/WireMap/Enabled for this channel to 'n' 00546 db_set_data_index(hDB, hKey, &enabled, size, i, TID_BOOL); 00547 00548 sprintf(keyName, "/Equipment/Crate 9/Settings/NFADC %s/Enabled", iAddr.c_str()); 00549 if(db_get_value(hDB, 0, keyName , &enabled, &size, TID_BOOL, 0) == DB_SUCCESS) { 00550 if(enabled){ 00551 sprintf(keyName, "/Equipment/Crate 9/Settings/NFADC %s/Channel %d/Trigger mask", iAddr.c_str(), iChn); 00552 int trigger_mask; 00553 size = sizeof(trigger_mask); 00554 if(db_get_value(hDB, 0, keyName , &trigger_mask, &size, TID_INT, 0) == DB_SUCCESS) { 00555 if (trigger_mask == 1){ // if this channel is taking data 00556 db_set_data_index(hDB, hKey, &enabled, size, i, TID_BOOL); 00557 } 00558 } else { // We found the channel 'Trigger mask' key in ODB 00559 printf("Could not find Trigger Mask key in ODB!\n"); 00560 ret = false; 00561 } 00562 } else { // This module is enabled 00563 if (duplicate_dets.at(i)) { 00564 printf("ATTENTION: Duplicate detector at index %d resolved (not enabled).\n", i); 00565 duplicate_dets.at(i) = false; 00566 } 00567 } 00568 } // We got the value of the module 'Enable' key in ODB 00569 00570 } else { // We found the 'Enabled' key in the ODB 00571 printf("Could not find Enabled key in ODB!\n"); 00572 ret = false; 00573 } 00574 } else if (TSetupData::IsHoustonCAEN(bank_name)) { 00575 BOOL enabled = true; 00576 int size; 00577 char aCh = bank_name[1]; 00578 int iCh = aCh - 'a'; // a->0, b->1, etc. 00579 00580 size = sizeof(enabled); 00581 sprintf(keyName, "/Equipment/Crate 4/Settings/CAEN0/Ch%1d/Enabled", iCh); 00582 if (db_get_value(hDB, 0, keyName, &enabled, &size, TID_BOOL, 0) == DB_SUCCESS) { 00583 if (!enabled && duplicate_dets.at(i)){ 00584 duplicate_dets[i] = false; 00585 printf("ATTENTION: Duplicate detector at index %d resolved (not enabled).\n", i); 00586 } 00587 } else { 00588 printf("Could not find UH CAEN Enabled key in ODB!\n"); 00589 ret = false; 00590 } 00591 } else if (TSetupData::IsBostonCAEN(bank_name)) { 00592 BOOL enabled = true; 00593 int size; 00594 char aCh = bank_name[1]; 00595 int iCh = aCh - 'a'; // a->0, b->1, etc. 00596 00597 size = sizeof(enabled); 00598 sprintf(keyName, "/Equipment/Crate 5/Settings/CAEN/Ch%02d/enable", iCh); 00599 if (db_get_value(hDB, 0, keyName, &enabled, &size, TID_BOOL, 0) == DB_SUCCESS) { 00600 if (!enabled && duplicate_dets.at(i)) { 00601 printf("ATTENTION: Duplicate detector at index %d resolved (not enabled).\n", i); 00602 duplicate_dets[i] = false; 00603 } 00604 } else { 00605 printf("Could not find BU CAEN Enabled key in ODB!\n"); 00606 ret = false; 00607 } 00608 } 00609 } // end loop over all non empty banks 00610 00611 // Check if there are duplicate detectors all enabled 00612 for (int i = 0; i < duplicate_dets.size(); ++i) { 00613 if (duplicate_dets.at(i)) { 00614 printf("ERROR: Multiple detectors enabled! (Index %d)\n", i); 00615 ret = false; 00616 } 00617 } 00618 00619 return ret; 00620 }
BANK_LIST ana_trigger_bank_list[] |
{
{ "" },
}
Definition at line 103 of file analyzer.cpp.
BANK_LIST ana_vacuum_bank_list[] |
{
{ "" },
}
Definition at line 108 of file analyzer.cpp.
ANALYZE_REQUEST analyze_request[] |
Definition at line 119 of file analyzer.cpp.
INT analyzer_loop_period = 0 |
Definition at line 68 of file analyzer.cpp.
char* analyzer_name = "Analyzer" |
Definition at line 65 of file analyzer.cpp.
Object to hold data used and produced by modules throughout alcapana stage of analysis.
Definition at line 76 of file analyzer.cpp.
Hardware information about digitizers and detectors to be used during alcapana stage of analysis.
Definition at line 80 of file analyzer.cpp.
Vacuum data slow control.
Definition at line 83 of file analyzer.cpp.
ANA_MODULE MVacuumHisto_module |
INT odb_size = DEFAULT_ODB_SIZE |
Definition at line 71 of file analyzer.cpp.
ANA_MODULE* Vacuum_module[] |
{ &MVacuumHisto_module, NULL }
Definition at line 115 of file analyzer.cpp.