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