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