Put back the doxygen comments in MUONTRGda.cxx
[u/mrichter/AliRoot.git] / MUON / DA / MUONTRGda.cxx
CommitLineData
9f5fafa6 1/*
113ad708 2MTR DA for online
3
3e42bf30 4Contact: Franck Manso <manso@clermont.in2p3.fr>
5Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_mtrda.html
e8f1ed57 6Reference run: 61898
7Run Type: PHYSICS
41a38dec 8DA Type: MON
e8f1ed57 9Number of events needed: 1000 events
10Input files: MtgGlobalCrate.dat MtgRegionalCrate.dat MtgLocalMask.dat MtgLocalLut.dat MtgCurrent.dat DAConfig.dat
11Output Files: ExportedFiles.dat MtgGlobalCrate.dat
12Trigger types used: PHYSICS_EVENT CALIBRATION_EVENT
3e42bf30 13*/
14
327f7faa 15//////////////////////////////////////////////////////////////////////////////
16// Detector Algorithm for the MUON trigger configuration. //
17// //
18// Calculates masks for the global trigger input, by looking at dead //
e8f1ed57 19// channels in calibration events and at noisy channels in physics events. //
327f7faa 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//////////////////////////////////////////////////////////////////////////////
3e42bf30 29
e8f1ed57 30//#define OFFLINE
31
9f5fafa6 32extern "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
4fd5ed63 43#include "AliRawReaderDate.h"
44
45#include "AliMpConstants.h"
9f5fafa6 46#include "AliMUONRawStreamTrigger.h"
e8f1ed57 47#include "AliMUONRawStreamTriggerHP.h"
9f5fafa6 48#include "AliMUONDarcHeader.h"
98bdda22 49#include "AliMUONRegHeader.h"
9f5fafa6 50#include "AliMUONDDLTrigger.h"
4fd5ed63 51#include "AliMUONVStore.h"
4fd5ed63 52#include "AliMUON1DArray.h"
53#include "AliMUONTriggerIO.h"
92c23b09 54#include "AliMUONRegionalTriggerConfig.h"
55#include "AliMUONGlobalCrateConfig.h"
98bdda22 56#include "AliMUONVCalibParam.h"
57#include "AliMUONCalibParamND.h"
58#include "AliMUONCalibParamNI.h"
59#include "AliMUONLocalStruct.h"
9f5fafa6 60
9f5fafa6 61#include "TString.h"
4fd5ed63 62#include "TSystem.h"
9f5fafa6 63#include "TStopwatch.h"
9f5fafa6 64#include "TROOT.h"
65#include "TPluginManager.h"
98bdda22 66#include "TArrayS.h"
9f5fafa6 67
87f615d8 68static const TString fileExp("ExportedFiles.dat");
69
37dacd7d 70/// class for DA run parameters and DA working space
71class AliDAConfig : TObject {
72
73public:
74
75 AliDAConfig() :
e8f1ed57 76 fDAConfigFileName("DAConfig.dat"),
37dacd7d 77 fCurrentFileName("MtgCurrent.dat"),
78 fLastCurrentFileName("MtgLastCurrent.dat"),
79 fSodName(""),
80 fSodFlag(0),
81 fDAName(""),
82 fDAFlag(0),
98bdda22 83 fDAMode(1),
37dacd7d 84 fGlobalFileName(""),
85 fRegionalFileName(""),
86 fLocalMaskFileName(""),
87 fLocalLutFileName(""),
88 fSignatureFileName(""),
87f615d8 89 fTrigScalFileName("MtgTrigScalers.dat"),
37dacd7d 90 fGlobalFileVersion(0),
91 fRegionalFileVersion(0),
92 fLocalMaskFileVersion(0),
93 fLocalLutFileVersion(0),
94 fSignatureFileVersion(0),
95 fGlobalFileLastVersion(0),
96 fRegionalFileLastVersion(0),
97 fLocalMaskFileLastVersion(0),
98 fLocalLutFileLastVersion(0),
99 fEventsN(0),
100 fEventsD(0),
101 fPrintLevel(0),
102 fLocalMasks(0x0),
98bdda22 103 fLocalMasksDA(0x0),
37dacd7d 104 fRegionalMasks(0x0),
105 fGlobalMasks(0x0),
106 fTriggerIO(new AliMUONTriggerIO),
98bdda22 107 fAlgoNoisyInput(kFALSE),
108 fAlgoDeadcInput(kFALSE),
37dacd7d 109 fThrN(0.1),
110 fThrD(0.9),
98bdda22 111 fThrLocN(0.1),
112 fThrLocD(0.9),
37dacd7d 113 fMinEvents(10),
114 fSkipEvents(0),
115 fMaxEvents(65535),
98bdda22 116 fWithWarnings(kFALSE),
117 fUseFastDecoder(kFALSE),
118 fNLocalBoard(AliMpConstants::TotalNofLocalBoards()+1),
119 fPatternStoreN(0x0),
87f615d8 120 fPatternStoreD(0x0),
121 fSaveScalers(kFALSE),
122 fScalerRecTime(600)
37dacd7d 123 {
124 /// default constructor
125 for (Int_t ii = 0; ii < kGlobalInputs; ii++) {
126 for (Int_t il = 0; il < kGlobalInputLength; il++) {
127 fAccGlobalInputN[ii][il] = 0;
128 fAccGlobalInputD[ii][il] = 0;
129 }
130 }
131 fLocalMasks = new AliMUON1DArray(fNLocalBoard);
98bdda22 132 fLocalMasksDA = new AliMUON1DArray(fNLocalBoard);
37dacd7d 133 fRegionalMasks = new AliMUONRegionalTriggerConfig();
134 fGlobalMasks = new AliMUONGlobalCrateConfig();
98bdda22 135 fPatternStoreN = new AliMUON1DArray(fNLocalBoard);
136 fPatternStoreD = new AliMUON1DArray(fNLocalBoard);
137
138 // Generate local trigger masks store. All masks are set to FFFF
139 for (Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); i++) {
140 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
141 for (Int_t x = 0; x < 2; x++) {
142 for (Int_t y = 0; y < 4; y++) {
143 Int_t index = x*4+y;
144 localBoard->SetValueAsInt(index,0,0xFFFF);
145 }
146 }
147 fLocalMasksDA->Add(localBoard);
148 }
149
b22f6547 150 // Create a default pattern store
151 for (Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); i++) {
152 AliMUONVCalibParam *patN = new AliMUONCalibParamND(2, 64, i, 0, 0.);
153 AliMUONVCalibParam *patD = new AliMUONCalibParamND(2, 64, i, 0, 0.);
154 fPatternStoreN->Add(patN);
155 fPatternStoreD->Add(patD);
156 }
157
37dacd7d 158 }
159
37dacd7d 160 virtual ~AliDAConfig()
161 {
162 /// destructor
163 delete fLocalMasks;
98bdda22 164 delete fLocalMasksDA;
37dacd7d 165 delete fRegionalMasks;
166 delete fGlobalMasks;
98bdda22 167 delete fPatternStoreN;
168 delete fPatternStoreD;
37dacd7d 169 delete fTriggerIO;
170 }
171 void PrintConfig()
172 {
173 /// print DA parameters
174 printf("DA config file name: %s \n",GetDAConfigFileName());
175 printf("Current file name: %s \n",GetCurrentFileName());
176 printf("Last current file name: %s \n",GetLastCurrentFileName());
177 printf("Global file name: %s (%d %d)\n",GetGlobalFileName(),GetGlobalFileVersion(),GetGlobalFileLastVersion());
178 printf("Regional file name: %s (%d %d)\n",GetRegionalFileName(),GetRegionalFileVersion(),GetRegionalFileLastVersion());
179 printf("Local mask file name: %s (%d %d)\n",GetLocalMaskFileName(),GetLocalMaskFileVersion(),GetLocalMaskFileLastVersion());
180 printf("Local LUT file name: %s (%d %d)\n",GetLocalLutFileName(),GetLocalLutFileVersion(),GetLocalLutFileLastVersion());
181 printf("Signature file name: %s (%d)\n",GetSignatureFileName(),GetSignatureFileVersion());
182 }
183
bb440407 184 /// name of the DA configuration file from detector DB
37dacd7d 185 const Char_t* GetDAConfigFileName() { return fDAConfigFileName.Data(); }
bb440407 186 /// file with current versions of the configuration files, usually MtgCurrent.dat
37dacd7d 187 const Char_t* GetCurrentFileName() { return fCurrentFileName.Data(); }
bb440407 188 /// last known versions of the configuration files, usually MtgLastCurrent.dat
37dacd7d 189 const Char_t* GetLastCurrentFileName() { return fLastCurrentFileName.Data(); }
190
bb440407 191 /// name of the Start-of-data field in MtgCurrent.dat
37dacd7d 192 const Char_t* GetSodName() { return fSodName.Data(); }
bb440407 193 /// flag value of the Start-of-data field in MtgCurrent.dat
37dacd7d 194 Int_t GetSodFlag() const { return fSodFlag; }
195
bb440407 196 /// name of the Detector Algorithm field in MtgCurrent.dat
37dacd7d 197 const Char_t* GetDAName() { return fDAName.Data(); }
bb440407 198 /// flag value of the Detector Algorithm field in MtgCurrent.dat
37dacd7d 199 Int_t GetDAFlag() const { return fDAFlag; }
98bdda22 200 /// DA active mode (GLOBAL or GLOBAL+LOCAL)
201 Int_t GetDAMode() const { return fDAMode; }
37dacd7d 202
bb440407 203 /// global crate configuration file name
37dacd7d 204 const Char_t* GetGlobalFileName() { return fGlobalFileName.Data(); }
bb440407 205 /// regional crate configuration file name
37dacd7d 206 const Char_t* GetRegionalFileName() { return fRegionalFileName.Data(); }
bb440407 207 /// masks for the local cards, file name
37dacd7d 208 const Char_t* GetLocalMaskFileName() { return fLocalMaskFileName.Data(); }
bb440407 209 /// transverse momentum Look-Up-Table, file name
37dacd7d 210 const Char_t* GetLocalLutFileName() { return fLocalLutFileName.Data(); }
87f615d8 211 /// signature, file name
37dacd7d 212 const Char_t* GetSignatureFileName() { return fSignatureFileName.Data(); }
87f615d8 213 /// signature, file name
214 const Char_t* GetTrigScalFileName() { return fTrigScalFileName.Data(); }
37dacd7d 215
bb440407 216 /// version of the global crate configuration in the detector DB
37dacd7d 217 Int_t GetGlobalFileVersion() const { return fGlobalFileVersion; }
bb440407 218 /// version of the regional crate configuration in the detector DB
37dacd7d 219 Int_t GetRegionalFileVersion() const { return fRegionalFileVersion; }
bb440407 220 /// version of the masks for the local cards in the detector DB
37dacd7d 221 Int_t GetLocalMaskFileVersion() const { return fLocalMaskFileVersion; }
bb440407 222 /// version of the transverse momentum Look-Up-Table in the detector DB
37dacd7d 223 Int_t GetLocalLutFileVersion() const { return fLocalLutFileVersion; }
bb440407 224 /// version of the signature file in the detector DB
37dacd7d 225 Int_t GetSignatureFileVersion() const { return fSignatureFileVersion; }
226
bb440407 227 /// last known version of the global crate configuration
37dacd7d 228 Int_t GetGlobalFileLastVersion() const { return fGlobalFileLastVersion; }
bb440407 229 /// last known version of the regional crate configuration
37dacd7d 230 Int_t GetRegionalFileLastVersion() const { return fRegionalFileLastVersion; }
bb440407 231 /// last known version of the masks for the local cards
37dacd7d 232 Int_t GetLocalMaskFileLastVersion() const { return fLocalMaskFileLastVersion; }
bb440407 233 /// last known version of the transverse momentum Look-Up-Table
37dacd7d 234 Int_t GetLocalLutFileLastVersion() const { return fLocalLutFileLastVersion; }
235
bb440407 236 /// store for the masks for the local cards (own)
37dacd7d 237 AliMUONVStore* GetLocalMasks() const { return fLocalMasks; }
98bdda22 238 /// store for the DA-calculated masks for the local cards (own)
239 AliMUONVStore* GetLocalMasksDA() const { return fLocalMasksDA; }
bb440407 240 /// configuration object for the regional crate (own)
37dacd7d 241 AliMUONRegionalTriggerConfig* GetRegionalMasks() const { return fRegionalMasks; }
bb440407 242 /// configuration object for the global crate (own)
37dacd7d 243 AliMUONGlobalCrateConfig* GetGlobalMasks() const { return fGlobalMasks; }
244
bb440407 245 /// read/write configurations, masks and LUT to/from online files (own)
37dacd7d 246 AliMUONTriggerIO* GetTriggerIO() const { return fTriggerIO; }
247
98bdda22 248 /// store for local strips patterns (noisy strips)
249 AliMUONVStore* GetPatternStoreN() const { return fPatternStoreN; }
250 /// store for local strips patterns (dead strips)
251 AliMUONVStore* GetPatternStoreD() const { return fPatternStoreD; }
252
bb440407 253 /// number of accumulated PHYSICS events for noisy channels analysis
37dacd7d 254 Int_t GetEventsN() const { return fEventsN; }
bb440407 255 /// number of accumulated CALIBRATION events for dead channels analysis
37dacd7d 256 Int_t GetEventsD() const { return fEventsD; }
257
bb440407 258 /// print verbosity of the DA
37dacd7d 259 Int_t GetPrintLevel() const { return fPrintLevel; }
260
bb440407 261 /// select PHYSICS events for noisy channels analysis
37dacd7d 262 Bool_t GetAlgoNoisyInput() const { return fAlgoNoisyInput; }
bb440407 263 /// select CALIBRATION events for dead channels analysis
37dacd7d 264 Bool_t GetAlgoDeadcInput() const { return fAlgoDeadcInput; }
265
98bdda22 266 /// threshold for noisy global inputs (fraction of events)
37dacd7d 267 Float_t GetThrN() const { return fThrN; }
98bdda22 268 /// threshold for dead global inputs (fraction of events)
37dacd7d 269 Float_t GetThrD() const { return fThrD; }
98bdda22 270 /// threshold for noisy local strips (fraction of events)
271 Float_t GetThrLocN() const { return fThrLocN; }
272 /// threshold for dead local strips (fraction of events)
273 Float_t GetThrLocD() const { return fThrLocD; }
37dacd7d 274
bb440407 275 /// minumum nr of events for rate calculation
37dacd7d 276 Int_t GetMinEvents() const { return fMinEvents; }
bb440407 277 /// maximum number of events to analyze
37dacd7d 278 Int_t GetMaxEvents() const { return fMaxEvents; }
bb440407 279 /// number of events to skip from start
37dacd7d 280 Int_t GetSkipEvents() const { return fSkipEvents; }
281
bb440407 282 /// show warnings from the raw data decoder
37dacd7d 283 Bool_t WithWarnings() const { return fWithWarnings; }
bb440407 284 /// use the high-performance (HP) decoder
e8f1ed57 285 Bool_t UseFastDecoder() const { return fUseFastDecoder; }
37dacd7d 286
87f615d8 287 /// save cooked information from scalers
288 Bool_t SaveScalers() const { return fSaveScalers; }
289 /// time between two records, in seconds
290 UInt_t GetScalerRecTime() const { return fScalerRecTime; }
291
292
bb440407 293 /// number of global input words
37dacd7d 294 Int_t GetGlobalInputs() const { return kGlobalInputs; }
bb440407 295 /// length in bits of a global input word
37dacd7d 296 Int_t GetGlobalInputLength() const { return kGlobalInputLength; }
297
bb440407 298 /// get accumulated values for bit "ib" from global input word "ii", PHYSICS events
37dacd7d 299 Int_t GetAccGlobalInputN(Int_t ii, Int_t ib) const { return fAccGlobalInputN[ii][ib]; }
bb440407 300 /// get accumulated values for bit "ib" from global input word "ii", CALIBRATION events
37dacd7d 301 Int_t GetAccGlobalInputD(Int_t ii, Int_t ib) const { return fAccGlobalInputD[ii][ib]; }
302
bb440407 303 /// set the name of the Start-of-data field in MtgCurrent.dat
37dacd7d 304 void SetSodName(Char_t *name) { fSodName = TString(name); }
bb440407 305 /// set the flag value of the Start-of-data field in MtgCurrent.dat
37dacd7d 306 void SetSodFlag(Int_t flag) { fSodFlag = flag; }
307
bb440407 308 /// set the name of the Detector Algorithm field in MtgCurrent.dat
37dacd7d 309 void SetDAName(Char_t *name) { fDAName = TString(name); }
bb440407 310 /// set the flag value of the Detector Algorithm field in MtgCurrent.dat
37dacd7d 311 void SetDAFlag(Int_t flag) { fDAFlag = flag; }
98bdda22 312 /// set DA active mode, 1 = GLOBAL (default), 2 = GLOBAL and LOCAL
313 void SetDAMode(Int_t mode) { fDAMode = mode; }
37dacd7d 314
bb440407 315 /// set the global crate configuration file name
37dacd7d 316 void SetGlobalFileName(const Char_t *name) { fGlobalFileName = TString(name); }
bb440407 317 /// set the regional crate configuration file name
37dacd7d 318 void SetRegionalFileName(const Char_t *name) { fRegionalFileName = TString(name); }
bb440407 319 /// set the masks for the local cards, file name
37dacd7d 320 void SetLocalMaskFileName(const Char_t *name) { fLocalMaskFileName = TString(name); }
bb440407 321 /// set the transverse momentum Look-Up-Table, file name
37dacd7d 322 void SetLocalLutFileName(const Char_t *name) { fLocalLutFileName = TString(name); }
bb440407 323 /// set the signature file name
37dacd7d 324 void SetSignatureFileName(const Char_t *name) { fSignatureFileName = TString(name); }
87f615d8 325 /// set the trigger scalers file name
326 void SetTrigScalFileName(const Char_t *name) { fTrigScalFileName = TString(name); }
37dacd7d 327
bb440407 328 /// set the version of the global crate configuration in the detector DB
37dacd7d 329 void SetGlobalFileVersion(Int_t ver) { fGlobalFileVersion = ver; }
bb440407 330 /// set the version of the regional crate configuration in the detector DB
37dacd7d 331 void SetRegionalFileVersion(Int_t ver) { fRegionalFileVersion = ver; }
bb440407 332 /// set the version of the masks for the local cards in the detector DB
37dacd7d 333 void SetLocalMaskFileVersion(Int_t ver) { fLocalMaskFileVersion = ver; }
bb440407 334 /// set the version of the transverse momentum Look-Up-Table in the detector DB
37dacd7d 335 void SetLocalLutFileVersion(Int_t ver) { fLocalLutFileVersion = ver; }
bb440407 336 /// set the version of the signature file in the detector DB
37dacd7d 337 void SetSignatureFileVersion(Int_t ver) { fSignatureFileVersion = ver; }
338
bb440407 339 /// set the last known version of the global crate configuration
37dacd7d 340 void SetGlobalFileLastVersion(Int_t ver) { fGlobalFileLastVersion = ver; }
bb440407 341 /// set the last known version of the regional crate configuration
37dacd7d 342 void SetRegionalFileLastVersion(Int_t ver) { fRegionalFileLastVersion = ver; }
bb440407 343 /// set the last known version of the masks for the local cards
37dacd7d 344 void SetLocalMaskFileLastVersion(Int_t ver) { fLocalMaskFileLastVersion = ver; }
bb440407 345 /// set the last known version of the transverse momentum Look-Up-Table
37dacd7d 346 void SetLocalLutFileLastVersion(Int_t ver) { fLocalLutFileLastVersion = ver; }
347
bb440407 348 /// increment the number of selected PHYSICS events
37dacd7d 349 void IncNoiseEvent() { fEventsN++; }
bb440407 350 /// increment the number of selected CALIBRATION events
37dacd7d 351 void IncDeadcEvent() { fEventsD++; }
352
bb440407 353 /// count the value of the bit "ib" of global input word "ii" (PHYSICS events)
37dacd7d 354 void AddAccGlobalInputN(Int_t ii, Int_t ib, Int_t val) { fAccGlobalInputN[ii][ib] += val; }
bb440407 355 /// count the value of the bit "ib" of global input word "ii" (CALIBRATION events)
37dacd7d 356 void AddAccGlobalInputD(Int_t ii, Int_t ib, Int_t val) { fAccGlobalInputD[ii][ib] += val; }
357
bb440407 358 /// set the print verbosity level of the DA
37dacd7d 359 void SetPrintLevel(Int_t level) { fPrintLevel = level; }
360
bb440407 361 /// select PHYSICS events for noisy channels analysis
37dacd7d 362 void SetAlgoNoisyInput(Bool_t val) { fAlgoNoisyInput = val; }
bb440407 363 /// select CALIBRATION events for dead channels analysis
37dacd7d 364 void SetAlgoDeadcInput(Bool_t val) { fAlgoDeadcInput = val; }
365
98bdda22 366 /// set the threshold for noisy global inputs (fraction of events)
37dacd7d 367 void SetThrN(Float_t val) { fThrN = val; }
98bdda22 368 /// set the threshold for dead global inputs (fraction of events)
37dacd7d 369 void SetThrD(Float_t val) { fThrD = val; }
98bdda22 370 /// set the threshold for noisy local strips (fraction of events)
371 void SetThrLocN(Float_t val) { fThrLocN = val; }
372 /// set the threshold for dead local strips (fraction of events)
373 void SetThrLocD(Float_t val) { fThrLocD = val; }
37dacd7d 374
bb440407 375 /// set the minumum nr of events for rate calculation
37dacd7d 376 void SetMinEvents(Int_t val) { fMinEvents = val; }
bb440407 377 /// set the maximum number of events to analyze
37dacd7d 378 void SetMaxEvents(Int_t val) { fMaxEvents = val; }
bb440407 379 /// set the number of events to skip from start
37dacd7d 380 void SetSkipEvents(Int_t val) { fSkipEvents = val; }
381
bb440407 382 /// set/unset to show warnings from the raw data decoder
98bdda22 383 void SetWithWarnings() { fWithWarnings = kTRUE; }
bb440407 384 /// set/unset the use of the high-performance (HP) decoder
98bdda22 385 void SetUseFastDecoder() { fUseFastDecoder = kTRUE; }
87f615d8 386 /// set/unset the saving of cooked information from scalers
387 void SetSaveScalers(Bool_t val) { fSaveScalers = val; }
388 /// time between two records, in seconds
389 void SetScalerRecTime(Int_t trec) { fScalerRecTime = (UInt_t)trec; }
37dacd7d 390
bb440407 391 /// increment version of the global crate configuration file
37dacd7d 392 void IncGlobalFileVersion() { fGlobalFileVersion++; }
98bdda22 393 /// increment version of the local mask configuration file
394 void IncLocalMaskFileVersion() { fLocalMaskFileVersion++; }
bb440407 395 /// count skipped events
37dacd7d 396 void DecSkipEvents() { fSkipEvents--; }
397
398private:
4fd5ed63 399
bb440407 400 /// copy constructor, not implemented
401 AliDAConfig (const AliDAConfig& cfg);
402 /// assignment operator, not implemented
403 AliDAConfig& operator=(const AliDAConfig& cfg);
4fd5ed63 404
208a1e3a 405 const TString fDAConfigFileName; //!< name of the DA configuration file from detector DB
406 const TString fCurrentFileName; //!< usually MtgCurrent.dat
407 const TString fLastCurrentFileName; //!< usually MtgLastCurrent.dat
408
409 TString fSodName; //!< name of the Start-of-data field in MtgCurrent.dat
410 Int_t fSodFlag; //!< flag value of the Start-of-data field in MtgCurrent.dat
411
412 TString fDAName; //!< name of the Detector Algorithm field in MtgCurrent.dat
413 Int_t fDAFlag; //!< flag value of the Detector Algorithm field in MtgCurrent.dat (enabled/disabled)
414 Int_t fDAMode; //!< DA active mode, GLOBAL or GLOBAL+LOCAL
415
416 TString fGlobalFileName; //!< global crate configuration, file name
417 TString fRegionalFileName; //!< regional crate configuration, file name
418 TString fLocalMaskFileName; //!< masks for the local cards, file name
419 TString fLocalLutFileName; //!< transverse momentum Look-Up-Table, file name
420 TString fSignatureFileName; //!< signature, file name
421 TString fTrigScalFileName; //!< trigger scalers, file name
422
423 Int_t fGlobalFileVersion; //!< version of the global crate configuration in the detector DB
424 Int_t fRegionalFileVersion; //!< version of the regional crate configuration in the detector DB
425 Int_t fLocalMaskFileVersion; //!< version of the masks for the local cards in the detector DB
426 Int_t fLocalLutFileVersion; //!< version of the transverse momentum Look-Up-Table in the detector DB
427 Int_t fSignatureFileVersion; //!< version of the signature file in the detector DB
327f7faa 428
208a1e3a 429 Int_t fGlobalFileLastVersion; //!< last known version of the global crate configuration
430 Int_t fRegionalFileLastVersion; //!< last known version of the regional crate configuration
431 Int_t fLocalMaskFileLastVersion; //!< last known version of the masks for the local cards
432 Int_t fLocalLutFileLastVersion; //!< last known version of the transverse momentum Look-Up-Table
327f7faa 433
208a1e3a 434 Int_t fEventsN; //!< number of accumulated PHYSICS events
435 Int_t fEventsD; //!< number of accumulated CALIBRATION events
327f7faa 436
208a1e3a 437 Int_t fPrintLevel; //!< print verbosity of the DA
327f7faa 438
208a1e3a 439 AliMUONVStore* fLocalMasks; //!< store for the masks for the local cards
440 AliMUONVStore* fLocalMasksDA; //!< store for the DA-calculated masks for the local cards
441 AliMUONRegionalTriggerConfig* fRegionalMasks; //!< configuration object for the regional crate
442 AliMUONGlobalCrateConfig* fGlobalMasks; //!< configuration object for the global crate
327f7faa 443
208a1e3a 444 AliMUONTriggerIO *fTriggerIO; //!< read/write masks and LUT to/from online files
327f7faa 445
208a1e3a 446 Bool_t fAlgoNoisyInput; //!< select PHYSICS events for noisy channels analysis
447 Bool_t fAlgoDeadcInput; //!< select CALIBRATION events for dead channels analysis
327f7faa 448
208a1e3a 449 Float_t fThrN; //!< threshold for noisy global inputs (fraction of events)
450 Float_t fThrD; //!< threshold for dead global inputs (fraction of events)
451 Float_t fThrLocN; //!< threshold for noisy local strips (fraction of events)
452 Float_t fThrLocD; //!< threshold for dead local strips (fraction of events)
453 Int_t fMinEvents; //!< minumum nr of events for rate calculation
454 Int_t fSkipEvents; //!< number of events to skip from start
455 Int_t fMaxEvents; //!< maximum number of events to analyze
456 Bool_t fWithWarnings; //!< show warnings from the raw data decoder
457 Bool_t fUseFastDecoder; //!< use the high-performance (HP) decoder
327f7faa 458
208a1e3a 459 const Int_t fNLocalBoard; //!< number of local boards
327f7faa 460
208a1e3a 461 enum { kGlobalInputs = 4, //!< number of global input words
462 kGlobalInputLength = 32 //!< length in bits of a global input word
bb440407 463 };
327f7faa 464
208a1e3a 465 AliMUONVStore *fPatternStoreN; //!< store for local strips patterns
466 AliMUONVStore *fPatternStoreD; //!< store for local strips patterns
98bdda22 467
208a1e3a 468 Int_t fAccGlobalInputN[kGlobalInputs][kGlobalInputLength]; //!< storage for global input (PHYSICS events)
469 Int_t fAccGlobalInputD[kGlobalInputs][kGlobalInputLength]; //!< storage for global input (CALIBRATION events)
87f615d8 470
208a1e3a 471 Bool_t fSaveScalers; //!< save cooked information from the trigger scalers
472 Int_t fScalerRecTime; //!< time between two records, in seconds
327f7faa 473
327f7faa 474};
4fd5ed63 475
327f7faa 476//__________________________________________________________________
37dacd7d 477Bool_t ReadDAConfig(AliDAConfig& cfg)
327f7faa 478{
37dacd7d 479 /// read run parameters for the DA
4fd5ed63 480
327f7faa 481 char line[80];
4fd5ed63 482
327f7faa 483 TString file;
37dacd7d 484 file = cfg.GetDAConfigFileName();
327f7faa 485 std::ifstream in(gSystem->ExpandPathName(file.Data()));
486 if (!in.good()) {
487 printf("Cannot open DA configuration file %s ; use default values.\n",file.Data());
98bdda22 488 return kTRUE;
327f7faa 489 }
490
491 TString tmp;
492 Int_t pos;
493
494 in.getline(line,80);
495 tmp = line;
496 pos = tmp.First(" ");
497 tmp = tmp(0,pos);
37dacd7d 498 cfg.SetPrintLevel(tmp.Atoi());
327f7faa 499
500 in.getline(line,80);
501 tmp = line;
502 pos = tmp.First(" ");
503 tmp = tmp(0,pos);
37dacd7d 504 cfg.SetThrN(tmp.Atof());
327f7faa 505
506 in.getline(line,80);
507 tmp = line;
508 pos = tmp.First(" ");
509 tmp = tmp(0,pos);
37dacd7d 510 cfg.SetThrD(tmp.Atof());
327f7faa 511
512 in.getline(line,80);
513 tmp = line;
514 pos = tmp.First(" ");
515 tmp = tmp(0,pos);
37dacd7d 516 cfg.SetMinEvents(tmp.Atoi());
327f7faa 517
518 in.getline(line,80);
519 tmp = line;
520 pos = tmp.First(" ");
521 tmp = tmp(0,pos);
37dacd7d 522 cfg.SetSkipEvents(tmp.Atoi());
4fd5ed63 523
327f7faa 524 in.getline(line,80);
525 tmp = line;
526 pos = tmp.First(" ");
527 tmp = tmp(0,pos);
37dacd7d 528 cfg.SetMaxEvents(tmp.Atoi());
4fd5ed63 529
327f7faa 530 in.getline(line,80);
531 tmp = line;
532 pos = tmp.First(" ");
533 tmp = tmp(0,pos);
37dacd7d 534 if (tmp.Atoi() != 0) cfg.SetWithWarnings();
327f7faa 535
e8f1ed57 536 in.getline(line,80);
537 tmp = line;
538 pos = tmp.First(" ");
539 tmp = tmp(0,pos);
540 if (tmp.Atoi() != 0) cfg.SetUseFastDecoder();
541
98bdda22 542 in.getline(line,80);
543 tmp = line;
544 pos = tmp.First(" ");
545 tmp = tmp(0,pos);
546 cfg.SetThrLocN(tmp.Atof());
547
548 in.getline(line,80);
549 tmp = line;
550 pos = tmp.First(" ");
551 tmp = tmp(0,pos);
552 cfg.SetThrLocD(tmp.Atof());
553
554 in.getline(line,80);
555 tmp = line;
556 pos = tmp.First(" ");
557 tmp = tmp(0,pos);
558 cfg.SetDAMode(tmp.Atoi());
559
87f615d8 560 in.getline(line,80);
561 tmp = line;
562 pos = tmp.First(" ");
563 tmp = tmp(0,pos);
564 tmp.Atoi() == 0 ? cfg.SetSaveScalers(kFALSE) : cfg.SetSaveScalers(kTRUE);
565
566 in.getline(line,80);
567 tmp = line;
568 pos = tmp.First(" ");
569 tmp = tmp(0,pos);
570 cfg.SetScalerRecTime(tmp.Atoi());
571
98bdda22 572 return kTRUE;
4fd5ed63 573
327f7faa 574}
4fd5ed63 575
4fd5ed63 576//__________________________________________________________________
37dacd7d 577void WriteLastCurrentFile(AliDAConfig& cfg, TString currentFile)
4fd5ed63 578{
37dacd7d 579 /// write last current file
4fd5ed63 580
4fd5ed63 581 ofstream out;
582 TString file;
583 file = currentFile;
87f615d8 584 out.open(file.Data(), std::ofstream::out);
37dacd7d 585 out << cfg.GetSodName() << " " << cfg.GetSodFlag() << endl;
586 out << cfg.GetDAName() << " " << cfg.GetDAFlag() << endl;
4fd5ed63 587
37dacd7d 588 out << cfg.GetGlobalFileName() << " " << cfg.GetGlobalFileVersion() << endl;
589 out << cfg.GetRegionalFileName() << " " << cfg.GetRegionalFileVersion() << endl;
590 out << cfg.GetLocalMaskFileName() << " " << cfg.GetLocalMaskFileVersion() << endl;
591 out << cfg.GetLocalLutFileName() << " " << cfg.GetLocalLutFileVersion() << endl;
592 out << cfg.GetSignatureFileName() << " " << cfg.GetSignatureFileVersion() << endl;
4fd5ed63 593
594 out.close();
595}
596
597//___________________________________________________________________________________________
98bdda22 598Bool_t ReadCurrentFile(AliDAConfig& cfg, TString currentFile, Bool_t lastCurrentFlag = kFALSE)
4fd5ed63 599{
37dacd7d 600 /// read last current file name and version
4fd5ed63 601
4fd5ed63 602 char line[80];
603 char name[80];
37dacd7d 604 Int_t flag;
4fd5ed63 605
606 TString file;
607 file = currentFile;
608 std::ifstream in(gSystem->ExpandPathName(file.Data()));
609 if (!in.good()) {
610 printf("Cannot open last current file %s\n",currentFile.Data());
98bdda22 611 return kFALSE;
4fd5ed63 612 }
613
4fd5ed63 614 // read SOD
615 in.getline(line,80);
37dacd7d 616 sscanf(line, "%s %d", name, &flag);
617 cfg.SetSodName(name);
618 cfg.SetSodFlag(flag);
619 if (cfg.GetPrintLevel()) printf("Sod Flag %d\n", cfg.GetSodFlag());
4fd5ed63 620
621 //read DA
622 in.getline(line,80);
37dacd7d 623 sscanf(line, "%s %d", name, &flag);
624 cfg.SetDAName(name);
625 cfg.SetDAFlag(flag);
626 if (cfg.GetPrintLevel()) printf("DA Flag: %d\n", cfg.GetDAFlag());
4fd5ed63 627
4fd5ed63 628 // read global
629 in.getline(line,80);
630 TString tmp(line);
631 Int_t pos = tmp.First(" ");
37dacd7d 632 TString tmp1 = tmp(0, pos);
633 cfg.SetGlobalFileName(tmp1.Data());
4fd5ed63 634
635 if (!lastCurrentFlag) {
37dacd7d 636 cfg.SetGlobalFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
637 if (cfg.GetPrintLevel()) printf("Global File Name: %s version: %d\n",
638 cfg.GetGlobalFileName(), cfg.GetGlobalFileVersion());
4fd5ed63 639 } else {
37dacd7d 640 cfg.SetGlobalFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
641 if (cfg.GetPrintLevel()) printf("Global File Name: %s last version: %d\n",
642 cfg.GetGlobalFileName(), cfg.GetGlobalFileLastVersion());
4fd5ed63 643 }
644
645 // read regional
646 in.getline(line,80);
647 tmp = line;
648 pos = tmp.First(" ");
37dacd7d 649 tmp1 = tmp(0, pos);
650 cfg.SetRegionalFileName(tmp1.Data());
4fd5ed63 651
652 if (!lastCurrentFlag) {
37dacd7d 653 cfg.SetRegionalFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
654 if (cfg.GetPrintLevel()) printf("Regional File Name: %s version: %d\n",
655 cfg.GetRegionalFileName(), cfg.GetRegionalFileVersion());
4fd5ed63 656
657 } else {
37dacd7d 658 cfg.SetRegionalFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
659 if (cfg.GetPrintLevel()) printf("Regional File Name: %s last version: %d\n",
660 cfg.GetRegionalFileName(), cfg.GetRegionalFileLastVersion());
4fd5ed63 661 }
662
4fd5ed63 663 // read mask
664 in.getline(line,80);
665 tmp = line;
666 pos = tmp.First(" ");
37dacd7d 667 tmp1 = tmp(0, pos);
668 cfg.SetLocalMaskFileName(tmp1.Data());
4fd5ed63 669
670 if (!lastCurrentFlag) {
37dacd7d 671 cfg.SetLocalMaskFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
672 if (cfg.GetPrintLevel()) printf("Mask File Name: %s version: %d\n",
673 cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileVersion());
4fd5ed63 674 } else {
37dacd7d 675 cfg.SetLocalMaskFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
676 if (cfg.GetPrintLevel()) printf("Mask File Name: %s last version: %d\n",
677 cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileLastVersion());
4fd5ed63 678 }
679 // read Lut
680 in.getline(line,80);
681 tmp = line;
682 pos = tmp.First(" ");
37dacd7d 683 tmp1 = tmp(0, pos);
684 cfg.SetLocalLutFileName(tmp1.Data());
4fd5ed63 685
686 if (!lastCurrentFlag) {
37dacd7d 687 cfg.SetLocalLutFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
688 if (cfg.GetPrintLevel()) printf("Lut File Name: %s version: %d\n",
689 cfg.GetLocalLutFileName(), cfg.GetLocalLutFileVersion());
4fd5ed63 690 } else {
37dacd7d 691 cfg.SetLocalLutFileLastVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
692 if (cfg.GetPrintLevel()) printf("Lut File Name: %s last version: %d\n",
693 cfg.GetLocalLutFileName(), cfg.GetLocalLutFileLastVersion());
4fd5ed63 694 }
695
696 in.getline(line,80);
697 tmp = line;
698 pos = tmp.First(" ");
37dacd7d 699 tmp1 = tmp(0, pos);
700 cfg.SetSignatureFileName(tmp1.Data());
701 cfg.SetSignatureFileVersion(atoi(tmp(pos+1, tmp.Length()-pos).Data()));
702 if (cfg.GetPrintLevel()) printf("Lut File Name: %s version: %d\n",
703 cfg.GetSignatureFileName(), cfg.GetSignatureFileVersion());
4fd5ed63 704
98bdda22 705 return kTRUE;
4fd5ed63 706}
707
708//_____________
37dacd7d 709void ReadFileNames(AliDAConfig& cfg)
4fd5ed63 710{
37dacd7d 711 /// if last current file does not exist than read current file
327f7faa 712
98bdda22 713 if (!ReadCurrentFile(cfg,cfg.GetLastCurrentFileName(), kTRUE))
4fd5ed63 714 {
98bdda22 715 ReadCurrentFile(cfg,cfg.GetCurrentFileName(), kTRUE);
4fd5ed63 716 }
37dacd7d 717
718 // any case read current file
719 ReadCurrentFile(cfg,cfg.GetCurrentFileName());
720
4fd5ed63 721}
722
723//__________________
37dacd7d 724Bool_t ExportFiles(AliDAConfig& cfg)
4fd5ed63 725{
37dacd7d 726 /// Export files to FES
4fd5ed63 727
4fd5ed63 728 // env variables have to be set (suppose by ECS ?)
729 // setenv DATE_FES_PATH
730 // setenv DATE_RUN_NUMBER
731 // setenv DATE_ROLE_NAME
732 // setenv DATE_DETECTOR_CODE
733
e8f1ed57 734#ifdef OFFLINE
87f615d8 735 gSystem->Setenv("DAQDALIB_PATH", "$DATE_ROOT/infoLogger");
736 gSystem->Setenv("DAQDA_TEST_DIR", "/users_local1/Software/ALICE/AMORE/FES");
e8f1ed57 737#endif
8f8ae0de 738
4fd5ed63 739 // update files
740 Int_t status = 0;
741
98bdda22 742 Bool_t modified = kFALSE;
743 Bool_t globalExported = kFALSE;
4fd5ed63 744
745 ofstream out;
4fd5ed63 746 TString file;
747
87f615d8 748 out.open(fileExp.Data(), std::ofstream::out);
4fd5ed63 749 if (!out.good()) {
750 printf("Failed to create file: %s\n",file.Data());
98bdda22 751 return kFALSE;
113ad708 752 }
4fd5ed63 753
8f8ae0de 754 // check if MtgLastCurrent.dat exists
755 // if not, do initial export of all files
98bdda22 756 Bool_t initFES = kFALSE;
8f8ae0de 757 if (gSystem->AccessPathName("MtgLastCurrent.dat"))
98bdda22 758 initFES = kTRUE;
8f8ae0de 759 if (initFES) printf("Copy all configuration files to the FES.\n");
760
37dacd7d 761 file = cfg.GetLocalMaskFileName();
762 if ((cfg.GetLocalMaskFileLastVersion() != cfg.GetLocalMaskFileVersion()) || initFES) {
98bdda22 763 modified = kTRUE;
e8f1ed57 764 status = daqDA_FES_storeFile(file.Data(), "LOCAL");
4fd5ed63 765 if (status) {
37dacd7d 766 printf("Failed to export file: %s\n",cfg.GetLocalMaskFileName());
98bdda22 767 return kFALSE;
4fd5ed63 768 }
37dacd7d 769 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetLocalMaskFileName());
770 out << cfg.GetLocalMaskFileName() << endl;
4fd5ed63 771 }
772
37dacd7d 773 file = cfg.GetLocalLutFileName();
774 if ((cfg.GetLocalLutFileLastVersion() != cfg.GetLocalLutFileVersion()) || initFES) {
98bdda22 775 modified = kTRUE;
e8f1ed57 776 status = daqDA_FES_storeFile(file.Data(), "LUT");
4fd5ed63 777 if (status) {
37dacd7d 778 printf("Failed to export file: %s\n",cfg.GetLocalLutFileName());
98bdda22 779 return kFALSE;
4fd5ed63 780 }
37dacd7d 781 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetLocalLutFileName());
782 out << cfg.GetLocalLutFileName() << endl;
4fd5ed63 783
784 }
785
bb440407 786 file = cfg.GetGlobalFileName();
787 if ((cfg.GetGlobalFileLastVersion() != cfg.GetGlobalFileVersion()) || modified || initFES) {
98bdda22 788 modified = kTRUE;
789 globalExported = kTRUE;
bb440407 790 status = daqDA_FES_storeFile(file.Data(), "GLOBAL");
791 if (status) {
792 printf("Failed to export file: %s\n",cfg.GetGlobalFileName());
98bdda22 793 return kFALSE;
bb440407 794 }
795 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetGlobalFileName());
796 out << cfg.GetGlobalFileName() << endl;
797 }
798
37dacd7d 799 file = cfg.GetRegionalFileName();
800 if ( (cfg.GetRegionalFileLastVersion() != cfg.GetRegionalFileVersion()) || modified || initFES) {
e8f1ed57 801 status = daqDA_FES_storeFile(file.Data(), "REGIONAL");
4fd5ed63 802 if (status) {
37dacd7d 803 printf("Failed to export file: %s\n",cfg.GetRegionalFileName());
98bdda22 804 return kFALSE;
4fd5ed63 805 }
37dacd7d 806 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetRegionalFileName());
807 out << cfg.GetRegionalFileName() << endl;
bb440407 808
809 // needed for the initialisation of the mapping
810 if (!globalExported) {
811 file = cfg.GetGlobalFileName();
812 status = daqDA_FES_storeFile(file.Data(), "GLOBAL");
813 if (status) {
814 printf("Failed to export file: %s\n",cfg.GetGlobalFileName());
98bdda22 815 return kFALSE;
bb440407 816 }
817 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetGlobalFileName());
818 out << cfg.GetGlobalFileName() << endl;
819 }
820
4fd5ed63 821 }
822
87f615d8 823 if (cfg.SaveScalers()) {
824 out << cfg.GetTrigScalFileName() << endl;
825 }
826
4fd5ed63 827 out.close();
828
829 // export Exported file to FES anyway
e8f1ed57 830 status = daqDA_FES_storeFile(fileExp.Data(), "EXPORTED");
4fd5ed63 831 if (status) {
832 printf("Failed to export file: %s\n", fileExp.Data());
98bdda22 833 return kFALSE;
4fd5ed63 834 }
37dacd7d 835 if(cfg.GetPrintLevel()) printf("Export file: %s\n",fileExp.Data());
4fd5ed63 836
113ad708 837 // write last current file
37dacd7d 838 WriteLastCurrentFile(cfg,cfg.GetLastCurrentFileName());
113ad708 839
98bdda22 840 return kTRUE;
4fd5ed63 841}
41a38dec 842
4fd5ed63 843//__________________
37dacd7d 844Bool_t ImportFiles(AliDAConfig& cfg)
4fd5ed63 845{
37dacd7d 846 /// copy locally a file from daq detector config db
847 /// The current detector is identified by detector code in variable
848 /// DATE_DETECTOR_CODE. It must be defined.
849 /// If environment variable DAQDA_TEST_DIR is defined, files are copied from
850 /// DAQDA_TEST_DIR instead of the database.
851 /// The usual environment variables are not needed.
4fd5ed63 852
41a38dec 853 Int_t status = 0;
4fd5ed63 854
e8f1ed57 855#ifdef OFFLINE
87f615d8 856 gSystem->Setenv("DAQDALIB_PATH", "$DATE_ROOT/db");
e8f1ed57 857#endif
113ad708 858
37dacd7d 859 status = daqDA_DB_getFile(cfg.GetDAConfigFileName(), cfg.GetDAConfigFileName());
4fd5ed63 860 if (status) {
37dacd7d 861 printf("Failed to get DA config file from DB: %s\n",cfg.GetDAConfigFileName());
98bdda22 862 return kFALSE;
4fd5ed63 863 }
864
327f7faa 865 ReadDAConfig(cfg);
e8f1ed57 866
37dacd7d 867 status = daqDA_DB_getFile(cfg.GetCurrentFileName(), cfg.GetCurrentFileName());
4fd5ed63 868 if (status) {
37dacd7d 869 printf("Failed to get current config file from DB: %s\n",cfg.GetCurrentFileName());
98bdda22 870 return kFALSE;
4fd5ed63 871 }
e8f1ed57 872
327f7faa 873 ReadFileNames(cfg);
4fd5ed63 874
37dacd7d 875 status = daqDA_DB_getFile(cfg.GetGlobalFileName(), cfg.GetGlobalFileName());
327f7faa 876 if (status) {
37dacd7d 877 printf("Failed to get current config file from DB: %s\n", cfg.GetGlobalFileName());
98bdda22 878 return kFALSE;
327f7faa 879 }
41a38dec 880
37dacd7d 881 status = daqDA_DB_getFile(cfg.GetRegionalFileName(), cfg.GetRegionalFileName());
4fd5ed63 882 if (status) {
37dacd7d 883 printf("Failed to get current config file from DB: %s\n",cfg.GetRegionalFileName());
98bdda22 884 return kFALSE;
4fd5ed63 885 }
886
37dacd7d 887 status = daqDA_DB_getFile(cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileName());
4fd5ed63 888 if (status) {
37dacd7d 889 printf("Failed to get current config file from DB: %s\n",cfg.GetLocalMaskFileName());
98bdda22 890 return kFALSE;
4fd5ed63 891 }
892
37dacd7d 893 status = daqDA_DB_getFile(cfg.GetLocalLutFileName(), cfg.GetLocalLutFileName());
4fd5ed63 894 if (status) {
37dacd7d 895 printf("Failed to get current config file from DB: %s\n",cfg.GetLocalLutFileName());
98bdda22 896 return kFALSE;
4fd5ed63 897 }
898
98bdda22 899 return kTRUE;
4fd5ed63 900}
901
902//_____________
37dacd7d 903void ReadMaskFiles(AliDAConfig& cfg)
4fd5ed63 904{
37dacd7d 905 /// read mask files
327f7faa 906
37dacd7d 907 const Char_t* localFile = cfg.GetLocalMaskFileName();
908 const Char_t* regionalFile = cfg.GetRegionalFileName();
909 const Char_t* globalFile = cfg.GetGlobalFileName();
4fd5ed63 910
37dacd7d 911 cfg.GetTriggerIO()->ReadConfig(localFile, regionalFile, globalFile, cfg.GetLocalMasks(), cfg.GetRegionalMasks(), cfg.GetGlobalMasks());
4fd5ed63 912}
4fd5ed63 913
41a38dec 914//______________________________________________________________
37dacd7d 915UInt_t GetFetMode(const AliDAConfig & cfg)
41a38dec 916{
37dacd7d 917 /// FET mode = 3 to run algorithm for dead global inputs
918 /// 0x3 prepulse
919 /// 0x0 internal
4fd5ed63 920
37dacd7d 921 return cfg.GetGlobalMasks()->GetFetRegister(3);
4fd5ed63 922
41a38dec 923}
4fd5ed63 924
41a38dec 925//______________________________________________________________
37dacd7d 926void StoreGlobalInput(AliDAConfig& cfg, const UInt_t * const globalInput)
41a38dec 927{
37dacd7d 928 /// accumulate and build statistics of global input values
41a38dec 929
37dacd7d 930 for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
931 for (Int_t ib = 0; ib < cfg.GetGlobalInputLength(); ib++) {
41a38dec 932 // lsb -> msb
37dacd7d 933 if (cfg.GetAlgoNoisyInput())
934 cfg.AddAccGlobalInputN(ii,ib,((globalInput[ii] >> ib) & 0x1));
935 if (cfg.GetAlgoDeadcInput())
936 cfg.AddAccGlobalInputD(ii,ib,((globalInput[ii] >> ib) & 0x1));
4fd5ed63 937 }
41a38dec 938 }
4fd5ed63 939
940}
941
41a38dec 942//______________________________________________________________
37dacd7d 943void UpdateGlobalMasks(AliDAConfig& cfg)
4fd5ed63 944{
37dacd7d 945 /// update the global masks
4fd5ed63 946
e8f1ed57 947#ifdef OFFLINE
87f615d8 948 gSystem->Setenv("DAQDALIB_PATH", "$DATE_ROOT/db");
e8f1ed57 949#endif
327f7faa 950
41a38dec 951 Float_t rateN = 0.0, rateD = 0.0;
952 UInt_t gmask[4], omask;
98bdda22 953 Bool_t noise, deadc, withEvN, withEvD, updated = kFALSE;
41a38dec 954
37dacd7d 955 for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
41a38dec 956 gmask[ii] = 0;
957
37dacd7d 958 for (Int_t ib = 0; ib < cfg.GetGlobalInputLength(); ib++) {
41a38dec 959 // lsb -> msb
98bdda22 960 noise = kFALSE;
961 deadc = kFALSE;
962 withEvN = kFALSE;
963 withEvD = kFALSE;
37dacd7d 964 if (cfg.GetEventsN() > cfg.GetMinEvents()) {
965 rateN = (Float_t)cfg.GetAccGlobalInputN(ii,ib)/(Float_t)cfg.GetEventsN();
966 noise = (rateN > cfg.GetThrN());
98bdda22 967 withEvN = kTRUE;
4fd5ed63 968 }
37dacd7d 969 if (cfg.GetEventsD() > cfg.GetMinEvents()) {
970 rateD = (Float_t)cfg.GetAccGlobalInputD(ii,ib)/(Float_t)cfg.GetEventsD();
971 deadc = (rateD < cfg.GetThrD());
98bdda22 972 withEvD = kTRUE;
41a38dec 973 }
974 if (!withEvN && !withEvD) {
975 // - copy the bit from the old mask
37dacd7d 976 gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
e8f1ed57 977 if (cfg.GetPrintLevel())
978 printf("Mask not changed (just copy the old values)\n");
41a38dec 979 }
980 if (!withEvN && withEvD) {
981 if (!deadc) {
982 // - create a new mask, set the bit to 1
8f8ae0de 983 // not allowed!
984 //gmask[ii] |= 0x1 << ib;
985 // - copy the bit from the old mask
37dacd7d 986 gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
41a38dec 987 } else {
988 // - create a new mask, set the bit to 0
989 gmask[ii] |= 0x0 << ib;
e8f1ed57 990 if (cfg.GetPrintLevel())
991 printf("Found dead channel %1d:%02d (%4.2f) \n",ii,ib,rateD);
4fd5ed63 992 }
41a38dec 993 }
994 if (withEvN && !withEvD) {
995 if (!noise) {
996 // - create a new mask, set the bit to 1
8f8ae0de 997 // not allowed!
998 //gmask[ii] |= 0x1 << ib;
999 // - copy the bit from the old mask
37dacd7d 1000 gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
41a38dec 1001 } else {
1002 // - create a new mask, set the bit to 0
1003 gmask[ii] |= 0x0 << ib;
e8f1ed57 1004 if (cfg.GetPrintLevel())
1005 printf("Found noisy channel %1d:%02d (%4.2f) \n",ii,ib,rateN);
41a38dec 1006 }
1007 }
1008 if (withEvN && withEvD) {
1009 if (!noise && !deadc) {
1010 // - create a new mask, set the bit to 1
8f8ae0de 1011 // not allowed!
1012 //gmask[ii] |= 0x1 << ib;
1013 // - copy the bit from the old mask
37dacd7d 1014 gmask[ii] |= ((cfg.GetGlobalMasks()->GetGlobalMask(ii) >> ib) & 0x1) << ib;
41a38dec 1015 } else {
1016 // - create a new mask, set the bit to 0
1017 gmask[ii] |= 0x0 << ib;
e8f1ed57 1018 if (cfg.GetPrintLevel()) {
1019 if (noise)
1020 printf("Found noisy channel %1d:%02d (%4.2f) \n",ii,ib,rateN);
1021 if (deadc)
1022 printf("Found dead channel %1d:%02d (%4.2f) \n",ii,ib,rateD);
1023 }
4fd5ed63 1024 }
4fd5ed63 1025 }
1026 }
41a38dec 1027 }
1028
1029 // check if at least one mask value has been changed from previous version
37dacd7d 1030 for (Int_t ii = 0; ii < cfg.GetGlobalInputs(); ii++) {
327f7faa 1031 printf("Global mask [%1d] %08x \n",ii,gmask[ii]);
37dacd7d 1032 omask = cfg.GetGlobalMasks()->GetGlobalMask(ii);
41a38dec 1033 if (gmask[ii] != omask) {
98bdda22 1034 updated = kTRUE;
37dacd7d 1035 cfg.GetGlobalMasks()->SetGlobalMask(ii,gmask[ii]);
4fd5ed63 1036 }
41a38dec 1037 }
4fd5ed63 1038
41a38dec 1039 Int_t status = 0;
1040 if (updated) {
1041
1042 // update version
37dacd7d 1043 cfg.IncGlobalFileVersion();
41a38dec 1044
1045 // don't change the file version ("-x.dat")
1046
37dacd7d 1047 cfg.GetTriggerIO()->WriteGlobalConfig(cfg.GetGlobalFileName(),cfg.GetGlobalMasks());
41a38dec 1048
1049 // write last current file
37dacd7d 1050 WriteLastCurrentFile(cfg,cfg.GetCurrentFileName());
4fd5ed63 1051
37dacd7d 1052 status = daqDA_DB_storeFile(cfg.GetGlobalFileName(), cfg.GetGlobalFileName());
41a38dec 1053 if (status) {
37dacd7d 1054 printf("Failed to export file to DB: %s\n",cfg.GetGlobalFileName());
41a38dec 1055 return;
1056 }
1057
37dacd7d 1058 status = daqDA_DB_storeFile(cfg.GetCurrentFileName(), cfg.GetCurrentFileName());
41a38dec 1059 if (status) {
37dacd7d 1060 printf("Failed to export file to DB: %s\n",cfg.GetCurrentFileName());
41a38dec 1061 return;
1062 }
113ad708 1063
41a38dec 1064 }
1065
1066}
113ad708 1067
98bdda22 1068//______________________________________________________________
1069void UpdateLocalMask(AliDAConfig& cfg, Int_t localBoardId, Int_t connector, Int_t strip)
1070{
1071
1072 /// update local strip mask
1073
1074 AliMUONVCalibParam* localMask =
1075 static_cast<AliMUONVCalibParam*>(cfg.GetLocalMasksDA()->FindObject(localBoardId));
1076
1077 UShort_t mask = static_cast<UShort_t>(localMask->ValueAsInt(connector,0));
1078
1079 mask &= ~(0x1 << strip); // set strip mask to zero
1080
1081 localMask->SetValueAsInt(connector, 0, mask);
1082
1083}
1084
1085//______________________________________________________________
1086void MakePattern(AliDAConfig& cfg, Int_t localBoardId, const TArrayS& xPattern, const TArrayS& yPattern)
1087{
1088 /// calculate the hit map for each strip in x and y direction
1089
1090 AliMUONVCalibParam* pat = 0x0;
1091
1092 if (cfg.GetAlgoNoisyInput())
1093 pat = static_cast<AliMUONVCalibParam*>(cfg.GetPatternStoreN()->FindObject(localBoardId));
1094 if (cfg.GetAlgoDeadcInput())
1095 pat = static_cast<AliMUONVCalibParam*>(cfg.GetPatternStoreD()->FindObject(localBoardId));
1096
1097 if (!pat) {
1098 pat = new AliMUONCalibParamND(2, 64, localBoardId, 0, 0.);
1099 if (cfg.GetAlgoNoisyInput())
1100 cfg.GetPatternStoreN()->Add(pat);
1101 if (cfg.GetAlgoDeadcInput())
1102 cfg.GetPatternStoreD()->Add(pat);
1103 }
1104
1105 for (Int_t i = 0; i < 4; ++i) {
1106 for (Int_t j = 0; j < 16; ++j) {
1107
1108 Int_t xMask = xPattern[i];
1109 Int_t yMask = yPattern[i];
1110
1111 Int_t index = 16*i + j;
1112 Double_t patOcc = 0.;
1113
1114 if ( (xMask >> j ) & 0x1 ) {
1115 patOcc = pat->ValueAsDouble(index, 0) + 1.;
1116 pat->SetValueAsDouble(index, 0, patOcc);
1117 }
1118 if ( (yMask >> j ) & 0x1 ) {
1119 patOcc = pat->ValueAsDouble(index, 1) + 1.;
1120 pat->SetValueAsDouble(index, 1, patOcc);
1121 }
1122 }
1123 }
1124
1125}
1126
1127//______________________________________________________________
1128void MakePatternStore(AliDAConfig& cfg)
1129{
1130 /// analyse patterns for local strips (calculate occupancy)
1131
1132#ifdef OFFLINE
87f615d8 1133 gSystem->Setenv("DAQDALIB_PATH", "$DATE_ROOT/db");
98bdda22 1134#endif
1135
1136 AliMUONVCalibParam* pat;
1137 Int_t localBoardId = 0;
1138 Int_t nEventsN = 0, nEventsD = 0;
1139 UShort_t strip = 0;
1140 Int_t connector = 0;
1141 Bool_t updated = kFALSE;
1142
1143 if (cfg.GetEventsN() > cfg.GetMinEvents()) {
1144 nEventsN = cfg.GetEventsN();
1145 }
1146 if (cfg.GetEventsD() > cfg.GetMinEvents()) {
1147 nEventsD = cfg.GetEventsD();
1148 }
1149
1150 // noisy strips
1151 if (nEventsN > 0) {
1152
1153 TIter next(cfg.GetPatternStoreN()->CreateIterator());
1154
1155 while ( ( pat = dynamic_cast<AliMUONVCalibParam*>(next() ) ) ) {
1156
1157 localBoardId = pat->ID0();
1158
1159 for (Int_t index = 0; index < pat->Size(); index++) {
1160
1161 Double_t patXOcc = pat->ValueAsDouble(index, 0)/(Double_t)nEventsN;
1162 Double_t patYOcc = pat->ValueAsDouble(index, 1)/(Double_t)nEventsN;
1163
1164 pat->SetValueAsDouble(index, 0, patXOcc);
1165 pat->SetValueAsDouble(index, 1, patYOcc);
1166
1167 // check for x strip
1168 if (patXOcc > cfg.GetThrLocN()) {
1169 strip = index % 16;
1170 connector = index/16;
1171 UpdateLocalMask(cfg, localBoardId, connector, strip);
1172 }
1173 // check for y strip
1174 if (patYOcc > cfg.GetThrLocN()) {
1175 strip = index % 16;
1176 connector = index/16 + 4;
1177 UpdateLocalMask(cfg, localBoardId, connector, strip);
1178 }
1179
1180 }
1181 }
1182
1183 }
1184
1185 // dead strips
1186 if (nEventsD > 0) {
1187
1188 TIter next(cfg.GetPatternStoreD()->CreateIterator());
1189
1190 while ( ( pat = dynamic_cast<AliMUONVCalibParam*>(next() ) ) ) {
1191
1192 localBoardId = pat->ID0();
1193
1194 for (Int_t index = 0; index < pat->Size(); index++) {
1195
1196 Double_t patXOcc = pat->ValueAsDouble(index, 0)/(Double_t)nEventsD;
1197 Double_t patYOcc = pat->ValueAsDouble(index, 1)/(Double_t)nEventsD;
1198
1199 pat->SetValueAsDouble(index, 0, patXOcc);
1200 pat->SetValueAsDouble(index, 1, patYOcc);
1201
1202 // check for x strip
1203 if (patXOcc < cfg.GetThrLocD()) {
1204 strip = index % 16;
1205 connector = index/16;
1206 UpdateLocalMask(cfg, localBoardId, connector, strip);
1207 }
1208 // check for y strip
1209 if (patYOcc < cfg.GetThrLocD()) {
1210 strip = index % 16;
1211 connector = index/16 + 4;
1212 UpdateLocalMask(cfg, localBoardId, connector, strip);
1213 }
1214
1215 }
1216 }
1217
1218 }
1219
7df9b0e4 1220 // make and AND with the previous version of the mask and
1221 // check if the mask has changed
98bdda22 1222 UShort_t maskDA, mask;
7df9b0e4 1223 Int_t nMaskBits = AliMpConstants::TotalNofLocalBoards()*8*16;
1224 Int_t nMaskBitsChanged = 0;
98bdda22 1225 for (localBoardId = 1; localBoardId <= AliMpConstants::TotalNofLocalBoards(); localBoardId++) {
1226 AliMUONVCalibParam* localMaskDA = static_cast<AliMUONVCalibParam*>(cfg.GetLocalMasksDA()->FindObject(localBoardId));
1227 AliMUONVCalibParam* localMask = static_cast<AliMUONVCalibParam*>(cfg.GetLocalMasks()->FindObject(localBoardId));
1228 for (connector = 0; connector < 8; connector++) {
1229 maskDA = static_cast<UShort_t>(localMaskDA->ValueAsInt(connector,0));
7df9b0e4 1230 mask = static_cast<UShort_t>(localMask->ValueAsInt(connector,0));
1231 maskDA &= mask;
1232 localMaskDA->SetValueAsInt(connector, 0, maskDA);
98bdda22 1233 if (maskDA != mask) {
1234 updated = kTRUE;
7df9b0e4 1235 // calculated percentage of mask bits changed
1236 for (Int_t iBit = 0; iBit < 16; iBit++) {
1237 if (((maskDA >> iBit) & 0x1) != ((mask >> iBit) &0x1)) {
1238 nMaskBitsChanged++;
1239 }
1240 }
98bdda22 1241 }
1242 }
1243 }
1244
5f6ff25f 1245 printf("LOCAL mask bits changed = %5d (%7.3f %%) \n",nMaskBitsChanged,100*(Float_t)nMaskBitsChanged/(Float_t)nMaskBits);
7df9b0e4 1246
98bdda22 1247 Int_t status = 0;
1248 if (updated) {
1249
1250 // update version
1251 cfg.IncLocalMaskFileVersion();
1252
1253 // don't change the file version ("-x.dat")
1254
b22f6547 1255 cfg.GetTriggerIO()->WriteLocalMasks(cfg.GetLocalMaskFileName(),*cfg.GetLocalMasksDA());
98bdda22 1256
1257 // write last current file
1258 WriteLastCurrentFile(cfg,cfg.GetCurrentFileName());
1259
1260 status = daqDA_DB_storeFile(cfg.GetLocalMaskFileName(), cfg.GetLocalMaskFileName());
1261 if (status) {
1262 printf("Failed to export file to DB: %s\n",cfg.GetLocalMaskFileName());
1263 return;
1264 }
1265
1266 status = daqDA_DB_storeFile(cfg.GetCurrentFileName(), cfg.GetCurrentFileName());
1267 if (status) {
1268 printf("Failed to export file to DB: %s\n",cfg.GetCurrentFileName());
1269 return;
1270 }
1271
1272 }
1273
1274}
1275
9f5fafa6 1276//*************************************************************//
9f5fafa6 1277int main(Int_t argc, Char_t **argv)
1278{
37dacd7d 1279 /// main routine
9f5fafa6 1280
1281 // needed for streamer application
327f7faa 1282 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo", "RIO", "TStreamerInfo()");
1283
1284 /* check that we got some arguments = list of files */
1285 if (argc<2) {
1286 printf("Wrong number of arguments\n");
1287 return -1;
1288 }
1289
37dacd7d 1290 AliDAConfig cfg;
9f5fafa6 1291
8f8ae0de 1292 Char_t inputFile[256] = "";
113ad708 1293 inputFile[0] = 0;
1294 if (argc > 1)
1295 if (argv[1] != NULL)
1296 strncpy(inputFile, argv[1], 256);
1297 else {
1298 printf("MUONTRGda : No input File !\n");
1299 return -1;
1300 }
9f5fafa6 1301
4fd5ed63 1302 // decoding the events
9f5fafa6 1303
bb440407 1304 Int_t status = 0;
4fd5ed63 1305 Int_t nDateEvents = 0;
9f5fafa6 1306
4fd5ed63 1307 void* event;
9f5fafa6 1308
4fd5ed63 1309 // containers
e8f1ed57 1310 // old decoder
98bdda22 1311 AliMUONDDLTrigger* ddlTrigger = 0x0;
1312 AliMUONDarcHeader* darcHeader = 0x0;
1313 AliMUONRegHeader* regHeader = 0x0;
1314 AliMUONLocalStruct* localStruct = 0x0;
e8f1ed57 1315 // new (fast) decoder
98bdda22 1316 const AliMUONRawStreamTriggerHP::AliHeader* darcHeaderHP = 0x0;
1317 const AliMUONRawStreamTriggerHP::AliLocalStruct* localStructHP = 0x0;
1318
1319 TArrayS xPattern(4);
1320 TArrayS yPattern(4);
1321 Int_t localBoardId = 0;
9f5fafa6 1322
4fd5ed63 1323 TStopwatch timers;
9f5fafa6 1324
4fd5ed63 1325 timers.Start(kTRUE);
9f5fafa6 1326
4fd5ed63 1327 // comment out, since we do not retrieve files from database
327f7faa 1328 if (!ImportFiles(cfg)) {
4fd5ed63 1329 printf("Import from DB failed\n");
1330 printf("For local test set DAQDA_TEST_DIR to the local directory where the Mtg files are located \n");
9f5fafa6 1331 return -1;
1332 }
327f7faa 1333
1334 ReadMaskFiles(cfg);
4fd5ed63 1335
e8f1ed57 1336#ifdef OFFLINE
1337 // the run number extracted from the file name
1338 TString tmp(inputFile);
5f6ff25f 1339 Int_t pos1 = tmp.First('d');
1340 Int_t pos2 = tmp.Last('.');
1341 Int_t len = pos2 - (pos1+3);
1342 tmp = tmp(pos1+3,len);
e8f1ed57 1343 gSystem->Setenv("DATE_RUN_NUMBER",tmp.Data());
1344 gSystem->Exec("echo \"DATE_RUN_NUMBER = \" $DATE_RUN_NUMBER");
1345#endif
37dacd7d 1346
327f7faa 1347 if(!ExportFiles(cfg)) {
41a38dec 1348 printf("ExportFiles failed\n");
1349 return -1;
1350 }
1351
41a38dec 1352 // FET is triggered by CTP
e8f1ed57 1353 Bool_t modeFET3 = kTRUE;
327f7faa 1354 if (GetFetMode(cfg) != 3) {
e8f1ed57 1355 printf("FET is not in mode 3. Only PHYSICS events will be analysed (noisy channels)\n");
1356 modeFET3 = kFALSE;
41a38dec 1357 }
87f615d8 1358
41a38dec 1359 // All 5 global cards are controlled by the Mts proxy
87f615d8 1360 // sans carte JTAG 0x1F ---> 0x0F (!)
37dacd7d 1361 if (cfg.GetGlobalMasks()->GetGlobalCrateEnable() != 0x1F) {
41a38dec 1362 printf("The MTS proxy does not control all global cards\n");
1363 return -1;
1364 }
87f615d8 1365
41a38dec 1366 // The global cards are ON (active on the global inputs)
37dacd7d 1367 if (!cfg.GetGlobalMasks()->GetMasksOn()) {
41a38dec 1368 printf("Global masks are not ON\n");
1369 return -1;
1370 }
87f615d8 1371
41a38dec 1372 // make sure to catch the "rare" calib events (1 every 50s in physics)
1373 const Char_t* tableSOD[] = {"ALL", "yes", "CAL", "all", NULL, NULL};
1374 monitorDeclareTable(const_cast<char**>(tableSOD));
1375
4fd5ed63 1376 status = monitorSetDataSource(inputFile);
1377 if (status) {
1378 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
1379 << " " << monitorDecodeError(status) << endl;
1380 return -1;
1381 }
1382 status = monitorDeclareMp("MUON Trigger monitoring");
1383 if (status) {
1384 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
1385 << " " << monitorDecodeError(status) << endl;
1386 return -1;
9f5fafa6 1387 }
1388
113ad708 1389 /* define wait event timeout - 1s max */
1390 monitorSetNowait();
1391 monitorSetNoWaitNetworkTimeout(1000);
1392
113ad708 1393 cout << "MUONTRGda : Reading data from file " << inputFile <<endl;
4fd5ed63 1394
87f615d8 1395 UInt_t nCalibEvents;
1396 UInt_t elapsT;
1397 UInt_t deltaT;
1398 UInt_t glSc[6];
1399 Bool_t overFlow, firstCalibEvent = kTRUE;
1400 const Int_t nTriChambers = AliMpConstants::NofTriggerChambers();
1401 const Int_t nLocBoards = AliMpConstants::NofLocalBoards();
1402 const Int_t nCathodes = 2;
1403 UInt_t locLptScaler[nLocBoards];
1404 ULong64_t locStripScaler[nTriChambers][nLocBoards][nCathodes];
1405 UInt_t locStripOver[nTriChambers][nLocBoards][nCathodes];
1406
1407 const Int_t bufflen =
1408 8*sizeof(UInt_t)+
1409 nLocBoards*sizeof(UInt_t)+
1410 nLocBoards*nCathodes*nTriChambers*(sizeof(UInt_t)+sizeof(ULong64_t));
1411 UChar_t buffer[bufflen];
1412 //printf("Buffer length = %d bytes \n",bufflen);
1413
1414 // reset scalers
1415 deltaT = 0.;
1416 nCalibEvents = 0;
1417 for (Int_t bit = 0; bit < 6; bit++) {
1418 glSc[bit] = 0;
1419 }
1420 for (Int_t iLoc = 0; iLoc < nLocBoards; iLoc++) {
1421 locLptScaler[iLoc] = 0;
1422 for (Int_t iCath = 0; iCath < nCathodes; iCath++) {
1423 for (Int_t iCha = 0; iCha < nTriChambers; iCha++) {
1424 locStripScaler[iCha][iLoc][iCath] = 0;
1425 locStripOver[iCha][iLoc][iCath] = 0;
1426 }
1427 }
1428 }
1429
1430 FILE* fsc = fopen(cfg.GetTrigScalFileName(),"wb");
1431
e8f1ed57 1432 UInt_t *globalInput = new UInt_t[4];
98bdda22 1433 Bool_t doUpdate = kFALSE;
327f7faa 1434 Int_t runNumber = 0;
1435 Int_t nEvents = 0;
1436
87f615d8 1437 // event loop
4fd5ed63 1438 while(1)
1439 {
87f615d8 1440
e8f1ed57 1441 if (cfg.GetPrintLevel()) {
1442 if (nEvents && nEvents % 1000 == 0)
327f7faa 1443 cout<<"Cumulated events " << nEvents << endl;
e8f1ed57 1444 }
4fd5ed63 1445 // check shutdown condition
1446 if (daqDA_checkShutdown())
1447 break;
1448
1449 // Skip Events if needed
37dacd7d 1450 while (cfg.GetSkipEvents()) {
4fd5ed63 1451 status = monitorGetEventDynamic(&event);
37dacd7d 1452 cfg.DecSkipEvents();
4fd5ed63 1453 }
1454
1455 // starts reading
1456 status = monitorGetEventDynamic(&event);
1457 if (status < 0) {
113ad708 1458 cout << "MUONTRGda : EOF found" << endl;
4fd5ed63 1459 break;
1460 }
1461
1462 nDateEvents++;
1463
1464 // decoding rawdata headers
1465 AliRawReader *rawReader = new AliRawReaderDate(event);
9f5fafa6 1466
4fd5ed63 1467 Int_t eventType = rawReader->GetType();
327f7faa 1468 runNumber = rawReader->GetRunNumber();
9f5fafa6 1469
87f615d8 1470 if (cfg.GetDAFlag() && (nEvents < cfg.GetMaxEvents())) {
1471 // L1Swc1
1472 // CALIBRATION_EVENT
1473 // SYSTEM_SOFTWARE_TRIGGER_EVENT
1474 // DETECTOR_SOFTWARE_TRIGGER_EVENT
1475 cfg.SetAlgoNoisyInput(kFALSE);
1476 cfg.SetAlgoDeadcInput(kFALSE);
1477 if (eventType == PHYSICS_EVENT) {
1478 cfg.SetAlgoNoisyInput(kTRUE);
1479 doUpdate = kTRUE;
1480 cfg.IncNoiseEvent();
1481 } else if (modeFET3 && eventType == CALIBRATION_EVENT) {
1482 cfg.SetAlgoDeadcInput(kTRUE);
1483 doUpdate = kTRUE;
1484 cfg.IncDeadcEvent();
1485 } else {
1486 continue;
1487 }
1488 }
1489 /*
41a38dec 1490 if (eventType == PHYSICS_EVENT) {
87f615d8 1491 printf("DBG: PHYSICS_EVENT\n");
e8f1ed57 1492 } else if (modeFET3 && eventType == CALIBRATION_EVENT) {
87f615d8 1493 printf("DBG: CALIBRATION_EVENT\n");
41a38dec 1494 } else {
87f615d8 1495 printf("DBG: OTHER (%d)\n",eventType);
41a38dec 1496 }
87f615d8 1497 */
327f7faa 1498 nEvents++;
e8f1ed57 1499 if (cfg.GetPrintLevel() == 2) printf("\nEvent # %d\n",nEvents);
9f5fafa6 1500
4fd5ed63 1501 // decoding MUON payload
e8f1ed57 1502 AliMUONVRawStreamTrigger *rawStream = 0x0;
1503 if (cfg.UseFastDecoder()) {
1504 rawStream = new AliMUONRawStreamTriggerHP(rawReader);
1505 } else {
1506 rawStream = new AliMUONRawStreamTrigger(rawReader);
1507 }
1508
8f8ae0de 1509 // ... without warnings from the decoder !!!
37dacd7d 1510 if (!cfg.WithWarnings())
8f8ae0de 1511 rawStream->DisableWarnings();
9f5fafa6 1512
87f615d8 1513 // if there is global clock overflow
1514 overFlow = kFALSE;
4fd5ed63 1515 // loops over DDL
1516 while((status = rawStream->NextDDL())) {
9f5fafa6 1517
e8f1ed57 1518 if (cfg.GetPrintLevel() == 2) printf("iDDL %d\n", rawStream->GetDDL());
9f5fafa6 1519
98bdda22 1520 if (cfg.UseFastDecoder()) {
1521 darcHeaderHP = static_cast<AliMUONRawStreamTriggerHP*>(rawStream)->GetHeaders();
1522 if (cfg.GetPrintLevel() == 2) printf("Global output (fast decoder) %x\n", (Int_t)darcHeaderHP->GetGlobalOutput());
1523 for (Int_t ig = 0; ig < cfg.GetGlobalInputs(); ig++) {
1524 globalInput[ig] = darcHeaderHP->GetGlobalInput(ig);
e8f1ed57 1525 }
87f615d8 1526 // global scalers
1527 if (cfg.SaveScalers() && (eventType == CALIBRATION_EVENT)) {
1528 if (darcHeaderHP->GetGlobalFlag()) {
1529 if (firstCalibEvent) {
1530 //printf("Skip first calib event: %x \n",darcHeaderHP->GetGlobalClock());
1531 overFlow = kTRUE;
1532 firstCalibEvent = kFALSE;
1533 } else {
1534 elapsT = darcHeaderHP->GetGlobalClock()/40e6; // [s]
1535 if (elapsT > 50) {
1536 //printf("Possible overflow: %x \n",darcHeaderHP->GetGlobalClock());
1537 overFlow = kTRUE;
1538 } else {
1539 deltaT += elapsT;
1540 nCalibEvents++;
1541 const UInt_t* globScaler = darcHeaderHP->GetGlobalScaler();
1542 for (Int_t bit = 0; bit < 6; bit++) {
1543 glSc[bit] += (double)(*(globScaler+bit));
1544 }
1545 } // end check overflow
1546 } // end first calib event
1547 } // end global flag
1548 } // end scalers calib event
98bdda22 1549 // loop over regional structure
1550 Int_t nReg = (Int_t)static_cast<AliMUONRawStreamTriggerHP*>(rawStream)->GetRegionalHeaderCount();
1551 for(Int_t iReg = 0; iReg < nReg; iReg++) {
1552 // loop over local structures
1553 Int_t nLoc = (Int_t)static_cast<AliMUONRawStreamTriggerHP*>(rawStream)->GetLocalStructCount(iReg);
1554 for(Int_t iLoc = 0; iLoc < nLoc; iLoc++) {
1555 localStructHP = static_cast<AliMUONRawStreamTriggerHP*>(rawStream)->GetLocalStruct(iReg, iLoc);
1556 localBoardId = cfg.GetTriggerIO()->LocalBoardId(rawStream->GetDDL(),iReg,localStructHP->GetId());
1557 if (localBoardId > 0) {
1558 localStructHP->GetXPattern(xPattern);
1559 localStructHP->GetYPattern(yPattern);
87f615d8 1560 if (cfg.GetDAFlag() && (nEvents < cfg.GetMaxEvents())) {
1561 MakePattern(cfg,localBoardId,xPattern,yPattern);
1562 }
1563 // local scalers
1564 if (cfg.SaveScalers() && (eventType == CALIBRATION_EVENT)) {
1565 if (!overFlow) {
1566 // skip dead and copy cards
1567 if(localBoardId <= nLocBoards) {
1568 locLptScaler[localBoardId-1] +=
1569 localStructHP->GetScalars()->fLPtRTrig +
1570 localStructHP->GetScalars()->fLPtLTrig +
1571 localStructHP->GetScalars()->fLPtSTrig;
1572 Int_t cathode = localStructHP->GetComptXY();
1573 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) {
1574 UInt_t scalerVal[4] = {
1575 localStructHP->GetXY1(ibitxy),
1576 localStructHP->GetXY2(ibitxy),
1577 localStructHP->GetXY3(ibitxy),
1578 localStructHP->GetXY4(ibitxy)
1579 };
1580
1581 for(Int_t ich = 0; ich < nTriChambers; ich++) {
1582 // sum over all strips
1583 if (scalerVal[ich] < 0xffff/2) {
1584 locStripScaler[ich][localBoardId-1][cathode] += 2*scalerVal[ich];
1585 } else {
1586 locStripOver[ich][localBoardId-1][cathode]++;
1587 }
1588 } // end chamber loop
1589
1590 } // end strip loop
1591 } // end skip copy cards
1592 } // env check overflow
1593 } // end scalers calib event
1594 } // end valid local
1595 } // end loc loop
1596 } // end reg loop
98bdda22 1597 } else {
1598 ddlTrigger = rawStream->GetDDLTrigger();
1599 darcHeader = ddlTrigger->GetDarcHeader();
1600 if (cfg.GetPrintLevel() == 2) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
1601 globalInput = darcHeader->GetGlobalInput();
1602 // loop over regional structure
1603 Int_t nReg = darcHeader->GetRegHeaderEntries();
1604 for(Int_t iReg = 0; iReg < nReg; iReg++) {
1605 regHeader = darcHeader->GetRegHeaderEntry(iReg);
1606 // loop over local structures
1607 Int_t nLoc = regHeader->GetLocalEntries();
1608 for(Int_t iLoc = 0; iLoc < nLoc; iLoc++) {
1609 localStruct = regHeader->GetLocalEntry(iLoc);
1610 localBoardId = cfg.GetTriggerIO()->LocalBoardId(rawStream->GetDDL(),iReg,localStruct->GetId());
1611 if (localBoardId > 0) {
1612 localStruct->GetXPattern(xPattern);
1613 localStruct->GetYPattern(yPattern);
87f615d8 1614 if (cfg.GetDAFlag() && (nEvents < cfg.GetMaxEvents())) {
1615 MakePattern(cfg,localBoardId,xPattern,yPattern);
1616 }
98bdda22 1617 }
1618 }
1619 }
1620 }
87f615d8 1621 if (cfg.GetDAFlag() && (nEvents < cfg.GetMaxEvents())) {
1622 if (rawStream->GetDDL() == 0) {
1623 StoreGlobalInput(cfg,globalInput);
1624 }
41a38dec 1625 }
98bdda22 1626
4fd5ed63 1627 } // NextDDL
1628
87f615d8 1629 if (cfg.SaveScalers()) {
1630 if (!overFlow && (deltaT > cfg.GetScalerRecTime())) {
1631 //printf("Write scalers after %d events\n",nEvents);
1632 Int_t ibw = 0;
1633 // global
1634 buffer[ibw++] = (nCalibEvents >> 24) & 0xff;
1635 buffer[ibw++] = (nCalibEvents >> 16) & 0xff;
1636 buffer[ibw++] = (nCalibEvents >> 8) & 0xff;
1637 buffer[ibw++] = (nCalibEvents >> 0) & 0xff;
1638 buffer[ibw++] = (deltaT >> 24) & 0xff;
1639 buffer[ibw++] = (deltaT >> 16) & 0xff;
1640 buffer[ibw++] = (deltaT >> 8) & 0xff;
1641 buffer[ibw++] = (deltaT >> 0) & 0xff;
1642 //printf("nev %u time %u \n",nCalibEvents,deltaT);
1643 for (Int_t bit = 0; bit < 6; bit++) {
1644 buffer[ibw++] = (glSc[bit] >> 24) & 0xff;
1645 buffer[ibw++] = (glSc[bit] >> 16) & 0xff;
1646 buffer[ibw++] = (glSc[bit] >> 8) & 0xff;
1647 buffer[ibw++] = (glSc[bit] >> 0) & 0xff;
1648 //printf("glSc %u \n",glSc[bit]);
1649 }
1650 // local
1651 for (Int_t iLoc = 0; iLoc < nLocBoards; iLoc++) {
1652 buffer[ibw++] = (locLptScaler[iLoc] >> 24) & 0xff;
1653 buffer[ibw++] = (locLptScaler[iLoc] >> 16) & 0xff;
1654 buffer[ibw++] = (locLptScaler[iLoc] >> 8) & 0xff;
1655 buffer[ibw++] = (locLptScaler[iLoc] >> 0) & 0xff;
1656 for (Int_t iCath = 0; iCath < nCathodes; iCath++) {
1657 for (Int_t iCha = 0; iCha < nTriChambers; iCha++) {
1658 //printf("Ch%1dCath%1dLoc%03d %u %u \n",iCha,iCath,iLoc+1,locStripScaler[iCha][iLoc][iCath],locStripOver[iCha][iLoc][iCath]);
1659 // strip scalers
1660 buffer[ibw++] = (locStripScaler[iCha][iLoc][iCath] >> 56) & 0xff;
1661 buffer[ibw++] = (locStripScaler[iCha][iLoc][iCath] >> 48) & 0xff;
1662 buffer[ibw++] = (locStripScaler[iCha][iLoc][iCath] >> 40) & 0xff;
1663 buffer[ibw++] = (locStripScaler[iCha][iLoc][iCath] >> 32) & 0xff;
1664 buffer[ibw++] = (locStripScaler[iCha][iLoc][iCath] >> 24) & 0xff;
1665 buffer[ibw++] = (locStripScaler[iCha][iLoc][iCath] >> 16) & 0xff;
1666 buffer[ibw++] = (locStripScaler[iCha][iLoc][iCath] >> 8) & 0xff;
1667 buffer[ibw++] = (locStripScaler[iCha][iLoc][iCath] >> 0) & 0xff;
1668 // number of strips in overflow
1669 buffer[ibw++] = (locStripOver[iCha][iLoc][iCath] >> 24) & 0xff;
1670 buffer[ibw++] = (locStripOver[iCha][iLoc][iCath] >> 16) & 0xff;
1671 buffer[ibw++] = (locStripOver[iCha][iLoc][iCath] >> 8) & 0xff;
1672 buffer[ibw++] = (locStripOver[iCha][iLoc][iCath] >> 0) & 0xff;
1673 }
1674 }
1675 }
1676 //printf("Write to buffer %d bytes.\n",ibw);
1677 fwrite(&buffer,ibw,1,fsc);
1678 // reset
1679 deltaT = 0.;
1680 nCalibEvents = 0;
1681 for (Int_t bit = 0; bit < 6; bit++) {
1682 glSc[bit] = 0;
1683 }
1684 for (Int_t iLoc = 0; iLoc < nLocBoards; iLoc++) {
1685 locLptScaler[iLoc] = 0;
1686 for (Int_t iCath = 0; iCath < nCathodes; iCath++) {
1687 for (Int_t iCha = 0; iCha < nTriChambers; iCha++) {
1688 locStripScaler[iCha][iLoc][iCath] = 0;
1689 locStripOver[iCha][iLoc][iCath] = 0;
1690 }
1691 }
1692 }
1693 }
1694 } // end write scalers
1695
4fd5ed63 1696 delete rawReader;
1697 delete rawStream;
1698
1699 } // while (1)
1700
87f615d8 1701 if (cfg.GetDAFlag() && (nEvents < cfg.GetMaxEvents())) {
1702 // update configuration files ifrequested event types were found
1703 if (doUpdate) {
1704 if (cfg.GetDAMode() > 0) UpdateGlobalMasks(cfg);
1705 if (cfg.GetDAMode() > 1) MakePatternStore(cfg);
1706 }
98bdda22 1707 }
9f5fafa6 1708
87f615d8 1709 fclose(fsc);
1710
1711 if (cfg.SaveScalers()) {
1712 //printf("Store scalers to FES, DATE_RUN_NUMBER %s \n",gSystem->Getenv("DATE_RUN_NUMBER"));
1713 Int_t stat = 0;
1714 TString file = cfg.GetTrigScalFileName();
1715 stat = daqDA_FES_storeFile(file.Data(), "TRIGSCAL");
1716 if (stat) {
1717 printf("Failed to export file: %s\n",cfg.GetTrigScalFileName());
1718 return stat;
1719 }
1720 if(cfg.GetPrintLevel()) printf("Export file: %s\n",cfg.GetTrigScalFileName());
1721 }
1722
4fd5ed63 1723 timers.Stop();
9f5fafa6 1724
e8f1ed57 1725 cout << "MUONTRGda: DA enable: " << cfg.GetDAFlag() << endl;
1726 cout << "MUONTRGda: Run number: " << runNumber << endl;
1727 cout << "MUONTRGda: Nb of DATE events: " << nDateEvents << endl;
1728 cout << "MUONTRGda: Nb of events used: " << nEvents << endl;
1729 cout << "MUONTRGda: Nb of events used (noise): " << cfg.GetEventsN() << endl;
1730 cout << "MUONTRGda: Nb of events used (deadc): " << cfg.GetEventsD() << endl;
1731 cout << "MUONTRGda: Minumum nr of events for rate calculation: " << cfg.GetMinEvents() << endl;
1732 cout << "MUONTRGda: Maximum nr of analyzed events: " << cfg.GetMaxEvents() << endl;
1733 cout << "MUONTRGda: Skip events from start: " << cfg.GetSkipEvents() << endl;
98bdda22 1734 cout << "MUONTRGda: Threshold for global noisy inputs: " << 100*cfg.GetThrN() << "%" << endl;
1735 cout << "MUONTRGda: Threshold for global dead inputs: " << 100*cfg.GetThrD() << "%" << endl;
1736 cout << "MUONTRGda: Threshold for local noisy inputs: " << 100*cfg.GetThrLocN() << "%" << endl;
1737 cout << "MUONTRGda: Threshold for local dead inputs: " << 100*cfg.GetThrLocD() << "%" << endl;
e8f1ed57 1738 cout << "MUONTRGda: Print level: " << cfg.GetPrintLevel() << endl;
1739 cout << "MUONTRGda: Show decoder warnings: " << cfg.WithWarnings() << endl;
1740 cout << "MUONTRGda: Use the fast decoder: " << cfg.UseFastDecoder() << endl;
98bdda22 1741 cout << "MUONTRGda: DA mode (1=GLOBAL, 2=GLOBAL+LOCAL): " << cfg.GetDAMode() << endl;
87f615d8 1742 cout << "MUONTRGda: Save scalers: " << cfg.SaveScalers() << endl;
1743 if (cfg.SaveScalers()) {
1744 cout << "MUONTRGda: Time to record scalers: " << cfg.GetScalerRecTime() << " seconds" << endl;
1745 }
327f7faa 1746
1747 printf("MUONTRGda: Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
1748
4fd5ed63 1749 return status;
41a38dec 1750
9f5fafa6 1751}
92c23b09 1752