We have added the possibility to perform an
[u/mrichter/AliRoot.git] / MUON / MUONTRGda.cxx
CommitLineData
9f5fafa6 1/*
113ad708 2MTR DA for online
3
3e42bf30 4Contact: Franck Manso <manso@clermont.in2p3.fr>
5Link: http://aliceinfo.cern.ch/static/Offline/dimuon/muon_html/README_mtrda.html
6Run Type: ELECTRONICS_CALIBRATION_RUN (calib), DETECTOR_CALIBRATION_RUN (ped)
7DA Type: LDC
8Number of events needed: 100 events for ped and calib
9Input Files: Rawdata file (DATE format)
10Input Files from DB:
11MtgGlobalCrate-<version>.dat
12MtgRegionalCrate-<version>.dat
13MtgLocalMask-<version>.dat
14MtgLocalLut-<version>.dat
15MtgCurrent.dat
16
17Output Files: local dir (not persistent)
18ExportedFiles.dat
19*/
20
21
22/*
9f5fafa6 23
4fd5ed63 24Version 2 for MUONTRGda MUON trigger
25Working 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
39November 2007
40Ch. Finck
41
3e42bf30 42To be checked:
4fd5ed63 43 Writing into the online database (need update of daqDAlib)
3e42bf30 44To be done:
4fd5ed63 45 Looking at scalers outputs
9f5fafa6 46*/
3e42bf30 47
9f5fafa6 48extern "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 92const Int_t gkNLocalBoard = AliMpConstants::TotalNofLocalBoards()+1;
4fd5ed63 93
113ad708 94TString gCommand("ped");
4fd5ed63 95
96TString gCurrentFileName("MtgCurrent.dat");
97TString gLastCurrentFileName("MtgLastCurrent.dat");
98
99TString gSodName;
100Int_t gSodFlag = 0;
101
102TString gDAName;
103Int_t gDAFlag = 0;
104
105TString gGlobalFileName;
106TString gRegionalFileName;
107TString gLocalMaskFileName;
108TString gLocalLutFileName;
109TString gSignatureFileName;
110
111Int_t gGlobalFileVersion;
112Int_t gRegionalFileVersion;
113Int_t gLocalMaskFileVersion;
114Int_t gLocalLutFileVersion;
115Int_t gSignatureFileVersion;
116
117Int_t gGlobalFileLastVersion;
118Int_t gRegionalFileLastVersion;
119Int_t gLocalMaskFileLastVersion;
120Int_t gLocalLutFileLastVersion;
121
122UInt_t gRunNumber = 0;
123Int_t gNEvents = 0;
124
125Int_t gPrintLevel = 0;
126
127AliMUONVStore* gLocalMasks = 0x0;
92c23b09 128AliMUONRegionalTriggerConfig* gRegionalMasks = 0x0;
129AliMUONGlobalCrateConfig* gGlobalMasks = 0x0;
4fd5ed63 130
4fd5ed63 131
92c23b09 132 AliMUONTriggerIO gTriggerIO;
133
134AliMUONVStore* gPatternStore = new AliMUON1DArray(gkNLocalBoard);
4fd5ed63 135
136Char_t gHistoFileName[256];
137
74e61e0d 138Float_t gkThreshold = 0.2;
4fd5ed63 139
140//__________________________________________________________________
141void 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//__________________________________________________________________
156void 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//___________________________________________________________________________________________
177Bool_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//_____________
284void 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//__________________
298Bool_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//__________________
398Bool_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//_____________
448void 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//__________
463void 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//__________
498void 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("-");
4fd5ed63 611
041eaef1 612 gLocalMaskFileName = tmp(0,pos+1) + Form("%d",gLocalMaskFileVersion) + ".dat";
613 gTriggerIO.WriteConfig(gLocalMaskFileName, gRegionalFileName,
614 gGlobalFileName, gLocalMasks, gRegionalMasks, gGlobalMasks);
113ad708 615
616 WriteLastCurrentFile(gCurrentFileName);
617
618
619 Int_t status = daqDA_DB_storeFile(gLocalMaskFileName.Data(), gLocalMaskFileName.Data());
620 if (status) {
621 printf("Failed to export file to DB: %s\n",gLocalMaskFileName.Data());
622 return;
623 }
624
625 status = daqDA_DB_storeFile(gCurrentFileName.Data(), gCurrentFileName.Data());
626 if (status) {
627 printf("Failed to export file to DB: %s\n",gCurrentFileName.Data());
628 return;
629 }
630
4fd5ed63 631 }
632}
9f5fafa6 633
634//*************************************************************//
635
4fd5ed63 636 // main routine
9f5fafa6 637int main(Int_t argc, Char_t **argv)
638{
639
640 // needed for streamer application
4fd5ed63 641 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo",
642 "RIO", "TStreamerInfo()");
9f5fafa6 643
9f5fafa6 644 Int_t skipEvents = 0;
645 Int_t maxEvents = 1000000;
646 Char_t inputFile[256];
113ad708 647 inputFile[0] = 0;
648 if (argc > 1)
649 if (argv[1] != NULL)
650 strncpy(inputFile, argv[1], 256);
651 else {
652 printf("MUONTRGda : No input File !\n");
653 return -1;
654 }
9f5fafa6 655 TString flatOutputFile;
9f5fafa6 656
657// option handler
658
4fd5ed63 659 // decode the input line
660 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
661 {
9f5fafa6 662 Char_t* arg;
663
664 arg = argv[i];
665 if (arg[0] != '-') continue;
666 switch (arg[1])
4fd5ed63 667 {
668 case 'f' :
9f5fafa6 669 i++;
670 sprintf(inputFile,argv[i]);
671 break;
74e61e0d 672 case 't' :
9f5fafa6 673 i++;
74e61e0d 674 gkThreshold = atof(argv[i]);
9f5fafa6 675 break;
4fd5ed63 676 case 'e' :
9f5fafa6 677 i++;
4fd5ed63 678 gCommand = argv[i];
9f5fafa6 679 break;
4fd5ed63 680 case 'd' :
9f5fafa6 681 i++;
4fd5ed63 682 gPrintLevel=atoi(argv[i]);
9f5fafa6 683 break;
4fd5ed63 684 case 's' :
9f5fafa6 685 i++;
686 skipEvents=atoi(argv[i]);
687 break;
4fd5ed63 688 case 'n' :
9f5fafa6 689 i++;
690 sscanf(argv[i],"%d",&maxEvents);
691 break;
4fd5ed63 692 case 'r' :
693 i++;
694 sscanf(argv[i],"%s",gHistoFileName);
695 break;
696 case 'h' :
9f5fafa6 697 i++;
698 printf("\n******************* %s usage **********************",argv[0]);
699 printf("\n%s -options, the available options are :",argv[0]);
700 printf("\n-h help (this screen)");
701 printf("\n");
702 printf("\n Input");
703 printf("\n-f <raw data file> (default = %s)",inputFile);
704 printf("\n");
4fd5ed63 705 printf("\n output");
706 printf("\n-r <root file> (default = %s)",gHistoFileName);
9f5fafa6 707 printf("\n");
708 printf("\n Options");
74e61e0d 709 printf("\n-t <threshold values> (default = %3.1f)",gkThreshold);
4fd5ed63 710 printf("\n-d <print level> (default = %d)",gPrintLevel);
9f5fafa6 711 printf("\n-s <skip events> (default = %d)",skipEvents);
712 printf("\n-n <max events> (default = %d)",maxEvents);
4fd5ed63 713 printf("\n-e <execute ped/calib> (default = %s)",gCommand.Data());
9f5fafa6 714
715 printf("\n\n");
716 exit(-1);
4fd5ed63 717 default :
9f5fafa6 718 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
719 argc = 2; exit(-1); // exit if error
4fd5ed63 720 } // end of switch
9f5fafa6 721 } // end of for i
722
4fd5ed63 723 // set command to lower case
724 gCommand.ToLower();
9f5fafa6 725
4fd5ed63 726 // decoding the events
9f5fafa6 727
4fd5ed63 728 Int_t status;
729 Int_t nDateEvents = 0;
9f5fafa6 730
4fd5ed63 731 void* event;
9f5fafa6 732
4fd5ed63 733 // containers
734 AliMUONDDLTrigger* ddlTrigger = 0x0;
735 AliMUONDarcHeader* darcHeader = 0x0;
736 AliMUONRegHeader* regHeader = 0x0;
737 AliMUONLocalStruct* localStruct = 0x0;
9f5fafa6 738
4fd5ed63 739 TStopwatch timers;
9f5fafa6 740
4fd5ed63 741 timers.Start(kTRUE);
9f5fafa6 742
4fd5ed63 743 // comment out, since we do not retrieve files from database
744 if (!ImportFiles()) {
745 printf("Import from DB failed\n");
746 printf("For local test set DAQDA_TEST_DIR to the local directory where the Mtg files are located \n");
9f5fafa6 747 return -1;
748 }
9f5fafa6 749
4fd5ed63 750 ReadMaskFiles();
751
113ad708 752 if(!ExportFiles())
753 return -1;
754
755
4fd5ed63 756 status = monitorSetDataSource(inputFile);
757 if (status) {
758 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
759 << " " << monitorDecodeError(status) << endl;
760 return -1;
761 }
762 status = monitorDeclareMp("MUON Trigger monitoring");
763 if (status) {
764 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
765 << " " << monitorDecodeError(status) << endl;
766 return -1;
9f5fafa6 767 }
768
113ad708 769 /* define wait event timeout - 1s max */
770 monitorSetNowait();
771 monitorSetNoWaitNetworkTimeout(1000);
772
773
774 cout << "MUONTRGda : Reading data from file " << inputFile <<endl;
4fd5ed63 775
776 while(1)
777 {
778 if (gNEvents >= maxEvents) break;
779 if (gNEvents && gNEvents % 100 == 0)
780 cout<<"Cumulated events " << gNEvents << endl;
9f5fafa6 781
4fd5ed63 782 // check shutdown condition
783 if (daqDA_checkShutdown())
784 break;
785
786 // Skip Events if needed
787 while (skipEvents) {
788 status = monitorGetEventDynamic(&event);
789 skipEvents--;
790 }
791
792 // starts reading
793 status = monitorGetEventDynamic(&event);
794 if (status < 0) {
113ad708 795 cout << "MUONTRGda : EOF found" << endl;
4fd5ed63 796 break;
797 }
798
799 nDateEvents++;
800
801 // decoding rawdata headers
802 AliRawReader *rawReader = new AliRawReaderDate(event);
9f5fafa6 803
4fd5ed63 804 Int_t eventType = rawReader->GetType();
805 gRunNumber = rawReader->GetRunNumber();
9f5fafa6 806
113ad708 807 // L1Swc1
808 // CALIBRATION_EVENT
809 // SYSTEM_SOFTWARE_TRIGGER_EVENT
810 // DETECTOR_SOFTWARE_TRIGGER_EVENT
4fd5ed63 811 if (eventType != PHYSICS_EVENT)
812 continue; // for the moment
9f5fafa6 813
4fd5ed63 814 gNEvents++;
815 if (gPrintLevel) printf("\nEvent # %d\n",gNEvents);
9f5fafa6 816
4fd5ed63 817 // decoding MUON payload
818 AliMUONRawStreamTrigger* rawStream = new AliMUONRawStreamTrigger(rawReader);
819 //rawStream->SetMaxReg(1);
9f5fafa6 820
4fd5ed63 821 // loops over DDL
822 while((status = rawStream->NextDDL())) {
9f5fafa6 823
4fd5ed63 824 if (gPrintLevel) printf("iDDL %d\n", rawStream->GetDDL());
9f5fafa6 825
4fd5ed63 826 ddlTrigger = rawStream->GetDDLTrigger();
827 darcHeader = ddlTrigger->GetDarcHeader();
9f5fafa6 828
4fd5ed63 829 if (gPrintLevel) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
9f5fafa6 830
4fd5ed63 831 // loop over regional structures
832 Int_t nReg = darcHeader->GetRegHeaderEntries();
833 for(Int_t iReg = 0; iReg < nReg; ++iReg){ //REG loop
9f5fafa6 834
4fd5ed63 835 if (gPrintLevel) printf("RegionalId %d\n", iReg);
9f5fafa6 836
4fd5ed63 837 regHeader = darcHeader->GetRegHeaderEntry(iReg);
9f5fafa6 838
4fd5ed63 839 // loop over local structures
840 Int_t nLocal = regHeader->GetLocalEntries();
841 for(Int_t iLocal = 0; iLocal < nLocal; ++iLocal) {
9f5fafa6 842
4fd5ed63 843 localStruct = regHeader->GetLocalEntry(iLocal);
9f5fafa6 844
113ad708 845 Int_t localBoardId = gTriggerIO.LocalBoardId(rawStream->GetDDL(), iReg, iLocal);
846 if (localBoardId == 0) continue;
4fd5ed63 847 if (gPrintLevel) printf("local %d\n", localBoardId );
848
849 TArrayS xPattern(4);
850 TArrayS yPattern(4);
851 localStruct->GetXPattern(xPattern);
852 localStruct->GetYPattern(yPattern);
853 MakePattern(localBoardId, xPattern, yPattern);
9f5fafa6 854
4fd5ed63 855 if (gPrintLevel) printf("X pattern %x %x %x %x, Y pattern %x %x %x %x\n",
856 localStruct->GetX1(), localStruct->GetX2(),localStruct->GetX3(),localStruct->GetX4(),
857 localStruct->GetY1(), localStruct->GetY2(),localStruct->GetY3(),localStruct->GetY4());
9f5fafa6 858
4fd5ed63 859 } // iLocal
860 } // iReg
861 } // NextDDL
862
863 delete rawReader;
864 delete rawStream;
865
866 } // while (1)
867
113ad708 868 if (gCommand.Contains("ped") && gDAFlag)
4fd5ed63 869 MakePatternStore();
9f5fafa6 870
113ad708 871 if (gCommand.Contains("cal") && gDAFlag)
92c23b09 872 MakePatternStore(false);
9f5fafa6 873
9f5fafa6 874
4fd5ed63 875 timers.Stop();
9f5fafa6 876
92c23b09 877 cout << "MUONTRGda : Run number : " << gRunNumber << endl;
878 cout << "MUONTRGda : Histo file generated : " << gHistoFileName << endl;
879 cout << "MUONTRGda : Nb of DATE events = " << nDateEvents << endl;
880 cout << "MUONTRGda : Nb of events used = " << gNEvents << endl;
9f5fafa6 881
4fd5ed63 882 printf("Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
9f5fafa6 883
4fd5ed63 884 delete gLocalMasks;
885 delete gRegionalMasks;
113ad708 886 delete gGlobalMasks;
4fd5ed63 887 delete gPatternStore;
9f5fafa6 888
4fd5ed63 889 return status;
9f5fafa6 890}
92c23b09 891