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