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