4 Contact: Franck Manso <manso@clermont.in2p3.fr>
5 Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_mtrda.html
6 Reference run: 61898, 61945 (dead channels), 61963 (noisy channels)
7 Run Type: PHYSICS (noisy channels), STANDALONE (dead channels)
9 Number of events needed: 1000 events for noisy and dead channels
10 Input Files: Rawdata file (DATE format)
12 MtgGlobalCrate-<version>.dat
13 MtgRegionalCrate-<version>.dat
14 MtgLocalMask-<version>.dat
15 MtgLocalLut-<version>.dat
18 Output Files: local dir (not persistent)
25 Version 2 for MUONTRGda MUON trigger
30 Versionning of the Mtg file
32 DA for ELECTRONICS_CALIBRATION_RUN (calib)
33 checking dead channels
35 DA for DETECTOR_CALIBRATION_RUN (ped)
36 checking the noisy channels
38 Interfaced with online database and file exchange server
44 Writing into the online database (need update of daqDAlib)
46 Looking at scalers outputs
56 #include <Riostream.h>
61 #include "AliRawReaderDate.h"
63 #include "AliMpConstants.h"
64 #include "AliMUONRawStreamTrigger.h"
65 #include "AliMUONDarcHeader.h"
66 #include "AliMUONRegHeader.h"
67 #include "AliMUONLocalStruct.h"
68 #include "AliMUONDDLTrigger.h"
69 #include "AliMUONVCalibParam.h"
70 #include "AliMUONVStore.h"
71 #include "AliMUONCalibParamND.h"
72 #include "AliMUONCalibParamNI.h"
73 #include "AliMUON1DArray.h"
74 #include "AliMUONTriggerIO.h"
75 #include "AliMUONRegionalTriggerConfig.h"
76 #include "AliMUONGlobalCrateConfig.h"
77 #include "AliMUONTriggerCrateConfig.h"
82 #include "TStopwatch.h"
84 #include "TTimeStamp.h"
86 #include "TPluginManager.h"
93 const Int_t gkNLocalBoard = AliMpConstants::TotalNofLocalBoards()+1;
95 TString gCurrentFileName("MtgCurrent.dat");
96 TString gLastCurrentFileName("MtgLastCurrent.dat");
104 TString gGlobalFileName;
105 TString gRegionalFileName;
106 TString gLocalMaskFileName;
107 TString gLocalLutFileName;
108 TString gSignatureFileName;
110 Int_t gGlobalFileVersion;
111 Int_t gRegionalFileVersion;
112 Int_t gLocalMaskFileVersion;
113 Int_t gLocalLutFileVersion;
114 Int_t gSignatureFileVersion;
116 Int_t gGlobalFileLastVersion;
117 Int_t gRegionalFileLastVersion;
118 Int_t gLocalMaskFileLastVersion;
119 Int_t gLocalLutFileLastVersion;
121 UInt_t gRunNumber = 0;
126 Int_t gPrintLevel = 0;
128 AliMUONVStore* gLocalMasks = 0x0;
129 AliMUONRegionalTriggerConfig* gRegionalMasks = 0x0;
130 AliMUONGlobalCrateConfig* gGlobalMasks = 0x0;
132 AliMUONTriggerIO gTriggerIO;
134 Bool_t gAlgoNoisyInput = false;
135 Bool_t gAlgoDeadInput = false;
137 Int_t gkGlobalInputs = 4;
138 Int_t gkGlobalInputLength = 32;
139 Float_t gkThreshold = 0.1;
140 Int_t gkMinEvents = 10;
142 Int_t gAccGlobalInputN[4][32] = {0};
143 Int_t gAccGlobalInputD[4][32] = {0};
145 Bool_t gWriteInitialDB = false;
147 //__________________________________________________________________
148 void WriteLastCurrentFile(TString currentFile = gLastCurrentFileName)
151 // write last current file
155 out.open(file.Data());
156 out << gSodName << " " << gSodFlag << endl;
157 out << gDAName << " " << gDAFlag << endl;
159 out << gGlobalFileName << " " << gGlobalFileVersion << endl;
160 out << gRegionalFileName << " " << gRegionalFileVersion << endl;
161 out << gLocalMaskFileName << " " << gLocalMaskFileVersion << endl;
162 out << gLocalLutFileName << " " << gLocalLutFileVersion << endl;
163 out << gSignatureFileName << " " << gSignatureFileVersion << endl;
168 //___________________________________________________________________________________________
169 Bool_t ReadCurrentFile(TString currentFile = gCurrentFileName, Bool_t lastCurrentFlag = false)
172 // read last current file name and version
178 std::ifstream in(gSystem->ExpandPathName(file.Data()));
180 printf("Cannot open last current file %s\n",currentFile.Data());
186 sscanf(line, "%s %d", name, &gSodFlag);
188 if (gPrintLevel) printf("Sod Flag %d\n", gSodFlag);
192 sscanf(line, "%s %d", name, &gDAFlag);
194 if (gPrintLevel) printf("DA Flag: %d\n", gDAFlag);
199 Int_t pos = tmp.First(" ");
200 gGlobalFileName = tmp(0, pos);
202 if (!lastCurrentFlag) {
203 gGlobalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
204 if (gPrintLevel) printf("Global File Name: %s version: %d\n",
205 gGlobalFileName.Data(), gGlobalFileVersion);
207 gGlobalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
208 if (gPrintLevel) printf("Global File Name: %s last version: %d\n",
209 gGlobalFileName.Data(), gGlobalFileLastVersion);
215 pos = tmp.First(" ");
216 gRegionalFileName = tmp(0, pos);
218 if (!lastCurrentFlag) {
219 gRegionalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
220 if (gPrintLevel) printf("Regional File Name: %s version: %d\n",
221 gRegionalFileName.Data(), gRegionalFileVersion);
224 gRegionalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
225 if (gPrintLevel) printf("Regional File Name: %s last version: %d\n",
226 gRegionalFileName.Data(), gRegionalFileLastVersion);
232 pos = tmp.First(" ");
233 gLocalMaskFileName = tmp(0, pos);
235 if (!lastCurrentFlag) {
236 gLocalMaskFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
237 if (gPrintLevel) printf("Mask File Name: %s version: %d\n",
238 gLocalMaskFileName.Data(), gLocalMaskFileVersion);
240 gLocalMaskFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
241 if (gPrintLevel) printf("Mask File Name: %s last version: %d\n",
242 gLocalMaskFileName.Data(), gLocalMaskFileLastVersion);
247 pos = tmp.First(" ");
248 gLocalLutFileName = tmp(0, pos);
250 if (!lastCurrentFlag) {
251 gLocalLutFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
252 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
253 gLocalLutFileName.Data(), gLocalLutFileVersion);
255 gLocalLutFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
256 if (gPrintLevel) printf("Lut File Name: %s last version: %d\n",
257 gLocalLutFileName.Data(), gLocalLutFileLastVersion);
262 pos = tmp.First(" ");
263 gSignatureFileName = tmp(0, pos);
264 gSignatureFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
265 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
266 gSignatureFileName.Data(), gSignatureFileVersion);
274 // if last current file does not exist than read current file
275 if (!ReadCurrentFile(gLastCurrentFileName, true))
277 ReadCurrentFile(gCurrentFileName, true);
280 // any case read current file
289 // Export files to FES
290 // env variables have to be set (suppose by ECS ?)
291 // setenv DATE_FES_PATH
292 // setenv DATE_RUN_NUMBER
293 // setenv DATE_ROLE_NAME
294 // setenv DATE_DETECTOR_CODE
297 //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
302 Bool_t modified = false;
305 TString fileExp("ExportedFiles.dat");
308 out.open(fileExp.Data());
310 printf("Failed to create file: %s\n",file.Data());
314 file = gGlobalFileName.Data();
315 if (gGlobalFileLastVersion != gGlobalFileVersion) {
316 status = daqDA_FES_storeFile(file.Data(), file.Data());
318 printf("Failed to export file: %s\n",gGlobalFileName.Data());
321 if(gPrintLevel) printf("Export file: %s\n",gGlobalFileName.Data());
322 out << gGlobalFileName.Data() << endl;
325 file = gLocalMaskFileName;
326 if (gLocalMaskFileLastVersion != gLocalMaskFileVersion) {
328 status = daqDA_FES_storeFile(file.Data(), file.Data());
330 printf("Failed to export file: %s\n",gLocalMaskFileName.Data());
333 if(gPrintLevel) printf("Export file: %s\n",gLocalMaskFileName.Data());
334 out << gLocalMaskFileName.Data() << endl;
337 file = gLocalLutFileName;
338 if (gLocalLutFileLastVersion != gLocalLutFileVersion) {
340 status = daqDA_FES_storeFile(file.Data(), file.Data());
342 printf("Failed to export file: %s\n",gLocalLutFileName.Data());
345 if(gPrintLevel) printf("Export file: %s\n",gLocalLutFileName.Data());
346 out << gLocalLutFileName.Data() << endl;
350 // exported regional file whenever mask or/and Lut are modified
351 file = gRegionalFileName;
352 if ( (gRegionalFileLastVersion != gRegionalFileVersion) || modified) {
353 status = daqDA_FES_storeFile(file.Data(), file.Data());
355 printf("Failed to export file: %s\n",gRegionalFileName.Data());
358 if(gPrintLevel) printf("Export file: %s\n",gRegionalFileName.Data());
359 out << gRegionalFileName.Data() << endl;
364 // export Exported file to FES anyway
365 status = daqDA_FES_storeFile(fileExp.Data(), fileExp.Data());
367 printf("Failed to export file: %s\n", fileExp.Data());
370 if(gPrintLevel) printf("Export file: %s\n",fileExp.Data());
372 // write last current file
373 WriteLastCurrentFile();
381 // copy locally a file from daq detector config db
382 // The current detector is identified by detector code in variable
383 // DATE_DETECTOR_CODE. It must be defined.
384 // If environment variable DAQDA_TEST_DIR is defined, files are copied from DAQDA_TEST_DIR
385 // instead of the database. The usual environment variables are not needed.
390 //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
392 // offline: use the test directory as a source / else use the database
394 if (gWriteInitialDB) {
395 gSystem->Setenv("DAQDA_TEST_DIR", "/alisoft/Mts-files");
396 gSystem->Exec("echo $DAQDA_TEST_DIR");
398 gSystem->Unsetenv("DAQDA_TEST_DIR");
399 gSystem->Exec("echo $DAQDA_TEST_DIR");
402 status = daqDA_DB_getFile(gCurrentFileName.Data(), gCurrentFileName.Data());
404 printf("Failed to get current config file from DB: %s\n",gCurrentFileName.Data());
410 status = daqDA_DB_getFile(gGlobalFileName.Data(), gGlobalFileName.Data());
412 printf("Failed to get current config file from DB: %s\n", gGlobalFileName.Data());
416 // offline: use always the test directory as a source
417 //gSystem->Setenv("DAQDA_TEST_DIR", "/alisoft/Mts-files");
418 //gSystem->Exec("echo $DAQDA_TEST_DIR");
420 status = daqDA_DB_getFile(gRegionalFileName.Data(), gRegionalFileName.Data());
422 printf("Failed to get current config file from DB: %s\n",gRegionalFileName.Data());
426 status = daqDA_DB_getFile(gLocalMaskFileName.Data(), gLocalMaskFileName.Data());
428 printf("Failed to get current config file from DB: %s\n",gLocalMaskFileName.Data());
432 status = daqDA_DB_getFile(gLocalLutFileName.Data(), gLocalLutFileName.Data());
434 printf("Failed to get current config file from DB: %s\n",gLocalLutFileName.Data());
445 gLocalMasks = new AliMUON1DArray(gkNLocalBoard);
446 gRegionalMasks = new AliMUONRegionalTriggerConfig();
447 gGlobalMasks = new AliMUONGlobalCrateConfig();
449 TString localFile = gLocalMaskFileName;
450 TString regionalFile = gRegionalFileName;
451 TString globalFile = gGlobalFileName;
453 gTriggerIO.ReadConfig(localFile.Data(), regionalFile.Data(), globalFile.Data(),
454 gLocalMasks, gRegionalMasks, gGlobalMasks);
457 //______________________________________________________________
460 // FET mode = 3 to run algorithm for dead global inputs
464 return gGlobalMasks->GetFetRegister(3);
468 //______________________________________________________________
469 void StoreGlobalInput(UInt_t *globalInput)
471 // accumulate and build statistics of global input values
473 for (Int_t ii = 0; ii < gkGlobalInputs; ii++) {
474 for (Int_t ib = 0; ib < gkGlobalInputLength; ib++) {
477 gAccGlobalInputN[ii][ib] += (globalInput[ii] >> ib) & 0x1;
479 gAccGlobalInputD[ii][ib] += (globalInput[ii] >> ib) & 0x1;
485 //______________________________________________________________
486 void UpdateGlobalMasks()
488 // update the global masks
491 //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
493 Float_t rateN = 0.0, rateD = 0.0;
494 UInt_t gmask[4], omask;
495 Bool_t noise, deadc, withEvN, withEvD, updated = false;
497 for (Int_t ii = 0; ii < gkGlobalInputs; ii++) {
500 for (Int_t ib = 0; ib < gkGlobalInputLength; ib++) {
506 if (gNEventsN > gkMinEvents) {
507 rateN = (Float_t)gAccGlobalInputN[ii][ib]/(Float_t)gNEventsN;
508 noise = (rateN > gkThreshold);
511 if (gNEventsD > gkMinEvents) {
512 rateD = (Float_t)gAccGlobalInputD[ii][ib]/(Float_t)gNEventsD;
513 deadc = (rateD < (1.0 - gkThreshold));
516 if (!withEvN && !withEvD) {
517 // - copy the bit from the old mask
518 gmask[ii] |= ((gGlobalMasks->GetGlobalMask(ii) >> ib) & 0x1) << ib;
519 printf("Mask not changed (just copy the old values)\n");
521 if (!withEvN && withEvD) {
523 // - create a new mask, set the bit to 1
524 gmask[ii] |= 0x1 << ib;
526 // - create a new mask, set the bit to 0
527 gmask[ii] |= 0x0 << ib;
528 printf("Found dead channel %1d:%02d \n",ii,ib);
531 if (withEvN && !withEvD) {
533 // - create a new mask, set the bit to 1
534 gmask[ii] |= 0x1 << ib;
536 // - create a new mask, set the bit to 0
537 gmask[ii] |= 0x0 << ib;
538 printf("Found noisy channel %1d:%02d \n",ii,ib);
541 if (withEvN && withEvD) {
542 if (!noise && !deadc) {
543 // - create a new mask, set the bit to 1
544 gmask[ii] |= 0x1 << ib;
546 // - create a new mask, set the bit to 0
547 gmask[ii] |= 0x0 << ib;
549 printf("Found noisy channel %1d:%02d \n",ii,ib);
551 printf("Found dead channel %1d:%02d \n",ii,ib);
555 printf("gmask %08x \n",gmask[ii]);
558 // check if at least one mask value has been changed from previous version
559 for (Int_t ii = 0; ii < gkGlobalInputs; ii++) {
560 omask = gGlobalMasks->GetGlobalMask(ii);
561 if (gmask[ii] != omask) {
563 gGlobalMasks->SetGlobalMask(ii,gmask[ii]);
571 gGlobalFileVersion++;
573 // don't change the file version ("-x.dat")
575 gTriggerIO.WriteGlobalConfig(gGlobalFileName,gGlobalMasks);
577 // write last current file
578 WriteLastCurrentFile(gCurrentFileName);
580 status = daqDA_DB_storeFile(gGlobalFileName.Data(), gGlobalFileName.Data());
582 printf("Failed to export file to DB: %s\n",gGlobalFileName.Data());
586 status = daqDA_DB_storeFile(gCurrentFileName.Data(), gCurrentFileName.Data());
588 printf("Failed to export file to DB: %s\n",gCurrentFileName.Data());
596 //______________________________________________________________
597 void WriteConfigToDB()
599 // offline: populate db with initial configuration files
600 // only the global configuration and the current file, for the moment ...
601 //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
605 status = daqDA_DB_storeFile(gCurrentFileName.Data(), gCurrentFileName.Data());
607 printf("Failed to export file to DB: %s\n",gCurrentFileName.Data());
611 status = daqDA_DB_storeFile(gGlobalFileName.Data(), gGlobalFileName.Data());
613 printf("Failed to export file to DB: %s\n",gGlobalFileName.Data());
617 status = daqDA_DB_storeFile(gRegionalFileName.Data(), gRegionalFileName.Data());
619 printf("Failed to export file to DB: %s\n",gRegionalFileName.Data());
623 status = daqDA_DB_storeFile(gLocalMaskFileName.Data(), gLocalMaskFileName.Data());
625 printf("Failed to export file to DB: %s\n",gLocalMaskFileName.Data());
630 // Error : mysqlsel/db server:
631 // Got a packet bigger than 'max_allowed_packet' bytes
633 status = daqDA_DB_storeFile(gLocalLutFileName.Data(), gLocalLutFileName.Data());
635 printf("Failed to export file to DB: %s\n",gLocalLutFileName.Data());
639 printf("Initial configuration files written to the DB\n");
643 //*************************************************************//
646 int main(Int_t argc, Char_t **argv)
649 // needed for streamer application
650 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo",
651 "RIO", "TStreamerInfo()");
653 Int_t skipEvents = 0;
654 Int_t maxEvents = 1000000;
655 Char_t inputFile[256];
659 strncpy(inputFile, argv[1], 256);
661 printf("MUONTRGda : No input File !\n");
664 TString flatOutputFile;
668 // decode the input line
669 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
674 if (arg[0] != '-') continue;
679 sprintf(inputFile,argv[i]);
683 gkThreshold = atof(argv[i]);
687 gPrintLevel=atoi(argv[i]);
691 skipEvents=atoi(argv[i]);
695 sscanf(argv[i],"%d",&maxEvents);
699 gWriteInitialDB=atoi(argv[i]);
703 printf("\n******************* %s usage **********************",argv[0]);
704 printf("\n%s -options, the available options are :",argv[0]);
705 printf("\n-h help (this screen)");
708 printf("\n-f <raw data file> (default = %s)",inputFile);
712 printf("\n Options");
713 printf("\n-t <threshold values> (default = %3.1f)",gkThreshold);
714 printf("\n-d <print level> (default = %d)",gPrintLevel);
715 printf("\n-s <skip events> (default = %d)",skipEvents);
716 printf("\n-n <max events> (default = %d)",maxEvents);
717 printf("\n-b <write config in data base> (0/1 default = %1d)",gWriteInitialDB);
722 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
723 argc = 2; exit(-1); // exit if error
727 // decoding the events
730 Int_t nDateEvents = 0;
735 AliMUONDDLTrigger* ddlTrigger = 0x0;
736 AliMUONDarcHeader* darcHeader = 0x0;
742 // comment out, since we do not retrieve files from database
743 if (!ImportFiles()) {
744 printf("Import from DB failed\n");
745 printf("For local test set DAQDA_TEST_DIR to the local directory where the Mtg files are located \n");
752 printf("ExportFiles failed\n");
756 if (gWriteInitialDB) {
761 // FET is triggered by CTP
762 if (GetFetMode() != 3) {
763 printf("FET is not in mode 3\n");
767 // All 5 global cards are controlled by the Mts proxy
768 if (gGlobalMasks->GetGlobalCrateEnable() != 0x1F) {
769 printf("The MTS proxy does not control all global cards\n");
773 // The global cards are ON (active on the global inputs)
774 if (!gGlobalMasks->GetMasksOn()) {
775 printf("Global masks are not ON\n");
779 // make sure to catch the "rare" calib events (1 every 50s in physics)
780 const Char_t* tableSOD[] = {"ALL", "yes", "CAL", "all", NULL, NULL};
781 monitorDeclareTable(const_cast<char**>(tableSOD));
783 status = monitorSetDataSource(inputFile);
785 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
786 << " " << monitorDecodeError(status) << endl;
789 status = monitorDeclareMp("MUON Trigger monitoring");
791 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
792 << " " << monitorDecodeError(status) << endl;
796 /* define wait event timeout - 1s max */
798 monitorSetNoWaitNetworkTimeout(1000);
800 cout << "MUONTRGda : Reading data from file " << inputFile <<endl;
803 Bool_t doUpdate = false;
806 if (gNEvents >= maxEvents) break;
807 if (gNEvents && gNEvents % 100 == 0)
808 cout<<"Cumulated events " << gNEvents << endl;
810 // check shutdown condition
811 if (daqDA_checkShutdown())
814 // Skip Events if needed
816 status = monitorGetEventDynamic(&event);
821 status = monitorGetEventDynamic(&event);
823 cout << "MUONTRGda : EOF found" << endl;
829 // decoding rawdata headers
830 AliRawReader *rawReader = new AliRawReaderDate(event);
832 Int_t eventType = rawReader->GetType();
833 gRunNumber = rawReader->GetRunNumber();
837 // SYSTEM_SOFTWARE_TRIGGER_EVENT
838 // DETECTOR_SOFTWARE_TRIGGER_EVENT
839 gAlgoNoisyInput = false;
840 gAlgoDeadInput = false;
841 if (eventType == PHYSICS_EVENT) {
842 gAlgoNoisyInput = true;
845 } else if (eventType == CALIBRATION_EVENT) {
846 gAlgoDeadInput = true;
849 if (gRunNumber == 61963) { // FET overwrite, not used for dead channels
850 gAlgoNoisyInput = true;
852 gAlgoDeadInput = false;
860 if (gPrintLevel) printf("\nEvent # %d\n",gNEvents);
862 // decoding MUON payload
863 AliMUONRawStreamTrigger* rawStream = new AliMUONRawStreamTrigger(rawReader);
864 //rawStream->SetMaxReg(1);
867 while((status = rawStream->NextDDL())) {
869 if (gPrintLevel) printf("iDDL %d\n", rawStream->GetDDL());
871 ddlTrigger = rawStream->GetDDLTrigger();
872 darcHeader = ddlTrigger->GetDarcHeader();
874 if (rawStream->GetDDL() == 0) {
875 if (gPrintLevel) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
876 globalInput = darcHeader->GetGlobalInput();
877 StoreGlobalInput(globalInput);
887 // update configuration files ifrequested event types were found
888 if (doUpdate && gDAFlag)
893 cout << "MUONTRGda : Run number : " << gRunNumber << endl;
894 cout << "MUONTRGda : Nb of DATE events = " << nDateEvents << endl;
895 cout << "MUONTRGda : Nb of events used = " << gNEvents << endl;
896 cout << "MUONTRGda : Nb of events used (noise) = " << gNEventsN << endl;
897 cout << "MUONTRGda : Nb of events used (deadc) = " << gNEventsD << endl;
899 printf("Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
902 delete gRegionalMasks;