Fixing code so that components use the new standard DDL_RAW data type.
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONTriggerCalibratorComponent.cxx
CommitLineData
8134dd2e 1/**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
4 * *
5 * Primary Authors: *
6 * Artur Szostak <artursz@iafrica.com> *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17/* $Id$ */
18
19///
20/// @file AliHLTMUONTriggerCalibratorComponent.cxx
21/// @author Artur Szostak <artursz@iafrica.com>
22/// @date
23/// @brief Implementation of the AliHLTMUONTriggerCalibratorComponent class.
24///
25
26#include "AliHLTMUONTriggerCalibratorComponent.h"
27#include "AliHLTMUONConstants.h"
28#include "AliHLTMUONUtils.h"
29
30ClassImp(AliHLTMUONTriggerCalibratorComponent);
31
32///////////////////////////////////////////////////////////////////////////////
33// The code from here on was copied from MUONTRGda.cxx and addapted to the
34// HLT framework.
35//TODO: test that any of this actually works and clean up the code.
36///////////////////////////////////////////////////////////////////////////////
37
38#include <iostream>
39#include <fstream>
40using namespace std;
41
42#include <cstdio>
43#include <cstdlib>
44
45//AliRoot
46#include "AliRawDataHeader.h"
47#include "AliRawReaderMemory.h"
48#include "AliMpConstants.h"
49#include "AliMUONRawStreamTrigger.h"
50#include "AliMUONDarcHeader.h"
51#include "AliMUONRegHeader.h"
52#include "AliMUONLocalStruct.h"
53#include "AliMUONDDLTrigger.h"
54#include "AliMUONVCalibParam.h"
55#include "AliMUONVStore.h"
56#include "AliMUONCalibParamND.h"
57#include "AliMUONCalibParamNI.h"
58#include "AliMUON1DArray.h"
59#include "AliMUONTriggerIO.h"
60
61//ROOT
62#include "TString.h"
63#include "TSystem.h"
64#include "TStopwatch.h"
65#include "TMath.h"
66#include "TTimeStamp.h"
67#include "TROOT.h"
68#include "TPluginManager.h"
69#include "TFile.h"
70#include "TH1F.h"
71#include "TArrayI.h"
72#include "TArrayS.h"
73
74namespace
75{
76
77// global variables
78const Int_t gkNLocalBoard = AliMpConstants::NofLocalBoards();
79
80TString gCommand("ped");
81
82TString gCurrentFileName("MtgCurrent.dat");
83TString gLastCurrentFileName("MtgLastCurrent.dat");
84
85TString gSodName;
86Int_t gSodFlag = 0;
87
88TString gDAName;
89Int_t gDAFlag = 0;
90
91TString gGlobalFileName;
92TString gRegionalFileName;
93TString gLocalMaskFileName;
94TString gLocalLutFileName;
95TString gSignatureFileName;
96
97Int_t gGlobalFileVersion;
98Int_t gRegionalFileVersion;
99Int_t gLocalMaskFileVersion;
100Int_t gLocalLutFileVersion;
101Int_t gSignatureFileVersion;
102
103Int_t gGlobalFileLastVersion;
104Int_t gRegionalFileLastVersion;
105Int_t gLocalMaskFileLastVersion;
106Int_t gLocalLutFileLastVersion;
107
108UInt_t gRunNumber = 0;
109Int_t gNEvents = 0;
110
111Int_t gPrintLevel = 0;
112
113AliMUONVStore* gLocalMasks = NULL;
114AliMUONVStore* gRegionalMasks = NULL;
115AliMUONVCalibParam* gGlobalMasks = NULL;
116
117AliMUONTriggerIO gTriggerIO;
118
119AliMUONVStore* gPatternStore = NULL;
120
121TString gHistoFileName = "";
122
123Float_t gkThreshold = 0.2;
124
125}; // end of namespace
126
127//__________________________________________________________________
128void UpdateLocalMask(Int_t localBoardId, Int_t connector, Int_t strip)
129{
130
131 // update local mask
132 AliMUONVCalibParam* localMask =
133 static_cast<AliMUONVCalibParam*>(gLocalMasks->FindObject(localBoardId));
134
135 UShort_t mask = localMask->ValueAsInt(connector,0);
136
137 mask ^= (0x1 << strip); // set strip mask to zero
138
139 localMask->SetValueAsInt(connector,0, mask);
140}
141
142//__________________________________________________________________
143void WriteLastCurrentFile(TString currentFile = gLastCurrentFileName)
144{
145 if (gSodName.IsNull()) gSodName = "SOD";
146 if (gDAName.IsNull()) gDAName = "MTG";
147 if (gGlobalFileName.IsNull()) gGlobalFileName = "global.dat";
148 if (gRegionalFileName.IsNull()) gRegionalFileName = "regional.dat";
149 if (gLocalMaskFileName.IsNull()) gLocalMaskFileName = "localMask.dat";
150 if (gLocalLutFileName.IsNull()) gLocalLutFileName = "localLut.dat";
151 if (gSignatureFileName.IsNull()) gSignatureFileName = "signature.dat";
152
153 // write last current file
154 ofstream out;
155 TString file;
156 file = currentFile;
157 out.open(file.Data());
158 out << gSodName << " " << gSodFlag << endl;
159 out << gDAName << " " << gDAFlag << endl;
160
161 out << gGlobalFileName << " " << gGlobalFileVersion << endl;
162 out << gRegionalFileName << " " << gRegionalFileVersion << endl;
163 out << gLocalMaskFileName << " " << gLocalMaskFileVersion << endl;
164 out << gLocalLutFileName << " " << gLocalLutFileVersion << endl;
165 out << gSignatureFileName << " " << gSignatureFileVersion << endl;
166
167 out.close();
168}
169
170//___________________________________________________________________________________________
171Bool_t ReadCurrentFile(TString currentFile = gCurrentFileName, Bool_t lastCurrentFlag = false)
172{
173
174 // read last current file name and version
175 char line[80];
176 char name[80];
177
178 TString file;
179 file = currentFile;
180 std::ifstream in(gSystem->ExpandPathName(file.Data()));
181 if (!in.good()) {
182 printf("Cannot open last current file %s\n",currentFile.Data());
183 return false;
184 }
185
186
187 // read SOD
188 in.getline(line,80);
189 sscanf(line, "%s %d", name, &gSodFlag);
190 gSodName = name;
191 if (gPrintLevel) printf("Sod Flag %d\n", gSodFlag);
192
193 //read DA
194 in.getline(line,80);
195 sscanf(line, "%s %d", name, &gDAFlag);
196 gDAName = name;
197 if (gPrintLevel) printf("DA Flag: %d\n", gDAFlag);
198
199
200 // read global
201 in.getline(line,80);
202 TString tmp(line);
203 Int_t pos = tmp.First(" ");
204 gGlobalFileName = tmp(0, pos);
205
206 if (!lastCurrentFlag) {
207 gGlobalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
208 if (gPrintLevel) printf("Global File Name: %s version: %d\n",
209 gGlobalFileName.Data(), gGlobalFileVersion);
210 } else {
211 gGlobalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
212 if (gPrintLevel) printf("Global File Name: %s last version: %d\n",
213 gGlobalFileName.Data(), gGlobalFileLastVersion);
214 }
215
216 // read regional
217 in.getline(line,80);
218 tmp = line;
219 pos = tmp.First(" ");
220 gRegionalFileName = tmp(0, pos);
221
222 if (!lastCurrentFlag) {
223 gRegionalFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
224 if (gPrintLevel) printf("Regional File Name: %s version: %d\n",
225 gRegionalFileName.Data(), gRegionalFileVersion);
226
227 } else {
228 gRegionalFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
229 if (gPrintLevel) printf("Regional File Name: %s last version: %d\n",
230 gRegionalFileName.Data(), gRegionalFileLastVersion);
231 }
232
233 // read mask
234 in.getline(line,80);
235 tmp = line;
236 pos = tmp.First(" ");
237 gLocalMaskFileName = tmp(0, pos);
238
239 if (!lastCurrentFlag) {
240 gLocalMaskFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
241 if (gPrintLevel) printf("Mask File Name: %s version: %d\n",
242 gLocalMaskFileName.Data(), gLocalMaskFileVersion);
243 } else {
244 gLocalMaskFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
245 if (gPrintLevel) printf("Mask File Name: %s last version: %d\n",
246 gLocalMaskFileName.Data(), gLocalMaskFileLastVersion);
247 }
248 // read Lut
249 in.getline(line,80);
250 tmp = line;
251 pos = tmp.First(" ");
252 gLocalLutFileName = tmp(0, pos);
253
254 if (!lastCurrentFlag) {
255 gLocalLutFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
256 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
257 gLocalLutFileName.Data(), gLocalLutFileVersion);
258 } else {
259 gLocalLutFileLastVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
260 if (gPrintLevel) printf("Lut File Name: %s last version: %d\n",
261 gLocalLutFileName.Data(), gLocalLutFileLastVersion);
262 }
263
264 in.getline(line,80);
265 tmp = line;
266 pos = tmp.First(" ");
267 gSignatureFileName = tmp(0, pos);
268 gSignatureFileVersion = atoi(tmp(pos+1, tmp.Length()-pos).Data());
269 if (gPrintLevel) printf("Lut File Name: %s version: %d\n",
270 gSignatureFileName.Data(), gSignatureFileVersion);
271
272 return true;
273}
274
275//_____________
276void ReadFileNames()
277{
278 // if last current file does not exist than read current file
279 if (!ReadCurrentFile(gLastCurrentFileName, true))
280 {
281 ReadCurrentFile(gCurrentFileName, true);
282 WriteLastCurrentFile();
283 }
284
285 // any case read current file
286 ReadCurrentFile();
287
288}
289
290//__________________
291Bool_t ExportFiles()
292{
293
294 // Export files to FES
295 // Export files to DB not yet done, waiting for a version > 1.2 of daqDAlib
296 // env variables have to be set (suppose by ECS ?)
297 // setenv DATE_FES_PATH
298 // setenv DATE_RUN_NUMBER
299 // setenv DATE_ROLE_NAME
300 // setenv DATE_DETECTOR_CODE
301
302 // to be sure that env variable is set
303 gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/infoLogger");
304
305 // update files
306 Int_t status = 0;
307
308 Bool_t modified = false;
309
310 ofstream out;
311 TString fileExp("ExportedFiles.dat");
312 TString file;
313
314 out.open(fileExp.Data());
315 if (!out.good()) {
316 printf("Failed to create file: %s\n",file.Data());
317 return false;
318 }
319
320 if (gGlobalFileLastVersion != gGlobalFileVersion) {
321 file = gGlobalFileName.Data();
322// status = daqDA_FES_storeFile(file.Data(), file.Data());
323 status = 0;
324 if (status) {
325 printf("Failed to export file: %s\n",gGlobalFileName.Data());
326 return false;
327 }
328 out << gGlobalFileName.Data() << endl;
329 if(gPrintLevel) printf("Export file: %s\n",gGlobalFileName.Data());
330 }
331
332 if (gLocalMaskFileLastVersion != gLocalMaskFileVersion) {
333 modified = true;
334 file = gLocalMaskFileName;
335// status = daqDA_FES_storeFile(file.Data(), file.Data());
336 status = 0;
337 if (status) {
338 printf("Failed to export file: %s\n",gLocalMaskFileName.Data());
339 return false;
340 }
341 if(gPrintLevel) printf("Export file: %s\n",gLocalMaskFileName.Data());
342 out << gLocalMaskFileName.Data() << endl;
343 }
344
345 if (gLocalLutFileLastVersion != gLocalLutFileVersion) {
346 file = gLocalLutFileName;
347 modified = true;
348// status = daqDA_FES_storeFile(file.Data(), file.Data());
349 status = 0;
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
360 if ( (gRegionalFileLastVersion != gRegionalFileVersion) || modified) {
361 file = gRegionalFileName;
362// status = daqDA_FES_storeFile(file.Data(), file.Data());
363 status = 0;
364 if (status) {
365 printf("Failed to export file: %s\n",gRegionalFileName.Data());
366 return false;
367 }
368 if(gPrintLevel) printf("Export file: %s\n",gRegionalFileName.Data());
369 out << gRegionalFileName.Data() << endl;
370 }
371
372 out.close();
373
374 // export Exported file to FES anyway
375// status = daqDA_FES_storeFile(fileExp.Data(), fileExp.Data());
376 status = 0;
377 if (status) {
378 printf("Failed to export file: %s\n", fileExp.Data());
379 return false;
380 }
381 if(gPrintLevel) printf("Export file: %s\n",fileExp.Data());
382
383 return true;
384}
385
386//__________________
387Bool_t ImportFiles()
388{
389 // copy locally a file from daq detector config db
390 // The current detector is identified by detector code in variable
391 // DATE_DETECTOR_CODE. It must be defined.
392 // If environment variable DAQDA_TEST_DIR is defined, files are copied from DAQDA_TEST_DIR
393 // instead of the database. The usual environment variables are not needed.
394
395 // to be sure that env variable is set
396 gSystem->Setenv("DAQDALIB_PATH", "$DATE_SITE/db");
397
398 Int_t status = 0;
399
400// status = daqDA_DB_getFile(gCurrentFileName.Data(), gCurrentFileName.Data());
401 status = 0;
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 status = 0;
411 if (status) {
412 printf("Failed to get current config file from DB: %s\n", gGlobalFileName.Data());
413 return false;
414 }
415
416// status = daqDA_DB_getFile(gRegionalFileName.Data(), gRegionalFileName.Data());
417 status = 0;
418 if (status) {
419 printf("Failed to get current config file from DB: %s\n",gRegionalFileName.Data());
420 return false;
421 }
422
423// status = daqDA_DB_getFile(gLocalMaskFileName.Data(), gLocalMaskFileName.Data());
424 status = 0;
425 if (status) {
426 printf("Failed to get current config file from DB: %s\n",gLocalMaskFileName.Data());
427 return false;
428 }
429
430// status = daqDA_DB_getFile(gLocalLutFileName.Data(), gLocalLutFileName.Data());
431 status = 0;
432 if (status) {
433 printf("Failed to get current config file from DB: %s\n",gLocalLutFileName.Data());
434 return false;
435 }
436
437 return true;
438}
439
440//__________
441void MakePattern(Int_t localBoardId, TArrayS& xPattern, TArrayS& yPattern)
442{
443
444 // calculate the hit map for each strip in x and y direction
445 AliMUONVCalibParam* pat =
446 static_cast<AliMUONVCalibParam*>(gPatternStore->FindObject(localBoardId));
447
448 if (!pat) {
449 pat = new AliMUONCalibParamND(2, 64, localBoardId, 0,0.); // put default wise 0.
450 gPatternStore->Add(pat);
451 }
452
453 for (Int_t i = 0; i < 4; ++i) {
454 for (Int_t j = 0; j < 16; ++j) {
455
456 Int_t xMask = xPattern[i];
457 Int_t yMask = yPattern[i];
458
459 Int_t index = 16*i + j;
460 Double_t patOcc = 0.;
461
462 if ( (xMask >> j ) & 0x1 ) {
463 patOcc = pat->ValueAsDouble(index, 0) + 1.;
464 pat->SetValueAsDouble(index, 0, patOcc);
465 }
466 if ( (yMask >> j ) & 0x1 ) {
467 patOcc = pat->ValueAsDouble(index, 0) + 1.;
468 pat->SetValueAsDouble(index, 0, patOcc);
469 }
470 }
471 }
472
473}
474
475//__________
476void MakePatternStore(Bool_t pedestal = true)
477{
478
479 // calculates the occupancy (option: store in a root file)
480 // check noisy strip (pedestal true, software trigger)
481 // check dead channel (pesdetal false, FET trigger)
482
483 Int_t localBoardId = 0;
484 Bool_t updated = false;
485
486 // histo
487
488 Char_t name[255];
489 Char_t title[255];
490
491 TH1F* xOccHisto[243];
492 TH1F* yOccHisto[243];
493 TH1F* xPatOccHisto = 0x0;
494 TH1F* yPatOccHisto = 0x0;
495
496 TFile* histoFile = 0x0;
497
498 if (gHistoFileName[0] != 0) {
499 histoFile = new TFile(gHistoFileName,"RECREATE","MUON Tracking pedestals");
500
501 sprintf(name,"pat_x");
502 sprintf(title,"Occupancy for x strip");
503 Int_t nx = 200;
504 Float_t xmin = -0.2;
505 Float_t xmax = 1.2;
506 xPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
507 xPatOccHisto ->SetDirectory(histoFile);
508
509 sprintf(name,"pat_y");
510 sprintf(title,"Occupancy for y strip");
511 yPatOccHisto = new TH1F(name,title,nx,xmin,xmax);
512 yPatOccHisto->SetDirectory(histoFile);
513
514 }
515
516 // iterator over pedestal
517 TIter next(gPatternStore->CreateIterator());
518 AliMUONVCalibParam* pat;
519
520 while ( ( pat = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
521 {
522 localBoardId = pat->ID0();
523
524 if (gHistoFileName[0] != 0) {
525
526 Int_t nx = 64;
527 Float_t xmin = 0;
528 Float_t xmax = 64;
529
530 sprintf(name,"pat_x_%d",localBoardId);
531 sprintf(title,"Occupancy for x strip, board %d",localBoardId);
532 xOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
533
534 sprintf(name,"pat_y_%d",localBoardId);
535 sprintf(title,"Occupancy for y strip, board %d",localBoardId);
536 yOccHisto[localBoardId] = new TH1F(name,title,nx,xmin,xmax);
537
538 }
539
540 for (Int_t index = 0; index < pat->Size() ; ++index) {// 64 bits for X and 64 bits for Y strips
541
542 Double_t patXOcc = pat->ValueAsDouble(index, 0)/(Double_t)gNEvents;
543 Double_t patYOcc = pat->ValueAsDouble(index, 1)/(Double_t)gNEvents;
544
545 pat->SetValueAsDouble(index, 0, patXOcc);
546 pat->SetValueAsDouble(index, 1, patYOcc);
547
548
549 // check for x strip
550 if ( (patXOcc > gkThreshold && pedestal) || (patXOcc < 1.- gkThreshold && !pedestal) ) {
551 UShort_t strip = index % 16;
552 Int_t connector = index/16;
553 UpdateLocalMask(localBoardId, connector, strip);
554 updated = true;
555 }
556
557 // check for y strip
558 if ( (patYOcc > gkThreshold && pedestal) || (patYOcc < 1.- gkThreshold && !pedestal) ) {
559 UShort_t strip = index % 16;
560 Int_t connector = index/16 + 4;
561 UpdateLocalMask(localBoardId, connector, strip);
562 updated = true;
563
564 }
565
566 if (gHistoFileName[0] != 0) {
567 xPatOccHisto->Fill(patXOcc);
568 yPatOccHisto->Fill(patYOcc);
569 xOccHisto[localBoardId]->Fill(index, patXOcc);
570 yOccHisto[localBoardId]->Fill(index, patYOcc);
571
572 }
573 }
574 }
575
576 if (gHistoFileName[0] != 0) {
577 histoFile->Write();
578 histoFile->Close();
579 }
580
581 if (updated) {
582
583 // update version
584 gLocalMaskFileVersion++;
585
586 TString tmp(gLocalMaskFileName);
587 Int_t pos = tmp.First("-");
588 gLocalMaskFileName = tmp(0,pos+1) + Form("%d",gLocalMaskFileVersion) + ".dat";
589
590 // write last current file
591 WriteLastCurrentFile();
592
593 gTriggerIO.WriteMasks(gLocalMaskFileName, gRegionalFileName, gGlobalFileName, gLocalMasks, gRegionalMasks, gGlobalMasks);
594 }
595}
596
597
598AliHLTMUONTriggerCalibratorComponent::AliHLTMUONTriggerCalibratorComponent() :
599 AliHLTCalibrationProcessor(),
600 fSkipEvents(0),
601 fMaxEvents(1000000)
602{
603 /// Default contructor.
604}
605
606
607AliHLTMUONTriggerCalibratorComponent::~AliHLTMUONTriggerCalibratorComponent()
608{
609 /// Default destructor.
610}
611
612
613const char* AliHLTMUONTriggerCalibratorComponent::GetComponentID()
614{
615 /// Inherited from AliHLTComponent.
616 /// Returns the component ID string for this component type.
617
618 return AliHLTMUONConstants::TriggerCalibratorId();
619}
620
621
622void AliHLTMUONTriggerCalibratorComponent::GetInputDataTypes(
623 vector<AliHLTComponentDataType>& list
624 )
625{
626 /// Inherited from AliHLTComponent.
627 /// Returns the list of input block types expected by this component.
628
629 list.clear();
668eee9f 630 list.push_back( AliHLTMUONConstants::DDLRawDataType() );
8134dd2e 631}
632
633
634AliHLTComponentDataType AliHLTMUONTriggerCalibratorComponent::GetOutputDataType()
635{
636 /// Inherited from AliHLTComponent.
637 /// Returns the type of output block generated by this component.
638
639 //TODO: fix.
668eee9f 640 return AliHLTMUONConstants::DDLRawDataType();
8134dd2e 641}
642
643
644void AliHLTMUONTriggerCalibratorComponent::GetOutputDataSize(
645 unsigned long& constBase, double& inputMultiplier
646 )
647{
648 /// Inherited from AliHLTComponent.
649 /// Returns an estimate of the expected output data size.
650
651 constBase = 0;
652 inputMultiplier = 2.; //TODO: is this the correct estimate.
653}
654
655
656AliHLTComponent* AliHLTMUONTriggerCalibratorComponent::Spawn()
657{
658 /// Inherited from AliHLTComponent.
659 /// Creates a new instance of AliHLTMUONTriggerCalibratorComponent.
660
661 return new AliHLTMUONTriggerCalibratorComponent();
662}
663
664
665Int_t AliHLTMUONTriggerCalibratorComponent::ScanArgument(int argc, const char** argv)
666{
667 /// Inherited from AliHLTCalibrationProcessor.
668 /// Parses the command line parameters.
669
670 TString arg = argv[0];
671
672 if (arg.CompareTo("-h") == 0)
673 {
674 HLTInfo("******************* usage **********************");
675 HLTInfo("The available options are :");
676 HLTInfo("-h help (this screen)");
677 HLTInfo("");
678 HLTInfo(" Output");
679 HLTInfo("-r <root file> (default = %s)", gHistoFileName.Data());
680 HLTInfo("");
681 HLTInfo(" Options");
682 HLTInfo("-t <threshold values> (default = %3.1f)", gkThreshold);
683 HLTInfo("-d <print level> (default = %d)", gPrintLevel);
684 HLTInfo("-s <skip events> (default = %d)", fSkipEvents);
685 HLTInfo("-n <max events> (default = %d)", fMaxEvents);
686 HLTInfo("-e <execute ped/calib> (default = %s)", gCommand.Data());
687 return 0; // Zero parameters parsed.
688 }
689
690 if (arg.CompareTo("-t") == 0)
691 {
692 if (argc < 2) return -EPROTO;
693 gkThreshold = atof(argv[1]);
694 return 1; // 1 parameter parsed.
695 }
696 if (arg.CompareTo("-e") == 0)
697 {
698 if (argc < 2) return -EPROTO;
699 gCommand = argv[1];
700 gCommand.ToLower(); // set command to lower case
701 return 1; // 1 parameter parsed.
702 }
703 if (arg.CompareTo("-d") == 0)
704 {
705 if (argc < 2) return -EPROTO;
706 gPrintLevel = atoi(argv[1]);
707 return 1; // 1 parameter parsed.
708 }
709 if (arg.CompareTo("-s") == 0)
710 {
711 if (argc < 2) return -EPROTO;
712 fSkipEvents = atoi(argv[1]);
713 return 1; // 1 parameter parsed.
714 }
715 if (arg.CompareTo("-n") == 0)
716 {
717 if (argc < 2) return -EPROTO;
718 fMaxEvents = atoi(argv[1]);
719 return 1; // 1 parameter parsed.
720 }
721 if (arg.CompareTo("-r") == 0)
722 {
723 if (argc < 2) return -EPROTO;
724 gHistoFileName = argv[1];
725 return 1; // 1 parameter parsed.
726 }
727
728 // Do not know what this argument is so return an error code.
729 HLTError("Bad argument %s (please check with -h)", arg.Data());
730 return -EINVAL;
731}
732
733
734Int_t AliHLTMUONTriggerCalibratorComponent::InitCalibration()
735{
736 /// Inherited from AliHLTCalibrationProcessor.
737 /// Initialise the calibration component.
738
739 // comment out, since we do not retrieve files from database
740 if (!ImportFiles())
741 {
742 HLTError("Import from DB failed");
743 HLTError("For local test set DAQDA_TEST_DIR to the local directory where the Mtg files are located.");
744 return -1;
745 }
746 /*
747 if (!gDAFlag)
748 {
749 if(!ExportFiles()) return -1;
750 return 0;
751 }
752 */
753
754 // read mask files
755 gLocalMasks = new AliMUON1DArray(gkNLocalBoard+9);
756 gRegionalMasks = new AliMUON1DArray(16);
757 gGlobalMasks = new AliMUONCalibParamNI(1,2,1,0,0);
758 gPatternStore = new AliMUON1DArray(gkNLocalBoard+9);
759
760 TString localFile = gLocalMaskFileName;
761 TString regionalFile = gRegionalFileName;
762 TString globalFile = gGlobalFileName;
763
764 gTriggerIO.ReadMasks(localFile.Data(), regionalFile.Data(), globalFile.Data(),
765 gLocalMasks, gRegionalMasks, gGlobalMasks, false);
766
767 return 0;
768}
769
770
771Int_t AliHLTMUONTriggerCalibratorComponent::DeinitCalibration()
772{
773 /// Inherited from AliHLTCalibrationProcessor.
774 /// Cleanup the calibration component releasing allocated memory.
775
776 delete gLocalMasks;
777 delete gRegionalMasks;
778 delete gGlobalMasks; // in case
779 delete gPatternStore;
780 gLocalMasks = NULL;
781 gRegionalMasks = NULL;
782 gGlobalMasks = NULL;
783 gPatternStore = NULL;
784
785 return 0;
786}
787
788
789Int_t AliHLTMUONTriggerCalibratorComponent::ProcessCalibration(
790 const AliHLTComponentEventData& /*evtData*/,
791 AliHLTComponentTriggerData& /*trigData*/
792 )
793{
794 /// Inherited from AliHLTCalibrationProcessor.
795 /// Perform a calibration procedure on the new event.
796
797 // Skip Events if needed
798 if (fSkipEvents > 0)
799 {
800 fSkipEvents--;
801 return 0;
802 }
803
804 // Do not process more than fMaxEvents.
805 if (gNEvents >= fMaxEvents) return 0;
806 if (gNEvents && gNEvents % 100 == 0)
807 HLTInfo("Cumulated events %d", gNEvents);
808
809 gNEvents++;
810
811 gRunNumber = GetRunNo();
812
813 /*
814 Int_t eventType = GetRunType();
815 if (eventType != 7) // PHYSICS_EVENT - from event.h (DATE software)
816 {
817 HLTWarning("This event is not a physics event");
818 return 0;
819 }
820 */
821
822 Int_t status;
823
824 // containers
825 AliMUONDDLTrigger* ddlTrigger = 0x0;
826 AliMUONDarcHeader* darcHeader = 0x0;
827 AliMUONRegHeader* regHeader = 0x0;
828 AliMUONLocalStruct* localStruct = 0x0;
829
830 const AliHLTComponentBlockData* iter = NULL;
831
832 // Loop over all DDL raw data input blocks and decode the event.
668eee9f 833 iter = GetFirstInputBlock( AliHLTMUONConstants::DDLRawDataType() );
8134dd2e 834 while (iter != NULL)
835 {
668eee9f 836 // Make sure we have the correct muon trigger DDL type.
837 if (not AliHLTMUONUtils::IsTriggerDDL(iter->fSpecification))
838 {
839 iter = GetNextInputBlock();
840 continue;
841 }
8134dd2e 842
843 // decoding rawdata headers
844 AliRawReaderMemory* rawReader = new AliRawReaderMemory(
845 reinterpret_cast<UChar_t*>(iter->fPtr), iter->fSize
846 );
847 rawReader->SetEquipmentID(AliHLTMUONUtils::SpecToEquipId(iter->fSpecification));
848
849 // decoding MUON payload
850 AliMUONRawStreamTrigger* rawStream = new AliMUONRawStreamTrigger(rawReader);
851 //rawStream->SetMaxReg(1);
852
853 Int_t index = 0;
854 // loops over DDL
855 while((status = rawStream->NextDDL()))
856 {
857 if (gPrintLevel) HLTInfo("iDDL %d", rawStream->GetDDL());
858
859 ddlTrigger = rawStream->GetDDLTrigger();
860 darcHeader = ddlTrigger->GetDarcHeader();
861
862 if (gPrintLevel) HLTInfo("Global output %x", (Int_t)darcHeader->GetGlobalOutput());
863
864 // loop over regional structures
865 Int_t nReg = darcHeader->GetRegHeaderEntries();
866 for(Int_t iReg = 0; iReg < nReg; ++iReg)
867 { //REG loop
868 if (gPrintLevel) HLTInfo("RegionalId %d", iReg);
869
870 regHeader = darcHeader->GetRegHeaderEntry(iReg);
871
872 // loop over local structures
873 Int_t nLocal = regHeader->GetLocalEntries();
874 for(Int_t iLocal = 0; iLocal < nLocal; ++iLocal)
875 {
876 localStruct = regHeader->GetLocalEntry(iLocal);
877
878 Int_t localBoardId = gTriggerIO.LocalBoardId(index++);
879 if (gPrintLevel) HLTInfo("local %d", localBoardId );
880
881 TArrayS xPattern(4);
882 TArrayS yPattern(4);
883 localStruct->GetXPattern(xPattern);
884 localStruct->GetYPattern(yPattern);
885 MakePattern(localBoardId, xPattern, yPattern);
886
887 if (gPrintLevel)
888 {
889 HLTInfo("X pattern %x %x %x %x, Y pattern %x %x %x %x",
890 localStruct->GetX1(), localStruct->GetX2(),localStruct->GetX3(),localStruct->GetX4(),
891 localStruct->GetY1(), localStruct->GetY2(),localStruct->GetY3(),localStruct->GetY4()
892 );
893 }
894 } // iLocal
895 } // iReg
896 } // NextDDL
897
898 delete rawReader;
899 delete rawStream;
900
901 // Get next DDL raw data input block, with the same specification as defined in GetFirstInputBlock().
902 iter = GetNextInputBlock();
903 }
904
905 if (gCommand.Contains("ped"))
906 MakePatternStore();
907
908 if (gCommand.Contains("cal"))
909 HLTWarning("Options %s disabled", gCommand.Data());
910 // MakePatternStore(false);
911
912 if (!ExportFiles())
913 return -1;
914
915 HLTInfo("MUONTRKda : Run number : %d", gRunNumber);
916 HLTInfo("MUONTRKda : Histo file generated : %s", gHistoFileName.Data());
917 HLTInfo("MUONTRKda : Nb of events used = %d", gNEvents);
918
919 //TODO:
920 // PushBack data to shared memory ...
921 //PushBack(.....);
922
923 return 0;
924}
925
926
927Int_t AliHLTMUONTriggerCalibratorComponent::ShipDataToFXS(
928 const AliHLTComponentEventData& /*evtData*/,
929 AliHLTComponentTriggerData& /*trigData*/
930 )
931{
932 /// Inherited from AliHLTCalibrationProcessor.
933 /// Push the data to the FXS to ship off to the offline CDB.
934
935 //TODO:
936 // PushBack data to FXS ...
937 //PushToFXS( ..... ) ;
938
939 return 0;
940}