3 Version 2 for MUONTRGda MUON trigger
8 Versionning of the Mtg file
10 DA for ELECTRONICS_CALIBRATION_RUN (calib)
11 checking dead channels
13 DA for DETECTOR_CALIBRATION_RUN (ped)
14 checking the noisy channels
16 Interfaced with online database and file exchange server
22 Writing into the online database (need update of daqDAlib)
23 Looking at scalers outputs
34 #include <Riostream.h>
39 #include "AliRawReaderDate.h"
41 #include "AliMpConstants.h"
42 #include "AliMUONRawStreamTrigger.h"
43 #include "AliMUONDarcHeader.h"
44 #include "AliMUONRegHeader.h"
45 #include "AliMUONLocalStruct.h"
46 #include "AliMUONDDLTrigger.h"
47 #include "AliMUONVCalibParam.h"
48 #include "AliMUONVStore.h"
49 #include "AliMUONCalibParamND.h"
50 #include "AliMUONCalibParamNI.h"
51 #include "AliMUON1DArray.h"
52 #include "AliMUONTriggerIO.h"
53 #include "AliMUONRegionalTriggerConfig.h"
54 #include "AliMUONGlobalCrateConfig.h"
55 #include "AliMUONTriggerCrateConfig.h"
60 #include "TStopwatch.h"
62 #include "TTimeStamp.h"
64 #include "TPluginManager.h"
71 const Int_t gkNLocalBoard = AliMpConstants::TotalNofLocalBoards();
75 TString gCurrentFileName("MtgCurrent.dat");
76 TString gLastCurrentFileName("MtgLastCurrent.dat");
84 TString gGlobalFileName;
85 TString gRegionalFileName;
86 TString gLocalMaskFileName;
87 TString gLocalLutFileName;
88 TString gSignatureFileName;
90 Int_t gGlobalFileVersion;
91 Int_t gRegionalFileVersion;
92 Int_t gLocalMaskFileVersion;
93 Int_t gLocalLutFileVersion;
94 Int_t gSignatureFileVersion;
96 Int_t gGlobalFileLastVersion;
97 Int_t gRegionalFileLastVersion;
98 Int_t gLocalMaskFileLastVersion;
99 Int_t gLocalLutFileLastVersion;
101 UInt_t gRunNumber = 0;
104 Int_t gPrintLevel = 0;
106 AliMUONVStore* gLocalMasks = 0x0;
107 AliMUONRegionalTriggerConfig* gRegionalMasks = 0x0;
108 AliMUONGlobalCrateConfig* gGlobalMasks = 0x0;
111 AliMUONTriggerIO gTriggerIO;
113 AliMUONVStore* gPatternStore = new AliMUON1DArray(gkNLocalBoard);
115 Char_t gHistoFileName[256];
117 Float_t gkThreshold = 0.2;
119 //__________________________________________________________________
120 void UpdateLocalMask(Int_t localBoardId, Int_t connector, Int_t strip)
124 AliMUONVCalibParam* localMask =
125 static_cast<AliMUONVCalibParam*>(gLocalMasks->FindObject(localBoardId));
127 UShort_t mask = localMask->ValueAsInt(connector,0);
129 mask ^= (0x1 << strip); // set strip mask to zero
131 localMask->SetValueAsInt(connector,0, mask);
134 //__________________________________________________________________
135 void WriteLastCurrentFile(TString currentFile = gLastCurrentFileName)
138 // write last current file
142 out.open(file.Data());
143 out << gSodName << " " << gSodFlag << endl;
144 out << gDAName << " " << gDAFlag << endl;
146 out << gGlobalFileName << " " << gGlobalFileVersion << endl;
147 out << gRegionalFileName << " " << gRegionalFileVersion << endl;
148 out << gLocalMaskFileName << " " << gLocalMaskFileVersion << endl;
149 out << gLocalLutFileName << " " << gLocalLutFileVersion << endl;
150 out << gSignatureFileName << " " << gSignatureFileVersion << endl;
155 //___________________________________________________________________________________________
156 Bool_t ReadCurrentFile(TString currentFile = gCurrentFileName, Bool_t lastCurrentFlag = false)
159 // read last current file name and version
165 std::ifstream in(gSystem->ExpandPathName(file.Data()));
167 printf("Cannot open last current file %s\n",currentFile.Data());
174 sscanf(line, "%s %d", name, &gSodFlag);
176 if (gPrintLevel) printf("Sod Flag %d\n", gSodFlag);
180 sscanf(line, "%s %d", name, &gDAFlag);
182 if (gPrintLevel) printf("DA Flag: %d\n", gDAFlag);
188 Int_t pos = tmp.First(" ");
189 gGlobalFileName = tmp(0, pos);
191 if (!lastCurrentFlag) {
192 gGlobalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
193 if (gPrintLevel) printf("Global File Name: %s version: %d\n",
194 gGlobalFileName.Data(), gGlobalFileVersion);
196 gGlobalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
197 if (gPrintLevel) printf("Global File Name: %s last version: %d\n",
198 gGlobalFileName.Data(), gGlobalFileLastVersion);
204 pos = tmp.First(" ");
205 gRegionalFileName = tmp(0, pos);
207 if (!lastCurrentFlag) {
208 gRegionalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
209 if (gPrintLevel) printf("Regional File Name: %s version: %d\n",
210 gRegionalFileName.Data(), gRegionalFileVersion);
213 gRegionalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
214 if (gPrintLevel) printf("Regional File Name: %s last version: %d\n",
215 gRegionalFileName.Data(), gRegionalFileLastVersion);
223 pos = tmp.First(" ");
224 gLocalMaskFileName = tmp(0, pos);
226 if (!lastCurrentFlag) {
227 gLocalMaskFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
228 if (gPrintLevel) printf("Mask File Name: %s version: %d\n",
229 gLocalMaskFileName.Data(), gLocalMaskFileVersion);
231 gLocalMaskFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
232 if (gPrintLevel) printf("Mask File Name: %s last version: %d\n",
233 gLocalMaskFileName.Data(), gLocalMaskFileLastVersion);
238 pos = tmp.First(" ");
239 gLocalLutFileName = tmp(0, pos);
241 if (!lastCurrentFlag) {
242 gLocalLutFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
243 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
244 gLocalLutFileName.Data(), gLocalLutFileVersion);
246 gLocalLutFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
247 if (gPrintLevel) printf("Lut File Name: %s last version: %d\n",
248 gLocalLutFileName.Data(), gLocalLutFileLastVersion);
253 pos = tmp.First(" ");
254 gSignatureFileName = tmp(0, pos);
255 gSignatureFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
256 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
257 gSignatureFileName.Data(), gSignatureFileVersion);
265 // if last current file does not exist than read current file
266 if (!ReadCurrentFile(gLastCurrentFileName, true))
268 ReadCurrentFile(gCurrentFileName, true);
269 WriteLastCurrentFile();
272 // any case read current file
281 // Export files to FES
282 // env variables have to be set (suppose by ECS ?)
283 // setenv DATE_FES_PATH
284 // setenv DATE_RUN_NUMBER
285 // setenv DATE_ROLE_NAME
286 // setenv DATE_DETECTOR_CODE
288 // Export files into the database
289 // setenv DATE_DETECTOR_CODE MTR
290 // setenv DAQDALIB_PATH $ALICE/daqDAlib
291 // setenv DATE_DB_MYSQL_USER det_MTR
292 // setenv DATE_DB_MYSQL_PWD MTR123
293 // setenv DATE_DB_MYSQL_HOST aldaqdb.cern.ch
294 // setenv DATE_DB_MYSQL_DB $DATE_CONFIG
295 // set PATH=$PATH:${DAQDALIB_PATH}
298 // to be sure that env variable is set
299 // gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
300 gSystem->Setenv("DAQDALIB_PATH", "$ALICE/daqDAlib");
301 gSystem->Setenv("DATE_DETECTOR_CODE", "MTR");
302 gSystem->Setenv("DATE_DB_MYSQL_USER", "det_MTR");
303 gSystem->Setenv("DATE_DB_MYSQL_PWD", "MTR123");
304 gSystem->Setenv("DATE_DB_MYSQL_HOST", "aldaqdb.cern.ch");
305 gSystem->Setenv("DATE_DB_MYSQL_DB", "$DATE_CONFIG");
310 Bool_t modified = false;
313 TString fileExp("ExportedFiles.dat");
316 out.open(fileExp.Data());
318 printf("Failed to create file: %s\n",file.Data());
320 } file = gGlobalFileName.Data();
322 if (gGlobalFileLastVersion != gGlobalFileVersion) {
324 status = daqDA_FES_storeFile(file.Data(), file.Data());
326 printf("Failed to export file: %s\n",gGlobalFileName.Data());
329 out << gGlobalFileName.Data() << endl;
330 if(gPrintLevel) printf("Export file: %s\n",gGlobalFileName.Data());
333 if (gLocalMaskFileLastVersion != gLocalMaskFileVersion) {
335 file = gLocalMaskFileName;
337 status = daqDA_FES_storeFile(file.Data(), file.Data());
339 printf("Failed to export file: %s\n",gLocalMaskFileName.Data());
343 status = daqDA_DB_storeFile(file.Data(), file.Data());
345 printf("Failed to export file to DB: %s\n",gLocalMaskFileName.Data());
349 if(gPrintLevel) printf("Export file: %s\n",gLocalMaskFileName.Data());
350 out << gLocalMaskFileName.Data() << endl;
353 if (gLocalLutFileLastVersion != gLocalLutFileVersion) {
354 file = gLocalLutFileName;
356 status = daqDA_FES_storeFile(file.Data(), file.Data());
358 printf("Failed to export file: %s\n",gLocalLutFileName.Data());
361 if(gPrintLevel) printf("Export file: %s\n",gLocalLutFileName.Data());
362 out << gLocalLutFileName.Data() << endl;
366 // exported regional file whenever mask or/and Lut are modified
367 if ( (gRegionalFileLastVersion != gRegionalFileVersion) || modified) {
368 file = gRegionalFileName;
369 status = daqDA_FES_storeFile(file.Data(), file.Data());
371 printf("Failed to export file: %s\n",gRegionalFileName.Data());
374 if(gPrintLevel) printf("Export file: %s\n",gRegionalFileName.Data());
375 out << gRegionalFileName.Data() << endl;
380 // export Exported file to FES anyway
381 status = daqDA_FES_storeFile(fileExp.Data(), fileExp.Data());
383 printf("Failed to export file: %s\n", fileExp.Data());
386 if(gPrintLevel) printf("Export file: %s\n",fileExp.Data());
393 // copy locally a file from daq detector config db
394 // The current detector is identified by detector code in variable
395 // DATE_DETECTOR_CODE. It must be defined.
396 // If environment variable DAQDA_TEST_DIR is defined, files are copied from DAQDA_TEST_DIR
397 // instead of the database. The usual environment variables are not needed.
399 // to be sure that env variable is set
400 // gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
401 gSystem->Setenv("DAQDALIB_PATH", "$ALICE/daqDAlib");
405 status = daqDA_DB_getFile(gCurrentFileName.Data(), gCurrentFileName.Data());
407 printf("Failed to get current config file from DB: %s\n",gCurrentFileName.Data());
413 status = daqDA_DB_getFile(gGlobalFileName.Data(), gGlobalFileName.Data());
415 printf("Failed to get current config file from DB: %s\n", gGlobalFileName.Data());
419 status = daqDA_DB_getFile(gRegionalFileName.Data(), gRegionalFileName.Data());
421 printf("Failed to get current config file from DB: %s\n",gRegionalFileName.Data());
425 status = daqDA_DB_getFile(gLocalMaskFileName.Data(), gLocalMaskFileName.Data());
427 printf("Failed to get current config file from DB: %s\n",gLocalMaskFileName.Data());
431 status = daqDA_DB_getFile(gLocalLutFileName.Data(), gLocalLutFileName.Data());
433 printf("Failed to get current config file from DB: %s\n",gLocalLutFileName.Data());
444 gLocalMasks = new AliMUON1DArray(gkNLocalBoard+9);
445 gRegionalMasks = new AliMUONRegionalTriggerConfig();
446 gGlobalMasks = new AliMUONGlobalCrateConfig();
448 TString localFile = gLocalMaskFileName;
449 TString regionalFile = gRegionalFileName;
450 TString globalFile = gGlobalFileName;
452 gTriggerIO.ReadConfig(localFile.Data(), regionalFile.Data(), globalFile.Data(),
453 gLocalMasks, gRegionalMasks, gGlobalMasks);
456 void MakePattern(Int_t localBoardId, TArrayS& xPattern, TArrayS& yPattern)
459 // calculate the hit map for each strip in x and y direction
460 AliMUONVCalibParam* pat =
461 static_cast<AliMUONVCalibParam*>(gPatternStore->FindObject(localBoardId));
464 pat = new AliMUONCalibParamND(2, 64, localBoardId, 0,0.); // put default wise 0.
465 gPatternStore->Add(pat);
468 for (Int_t i = 0; i < 4; ++i) {
469 for (Int_t j = 0; j < 16; ++j) {
471 Int_t xMask = xPattern[i];
472 Int_t yMask = yPattern[i];
474 Int_t index = 16*i + j;
475 Double_t patOcc = 0.;
477 if ( (xMask >> j ) & 0x1 ) {
478 patOcc = pat->ValueAsDouble(index, 0) + 1.;
479 pat->SetValueAsDouble(index, 0, patOcc);
481 if ( (yMask >> j ) & 0x1 ) {
482 patOcc = pat->ValueAsDouble(index, 0) + 1.;
483 pat->SetValueAsDouble(index, 0, patOcc);
491 void MakePatternStore(Bool_t pedestal = true)
494 // calculates the occupancy (option: store in a root file)
495 // check noisy strip (pedestal true, software trigger)
496 // check dead channel (pesdetal false, FET trigger)
498 Int_t localBoardId = 0;
499 Bool_t updated = false;
506 TH1F* xOccHisto[243];
507 TH1F* yOccHisto[243];
508 TH1F* xPatOccHisto = 0x0;
509 TH1F* yPatOccHisto = 0x0;
511 TFile* histoFile = 0x0;
513 if (gHistoFileName[0] != 0) {
514 histoFile = new TFile(gHistoFileName,"RECREATE","MUON Tracking pedestals");
516 sprintf(name,"pat_x");
517 sprintf(title,"Occupancy for x strip");
521 xPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
522 xPatOccHisto ->SetDirectory(histoFile);
524 sprintf(name,"pat_y");
525 sprintf(title,"Occupancy for y strip");
526 yPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
527 yPatOccHisto->SetDirectory(histoFile);
531 // iterator over pedestal
532 TIter next(gPatternStore->CreateIterator());
533 AliMUONVCalibParam* pat;
535 while ( ( pat = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
537 localBoardId = pat->ID0();
539 if (gHistoFileName[0] != 0) {
545 sprintf(name,"pat_x_%d",localBoardId);
546 sprintf(title,"Occupancy for x strip, board %d",localBoardId);
547 xOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
549 sprintf(name,"pat_y_%d",localBoardId);
550 sprintf(title,"Occupancy for y strip, board %d",localBoardId);
551 yOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
555 for (Int_t index = 0; index < pat->Size() ; ++index) {// 64 bits for X and 64 bits for Y strips
557 Double_t patXOcc = pat->ValueAsDouble(index, 0)/(Double_t)gNEvents;
558 Double_t patYOcc = pat->ValueAsDouble(index, 1)/(Double_t)gNEvents;
560 pat->SetValueAsDouble(index, 0, patXOcc);
561 pat->SetValueAsDouble(index, 1, patYOcc);
565 if ( (patXOcc > gkThreshold && pedestal) || (patXOcc < 1.- gkThreshold && !pedestal) ) {
566 UShort_t strip = index % 16;
567 Int_t connector = index/16;
568 UpdateLocalMask(localBoardId, connector, strip);
573 if ( (patYOcc > gkThreshold && pedestal) || (patYOcc < 1.- gkThreshold && !pedestal) ) {
574 UShort_t strip = index % 16;
575 Int_t connector = index/16 + 4;
576 UpdateLocalMask(localBoardId, connector, strip);
581 if (gHistoFileName[0] != 0) {
582 xPatOccHisto->Fill(patXOcc);
583 yPatOccHisto->Fill(patYOcc);
584 xOccHisto[localBoardId]->Fill(index, patXOcc);
585 yOccHisto[localBoardId]->Fill(index, patYOcc);
591 if (gHistoFileName[0] != 0) {
600 gLocalMaskFileVersion++;
602 TString tmp(gLocalMaskFileName);
603 Int_t pos = tmp.First("-");
604 gLocalMaskFileName = tmp(0,pos+1) + Form("%d",gLocalMaskFileVersion) + ".dat";
606 // write last current file
607 WriteLastCurrentFile();
609 gTriggerIO.WriteConfig(gLocalMaskFileName, gRegionalFileName, gGlobalFileName, gLocalMasks, gRegionalMasks, gGlobalMasks);
613 //*************************************************************//
616 int main(Int_t argc, Char_t **argv)
619 // needed for streamer application
620 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo",
621 "RIO", "TStreamerInfo()");
623 Int_t skipEvents = 0;
624 Int_t maxEvents = 1000000;
625 Char_t inputFile[256];
626 strcpy(inputFile, "");
627 TString flatOutputFile;
631 // decode the input line
632 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
637 if (arg[0] != '-') continue;
642 sprintf(inputFile,argv[i]);
646 gkThreshold = atof(argv[i]);
654 gPrintLevel=atoi(argv[i]);
658 skipEvents=atoi(argv[i]);
662 sscanf(argv[i],"%d",&maxEvents);
666 sscanf(argv[i],"%s",gHistoFileName);
670 printf("\n******************* %s usage **********************",argv[0]);
671 printf("\n%s -options, the available options are :",argv[0]);
672 printf("\n-h help (this screen)");
675 printf("\n-f <raw data file> (default = %s)",inputFile);
678 printf("\n-r <root file> (default = %s)",gHistoFileName);
680 printf("\n Options");
681 printf("\n-t <threshold values> (default = %3.1f)",gkThreshold);
682 printf("\n-d <print level> (default = %d)",gPrintLevel);
683 printf("\n-s <skip events> (default = %d)",skipEvents);
684 printf("\n-n <max events> (default = %d)",maxEvents);
685 printf("\n-e <execute ped/calib> (default = %s)",gCommand.Data());
690 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
691 argc = 2; exit(-1); // exit if error
695 // set command to lower case
698 // decoding the events
701 Int_t nDateEvents = 0;
706 AliMUONDDLTrigger* ddlTrigger = 0x0;
707 AliMUONDarcHeader* darcHeader = 0x0;
708 AliMUONRegHeader* regHeader = 0x0;
709 AliMUONLocalStruct* localStruct = 0x0;
715 // comment out, since we do not retrieve files from database
716 if (!ImportFiles()) {
717 printf("Import from DB failed\n");
718 printf("For local test set DAQDA_TEST_DIR to the local directory where the Mtg files are located \n");
723 if(!ExportFiles()) return -1;
729 status = monitorSetDataSource(inputFile);
731 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
732 << " " << monitorDecodeError(status) << endl;
735 status = monitorDeclareMp("MUON Trigger monitoring");
737 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
738 << " " << monitorDecodeError(status) << endl;
742 cout << "MUONTRKda : Reading data from file " << inputFile <<endl;
746 if (gNEvents >= maxEvents) break;
747 if (gNEvents && gNEvents % 100 == 0)
748 cout<<"Cumulated events " << gNEvents << endl;
750 // check shutdown condition
751 if (daqDA_checkShutdown())
754 // Skip Events if needed
756 status = monitorGetEventDynamic(&event);
761 status = monitorGetEventDynamic(&event);
763 cout<<"EOF found"<<endl;
769 // decoding rawdata headers
770 AliRawReader *rawReader = new AliRawReaderDate(event);
772 Int_t eventType = rawReader->GetType();
773 gRunNumber = rawReader->GetRunNumber();
776 if (eventType != PHYSICS_EVENT)
777 continue; // for the moment
780 if (gPrintLevel) printf("\nEvent # %d\n",gNEvents);
782 // decoding MUON payload
783 AliMUONRawStreamTrigger* rawStream = new AliMUONRawStreamTrigger(rawReader);
784 //rawStream->SetMaxReg(1);
788 while((status = rawStream->NextDDL())) {
790 if (gPrintLevel) printf("iDDL %d\n", rawStream->GetDDL());
792 ddlTrigger = rawStream->GetDDLTrigger();
793 darcHeader = ddlTrigger->GetDarcHeader();
795 if (gPrintLevel) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
797 // loop over regional structures
798 Int_t nReg = darcHeader->GetRegHeaderEntries();
799 for(Int_t iReg = 0; iReg < nReg; ++iReg){ //REG loop
801 if (gPrintLevel) printf("RegionalId %d\n", iReg);
803 regHeader = darcHeader->GetRegHeaderEntry(iReg);
805 // loop over local structures
806 Int_t nLocal = regHeader->GetLocalEntries();
807 for(Int_t iLocal = 0; iLocal < nLocal; ++iLocal) {
809 localStruct = regHeader->GetLocalEntry(iLocal);
811 Int_t localBoardId = gTriggerIO.LocalBoardId(index++);
812 if (gPrintLevel) printf("local %d\n", localBoardId );
816 localStruct->GetXPattern(xPattern);
817 localStruct->GetYPattern(yPattern);
818 MakePattern(localBoardId, xPattern, yPattern);
820 if (gPrintLevel) printf("X pattern %x %x %x %x, Y pattern %x %x %x %x\n",
821 localStruct->GetX1(), localStruct->GetX2(),localStruct->GetX3(),localStruct->GetX4(),
822 localStruct->GetY1(), localStruct->GetY2(),localStruct->GetY3(),localStruct->GetY4());
833 if (gCommand.Contains("ped"))
836 if (gCommand.Contains("cal"))
837 MakePatternStore(false);
844 cout << "MUONTRGda : Run number : " << gRunNumber << endl;
845 cout << "MUONTRGda : Histo file generated : " << gHistoFileName << endl;
846 cout << "MUONTRGda : Nb of DATE events = " << nDateEvents << endl;
847 cout << "MUONTRGda : Nb of events used = " << gNEvents << endl;
849 printf("Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
852 delete gRegionalMasks;
853 delete gGlobalMasks; // in case
854 delete gPatternStore;