4 Contact: Franck Manso <manso@clermont.in2p3.fr>
5 Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_mtrda.html
9 Number of events needed: 1000 events
10 Input files: MtgGlobalCrate.dat MtgRegionalCrate.dat MtgLocalMask.dat MtgLocalLut.dat MtgCurrent.dat DAConfig.dat
11 Output Files: ExportedFiles.dat MtgGlobalCrate.dat
12 Trigger types used: PHYSICS_EVENT CALIBRATION_EVENT
15 //////////////////////////////////////////////////////////////////////////////
16 // Detector Algorithm for the MUON trigger configuration. //
18 // Calculates masks for the global trigger input, by looking at dead //
19 // channels in calibration events and at noisy channels in physics events. //
20 // Transfers trigger configuration files to the File Exchange Server and //
21 // writes them (if modified) into the trigger configuration data base. //
24 // Christian Fink (formerly at Subatech, Nantes) //
25 // Franck Manso (LPC Clermont-Ferrand, manso@clermont.in2p3.fr) //
26 // Bogdan Vulpescu (LPC Clermont-Ferrand, vulpescu@clermont.in2p3.fr) //
28 //////////////////////////////////////////////////////////////////////////////
39 #include <Riostream.h>
44 #include "AliRawReaderDate.h"
46 #include "AliMpConstants.h"
47 #include "AliMUONRawStreamTrigger.h"
48 #include "AliMUONRawStreamTriggerHP.h"
49 #include "AliMUONDarcHeader.h"
50 #include "AliMUONDDLTrigger.h"
51 #include "AliMUONVStore.h"
52 #include "AliMUON1DArray.h"
53 #include "AliMUONTriggerIO.h"
54 #include "AliMUONRegionalTriggerConfig.h"
55 #include "AliMUONGlobalCrateConfig.h"
56 #include "AliMUONTriggerCrateConfig.h"
61 #include "TStopwatch.h"
63 #include "TPluginManager.h"
65 /// class for DA run parameters and DA working space
66 class AliDAConfig : TObject {
71 fDAConfigFileName("DAConfig.dat"),
72 fCurrentFileName("MtgCurrent.dat"),
73 fLastCurrentFileName("MtgLastCurrent.dat"),
79 fRegionalFileName(""),
80 fLocalMaskFileName(""),
81 fLocalLutFileName(""),
82 fSignatureFileName(""),
83 fGlobalFileVersion(0),
84 fRegionalFileVersion(0),
85 fLocalMaskFileVersion(0),
86 fLocalLutFileVersion(0),
87 fSignatureFileVersion(0),
88 fGlobalFileLastVersion(0),
89 fRegionalFileLastVersion(0),
90 fLocalMaskFileLastVersion(0),
91 fLocalLutFileLastVersion(0),
98 fTriggerIO(new AliMUONTriggerIO),
99 fAlgoNoisyInput(false),
100 fAlgoDeadcInput(false),
106 fWithWarnings(false),
107 fUseFastDecoder(false),
108 fNLocalBoard(AliMpConstants::TotalNofLocalBoards()+1)
110 /// default constructor
111 for (Int_t ii = 0; ii < kGlobalInputs; ii++) {
112 for (Int_t il = 0; il < kGlobalInputLength; il++) {
113 fAccGlobalInputN[ii][il] = 0;
114 fAccGlobalInputD[ii][il] = 0;
117 fLocalMasks = new AliMUON1DArray(fNLocalBoard);
118 fRegionalMasks = new AliMUONRegionalTriggerConfig();
119 fGlobalMasks = new AliMUONGlobalCrateConfig();
122 virtual ~AliDAConfig()
126 delete fRegionalMasks;
132 /// print DA parameters
133 printf("DA config file name: %s \n",GetDAConfigFileName());
134 printf("Current file name: %s \n",GetCurrentFileName());
135 printf("Last current file name: %s \n",GetLastCurrentFileName());
136 printf("Global file name: %s (%d %d)\n",GetGlobalFileName(),GetGlobalFileVersion(),GetGlobalFileLastVersion());
137 printf("Regional file name: %s (%d %d)\n",GetRegionalFileName(),GetRegionalFileVersion(),GetRegionalFileLastVersion());
138 printf("Local mask file name: %s (%d %d)\n",GetLocalMaskFileName(),GetLocalMaskFileVersion(),GetLocalMaskFileLastVersion());
139 printf("Local LUT file name: %s (%d %d)\n",GetLocalLutFileName(),GetLocalLutFileVersion(),GetLocalLutFileLastVersion());
140 printf("Signature file name: %s (%d)\n",GetSignatureFileName(),GetSignatureFileVersion());
143 /// name of the DA configuration file from detector DB
144 const Char_t* GetDAConfigFileName() { return fDAConfigFileName.Data(); }
145 /// file with current versions of the configuration files, usually MtgCurrent.dat
146 const Char_t* GetCurrentFileName() { return fCurrentFileName.Data(); }
147 /// last known versions of the configuration files, usually MtgLastCurrent.dat
148 const Char_t* GetLastCurrentFileName() { return fLastCurrentFileName.Data(); }
150 /// name of the Start-of-data field in MtgCurrent.dat
151 const Char_t* GetSodName() { return fSodName.Data(); }
152 /// flag value of the Start-of-data field in MtgCurrent.dat
153 Int_t GetSodFlag() const { return fSodFlag; }
155 /// name of the Detector Algorithm field in MtgCurrent.dat
156 const Char_t* GetDAName() { return fDAName.Data(); }
157 /// flag value of the Detector Algorithm field in MtgCurrent.dat
158 Int_t GetDAFlag() const { return fDAFlag; }
160 /// global crate configuration file name
161 const Char_t* GetGlobalFileName() { return fGlobalFileName.Data(); }
162 /// regional crate configuration file name
163 const Char_t* GetRegionalFileName() { return fRegionalFileName.Data(); }
164 /// masks for the local cards, file name
165 const Char_t* GetLocalMaskFileName() { return fLocalMaskFileName.Data(); }
166 /// transverse momentum Look-Up-Table, file name
167 const Char_t* GetLocalLutFileName() { return fLocalLutFileName.Data(); }
168 /// signature file name
169 const Char_t* GetSignatureFileName() { return fSignatureFileName.Data(); }
171 /// version of the global crate configuration in the detector DB
172 Int_t GetGlobalFileVersion() const { return fGlobalFileVersion; }
173 /// version of the regional crate configuration in the detector DB
174 Int_t GetRegionalFileVersion() const { return fRegionalFileVersion; }
175 /// version of the masks for the local cards in the detector DB
176 Int_t GetLocalMaskFileVersion() const { return fLocalMaskFileVersion; }
177 /// version of the transverse momentum Look-Up-Table in the detector DB
178 Int_t GetLocalLutFileVersion() const { return fLocalLutFileVersion; }
179 /// version of the signature file in the detector DB
180 Int_t GetSignatureFileVersion() const { return fSignatureFileVersion; }
182 /// last known version of the global crate configuration
183 Int_t GetGlobalFileLastVersion() const { return fGlobalFileLastVersion; }
184 /// last known version of the regional crate configuration
185 Int_t GetRegionalFileLastVersion() const { return fRegionalFileLastVersion; }
186 /// last known version of the masks for the local cards
187 Int_t GetLocalMaskFileLastVersion() const { return fLocalMaskFileLastVersion; }
188 /// last known version of the transverse momentum Look-Up-Table
189 Int_t GetLocalLutFileLastVersion() const { return fLocalLutFileLastVersion; }
191 /// store for the masks for the local cards (own)
192 AliMUONVStore* GetLocalMasks() const { return fLocalMasks; }
193 /// configuration object for the regional crate (own)
194 AliMUONRegionalTriggerConfig* GetRegionalMasks() const { return fRegionalMasks; }
195 /// configuration object for the global crate (own)
196 AliMUONGlobalCrateConfig* GetGlobalMasks() const { return fGlobalMasks; }
198 /// read/write configurations, masks and LUT to/from online files (own)
199 AliMUONTriggerIO* GetTriggerIO() const { return fTriggerIO; }
201 /// number of accumulated PHYSICS events for noisy channels analysis
202 Int_t GetEventsN() const { return fEventsN; }
203 /// number of accumulated CALIBRATION events for dead channels analysis
204 Int_t GetEventsD() const { return fEventsD; }
206 /// print verbosity of the DA
207 Int_t GetPrintLevel() const { return fPrintLevel; }
209 /// select PHYSICS events for noisy channels analysis
210 Bool_t GetAlgoNoisyInput() const { return fAlgoNoisyInput; }
211 /// select CALIBRATION events for dead channels analysis
212 Bool_t GetAlgoDeadcInput() const { return fAlgoDeadcInput; }
214 /// threshold for noisy inputs (fraction of events)
215 Float_t GetThrN() const { return fThrN; }
216 /// threshold for dead inputs (fraction of events)
217 Float_t GetThrD() const { return fThrD; }
219 /// minumum nr of events for rate calculation
220 Int_t GetMinEvents() const { return fMinEvents; }
221 /// maximum number of events to analyze
222 Int_t GetMaxEvents() const { return fMaxEvents; }
223 /// number of events to skip from start
224 Int_t GetSkipEvents() const { return fSkipEvents; }
226 /// show warnings from the raw data decoder
227 Bool_t WithWarnings() const { return fWithWarnings; }
228 /// use the high-performance (HP) decoder
229 Bool_t UseFastDecoder() const { return fUseFastDecoder; }
231 /// number of global input words
232 Int_t GetGlobalInputs() const { return kGlobalInputs; }
233 /// length in bits of a global input word
234 Int_t GetGlobalInputLength() const { return kGlobalInputLength; }
236 /// get accumulated values for bit "ib" from global input word "ii", PHYSICS events
237 Int_t GetAccGlobalInputN(Int_t ii, Int_t ib) const { return fAccGlobalInputN[ii][ib]; }
238 /// get accumulated values for bit "ib" from global input word "ii", CALIBRATION events
239 Int_t GetAccGlobalInputD(Int_t ii, Int_t ib) const { return fAccGlobalInputD[ii][ib]; }
241 /// set the name of the Start-of-data field in MtgCurrent.dat
242 void SetSodName(Char_t *name) { fSodName = TString(name); }
243 /// set the flag value of the Start-of-data field in MtgCurrent.dat
244 void SetSodFlag(Int_t flag) { fSodFlag = flag; }
246 /// set the name of the Detector Algorithm field in MtgCurrent.dat
247 void SetDAName(Char_t *name) { fDAName = TString(name); }
248 /// set the flag value of the Detector Algorithm field in MtgCurrent.dat
249 void SetDAFlag(Int_t flag) { fDAFlag = flag; }
251 /// set the global crate configuration file name
252 void SetGlobalFileName(const Char_t *name) { fGlobalFileName = TString(name); }
253 /// set the regional crate configuration file name
254 void SetRegionalFileName(const Char_t *name) { fRegionalFileName = TString(name); }
255 /// set the masks for the local cards, file name
256 void SetLocalMaskFileName(const Char_t *name) { fLocalMaskFileName = TString(name); }
257 /// set the transverse momentum Look-Up-Table, file name
258 void SetLocalLutFileName(const Char_t *name) { fLocalLutFileName = TString(name); }
259 /// set the signature file name
260 void SetSignatureFileName(const Char_t *name) { fSignatureFileName = TString(name); }
262 /// set the version of the global crate configuration in the detector DB
263 void SetGlobalFileVersion(Int_t ver) { fGlobalFileVersion = ver; }
264 /// set the version of the regional crate configuration in the detector DB
265 void SetRegionalFileVersion(Int_t ver) { fRegionalFileVersion = ver; }
266 /// set the version of the masks for the local cards in the detector DB
267 void SetLocalMaskFileVersion(Int_t ver) { fLocalMaskFileVersion = ver; }
268 /// set the version of the transverse momentum Look-Up-Table in the detector DB
269 void SetLocalLutFileVersion(Int_t ver) { fLocalLutFileVersion = ver; }
270 /// set the version of the signature file in the detector DB
271 void SetSignatureFileVersion(Int_t ver) { fSignatureFileVersion = ver; }
273 /// set the last known version of the global crate configuration
274 void SetGlobalFileLastVersion(Int_t ver) { fGlobalFileLastVersion = ver; }
275 /// set the last known version of the regional crate configuration
276 void SetRegionalFileLastVersion(Int_t ver) { fRegionalFileLastVersion = ver; }
277 /// set the last known version of the masks for the local cards
278 void SetLocalMaskFileLastVersion(Int_t ver) { fLocalMaskFileLastVersion = ver; }
279 /// set the last known version of the transverse momentum Look-Up-Table
280 void SetLocalLutFileLastVersion(Int_t ver) { fLocalLutFileLastVersion = ver; }
282 /// increment the number of selected PHYSICS events
283 void IncNoiseEvent() { fEventsN++; }
284 /// increment the number of selected CALIBRATION events
285 void IncDeadcEvent() { fEventsD++; }
287 /// count the value of the bit "ib" of global input word "ii" (PHYSICS events)
288 void AddAccGlobalInputN(Int_t ii, Int_t ib, Int_t val) { fAccGlobalInputN[ii][ib] += val; }
289 /// count the value of the bit "ib" of global input word "ii" (CALIBRATION events)
290 void AddAccGlobalInputD(Int_t ii, Int_t ib, Int_t val) { fAccGlobalInputD[ii][ib] += val; }
292 /// set the print verbosity level of the DA
293 void SetPrintLevel(Int_t level) { fPrintLevel = level; }
295 /// select PHYSICS events for noisy channels analysis
296 void SetAlgoNoisyInput(Bool_t val) { fAlgoNoisyInput = val; }
297 /// select CALIBRATION events for dead channels analysis
298 void SetAlgoDeadcInput(Bool_t val) { fAlgoDeadcInput = val; }
300 /// set the threshold for noisy inputs (fraction of events)
301 void SetThrN(Float_t val) { fThrN = val; }
302 /// set the threshold for dead inputs (fraction of events)
303 void SetThrD(Float_t val) { fThrD = val; }
305 /// set the minumum nr of events for rate calculation
306 void SetMinEvents(Int_t val) { fMinEvents = val; }
307 /// set the maximum number of events to analyze
308 void SetMaxEvents(Int_t val) { fMaxEvents = val; }
309 /// set the number of events to skip from start
310 void SetSkipEvents(Int_t val) { fSkipEvents = val; }
312 /// set/unset to show warnings from the raw data decoder
313 void SetWithWarnings() { fWithWarnings = true; }
314 /// set/unset the use of the high-performance (HP) decoder
315 void SetUseFastDecoder() { fUseFastDecoder = true; }
317 /// increment version of the global crate configuration file
318 void IncGlobalFileVersion() { fGlobalFileVersion++; }
319 /// count skipped events
320 void DecSkipEvents() { fSkipEvents--; }
324 /// copy constructor, not implemented
325 AliDAConfig (const AliDAConfig& cfg);
326 /// assignment operator, not implemented
327 AliDAConfig& operator=(const AliDAConfig& cfg);
329 const TString fDAConfigFileName; //!< name of the DA configuration file from detector DB
330 const TString fCurrentFileName; //!< usually MtgCurrent.dat
331 const TString fLastCurrentFileName; //!< usually MtgLastCurrent.dat
333 TString fSodName; //!< name of the Start-of-data field in MtgCurrent.dat
334 Int_t fSodFlag; //!< flag value of the Start-of-data field in MtgCurrent.dat
336 TString fDAName; //!< name of the Detector Algorithm field in MtgCurrent.dat
337 Int_t fDAFlag; //!< flag value of the Detector Algorithm field in MtgCurrent.dat (enabled/disabled)
339 TString fGlobalFileName; //!< global crate configuration, file name
340 TString fRegionalFileName; //!< regional crate configuration, file name
341 TString fLocalMaskFileName; //!< masks for the local cards, file name
342 TString fLocalLutFileName; //!< transverse momentum Look-Up-Table, file name
343 TString fSignatureFileName; //!< signature file name
345 Int_t fGlobalFileVersion; //!< version of the global crate configuration in the detector DB
346 Int_t fRegionalFileVersion; //!< version of the regional crate configuration in the detector DB
347 Int_t fLocalMaskFileVersion; //!< version of the masks for the local cards in the detector DB
348 Int_t fLocalLutFileVersion; //!< version of the transverse momentum Look-Up-Table in the detector DB
349 Int_t fSignatureFileVersion; //!< version of the signature file in the detector DB
351 Int_t fGlobalFileLastVersion; //!< last known version of the global crate configuration
352 Int_t fRegionalFileLastVersion; //!< last known version of the regional crate configuration
353 Int_t fLocalMaskFileLastVersion; //!< last known version of the masks for the local cards
354 Int_t fLocalLutFileLastVersion; //!< last known version of the transverse momentum Look-Up-Table
356 Int_t fEventsN; //!< number of accumulated PHYSICS events
357 Int_t fEventsD; //!< number of accumulated CALIBRATION events
359 Int_t fPrintLevel; //!< print verbosity of the DA
361 AliMUONVStore* fLocalMasks; //!< store for the masks for the local cards
362 AliMUONRegionalTriggerConfig* fRegionalMasks; //!< configuration object for the regional crate
363 AliMUONGlobalCrateConfig* fGlobalMasks; //!< configuration object for the global crate
365 AliMUONTriggerIO *fTriggerIO; //!< read/write masks and LUT to/from online files
367 Bool_t fAlgoNoisyInput; //!< select PHYSICS events for noisy channels analysis
368 Bool_t fAlgoDeadcInput; //!< select CALIBRATION events for dead channels analysis
370 Float_t fThrN; //!< threshold for noisy inputs (fraction of events)
371 Float_t fThrD; //!< threshold for dead inputs (fraction of events)
372 Int_t fMinEvents; //!< minumum nr of events for rate calculation
373 Int_t fSkipEvents; //!< number of events to skip from start
374 Int_t fMaxEvents; //!< maximum number of events to analyze
375 Bool_t fWithWarnings; //!< show warnings from the raw data decoder
376 Bool_t fUseFastDecoder; //!< use the high-performance (HP) decoder
378 const Int_t fNLocalBoard; //!< number of local boards
380 enum { kGlobalInputs = 4, //!< number of global input words
381 kGlobalInputLength = 32 //!< length in bits of a global input word
384 Int_t fAccGlobalInputN[kGlobalInputs][kGlobalInputLength]; //!< storage for global input (PHYSICS events)
385 Int_t fAccGlobalInputD[kGlobalInputs][kGlobalInputLength]; //!< storage for global input (CALIBRATION events)
389 //__________________________________________________________________
390 Bool_t ReadDAConfig(AliDAConfig& cfg)
392 /// read run parameters for the DA
397 file = cfg.GetDAConfigFileName();
398 std::ifstream in(gSystem->ExpandPathName(file.Data()));
400 printf("Cannot open DA configuration file %s ; use default values.\n",file.Data());
409 pos = tmp.First(" ");
411 cfg.SetPrintLevel(tmp.Atoi());
415 pos = tmp.First(" ");
417 cfg.SetThrN(tmp.Atof());
421 pos = tmp.First(" ");
423 cfg.SetThrD(tmp.Atof());
427 pos = tmp.First(" ");
429 cfg.SetMinEvents(tmp.Atoi());
433 pos = tmp.First(" ");
435 cfg.SetSkipEvents(tmp.Atoi());
439 pos = tmp.First(" ");
441 cfg.SetMaxEvents(tmp.Atoi());
445 pos = tmp.First(" ");
447 if (tmp.Atoi() != 0) cfg.SetWithWarnings();
451 pos = tmp.First(" ");
453 if (tmp.Atoi() != 0) cfg.SetUseFastDecoder();
459 //__________________________________________________________________
460 void WriteLastCurrentFile(AliDAConfig& cfg, TString currentFile)
462 /// write last current file
467 out.open(file.Data());
468 out << cfg.GetSodName() << " " << cfg.GetSodFlag() << endl;
469 out << cfg.GetDAName() << " " << cfg.GetDAFlag() << endl;
471 out << cfg.GetGlobalFileName() << " " << cfg.GetGlobalFileVersion() << endl;
472 out << cfg.GetRegionalFileName() << " " << cfg.GetRegionalFileVersion() << endl;
473 out << cfg.GetLocalMaskFileName() << " " << cfg.GetLocalMaskFileVersion() << endl;
474 out << cfg.GetLocalLutFileName() << " " << cfg.GetLocalLutFileVersion() << endl;
475 out << cfg.GetSignatureFileName() << " " << cfg.GetSignatureFileVersion() << endl;
480 //___________________________________________________________________________________________
481 Bool_t ReadCurrentFile(AliDAConfig& cfg, TString currentFile, Bool_t lastCurrentFlag = false)
483 /// read last current file name and version
491 std::ifstream in(gSystem->ExpandPathName(file.Data()));
493 printf("Cannot open last current file %s\n",currentFile.Data());
499 sscanf(line, "%s %d", name, &flag);
500 cfg.SetSodName(name);
501 cfg.SetSodFlag(flag);
502 if (cfg.GetPrintLevel()) printf("Sod Flag %d\n", cfg.GetSodFlag());
506 sscanf(line, "%s %d", name, &flag);
509 if (cfg.GetPrintLevel()) printf("DA Flag: %d\n", cfg.GetDAFlag());
514 Int_t pos = tmp.First(" ");
515 TString tmp1 = tmp(0, pos);
516 cfg.SetGlobalFileName(tmp1.Data());
518 if (!lastCurrentFlag) {
519 cfg.SetGlobalFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
520 if (cfg.GetPrintLevel()) printf("Global File Name: %s version: %d\n",
521 cfg.GetGlobalFileName(), cfg.GetGlobalFileVersion());
523 cfg.SetGlobalFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
524 if (cfg.GetPrintLevel()) printf("Global File Name: %s last version: %d\n",
525 cfg.GetGlobalFileName(), cfg.GetGlobalFileLastVersion());
531 pos = tmp.First(" ");
533 cfg.SetRegionalFileName(tmp1.Data());
535 if (!lastCurrentFlag) {
536 cfg.SetRegionalFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
537 if (cfg.GetPrintLevel()) printf("Regional File Name: %s version: %d\n",
538 cfg.GetRegionalFileName(), cfg.GetRegionalFileVersion());
541 cfg.SetRegionalFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
542 if (cfg.GetPrintLevel()) printf("Regional File Name: %s last version: %d\n",
543 cfg.GetRegionalFileName(), cfg.GetRegionalFileLastVersion());
549 pos = tmp.First(" ");
551 cfg.SetLocalMaskFileName(tmp1.Data());
553 if (!lastCurrentFlag) {
554 cfg.SetLocalMaskFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
555 if (cfg.GetPrintLevel()) printf("Mask File Name: %s version: %d\n",
556 cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileVersion());
558 cfg.SetLocalMaskFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
559 if (cfg.GetPrintLevel()) printf("Mask File Name: %s last version: %d\n",
560 cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileLastVersion());
565 pos = tmp.First(" ");
567 cfg.SetLocalLutFileName(tmp1.Data());
569 if (!lastCurrentFlag) {
570 cfg.SetLocalLutFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
571 if (cfg.GetPrintLevel()) printf("Lut File Name: %s version: %d\n",
572 cfg.GetLocalLutFileName(), cfg.GetLocalLutFileVersion());
574 cfg.SetLocalLutFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
575 if (cfg.GetPrintLevel()) printf("Lut File Name: %s last version: %d\n",
576 cfg.GetLocalLutFileName(), cfg.GetLocalLutFileLastVersion());
581 pos = tmp.First(" ");
583 cfg.SetSignatureFileName(tmp1.Data());
584 cfg.SetSignatureFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
585 if (cfg.GetPrintLevel()) printf("Lut File Name: %s version: %d\n",
586 cfg.GetSignatureFileName(), cfg.GetSignatureFileVersion());
592 void ReadFileNames(AliDAConfig& cfg)
594 /// if last current file does not exist than read current file
596 if (!ReadCurrentFile(cfg,cfg.GetLastCurrentFileName(), true))
598 ReadCurrentFile(cfg,cfg.GetCurrentFileName(), true);
601 // any case read current file
602 ReadCurrentFile(cfg,cfg.GetCurrentFileName());
607 Bool_t ExportFiles(AliDAConfig& cfg)
609 /// Export files to FES
611 // env variables have to be set (suppose by ECS ?)
612 // setenv DATE_FES_PATH
613 // setenv DATE_RUN_NUMBER
614 // setenv DATE_ROLE_NAME
615 // setenv DATE_DETECTOR_CODE
618 gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
619 gSystem->Setenv("DAQDA_TEST_DIR", "/alisoft/FES");
625 Bool_t modified = false;
626 Bool_t globalExported = false;
629 TString fileExp("ExportedFiles.dat");
632 out.open(fileExp.Data());
634 printf("Failed to create file: %s\n",file.Data());
638 // check if MtgLastCurrent.dat exists
639 // if not, do initial export of all files
640 Bool_t initFES = false;
641 if (gSystem->AccessPathName("MtgLastCurrent.dat"))
643 if (initFES) printf("Copy all configuration files to the FES.\n");
645 file = cfg.GetLocalMaskFileName();
646 if ((cfg.GetLocalMaskFileLastVersion() != cfg.GetLocalMaskFileVersion()) || initFES) {
648 status = daqDA_FES_storeFile(file.Data(), "LOCAL");
650 printf("Failed to export file: %s\n",cfg.GetLocalMaskFileName());
653 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetLocalMaskFileName());
654 out << cfg.GetLocalMaskFileName() << endl;
657 file = cfg.GetLocalLutFileName();
658 if ((cfg.GetLocalLutFileLastVersion() != cfg.GetLocalLutFileVersion()) || initFES) {
660 status = daqDA_FES_storeFile(file.Data(), "LUT");
662 printf("Failed to export file: %s\n",cfg.GetLocalLutFileName());
665 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetLocalLutFileName());
666 out << cfg.GetLocalLutFileName() << endl;
670 file = cfg.GetGlobalFileName();
671 if ((cfg.GetGlobalFileLastVersion() != cfg.GetGlobalFileVersion()) || modified || initFES) {
673 globalExported = true;
674 status = daqDA_FES_storeFile(file.Data(), "GLOBAL");
676 printf("Failed to export file: %s\n",cfg.GetGlobalFileName());
679 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetGlobalFileName());
680 out << cfg.GetGlobalFileName() << endl;
683 file = cfg.GetRegionalFileName();
684 if ( (cfg.GetRegionalFileLastVersion() != cfg.GetRegionalFileVersion()) || modified || initFES) {
685 status = daqDA_FES_storeFile(file.Data(), "REGIONAL");
687 printf("Failed to export file: %s\n",cfg.GetRegionalFileName());
690 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetRegionalFileName());
691 out << cfg.GetRegionalFileName() << endl;
693 // needed for the initialisation of the mapping
694 if (!globalExported) {
695 file = cfg.GetGlobalFileName();
696 status = daqDA_FES_storeFile(file.Data(), "GLOBAL");
698 printf("Failed to export file: %s\n",cfg.GetGlobalFileName());
701 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetGlobalFileName());
702 out << cfg.GetGlobalFileName() << endl;
709 // export Exported file to FES anyway
710 status = daqDA_FES_storeFile(fileExp.Data(), "EXPORTED");
712 printf("Failed to export file: %s\n", fileExp.Data());
715 if(cfg.GetPrintLevel()) printf("Export file: %s\n",fileExp.Data());
717 // write last current file
718 WriteLastCurrentFile(cfg,cfg.GetLastCurrentFileName());
724 Bool_t ImportFiles(AliDAConfig& cfg)
726 /// copy locally a file from daq detector config db
727 /// The current detector is identified by detector code in variable
728 /// DATE_DETECTOR_CODE. It must be defined.
729 /// If environment variable DAQDA_TEST_DIR is defined, files are copied from
730 /// DAQDA_TEST_DIR instead of the database.
731 /// The usual environment variables are not needed.
736 gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
739 status = daqDA_DB_getFile(cfg.GetDAConfigFileName(), cfg.GetDAConfigFileName());
741 printf("Failed to get DA config file from DB: %s\n",cfg.GetDAConfigFileName());
747 status = daqDA_DB_getFile(cfg.GetCurrentFileName(), cfg.GetCurrentFileName());
749 printf("Failed to get current config file from DB: %s\n",cfg.GetCurrentFileName());
755 status = daqDA_DB_getFile(cfg.GetGlobalFileName(), cfg.GetGlobalFileName());
757 printf("Failed to get current config file from DB: %s\n", cfg.GetGlobalFileName());
761 status = daqDA_DB_getFile(cfg.GetRegionalFileName(), cfg.GetRegionalFileName());
763 printf("Failed to get current config file from DB: %s\n",cfg.GetRegionalFileName());
767 status = daqDA_DB_getFile(cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileName());
769 printf("Failed to get current config file from DB: %s\n",cfg.GetLocalMaskFileName());
773 status = daqDA_DB_getFile(cfg.GetLocalLutFileName(), cfg.GetLocalLutFileName());
775 printf("Failed to get current config file from DB: %s\n",cfg.GetLocalLutFileName());
783 void ReadMaskFiles(AliDAConfig& cfg)
787 const Char_t* localFile = cfg.GetLocalMaskFileName();
788 const Char_t* regionalFile = cfg.GetRegionalFileName();
789 const Char_t* globalFile = cfg.GetGlobalFileName();
791 cfg.GetTriggerIO()->ReadConfig(localFile, regionalFile, globalFile, cfg.GetLocalMasks(), cfg.GetRegionalMasks(), cfg.GetGlobalMasks());
794 //______________________________________________________________
795 UInt_t GetFetMode(const AliDAConfig & cfg)
797 /// FET mode = 3 to run algorithm for dead global inputs
801 return cfg.GetGlobalMasks()->GetFetRegister(3);
805 //______________________________________________________________
806 void StoreGlobalInput(AliDAConfig& cfg, const UInt_t * const globalInput)
808 /// accumulate and build statistics of global input values
810 for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
811 for (Int_t ib = 0; ib < cfg.GetGlobalInputLength(); ib++) {
813 if (cfg.GetAlgoNoisyInput())
814 cfg.AddAccGlobalInputN(ii,ib,((globalInput[ii] >> ib) & 0x1));
815 if (cfg.GetAlgoDeadcInput())
816 cfg.AddAccGlobalInputD(ii,ib,((globalInput[ii] >> ib) & 0x1));
822 //______________________________________________________________
823 void UpdateGlobalMasks(AliDAConfig& cfg)
825 /// update the global masks
828 gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
831 Float_t rateN = 0.0, rateD = 0.0;
832 UInt_t gmask[4], omask;
833 Bool_t noise, deadc, withEvN, withEvD, updated = false;
835 for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
838 for (Int_t ib = 0; ib < cfg.GetGlobalInputLength(); ib++) {
844 if (cfg.GetEventsN() > cfg.GetMinEvents()) {
845 rateN = (Float_t)cfg.GetAccGlobalInputN(ii,ib)/(Float_t)cfg.GetEventsN();
846 noise = (rateN > cfg.GetThrN());
849 if (cfg.GetEventsD() > cfg.GetMinEvents()) {
850 rateD = (Float_t)cfg.GetAccGlobalInputD(ii,ib)/(Float_t)cfg.GetEventsD();
851 deadc = (rateD < cfg.GetThrD());
854 if (!withEvN && !withEvD) {
855 // - copy the bit from the old mask
856 gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
857 if (cfg.GetPrintLevel())
858 printf("Mask not changed (just copy the old values)\n");
860 if (!withEvN && withEvD) {
862 // - create a new mask, set the bit to 1
864 //gmask[ii] |= 0x1 << ib;
865 // - copy the bit from the old mask
866 gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
868 // - create a new mask, set the bit to 0
869 gmask[ii] |= 0x0 << ib;
870 if (cfg.GetPrintLevel())
871 printf("Found dead channel %1d:%02d (%4.2f) \n",ii,ib,rateD);
874 if (withEvN && !withEvD) {
876 // - create a new mask, set the bit to 1
878 //gmask[ii] |= 0x1 << ib;
879 // - copy the bit from the old mask
880 gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
882 // - create a new mask, set the bit to 0
883 gmask[ii] |= 0x0 << ib;
884 if (cfg.GetPrintLevel())
885 printf("Found noisy channel %1d:%02d (%4.2f) \n",ii,ib,rateN);
888 if (withEvN && withEvD) {
889 if (!noise && !deadc) {
890 // - create a new mask, set the bit to 1
892 //gmask[ii] |= 0x1 << ib;
893 // - copy the bit from the old mask
894 gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
896 // - create a new mask, set the bit to 0
897 gmask[ii] |= 0x0 << ib;
898 if (cfg.GetPrintLevel()) {
900 printf("Found noisy channel %1d:%02d (%4.2f) \n",ii,ib,rateN);
902 printf("Found dead channel %1d:%02d (%4.2f) \n",ii,ib,rateD);
909 // check if at least one mask value has been changed from previous version
910 for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
911 printf("Global mask [%1d] %08x \n",ii,gmask[ii]);
912 omask = cfg.GetGlobalMasks()->GetGlobalMask(ii);
913 if (gmask[ii] != omask) {
915 cfg.GetGlobalMasks()->SetGlobalMask(ii,gmask[ii]);
923 cfg.IncGlobalFileVersion();
925 // don't change the file version ("-x.dat")
927 cfg.GetTriggerIO()->WriteGlobalConfig(cfg.GetGlobalFileName(),cfg.GetGlobalMasks());
929 // write last current file
930 WriteLastCurrentFile(cfg,cfg.GetCurrentFileName());
932 status = daqDA_DB_storeFile(cfg.GetGlobalFileName(), cfg.GetGlobalFileName());
934 printf("Failed to export file to DB: %s\n",cfg.GetGlobalFileName());
938 status = daqDA_DB_storeFile(cfg.GetCurrentFileName(), cfg.GetCurrentFileName());
940 printf("Failed to export file to DB: %s\n",cfg.GetCurrentFileName());
948 //*************************************************************//
949 int main(Int_t argc, Char_t **argv)
953 // needed for streamer application
954 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo", "RIO", "TStreamerInfo()");
956 /* check that we got some arguments = list of files */
958 printf("Wrong number of arguments\n");
964 Char_t inputFile[256] = "";
968 strncpy(inputFile, argv[1], 256);
970 printf("MUONTRGda : No input File !\n");
974 // decoding the events
977 Int_t nDateEvents = 0;
983 AliMUONDDLTrigger* ddlTrigger = 0x0;
984 AliMUONDarcHeader* darcHeader = 0x0;
985 // new (fast) decoder
986 const AliMUONRawStreamTriggerHP::AliHeader* darcHeaderHP = 0x0;
992 // comment out, since we do not retrieve files from database
993 if (!ImportFiles(cfg)) {
994 printf("Import from DB failed\n");
995 printf("For local test set DAQDA_TEST_DIR to the local directory where the Mtg files are located \n");
1002 // the run number extracted from the file name
1003 TString tmp(inputFile);
1004 Int_t pos = tmp.First("daq");
1006 gSystem->Setenv("DATE_RUN_NUMBER",tmp.Data());
1007 gSystem->Exec("echo \"DATE_RUN_NUMBER = \" $DATE_RUN_NUMBER");
1010 if(!ExportFiles(cfg)) {
1011 printf("ExportFiles failed\n");
1015 if (!cfg.GetDAFlag()) {
1017 cout << "MUONTRGda: DA enable: " << cfg.GetDAFlag() << endl;
1018 cout << "MUONTRGda: Print level: " << cfg.GetPrintLevel() << endl;
1020 printf("MUONTRGda: Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
1026 // FET is triggered by CTP
1027 Bool_t modeFET3 = kTRUE;
1028 if (GetFetMode(cfg) != 3) {
1029 printf("FET is not in mode 3. Only PHYSICS events will be analysed (noisy channels)\n");
1033 // All 5 global cards are controlled by the Mts proxy
1034 if (cfg.GetGlobalMasks()->GetGlobalCrateEnable() != 0x1F) {
1035 printf("The MTS proxy does not control all global cards\n");
1039 // The global cards are ON (active on the global inputs)
1040 if (!cfg.GetGlobalMasks()->GetMasksOn()) {
1041 printf("Global masks are not ON\n");
1045 // make sure to catch the "rare" calib events (1 every 50s in physics)
1046 const Char_t* tableSOD[] = {"ALL", "yes", "CAL", "all", NULL, NULL};
1047 monitorDeclareTable(const_cast<char**>(tableSOD));
1049 status = monitorSetDataSource(inputFile);
1051 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
1052 << " " << monitorDecodeError(status) << endl;
1055 status = monitorDeclareMp("MUON Trigger monitoring");
1057 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
1058 << " " << monitorDecodeError(status) << endl;
1062 /* define wait event timeout - 1s max */
1064 monitorSetNoWaitNetworkTimeout(1000);
1066 cout << "MUONTRGda : Reading data from file " << inputFile <<endl;
1068 UInt_t *globalInput = new UInt_t[4];
1069 Bool_t doUpdate = false;
1070 Int_t runNumber = 0;
1075 if (nEvents >= cfg.GetMaxEvents()) break;
1076 if (cfg.GetPrintLevel()) {
1077 if (nEvents && nEvents % 1000 == 0)
1078 cout<<"Cumulated events " << nEvents << endl;
1080 // check shutdown condition
1081 if (daqDA_checkShutdown())
1084 // Skip Events if needed
1085 while (cfg.GetSkipEvents()) {
1086 status = monitorGetEventDynamic(&event);
1087 cfg.DecSkipEvents();
1091 status = monitorGetEventDynamic(&event);
1093 cout << "MUONTRGda : EOF found" << endl;
1099 // decoding rawdata headers
1100 AliRawReader *rawReader = new AliRawReaderDate(event);
1102 Int_t eventType = rawReader->GetType();
1103 runNumber = rawReader->GetRunNumber();
1106 // CALIBRATION_EVENT
1107 // SYSTEM_SOFTWARE_TRIGGER_EVENT
1108 // DETECTOR_SOFTWARE_TRIGGER_EVENT
1109 cfg.SetAlgoNoisyInput(false);
1110 cfg.SetAlgoDeadcInput(false);
1111 if (eventType == PHYSICS_EVENT) {
1112 cfg.SetAlgoNoisyInput(true);
1114 cfg.IncNoiseEvent();
1115 } else if (modeFET3 && eventType == CALIBRATION_EVENT) {
1116 cfg.SetAlgoDeadcInput(true);
1118 cfg.IncDeadcEvent();
1124 if (cfg.GetPrintLevel() == 2) printf("\nEvent # %d\n",nEvents);
1126 // decoding MUON payload
1127 AliMUONVRawStreamTrigger *rawStream = 0x0;
1128 if (cfg.UseFastDecoder()) {
1129 rawStream = new AliMUONRawStreamTriggerHP(rawReader);
1131 rawStream = new AliMUONRawStreamTrigger(rawReader);
1134 // ... without warnings from the decoder !!!
1135 if (!cfg.WithWarnings())
1136 rawStream->DisableWarnings();
1139 while((status = rawStream->NextDDL())) {
1141 if (cfg.GetPrintLevel() == 2) printf("iDDL %d\n", rawStream->GetDDL());
1143 if (rawStream->GetDDL() == 0) {
1144 if (cfg.UseFastDecoder()) {
1145 darcHeaderHP = static_cast<AliMUONRawStreamTriggerHP*>(rawStream)->GetHeaders();
1146 if (cfg.GetPrintLevel() == 2) printf("Global output (fast decoder) %x\n", (Int_t)darcHeaderHP->GetGlobalOutput());
1147 for (Int_t ig = 0; ig < cfg.GetGlobalInputs(); ig++)
1148 globalInput[ig] = darcHeaderHP->GetGlobalInput(ig);
1150 ddlTrigger = rawStream->GetDDLTrigger();
1151 darcHeader = ddlTrigger->GetDarcHeader();
1152 if (cfg.GetPrintLevel() == 2) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
1153 globalInput = darcHeader->GetGlobalInput();
1155 StoreGlobalInput(cfg,globalInput);
1165 // update configuration files ifrequested event types were found
1167 UpdateGlobalMasks(cfg);
1171 cout << "MUONTRGda: DA enable: " << cfg.GetDAFlag() << endl;
1172 cout << "MUONTRGda: Run number: " << runNumber << endl;
1173 cout << "MUONTRGda: Nb of DATE events: " << nDateEvents << endl;
1174 cout << "MUONTRGda: Nb of events used: " << nEvents << endl;
1175 cout << "MUONTRGda: Nb of events used (noise): " << cfg.GetEventsN() << endl;
1176 cout << "MUONTRGda: Nb of events used (deadc): " << cfg.GetEventsD() << endl;
1177 cout << "MUONTRGda: Minumum nr of events for rate calculation: " << cfg.GetMinEvents() << endl;
1178 cout << "MUONTRGda: Maximum nr of analyzed events: " << cfg.GetMaxEvents() << endl;
1179 cout << "MUONTRGda: Skip events from start: " << cfg.GetSkipEvents() << endl;
1180 cout << "MUONTRGda: Threshold for noisy inputs: " << 100*cfg.GetThrN() << "%" << endl;
1181 cout << "MUONTRGda: Threshold for dead inputs: " << 100*cfg.GetThrD() << "%" << endl;
1182 cout << "MUONTRGda: Print level: " << cfg.GetPrintLevel() << endl;
1183 cout << "MUONTRGda: Show decoder warnings: " << cfg.WithWarnings() << endl;
1184 cout << "MUONTRGda: Use the fast decoder: " << cfg.UseFastDecoder() << endl;
1186 printf("MUONTRGda: Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());