4 Contact: Franck Manso <manso@clermont.in2p3.fr>
5 Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_mtrda.html
6 Reference run: 61898, 63698 (dead channels), 63701 (noisy channels)
7 Run Type: PHYSICS (noisy channels), STANDALONE (dead channels)
9 Number of events needed: 1000 events for noisy and dead channels
10 Input Files: Rawdata file (DATE format)
12 MtgGlobalCrate-<version>.dat
13 MtgRegionalCrate-<version>.dat
14 MtgLocalMask-<version>.dat
15 MtgLocalLut-<version>.dat
18 Output Files: local dir (not persistent)
22 //////////////////////////////////////////////////////////////////////////////
23 // Detector Algorithm for the MUON trigger configuration. //
25 // Calculates masks for the global trigger input, by looking at dead //
26 // channels in calibration runs and at noisy channels in physics runs. //
27 // Transfers trigger configuration files to the File Exchange Server and //
28 // writes them (if modified) into the trigger configuration data base. //
31 // Christian Fink (formerly at Subatech, Nantes) //
32 // Franck Manso (LPC Clermont-Ferrand, manso@clermont.in2p3.fr) //
33 // Bogdan Vulpescu (LPC Clermont-Ferrand, vulpescu@clermont.in2p3.fr) //
35 //////////////////////////////////////////////////////////////////////////////
44 #include <Riostream.h>
49 #include "AliRawReaderDate.h"
51 #include "AliMpConstants.h"
52 #include "AliMUONRawStreamTrigger.h"
53 #include "AliMUONDarcHeader.h"
54 #include "AliMUONDDLTrigger.h"
55 #include "AliMUONVStore.h"
56 #include "AliMUON1DArray.h"
57 #include "AliMUONTriggerIO.h"
58 #include "AliMUONRegionalTriggerConfig.h"
59 #include "AliMUONGlobalCrateConfig.h"
60 #include "AliMUONTriggerCrateConfig.h"
65 #include "TStopwatch.h"
67 #include "TPluginManager.h"
69 /// class for DA run parameters and DA working space
70 class AliDAConfig : TObject {
75 fDAConfigFileName("DAConfig.txt"),
76 fCurrentFileName("MtgCurrent.dat"),
77 fLastCurrentFileName("MtgLastCurrent.dat"),
83 fRegionalFileName(""),
84 fLocalMaskFileName(""),
85 fLocalLutFileName(""),
86 fSignatureFileName(""),
87 fGlobalFileVersion(0),
88 fRegionalFileVersion(0),
89 fLocalMaskFileVersion(0),
90 fLocalLutFileVersion(0),
91 fSignatureFileVersion(0),
92 fGlobalFileLastVersion(0),
93 fRegionalFileLastVersion(0),
94 fLocalMaskFileLastVersion(0),
95 fLocalLutFileLastVersion(0),
102 fTriggerIO(new AliMUONTriggerIO),
103 fAlgoNoisyInput(false),
104 fAlgoDeadcInput(false),
110 fWithWarnings(false),
111 fNLocalBoard(AliMpConstants::TotalNofLocalBoards()+1)
113 /// default constructor
114 for (Int_t ii = 0; ii < kGlobalInputs; ii++) {
115 for (Int_t il = 0; il < kGlobalInputLength; il++) {
116 fAccGlobalInputN[ii][il] = 0;
117 fAccGlobalInputD[ii][il] = 0;
120 fLocalMasks = new AliMUON1DArray(fNLocalBoard);
121 fRegionalMasks = new AliMUONRegionalTriggerConfig();
122 fGlobalMasks = new AliMUONGlobalCrateConfig();
125 AliDAConfig (const AliDAConfig& cfg); // copy constructor
126 AliDAConfig& operator=(const AliDAConfig& cfg); // assignment operator
127 virtual ~AliDAConfig()
131 delete fRegionalMasks;
137 /// print DA parameters
138 printf("DA config file name: %s \n",GetDAConfigFileName());
139 printf("Current file name: %s \n",GetCurrentFileName());
140 printf("Last current file name: %s \n",GetLastCurrentFileName());
141 printf("Global file name: %s (%d %d)\n",GetGlobalFileName(),GetGlobalFileVersion(),GetGlobalFileLastVersion());
142 printf("Regional file name: %s (%d %d)\n",GetRegionalFileName(),GetRegionalFileVersion(),GetRegionalFileLastVersion());
143 printf("Local mask file name: %s (%d %d)\n",GetLocalMaskFileName(),GetLocalMaskFileVersion(),GetLocalMaskFileLastVersion());
144 printf("Local LUT file name: %s (%d %d)\n",GetLocalLutFileName(),GetLocalLutFileVersion(),GetLocalLutFileLastVersion());
145 printf("Signature file name: %s (%d)\n",GetSignatureFileName(),GetSignatureFileVersion());
148 const Char_t* GetDAConfigFileName() { return fDAConfigFileName.Data(); }
149 const Char_t* GetCurrentFileName() { return fCurrentFileName.Data(); }
150 const Char_t* GetLastCurrentFileName() { return fLastCurrentFileName.Data(); }
152 const Char_t* GetSodName() { return fSodName.Data(); }
153 Int_t GetSodFlag() const { return fSodFlag; }
155 const Char_t* GetDAName() { return fDAName.Data(); }
156 Int_t GetDAFlag() const { return fDAFlag; }
158 const Char_t* GetGlobalFileName() { return fGlobalFileName.Data(); }
159 const Char_t* GetRegionalFileName() { return fRegionalFileName.Data(); }
160 const Char_t* GetLocalMaskFileName() { return fLocalMaskFileName.Data(); }
161 const Char_t* GetLocalLutFileName() { return fLocalLutFileName.Data(); }
162 const Char_t* GetSignatureFileName() { return fSignatureFileName.Data(); }
164 Int_t GetGlobalFileVersion() const { return fGlobalFileVersion; }
165 Int_t GetRegionalFileVersion() const { return fRegionalFileVersion; }
166 Int_t GetLocalMaskFileVersion() const { return fLocalMaskFileVersion; }
167 Int_t GetLocalLutFileVersion() const { return fLocalLutFileVersion; }
168 Int_t GetSignatureFileVersion() const { return fSignatureFileVersion; }
170 Int_t GetGlobalFileLastVersion() const { return fGlobalFileLastVersion; }
171 Int_t GetRegionalFileLastVersion() const { return fRegionalFileLastVersion; }
172 Int_t GetLocalMaskFileLastVersion() const { return fLocalMaskFileLastVersion; }
173 Int_t GetLocalLutFileLastVersion() const { return fLocalLutFileLastVersion; }
175 AliMUONVStore* GetLocalMasks() const { return fLocalMasks; }
176 AliMUONRegionalTriggerConfig* GetRegionalMasks() const { return fRegionalMasks; }
177 AliMUONGlobalCrateConfig* GetGlobalMasks() const { return fGlobalMasks; }
179 AliMUONTriggerIO* GetTriggerIO() const { return fTriggerIO; }
181 Int_t GetEventsN() const { return fEventsN; }
182 Int_t GetEventsD() const { return fEventsD; }
184 Int_t GetPrintLevel() const { return fPrintLevel; }
186 Bool_t GetAlgoNoisyInput() const { return fAlgoNoisyInput; }
187 Bool_t GetAlgoDeadcInput() const { return fAlgoDeadcInput; }
189 Float_t GetThrN() const { return fThrN; }
190 Float_t GetThrD() const { return fThrD; }
192 Int_t GetMinEvents() const { return fMinEvents; }
193 Int_t GetMaxEvents() const { return fMaxEvents; }
194 Int_t GetSkipEvents() const { return fSkipEvents; }
196 Bool_t WithWarnings() const { return fWithWarnings; }
198 Int_t GetGlobalInputs() const { return kGlobalInputs; }
199 Int_t GetGlobalInputLength() const { return kGlobalInputLength; }
201 Int_t GetAccGlobalInputN(Int_t ii, Int_t ib) const { return fAccGlobalInputN[ii][ib]; }
202 Int_t GetAccGlobalInputD(Int_t ii, Int_t ib) const { return fAccGlobalInputD[ii][ib]; }
204 void SetSodName(Char_t *name) { fSodName = TString(name); }
205 void SetSodFlag(Int_t flag) { fSodFlag = flag; }
207 void SetDAName(Char_t *name) { fDAName = TString(name); }
208 void SetDAFlag(Int_t flag) { fDAFlag = flag; }
210 void SetGlobalFileName(const Char_t *name) { fGlobalFileName = TString(name); }
211 void SetRegionalFileName(const Char_t *name) { fRegionalFileName = TString(name); }
212 void SetLocalMaskFileName(const Char_t *name) { fLocalMaskFileName = TString(name); }
213 void SetLocalLutFileName(const Char_t *name) { fLocalLutFileName = TString(name); }
214 void SetSignatureFileName(const Char_t *name) { fSignatureFileName = TString(name); }
216 void SetGlobalFileVersion(Int_t ver) { fGlobalFileVersion = ver; }
217 void SetRegionalFileVersion(Int_t ver) { fRegionalFileVersion = ver; }
218 void SetLocalMaskFileVersion(Int_t ver) { fLocalMaskFileVersion = ver; }
219 void SetLocalLutFileVersion(Int_t ver) { fLocalLutFileVersion = ver; }
220 void SetSignatureFileVersion(Int_t ver) { fSignatureFileVersion = ver; }
222 void SetGlobalFileLastVersion(Int_t ver) { fGlobalFileLastVersion = ver; }
223 void SetRegionalFileLastVersion(Int_t ver) { fRegionalFileLastVersion = ver; }
224 void SetLocalMaskFileLastVersion(Int_t ver) { fLocalMaskFileLastVersion = ver; }
225 void SetLocalLutFileLastVersion(Int_t ver) { fLocalLutFileLastVersion = ver; }
227 void IncNoiseEvent() { fEventsN++; }
228 void IncDeadcEvent() { fEventsD++; }
230 void AddAccGlobalInputN(Int_t ii, Int_t ib, Int_t val) { fAccGlobalInputN[ii][ib] += val; }
231 void AddAccGlobalInputD(Int_t ii, Int_t ib, Int_t val) { fAccGlobalInputD[ii][ib] += val; }
233 void SetPrintLevel(Int_t level) { fPrintLevel = level; }
235 void SetAlgoNoisyInput(Bool_t val) { fAlgoNoisyInput = val; }
236 void SetAlgoDeadcInput(Bool_t val) { fAlgoDeadcInput = val; }
238 void SetThrN(Float_t val) { fThrN = val; }
239 void SetThrD(Float_t val) { fThrD = val; }
241 void SetMinEvents(Int_t val) { fMinEvents = val; }
242 void SetMaxEvents(Int_t val) { fMaxEvents = val; }
243 void SetSkipEvents(Int_t val) { fSkipEvents = val; }
245 void SetWithWarnings() { fWithWarnings = true; }
247 void IncGlobalFileVersion() { fGlobalFileVersion++; }
248 void DecSkipEvents() { fSkipEvents--; }
252 const TString fDAConfigFileName;
253 const TString fCurrentFileName;
254 const TString fLastCurrentFileName;
262 TString fGlobalFileName;
263 TString fRegionalFileName;
264 TString fLocalMaskFileName;
265 TString fLocalLutFileName;
266 TString fSignatureFileName;
268 Int_t fGlobalFileVersion;
269 Int_t fRegionalFileVersion;
270 Int_t fLocalMaskFileVersion;
271 Int_t fLocalLutFileVersion;
272 Int_t fSignatureFileVersion;
274 Int_t fGlobalFileLastVersion;
275 Int_t fRegionalFileLastVersion;
276 Int_t fLocalMaskFileLastVersion;
277 Int_t fLocalLutFileLastVersion;
284 AliMUONVStore* fLocalMasks;
285 AliMUONRegionalTriggerConfig* fRegionalMasks;
286 AliMUONGlobalCrateConfig* fGlobalMasks;
288 AliMUONTriggerIO *fTriggerIO;
290 Bool_t fAlgoNoisyInput;
291 Bool_t fAlgoDeadcInput;
298 Bool_t fWithWarnings;
300 const Int_t fNLocalBoard;
302 enum { kGlobalInputs = 4, kGlobalInputLength = 32 };
304 Int_t fAccGlobalInputN[kGlobalInputs][kGlobalInputLength];
305 Int_t fAccGlobalInputD[kGlobalInputs][kGlobalInputLength];
309 //__________________________________________________________________
310 Bool_t ReadDAConfig(AliDAConfig& cfg)
312 /// read run parameters for the DA
317 file = cfg.GetDAConfigFileName();
318 std::ifstream in(gSystem->ExpandPathName(file.Data()));
320 printf("Cannot open DA configuration file %s ; use default values.\n",file.Data());
329 pos = tmp.First(" ");
331 cfg.SetPrintLevel(tmp.Atoi());
335 pos = tmp.First(" ");
337 cfg.SetThrN(tmp.Atof());
341 pos = tmp.First(" ");
343 cfg.SetThrD(tmp.Atof());
347 pos = tmp.First(" ");
349 cfg.SetMinEvents(tmp.Atoi());
353 pos = tmp.First(" ");
355 cfg.SetSkipEvents(tmp.Atoi());
359 pos = tmp.First(" ");
361 cfg.SetMaxEvents(tmp.Atoi());
365 pos = tmp.First(" ");
367 if (tmp.Atoi() != 0) cfg.SetWithWarnings();
373 //__________________________________________________________________
374 void WriteLastCurrentFile(AliDAConfig& cfg, TString currentFile)
376 /// write last current file
381 out.open(file.Data());
382 out << cfg.GetSodName() << " " << cfg.GetSodFlag() << endl;
383 out << cfg.GetDAName() << " " << cfg.GetDAFlag() << endl;
385 out << cfg.GetGlobalFileName() << " " << cfg.GetGlobalFileVersion() << endl;
386 out << cfg.GetRegionalFileName() << " " << cfg.GetRegionalFileVersion() << endl;
387 out << cfg.GetLocalMaskFileName() << " " << cfg.GetLocalMaskFileVersion() << endl;
388 out << cfg.GetLocalLutFileName() << " " << cfg.GetLocalLutFileVersion() << endl;
389 out << cfg.GetSignatureFileName() << " " << cfg.GetSignatureFileVersion() << endl;
394 //___________________________________________________________________________________________
395 Bool_t ReadCurrentFile(AliDAConfig& cfg, TString currentFile, Bool_t lastCurrentFlag = false)
397 /// read last current file name and version
405 std::ifstream in(gSystem->ExpandPathName(file.Data()));
407 printf("Cannot open last current file %s\n",currentFile.Data());
413 sscanf(line, "%s %d", name, &flag);
414 cfg.SetSodName(name);
415 cfg.SetSodFlag(flag);
416 if (cfg.GetPrintLevel()) printf("Sod Flag %d\n", cfg.GetSodFlag());
420 sscanf(line, "%s %d", name, &flag);
423 if (cfg.GetPrintLevel()) printf("DA Flag: %d\n", cfg.GetDAFlag());
428 Int_t pos = tmp.First(" ");
429 TString tmp1 = tmp(0, pos);
430 cfg.SetGlobalFileName(tmp1.Data());
432 if (!lastCurrentFlag) {
433 cfg.SetGlobalFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
434 if (cfg.GetPrintLevel()) printf("Global File Name: %s version: %d\n",
435 cfg.GetGlobalFileName(), cfg.GetGlobalFileVersion());
437 cfg.SetGlobalFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
438 if (cfg.GetPrintLevel()) printf("Global File Name: %s last version: %d\n",
439 cfg.GetGlobalFileName(), cfg.GetGlobalFileLastVersion());
445 pos = tmp.First(" ");
447 cfg.SetRegionalFileName(tmp1.Data());
449 if (!lastCurrentFlag) {
450 cfg.SetRegionalFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
451 if (cfg.GetPrintLevel()) printf("Regional File Name: %s version: %d\n",
452 cfg.GetRegionalFileName(), cfg.GetRegionalFileVersion());
455 cfg.SetRegionalFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
456 if (cfg.GetPrintLevel()) printf("Regional File Name: %s last version: %d\n",
457 cfg.GetRegionalFileName(), cfg.GetRegionalFileLastVersion());
463 pos = tmp.First(" ");
465 cfg.SetLocalMaskFileName(tmp1.Data());
467 if (!lastCurrentFlag) {
468 cfg.SetLocalMaskFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
469 if (cfg.GetPrintLevel()) printf("Mask File Name: %s version: %d\n",
470 cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileVersion());
472 cfg.SetLocalMaskFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
473 if (cfg.GetPrintLevel()) printf("Mask File Name: %s last version: %d\n",
474 cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileLastVersion());
479 pos = tmp.First(" ");
481 cfg.SetLocalLutFileName(tmp1.Data());
483 if (!lastCurrentFlag) {
484 cfg.SetLocalLutFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
485 if (cfg.GetPrintLevel()) printf("Lut File Name: %s version: %d\n",
486 cfg.GetLocalLutFileName(), cfg.GetLocalLutFileVersion());
488 cfg.SetLocalLutFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
489 if (cfg.GetPrintLevel()) printf("Lut File Name: %s last version: %d\n",
490 cfg.GetLocalLutFileName(), cfg.GetLocalLutFileLastVersion());
495 pos = tmp.First(" ");
497 cfg.SetSignatureFileName(tmp1.Data());
498 cfg.SetSignatureFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
499 if (cfg.GetPrintLevel()) printf("Lut File Name: %s version: %d\n",
500 cfg.GetSignatureFileName(), cfg.GetSignatureFileVersion());
506 void ReadFileNames(AliDAConfig& cfg)
508 /// if last current file does not exist than read current file
510 if (!ReadCurrentFile(cfg,cfg.GetLastCurrentFileName(), true))
512 ReadCurrentFile(cfg,cfg.GetCurrentFileName(), true);
515 // any case read current file
516 ReadCurrentFile(cfg,cfg.GetCurrentFileName());
521 Bool_t ExportFiles(AliDAConfig& cfg)
523 /// Export files to FES
525 // env variables have to be set (suppose by ECS ?)
526 // setenv DATE_FES_PATH
527 // setenv DATE_RUN_NUMBER
528 // setenv DATE_ROLE_NAME
529 // setenv DATE_DETECTOR_CODE
532 //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
534 // offline: use a dummy FES (local directory)
535 //gSystem->Setenv("DAQDA_TEST_DIR", "/alisoft/FES");
540 Bool_t modified = false;
543 TString fileExp("ExportedFiles.dat");
546 out.open(fileExp.Data());
548 printf("Failed to create file: %s\n",file.Data());
552 // check if MtgLastCurrent.dat exists
553 // if not, do initial export of all files
554 Bool_t initFES = false;
555 if (gSystem->AccessPathName("MtgLastCurrent.dat"))
557 if (initFES) printf("Copy all configuration files to the FES.\n");
559 file = cfg.GetGlobalFileName();
560 if ((cfg.GetGlobalFileLastVersion() != cfg.GetGlobalFileVersion()) || initFES) {
561 status = daqDA_FES_storeFile(file.Data(), file.Data());
563 printf("Failed to export file: %s\n",cfg.GetGlobalFileName());
566 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetGlobalFileName());
567 out << cfg.GetGlobalFileName() << endl;
570 file = cfg.GetLocalMaskFileName();
571 if ((cfg.GetLocalMaskFileLastVersion() != cfg.GetLocalMaskFileVersion()) || initFES) {
573 status = daqDA_FES_storeFile(file.Data(), file.Data());
575 printf("Failed to export file: %s\n",cfg.GetLocalMaskFileName());
578 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetLocalMaskFileName());
579 out << cfg.GetLocalMaskFileName() << endl;
582 file = cfg.GetLocalLutFileName();
583 if ((cfg.GetLocalLutFileLastVersion() != cfg.GetLocalLutFileVersion()) || initFES) {
585 status = daqDA_FES_storeFile(file.Data(), file.Data());
587 printf("Failed to export file: %s\n",cfg.GetLocalLutFileName());
590 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetLocalLutFileName());
591 out << cfg.GetLocalLutFileName() << endl;
595 // exported regional file whenever mask or/and Lut are modified
596 file = cfg.GetRegionalFileName();
597 if ( (cfg.GetRegionalFileLastVersion() != cfg.GetRegionalFileVersion()) || modified || initFES) {
598 status = daqDA_FES_storeFile(file.Data(), file.Data());
600 printf("Failed to export file: %s\n",cfg.GetRegionalFileName());
603 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetRegionalFileName());
604 out << cfg.GetRegionalFileName() << endl;
609 // export Exported file to FES anyway
610 status = daqDA_FES_storeFile(fileExp.Data(), fileExp.Data());
612 printf("Failed to export file: %s\n", fileExp.Data());
615 if(cfg.GetPrintLevel()) printf("Export file: %s\n",fileExp.Data());
617 // write last current file
618 WriteLastCurrentFile(cfg,cfg.GetLastCurrentFileName());
624 Bool_t ImportFiles(AliDAConfig& cfg)
626 /// copy locally a file from daq detector config db
627 /// The current detector is identified by detector code in variable
628 /// DATE_DETECTOR_CODE. It must be defined.
629 /// If environment variable DAQDA_TEST_DIR is defined, files are copied from
630 /// DAQDA_TEST_DIR instead of the database.
631 /// The usual environment variables are not needed.
636 //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
638 status = daqDA_DB_getFile(cfg.GetDAConfigFileName(), cfg.GetDAConfigFileName());
640 printf("Failed to get DA config file from DB: %s\n",cfg.GetDAConfigFileName());
646 status = daqDA_DB_getFile(cfg.GetCurrentFileName(), cfg.GetCurrentFileName());
648 printf("Failed to get current config file from DB: %s\n",cfg.GetCurrentFileName());
654 status = daqDA_DB_getFile(cfg.GetGlobalFileName(), cfg.GetGlobalFileName());
656 printf("Failed to get current config file from DB: %s\n", cfg.GetGlobalFileName());
660 status = daqDA_DB_getFile(cfg.GetRegionalFileName(), cfg.GetRegionalFileName());
662 printf("Failed to get current config file from DB: %s\n",cfg.GetRegionalFileName());
666 status = daqDA_DB_getFile(cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileName());
668 printf("Failed to get current config file from DB: %s\n",cfg.GetLocalMaskFileName());
672 status = daqDA_DB_getFile(cfg.GetLocalLutFileName(), cfg.GetLocalLutFileName());
674 printf("Failed to get current config file from DB: %s\n",cfg.GetLocalLutFileName());
682 void ReadMaskFiles(AliDAConfig& cfg)
686 const Char_t* localFile = cfg.GetLocalMaskFileName();
687 const Char_t* regionalFile = cfg.GetRegionalFileName();
688 const Char_t* globalFile = cfg.GetGlobalFileName();
690 cfg.GetTriggerIO()->ReadConfig(localFile, regionalFile, globalFile, cfg.GetLocalMasks(), cfg.GetRegionalMasks(), cfg.GetGlobalMasks());
693 //______________________________________________________________
694 UInt_t GetFetMode(const AliDAConfig & cfg)
696 /// FET mode = 3 to run algorithm for dead global inputs
700 return cfg.GetGlobalMasks()->GetFetRegister(3);
704 //______________________________________________________________
705 void StoreGlobalInput(AliDAConfig& cfg, const UInt_t * const globalInput)
707 /// accumulate and build statistics of global input values
709 for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
710 for (Int_t ib = 0; ib < cfg.GetGlobalInputLength(); ib++) {
712 if (cfg.GetAlgoNoisyInput())
713 cfg.AddAccGlobalInputN(ii,ib,((globalInput[ii] >> ib) & 0x1));
714 if (cfg.GetAlgoDeadcInput())
715 cfg.AddAccGlobalInputD(ii,ib,((globalInput[ii] >> ib) & 0x1));
721 //______________________________________________________________
722 void UpdateGlobalMasks(AliDAConfig& cfg)
724 /// update the global masks
727 //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
729 Float_t rateN = 0.0, rateD = 0.0;
730 UInt_t gmask[4], omask;
731 Bool_t noise, deadc, withEvN, withEvD, updated = false;
733 for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
736 for (Int_t ib = 0; ib < cfg.GetGlobalInputLength(); ib++) {
742 if (cfg.GetEventsN() > cfg.GetMinEvents()) {
743 rateN = (Float_t)cfg.GetAccGlobalInputN(ii,ib)/(Float_t)cfg.GetEventsN();
744 noise = (rateN > cfg.GetThrN());
747 if (cfg.GetEventsD() > cfg.GetMinEvents()) {
748 rateD = (Float_t)cfg.GetAccGlobalInputD(ii,ib)/(Float_t)cfg.GetEventsD();
749 deadc = (rateD < cfg.GetThrD());
752 if (!withEvN && !withEvD) {
753 // - copy the bit from the old mask
754 gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
755 printf("Mask not changed (just copy the old values)\n");
757 if (!withEvN && withEvD) {
759 // - create a new mask, set the bit to 1
761 //gmask[ii] |= 0x1 << ib;
762 // - copy the bit from the old mask
763 gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
765 // - create a new mask, set the bit to 0
766 gmask[ii] |= 0x0 << ib;
767 printf("Found dead channel %1d:%02d (%4.2f) \n",ii,ib,rateD);
770 if (withEvN && !withEvD) {
772 // - create a new mask, set the bit to 1
774 //gmask[ii] |= 0x1 << ib;
775 // - copy the bit from the old mask
776 gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
778 // - create a new mask, set the bit to 0
779 gmask[ii] |= 0x0 << ib;
780 printf("Found noisy channel %1d:%02d (%4.2f) \n",ii,ib,rateN);
783 if (withEvN && withEvD) {
784 if (!noise && !deadc) {
785 // - create a new mask, set the bit to 1
787 //gmask[ii] |= 0x1 << ib;
788 // - copy the bit from the old mask
789 gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
791 // - create a new mask, set the bit to 0
792 gmask[ii] |= 0x0 << ib;
794 printf("Found noisy channel %1d:%02d (%4.2f) \n",ii,ib,rateN);
796 printf("Found dead channel %1d:%02d (%4.2f) \n",ii,ib,rateD);
802 // check if at least one mask value has been changed from previous version
803 for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
804 printf("Global mask [%1d] %08x \n",ii,gmask[ii]);
805 omask = cfg.GetGlobalMasks()->GetGlobalMask(ii);
806 if (gmask[ii] != omask) {
808 cfg.GetGlobalMasks()->SetGlobalMask(ii,gmask[ii]);
816 cfg.IncGlobalFileVersion();
818 // don't change the file version ("-x.dat")
820 cfg.GetTriggerIO()->WriteGlobalConfig(cfg.GetGlobalFileName(),cfg.GetGlobalMasks());
822 // write last current file
823 WriteLastCurrentFile(cfg,cfg.GetCurrentFileName());
825 status = daqDA_DB_storeFile(cfg.GetGlobalFileName(), cfg.GetGlobalFileName());
827 printf("Failed to export file to DB: %s\n",cfg.GetGlobalFileName());
831 status = daqDA_DB_storeFile(cfg.GetCurrentFileName(), cfg.GetCurrentFileName());
833 printf("Failed to export file to DB: %s\n",cfg.GetCurrentFileName());
841 //*************************************************************//
842 int main(Int_t argc, Char_t **argv)
846 // needed for streamer application
847 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo", "RIO", "TStreamerInfo()");
849 /* check that we got some arguments = list of files */
851 printf("Wrong number of arguments\n");
857 Char_t inputFile[256] = "";
861 strncpy(inputFile, argv[1], 256);
863 printf("MUONTRGda : No input File !\n");
867 // decoding the events
870 Int_t nDateEvents = 0;
875 AliMUONDDLTrigger* ddlTrigger = 0x0;
876 AliMUONDarcHeader* darcHeader = 0x0;
882 // comment out, since we do not retrieve files from database
883 if (!ImportFiles(cfg)) {
884 printf("Import from DB failed\n");
885 printf("For local test set DAQDA_TEST_DIR to the local directory where the Mtg files are located \n");
891 // offline: the run number extracted from the file name
892 //TString tmp(inputFile);
893 //Int_t pos = tmp.First("daq");
894 //tmp = tmp(pos+3,5);
895 //gSystem->Setenv("DATE_RUN_NUMBER",tmp.Data());
896 //gSystem->Exec("echo \"DATE_RUN_NUMBER = \" $DATE_RUN_NUMBER");
898 if(!ExportFiles(cfg)) {
899 printf("ExportFiles failed\n");
903 // FET is triggered by CTP
904 if (GetFetMode(cfg) != 3) {
905 printf("FET is not in mode 3\n");
909 // All 5 global cards are controlled by the Mts proxy
910 if (cfg.GetGlobalMasks()->GetGlobalCrateEnable() != 0x1F) {
911 printf("The MTS proxy does not control all global cards\n");
915 // The global cards are ON (active on the global inputs)
916 if (!cfg.GetGlobalMasks()->GetMasksOn()) {
917 printf("Global masks are not ON\n");
921 // make sure to catch the "rare" calib events (1 every 50s in physics)
922 const Char_t* tableSOD[] = {"ALL", "yes", "CAL", "all", NULL, NULL};
923 monitorDeclareTable(const_cast<char**>(tableSOD));
925 status = monitorSetDataSource(inputFile);
927 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
928 << " " << monitorDecodeError(status) << endl;
931 status = monitorDeclareMp("MUON Trigger monitoring");
933 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
934 << " " << monitorDecodeError(status) << endl;
938 /* define wait event timeout - 1s max */
940 monitorSetNoWaitNetworkTimeout(1000);
942 cout << "MUONTRGda : Reading data from file " << inputFile <<endl;
945 Bool_t doUpdate = false;
951 if (nEvents >= cfg.GetMaxEvents()) break;
952 if (nEvents && nEvents % 100 == 0)
953 cout<<"Cumulated events " << nEvents << endl;
955 // check shutdown condition
956 if (daqDA_checkShutdown())
959 // Skip Events if needed
960 while (cfg.GetSkipEvents()) {
961 status = monitorGetEventDynamic(&event);
966 status = monitorGetEventDynamic(&event);
968 cout << "MUONTRGda : EOF found" << endl;
974 // decoding rawdata headers
975 AliRawReader *rawReader = new AliRawReaderDate(event);
977 Int_t eventType = rawReader->GetType();
978 runNumber = rawReader->GetRunNumber();
982 // SYSTEM_SOFTWARE_TRIGGER_EVENT
983 // DETECTOR_SOFTWARE_TRIGGER_EVENT
984 cfg.SetAlgoNoisyInput(false);
985 cfg.SetAlgoDeadcInput(false);
986 if (eventType == PHYSICS_EVENT) {
987 cfg.SetAlgoNoisyInput(true);
990 } else if (eventType == CALIBRATION_EVENT) {
991 cfg.SetAlgoDeadcInput(true);
999 if (cfg.GetPrintLevel()) printf("\nEvent # %d\n",nEvents);
1001 // decoding MUON payload
1002 AliMUONRawStreamTrigger* rawStream = new AliMUONRawStreamTrigger(rawReader);
1003 // ... without warnings from the decoder !!!
1004 if (!cfg.WithWarnings())
1005 rawStream->DisableWarnings();
1008 while((status = rawStream->NextDDL())) {
1010 if (cfg.GetPrintLevel()) printf("iDDL %d\n", rawStream->GetDDL());
1012 ddlTrigger = rawStream->GetDDLTrigger();
1013 darcHeader = ddlTrigger->GetDarcHeader();
1015 if (rawStream->GetDDL() == 0) {
1016 if (cfg.GetPrintLevel()) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
1017 globalInput = darcHeader->GetGlobalInput();
1018 StoreGlobalInput(cfg,globalInput);
1028 // update configuration files ifrequested event types were found
1029 if (doUpdate && cfg.GetDAFlag())
1030 UpdateGlobalMasks(cfg);
1034 cout << "MUONTRGda: DA enable: \t" << cfg.GetDAFlag() << endl;
1035 cout << "MUONTRGda: Run number: \t" << runNumber << endl;
1036 cout << "MUONTRGda: Nb of DATE events: \t" << nDateEvents << endl;
1037 cout << "MUONTRGda: Nb of events used: \t" << nEvents << endl;
1038 cout << "MUONTRGda: Nb of events used (noise): \t" << cfg.GetEventsN() << endl;
1039 cout << "MUONTRGda: Nb of events used (deadc): \t" << cfg.GetEventsD() << endl;
1040 cout << "MUONTRGda: Minumum nr of events for rate calculation: \t" << cfg.GetMinEvents() << endl;
1041 cout << "MUONTRGda: Maximum nr of analyzed events: \t" << cfg.GetMaxEvents() << endl;
1042 cout << "MUONTRGda: Skip events from start: \t" << cfg.GetSkipEvents() << endl;
1043 cout << "MUONTRGda: Threshold for noisy inputs: \t" << 100*cfg.GetThrN() << "%" << endl;
1044 cout << "MUONTRGda: Threshold for dead inputs: \t" << 100*cfg.GetThrD() << "%" << endl;
1045 cout << "MUONTRGda: Print level: \t" << cfg.GetPrintLevel() << endl;
1046 cout << "MUONTRGda: Show decoder warnings: \t" << cfg.WithWarnings() << endl;
1048 printf("MUONTRGda: Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());