4 Contact: Franck Manso <manso@clermont.in2p3.fr>
5 Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_mtrda.html
6 Run Type: ELECTRONICS_CALIBRATION_RUN (calib), DETECTOR_CALIBRATION_RUN (ped)
8 Number of events needed: 100 events for ped and calib
9 Input Files: Rawdata file (DATE format)
11 MtgGlobalCrate-<version>.dat
12 MtgRegionalCrate-<version>.dat
13 MtgLocalMask-<version>.dat
14 MtgLocalLut-<version>.dat
17 Output Files: local dir (not persistent)
24 Version 2 for MUONTRGda MUON trigger
29 Versionning of the Mtg file
31 DA for ELECTRONICS_CALIBRATION_RUN (calib)
32 checking dead channels
34 DA for DETECTOR_CALIBRATION_RUN (ped)
35 checking the noisy channels
37 Interfaced with online database and file exchange server
43 Writing into the online database (need update of daqDAlib)
45 Looking at scalers outputs
55 #include <Riostream.h>
60 #include "AliRawReaderDate.h"
62 #include "AliMpConstants.h"
63 #include "AliMUONRawStreamTrigger.h"
64 #include "AliMUONDarcHeader.h"
65 #include "AliMUONRegHeader.h"
66 #include "AliMUONLocalStruct.h"
67 #include "AliMUONDDLTrigger.h"
68 #include "AliMUONVCalibParam.h"
69 #include "AliMUONVStore.h"
70 #include "AliMUONCalibParamND.h"
71 #include "AliMUONCalibParamNI.h"
72 #include "AliMUON1DArray.h"
73 #include "AliMUONTriggerIO.h"
74 #include "AliMUONRegionalTriggerConfig.h"
75 #include "AliMUONGlobalCrateConfig.h"
76 #include "AliMUONTriggerCrateConfig.h"
81 #include "TStopwatch.h"
83 #include "TTimeStamp.h"
85 #include "TPluginManager.h"
92 const Int_t gkNLocalBoard = AliMpConstants::TotalNofLocalBoards()+1;
94 TString gCommand("ped");
96 TString gCurrentFileName("MtgCurrent.dat");
97 TString gLastCurrentFileName("MtgLastCurrent.dat");
105 TString gGlobalFileName;
106 TString gRegionalFileName;
107 TString gLocalMaskFileName;
108 TString gLocalLutFileName;
109 TString gSignatureFileName;
111 Int_t gGlobalFileVersion;
112 Int_t gRegionalFileVersion;
113 Int_t gLocalMaskFileVersion;
114 Int_t gLocalLutFileVersion;
115 Int_t gSignatureFileVersion;
117 Int_t gGlobalFileLastVersion;
118 Int_t gRegionalFileLastVersion;
119 Int_t gLocalMaskFileLastVersion;
120 Int_t gLocalLutFileLastVersion;
122 UInt_t gRunNumber = 0;
125 Int_t gPrintLevel = 0;
127 AliMUONVStore* gLocalMasks = 0x0;
128 AliMUONRegionalTriggerConfig* gRegionalMasks = 0x0;
129 AliMUONGlobalCrateConfig* gGlobalMasks = 0x0;
132 AliMUONTriggerIO gTriggerIO;
134 AliMUONVStore* gPatternStore = new AliMUON1DArray(gkNLocalBoard);
136 Char_t gHistoFileName[256];
138 Float_t gkThreshold = 0.2;
140 //__________________________________________________________________
141 void UpdateLocalMask(Int_t localBoardId, Int_t connector, Int_t strip)
145 AliMUONVCalibParam* localMask =
146 static_cast<AliMUONVCalibParam*>(gLocalMasks->FindObject(localBoardId));
148 UShort_t mask = localMask->ValueAsInt(connector,0);
150 mask ^= (0x1 << strip); // set strip mask to zero
152 localMask->SetValueAsInt(connector,0, mask);
155 //__________________________________________________________________
156 void WriteLastCurrentFile(TString currentFile = gLastCurrentFileName)
159 // write last current file
163 out.open(file.Data());
164 out << gSodName << " " << gSodFlag << endl;
165 out << gDAName << " " << gDAFlag << endl;
167 out << gGlobalFileName << " " << gGlobalFileVersion << endl;
168 out << gRegionalFileName << " " << gRegionalFileVersion << endl;
169 out << gLocalMaskFileName << " " << gLocalMaskFileVersion << endl;
170 out << gLocalLutFileName << " " << gLocalLutFileVersion << endl;
171 out << gSignatureFileName << " " << gSignatureFileVersion << endl;
176 //___________________________________________________________________________________________
177 Bool_t ReadCurrentFile(TString currentFile = gCurrentFileName, Bool_t lastCurrentFlag = false)
180 // read last current file name and version
186 std::ifstream in(gSystem->ExpandPathName(file.Data()));
188 printf("Cannot open last current file %s\n",currentFile.Data());
195 sscanf(line, "%s %d", name, &gSodFlag);
197 if (gPrintLevel) printf("Sod Flag %d\n", gSodFlag);
201 sscanf(line, "%s %d", name, &gDAFlag);
203 if (gPrintLevel) printf("DA Flag: %d\n", gDAFlag);
209 Int_t pos = tmp.First(" ");
210 gGlobalFileName = tmp(0, pos);
212 if (!lastCurrentFlag) {
213 gGlobalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
214 if (gPrintLevel) printf("Global File Name: %s version: %d\n",
215 gGlobalFileName.Data(), gGlobalFileVersion);
217 gGlobalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
218 if (gPrintLevel) printf("Global File Name: %s last version: %d\n",
219 gGlobalFileName.Data(), gGlobalFileLastVersion);
225 pos = tmp.First(" ");
226 gRegionalFileName = tmp(0, pos);
228 if (!lastCurrentFlag) {
229 gRegionalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
230 if (gPrintLevel) printf("Regional File Name: %s version: %d\n",
231 gRegionalFileName.Data(), gRegionalFileVersion);
234 gRegionalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
235 if (gPrintLevel) printf("Regional File Name: %s last version: %d\n",
236 gRegionalFileName.Data(), gRegionalFileLastVersion);
244 pos = tmp.First(" ");
245 gLocalMaskFileName = tmp(0, pos);
247 if (!lastCurrentFlag) {
248 gLocalMaskFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
249 if (gPrintLevel) printf("Mask File Name: %s version: %d\n",
250 gLocalMaskFileName.Data(), gLocalMaskFileVersion);
252 gLocalMaskFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
253 if (gPrintLevel) printf("Mask File Name: %s last version: %d\n",
254 gLocalMaskFileName.Data(), gLocalMaskFileLastVersion);
259 pos = tmp.First(" ");
260 gLocalLutFileName = tmp(0, pos);
262 if (!lastCurrentFlag) {
263 gLocalLutFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
264 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
265 gLocalLutFileName.Data(), gLocalLutFileVersion);
267 gLocalLutFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
268 if (gPrintLevel) printf("Lut File Name: %s last version: %d\n",
269 gLocalLutFileName.Data(), gLocalLutFileLastVersion);
274 pos = tmp.First(" ");
275 gSignatureFileName = tmp(0, pos);
276 gSignatureFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
277 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
278 gSignatureFileName.Data(), gSignatureFileVersion);
286 // if last current file does not exist than read current file
287 if (!ReadCurrentFile(gLastCurrentFileName, true))
289 ReadCurrentFile(gCurrentFileName, true);
292 // any case read current file
301 // Export files to FES
302 // env variables have to be set (suppose by ECS ?)
303 // setenv DATE_FES_PATH
304 // setenv DATE_RUN_NUMBER
305 // setenv DATE_ROLE_NAME
306 // setenv DATE_DETECTOR_CODE
308 // for offline purposes
309 // gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
314 Bool_t modified = false;
317 TString fileExp("ExportedFiles.dat");
320 out.open(fileExp.Data());
322 printf("Failed to create file: %s\n",file.Data());
326 file = gGlobalFileName.Data();
327 if (gGlobalFileLastVersion != gGlobalFileVersion) {
328 status = daqDA_FES_storeFile(file.Data(), file.Data());
330 printf("Failed to export file: %s\n",gGlobalFileName.Data());
333 out << gGlobalFileName.Data() << endl;
334 if(gPrintLevel) printf("Export file: %s\n",gGlobalFileName.Data());
337 file = gLocalMaskFileName;
338 if (gLocalMaskFileLastVersion != gLocalMaskFileVersion) {
341 status = daqDA_FES_storeFile(file.Data(), file.Data());
343 printf("Failed to export file: %s\n",gLocalMaskFileName.Data());
347 status = daqDA_DB_storeFile(file.Data(), file.Data());
349 printf("Failed to export file to DB: %s\n",gLocalMaskFileName.Data());
353 if(gPrintLevel) printf("Export file: %s\n",gLocalMaskFileName.Data());
354 out << gLocalMaskFileName.Data() << endl;
357 file = gLocalLutFileName;
358 if (gLocalLutFileLastVersion != gLocalLutFileVersion) {
360 status = daqDA_FES_storeFile(file.Data(), file.Data());
362 printf("Failed to export file: %s\n",gLocalLutFileName.Data());
365 if(gPrintLevel) printf("Export file: %s\n",gLocalLutFileName.Data());
366 out << gLocalLutFileName.Data() << endl;
370 // exported regional file whenever mask or/and Lut are modified
371 file = gRegionalFileName;
372 if ( (gRegionalFileLastVersion != gRegionalFileVersion) || modified) {
373 status = daqDA_FES_storeFile(file.Data(), file.Data());
375 printf("Failed to export file: %s\n",gRegionalFileName.Data());
378 if(gPrintLevel) printf("Export file: %s\n",gRegionalFileName.Data());
379 out << gRegionalFileName.Data() << endl;
384 // export Exported file to FES anyway
385 status = daqDA_FES_storeFile(fileExp.Data(), fileExp.Data());
387 printf("Failed to export file: %s\n", fileExp.Data());
390 if(gPrintLevel) printf("Export file: %s\n",fileExp.Data());
392 // write last current file
393 WriteLastCurrentFile();
400 // copy locally a file from daq detector config db
401 // The current detector is identified by detector code in variable
402 // DATE_DETECTOR_CODE. It must be defined.
403 // If environment variable DAQDA_TEST_DIR is defined, files are copied from DAQDA_TEST_DIR
404 // instead of the database. The usual environment variables are not needed.
409 //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
410 //gSystem->Setenv("DAQDA_TEST_DIR", "v3r3data");
412 status = daqDA_DB_getFile(gCurrentFileName.Data(), gCurrentFileName.Data());
414 printf("Failed to get current config file from DB: %s\n",gCurrentFileName.Data());
420 status = daqDA_DB_getFile(gGlobalFileName.Data(), gGlobalFileName.Data());
422 printf("Failed to get current config file from DB: %s\n", gGlobalFileName.Data());
426 status = daqDA_DB_getFile(gRegionalFileName.Data(), gRegionalFileName.Data());
428 printf("Failed to get current config file from DB: %s\n",gRegionalFileName.Data());
432 status = daqDA_DB_getFile(gLocalMaskFileName.Data(), gLocalMaskFileName.Data());
434 printf("Failed to get current config file from DB: %s\n",gLocalMaskFileName.Data());
438 status = daqDA_DB_getFile(gLocalLutFileName.Data(), gLocalLutFileName.Data());
440 printf("Failed to get current config file from DB: %s\n",gLocalLutFileName.Data());
451 gLocalMasks = new AliMUON1DArray(gkNLocalBoard);
452 gRegionalMasks = new AliMUONRegionalTriggerConfig();
453 gGlobalMasks = new AliMUONGlobalCrateConfig();
455 TString localFile = gLocalMaskFileName;
456 TString regionalFile = gRegionalFileName;
457 TString globalFile = gGlobalFileName;
459 gTriggerIO.ReadConfig(localFile.Data(), regionalFile.Data(), globalFile.Data(),
460 gLocalMasks, gRegionalMasks, gGlobalMasks);
463 void MakePattern(Int_t localBoardId, TArrayS& xPattern, TArrayS& yPattern)
466 // calculate the hit map for each strip in x and y direction
467 AliMUONVCalibParam* pat =
468 static_cast<AliMUONVCalibParam*>(gPatternStore->FindObject(localBoardId));
471 pat = new AliMUONCalibParamND(2, 64, localBoardId, 0,0.); // put default wise 0.
472 gPatternStore->Add(pat);
475 for (Int_t i = 0; i < 4; ++i) {
476 for (Int_t j = 0; j < 16; ++j) {
478 Int_t xMask = xPattern[i];
479 Int_t yMask = yPattern[i];
481 Int_t index = 16*i + j;
482 Double_t patOcc = 0.;
484 if ( (xMask >> j ) & 0x1 ) {
485 patOcc = pat->ValueAsDouble(index, 0) + 1.;
486 pat->SetValueAsDouble(index, 0, patOcc);
488 if ( (yMask >> j ) & 0x1 ) {
489 patOcc = pat->ValueAsDouble(index, 0) + 1.;
490 pat->SetValueAsDouble(index, 0, patOcc);
498 void MakePatternStore(Bool_t pedestal = true)
501 // calculates the occupancy (option: store in a root file)
502 // check noisy strip (pedestal true, software trigger)
503 // check dead channel (pesdetal false, FET trigger)
505 Int_t localBoardId = 0;
506 Bool_t updated = false;
513 TH1F* xOccHisto[243];
514 TH1F* yOccHisto[243];
515 TH1F* xPatOccHisto = 0x0;
516 TH1F* yPatOccHisto = 0x0;
518 TFile* histoFile = 0x0;
520 if (gHistoFileName[0] != 0) {
521 histoFile = new TFile(gHistoFileName,"RECREATE","MUON Tracking pedestals");
523 sprintf(name,"pat_x");
524 sprintf(title,"Occupancy for x strip");
528 xPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
529 xPatOccHisto ->SetDirectory(histoFile);
531 sprintf(name,"pat_y");
532 sprintf(title,"Occupancy for y strip");
533 yPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
534 yPatOccHisto->SetDirectory(histoFile);
538 // iterator over pedestal
539 TIter next(gPatternStore->CreateIterator());
540 AliMUONVCalibParam* pat;
542 while ( ( pat = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
544 localBoardId = pat->ID0();
546 if (gHistoFileName[0] != 0) {
552 sprintf(name,"pat_x_%d",localBoardId);
553 sprintf(title,"Occupancy for x strip, board %d",localBoardId);
554 xOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
556 sprintf(name,"pat_y_%d",localBoardId);
557 sprintf(title,"Occupancy for y strip, board %d",localBoardId);
558 yOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
562 for (Int_t index = 0; index < pat->Size() ; ++index) {// 64 bits for X and 64 bits for Y strips
564 Double_t patXOcc = pat->ValueAsDouble(index, 0)/(Double_t)gNEvents;
565 Double_t patYOcc = pat->ValueAsDouble(index, 1)/(Double_t)gNEvents;
567 pat->SetValueAsDouble(index, 0, patXOcc);
568 pat->SetValueAsDouble(index, 1, patYOcc);
572 if ( (patXOcc > gkThreshold && pedestal) || (patXOcc < 1.- gkThreshold && !pedestal) ) {
573 UShort_t strip = index % 16;
574 Int_t connector = index/16;
575 UpdateLocalMask(localBoardId, connector, strip);
580 if ( (patYOcc > gkThreshold && pedestal) || (patYOcc < 1.- gkThreshold && !pedestal) ) {
581 UShort_t strip = index % 16;
582 Int_t connector = index/16 + 4;
583 UpdateLocalMask(localBoardId, connector, strip);
588 if (gHistoFileName[0] != 0) {
589 xPatOccHisto->Fill(patXOcc);
590 yPatOccHisto->Fill(patYOcc);
591 xOccHisto[localBoardId]->Fill(index, patXOcc);
592 yOccHisto[localBoardId]->Fill(index, patYOcc);
598 if (gHistoFileName[0] != 0) {
607 gLocalMaskFileVersion++;
609 TString tmp(gLocalMaskFileName);
610 Int_t pos = tmp.First("-");
612 gLocalMaskFileName = tmp(0,pos+1) + Form("%d",gLocalMaskFileVersion) + ".dat";
613 gTriggerIO.WriteConfig(gLocalMaskFileName, gRegionalFileName,
614 gGlobalFileName, gLocalMasks, gRegionalMasks, gGlobalMasks);
616 WriteLastCurrentFile(gCurrentFileName);
619 Int_t status = daqDA_DB_storeFile(gLocalMaskFileName.Data(), gLocalMaskFileName.Data());
621 printf("Failed to export file to DB: %s\n",gLocalMaskFileName.Data());
625 status = daqDA_DB_storeFile(gCurrentFileName.Data(), gCurrentFileName.Data());
627 printf("Failed to export file to DB: %s\n",gCurrentFileName.Data());
634 //*************************************************************//
637 int main(Int_t argc, Char_t **argv)
640 // needed for streamer application
641 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo",
642 "RIO", "TStreamerInfo()");
644 Int_t skipEvents = 0;
645 Int_t maxEvents = 1000000;
646 Char_t inputFile[256];
650 strncpy(inputFile, argv[1], 256);
652 printf("MUONTRGda : No input File !\n");
655 TString flatOutputFile;
659 // decode the input line
660 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
665 if (arg[0] != '-') continue;
670 sprintf(inputFile,argv[i]);
674 gkThreshold = atof(argv[i]);
682 gPrintLevel=atoi(argv[i]);
686 skipEvents=atoi(argv[i]);
690 sscanf(argv[i],"%d",&maxEvents);
694 sscanf(argv[i],"%s",gHistoFileName);
698 printf("\n******************* %s usage **********************",argv[0]);
699 printf("\n%s -options, the available options are :",argv[0]);
700 printf("\n-h help (this screen)");
703 printf("\n-f <raw data file> (default = %s)",inputFile);
706 printf("\n-r <root file> (default = %s)",gHistoFileName);
708 printf("\n Options");
709 printf("\n-t <threshold values> (default = %3.1f)",gkThreshold);
710 printf("\n-d <print level> (default = %d)",gPrintLevel);
711 printf("\n-s <skip events> (default = %d)",skipEvents);
712 printf("\n-n <max events> (default = %d)",maxEvents);
713 printf("\n-e <execute ped/calib> (default = %s)",gCommand.Data());
718 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
719 argc = 2; exit(-1); // exit if error
723 // set command to lower case
726 // decoding the events
729 Int_t nDateEvents = 0;
734 AliMUONDDLTrigger* ddlTrigger = 0x0;
735 AliMUONDarcHeader* darcHeader = 0x0;
736 AliMUONRegHeader* regHeader = 0x0;
737 AliMUONLocalStruct* localStruct = 0x0;
743 // comment out, since we do not retrieve files from database
744 if (!ImportFiles()) {
745 printf("Import from DB failed\n");
746 printf("For local test set DAQDA_TEST_DIR to the local directory where the Mtg files are located \n");
756 status = monitorSetDataSource(inputFile);
758 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
759 << " " << monitorDecodeError(status) << endl;
762 status = monitorDeclareMp("MUON Trigger monitoring");
764 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
765 << " " << monitorDecodeError(status) << endl;
769 /* define wait event timeout - 1s max */
771 monitorSetNoWaitNetworkTimeout(1000);
774 cout << "MUONTRGda : Reading data from file " << inputFile <<endl;
778 if (gNEvents >= maxEvents) break;
779 if (gNEvents && gNEvents % 100 == 0)
780 cout<<"Cumulated events " << gNEvents << endl;
782 // check shutdown condition
783 if (daqDA_checkShutdown())
786 // Skip Events if needed
788 status = monitorGetEventDynamic(&event);
793 status = monitorGetEventDynamic(&event);
795 cout << "MUONTRGda : EOF found" << endl;
801 // decoding rawdata headers
802 AliRawReader *rawReader = new AliRawReaderDate(event);
804 Int_t eventType = rawReader->GetType();
805 gRunNumber = rawReader->GetRunNumber();
809 // SYSTEM_SOFTWARE_TRIGGER_EVENT
810 // DETECTOR_SOFTWARE_TRIGGER_EVENT
811 if (eventType != PHYSICS_EVENT)
812 continue; // for the moment
815 if (gPrintLevel) printf("\nEvent # %d\n",gNEvents);
817 // decoding MUON payload
818 AliMUONRawStreamTrigger* rawStream = new AliMUONRawStreamTrigger(rawReader);
819 //rawStream->SetMaxReg(1);
822 while((status = rawStream->NextDDL())) {
824 if (gPrintLevel) printf("iDDL %d\n", rawStream->GetDDL());
826 ddlTrigger = rawStream->GetDDLTrigger();
827 darcHeader = ddlTrigger->GetDarcHeader();
829 if (gPrintLevel) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
831 // loop over regional structures
832 Int_t nReg = darcHeader->GetRegHeaderEntries();
833 for(Int_t iReg = 0; iReg < nReg; ++iReg){ //REG loop
835 if (gPrintLevel) printf("RegionalId %d\n", iReg);
837 regHeader = darcHeader->GetRegHeaderEntry(iReg);
839 // loop over local structures
840 Int_t nLocal = regHeader->GetLocalEntries();
841 for(Int_t iLocal = 0; iLocal < nLocal; ++iLocal) {
843 localStruct = regHeader->GetLocalEntry(iLocal);
845 Int_t localBoardId = gTriggerIO.LocalBoardId(rawStream->GetDDL(), iReg, iLocal);
846 if (localBoardId == 0) continue;
847 if (gPrintLevel) printf("local %d\n", localBoardId );
851 localStruct->GetXPattern(xPattern);
852 localStruct->GetYPattern(yPattern);
853 MakePattern(localBoardId, xPattern, yPattern);
855 if (gPrintLevel) printf("X pattern %x %x %x %x, Y pattern %x %x %x %x\n",
856 localStruct->GetX1(), localStruct->GetX2(),localStruct->GetX3(),localStruct->GetX4(),
857 localStruct->GetY1(), localStruct->GetY2(),localStruct->GetY3(),localStruct->GetY4());
868 if (gCommand.Contains("ped") && gDAFlag)
871 if (gCommand.Contains("cal") && gDAFlag)
872 MakePatternStore(false);
877 cout << "MUONTRGda : Run number : " << gRunNumber << endl;
878 cout << "MUONTRGda : Histo file generated : " << gHistoFileName << endl;
879 cout << "MUONTRGda : Nb of DATE events = " << nDateEvents << endl;
880 cout << "MUONTRGda : Nb of events used = " << gNEvents << endl;
882 printf("Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
885 delete gRegionalMasks;
887 delete gPatternStore;