2 Contact: Franck Manso <manso@clermont.in2p3.fr>
3 Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_mtrda.html
4 Run Type: ELECTRONICS_CALIBRATION_RUN (calib), DETECTOR_CALIBRATION_RUN (ped)
6 Number of events needed: 100 events for ped and calib
7 Input Files: Rawdata file (DATE format)
9 MtgGlobalCrate-<version>.dat
10 MtgRegionalCrate-<version>.dat
11 MtgLocalMask-<version>.dat
12 MtgLocalLut-<version>.dat
15 Output Files: local dir (not persistent)
22 Version 2 for MUONTRGda MUON trigger
27 Versionning of the Mtg file
29 DA for ELECTRONICS_CALIBRATION_RUN (calib)
30 checking dead channels
32 DA for DETECTOR_CALIBRATION_RUN (ped)
33 checking the noisy channels
35 Interfaced with online database and file exchange server
41 Writing into the online database (need update of daqDAlib)
43 Looking at scalers outputs
53 #include <Riostream.h>
58 #include "AliRawReaderDate.h"
60 #include "AliMpConstants.h"
61 #include "AliMUONRawStreamTrigger.h"
62 #include "AliMUONDarcHeader.h"
63 #include "AliMUONRegHeader.h"
64 #include "AliMUONLocalStruct.h"
65 #include "AliMUONDDLTrigger.h"
66 #include "AliMUONVCalibParam.h"
67 #include "AliMUONVStore.h"
68 #include "AliMUONCalibParamND.h"
69 #include "AliMUONCalibParamNI.h"
70 #include "AliMUON1DArray.h"
71 #include "AliMUONTriggerIO.h"
72 #include "AliMUONRegionalTriggerConfig.h"
73 #include "AliMUONGlobalCrateConfig.h"
74 #include "AliMUONTriggerCrateConfig.h"
79 #include "TStopwatch.h"
81 #include "TTimeStamp.h"
83 #include "TPluginManager.h"
90 const Int_t gkNLocalBoard = AliMpConstants::TotalNofLocalBoards();
94 TString gCurrentFileName("MtgCurrent.dat");
95 TString gLastCurrentFileName("MtgLastCurrent.dat");
103 TString gGlobalFileName;
104 TString gRegionalFileName;
105 TString gLocalMaskFileName;
106 TString gLocalLutFileName;
107 TString gSignatureFileName;
109 Int_t gGlobalFileVersion;
110 Int_t gRegionalFileVersion;
111 Int_t gLocalMaskFileVersion;
112 Int_t gLocalLutFileVersion;
113 Int_t gSignatureFileVersion;
115 Int_t gGlobalFileLastVersion;
116 Int_t gRegionalFileLastVersion;
117 Int_t gLocalMaskFileLastVersion;
118 Int_t gLocalLutFileLastVersion;
120 UInt_t gRunNumber = 0;
123 Int_t gPrintLevel = 0;
125 AliMUONVStore* gLocalMasks = 0x0;
126 AliMUONRegionalTriggerConfig* gRegionalMasks = 0x0;
127 AliMUONGlobalCrateConfig* gGlobalMasks = 0x0;
130 AliMUONTriggerIO gTriggerIO;
132 AliMUONVStore* gPatternStore = new AliMUON1DArray(gkNLocalBoard);
134 Char_t gHistoFileName[256];
136 Float_t gkThreshold = 0.2;
138 //__________________________________________________________________
139 void UpdateLocalMask(Int_t localBoardId, Int_t connector, Int_t strip)
143 AliMUONVCalibParam* localMask =
144 static_cast<AliMUONVCalibParam*>(gLocalMasks->FindObject(localBoardId));
146 UShort_t mask = localMask->ValueAsInt(connector,0);
148 mask ^= (0x1 << strip); // set strip mask to zero
150 localMask->SetValueAsInt(connector,0, mask);
153 //__________________________________________________________________
154 void WriteLastCurrentFile(TString currentFile = gLastCurrentFileName)
157 // write last current file
161 out.open(file.Data());
162 out << gSodName << " " << gSodFlag << endl;
163 out << gDAName << " " << gDAFlag << endl;
165 out << gGlobalFileName << " " << gGlobalFileVersion << endl;
166 out << gRegionalFileName << " " << gRegionalFileVersion << endl;
167 out << gLocalMaskFileName << " " << gLocalMaskFileVersion << endl;
168 out << gLocalLutFileName << " " << gLocalLutFileVersion << endl;
169 out << gSignatureFileName << " " << gSignatureFileVersion << endl;
174 //___________________________________________________________________________________________
175 Bool_t ReadCurrentFile(TString currentFile = gCurrentFileName, Bool_t lastCurrentFlag = false)
178 // read last current file name and version
184 std::ifstream in(gSystem->ExpandPathName(file.Data()));
186 printf("Cannot open last current file %s\n",currentFile.Data());
193 sscanf(line, "%s %d", name, &gSodFlag);
195 if (gPrintLevel) printf("Sod Flag %d\n", gSodFlag);
199 sscanf(line, "%s %d", name, &gDAFlag);
201 if (gPrintLevel) printf("DA Flag: %d\n", gDAFlag);
207 Int_t pos = tmp.First(" ");
208 gGlobalFileName = tmp(0, pos);
210 if (!lastCurrentFlag) {
211 gGlobalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
212 if (gPrintLevel) printf("Global File Name: %s version: %d\n",
213 gGlobalFileName.Data(), gGlobalFileVersion);
215 gGlobalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
216 if (gPrintLevel) printf("Global File Name: %s last version: %d\n",
217 gGlobalFileName.Data(), gGlobalFileLastVersion);
223 pos = tmp.First(" ");
224 gRegionalFileName = tmp(0, pos);
226 if (!lastCurrentFlag) {
227 gRegionalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
228 if (gPrintLevel) printf("Regional File Name: %s version: %d\n",
229 gRegionalFileName.Data(), gRegionalFileVersion);
232 gRegionalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
233 if (gPrintLevel) printf("Regional File Name: %s last version: %d\n",
234 gRegionalFileName.Data(), gRegionalFileLastVersion);
242 pos = tmp.First(" ");
243 gLocalMaskFileName = tmp(0, pos);
245 if (!lastCurrentFlag) {
246 gLocalMaskFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
247 if (gPrintLevel) printf("Mask File Name: %s version: %d\n",
248 gLocalMaskFileName.Data(), gLocalMaskFileVersion);
250 gLocalMaskFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
251 if (gPrintLevel) printf("Mask File Name: %s last version: %d\n",
252 gLocalMaskFileName.Data(), gLocalMaskFileLastVersion);
257 pos = tmp.First(" ");
258 gLocalLutFileName = tmp(0, pos);
260 if (!lastCurrentFlag) {
261 gLocalLutFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
262 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
263 gLocalLutFileName.Data(), gLocalLutFileVersion);
265 gLocalLutFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
266 if (gPrintLevel) printf("Lut File Name: %s last version: %d\n",
267 gLocalLutFileName.Data(), gLocalLutFileLastVersion);
272 pos = tmp.First(" ");
273 gSignatureFileName = tmp(0, pos);
274 gSignatureFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
275 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
276 gSignatureFileName.Data(), gSignatureFileVersion);
284 // if last current file does not exist than read current file
285 if (!ReadCurrentFile(gLastCurrentFileName, true))
287 ReadCurrentFile(gCurrentFileName, true);
288 WriteLastCurrentFile();
291 // any case read current file
300 // Export files to FES
301 // env variables have to be set (suppose by ECS ?)
302 // setenv DATE_FES_PATH
303 // setenv DATE_RUN_NUMBER
304 // setenv DATE_ROLE_NAME
305 // setenv DATE_DETECTOR_CODE
307 // Export files into the database
308 // setenv DATE_DETECTOR_CODE MTR
309 // setenv DAQDALIB_PATH $ALICE/daqDAlib
310 // setenv DATE_DB_MYSQL_USER det_MTR
311 // setenv DATE_DB_MYSQL_PWD MTR123
312 // setenv DATE_DB_MYSQL_HOST aldaqdb.cern.ch
313 // setenv DATE_DB_MYSQL_DB $DATE_CONFIG
314 // set PATH=$PATH:${DAQDALIB_PATH}
317 // to be sure that env variable is set
318 // gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
319 gSystem->Setenv("DAQDALIB_PATH", "$ALICE/daqDAlib");
320 gSystem->Setenv("DATE_DETECTOR_CODE", "MTR");
321 gSystem->Setenv("DATE_DB_MYSQL_USER", "det_MTR");
322 gSystem->Setenv("DATE_DB_MYSQL_PWD", "MTR123");
323 gSystem->Setenv("DATE_DB_MYSQL_HOST", "aldaqdb.cern.ch");
324 gSystem->Setenv("DATE_DB_MYSQL_DB", "$DATE_CONFIG");
329 Bool_t modified = false;
332 TString fileExp("ExportedFiles.dat");
335 out.open(fileExp.Data());
337 printf("Failed to create file: %s\n",file.Data());
339 } file = gGlobalFileName.Data();
341 if (gGlobalFileLastVersion != gGlobalFileVersion) {
343 status = daqDA_FES_storeFile(file.Data(), file.Data());
345 printf("Failed to export file: %s\n",gGlobalFileName.Data());
348 out << gGlobalFileName.Data() << endl;
349 if(gPrintLevel) printf("Export file: %s\n",gGlobalFileName.Data());
352 if (gLocalMaskFileLastVersion != gLocalMaskFileVersion) {
354 file = gLocalMaskFileName;
356 status = daqDA_FES_storeFile(file.Data(), file.Data());
358 printf("Failed to export file: %s\n",gLocalMaskFileName.Data());
362 status = daqDA_DB_storeFile(file.Data(), file.Data());
364 printf("Failed to export file to DB: %s\n",gLocalMaskFileName.Data());
368 if(gPrintLevel) printf("Export file: %s\n",gLocalMaskFileName.Data());
369 out << gLocalMaskFileName.Data() << endl;
372 if (gLocalLutFileLastVersion != gLocalLutFileVersion) {
373 file = gLocalLutFileName;
375 status = daqDA_FES_storeFile(file.Data(), file.Data());
377 printf("Failed to export file: %s\n",gLocalLutFileName.Data());
380 if(gPrintLevel) printf("Export file: %s\n",gLocalLutFileName.Data());
381 out << gLocalLutFileName.Data() << endl;
385 // exported regional file whenever mask or/and Lut are modified
386 if ( (gRegionalFileLastVersion != gRegionalFileVersion) || modified) {
387 file = gRegionalFileName;
388 status = daqDA_FES_storeFile(file.Data(), file.Data());
390 printf("Failed to export file: %s\n",gRegionalFileName.Data());
393 if(gPrintLevel) printf("Export file: %s\n",gRegionalFileName.Data());
394 out << gRegionalFileName.Data() << endl;
399 // export Exported file to FES anyway
400 status = daqDA_FES_storeFile(fileExp.Data(), fileExp.Data());
402 printf("Failed to export file: %s\n", fileExp.Data());
405 if(gPrintLevel) printf("Export file: %s\n",fileExp.Data());
412 // copy locally a file from daq detector config db
413 // The current detector is identified by detector code in variable
414 // DATE_DETECTOR_CODE. It must be defined.
415 // If environment variable DAQDA_TEST_DIR is defined, files are copied from DAQDA_TEST_DIR
416 // instead of the database. The usual environment variables are not needed.
418 // to be sure that env variable is set
419 // gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
420 gSystem->Setenv("DAQDALIB_PATH", "$ALICE/daqDAlib");
424 status = daqDA_DB_getFile(gCurrentFileName.Data(), gCurrentFileName.Data());
426 printf("Failed to get current config file from DB: %s\n",gCurrentFileName.Data());
432 status = daqDA_DB_getFile(gGlobalFileName.Data(), gGlobalFileName.Data());
434 printf("Failed to get current config file from DB: %s\n", gGlobalFileName.Data());
438 status = daqDA_DB_getFile(gRegionalFileName.Data(), gRegionalFileName.Data());
440 printf("Failed to get current config file from DB: %s\n",gRegionalFileName.Data());
444 status = daqDA_DB_getFile(gLocalMaskFileName.Data(), gLocalMaskFileName.Data());
446 printf("Failed to get current config file from DB: %s\n",gLocalMaskFileName.Data());
450 status = daqDA_DB_getFile(gLocalLutFileName.Data(), gLocalLutFileName.Data());
452 printf("Failed to get current config file from DB: %s\n",gLocalLutFileName.Data());
463 gLocalMasks = new AliMUON1DArray(gkNLocalBoard+9);
464 gRegionalMasks = new AliMUONRegionalTriggerConfig();
465 gGlobalMasks = new AliMUONGlobalCrateConfig();
467 TString localFile = gLocalMaskFileName;
468 TString regionalFile = gRegionalFileName;
469 TString globalFile = gGlobalFileName;
471 gTriggerIO.ReadConfig(localFile.Data(), regionalFile.Data(), globalFile.Data(),
472 gLocalMasks, gRegionalMasks, gGlobalMasks);
475 void MakePattern(Int_t localBoardId, TArrayS& xPattern, TArrayS& yPattern)
478 // calculate the hit map for each strip in x and y direction
479 AliMUONVCalibParam* pat =
480 static_cast<AliMUONVCalibParam*>(gPatternStore->FindObject(localBoardId));
483 pat = new AliMUONCalibParamND(2, 64, localBoardId, 0,0.); // put default wise 0.
484 gPatternStore->Add(pat);
487 for (Int_t i = 0; i < 4; ++i) {
488 for (Int_t j = 0; j < 16; ++j) {
490 Int_t xMask = xPattern[i];
491 Int_t yMask = yPattern[i];
493 Int_t index = 16*i + j;
494 Double_t patOcc = 0.;
496 if ( (xMask >> j ) & 0x1 ) {
497 patOcc = pat->ValueAsDouble(index, 0) + 1.;
498 pat->SetValueAsDouble(index, 0, patOcc);
500 if ( (yMask >> j ) & 0x1 ) {
501 patOcc = pat->ValueAsDouble(index, 0) + 1.;
502 pat->SetValueAsDouble(index, 0, patOcc);
510 void MakePatternStore(Bool_t pedestal = true)
513 // calculates the occupancy (option: store in a root file)
514 // check noisy strip (pedestal true, software trigger)
515 // check dead channel (pesdetal false, FET trigger)
517 Int_t localBoardId = 0;
518 Bool_t updated = false;
525 TH1F* xOccHisto[243];
526 TH1F* yOccHisto[243];
527 TH1F* xPatOccHisto = 0x0;
528 TH1F* yPatOccHisto = 0x0;
530 TFile* histoFile = 0x0;
532 if (gHistoFileName[0] != 0) {
533 histoFile = new TFile(gHistoFileName,"RECREATE","MUON Tracking pedestals");
535 sprintf(name,"pat_x");
536 sprintf(title,"Occupancy for x strip");
540 xPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
541 xPatOccHisto ->SetDirectory(histoFile);
543 sprintf(name,"pat_y");
544 sprintf(title,"Occupancy for y strip");
545 yPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
546 yPatOccHisto->SetDirectory(histoFile);
550 // iterator over pedestal
551 TIter next(gPatternStore->CreateIterator());
552 AliMUONVCalibParam* pat;
554 while ( ( pat = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
556 localBoardId = pat->ID0();
558 if (gHistoFileName[0] != 0) {
564 sprintf(name,"pat_x_%d",localBoardId);
565 sprintf(title,"Occupancy for x strip, board %d",localBoardId);
566 xOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
568 sprintf(name,"pat_y_%d",localBoardId);
569 sprintf(title,"Occupancy for y strip, board %d",localBoardId);
570 yOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
574 for (Int_t index = 0; index < pat->Size() ; ++index) {// 64 bits for X and 64 bits for Y strips
576 Double_t patXOcc = pat->ValueAsDouble(index, 0)/(Double_t)gNEvents;
577 Double_t patYOcc = pat->ValueAsDouble(index, 1)/(Double_t)gNEvents;
579 pat->SetValueAsDouble(index, 0, patXOcc);
580 pat->SetValueAsDouble(index, 1, patYOcc);
584 if ( (patXOcc > gkThreshold && pedestal) || (patXOcc < 1.- gkThreshold && !pedestal) ) {
585 UShort_t strip = index % 16;
586 Int_t connector = index/16;
587 UpdateLocalMask(localBoardId, connector, strip);
592 if ( (patYOcc > gkThreshold && pedestal) || (patYOcc < 1.- gkThreshold && !pedestal) ) {
593 UShort_t strip = index % 16;
594 Int_t connector = index/16 + 4;
595 UpdateLocalMask(localBoardId, connector, strip);
600 if (gHistoFileName[0] != 0) {
601 xPatOccHisto->Fill(patXOcc);
602 yPatOccHisto->Fill(patYOcc);
603 xOccHisto[localBoardId]->Fill(index, patXOcc);
604 yOccHisto[localBoardId]->Fill(index, patYOcc);
610 if (gHistoFileName[0] != 0) {
619 gLocalMaskFileVersion++;
621 TString tmp(gLocalMaskFileName);
622 Int_t pos = tmp.First("-");
623 gLocalMaskFileName = tmp(0,pos+1) + Form("%d",gLocalMaskFileVersion) + ".dat";
625 // write last current file
626 WriteLastCurrentFile();
628 gTriggerIO.WriteConfig(gLocalMaskFileName, gRegionalFileName, gGlobalFileName, gLocalMasks, gRegionalMasks, gGlobalMasks);
632 //*************************************************************//
635 int main(Int_t argc, Char_t **argv)
638 // needed for streamer application
639 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo",
640 "RIO", "TStreamerInfo()");
642 Int_t skipEvents = 0;
643 Int_t maxEvents = 1000000;
644 Char_t inputFile[256];
645 strcpy(inputFile, "");
646 TString flatOutputFile;
650 // decode the input line
651 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
656 if (arg[0] != '-') continue;
661 sprintf(inputFile,argv[i]);
665 gkThreshold = atof(argv[i]);
673 gPrintLevel=atoi(argv[i]);
677 skipEvents=atoi(argv[i]);
681 sscanf(argv[i],"%d",&maxEvents);
685 sscanf(argv[i],"%s",gHistoFileName);
689 printf("\n******************* %s usage **********************",argv[0]);
690 printf("\n%s -options, the available options are :",argv[0]);
691 printf("\n-h help (this screen)");
694 printf("\n-f <raw data file> (default = %s)",inputFile);
697 printf("\n-r <root file> (default = %s)",gHistoFileName);
699 printf("\n Options");
700 printf("\n-t <threshold values> (default = %3.1f)",gkThreshold);
701 printf("\n-d <print level> (default = %d)",gPrintLevel);
702 printf("\n-s <skip events> (default = %d)",skipEvents);
703 printf("\n-n <max events> (default = %d)",maxEvents);
704 printf("\n-e <execute ped/calib> (default = %s)",gCommand.Data());
709 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
710 argc = 2; exit(-1); // exit if error
714 // set command to lower case
717 // decoding the events
720 Int_t nDateEvents = 0;
725 AliMUONDDLTrigger* ddlTrigger = 0x0;
726 AliMUONDarcHeader* darcHeader = 0x0;
727 AliMUONRegHeader* regHeader = 0x0;
728 AliMUONLocalStruct* localStruct = 0x0;
734 // comment out, since we do not retrieve files from database
735 if (!ImportFiles()) {
736 printf("Import from DB failed\n");
737 printf("For local test set DAQDA_TEST_DIR to the local directory where the Mtg files are located \n");
742 if(!ExportFiles()) return -1;
748 status = monitorSetDataSource(inputFile);
750 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
751 << " " << monitorDecodeError(status) << endl;
754 status = monitorDeclareMp("MUON Trigger monitoring");
756 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
757 << " " << monitorDecodeError(status) << endl;
761 cout << "MUONTRKda : Reading data from file " << inputFile <<endl;
765 if (gNEvents >= maxEvents) break;
766 if (gNEvents && gNEvents % 100 == 0)
767 cout<<"Cumulated events " << gNEvents << endl;
769 // check shutdown condition
770 if (daqDA_checkShutdown())
773 // Skip Events if needed
775 status = monitorGetEventDynamic(&event);
780 status = monitorGetEventDynamic(&event);
782 cout<<"EOF found"<<endl;
788 // decoding rawdata headers
789 AliRawReader *rawReader = new AliRawReaderDate(event);
791 Int_t eventType = rawReader->GetType();
792 gRunNumber = rawReader->GetRunNumber();
795 if (eventType != PHYSICS_EVENT)
796 continue; // for the moment
799 if (gPrintLevel) printf("\nEvent # %d\n",gNEvents);
801 // decoding MUON payload
802 AliMUONRawStreamTrigger* rawStream = new AliMUONRawStreamTrigger(rawReader);
803 //rawStream->SetMaxReg(1);
807 while((status = rawStream->NextDDL())) {
809 if (gPrintLevel) printf("iDDL %d\n", rawStream->GetDDL());
811 ddlTrigger = rawStream->GetDDLTrigger();
812 darcHeader = ddlTrigger->GetDarcHeader();
814 if (gPrintLevel) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
816 // loop over regional structures
817 Int_t nReg = darcHeader->GetRegHeaderEntries();
818 for(Int_t iReg = 0; iReg < nReg; ++iReg){ //REG loop
820 if (gPrintLevel) printf("RegionalId %d\n", iReg);
822 regHeader = darcHeader->GetRegHeaderEntry(iReg);
824 // loop over local structures
825 Int_t nLocal = regHeader->GetLocalEntries();
826 for(Int_t iLocal = 0; iLocal < nLocal; ++iLocal) {
828 localStruct = regHeader->GetLocalEntry(iLocal);
830 Int_t localBoardId = gTriggerIO.LocalBoardId(index++);
831 if (gPrintLevel) printf("local %d\n", localBoardId );
835 localStruct->GetXPattern(xPattern);
836 localStruct->GetYPattern(yPattern);
837 MakePattern(localBoardId, xPattern, yPattern);
839 if (gPrintLevel) printf("X pattern %x %x %x %x, Y pattern %x %x %x %x\n",
840 localStruct->GetX1(), localStruct->GetX2(),localStruct->GetX3(),localStruct->GetX4(),
841 localStruct->GetY1(), localStruct->GetY2(),localStruct->GetY3(),localStruct->GetY4());
852 if (gCommand.Contains("ped"))
855 if (gCommand.Contains("cal"))
856 MakePatternStore(false);
863 cout << "MUONTRGda : Run number : " << gRunNumber << endl;
864 cout << "MUONTRGda : Histo file generated : " << gHistoFileName << endl;
865 cout << "MUONTRGda : Nb of DATE events = " << nDateEvents << endl;
866 cout << "MUONTRGda : Nb of events used = " << gNEvents << endl;
868 printf("Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
871 delete gRegionalMasks;
872 delete gGlobalMasks; // in case
873 delete gPatternStore;