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"
57 #include "TStopwatch.h"
59 #include "TTimeStamp.h"
61 #include "TPluginManager.h"
68 const Int_t gkNLocalBoard = AliMpConstants::NofLocalBoards();
70 TString gCommand("ped");
72 TString gCurrentFileName("MtgCurrent.dat");
73 TString gLastCurrentFileName("MtgLastCurrent.dat");
81 TString gGlobalFileName;
82 TString gRegionalFileName;
83 TString gLocalMaskFileName;
84 TString gLocalLutFileName;
85 TString gSignatureFileName;
87 Int_t gGlobalFileVersion;
88 Int_t gRegionalFileVersion;
89 Int_t gLocalMaskFileVersion;
90 Int_t gLocalLutFileVersion;
91 Int_t gSignatureFileVersion;
93 Int_t gGlobalFileLastVersion;
94 Int_t gRegionalFileLastVersion;
95 Int_t gLocalMaskFileLastVersion;
96 Int_t gLocalLutFileLastVersion;
98 UInt_t gRunNumber = 0;
101 Int_t gPrintLevel = 0;
103 AliMUONVStore* gLocalMasks = 0x0;
104 AliMUONVStore* gRegionalMasks = 0x0;
105 AliMUONVCalibParam* gGlobalMasks = 0x0;
107 AliMUONTriggerIO gTriggerIO;
109 AliMUONVStore* gPatternStore = new AliMUON1DArray(gkNLocalBoard+9);
111 Char_t gHistoFileName[256];
113 Float_t gkThreshold = 0.2;
115 //__________________________________________________________________
116 void UpdateLocalMask(Int_t localBoardId, Int_t connector, Int_t strip)
120 AliMUONVCalibParam* localMask =
121 static_cast<AliMUONVCalibParam*>(gLocalMasks->FindObject(localBoardId));
123 UShort_t mask = localMask->ValueAsInt(connector,0);
125 mask ^= (0x1 << strip); // set strip mask to zero
127 localMask->SetValueAsInt(connector,0, mask);
130 //__________________________________________________________________
131 void WriteLastCurrentFile(TString currentFile = gLastCurrentFileName)
134 // write last current file
138 out.open(file.Data());
139 out << gSodName << " " << gSodFlag << endl;
140 out << gDAName << " " << gDAFlag << endl;
142 out << gGlobalFileName << " " << gGlobalFileVersion << endl;
143 out << gRegionalFileName << " " << gRegionalFileVersion << endl;
144 out << gLocalMaskFileName << " " << gLocalMaskFileVersion << endl;
145 out << gLocalLutFileName << " " << gLocalLutFileVersion << endl;
146 out << gSignatureFileName << " " << gSignatureFileVersion << endl;
151 //___________________________________________________________________________________________
152 Bool_t ReadCurrentFile(TString currentFile = gCurrentFileName, Bool_t lastCurrentFlag = false)
155 // read last current file name and version
161 std::ifstream in(gSystem->ExpandPathName(file.Data()));
163 printf("Cannot open last current file %s\n",currentFile.Data());
170 sscanf(line, "%s %d", name, &gSodFlag);
172 if (gPrintLevel) printf("Sod Flag %d\n", gSodFlag);
176 sscanf(line, "%s %d", name, &gDAFlag);
178 if (gPrintLevel) printf("DA Flag: %d\n", gDAFlag);
184 Int_t pos = tmp.First(" ");
185 gGlobalFileName = tmp(0, pos);
187 if (!lastCurrentFlag) {
188 gGlobalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
189 if (gPrintLevel) printf("Global File Name: %s version: %d\n",
190 gGlobalFileName.Data(), gGlobalFileVersion);
192 gGlobalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
193 if (gPrintLevel) printf("Global File Name: %s last version: %d\n",
194 gGlobalFileName.Data(), gGlobalFileLastVersion);
200 pos = tmp.First(" ");
201 gRegionalFileName = tmp(0, pos);
203 if (!lastCurrentFlag) {
204 gRegionalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
205 if (gPrintLevel) printf("Regional File Name: %s version: %d\n",
206 gRegionalFileName.Data(), gRegionalFileVersion);
209 gRegionalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
210 if (gPrintLevel) printf("Regional File Name: %s last version: %d\n",
211 gRegionalFileName.Data(), gRegionalFileLastVersion);
219 pos = tmp.First(" ");
220 gLocalMaskFileName = tmp(0, pos);
222 if (!lastCurrentFlag) {
223 gLocalMaskFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
224 if (gPrintLevel) printf("Mask File Name: %s version: %d\n",
225 gLocalMaskFileName.Data(), gLocalMaskFileVersion);
227 gLocalMaskFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
228 if (gPrintLevel) printf("Mask File Name: %s last version: %d\n",
229 gLocalMaskFileName.Data(), gLocalMaskFileLastVersion);
234 pos = tmp.First(" ");
235 gLocalLutFileName = tmp(0, pos);
237 if (!lastCurrentFlag) {
238 gLocalLutFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
239 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
240 gLocalLutFileName.Data(), gLocalLutFileVersion);
242 gLocalLutFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
243 if (gPrintLevel) printf("Lut File Name: %s last version: %d\n",
244 gLocalLutFileName.Data(), gLocalLutFileLastVersion);
249 pos = tmp.First(" ");
250 gSignatureFileName = tmp(0, pos);
251 gSignatureFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
252 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
253 gSignatureFileName.Data(), gSignatureFileVersion);
261 // if last current file does not exist than read current file
262 if (!ReadCurrentFile(gLastCurrentFileName, true))
264 ReadCurrentFile(gCurrentFileName, true);
265 WriteLastCurrentFile();
268 // any case read current file
277 // Export files to FES
278 // Export files to DB not yet done, waiting for a version > 1.2 of daqDAlib
279 // env variables have to be set (suppose by ECS ?)
280 // setenv DATE_FES_PATH
281 // setenv DATE_RUN_NUMBER
282 // setenv DATE_ROLE_NAME
283 // setenv DATE_DETECTOR_CODE
285 // to be sure that env variable is set
286 gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
291 Bool_t modified = false;
294 TString fileExp("ExportedFiles.dat");
297 out.open(fileExp.Data());
299 printf("Failed to create file: %s\n",file.Data());
303 if (gGlobalFileLastVersion != gGlobalFileVersion) {
304 file = gGlobalFileName.Data();
305 status = daqDA_FES_storeFile(file.Data(), file.Data());
307 printf("Failed to export file: %s\n",gGlobalFileName.Data());
310 out << gGlobalFileName.Data() << endl;
311 if(gPrintLevel) printf("Export file: %s\n",gGlobalFileName.Data());
314 if (gLocalMaskFileLastVersion != gLocalMaskFileVersion) {
316 file = gLocalMaskFileName;
317 status = daqDA_FES_storeFile(file.Data(), file.Data());
319 printf("Failed to export file: %s\n",gLocalMaskFileName.Data());
322 if(gPrintLevel) printf("Export file: %s\n",gLocalMaskFileName.Data());
323 out << gLocalMaskFileName.Data() << endl;
326 if (gLocalLutFileLastVersion != gLocalLutFileVersion) {
327 file = gLocalLutFileName;
329 status = daqDA_FES_storeFile(file.Data(), file.Data());
331 printf("Failed to export file: %s\n",gLocalLutFileName.Data());
334 if(gPrintLevel) printf("Export file: %s\n",gLocalLutFileName.Data());
335 out << gLocalLutFileName.Data() << endl;
339 // exported regional file whenever mask or/and Lut are modified
340 if ( (gRegionalFileLastVersion != gRegionalFileVersion) || modified) {
341 file = gRegionalFileName;
342 status = daqDA_FES_storeFile(file.Data(), file.Data());
344 printf("Failed to export file: %s\n",gRegionalFileName.Data());
347 if(gPrintLevel) printf("Export file: %s\n",gRegionalFileName.Data());
348 out << gRegionalFileName.Data() << endl;
353 // export Exported file to FES anyway
354 status = daqDA_FES_storeFile(fileExp.Data(), fileExp.Data());
356 printf("Failed to export file: %s\n", fileExp.Data());
359 if(gPrintLevel) printf("Export file: %s\n",fileExp.Data());
366 // copy locally a file from daq detector config db
367 // The current detector is identified by detector code in variable
368 // DATE_DETECTOR_CODE. It must be defined.
369 // If environment variable DAQDA_TEST_DIR is defined, files are copied from DAQDA_TEST_DIR
370 // instead of the database. The usual environment variables are not needed.
372 // to be sure that env variable is set
373 gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
377 status = daqDA_DB_getFile(gCurrentFileName.Data(), gCurrentFileName.Data());
379 printf("Failed to get current config file from DB: %s\n",gCurrentFileName.Data());
385 status = daqDA_DB_getFile(gGlobalFileName.Data(), gGlobalFileName.Data());
387 printf("Failed to get current config file from DB: %s\n", gGlobalFileName.Data());
391 status = daqDA_DB_getFile(gRegionalFileName.Data(), gRegionalFileName.Data());
393 printf("Failed to get current config file from DB: %s\n",gRegionalFileName.Data());
397 status = daqDA_DB_getFile(gLocalMaskFileName.Data(), gLocalMaskFileName.Data());
399 printf("Failed to get current config file from DB: %s\n",gLocalMaskFileName.Data());
403 status = daqDA_DB_getFile(gLocalLutFileName.Data(), gLocalLutFileName.Data());
405 printf("Failed to get current config file from DB: %s\n",gLocalLutFileName.Data());
416 gLocalMasks = new AliMUON1DArray(gkNLocalBoard+9);
417 gRegionalMasks = new AliMUON1DArray(16);
418 gGlobalMasks = new AliMUONCalibParamNI(1,2,1,0,0);
420 TString localFile = gLocalMaskFileName;
421 TString regionalFile = gRegionalFileName;
422 TString globalFile = gGlobalFileName;
424 gTriggerIO.ReadMasks(localFile.Data(), regionalFile.Data(), globalFile.Data(),
425 gLocalMasks, gRegionalMasks, gGlobalMasks, false);
428 void MakePattern(Int_t localBoardId, TArrayS& xPattern, TArrayS& yPattern)
431 // calculate the hit map for each strip in x and y direction
432 AliMUONVCalibParam* pat =
433 static_cast<AliMUONVCalibParam*>(gPatternStore->FindObject(localBoardId));
436 pat = new AliMUONCalibParamND(2, 64, localBoardId, 0,0.); // put default wise 0.
437 gPatternStore->Add(pat);
440 for (Int_t i = 0; i < 4; ++i) {
441 for (Int_t j = 0; j < 16; ++j) {
443 Int_t xMask = xPattern[i];
444 Int_t yMask = yPattern[i];
446 Int_t index = 16*i + j;
447 Double_t patOcc = 0.;
449 if ( (xMask >> j ) & 0x1 ) {
450 patOcc = pat->ValueAsDouble(index, 0) + 1.;
451 pat->SetValueAsDouble(index, 0, patOcc);
453 if ( (yMask >> j ) & 0x1 ) {
454 patOcc = pat->ValueAsDouble(index, 0) + 1.;
455 pat->SetValueAsDouble(index, 0, patOcc);
463 void MakePatternStore(Bool_t pedestal = true)
466 // calculates the occupancy (option: store in a root file)
467 // check noisy strip (pedestal true, software trigger)
468 // check dead channel (pesdetal false, FET trigger)
470 Int_t localBoardId = 0;
471 Bool_t updated = false;
478 TH1F* xOccHisto[243];
479 TH1F* yOccHisto[243];
480 TH1F* xPatOccHisto = 0x0;
481 TH1F* yPatOccHisto = 0x0;
483 TFile* histoFile = 0x0;
485 if (gHistoFileName[0] != 0) {
486 histoFile = new TFile(gHistoFileName,"RECREATE","MUON Tracking pedestals");
488 sprintf(name,"pat_x");
489 sprintf(title,"Occupancy for x strip");
493 xPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
494 xPatOccHisto ->SetDirectory(histoFile);
496 sprintf(name,"pat_y");
497 sprintf(title,"Occupancy for y strip");
498 yPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
499 yPatOccHisto->SetDirectory(histoFile);
503 // iterator over pedestal
504 TIter next(gPatternStore->CreateIterator());
505 AliMUONVCalibParam* pat;
507 while ( ( pat = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
509 localBoardId = pat->ID0();
511 if (gHistoFileName[0] != 0) {
517 sprintf(name,"pat_x_%d",localBoardId);
518 sprintf(title,"Occupancy for x strip, board %d",localBoardId);
519 xOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
521 sprintf(name,"pat_y_%d",localBoardId);
522 sprintf(title,"Occupancy for y strip, board %d",localBoardId);
523 yOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
527 for (Int_t index = 0; index < pat->Size() ; ++index) {// 64 bits for X and 64 bits for Y strips
529 Double_t patXOcc = pat->ValueAsDouble(index, 0)/(Double_t)gNEvents;
530 Double_t patYOcc = pat->ValueAsDouble(index, 1)/(Double_t)gNEvents;
532 pat->SetValueAsDouble(index, 0, patXOcc);
533 pat->SetValueAsDouble(index, 1, patYOcc);
537 if ( (patXOcc > gkThreshold && pedestal) || (patXOcc < 1.- gkThreshold && !pedestal) ) {
538 UShort_t strip = index % 16;
539 Int_t connector = index/16;
540 UpdateLocalMask(localBoardId, connector, strip);
545 if ( (patYOcc > gkThreshold && pedestal) || (patYOcc < 1.- gkThreshold && !pedestal) ) {
546 UShort_t strip = index % 16;
547 Int_t connector = index/16 + 4;
548 UpdateLocalMask(localBoardId, connector, strip);
553 if (gHistoFileName[0] != 0) {
554 xPatOccHisto->Fill(patXOcc);
555 yPatOccHisto->Fill(patYOcc);
556 xOccHisto[localBoardId]->Fill(index, patXOcc);
557 yOccHisto[localBoardId]->Fill(index, patYOcc);
563 if (gHistoFileName[0] != 0) {
572 gLocalMaskFileVersion++;
574 TString tmp(gLocalMaskFileName);
575 Int_t pos = tmp.First("-");
576 gLocalMaskFileName = tmp(0,pos+1) + Form("%d",gLocalMaskFileVersion) + ".dat";
578 // write last current file
579 WriteLastCurrentFile();
581 gTriggerIO.WriteMasks(gLocalMaskFileName, gRegionalFileName, gGlobalFileName, gLocalMasks, gRegionalMasks, gGlobalMasks);
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;
602 // decode the input line
603 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
608 if (arg[0] != '-') continue;
613 sprintf(inputFile,argv[i]);
617 gkThreshold = atof(argv[i]);
625 gPrintLevel=atoi(argv[i]);
629 skipEvents=atoi(argv[i]);
633 sscanf(argv[i],"%d",&maxEvents);
637 sscanf(argv[i],"%s",gHistoFileName);
641 printf("\n******************* %s usage **********************",argv[0]);
642 printf("\n%s -options, the available options are :",argv[0]);
643 printf("\n-h help (this screen)");
646 printf("\n-f <raw data file> (default = %s)",inputFile);
649 printf("\n-r <root file> (default = %s)",gHistoFileName);
651 printf("\n Options");
652 printf("\n-t <threshold values> (default = %3.1f)",gkThreshold);
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 printf("Options %s disabled", gCommand.Data());
809 // MakePatternStore(false);
816 cout << "MUONTRKda : Run number : " << gRunNumber << endl;
817 cout << "MUONTRKda : Histo file generated : " << gHistoFileName << endl;
818 cout << "MUONTRKda : Nb of DATE events = " << nDateEvents << endl;
819 cout << "MUONTRKda : Nb of events used = " << gNEvents << endl;
821 printf("Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
824 delete gRegionalMasks;
825 delete gGlobalMasks; // in case
826 delete gPatternStore;