]>
Commit | Line | Data |
---|---|---|
3e42bf30 | 1 | /* |
113ad708 | 2 | MTR DA for online |
3 | ||
3e42bf30 | 4 | Contact: Franck Manso <manso@clermont.in2p3.fr> |
5 | Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_mtrda.html | |
327f7faa | 6 | Reference run: 61898, 63698 (dead channels), 63701 (noisy channels) |
41a38dec | 7 | Run Type: PHYSICS (noisy channels), STANDALONE (dead channels) |
8 | DA Type: MON | |
9 | Number of events needed: 1000 events for noisy and dead channels | |
3e42bf30 | 10 | Input Files: Rawdata file (DATE format) |
11 | Input Files from DB: | |
12 | MtgGlobalCrate-<version>.dat | |
13 | MtgRegionalCrate-<version>.dat | |
14 | MtgLocalMask-<version>.dat | |
15 | MtgLocalLut-<version>.dat | |
16 | MtgCurrent.dat | |
17 | ||
18 | Output Files: local dir (not persistent) | |
19 | ExportedFiles.dat | |
20 | */ | |
21 | ||
327f7faa | 22 | ////////////////////////////////////////////////////////////////////////////// |
23 | // Detector Algorithm for the MUON trigger configuration. // | |
24 | // // | |
25 | // Calculates masks for the global trigger input, by looking at dead // | |
26 | // channels in calibration runs and at noisy channels in physics runs. // | |
27 | // Transfers trigger configuration files to the File Exchange Server and // | |
28 | // writes them (if modified) into the trigger configuration data base. // | |
29 | // // | |
30 | // Authors: // | |
31 | // Christian Fink (formerly at Subatech, Nantes) // | |
32 | // Franck Manso (LPC Clermont-Ferrand, manso@clermont.in2p3.fr) // | |
33 | // Bogdan Vulpescu (LPC Clermont-Ferrand, vulpescu@clermont.in2p3.fr) // | |
34 | // // | |
35 | ////////////////////////////////////////////////////////////////////////////// | |
3e42bf30 | 36 | |
9f5fafa6 | 37 | extern "C" { |
38 | #include <daqDA.h> | |
39 | } | |
40 | ||
41 | #include "event.h" | |
42 | #include "monitor.h" | |
43 | ||
44 | #include <Riostream.h> | |
45 | #include <stdio.h> | |
46 | #include <stdlib.h> | |
47 | ||
48 | //AliRoot | |
4fd5ed63 | 49 | #include "AliRawReaderDate.h" |
50 | ||
51 | #include "AliMpConstants.h" | |
9f5fafa6 | 52 | #include "AliMUONRawStreamTrigger.h" |
53 | #include "AliMUONDarcHeader.h" | |
9f5fafa6 | 54 | #include "AliMUONDDLTrigger.h" |
4fd5ed63 | 55 | #include "AliMUONVStore.h" |
4fd5ed63 | 56 | #include "AliMUON1DArray.h" |
57 | #include "AliMUONTriggerIO.h" | |
92c23b09 | 58 | #include "AliMUONRegionalTriggerConfig.h" |
59 | #include "AliMUONGlobalCrateConfig.h" | |
60 | #include "AliMUONTriggerCrateConfig.h" | |
9f5fafa6 | 61 | |
62 | //ROOT | |
9f5fafa6 | 63 | #include "TString.h" |
4fd5ed63 | 64 | #include "TSystem.h" |
9f5fafa6 | 65 | #include "TStopwatch.h" |
9f5fafa6 | 66 | #include "TROOT.h" |
67 | #include "TPluginManager.h" | |
9f5fafa6 | 68 | |
327f7faa | 69 | // structure for DA run parameters and DA working space |
70 | struct DAConfig { | |
4fd5ed63 | 71 | |
327f7faa | 72 | const TString fDAConfigFileName; |
73 | const TString fCurrentFileName; | |
74 | const TString fLastCurrentFileName; | |
4fd5ed63 | 75 | |
327f7faa | 76 | TString fSodName; |
77 | Int_t fSodFlag; | |
4fd5ed63 | 78 | |
327f7faa | 79 | TString fDAName; |
80 | Int_t fDAFlag; | |
4fd5ed63 | 81 | |
327f7faa | 82 | TString fGlobalFileName; |
83 | TString fRegionalFileName; | |
84 | TString fLocalMaskFileName; | |
85 | TString fLocalLutFileName; | |
86 | TString fSignatureFileName; | |
4fd5ed63 | 87 | |
327f7faa | 88 | Int_t fGlobalFileVersion; |
89 | Int_t fRegionalFileVersion; | |
90 | Int_t fLocalMaskFileVersion; | |
91 | Int_t fLocalLutFileVersion; | |
92 | Int_t fSignatureFileVersion; | |
93 | ||
94 | Int_t fGlobalFileLastVersion; | |
95 | Int_t fRegionalFileLastVersion; | |
96 | Int_t fLocalMaskFileLastVersion; | |
97 | Int_t fLocalLutFileLastVersion; | |
98 | ||
99 | Int_t fNEventsN; | |
100 | Int_t fNEventsD; | |
101 | ||
102 | Int_t fPrintLevel; | |
103 | ||
104 | AliMUONVStore* fLocalMasks; | |
105 | AliMUONRegionalTriggerConfig* fRegionalMasks; | |
106 | AliMUONGlobalCrateConfig* fGlobalMasks; | |
107 | ||
108 | AliMUONTriggerIO *fTriggerIO; | |
109 | ||
110 | Bool_t fAlgoNoisyInput; | |
111 | Bool_t fAlgoDeadInput; | |
112 | ||
113 | Float_t fThrN; | |
114 | Float_t fThrD; | |
115 | Int_t fMinEvents; | |
116 | Int_t fSkipEvents; | |
117 | Int_t fMaxEvents; | |
118 | Bool_t fWithWarnings; | |
119 | ||
120 | const Int_t fNLocalBoard; | |
121 | ||
122 | enum { kGlobalInputs = 4, kGlobalInputLength = 32 }; | |
123 | ||
124 | Int_t fAccGlobalInputN[kGlobalInputs][kGlobalInputLength]; | |
125 | Int_t fAccGlobalInputD[kGlobalInputs][kGlobalInputLength]; | |
126 | ||
127 | DAConfig() : | |
128 | fDAConfigFileName("DAConfig.txt"), | |
129 | fCurrentFileName("MtgCurrent.dat"), | |
130 | fLastCurrentFileName("MtgLastCurrent.dat"), | |
131 | fSodName(""), | |
132 | fSodFlag(0), | |
133 | fDAName(""), | |
134 | fDAFlag(0), | |
135 | fGlobalFileName(""), | |
136 | fRegionalFileName(""), | |
137 | fLocalMaskFileName(""), | |
138 | fLocalLutFileName(""), | |
139 | fSignatureFileName(""), | |
140 | fGlobalFileVersion(0), | |
141 | fRegionalFileVersion(0), | |
142 | fLocalMaskFileVersion(0), | |
143 | fLocalLutFileVersion(0), | |
144 | fSignatureFileVersion(0), | |
145 | fGlobalFileLastVersion(0), | |
146 | fRegionalFileLastVersion(0), | |
147 | fLocalMaskFileLastVersion(0), | |
148 | fLocalLutFileLastVersion(0), | |
149 | fNEventsN(0), | |
150 | fNEventsD(0), | |
151 | fPrintLevel(0), | |
152 | fLocalMasks(0x0), | |
153 | fRegionalMasks(0x0), | |
154 | fGlobalMasks(0x0), | |
155 | fTriggerIO(new AliMUONTriggerIO), | |
156 | fAlgoNoisyInput(false), | |
157 | fAlgoDeadInput(false), | |
158 | fThrN(0.1), | |
159 | fThrD(0.9), | |
160 | fMinEvents(10), | |
161 | fSkipEvents(0), | |
162 | fMaxEvents(65535), | |
163 | fWithWarnings(false), | |
164 | fNLocalBoard(AliMpConstants::TotalNofLocalBoards()+1) | |
165 | { | |
166 | for (Int_t ii = 0; ii < kGlobalInputs; ii++) { | |
167 | for (Int_t il = 0; il < kGlobalInputLength; il++) { | |
168 | fAccGlobalInputN[ii][il] = 0; | |
169 | fAccGlobalInputD[ii][il] = 0; | |
170 | } | |
171 | } | |
172 | } | |
4fd5ed63 | 173 | |
327f7faa | 174 | DAConfig (const DAConfig& cfg); |
175 | DAConfig& operator=(const DAConfig& cfg); | |
4fd5ed63 | 176 | |
327f7faa | 177 | }; |
4fd5ed63 | 178 | |
327f7faa | 179 | //__________________________________________________________________ |
180 | Bool_t ReadDAConfig(DAConfig& cfg) | |
181 | { | |
182 | // read run parameters for the DA | |
4fd5ed63 | 183 | |
327f7faa | 184 | char line[80]; |
4fd5ed63 | 185 | |
327f7faa | 186 | TString file; |
187 | file = cfg.fDAConfigFileName; | |
188 | std::ifstream in(gSystem->ExpandPathName(file.Data())); | |
189 | if (!in.good()) { | |
190 | printf("Cannot open DA configuration file %s ; use default values.\n",file.Data()); | |
191 | return true; | |
192 | } | |
193 | ||
194 | TString tmp; | |
195 | Int_t pos; | |
196 | ||
197 | in.getline(line,80); | |
198 | tmp = line; | |
199 | pos = tmp.First(" "); | |
200 | tmp = tmp(0,pos); | |
201 | cfg.fPrintLevel = tmp.Atoi(); | |
202 | ||
203 | in.getline(line,80); | |
204 | tmp = line; | |
205 | pos = tmp.First(" "); | |
206 | tmp = tmp(0,pos); | |
207 | cfg.fThrN = tmp.Atof(); | |
208 | ||
209 | in.getline(line,80); | |
210 | tmp = line; | |
211 | pos = tmp.First(" "); | |
212 | tmp = tmp(0,pos); | |
213 | cfg.fThrD = tmp.Atof(); | |
214 | ||
215 | in.getline(line,80); | |
216 | tmp = line; | |
217 | pos = tmp.First(" "); | |
218 | tmp = tmp(0,pos); | |
219 | cfg.fMinEvents = tmp.Atoi(); | |
220 | ||
221 | in.getline(line,80); | |
222 | tmp = line; | |
223 | pos = tmp.First(" "); | |
224 | tmp = tmp(0,pos); | |
225 | cfg.fSkipEvents = tmp.Atoi(); | |
4fd5ed63 | 226 | |
327f7faa | 227 | in.getline(line,80); |
228 | tmp = line; | |
229 | pos = tmp.First(" "); | |
230 | tmp = tmp(0,pos); | |
231 | cfg.fMaxEvents = tmp.Atoi(); | |
4fd5ed63 | 232 | |
327f7faa | 233 | in.getline(line,80); |
234 | tmp = line; | |
235 | pos = tmp.First(" "); | |
236 | tmp = tmp(0,pos); | |
237 | cfg.fWithWarnings = tmp.Atoi(); | |
238 | ||
239 | return true; | |
4fd5ed63 | 240 | |
327f7faa | 241 | } |
4fd5ed63 | 242 | |
4fd5ed63 | 243 | //__________________________________________________________________ |
327f7faa | 244 | void WriteLastCurrentFile(DAConfig& cfg, TString currentFile) |
4fd5ed63 | 245 | { |
246 | ||
247 | // write last current file | |
248 | ofstream out; | |
249 | TString file; | |
250 | file = currentFile; | |
251 | out.open(file.Data()); | |
327f7faa | 252 | out << cfg.fSodName << " " << cfg.fSodFlag << endl; |
253 | out << cfg.fDAName << " " << cfg.fDAFlag << endl; | |
4fd5ed63 | 254 | |
327f7faa | 255 | out << cfg.fGlobalFileName << " " << cfg.fGlobalFileVersion << endl; |
256 | out << cfg.fRegionalFileName << " " << cfg.fRegionalFileVersion << endl; | |
257 | out << cfg.fLocalMaskFileName << " " << cfg.fLocalMaskFileVersion << endl; | |
258 | out << cfg.fLocalLutFileName << " " << cfg.fLocalLutFileVersion << endl; | |
259 | out << cfg.fSignatureFileName << " " << cfg.fSignatureFileVersion << endl; | |
4fd5ed63 | 260 | |
261 | out.close(); | |
262 | } | |
263 | ||
264 | //___________________________________________________________________________________________ | |
327f7faa | 265 | Bool_t ReadCurrentFile(DAConfig& cfg, TString currentFile, Bool_t lastCurrentFlag = false) |
4fd5ed63 | 266 | { |
267 | ||
268 | // read last current file name and version | |
269 | char line[80]; | |
270 | char name[80]; | |
271 | ||
272 | TString file; | |
273 | file = currentFile; | |
274 | std::ifstream in(gSystem->ExpandPathName(file.Data())); | |
275 | if (!in.good()) { | |
276 | printf("Cannot open last current file %s\n",currentFile.Data()); | |
277 | return false; | |
278 | } | |
279 | ||
4fd5ed63 | 280 | // read SOD |
281 | in.getline(line,80); | |
327f7faa | 282 | sscanf(line, "%s %d", name, &cfg.fSodFlag); |
283 | cfg.fSodName = name; | |
284 | if (cfg.fPrintLevel) printf("Sod Flag %d\n", cfg.fSodFlag); | |
4fd5ed63 | 285 | |
286 | //read DA | |
287 | in.getline(line,80); | |
327f7faa | 288 | sscanf(line, "%s %d", name, &cfg.fDAFlag); |
289 | cfg.fDAName = name; | |
290 | if (cfg.fPrintLevel) printf("DA Flag: %d\n", cfg.fDAFlag); | |
4fd5ed63 | 291 | |
4fd5ed63 | 292 | // read global |
293 | in.getline(line,80); | |
294 | TString tmp(line); | |
295 | Int_t pos = tmp.First(" "); | |
327f7faa | 296 | cfg.fGlobalFileName = tmp(0, pos); |
4fd5ed63 | 297 | |
298 | if (!lastCurrentFlag) { | |
327f7faa | 299 | cfg.fGlobalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data()); |
300 | if (cfg.fPrintLevel) printf("Global File Name: %s version: %d\n", | |
301 | cfg.fGlobalFileName.Data(), cfg.fGlobalFileVersion); | |
4fd5ed63 | 302 | } else { |
327f7faa | 303 | cfg.fGlobalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data()); |
304 | if (cfg.fPrintLevel) printf("Global File Name: %s last version: %d\n", | |
305 | cfg.fGlobalFileName.Data(), cfg.fGlobalFileLastVersion); | |
4fd5ed63 | 306 | } |
307 | ||
308 | // read regional | |
309 | in.getline(line,80); | |
310 | tmp = line; | |
311 | pos = tmp.First(" "); | |
327f7faa | 312 | cfg.fRegionalFileName = tmp(0, pos); |
4fd5ed63 | 313 | |
314 | if (!lastCurrentFlag) { | |
327f7faa | 315 | cfg.fRegionalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data()); |
316 | if (cfg.fPrintLevel) printf("Regional File Name: %s version: %d\n", | |
317 | cfg.fRegionalFileName.Data(), cfg.fRegionalFileVersion); | |
4fd5ed63 | 318 | |
319 | } else { | |
327f7faa | 320 | cfg.fRegionalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data()); |
321 | if (cfg.fPrintLevel) printf("Regional File Name: %s last version: %d\n", | |
322 | cfg.fRegionalFileName.Data(), cfg.fRegionalFileLastVersion); | |
4fd5ed63 | 323 | } |
324 | ||
4fd5ed63 | 325 | // read mask |
326 | in.getline(line,80); | |
327 | tmp = line; | |
328 | pos = tmp.First(" "); | |
327f7faa | 329 | cfg.fLocalMaskFileName = tmp(0, pos); |
4fd5ed63 | 330 | |
331 | if (!lastCurrentFlag) { | |
327f7faa | 332 | cfg.fLocalMaskFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data()); |
333 | if (cfg.fPrintLevel) printf("Mask File Name: %s version: %d\n", | |
334 | cfg.fLocalMaskFileName.Data(), cfg.fLocalMaskFileVersion); | |
4fd5ed63 | 335 | } else { |
327f7faa | 336 | cfg.fLocalMaskFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data()); |
337 | if (cfg.fPrintLevel) printf("Mask File Name: %s last version: %d\n", | |
338 | cfg.fLocalMaskFileName.Data(), cfg.fLocalMaskFileLastVersion); | |
4fd5ed63 | 339 | } |
340 | // read Lut | |
341 | in.getline(line,80); | |
342 | tmp = line; | |
343 | pos = tmp.First(" "); | |
327f7faa | 344 | cfg.fLocalLutFileName = tmp(0, pos); |
4fd5ed63 | 345 | |
346 | if (!lastCurrentFlag) { | |
327f7faa | 347 | cfg.fLocalLutFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data()); |
348 | if (cfg.fPrintLevel) printf("Lut File Name: %s version: %d\n", | |
349 | cfg.fLocalLutFileName.Data(), cfg.fLocalLutFileVersion); | |
4fd5ed63 | 350 | } else { |
327f7faa | 351 | cfg.fLocalLutFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data()); |
352 | if (cfg.fPrintLevel) printf("Lut File Name: %s last version: %d\n", | |
353 | cfg.fLocalLutFileName.Data(), cfg.fLocalLutFileLastVersion); | |
4fd5ed63 | 354 | } |
355 | ||
356 | in.getline(line,80); | |
357 | tmp = line; | |
358 | pos = tmp.First(" "); | |
327f7faa | 359 | cfg.fSignatureFileName = tmp(0, pos); |
360 | cfg.fSignatureFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data()); | |
361 | if (cfg.fPrintLevel) printf("Lut File Name: %s version: %d\n", | |
362 | cfg.fSignatureFileName.Data(), cfg.fSignatureFileVersion); | |
4fd5ed63 | 363 | |
364 | return true; | |
365 | } | |
366 | ||
367 | //_____________ | |
327f7faa | 368 | void ReadFileNames(DAConfig& cfg) |
4fd5ed63 | 369 | { |
327f7faa | 370 | |
4fd5ed63 | 371 | // if last current file does not exist than read current file |
327f7faa | 372 | if (!ReadCurrentFile(cfg,cfg.fLastCurrentFileName, true)) |
4fd5ed63 | 373 | { |
327f7faa | 374 | ReadCurrentFile(cfg,cfg.fCurrentFileName, true); |
4fd5ed63 | 375 | } |
376 | ||
377 | // any case read current file | |
327f7faa | 378 | ReadCurrentFile(cfg,cfg.fCurrentFileName); |
4fd5ed63 | 379 | |
380 | } | |
381 | ||
382 | //__________________ | |
327f7faa | 383 | Bool_t ExportFiles(DAConfig& cfg) |
4fd5ed63 | 384 | { |
385 | ||
386 | // Export files to FES | |
4fd5ed63 | 387 | // env variables have to be set (suppose by ECS ?) |
388 | // setenv DATE_FES_PATH | |
389 | // setenv DATE_RUN_NUMBER | |
390 | // setenv DATE_ROLE_NAME | |
391 | // setenv DATE_DETECTOR_CODE | |
392 | ||
41a38dec | 393 | // offline: |
394 | //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger"); | |
113ad708 | 395 | |
8f8ae0de | 396 | // offline: use a dummy FES (local directory) |
397 | //gSystem->Setenv("DAQDA_TEST_DIR", "/alisoft/FES"); | |
398 | ||
4fd5ed63 | 399 | // update files |
400 | Int_t status = 0; | |
401 | ||
402 | Bool_t modified = false; | |
403 | ||
404 | ofstream out; | |
405 | TString fileExp("ExportedFiles.dat"); | |
406 | TString file; | |
407 | ||
408 | out.open(fileExp.Data()); | |
409 | if (!out.good()) { | |
410 | printf("Failed to create file: %s\n",file.Data()); | |
411 | return false; | |
113ad708 | 412 | } |
4fd5ed63 | 413 | |
8f8ae0de | 414 | // check if MtgLastCurrent.dat exists |
415 | // if not, do initial export of all files | |
416 | Bool_t initFES = false; | |
417 | if (gSystem->AccessPathName("MtgLastCurrent.dat")) | |
418 | initFES = true; | |
419 | if (initFES) printf("Copy all configuration files to the FES.\n"); | |
420 | ||
327f7faa | 421 | file = cfg.fGlobalFileName; |
422 | if ((cfg.fGlobalFileLastVersion != cfg.fGlobalFileVersion) || initFES) { | |
4fd5ed63 | 423 | status = daqDA_FES_storeFile(file.Data(), file.Data()); |
424 | if (status) { | |
327f7faa | 425 | printf("Failed to export file: %s\n",cfg.fGlobalFileName.Data()); |
4fd5ed63 | 426 | return false; |
427 | } | |
327f7faa | 428 | if(cfg.fPrintLevel) printf("Export file: %s\n",cfg.fGlobalFileName.Data()); |
429 | out << cfg.fGlobalFileName.Data() << endl; | |
4fd5ed63 | 430 | } |
431 | ||
327f7faa | 432 | file = cfg.fLocalMaskFileName; |
433 | if ((cfg.fLocalMaskFileLastVersion != cfg.fLocalMaskFileVersion) || initFES) { | |
4fd5ed63 | 434 | modified = true; |
4fd5ed63 | 435 | status = daqDA_FES_storeFile(file.Data(), file.Data()); |
436 | if (status) { | |
327f7faa | 437 | printf("Failed to export file: %s\n",cfg.fLocalMaskFileName.Data()); |
4fd5ed63 | 438 | return false; |
439 | } | |
327f7faa | 440 | if(cfg.fPrintLevel) printf("Export file: %s\n",cfg.fLocalMaskFileName.Data()); |
441 | out << cfg.fLocalMaskFileName.Data() << endl; | |
4fd5ed63 | 442 | } |
443 | ||
327f7faa | 444 | file = cfg.fLocalLutFileName; |
445 | if ((cfg.fLocalLutFileLastVersion != cfg.fLocalLutFileVersion) || initFES) { | |
4fd5ed63 | 446 | modified = true; |
447 | status = daqDA_FES_storeFile(file.Data(), file.Data()); | |
448 | if (status) { | |
327f7faa | 449 | printf("Failed to export file: %s\n",cfg.fLocalLutFileName.Data()); |
4fd5ed63 | 450 | return false; |
451 | } | |
327f7faa | 452 | if(cfg.fPrintLevel) printf("Export file: %s\n",cfg.fLocalLutFileName.Data()); |
453 | out << cfg.fLocalLutFileName.Data() << endl; | |
4fd5ed63 | 454 | |
455 | } | |
456 | ||
457 | // exported regional file whenever mask or/and Lut are modified | |
327f7faa | 458 | file = cfg.fRegionalFileName; |
459 | if ( (cfg.fRegionalFileLastVersion != cfg.fRegionalFileVersion) || modified || initFES) { | |
4fd5ed63 | 460 | status = daqDA_FES_storeFile(file.Data(), file.Data()); |
461 | if (status) { | |
327f7faa | 462 | printf("Failed to export file: %s\n",cfg.fRegionalFileName.Data()); |
4fd5ed63 | 463 | return false; |
464 | } | |
327f7faa | 465 | if(cfg.fPrintLevel) printf("Export file: %s\n",cfg.fRegionalFileName.Data()); |
466 | out << cfg.fRegionalFileName.Data() << endl; | |
4fd5ed63 | 467 | } |
468 | ||
469 | out.close(); | |
470 | ||
471 | // export Exported file to FES anyway | |
472 | status = daqDA_FES_storeFile(fileExp.Data(), fileExp.Data()); | |
473 | if (status) { | |
474 | printf("Failed to export file: %s\n", fileExp.Data()); | |
475 | return false; | |
476 | } | |
327f7faa | 477 | if(cfg.fPrintLevel) printf("Export file: %s\n",fileExp.Data()); |
4fd5ed63 | 478 | |
113ad708 | 479 | // write last current file |
327f7faa | 480 | WriteLastCurrentFile(cfg,cfg.fLastCurrentFileName); |
113ad708 | 481 | |
4fd5ed63 | 482 | return true; |
483 | } | |
41a38dec | 484 | |
4fd5ed63 | 485 | //__________________ |
327f7faa | 486 | Bool_t ImportFiles(DAConfig& cfg) |
4fd5ed63 | 487 | { |
488 | // copy locally a file from daq detector config db | |
489 | // The current detector is identified by detector code in variable | |
490 | // DATE_DETECTOR_CODE. It must be defined. | |
491 | // If environment variable DAQDA_TEST_DIR is defined, files are copied from DAQDA_TEST_DIR | |
492 | // instead of the database. The usual environment variables are not needed. | |
493 | ||
41a38dec | 494 | Int_t status = 0; |
4fd5ed63 | 495 | |
41a38dec | 496 | // offline: |
113ad708 | 497 | //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db"); |
113ad708 | 498 | |
327f7faa | 499 | status = daqDA_DB_getFile(cfg.fDAConfigFileName.Data(), cfg.fDAConfigFileName.Data()); |
4fd5ed63 | 500 | if (status) { |
327f7faa | 501 | printf("Failed to get DA config file from DB: %s\n",cfg.fDAConfigFileName.Data()); |
4fd5ed63 | 502 | return false; |
503 | } | |
504 | ||
327f7faa | 505 | ReadDAConfig(cfg); |
4fd5ed63 | 506 | |
327f7faa | 507 | status = daqDA_DB_getFile(cfg.fCurrentFileName.Data(), cfg.fCurrentFileName.Data()); |
4fd5ed63 | 508 | if (status) { |
327f7faa | 509 | printf("Failed to get current config file from DB: %s\n",cfg.fCurrentFileName.Data()); |
4fd5ed63 | 510 | return false; |
511 | } | |
327f7faa | 512 | |
513 | ReadFileNames(cfg); | |
4fd5ed63 | 514 | |
327f7faa | 515 | status = daqDA_DB_getFile(cfg.fGlobalFileName.Data(), cfg.fGlobalFileName.Data()); |
516 | if (status) { | |
517 | printf("Failed to get current config file from DB: %s\n", cfg.fGlobalFileName.Data()); | |
518 | return false; | |
519 | } | |
41a38dec | 520 | |
327f7faa | 521 | status = daqDA_DB_getFile(cfg.fRegionalFileName.Data(), cfg.fRegionalFileName.Data()); |
4fd5ed63 | 522 | if (status) { |
327f7faa | 523 | printf("Failed to get current config file from DB: %s\n",cfg.fRegionalFileName.Data()); |
4fd5ed63 | 524 | return false; |
525 | } | |
526 | ||
327f7faa | 527 | status = daqDA_DB_getFile(cfg.fLocalMaskFileName.Data(), cfg.fLocalMaskFileName.Data()); |
4fd5ed63 | 528 | if (status) { |
327f7faa | 529 | printf("Failed to get current config file from DB: %s\n",cfg.fLocalMaskFileName.Data()); |
4fd5ed63 | 530 | return false; |
531 | } | |
532 | ||
327f7faa | 533 | status = daqDA_DB_getFile(cfg.fLocalLutFileName.Data(), cfg.fLocalLutFileName.Data()); |
4fd5ed63 | 534 | if (status) { |
327f7faa | 535 | printf("Failed to get current config file from DB: %s\n",cfg.fLocalLutFileName.Data()); |
4fd5ed63 | 536 | return false; |
537 | } | |
538 | ||
539 | return true; | |
540 | } | |
541 | ||
542 | //_____________ | |
327f7faa | 543 | void ReadMaskFiles(DAConfig& cfg) |
4fd5ed63 | 544 | { |
327f7faa | 545 | |
4fd5ed63 | 546 | // read mask files |
327f7faa | 547 | cfg.fLocalMasks = new AliMUON1DArray(cfg.fNLocalBoard); |
548 | cfg.fRegionalMasks = new AliMUONRegionalTriggerConfig(); | |
549 | cfg.fGlobalMasks = new AliMUONGlobalCrateConfig(); | |
4fd5ed63 | 550 | |
327f7faa | 551 | TString localFile = cfg.fLocalMaskFileName; |
552 | TString regionalFile = cfg.fRegionalFileName; | |
553 | TString globalFile = cfg.fGlobalFileName; | |
4fd5ed63 | 554 | |
327f7faa | 555 | cfg.fTriggerIO->ReadConfig(localFile.Data(), regionalFile.Data(), globalFile.Data(), |
556 | cfg.fLocalMasks, cfg.fRegionalMasks, cfg.fGlobalMasks); | |
4fd5ed63 | 557 | } |
4fd5ed63 | 558 | |
41a38dec | 559 | //______________________________________________________________ |
327f7faa | 560 | UInt_t GetFetMode(DAConfig& cfg) |
41a38dec | 561 | { |
562 | // FET mode = 3 to run algorithm for dead global inputs | |
563 | // 0x3 prepulse | |
564 | // 0x0 internal | |
4fd5ed63 | 565 | |
327f7faa | 566 | return cfg.fGlobalMasks->GetFetRegister(3); |
4fd5ed63 | 567 | |
41a38dec | 568 | } |
4fd5ed63 | 569 | |
41a38dec | 570 | //______________________________________________________________ |
327f7faa | 571 | void StoreGlobalInput(DAConfig& cfg, const UInt_t * const globalInput) |
41a38dec | 572 | { |
573 | // accumulate and build statistics of global input values | |
574 | ||
327f7faa | 575 | for (Int_t ii = 0; ii < cfg.kGlobalInputs; ii++) { |
576 | for (Int_t ib = 0; ib < cfg.kGlobalInputLength; ib++) { | |
41a38dec | 577 | // lsb -> msb |
327f7faa | 578 | if (cfg.fAlgoNoisyInput) |
579 | cfg.fAccGlobalInputN[ii][ib] += (globalInput[ii] >> ib) & 0x1; | |
580 | if (cfg.fAlgoDeadInput) | |
581 | cfg.fAccGlobalInputD[ii][ib] += (globalInput[ii] >> ib) & 0x1; | |
4fd5ed63 | 582 | } |
41a38dec | 583 | } |
4fd5ed63 | 584 | |
585 | } | |
586 | ||
41a38dec | 587 | //______________________________________________________________ |
327f7faa | 588 | void UpdateGlobalMasks(DAConfig& cfg) |
4fd5ed63 | 589 | { |
41a38dec | 590 | // update the global masks |
4fd5ed63 | 591 | |
41a38dec | 592 | // offline: |
593 | //gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db"); | |
327f7faa | 594 | |
41a38dec | 595 | Float_t rateN = 0.0, rateD = 0.0; |
596 | UInt_t gmask[4], omask; | |
597 | Bool_t noise, deadc, withEvN, withEvD, updated = false; | |
598 | ||
327f7faa | 599 | for (Int_t ii = 0; ii < cfg.kGlobalInputs; ii++) { |
41a38dec | 600 | gmask[ii] = 0; |
601 | ||
327f7faa | 602 | for (Int_t ib = 0; ib < cfg.kGlobalInputLength; ib++) { |
41a38dec | 603 | // lsb -> msb |
604 | noise = false; | |
605 | deadc = false; | |
606 | withEvN = false; | |
607 | withEvD = false; | |
327f7faa | 608 | if (cfg.fNEventsN > cfg.fMinEvents) { |
609 | rateN = (Float_t)cfg.fAccGlobalInputN[ii][ib]/(Float_t)cfg.fNEventsN; | |
610 | noise = (rateN > cfg.fThrN); | |
41a38dec | 611 | withEvN = true; |
4fd5ed63 | 612 | } |
327f7faa | 613 | if (cfg.fNEventsD > cfg.fMinEvents) { |
614 | rateD = (Float_t)cfg.fAccGlobalInputD[ii][ib]/(Float_t)cfg.fNEventsD; | |
615 | deadc = (rateD < cfg.fThrD); | |
41a38dec | 616 | withEvD = true; |
617 | } | |
618 | if (!withEvN && !withEvD) { | |
619 | // - copy the bit from the old mask | |
327f7faa | 620 | gmask[ii] |= ((cfg.fGlobalMasks->GetGlobalMask(ii) >> ib) & 0x1) << ib; |
41a38dec | 621 | printf("Mask not changed (just copy the old values)\n"); |
622 | } | |
623 | if (!withEvN && withEvD) { | |
624 | if (!deadc) { | |
625 | // - create a new mask, set the bit to 1 | |
8f8ae0de | 626 | // not allowed! |
627 | //gmask[ii] |= 0x1 << ib; | |
628 | // - copy the bit from the old mask | |
327f7faa | 629 | gmask[ii] |= ((cfg.fGlobalMasks->GetGlobalMask(ii) >> ib) & 0x1) << ib; |
41a38dec | 630 | } else { |
631 | // - create a new mask, set the bit to 0 | |
632 | gmask[ii] |= 0x0 << ib; | |
327f7faa | 633 | printf("Found dead channel %1d:%02d (%4.2f) \n",ii,ib,rateD); |
4fd5ed63 | 634 | } |
41a38dec | 635 | } |
636 | if (withEvN && !withEvD) { | |
637 | if (!noise) { | |
638 | // - create a new mask, set the bit to 1 | |
8f8ae0de | 639 | // not allowed! |
640 | //gmask[ii] |= 0x1 << ib; | |
641 | // - copy the bit from the old mask | |
327f7faa | 642 | gmask[ii] |= ((cfg.fGlobalMasks->GetGlobalMask(ii) >> ib) & 0x1) << ib; |
41a38dec | 643 | } else { |
644 | // - create a new mask, set the bit to 0 | |
645 | gmask[ii] |= 0x0 << ib; | |
327f7faa | 646 | printf("Found noisy channel %1d:%02d (%4.2f) \n",ii,ib,rateN); |
41a38dec | 647 | } |
648 | } | |
649 | if (withEvN && withEvD) { | |
650 | if (!noise && !deadc) { | |
651 | // - create a new mask, set the bit to 1 | |
8f8ae0de | 652 | // not allowed! |
653 | //gmask[ii] |= 0x1 << ib; | |
654 | // - copy the bit from the old mask | |
327f7faa | 655 | gmask[ii] |= ((cfg.fGlobalMasks->GetGlobalMask(ii) >> ib) & 0x1) << ib; |
41a38dec | 656 | } else { |
657 | // - create a new mask, set the bit to 0 | |
658 | gmask[ii] |= 0x0 << ib; | |
659 | if (noise) | |
327f7faa | 660 | printf("Found noisy channel %1d:%02d (%4.2f) \n",ii,ib,rateN); |
41a38dec | 661 | if (deadc) |
327f7faa | 662 | printf("Found dead channel %1d:%02d (%4.2f) \n",ii,ib,rateD); |
4fd5ed63 | 663 | } |
4fd5ed63 | 664 | } |
665 | } | |
41a38dec | 666 | } |
667 | ||
668 | // check if at least one mask value has been changed from previous version | |
327f7faa | 669 | for (Int_t ii = 0; ii < cfg.kGlobalInputs; ii++) { |
670 | printf("Global mask [%1d] %08x \n",ii,gmask[ii]); | |
671 | omask = cfg.fGlobalMasks->GetGlobalMask(ii); | |
41a38dec | 672 | if (gmask[ii] != omask) { |
673 | updated = true; | |
327f7faa | 674 | cfg.fGlobalMasks->SetGlobalMask(ii,gmask[ii]); |
4fd5ed63 | 675 | } |
41a38dec | 676 | } |
4fd5ed63 | 677 | |
41a38dec | 678 | Int_t status = 0; |
679 | if (updated) { | |
680 | ||
681 | // update version | |
327f7faa | 682 | cfg.fGlobalFileVersion++; |
41a38dec | 683 | |
684 | // don't change the file version ("-x.dat") | |
685 | ||
327f7faa | 686 | cfg.fTriggerIO->WriteGlobalConfig(cfg.fGlobalFileName,cfg.fGlobalMasks); |
41a38dec | 687 | |
688 | // write last current file | |
327f7faa | 689 | WriteLastCurrentFile(cfg,cfg.fCurrentFileName); |
4fd5ed63 | 690 | |
327f7faa | 691 | status = daqDA_DB_storeFile(cfg.fGlobalFileName.Data(), cfg.fGlobalFileName.Data()); |
41a38dec | 692 | if (status) { |
327f7faa | 693 | printf("Failed to export file to DB: %s\n",cfg.fGlobalFileName.Data()); |
41a38dec | 694 | return; |
695 | } | |
696 | ||
327f7faa | 697 | status = daqDA_DB_storeFile(cfg.fCurrentFileName.Data(), cfg.fCurrentFileName.Data()); |
41a38dec | 698 | if (status) { |
327f7faa | 699 | printf("Failed to export file to DB: %s\n",cfg.fCurrentFileName.Data()); |
41a38dec | 700 | return; |
701 | } | |
113ad708 | 702 | |
41a38dec | 703 | } |
704 | ||
705 | } | |
113ad708 | 706 | |
9f5fafa6 | 707 | //*************************************************************// |
708 | ||
41a38dec | 709 | // main routine |
9f5fafa6 | 710 | int main(Int_t argc, Char_t **argv) |
711 | { | |
712 | ||
713 | // needed for streamer application | |
327f7faa | 714 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo", "RIO", "TStreamerInfo()"); |
715 | ||
716 | /* check that we got some arguments = list of files */ | |
717 | if (argc<2) { | |
718 | printf("Wrong number of arguments\n"); | |
719 | return -1; | |
720 | } | |
721 | ||
722 | DAConfig cfg; | |
9f5fafa6 | 723 | |
8f8ae0de | 724 | Char_t inputFile[256] = ""; |
113ad708 | 725 | inputFile[0] = 0; |
726 | if (argc > 1) | |
727 | if (argv[1] != NULL) | |
728 | strncpy(inputFile, argv[1], 256); | |
729 | else { | |
730 | printf("MUONTRGda : No input File !\n"); | |
731 | return -1; | |
732 | } | |
9f5fafa6 | 733 | |
4fd5ed63 | 734 | // decoding the events |
9f5fafa6 | 735 | |
4fd5ed63 | 736 | Int_t status; |
737 | Int_t nDateEvents = 0; | |
9f5fafa6 | 738 | |
4fd5ed63 | 739 | void* event; |
9f5fafa6 | 740 | |
4fd5ed63 | 741 | // containers |
742 | AliMUONDDLTrigger* ddlTrigger = 0x0; | |
743 | AliMUONDarcHeader* darcHeader = 0x0; | |
9f5fafa6 | 744 | |
4fd5ed63 | 745 | TStopwatch timers; |
9f5fafa6 | 746 | |
4fd5ed63 | 747 | timers.Start(kTRUE); |
9f5fafa6 | 748 | |
4fd5ed63 | 749 | // comment out, since we do not retrieve files from database |
327f7faa | 750 | if (!ImportFiles(cfg)) { |
4fd5ed63 | 751 | printf("Import from DB failed\n"); |
752 | printf("For local test set DAQDA_TEST_DIR to the local directory where the Mtg files are located \n"); | |
9f5fafa6 | 753 | return -1; |
754 | } | |
327f7faa | 755 | |
756 | ReadMaskFiles(cfg); | |
4fd5ed63 | 757 | |
8f8ae0de | 758 | // offline: the run number extracted from the file name |
759 | //TString tmp(inputFile); | |
760 | //Int_t pos = tmp.First("daq"); | |
761 | //tmp = tmp(pos+3,5); | |
762 | //gSystem->Setenv("DATE_RUN_NUMBER",tmp.Data()); | |
763 | //gSystem->Exec("echo \"DATE_RUN_NUMBER = \" $DATE_RUN_NUMBER"); | |
327f7faa | 764 | |
765 | if(!ExportFiles(cfg)) { | |
41a38dec | 766 | printf("ExportFiles failed\n"); |
767 | return -1; | |
768 | } | |
769 | ||
41a38dec | 770 | // FET is triggered by CTP |
327f7faa | 771 | if (GetFetMode(cfg) != 3) { |
41a38dec | 772 | printf("FET is not in mode 3\n"); |
773 | return -1; | |
774 | } | |
775 | ||
776 | // All 5 global cards are controlled by the Mts proxy | |
327f7faa | 777 | if (cfg.fGlobalMasks->GetGlobalCrateEnable() != 0x1F) { |
41a38dec | 778 | printf("The MTS proxy does not control all global cards\n"); |
779 | return -1; | |
780 | } | |
113ad708 | 781 | |
41a38dec | 782 | // The global cards are ON (active on the global inputs) |
327f7faa | 783 | if (!cfg.fGlobalMasks->GetMasksOn()) { |
41a38dec | 784 | printf("Global masks are not ON\n"); |
785 | return -1; | |
786 | } | |
113ad708 | 787 | |
41a38dec | 788 | // make sure to catch the "rare" calib events (1 every 50s in physics) |
789 | const Char_t* tableSOD[] = {"ALL", "yes", "CAL", "all", NULL, NULL}; | |
790 | monitorDeclareTable(const_cast<char**>(tableSOD)); | |
791 | ||
4fd5ed63 | 792 | status = monitorSetDataSource(inputFile); |
793 | if (status) { | |
794 | cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status | |
795 | << " " << monitorDecodeError(status) << endl; | |
796 | return -1; | |
797 | } | |
798 | status = monitorDeclareMp("MUON Trigger monitoring"); | |
799 | if (status) { | |
800 | cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status | |
801 | << " " << monitorDecodeError(status) << endl; | |
802 | return -1; | |
9f5fafa6 | 803 | } |
804 | ||
113ad708 | 805 | /* define wait event timeout - 1s max */ |
806 | monitorSetNowait(); | |
807 | monitorSetNoWaitNetworkTimeout(1000); | |
808 | ||
113ad708 | 809 | cout << "MUONTRGda : Reading data from file " << inputFile <<endl; |
4fd5ed63 | 810 | |
41a38dec | 811 | UInt_t *globalInput; |
812 | Bool_t doUpdate = false; | |
327f7faa | 813 | Int_t runNumber = 0; |
814 | Int_t nEvents = 0; | |
815 | ||
4fd5ed63 | 816 | while(1) |
817 | { | |
327f7faa | 818 | if (nEvents >= cfg.fMaxEvents) break; |
819 | if (nEvents && nEvents % 100 == 0) | |
820 | cout<<"Cumulated events " << nEvents << endl; | |
9f5fafa6 | 821 | |
4fd5ed63 | 822 | // check shutdown condition |
823 | if (daqDA_checkShutdown()) | |
824 | break; | |
825 | ||
826 | // Skip Events if needed | |
327f7faa | 827 | while (cfg.fSkipEvents) { |
4fd5ed63 | 828 | status = monitorGetEventDynamic(&event); |
327f7faa | 829 | cfg.fSkipEvents--; |
4fd5ed63 | 830 | } |
831 | ||
832 | // starts reading | |
833 | status = monitorGetEventDynamic(&event); | |
834 | if (status < 0) { | |
113ad708 | 835 | cout << "MUONTRGda : EOF found" << endl; |
4fd5ed63 | 836 | break; |
837 | } | |
838 | ||
839 | nDateEvents++; | |
840 | ||
841 | // decoding rawdata headers | |
842 | AliRawReader *rawReader = new AliRawReaderDate(event); | |
9f5fafa6 | 843 | |
4fd5ed63 | 844 | Int_t eventType = rawReader->GetType(); |
327f7faa | 845 | runNumber = rawReader->GetRunNumber(); |
9f5fafa6 | 846 | |
113ad708 | 847 | // L1Swc1 |
848 | // CALIBRATION_EVENT | |
849 | // SYSTEM_SOFTWARE_TRIGGER_EVENT | |
850 | // DETECTOR_SOFTWARE_TRIGGER_EVENT | |
327f7faa | 851 | cfg.fAlgoNoisyInput = false; |
852 | cfg.fAlgoDeadInput = false; | |
41a38dec | 853 | if (eventType == PHYSICS_EVENT) { |
327f7faa | 854 | cfg.fAlgoNoisyInput = true; |
41a38dec | 855 | doUpdate = true; |
327f7faa | 856 | cfg.fNEventsN++; |
41a38dec | 857 | } else if (eventType == CALIBRATION_EVENT) { |
327f7faa | 858 | cfg.fAlgoDeadInput = true; |
41a38dec | 859 | doUpdate = true; |
327f7faa | 860 | cfg.fNEventsD++; |
41a38dec | 861 | } else { |
862 | continue; | |
863 | } | |
864 | ||
327f7faa | 865 | nEvents++; |
866 | if (cfg.fPrintLevel) printf("\nEvent # %d\n",nEvents); | |
9f5fafa6 | 867 | |
4fd5ed63 | 868 | // decoding MUON payload |
869 | AliMUONRawStreamTrigger* rawStream = new AliMUONRawStreamTrigger(rawReader); | |
8f8ae0de | 870 | // ... without warnings from the decoder !!! |
327f7faa | 871 | if (!cfg.fWithWarnings) |
8f8ae0de | 872 | rawStream->DisableWarnings(); |
9f5fafa6 | 873 | |
4fd5ed63 | 874 | // loops over DDL |
875 | while((status = rawStream->NextDDL())) { | |
9f5fafa6 | 876 | |
327f7faa | 877 | if (cfg.fPrintLevel) printf("iDDL %d\n", rawStream->GetDDL()); |
9f5fafa6 | 878 | |
4fd5ed63 | 879 | ddlTrigger = rawStream->GetDDLTrigger(); |
880 | darcHeader = ddlTrigger->GetDarcHeader(); | |
9f5fafa6 | 881 | |
41a38dec | 882 | if (rawStream->GetDDL() == 0) { |
327f7faa | 883 | if (cfg.fPrintLevel) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput()); |
41a38dec | 884 | globalInput = darcHeader->GetGlobalInput(); |
327f7faa | 885 | StoreGlobalInput(cfg,globalInput); |
41a38dec | 886 | } |
9f5fafa6 | 887 | |
4fd5ed63 | 888 | } // NextDDL |
889 | ||
890 | delete rawReader; | |
891 | delete rawStream; | |
892 | ||
893 | } // while (1) | |
894 | ||
41a38dec | 895 | // update configuration files ifrequested event types were found |
327f7faa | 896 | if (doUpdate && cfg.fDAFlag) |
897 | UpdateGlobalMasks(cfg); | |
9f5fafa6 | 898 | |
4fd5ed63 | 899 | timers.Stop(); |
9f5fafa6 | 900 | |
327f7faa | 901 | cout << "MUONTRGda: DA enable: \t" << cfg.fDAFlag << endl; |
902 | cout << "MUONTRGda: Run number: \t" << runNumber << endl; | |
903 | cout << "MUONTRGda: Nb of DATE events: \t" << nDateEvents << endl; | |
904 | cout << "MUONTRGda: Nb of events used: \t" << nEvents << endl; | |
905 | cout << "MUONTRGda: Nb of events used (noise): \t" << cfg.fNEventsN << endl; | |
906 | cout << "MUONTRGda: Nb of events used (deadc): \t" << cfg.fNEventsD << endl; | |
907 | cout << "MUONTRGda: Minumum nr of events for rate calculation: \t" << cfg.fMinEvents << endl; | |
908 | cout << "MUONTRGda: Maximum nr of analyzed events: \t" << cfg.fMaxEvents << endl; | |
909 | cout << "MUONTRGda: Skip events from start: \t" << cfg.fSkipEvents << endl; | |
910 | cout << "MUONTRGda: Threshold for noisy inputs: \t" << 100*cfg.fThrN << "%" << endl; | |
911 | cout << "MUONTRGda: Threshold for dead inputs: \t" << 100*cfg.fThrD << "%" << endl; | |
912 | cout << "MUONTRGda: Print level: \t" << cfg.fPrintLevel << endl; | |
913 | cout << "MUONTRGda: Show decoder warnings: \t" << cfg.fWithWarnings << endl; | |
914 | ||
915 | printf("MUONTRGda: Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime()); | |
916 | ||
917 | delete cfg.fLocalMasks; | |
918 | delete cfg.fRegionalMasks; | |
919 | delete cfg.fGlobalMasks; | |
920 | delete cfg.fTriggerIO; | |
9f5fafa6 | 921 | |
4fd5ed63 | 922 | return status; |
41a38dec | 923 | |
9f5fafa6 | 924 | } |
92c23b09 | 925 |