]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONTRGda.cxx
Finally got the ResetDetector correct.
[u/mrichter/AliRoot.git] / MUON / MUONTRGda.cxx
1 /*
2 MTR DA for online
3
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
7 Run Type:  PHYSICS
8 DA Type: MON
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
13 */
14
15 //////////////////////////////////////////////////////////////////////////////
16 // Detector Algorithm for the MUON trigger configuration.                   //
17 //                                                                          //
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.      //
22 //                                                                          //
23 // Authors:                                                                 //
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)       //
27 //                                                                          //
28 //////////////////////////////////////////////////////////////////////////////
29
30 //#define OFFLINE
31
32 extern "C" {
33 #include <daqDA.h>
34 }
35
36 #include "event.h"
37 #include "monitor.h"
38
39 #include <Riostream.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42
43 //AliRoot
44 #include "AliRawReaderDate.h"
45
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"
57
58 //ROOT
59 #include "TString.h"
60 #include "TSystem.h"
61 #include "TStopwatch.h"
62 #include "TROOT.h"
63 #include "TPluginManager.h"
64
65 /// class for DA run parameters and DA working space
66 class AliDAConfig : TObject {
67
68 public:
69
70   AliDAConfig() : 
71     fDAConfigFileName("DAConfig.dat"),
72     fCurrentFileName("MtgCurrent.dat"), 
73     fLastCurrentFileName("MtgLastCurrent.dat"), 
74     fSodName(""),
75     fSodFlag(0),
76     fDAName(""),
77     fDAFlag(0),
78     fGlobalFileName(""),
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),
92     fEventsN(0),
93     fEventsD(0),
94     fPrintLevel(0),
95     fLocalMasks(0x0),
96     fRegionalMasks(0x0),
97     fGlobalMasks(0x0),
98     fTriggerIO(new AliMUONTriggerIO),
99     fAlgoNoisyInput(false),
100     fAlgoDeadcInput(false),
101     fThrN(0.1),
102     fThrD(0.9),
103     fMinEvents(10),
104     fSkipEvents(0),
105     fMaxEvents(65535),
106     fWithWarnings(false),
107     fUseFastDecoder(false),
108     fNLocalBoard(AliMpConstants::TotalNofLocalBoards()+1)
109   {
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;
115       }
116     }
117     fLocalMasks    = new AliMUON1DArray(fNLocalBoard);
118     fRegionalMasks = new AliMUONRegionalTriggerConfig();
119     fGlobalMasks   = new AliMUONGlobalCrateConfig();
120   }
121
122   virtual ~AliDAConfig()
123   {
124     /// destructor
125     delete fLocalMasks;
126     delete fRegionalMasks;
127     delete fGlobalMasks; 
128     delete fTriggerIO;
129   }
130   void PrintConfig()
131   {
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());
141   }
142
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(); }
149
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; }
154
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; }
159
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(); }
170
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; }
181
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; }
190
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; }
197
198      /// read/write configurations, masks and LUT to/from online files (own)
199   AliMUONTriggerIO* GetTriggerIO() const { return fTriggerIO; }
200
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; }
205
206      /// print verbosity of the DA
207   Int_t GetPrintLevel() const { return fPrintLevel; }
208
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; }
213
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; }
218
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; }
225
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; }
230
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; }
235
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]; }
240
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; }
245
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; }
250
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); }
261
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; }
272
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; }
281
282      /// increment the number of selected PHYSICS events
283   void IncNoiseEvent() { fEventsN++; }
284      /// increment the number of selected CALIBRATION events
285   void IncDeadcEvent() { fEventsD++; }
286
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; }
291
292      /// set the print verbosity level of the DA
293   void SetPrintLevel(Int_t level) { fPrintLevel = level; }
294
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; }
299
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; }
304
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; }
311
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; }
316
317     /// increment version of the global crate configuration file
318   void IncGlobalFileVersion() { fGlobalFileVersion++; }
319     /// count skipped events
320   void DecSkipEvents() { fSkipEvents--; }
321
322 private:
323
324   /// copy constructor, not implemented
325   AliDAConfig (const AliDAConfig& cfg);
326   /// assignment operator, not implemented
327   AliDAConfig& operator=(const AliDAConfig& cfg);
328
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
332
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
335
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)
338
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
344
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
350   
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
355
356   Int_t   fEventsN; //!< number of accumulated PHYSICS events
357   Int_t   fEventsD; //!< number of accumulated CALIBRATION events
358
359   Int_t   fPrintLevel;  //!< print verbosity of the DA
360
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
364
365   AliMUONTriggerIO *fTriggerIO;  //!< read/write masks and LUT to/from online files
366
367   Bool_t fAlgoNoisyInput; //!< select PHYSICS events for noisy channels analysis
368   Bool_t fAlgoDeadcInput; //!< select CALIBRATION events for dead channels analysis
369
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
377
378   const Int_t fNLocalBoard; //!< number of local boards
379
380   enum { kGlobalInputs = 4,         //!< number of global input words
381          kGlobalInputLength = 32    //!< length in bits of a global input word
382   };
383
384   Int_t fAccGlobalInputN[kGlobalInputs][kGlobalInputLength]; //!< storage for global input (PHYSICS events)
385   Int_t fAccGlobalInputD[kGlobalInputs][kGlobalInputLength]; //!< storage for global input (CALIBRATION events)
386
387 };
388
389 //__________________________________________________________________
390 Bool_t ReadDAConfig(AliDAConfig& cfg)
391 {
392     /// read run parameters for the DA
393
394     char line[80];
395
396     TString file;
397     file = cfg.GetDAConfigFileName();
398     std::ifstream in(gSystem->ExpandPathName(file.Data()));
399     if (!in.good()) {
400       printf("Cannot open DA configuration file %s ; use default values.\n",file.Data());
401       return true;
402     }
403
404     TString tmp;
405     Int_t pos;
406     
407     in.getline(line,80);  
408     tmp = line;
409     pos = tmp.First(" ");
410     tmp = tmp(0,pos);
411     cfg.SetPrintLevel(tmp.Atoi());
412     
413     in.getline(line,80);  
414     tmp = line;
415     pos = tmp.First(" ");
416     tmp = tmp(0,pos);
417     cfg.SetThrN(tmp.Atof());
418
419     in.getline(line,80);  
420     tmp = line;
421     pos = tmp.First(" ");
422     tmp = tmp(0,pos);
423     cfg.SetThrD(tmp.Atof());
424
425     in.getline(line,80);  
426     tmp = line;
427     pos = tmp.First(" ");
428     tmp = tmp(0,pos);
429     cfg.SetMinEvents(tmp.Atoi());
430
431     in.getline(line,80);  
432     tmp = line;
433     pos = tmp.First(" ");
434     tmp = tmp(0,pos);
435     cfg.SetSkipEvents(tmp.Atoi());
436
437     in.getline(line,80);  
438     tmp = line;
439     pos = tmp.First(" ");
440     tmp = tmp(0,pos);
441     cfg.SetMaxEvents(tmp.Atoi());
442
443     in.getline(line,80);  
444     tmp = line;
445     pos = tmp.First(" ");
446     tmp = tmp(0,pos);
447     if (tmp.Atoi() != 0) cfg.SetWithWarnings();
448     
449     in.getline(line,80);  
450     tmp = line;
451     pos = tmp.First(" ");
452     tmp = tmp(0,pos);
453     if (tmp.Atoi() != 0) cfg.SetUseFastDecoder();
454     
455     return true;
456
457 }
458
459 //__________________________________________________________________
460 void WriteLastCurrentFile(AliDAConfig& cfg, TString currentFile)
461 {
462     /// write last current file
463
464     ofstream out;
465     TString file;
466     file = currentFile;
467     out.open(file.Data());
468     out << cfg.GetSodName() << " " << cfg.GetSodFlag() << endl;
469     out << cfg.GetDAName()  << " " << cfg.GetDAFlag()  << endl;
470
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;
476
477     out.close();
478 }
479
480 //___________________________________________________________________________________________
481 Bool_t ReadCurrentFile(AliDAConfig& cfg, TString currentFile, Bool_t lastCurrentFlag = false)
482 {
483     /// read last current file name and version
484
485     char line[80];
486     char name[80];
487     Int_t flag;
488
489     TString file;
490     file = currentFile;
491     std::ifstream in(gSystem->ExpandPathName(file.Data()));
492     if (!in.good()) {
493       printf("Cannot open last current file %s\n",currentFile.Data());
494       return false;
495     }
496     
497     // read SOD 
498     in.getline(line,80);  
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());
503
504     //read DA
505     in.getline(line,80);    
506     sscanf(line, "%s %d", name, &flag);
507     cfg.SetDAName(name);
508     cfg.SetDAFlag(flag);
509     if (cfg.GetPrintLevel()) printf("DA Flag: %d\n", cfg.GetDAFlag());
510
511     // read global
512     in.getline(line,80);    
513     TString tmp(line);
514     Int_t pos =  tmp.First(" ");
515     TString tmp1 = tmp(0, pos);
516     cfg.SetGlobalFileName(tmp1.Data());
517     
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());
522     } else {
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());
526     }
527
528     // read regional
529     in.getline(line,80);
530     tmp = line;
531     pos = tmp.First(" ");
532     tmp1 = tmp(0, pos);
533     cfg.SetRegionalFileName(tmp1.Data());
534
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());
539
540     } else {
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());
544     }
545
546     // read mask
547     in.getline(line,80);    
548     tmp = line;
549     pos = tmp.First(" ");
550     tmp1 = tmp(0, pos);
551     cfg.SetLocalMaskFileName(tmp1.Data());
552
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());
557     } else {
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());
561     }
562     // read Lut
563     in.getline(line,80);    
564     tmp = line;
565     pos = tmp.First(" ");
566     tmp1 = tmp(0, pos);
567     cfg.SetLocalLutFileName(tmp1.Data());
568
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());
573     } else {
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());
577     }
578
579     in.getline(line,80);    
580     tmp = line;
581     pos = tmp.First(" ");
582     tmp1 = tmp(0, pos);
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());
587
588     return true;
589 }
590
591 //_____________
592 void ReadFileNames(AliDAConfig& cfg)
593 {
594   /// if last current file does not exist than read current file
595
596   if (!ReadCurrentFile(cfg,cfg.GetLastCurrentFileName(), true)) 
597     {
598       ReadCurrentFile(cfg,cfg.GetCurrentFileName(), true);
599     } 
600   
601   // any case read current file
602   ReadCurrentFile(cfg,cfg.GetCurrentFileName());
603   
604 }
605
606 //__________________
607 Bool_t ExportFiles(AliDAConfig& cfg)
608 {
609     /// Export files to FES
610
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
616
617 #ifdef OFFLINE
618     gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
619     gSystem->Setenv("DAQDA_TEST_DIR", "/alisoft/FES");
620 #endif
621
622     // update files
623     Int_t status = 0;
624
625     Bool_t modified = false;
626     Bool_t globalExported = false;
627
628     ofstream out;
629     TString fileExp("ExportedFiles.dat");
630     TString file;
631
632     out.open(fileExp.Data());
633     if (!out.good()) {
634         printf("Failed to create file: %s\n",file.Data());
635         return false;
636     }      
637
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"))
642       initFES = true;
643     if (initFES) printf("Copy all configuration files to the FES.\n");
644
645     file = cfg.GetLocalMaskFileName();  
646     if ((cfg.GetLocalMaskFileLastVersion() != cfg.GetLocalMaskFileVersion()) || initFES) {
647       modified = true;
648       status = daqDA_FES_storeFile(file.Data(), "LOCAL");
649       if (status) {
650         printf("Failed to export file: %s\n",cfg.GetLocalMaskFileName());
651         return false;
652       }
653       if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetLocalMaskFileName());
654       out << cfg.GetLocalMaskFileName() << endl;
655     }
656
657     file = cfg.GetLocalLutFileName();
658     if ((cfg.GetLocalLutFileLastVersion() != cfg.GetLocalLutFileVersion()) || initFES) {
659       modified = true;
660       status = daqDA_FES_storeFile(file.Data(), "LUT");
661       if (status) {
662         printf("Failed to export file: %s\n",cfg.GetLocalLutFileName());
663         return false;
664       }
665       if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetLocalLutFileName());
666       out << cfg.GetLocalLutFileName() << endl;
667
668     }
669
670     file = cfg.GetGlobalFileName();
671     if ((cfg.GetGlobalFileLastVersion() != cfg.GetGlobalFileVersion()) || modified || initFES) {
672       modified = true;
673       globalExported = true;
674       status = daqDA_FES_storeFile(file.Data(), "GLOBAL");
675       if (status) {
676         printf("Failed to export file: %s\n",cfg.GetGlobalFileName());
677         return false;
678       }
679       if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetGlobalFileName());
680       out << cfg.GetGlobalFileName() << endl;
681     }
682
683     file = cfg.GetRegionalFileName();
684     if ( (cfg.GetRegionalFileLastVersion() != cfg.GetRegionalFileVersion()) || modified || initFES) {
685       status = daqDA_FES_storeFile(file.Data(), "REGIONAL");
686       if (status) {
687         printf("Failed to export file: %s\n",cfg.GetRegionalFileName());
688         return false;
689       }
690       if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetRegionalFileName());
691       out << cfg.GetRegionalFileName() << endl;
692
693       // needed for the initialisation of the mapping
694       if (!globalExported) {
695         file = cfg.GetGlobalFileName();
696         status = daqDA_FES_storeFile(file.Data(), "GLOBAL");
697         if (status) {
698           printf("Failed to export file: %s\n",cfg.GetGlobalFileName());
699           return false;
700         }
701         if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetGlobalFileName());
702         out << cfg.GetGlobalFileName() << endl;
703       }
704
705     }
706
707     out.close();
708
709     // export Exported file to FES anyway
710     status = daqDA_FES_storeFile(fileExp.Data(), "EXPORTED");
711     if (status) {
712       printf("Failed to export file: %s\n", fileExp.Data());
713       return false;
714     }
715     if(cfg.GetPrintLevel()) printf("Export file: %s\n",fileExp.Data());
716
717     // write last current file
718     WriteLastCurrentFile(cfg,cfg.GetLastCurrentFileName());
719
720     return true;
721 }
722
723 //__________________
724 Bool_t ImportFiles(AliDAConfig& cfg)
725 {
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.
732
733     Int_t status = 0;
734
735 #ifdef OFFLINE
736     gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
737 #endif
738
739     status = daqDA_DB_getFile(cfg.GetDAConfigFileName(), cfg.GetDAConfigFileName());
740     if (status) {
741       printf("Failed to get DA config file from DB: %s\n",cfg.GetDAConfigFileName());
742       return false;
743     }
744  
745     ReadDAConfig(cfg);
746     
747     status = daqDA_DB_getFile(cfg.GetCurrentFileName(), cfg.GetCurrentFileName());
748     if (status) {
749       printf("Failed to get current config file from DB: %s\n",cfg.GetCurrentFileName());
750       return false;
751     }
752     
753     ReadFileNames(cfg);
754
755     status = daqDA_DB_getFile(cfg.GetGlobalFileName(), cfg.GetGlobalFileName());
756     if (status) {
757       printf("Failed to get current config file from DB: %s\n", cfg.GetGlobalFileName());
758       return false;
759     }
760
761     status = daqDA_DB_getFile(cfg.GetRegionalFileName(), cfg.GetRegionalFileName());
762     if (status) {
763       printf("Failed to get current config file from DB: %s\n",cfg.GetRegionalFileName());
764       return false;
765     }
766
767     status = daqDA_DB_getFile(cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileName());
768     if (status) {
769       printf("Failed to get current config file from DB: %s\n",cfg.GetLocalMaskFileName());
770       return false;
771     }
772
773     status = daqDA_DB_getFile(cfg.GetLocalLutFileName(), cfg.GetLocalLutFileName());
774     if (status) {
775       printf("Failed to get current config file from DB: %s\n",cfg.GetLocalLutFileName());
776       return false;
777     }
778  
779     return true;
780 }
781
782 //_____________
783 void ReadMaskFiles(AliDAConfig& cfg)
784 {
785     /// read mask files
786
787     const Char_t* localFile    = cfg.GetLocalMaskFileName();
788     const Char_t* regionalFile = cfg.GetRegionalFileName();
789     const Char_t* globalFile   = cfg.GetGlobalFileName();
790
791     cfg.GetTriggerIO()->ReadConfig(localFile, regionalFile, globalFile, cfg.GetLocalMasks(), cfg.GetRegionalMasks(), cfg.GetGlobalMasks());                     
792 }
793
794 //______________________________________________________________
795 UInt_t GetFetMode(const AliDAConfig & cfg)
796 {
797   /// FET mode = 3 to run algorithm for dead global inputs
798   /// 0x3 prepulse
799   /// 0x0 internal
800
801   return cfg.GetGlobalMasks()->GetFetRegister(3);
802
803 }
804
805 //______________________________________________________________
806 void StoreGlobalInput(AliDAConfig& cfg, const UInt_t * const globalInput) 
807 {
808   /// accumulate and build statistics of global input values
809   
810   for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
811     for (Int_t ib = 0; ib < cfg.GetGlobalInputLength(); ib++) {
812       // lsb -> msb
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));
817     }
818   }
819
820 }
821
822 //______________________________________________________________
823 void UpdateGlobalMasks(AliDAConfig& cfg) 
824 {
825   /// update the global masks
826   
827 #ifdef OFFLINE
828   gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
829 #endif
830
831   Float_t rateN = 0.0, rateD = 0.0;
832   UInt_t gmask[4], omask;
833   Bool_t noise, deadc, withEvN, withEvD, updated = false;
834
835   for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
836     gmask[ii] = 0;
837
838     for (Int_t ib = 0; ib < cfg.GetGlobalInputLength(); ib++) {
839       // lsb -> msb
840       noise = false;
841       deadc = false;
842       withEvN = false;
843       withEvD = false;
844       if (cfg.GetEventsN() > cfg.GetMinEvents()) {
845         rateN = (Float_t)cfg.GetAccGlobalInputN(ii,ib)/(Float_t)cfg.GetEventsN();
846         noise = (rateN > cfg.GetThrN());        
847         withEvN = true;
848       }
849       if (cfg.GetEventsD() > cfg.GetMinEvents()) {
850         rateD = (Float_t)cfg.GetAccGlobalInputD(ii,ib)/(Float_t)cfg.GetEventsD();
851         deadc = (rateD < cfg.GetThrD());
852         withEvD = true;
853       }
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");
859       }
860       if (!withEvN && withEvD) {
861         if (!deadc) {
862           // - create a new mask, set the bit to 1
863           //   not allowed!
864           //gmask[ii] |= 0x1 << ib;
865           // - copy the bit from the old mask
866           gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
867         } else {
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);
872         }
873       }
874       if (withEvN && !withEvD) {
875         if (!noise) {
876           // - create a new mask, set the bit to 1
877           //   not allowed!
878           //gmask[ii] |= 0x1 << ib;
879           // - copy the bit from the old mask
880           gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
881         } else {
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);
886         }
887       }
888       if (withEvN && withEvD) {
889         if (!noise && !deadc) {
890           // - create a new mask, set the bit to 1
891           //   not allowed!
892           //gmask[ii] |= 0x1 << ib;
893           // - copy the bit from the old mask
894           gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
895         } else {
896           // - create a new mask, set the bit to 0
897           gmask[ii] |= 0x0 << ib;
898           if (cfg.GetPrintLevel()) {
899             if (noise)
900               printf("Found noisy channel %1d:%02d (%4.2f) \n",ii,ib,rateN);
901             if (deadc)
902               printf("Found dead  channel %1d:%02d (%4.2f) \n",ii,ib,rateD);
903           }
904         }
905       }
906     }
907   }
908
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) {
914       updated = true;
915       cfg.GetGlobalMasks()->SetGlobalMask(ii,gmask[ii]);
916     }
917   }
918
919   Int_t status = 0;
920   if (updated) {
921     
922     // update version
923     cfg.IncGlobalFileVersion();
924     
925     // don't change the file version ("-x.dat")
926     
927     cfg.GetTriggerIO()->WriteGlobalConfig(cfg.GetGlobalFileName(),cfg.GetGlobalMasks());
928     
929     // write last current file
930     WriteLastCurrentFile(cfg,cfg.GetCurrentFileName());
931
932     status = daqDA_DB_storeFile(cfg.GetGlobalFileName(), cfg.GetGlobalFileName());
933     if (status) {
934       printf("Failed to export file to DB: %s\n",cfg.GetGlobalFileName());
935       return;
936     }
937     
938     status = daqDA_DB_storeFile(cfg.GetCurrentFileName(), cfg.GetCurrentFileName());
939     if (status) {
940       printf("Failed to export file to DB: %s\n",cfg.GetCurrentFileName());
941       return;
942     }
943
944   }
945   
946 }
947
948 //*************************************************************//
949 int main(Int_t argc, Char_t **argv) 
950 {
951     /// main routine
952   
953     // needed for streamer application
954     gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo", "RIO", "TStreamerInfo()"); 
955
956     /* check that we got some arguments = list of files */
957     if (argc<2) {
958       printf("Wrong number of arguments\n");
959       return -1;
960     }
961
962     AliDAConfig cfg;
963
964     Char_t inputFile[256] = "";
965     inputFile[0] = 0;
966     if (argc > 1)
967       if (argv[1] != NULL)
968         strncpy(inputFile, argv[1], 256);
969       else {
970         printf("MUONTRGda : No input File !\n");
971         return -1;
972       }
973
974     // decoding the events
975   
976     Int_t status = 0;
977     Int_t nDateEvents = 0;
978
979     void* event;
980
981     // containers
982     // old decoder
983     AliMUONDDLTrigger*       ddlTrigger  = 0x0;
984     AliMUONDarcHeader*       darcHeader  = 0x0;
985     // new (fast) decoder
986     const AliMUONRawStreamTriggerHP::AliHeader* darcHeaderHP = 0x0;
987
988     TStopwatch timers;
989
990     timers.Start(kTRUE); 
991
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");
996       return -1;
997     }
998     
999     ReadMaskFiles(cfg);
1000
1001 #ifdef OFFLINE
1002     // the run number extracted from the file name
1003     TString tmp(inputFile);
1004     Int_t pos = tmp.First("daq");
1005     tmp = tmp(pos+3,5);
1006     gSystem->Setenv("DATE_RUN_NUMBER",tmp.Data());
1007     gSystem->Exec("echo \"DATE_RUN_NUMBER = \" $DATE_RUN_NUMBER");
1008 #endif
1009
1010     if(!ExportFiles(cfg)) {
1011       printf("ExportFiles failed\n");
1012       return -1;
1013     }
1014
1015     if (!cfg.GetDAFlag()) {
1016
1017       cout << "MUONTRGda: DA enable: " << cfg.GetDAFlag() << endl;
1018       cout << "MUONTRGda: Print level: " << cfg.GetPrintLevel() << endl;
1019       
1020       printf("MUONTRGda: Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
1021
1022       return status;
1023
1024     }
1025
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");
1030       modeFET3 = kFALSE;
1031     }
1032
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");
1036       return -1;
1037     }
1038
1039     // The global cards are ON (active on the global inputs)
1040     if (!cfg.GetGlobalMasks()->GetMasksOn()) {
1041       printf("Global masks are not ON\n");
1042       return -1;
1043     }
1044   
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));
1048
1049     status = monitorSetDataSource(inputFile);
1050     if (status) {
1051       cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
1052            << " " << monitorDecodeError(status) << endl;
1053       return -1;
1054     }
1055     status = monitorDeclareMp("MUON Trigger monitoring");
1056     if (status) {
1057       cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
1058            << " " << monitorDecodeError(status) << endl;
1059       return -1;
1060     }
1061
1062     /* define wait event timeout - 1s max */
1063     monitorSetNowait();
1064     monitorSetNoWaitNetworkTimeout(1000);
1065
1066     cout << "MUONTRGda : Reading data from file " << inputFile <<endl;
1067
1068     UInt_t *globalInput = new UInt_t[4];
1069     Bool_t doUpdate = false;
1070     Int_t runNumber = 0;
1071     Int_t nEvents = 0;
1072
1073     while(1) 
1074     {
1075       if (nEvents >= cfg.GetMaxEvents()) break;
1076       if (cfg.GetPrintLevel()) {
1077         if (nEvents && nEvents % 1000 == 0)     
1078           cout<<"Cumulated events " << nEvents << endl;
1079       }
1080       // check shutdown condition 
1081       if (daqDA_checkShutdown()) 
1082           break;
1083
1084       // Skip Events if needed
1085       while (cfg.GetSkipEvents()) {
1086         status = monitorGetEventDynamic(&event);
1087         cfg.DecSkipEvents();
1088       }
1089
1090       // starts reading
1091       status = monitorGetEventDynamic(&event);
1092       if (status < 0)  {
1093         cout << "MUONTRGda : EOF found" << endl;
1094         break;
1095       }
1096
1097       nDateEvents++;
1098
1099       // decoding rawdata headers
1100       AliRawReader *rawReader = new AliRawReaderDate(event);
1101  
1102       Int_t eventType = rawReader->GetType();
1103       runNumber = rawReader->GetRunNumber();
1104     
1105       // L1Swc1
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);
1113         doUpdate = true;
1114         cfg.IncNoiseEvent();
1115       } else if (modeFET3 && eventType == CALIBRATION_EVENT) {
1116         cfg.SetAlgoDeadcInput(true);
1117         doUpdate = true;
1118         cfg.IncDeadcEvent();
1119       } else {
1120         continue;
1121       }
1122       
1123       nEvents++;
1124       if (cfg.GetPrintLevel() == 2) printf("\nEvent # %d\n",nEvents);
1125
1126       // decoding MUON payload
1127       AliMUONVRawStreamTrigger   *rawStream   = 0x0;
1128       if (cfg.UseFastDecoder()) {
1129         rawStream = new AliMUONRawStreamTriggerHP(rawReader);
1130       } else {
1131         rawStream = new AliMUONRawStreamTrigger(rawReader);
1132       }
1133
1134       // ... without warnings from the decoder !!!
1135       if (!cfg.WithWarnings())
1136         rawStream->DisableWarnings();
1137
1138       // loops over DDL 
1139       while((status = rawStream->NextDDL())) {
1140
1141         if (cfg.GetPrintLevel() == 2) printf("iDDL %d\n", rawStream->GetDDL());
1142
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);
1149           } else {
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();
1154           }
1155           StoreGlobalInput(cfg,globalInput);
1156         }
1157
1158       } // NextDDL
1159
1160       delete rawReader;
1161       delete rawStream;
1162
1163     } // while (1)
1164
1165     // update configuration files ifrequested event types were found
1166     if (doUpdate) 
1167       UpdateGlobalMasks(cfg);
1168
1169     timers.Stop();
1170
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;
1185
1186     printf("MUONTRGda: Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
1187
1188     return status;
1189
1190 }
1191