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 "AliMUON1DArray.h"
51 #include "AliMUONTriggerIO.h"
56 #include "TStopwatch.h"
58 #include "TTimeStamp.h"
60 #include "TPluginManager.h"
67 const Int_t gkNLocalBoard = AliMpConstants::NofLocalBoards();
69 TString gCommand("ped");
71 TString gCurrentFileName("MtgCurrent.dat");
72 TString gLastCurrentFileName("MtgLastCurrent.dat");
80 TString gGlobalFileName;
81 TString gRegionalFileName;
82 TString gLocalMaskFileName;
83 TString gLocalLutFileName;
84 TString gSignatureFileName;
86 Int_t gGlobalFileVersion;
87 Int_t gRegionalFileVersion;
88 Int_t gLocalMaskFileVersion;
89 Int_t gLocalLutFileVersion;
90 Int_t gSignatureFileVersion;
92 Int_t gGlobalFileLastVersion;
93 Int_t gRegionalFileLastVersion;
94 Int_t gLocalMaskFileLastVersion;
95 Int_t gLocalLutFileLastVersion;
97 UInt_t gRunNumber = 0;
100 Int_t gPrintLevel = 0;
102 AliMUONVStore* gLocalMasks = 0x0;
103 AliMUONVStore* gRegionalMasks = 0x0;
104 AliMUONVCalibParam* globalMasks = 0x0;
106 AliMUONTriggerIO gTriggerIO;
108 AliMUONVStore* gPatternStore = new AliMUON1DArray(gkNLocalBoard+9);
110 Char_t gHistoFileName[256];
112 Float_t gkThreshold = 0.8;
114 //__________________________________________________________________
115 void UpdateLocalMask(Int_t localBoardId, Int_t connector, Int_t strip)
119 AliMUONVCalibParam* localMask =
120 static_cast<AliMUONVCalibParam*>(gLocalMasks->FindObject(localBoardId));
122 UShort_t mask = localMask->ValueAsInt(connector,0);
124 mask ^= (0x1 << strip); // set strip mask to zero
126 localMask->SetValueAsInt(connector,0, mask);
129 //__________________________________________________________________
130 void WriteLastCurrentFile(TString currentFile = gLastCurrentFileName)
133 // write last current file
137 out.open(file.Data());
138 out << gSodName << " " << gSodFlag << endl;
139 out << gDAName << " " << gDAFlag << endl;
141 out << gGlobalFileName << " " << gGlobalFileVersion << endl;
142 out << gRegionalFileName << " " << gRegionalFileVersion << endl;
143 out << gLocalMaskFileName << " " << gLocalMaskFileVersion << endl;
144 out << gLocalLutFileName << " " << gLocalLutFileVersion << endl;
145 out << gSignatureFileName << " " << gSignatureFileVersion << endl;
150 //___________________________________________________________________________________________
151 Bool_t ReadCurrentFile(TString currentFile = gCurrentFileName, Bool_t lastCurrentFlag = false)
154 // read last current file name and version
160 std::ifstream in(gSystem->ExpandPathName(file.Data()));
162 printf("Cannot open last current file %s\n",currentFile.Data());
169 sscanf(line, "%s %d", name, &gSodFlag);
171 if (gPrintLevel) printf("Sod Flag %d\n", gSodFlag);
175 sscanf(line, "%s %d", name, &gDAFlag);
177 if (gPrintLevel) printf("DA Flag: %d\n", gDAFlag);
183 Int_t pos = tmp.First(" ");
184 gGlobalFileName = tmp(0, pos);
186 if (!lastCurrentFlag) {
187 gGlobalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
188 if (gPrintLevel) printf("Global File Name: %s version: %d\n",
189 gGlobalFileName.Data(), gGlobalFileVersion);
191 gGlobalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
192 if (gPrintLevel) printf("Global File Name: %s last version: %d\n",
193 gGlobalFileName.Data(), gGlobalFileLastVersion);
199 pos = tmp.First(" ");
200 gRegionalFileName = tmp(0, pos);
202 if (!lastCurrentFlag) {
203 gRegionalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
204 if (gPrintLevel) printf("Regional File Name: %s version: %d\n",
205 gRegionalFileName.Data(), gRegionalFileVersion);
208 gRegionalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
209 if (gPrintLevel) printf("Regional File Name: %s last version: %d\n",
210 gRegionalFileName.Data(), gRegionalFileLastVersion);
218 pos = tmp.First(" ");
219 gLocalMaskFileName = tmp(0, pos);
221 if (!lastCurrentFlag) {
222 gLocalMaskFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
223 if (gPrintLevel) printf("Mask File Name: %s version: %d\n",
224 gLocalMaskFileName.Data(), gLocalMaskFileVersion);
226 gLocalMaskFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
227 if (gPrintLevel) printf("Mask File Name: %s last version: %d\n",
228 gLocalMaskFileName.Data(), gLocalMaskFileLastVersion);
233 pos = tmp.First(" ");
234 gLocalLutFileName = tmp(0, pos);
236 if (!lastCurrentFlag) {
237 gLocalLutFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
238 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
239 gLocalLutFileName.Data(), gLocalLutFileVersion);
241 gLocalLutFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
242 if (gPrintLevel) printf("Lut File Name: %s last version: %d\n",
243 gLocalLutFileName.Data(), gLocalLutFileLastVersion);
248 pos = tmp.First(" ");
249 gSignatureFileName = tmp(0, pos);
250 gSignatureFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
251 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
252 gSignatureFileName.Data(), gSignatureFileVersion);
260 // if last current file does not exist than read current file
261 if (!ReadCurrentFile(gLastCurrentFileName, true))
263 ReadCurrentFile(gCurrentFileName, true);
264 WriteLastCurrentFile();
267 // any case read current file
276 // Export files to FES
277 // Export files to DB not yet done, waiting for a version > 1.2 of daqDAlib
278 // env variables have to be set (suppose by ECS ?)
279 // setenv DATE_FES_PATH
280 // setenv DATE_RUN_NUMBER
281 // setenv DATE_ROLE_NAME
282 // setenv DATE_DETECTOR_CODE
284 // to be sure that env variable is set
285 gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
290 Bool_t modified = false;
293 TString fileExp("ExportedFiles.dat");
296 out.open(fileExp.Data());
298 printf("Failed to create file: %s\n",file.Data());
302 if (gGlobalFileLastVersion != gGlobalFileVersion) {
303 file = gGlobalFileName.Data();
304 status = daqDA_FES_storeFile(file.Data(), file.Data());
306 printf("Failed to export file: %s\n",gGlobalFileName.Data());
309 out << gGlobalFileName.Data() << endl;
310 if(gPrintLevel) printf("Export file: %s\n",gGlobalFileName.Data());
313 if (gLocalMaskFileLastVersion != gLocalMaskFileVersion) {
315 file = gLocalMaskFileName;
316 status = daqDA_FES_storeFile(file.Data(), file.Data());
318 printf("Failed to export file: %s\n",gLocalMaskFileName.Data());
321 if(gPrintLevel) printf("Export file: %s\n",gLocalMaskFileName.Data());
322 out << gLocalMaskFileName.Data() << endl;
325 if (gLocalLutFileLastVersion != gLocalLutFileVersion) {
326 file = gLocalLutFileName;
328 status = daqDA_FES_storeFile(file.Data(), file.Data());
330 printf("Failed to export file: %s\n",gLocalLutFileName.Data());
333 if(gPrintLevel) printf("Export file: %s\n",gLocalLutFileName.Data());
334 out << gLocalLutFileName.Data() << endl;
338 // exported regional file whenever mask or/and Lut are modified
339 if ( (gRegionalFileLastVersion != gRegionalFileVersion) || modified) {
340 file = gRegionalFileName;
341 status = daqDA_FES_storeFile(file.Data(), file.Data());
343 printf("Failed to export file: %s\n",gRegionalFileName.Data());
346 if(gPrintLevel) printf("Export file: %s\n",gRegionalFileName.Data());
347 out << gRegionalFileName.Data() << endl;
352 // export Exported file to FES anyway
353 status = daqDA_FES_storeFile(fileExp.Data(), fileExp.Data());
355 printf("Failed to export file: %s\n", fileExp.Data());
358 if(gPrintLevel) printf("Export file: %s\n",fileExp.Data());
365 // copy locally a file from daq detector config db
366 // The current detector is identified by detector code in variable
367 // DATE_DETECTOR_CODE. It must be defined.
368 // If environment variable DAQDA_TEST_DIR is defined, files are copied from DAQDA_TEST_DIR
369 // instead of the database. The usual environment variables are not needed.
371 // to be sure that env variable is set
372 gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
376 status = daqDA_DB_getFile(gCurrentFileName.Data(), gCurrentFileName.Data());
378 printf("Failed to get current config file from DB: %s\n",gCurrentFileName.Data());
384 status = daqDA_DB_getFile(gGlobalFileName.Data(), gGlobalFileName.Data());
386 printf("Failed to get current config file from DB: %s\n", gGlobalFileName.Data());
390 status = daqDA_DB_getFile(gRegionalFileName.Data(), gRegionalFileName.Data());
392 printf("Failed to get current config file from DB: %s\n",gRegionalFileName.Data());
396 status = daqDA_DB_getFile(gLocalMaskFileName.Data(), gLocalMaskFileName.Data());
398 printf("Failed to get current config file from DB: %s\n",gLocalMaskFileName.Data());
402 status = daqDA_DB_getFile(gLocalLutFileName.Data(), gLocalLutFileName.Data());
404 printf("Failed to get current config file from DB: %s\n",gLocalLutFileName.Data());
415 gLocalMasks = new AliMUON1DArray(gkNLocalBoard+9);
416 gRegionalMasks = new AliMUON1DArray(16);
419 TString localFile = gLocalMaskFileName;
420 TString regionalFile = gRegionalFileName;
421 TString globalFile = gGlobalFileName;
423 gTriggerIO.ReadMasks(localFile.Data(), regionalFile.Data(), globalFile.Data(),
424 gLocalMasks, gRegionalMasks, globalMasks, false);
427 void MakePattern(Int_t localBoardId, TArrayS& xPattern, TArrayS& yPattern)
430 // calculate the hit map for each strip in x and y direction
431 AliMUONVCalibParam* pat =
432 static_cast<AliMUONVCalibParam*>(gPatternStore->FindObject(localBoardId));
435 pat = new AliMUONCalibParamND(2, 64, localBoardId, 0,0.); // put default wise 0.
436 gPatternStore->Add(pat);
439 for (Int_t i = 0; i < 4; ++i) {
440 for (Int_t j = 0; j < 16; ++j) {
442 Int_t xMask = xPattern[i];
443 Int_t yMask = yPattern[i];
445 Int_t index = 16*i + j;
446 Double_t patOcc = 0.;
448 if ( (xMask >> j ) & 0x1 ) {
449 patOcc = pat->ValueAsDouble(index, 0) + 1.;
450 pat->SetValueAsDouble(index, 0, patOcc);
452 if ( (yMask >> j ) & 0x1 ) {
453 patOcc = pat->ValueAsDouble(index, 0) + 1.;
454 pat->SetValueAsDouble(index, 0, patOcc);
462 void MakePatternStore(Bool_t pedestal = true)
465 // calculates the occupancy (option: store in a root file)
466 // check noisy strip (pedestal true, software trigger)
467 // check dead channel (pesdetal false, FET trigger)
469 Int_t localBoardId = 0;
470 Bool_t updated = false;
477 TH1F* xOccHisto[243];
478 TH1F* yOccHisto[243];
479 TH1F* xPatOccHisto = 0x0;
480 TH1F* yPatOccHisto = 0x0;
482 TFile* histoFile = 0x0;
484 if (gHistoFileName[0] != 0) {
485 histoFile = new TFile(gHistoFileName,"RECREATE","MUON Tracking pedestals");
487 sprintf(name,"pat_x");
488 sprintf(title,"Occupancy for x strip");
492 xPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
493 xPatOccHisto ->SetDirectory(histoFile);
495 sprintf(name,"pat_y");
496 sprintf(title,"Occupancy for y strip");
497 yPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
498 yPatOccHisto->SetDirectory(histoFile);
502 // iterator over pedestal
503 TIter next(gPatternStore->CreateIterator());
504 AliMUONVCalibParam* pat;
506 while ( ( pat = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
508 localBoardId = pat->ID0();
510 if (gHistoFileName[0] != 0) {
516 sprintf(name,"pat_x_%d",localBoardId);
517 sprintf(title,"Occupancy for x strip, board %d",localBoardId);
518 xOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
520 sprintf(name,"pat_y_%d",localBoardId);
521 sprintf(title,"Occupancy for y strip, board %d",localBoardId);
522 yOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
526 for (Int_t index = 0; index < pat->Size() ; ++index) {// 64 bits for X and 64 bits for Y strips
528 Double_t patXOcc = pat->ValueAsDouble(index, 0)/(Double_t)gNEvents;
529 Double_t patYOcc = pat->ValueAsDouble(index, 1)/(Double_t)gNEvents;
531 pat->SetValueAsDouble(index, 0, patXOcc);
532 pat->SetValueAsDouble(index, 1, patYOcc);
536 if ( (patXOcc > gkThreshold && pedestal) || (patXOcc < 1.- gkThreshold && !pedestal) ) {
537 UShort_t strip = index % 16;
538 Int_t connector = index/16;
539 UpdateLocalMask(localBoardId, connector, strip);
544 if ( (patYOcc > gkThreshold && pedestal) || (patYOcc < 1.- gkThreshold && !pedestal) ) {
545 UShort_t strip = index % 16;
546 Int_t connector = index/16 + 4;
547 UpdateLocalMask(localBoardId, connector, strip);
552 if (gHistoFileName[0] != 0) {
553 xPatOccHisto->Fill(patXOcc);
554 yPatOccHisto->Fill(patYOcc);
555 xOccHisto[localBoardId]->Fill(index, patXOcc);
556 yOccHisto[localBoardId]->Fill(index, patYOcc);
562 if (gHistoFileName[0] != 0) {
571 gLocalMaskFileVersion++;
573 TString tmp(gLocalMaskFileName);
574 Int_t pos = tmp.First("-");
575 gLocalMaskFileName = tmp(0,pos+1) + Form("%d",gLocalMaskFileVersion) + ".dat";
577 // write last current file
578 WriteLastCurrentFile();
580 gTriggerIO.WriteMasks(gLocalMaskFileName, gRegionalFileName, " ", gLocalMasks, gRegionalMasks , 0);
585 //*************************************************************//
588 int main(Int_t argc, Char_t **argv)
591 // needed for streamer application
592 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo",
593 "RIO", "TStreamerInfo()");
595 Int_t skipEvents = 0;
596 Int_t maxEvents = 1000000;
597 Char_t inputFile[256];
598 TString flatOutputFile;
603 // decode the input line
604 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
609 if (arg[0] != '-') continue;
614 sprintf(inputFile,argv[i]);
618 configFile = argv[i];
626 gPrintLevel=atoi(argv[i]);
630 skipEvents=atoi(argv[i]);
634 sscanf(argv[i],"%d",&maxEvents);
638 sscanf(argv[i],"%s",gHistoFileName);
642 printf("\n******************* %s usage **********************",argv[0]);
643 printf("\n%s -options, the available options are :",argv[0]);
644 printf("\n-h help (this screen)");
647 printf("\n-f <raw data file> (default = %s)",inputFile);
650 printf("\n-r <root file> (default = %s)",gHistoFileName);
652 printf("\n Options");
653 printf("\n-d <print level> (default = %d)",gPrintLevel);
654 printf("\n-s <skip events> (default = %d)",skipEvents);
655 printf("\n-n <max events> (default = %d)",maxEvents);
656 printf("\n-e <execute ped/calib> (default = %s)",gCommand.Data());
661 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
662 argc = 2; exit(-1); // exit if error
666 // set command to lower case
669 // decoding the events
672 Int_t nDateEvents = 0;
677 AliMUONDDLTrigger* ddlTrigger = 0x0;
678 AliMUONDarcHeader* darcHeader = 0x0;
679 AliMUONRegHeader* regHeader = 0x0;
680 AliMUONLocalStruct* localStruct = 0x0;
686 // comment out, since we do not retrieve files from database
687 if (!ImportFiles()) {
688 printf("Import from DB failed\n");
689 printf("For local test set DAQDA_TEST_DIR to the local directory where the Mtg files are located \n");
694 if(!ExportFiles()) return -1;
700 status = monitorSetDataSource(inputFile);
702 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
703 << " " << monitorDecodeError(status) << endl;
706 status = monitorDeclareMp("MUON Trigger monitoring");
708 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
709 << " " << monitorDecodeError(status) << endl;
713 cout << "MUONTRKda : Reading data from file " << inputFile <<endl;
717 if (gNEvents >= maxEvents) break;
718 if (gNEvents && gNEvents % 100 == 0)
719 cout<<"Cumulated events " << gNEvents << endl;
721 // check shutdown condition
722 if (daqDA_checkShutdown())
725 // Skip Events if needed
727 status = monitorGetEventDynamic(&event);
732 status = monitorGetEventDynamic(&event);
734 cout<<"EOF found"<<endl;
740 // decoding rawdata headers
741 AliRawReader *rawReader = new AliRawReaderDate(event);
743 Int_t eventType = rawReader->GetType();
744 gRunNumber = rawReader->GetRunNumber();
747 if (eventType != PHYSICS_EVENT)
748 continue; // for the moment
751 if (gPrintLevel) printf("\nEvent # %d\n",gNEvents);
753 // decoding MUON payload
754 AliMUONRawStreamTrigger* rawStream = new AliMUONRawStreamTrigger(rawReader);
755 //rawStream->SetMaxReg(1);
759 while((status = rawStream->NextDDL())) {
761 if (gPrintLevel) printf("iDDL %d\n", rawStream->GetDDL());
763 ddlTrigger = rawStream->GetDDLTrigger();
764 darcHeader = ddlTrigger->GetDarcHeader();
766 if (gPrintLevel) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
768 // loop over regional structures
769 Int_t nReg = darcHeader->GetRegHeaderEntries();
770 for(Int_t iReg = 0; iReg < nReg; ++iReg){ //REG loop
772 if (gPrintLevel) printf("RegionalId %d\n", iReg);
774 regHeader = darcHeader->GetRegHeaderEntry(iReg);
776 // loop over local structures
777 Int_t nLocal = regHeader->GetLocalEntries();
778 for(Int_t iLocal = 0; iLocal < nLocal; ++iLocal) {
780 localStruct = regHeader->GetLocalEntry(iLocal);
782 Int_t localBoardId = gTriggerIO.LocalBoardId(index++);
783 if (gPrintLevel) printf("local %d\n", localBoardId );
787 localStruct->GetXPattern(xPattern);
788 localStruct->GetYPattern(yPattern);
789 MakePattern(localBoardId, xPattern, yPattern);
791 if (gPrintLevel) printf("X pattern %x %x %x %x, Y pattern %x %x %x %x\n",
792 localStruct->GetX1(), localStruct->GetX2(),localStruct->GetX3(),localStruct->GetX4(),
793 localStruct->GetY1(), localStruct->GetY2(),localStruct->GetY3(),localStruct->GetY4());
804 if (gCommand.Contains("ped"))
807 if (gCommand.Contains("cal"))
808 MakePatternStore(false);
815 cout << "MUONTRKda : Run number : " << gRunNumber << endl;
816 cout << "MUONTRKda : Histo file generated : " << gHistoFileName << endl;
817 cout << "MUONTRKda : Nb of DATE events = " << nDateEvents << endl;
818 cout << "MUONTRKda : Nb of events used = " << gNEvents << endl;
820 printf("Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
823 delete gRegionalMasks;
824 delete globalMasks; // in case
825 delete gPatternStore;