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