]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONTRGda.cxx
Fix to the fix: reverting the last commit in AliTPCParamSR.cxx and AliTPC.cxx, and...
[u/mrichter/AliRoot.git] / MUON / MUONTRGda.cxx
CommitLineData
3e42bf30 1/*
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
9f5fafa6 20/*
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
92c23b09 307 // Export files into the database
308 // setenv DATE_DETECTOR_CODE MTR
309 // setenv DAQDALIB_PATH $ALICE/daqDAlib
310 // setenv DATE_DB_MYSQL_USER det_MTR
311 // setenv DATE_DB_MYSQL_PWD MTR123
312 // setenv DATE_DB_MYSQL_HOST aldaqdb.cern.ch
313 // setenv DATE_DB_MYSQL_DB $DATE_CONFIG
314 // set PATH=$PATH:${DAQDALIB_PATH}
315
316
4fd5ed63 317 // to be sure that env variable is set
92c23b09 318 // gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
319 gSystem->Setenv("DAQDALIB_PATH", "$ALICE/daqDAlib");
320 gSystem->Setenv("DATE_DETECTOR_CODE", "MTR");
321 gSystem->Setenv("DATE_DB_MYSQL_USER", "det_MTR");
322 gSystem->Setenv("DATE_DB_MYSQL_PWD", "MTR123");
323 gSystem->Setenv("DATE_DB_MYSQL_HOST", "aldaqdb.cern.ch");
324 gSystem->Setenv("DATE_DB_MYSQL_DB", "$DATE_CONFIG");
325
4fd5ed63 326 // update files
327 Int_t status = 0;
328
329 Bool_t modified = false;
330
331 ofstream out;
332 TString fileExp("ExportedFiles.dat");
333 TString file;
334
335 out.open(fileExp.Data());
336 if (!out.good()) {
337 printf("Failed to create file: %s\n",file.Data());
338 return false;
92c23b09 339 } file = gGlobalFileName.Data();
4fd5ed63 340
341 if (gGlobalFileLastVersion != gGlobalFileVersion) {
92c23b09 342
4fd5ed63 343 status = daqDA_FES_storeFile(file.Data(), file.Data());
344 if (status) {
345 printf("Failed to export file: %s\n",gGlobalFileName.Data());
346 return false;
347 }
348 out << gGlobalFileName.Data() << endl;
349 if(gPrintLevel) printf("Export file: %s\n",gGlobalFileName.Data());
350 }
351
352 if (gLocalMaskFileLastVersion != gLocalMaskFileVersion) {
353 modified = true;
354 file = gLocalMaskFileName;
92c23b09 355 // export to FES
4fd5ed63 356 status = daqDA_FES_storeFile(file.Data(), file.Data());
357 if (status) {
358 printf("Failed to export file: %s\n",gLocalMaskFileName.Data());
359 return false;
360 }
92c23b09 361 // export to DB
362 status = daqDA_DB_storeFile(file.Data(), file.Data());
363 if (status) {
364 printf("Failed to export file to DB: %s\n",gLocalMaskFileName.Data());
365 return false;
366 }
367
4fd5ed63 368 if(gPrintLevel) printf("Export file: %s\n",gLocalMaskFileName.Data());
369 out << gLocalMaskFileName.Data() << endl;
370 }
371
372 if (gLocalLutFileLastVersion != gLocalLutFileVersion) {
373 file = gLocalLutFileName;
374 modified = true;
375 status = daqDA_FES_storeFile(file.Data(), file.Data());
376 if (status) {
377 printf("Failed to export file: %s\n",gLocalLutFileName.Data());
378 return false;
379 }
380 if(gPrintLevel) printf("Export file: %s\n",gLocalLutFileName.Data());
381 out << gLocalLutFileName.Data() << endl;
382
383 }
384
385 // exported regional file whenever mask or/and Lut are modified
386 if ( (gRegionalFileLastVersion != gRegionalFileVersion) || modified) {
387 file = gRegionalFileName;
388 status = daqDA_FES_storeFile(file.Data(), file.Data());
389 if (status) {
390 printf("Failed to export file: %s\n",gRegionalFileName.Data());
391 return false;
392 }
393 if(gPrintLevel) printf("Export file: %s\n",gRegionalFileName.Data());
394 out << gRegionalFileName.Data() << endl;
395 }
396
397 out.close();
398
399 // export Exported file to FES anyway
400 status = daqDA_FES_storeFile(fileExp.Data(), fileExp.Data());
401 if (status) {
402 printf("Failed to export file: %s\n", fileExp.Data());
403 return false;
404 }
405 if(gPrintLevel) printf("Export file: %s\n",fileExp.Data());
406
407 return true;
408}
409//__________________
410Bool_t ImportFiles()
411{
412 // copy locally a file from daq detector config db
413 // The current detector is identified by detector code in variable
414 // DATE_DETECTOR_CODE. It must be defined.
415 // If environment variable DAQDA_TEST_DIR is defined, files are copied from DAQDA_TEST_DIR
416 // instead of the database. The usual environment variables are not needed.
417
418 // to be sure that env variable is set
92c23b09 419 // gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
420 gSystem->Setenv("DAQDALIB_PATH", "$ALICE/daqDAlib");
421
4fd5ed63 422 Int_t status = 0;
423
424 status = daqDA_DB_getFile(gCurrentFileName.Data(), gCurrentFileName.Data());
425 if (status) {
426 printf("Failed to get current config file from DB: %s\n",gCurrentFileName.Data());
427 return false;
428 }
429
430 ReadFileNames();
431
432 status = daqDA_DB_getFile(gGlobalFileName.Data(), gGlobalFileName.Data());
433 if (status) {
434 printf("Failed to get current config file from DB: %s\n", gGlobalFileName.Data());
435 return false;
436 }
437
438 status = daqDA_DB_getFile(gRegionalFileName.Data(), gRegionalFileName.Data());
439 if (status) {
440 printf("Failed to get current config file from DB: %s\n",gRegionalFileName.Data());
441 return false;
442 }
443
444 status = daqDA_DB_getFile(gLocalMaskFileName.Data(), gLocalMaskFileName.Data());
445 if (status) {
446 printf("Failed to get current config file from DB: %s\n",gLocalMaskFileName.Data());
447 return false;
448 }
449
450 status = daqDA_DB_getFile(gLocalLutFileName.Data(), gLocalLutFileName.Data());
451 if (status) {
452 printf("Failed to get current config file from DB: %s\n",gLocalLutFileName.Data());
453 return false;
454 }
455
456 return true;
457}
458
459//_____________
460void ReadMaskFiles()
461{
462 // read mask files
463 gLocalMasks = new AliMUON1DArray(gkNLocalBoard+9);
92c23b09 464 gRegionalMasks = new AliMUONRegionalTriggerConfig();
465 gGlobalMasks = new AliMUONGlobalCrateConfig();
4fd5ed63 466
467 TString localFile = gLocalMaskFileName;
468 TString regionalFile = gRegionalFileName;
469 TString globalFile = gGlobalFileName;
470
92c23b09 471 gTriggerIO.ReadConfig(localFile.Data(), regionalFile.Data(), globalFile.Data(),
472 gLocalMasks, gRegionalMasks, gGlobalMasks);
4fd5ed63 473}
474//__________
475void MakePattern(Int_t localBoardId, TArrayS& xPattern, TArrayS& yPattern)
476{
477
478 // calculate the hit map for each strip in x and y direction
479 AliMUONVCalibParam* pat =
480 static_cast<AliMUONVCalibParam*>(gPatternStore->FindObject(localBoardId));
481
482 if (!pat) {
483 pat = new AliMUONCalibParamND(2, 64, localBoardId, 0,0.); // put default wise 0.
484 gPatternStore->Add(pat);
485 }
486
487 for (Int_t i = 0; i < 4; ++i) {
488 for (Int_t j = 0; j < 16; ++j) {
489
490 Int_t xMask = xPattern[i];
491 Int_t yMask = yPattern[i];
492
493 Int_t index = 16*i + j;
494 Double_t patOcc = 0.;
495
496 if ( (xMask >> j ) & 0x1 ) {
497 patOcc = pat->ValueAsDouble(index, 0) + 1.;
498 pat->SetValueAsDouble(index, 0, patOcc);
499 }
500 if ( (yMask >> j ) & 0x1 ) {
501 patOcc = pat->ValueAsDouble(index, 0) + 1.;
502 pat->SetValueAsDouble(index, 0, patOcc);
503 }
504 }
505 }
506
507}
508
509//__________
510void MakePatternStore(Bool_t pedestal = true)
511{
512
513 // calculates the occupancy (option: store in a root file)
514 // check noisy strip (pedestal true, software trigger)
515 // check dead channel (pesdetal false, FET trigger)
516
517 Int_t localBoardId = 0;
518 Bool_t updated = false;
519
520 // histo
521
522 Char_t name[255];
523 Char_t title[255];
524
525 TH1F* xOccHisto[243];
526 TH1F* yOccHisto[243];
527 TH1F* xPatOccHisto = 0x0;
528 TH1F* yPatOccHisto = 0x0;
529
530 TFile* histoFile = 0x0;
531
532 if (gHistoFileName[0] != 0) {
533 histoFile = new TFile(gHistoFileName,"RECREATE","MUON Tracking pedestals");
534
535 sprintf(name,"pat_x");
536 sprintf(title,"Occupancy for x strip");
537 Int_t nx = 200;
538 Float_t xmin = -0.2;
539 Float_t xmax = 1.2;
540 xPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
541 xPatOccHisto ->SetDirectory(histoFile);
542
543 sprintf(name,"pat_y");
544 sprintf(title,"Occupancy for y strip");
545 yPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
546 yPatOccHisto->SetDirectory(histoFile);
547
548 }
549
550 // iterator over pedestal
551 TIter next(gPatternStore->CreateIterator());
552 AliMUONVCalibParam* pat;
553
554 while ( ( pat = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
555 {
556 localBoardId = pat->ID0();
557
558 if (gHistoFileName[0] != 0) {
559
560 Int_t nx = 64;
561 Float_t xmin = 0;
562 Float_t xmax = 64;
563
564 sprintf(name,"pat_x_%d",localBoardId);
565 sprintf(title,"Occupancy for x strip, board %d",localBoardId);
566 xOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
567
568 sprintf(name,"pat_y_%d",localBoardId);
569 sprintf(title,"Occupancy for y strip, board %d",localBoardId);
570 yOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
9f5fafa6 571
4fd5ed63 572 }
573
574 for (Int_t index = 0; index < pat->Size() ; ++index) {// 64 bits for X and 64 bits for Y strips
575
576 Double_t patXOcc = pat->ValueAsDouble(index, 0)/(Double_t)gNEvents;
577 Double_t patYOcc = pat->ValueAsDouble(index, 1)/(Double_t)gNEvents;
578
579 pat->SetValueAsDouble(index, 0, patXOcc);
580 pat->SetValueAsDouble(index, 1, patYOcc);
581
582
583 // check for x strip
584 if ( (patXOcc > gkThreshold && pedestal) || (patXOcc < 1.- gkThreshold && !pedestal) ) {
585 UShort_t strip = index % 16;
586 Int_t connector = index/16;
587 UpdateLocalMask(localBoardId, connector, strip);
588 updated = true;
589 }
590
591 // check for y strip
592 if ( (patYOcc > gkThreshold && pedestal) || (patYOcc < 1.- gkThreshold && !pedestal) ) {
593 UShort_t strip = index % 16;
594 Int_t connector = index/16 + 4;
595 UpdateLocalMask(localBoardId, connector, strip);
596 updated = true;
597
598 }
599
600 if (gHistoFileName[0] != 0) {
601 xPatOccHisto->Fill(patXOcc);
602 yPatOccHisto->Fill(patYOcc);
603 xOccHisto[localBoardId]->Fill(index, patXOcc);
604 yOccHisto[localBoardId]->Fill(index, patYOcc);
605
606 }
607 }
608 }
609
610 if (gHistoFileName[0] != 0) {
611 histoFile->Write();
612 histoFile->Close();
613 }
614
615
616 if (updated) {
617
618 // update version
619 gLocalMaskFileVersion++;
620
621 TString tmp(gLocalMaskFileName);
622 Int_t pos = tmp.First("-");
623 gLocalMaskFileName = tmp(0,pos+1) + Form("%d",gLocalMaskFileVersion) + ".dat";
624
625 // write last current file
626 WriteLastCurrentFile();
627
92c23b09 628 gTriggerIO.WriteConfig(gLocalMaskFileName, gRegionalFileName, gGlobalFileName, gLocalMasks, gRegionalMasks, gGlobalMasks);
4fd5ed63 629 }
630}
9f5fafa6 631
632//*************************************************************//
633
4fd5ed63 634 // main routine
9f5fafa6 635int main(Int_t argc, Char_t **argv)
636{
637
638 // needed for streamer application
4fd5ed63 639 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", "*", "TStreamerInfo",
640 "RIO", "TStreamerInfo()");
9f5fafa6 641
9f5fafa6 642 Int_t skipEvents = 0;
643 Int_t maxEvents = 1000000;
644 Char_t inputFile[256];
92c23b09 645 strcpy(inputFile, "");
9f5fafa6 646 TString flatOutputFile;
9f5fafa6 647
648// option handler
649
4fd5ed63 650 // decode the input line
651 for (Int_t i = 1; i < argc; i++) // argument 0 is the executable name
652 {
9f5fafa6 653 Char_t* arg;
654
655 arg = argv[i];
656 if (arg[0] != '-') continue;
657 switch (arg[1])
4fd5ed63 658 {
659 case 'f' :
9f5fafa6 660 i++;
661 sprintf(inputFile,argv[i]);
662 break;
74e61e0d 663 case 't' :
9f5fafa6 664 i++;
74e61e0d 665 gkThreshold = atof(argv[i]);
9f5fafa6 666 break;
4fd5ed63 667 case 'e' :
9f5fafa6 668 i++;
4fd5ed63 669 gCommand = argv[i];
9f5fafa6 670 break;
4fd5ed63 671 case 'd' :
9f5fafa6 672 i++;
4fd5ed63 673 gPrintLevel=atoi(argv[i]);
9f5fafa6 674 break;
4fd5ed63 675 case 's' :
9f5fafa6 676 i++;
677 skipEvents=atoi(argv[i]);
678 break;
4fd5ed63 679 case 'n' :
9f5fafa6 680 i++;
681 sscanf(argv[i],"%d",&maxEvents);
682 break;
4fd5ed63 683 case 'r' :
684 i++;
685 sscanf(argv[i],"%s",gHistoFileName);
686 break;
687 case 'h' :
9f5fafa6 688 i++;
689 printf("\n******************* %s usage **********************",argv[0]);
690 printf("\n%s -options, the available options are :",argv[0]);
691 printf("\n-h help (this screen)");
692 printf("\n");
693 printf("\n Input");
694 printf("\n-f <raw data file> (default = %s)",inputFile);
695 printf("\n");
4fd5ed63 696 printf("\n output");
697 printf("\n-r <root file> (default = %s)",gHistoFileName);
9f5fafa6 698 printf("\n");
699 printf("\n Options");
74e61e0d 700 printf("\n-t <threshold values> (default = %3.1f)",gkThreshold);
4fd5ed63 701 printf("\n-d <print level> (default = %d)",gPrintLevel);
9f5fafa6 702 printf("\n-s <skip events> (default = %d)",skipEvents);
703 printf("\n-n <max events> (default = %d)",maxEvents);
4fd5ed63 704 printf("\n-e <execute ped/calib> (default = %s)",gCommand.Data());
9f5fafa6 705
706 printf("\n\n");
707 exit(-1);
4fd5ed63 708 default :
9f5fafa6 709 printf("%s : bad argument %s (please check %s -h)\n",argv[0],argv[i],argv[0]);
710 argc = 2; exit(-1); // exit if error
4fd5ed63 711 } // end of switch
9f5fafa6 712 } // end of for i
713
4fd5ed63 714 // set command to lower case
715 gCommand.ToLower();
9f5fafa6 716
4fd5ed63 717 // decoding the events
9f5fafa6 718
4fd5ed63 719 Int_t status;
720 Int_t nDateEvents = 0;
9f5fafa6 721
4fd5ed63 722 void* event;
9f5fafa6 723
4fd5ed63 724 // containers
725 AliMUONDDLTrigger* ddlTrigger = 0x0;
726 AliMUONDarcHeader* darcHeader = 0x0;
727 AliMUONRegHeader* regHeader = 0x0;
728 AliMUONLocalStruct* localStruct = 0x0;
9f5fafa6 729
4fd5ed63 730 TStopwatch timers;
9f5fafa6 731
4fd5ed63 732 timers.Start(kTRUE);
9f5fafa6 733
4fd5ed63 734 // comment out, since we do not retrieve files from database
735 if (!ImportFiles()) {
736 printf("Import from DB failed\n");
737 printf("For local test set DAQDA_TEST_DIR to the local directory where the Mtg files are located \n");
9f5fafa6 738 return -1;
739 }
9f5fafa6 740
4fd5ed63 741 if (!gDAFlag) {
742 if(!ExportFiles()) return -1;
743 return 0;
9f5fafa6 744 }
745
4fd5ed63 746 ReadMaskFiles();
747
748 status = monitorSetDataSource(inputFile);
749 if (status) {
750 cerr << "ERROR : monitorSetDataSource status (hex) = " << hex << status
751 << " " << monitorDecodeError(status) << endl;
752 return -1;
753 }
754 status = monitorDeclareMp("MUON Trigger monitoring");
755 if (status) {
756 cerr << "ERROR : monitorDeclareMp status (hex) = " << hex << status
757 << " " << monitorDecodeError(status) << endl;
758 return -1;
9f5fafa6 759 }
760
4fd5ed63 761 cout << "MUONTRKda : Reading data from file " << inputFile <<endl;
762
763 while(1)
764 {
765 if (gNEvents >= maxEvents) break;
766 if (gNEvents && gNEvents % 100 == 0)
767 cout<<"Cumulated events " << gNEvents << endl;
9f5fafa6 768
4fd5ed63 769 // check shutdown condition
770 if (daqDA_checkShutdown())
771 break;
772
773 // Skip Events if needed
774 while (skipEvents) {
775 status = monitorGetEventDynamic(&event);
776 skipEvents--;
777 }
778
779 // starts reading
780 status = monitorGetEventDynamic(&event);
781 if (status < 0) {
782 cout<<"EOF found"<<endl;
783 break;
784 }
785
786 nDateEvents++;
787
788 // decoding rawdata headers
789 AliRawReader *rawReader = new AliRawReaderDate(event);
9f5fafa6 790
4fd5ed63 791 Int_t eventType = rawReader->GetType();
792 gRunNumber = rawReader->GetRunNumber();
9f5fafa6 793
794
4fd5ed63 795 if (eventType != PHYSICS_EVENT)
796 continue; // for the moment
9f5fafa6 797
4fd5ed63 798 gNEvents++;
799 if (gPrintLevel) printf("\nEvent # %d\n",gNEvents);
9f5fafa6 800
4fd5ed63 801 // decoding MUON payload
802 AliMUONRawStreamTrigger* rawStream = new AliMUONRawStreamTrigger(rawReader);
803 //rawStream->SetMaxReg(1);
9f5fafa6 804
4fd5ed63 805 Int_t index = 0;
806 // loops over DDL
807 while((status = rawStream->NextDDL())) {
9f5fafa6 808
4fd5ed63 809 if (gPrintLevel) printf("iDDL %d\n", rawStream->GetDDL());
9f5fafa6 810
4fd5ed63 811 ddlTrigger = rawStream->GetDDLTrigger();
812 darcHeader = ddlTrigger->GetDarcHeader();
9f5fafa6 813
4fd5ed63 814 if (gPrintLevel) printf("Global output %x\n", (Int_t)darcHeader->GetGlobalOutput());
9f5fafa6 815
4fd5ed63 816 // loop over regional structures
817 Int_t nReg = darcHeader->GetRegHeaderEntries();
818 for(Int_t iReg = 0; iReg < nReg; ++iReg){ //REG loop
9f5fafa6 819
4fd5ed63 820 if (gPrintLevel) printf("RegionalId %d\n", iReg);
9f5fafa6 821
4fd5ed63 822 regHeader = darcHeader->GetRegHeaderEntry(iReg);
9f5fafa6 823
4fd5ed63 824 // loop over local structures
825 Int_t nLocal = regHeader->GetLocalEntries();
826 for(Int_t iLocal = 0; iLocal < nLocal; ++iLocal) {
9f5fafa6 827
4fd5ed63 828 localStruct = regHeader->GetLocalEntry(iLocal);
9f5fafa6 829
4fd5ed63 830 Int_t localBoardId = gTriggerIO.LocalBoardId(index++);
831 if (gPrintLevel) printf("local %d\n", localBoardId );
832
833 TArrayS xPattern(4);
834 TArrayS yPattern(4);
835 localStruct->GetXPattern(xPattern);
836 localStruct->GetYPattern(yPattern);
837 MakePattern(localBoardId, xPattern, yPattern);
9f5fafa6 838
4fd5ed63 839 if (gPrintLevel) printf("X pattern %x %x %x %x, Y pattern %x %x %x %x\n",
840 localStruct->GetX1(), localStruct->GetX2(),localStruct->GetX3(),localStruct->GetX4(),
841 localStruct->GetY1(), localStruct->GetY2(),localStruct->GetY3(),localStruct->GetY4());
9f5fafa6 842
4fd5ed63 843 } // iLocal
844 } // iReg
845 } // NextDDL
846
847 delete rawReader;
848 delete rawStream;
849
850 } // while (1)
851
852 if (gCommand.Contains("ped"))
853 MakePatternStore();
9f5fafa6 854
74e61e0d 855 if (gCommand.Contains("cal"))
92c23b09 856 MakePatternStore(false);
9f5fafa6 857
4fd5ed63 858 if (!ExportFiles())
859 return -1;
9f5fafa6 860
4fd5ed63 861 timers.Stop();
9f5fafa6 862
92c23b09 863 cout << "MUONTRGda : Run number : " << gRunNumber << endl;
864 cout << "MUONTRGda : Histo file generated : " << gHistoFileName << endl;
865 cout << "MUONTRGda : Nb of DATE events = " << nDateEvents << endl;
866 cout << "MUONTRGda : Nb of events used = " << gNEvents << endl;
9f5fafa6 867
4fd5ed63 868 printf("Execution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
9f5fafa6 869
4fd5ed63 870 delete gLocalMasks;
871 delete gRegionalMasks;
74e61e0d 872 delete gGlobalMasks; // in case
4fd5ed63 873 delete gPatternStore;
9f5fafa6 874
4fd5ed63 875 return status;
9f5fafa6 876}
92c23b09 877