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("-");
611 TString sNumber = tmp(pos+1,1);
612 Int_t currentFileNumber = sNumber.Atoi()+1;
614 gLocalMaskFileName = tmp(0,pos+1) + Form("%d",currentFileNumber) + ".dat";
615 gTriggerIO.WriteConfig(gLocalMaskFileName, gRegionalFileName, gGlobalFileName, gLocalMasks, gRegionalMasks, gGlobalMasks);
617 WriteLastCurrentFile(gCurrentFileName);
620 Int_t status = daqDA_DB_storeFile(gLocalMaskFileName.Data(), gLocalMaskFileName.Data());
622 printf("Failed to export file to DB: %s\n",gLocalMaskFileName.Data());
626 status = daqDA_DB_storeFile(gCurrentFileName.Data(), gCurrentFileName.Data());
628 printf("Failed to export file to DB: %s\n",gCurrentFileName.Data());
635 //*************************************************************//
638 int main(Int_t argc, Char_t **argv)
641 // needed for streamer application
642 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo",
643 "RIO", "TStreamerInfo()");
645 Int_t skipEvents = 0;
646 Int_t maxEvents = 1000000;
647 Char_t inputFile[256];
651 strncpy(inputFile, argv[1], 256);
653 printf("MUONTRGda : No input File !\n");
656 TString flatOutputFile;
660 // decode the input line
661 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
666 if (arg[0] != '-') continue;
671 sprintf(inputFile,argv[i]);
675 gkThreshold = atof(argv[i]);
683 gPrintLevel=atoi(argv[i]);
687 skipEvents=atoi(argv[i]);
691 sscanf(argv[i],"%d",&maxEvents);
695 sscanf(argv[i],"%s",gHistoFileName);
699 printf("\n******************* %s usage **********************",argv[0]);
700 printf("\n%s -options, the available options are :",argv[0]);
701 printf("\n-h help (this screen)");
704 printf("\n-f <raw data file> (default = %s)",inputFile);
707 printf("\n-r <root file> (default = %s)",gHistoFileName);
709 printf("\n Options");
710 printf("\n-t <threshold values> (default = %3.1f)",gkThreshold);
711 printf("\n-d <print level> (default = %d)",gPrintLevel);
712 printf("\n-s <skip events> (default = %d)",skipEvents);
713 printf("\n-n <max events> (default = %d)",maxEvents);
714 printf("\n-e <execute ped/calib> (default = %s)",gCommand.Data());
719 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
720 argc = 2; exit(-1); // exit if error
724 // set command to lower case
727 // decoding the events
730 Int_t nDateEvents = 0;
735 AliMUONDDLTrigger* ddlTrigger = 0x0;
736 AliMUONDarcHeader* darcHeader = 0x0;
737 AliMUONRegHeader* regHeader = 0x0;
738 AliMUONLocalStruct* localStruct = 0x0;
744 // comment out, since we do not retrieve files from database
745 if (!ImportFiles()) {
746 printf("Import from DB failed\n");
747 printf("For local test set DAQDA_TEST_DIR to the local directory where the Mtg files are located \n");
757 status = monitorSetDataSource(inputFile);
759 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
760 << " " << monitorDecodeError(status) << endl;
763 status = monitorDeclareMp("MUON Trigger monitoring");
765 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
766 << " " << monitorDecodeError(status) << endl;
770 /* define wait event timeout - 1s max */
772 monitorSetNoWaitNetworkTimeout(1000);
775 cout << "MUONTRGda : Reading data from file " << inputFile <<endl;
779 if (gNEvents >= maxEvents) break;
780 if (gNEvents && gNEvents % 100 == 0)
781 cout<<"Cumulated events " << gNEvents << endl;
783 // check shutdown condition
784 if (daqDA_checkShutdown())
787 // Skip Events if needed
789 status = monitorGetEventDynamic(&event);
794 status = monitorGetEventDynamic(&event);
796 cout << "MUONTRGda : EOF found" << endl;
802 // decoding rawdata headers
803 AliRawReader *rawReader = new AliRawReaderDate(event);
805 Int_t eventType = rawReader->GetType();
806 gRunNumber = rawReader->GetRunNumber();
810 // SYSTEM_SOFTWARE_TRIGGER_EVENT
811 // DETECTOR_SOFTWARE_TRIGGER_EVENT
812 if (eventType != PHYSICS_EVENT)
813 continue; // for the moment
816 if (gPrintLevel) printf("\nEvent # %d\n",gNEvents);
818 // decoding MUON payload
819 AliMUONRawStreamTrigger* rawStream = new AliMUONRawStreamTrigger(rawReader);
820 //rawStream->SetMaxReg(1);
823 while((status = rawStream->NextDDL())) {
825 if (gPrintLevel) printf("iDDL %d\n", rawStream->GetDDL());
827 ddlTrigger = rawStream->GetDDLTrigger();
828 darcHeader = ddlTrigger->GetDarcHeader();
830 if (gPrintLevel) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
832 // loop over regional structures
833 Int_t nReg = darcHeader->GetRegHeaderEntries();
834 for(Int_t iReg = 0; iReg < nReg; ++iReg){ //REG loop
836 if (gPrintLevel) printf("RegionalId %d\n", iReg);
838 regHeader = darcHeader->GetRegHeaderEntry(iReg);
840 // loop over local structures
841 Int_t nLocal = regHeader->GetLocalEntries();
842 for(Int_t iLocal = 0; iLocal < nLocal; ++iLocal) {
844 localStruct = regHeader->GetLocalEntry(iLocal);
846 Int_t localBoardId = gTriggerIO.LocalBoardId(rawStream->GetDDL(), iReg, iLocal);
847 if (localBoardId == 0) continue;
848 if (gPrintLevel) printf("local %d\n", localBoardId );
852 localStruct->GetXPattern(xPattern);
853 localStruct->GetYPattern(yPattern);
854 MakePattern(localBoardId, xPattern, yPattern);
856 if (gPrintLevel) printf("X pattern %x %x %x %x, Y pattern %x %x %x %x\n",
857 localStruct->GetX1(), localStruct->GetX2(),localStruct->GetX3(),localStruct->GetX4(),
858 localStruct->GetY1(), localStruct->GetY2(),localStruct->GetY3(),localStruct->GetY4());
869 if (gCommand.Contains("ped") && gDAFlag)
872 if (gCommand.Contains("cal") && gDAFlag)
873 MakePatternStore(false);
878 cout << "MUONTRGda : Run number : " << gRunNumber << endl;
879 cout << "MUONTRGda : Histo file generated : " << gHistoFileName << endl;
880 cout << "MUONTRGda : Nb of DATE events = " << nDateEvents << endl;
881 cout << "MUONTRGda : Nb of events used = " << gNEvents << endl;
883 printf("Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
886 delete gRegionalMasks;
888 delete gPatternStore;