3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Sebastian Bablok <Sebastian.Bablok@ift.uib.no> *
8 //* for The ALICE HLT Project. *
10 //* Permission to use, copy, modify and distribute this software and its *
11 //* documentation strictly for non-commercial purposes is hereby granted *
12 //* without fee, provided that the above copyright notice appears in all *
13 //* copies and that both the copyright notice and this permission notice *
14 //* appear in the supporting documentation. The authors make no claims *
15 //* about the suitability of this software for any purpose. It is *
16 //* provided "as is" without express or implied warranty. *
17 //**************************************************************************
19 /** @file AliHLTPendolino.cxx
20 @author Sebastian Bablok
25 #include "AliHLTPendolino.h"
27 #include "AliHLTPredictionProcessorInterface.h"
28 #include "AliHLTPendolinoLogger.h"
29 #include "AliHLTPendolinoLoggerOStream.h"
31 #include <AliCDBPath.h>
32 #include <AliCDBEntry.h>
33 #include <AliCDBManager.h>
34 #include <AliCDBStorage.h>
35 #include <AliPreprocessor.h>
38 #include <TObjString.h>
39 #include <TTimeStamp.h>
49 ClassImp(AliHLTPendolino)
52 /** Static string to define a local storage for the OCDB contact. */
53 const TString AliHLTPendolino::kLOCAL_STORAGE_DEFINE = "local://";
55 const char* AliHLTPendolino::kHLTInterfaceModule = "Pendolino-Core";
57 const TString AliHLTPendolino::kTaxiListBaseFolder = getenv("ALIHLT_T_HCDBDIR");
58 //"/opt/T-HCDB/lists/lists-taxi/";
60 const TString AliHLTPendolino::kTaxiListFolderName = "lists/lists-taxi/";
62 const TString AliHLTPendolino::kTaxiListPendolino = "Pendolino.list";
64 const Int_t AliHLTPendolino::kMAX_LINE_LENGTH = 256;
66 const Int_t AliHLTPendolino::kHLTPendolinoException = -10;
68 const Int_t AliHLTPendolino::kHLTPendolinoBadCast = -9;
70 const Int_t AliHLTPendolino::kHLTPendolinoNotPredictProc = -8;
72 const Int_t AliHLTPendolino::kHLTPendolinoModuleNotExisting = -7;
74 const Int_t AliHLTPendolino::kHLTPendolinoNoDCS = -6;
76 //const Int_t AliHLTPendolino::
80 AliHLTPendolino::AliHLTPendolino(Int_t run, TString HCDBbase, TString runType,
81 AliHLTPendolinoLogger* logger, UInt_t startTime, UInt_t endTime) :
82 fRunType(runType), fRunNumber(run),
83 fHCDBPath(""), fPredictionProcessorMap(),
84 fpLogger(0), fOwnLogger(kFALSE),
85 fStartTime(startTime), fEndTime(endTime) {
86 // C-tor of AliHLTPendolino
87 fHCDBPath = kLOCAL_STORAGE_DEFINE + HCDBbase;
89 fpLogger = new AliHLTPendolinoLoggerOStream();
98 AliHLTPendolino::~AliHLTPendolino() {
99 // D-tor of AliHLTPendolino
100 // clean up registered PredicitonProcs
101 TMapIter iter(&fPredictionProcessorMap, kIterForward);
102 AliHLTPredictionProcessorInterface* aPredict;
105 // get each key inside the map
106 while ((key = iter.Next())) {
107 TString detector = key->GetName();
110 // get value for the key
111 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*>
112 (fPredictionProcessorMap.GetValue(key));
115 Log(kHLTInterfaceModule,
116 " *** ERROR, cannot delete registered processor '"
117 + detector + "'; does not seem to be a PredictionProcessor.");
120 Log(kHLTInterfaceModule, " ### [DEBUG] deleting PredictProc '" +
123 } catch (std::bad_cast) {
124 // failed -> is not a AliHLTPredictionProcessorInterface implementation
125 // -> discarding call
126 Log(kHLTInterfaceModule, " *** ERROR, cannot delete registered processor '"
127 + detector + "'; does not seem to be a PredictionProcessor..");
130 } catch (std::exception& e) {
131 Log(kHLTInterfaceModule,
132 " *** Exception in call for deleting PrecitionProcessor '"
137 Log(kHLTInterfaceModule, " ### [DEBUG] Deleting of PredictionProcessors finished.");
140 if ((fOwnLogger) && (fpLogger != 0)) {
147 // inherited virtual functions, maybe use them from base class
148 Bool_t AliHLTPendolino::Store(const AliCDBPath& path, TObject* object,
149 AliCDBMetaData* metaData, Int_t validityStart,
150 Bool_t validityInfinite) {
151 // stores a entry in HCDB
152 Bool_t retVal = kFALSE;
153 Int_t startNumber = 0;
155 AliCDBManager* man = 0;
156 AliCDBStorage* local_hcdb = 0;
158 startNumber = ((fRunNumber - validityStart) <= 0) ? 0 : (fRunNumber - validityStart);
159 endNumber = (validityInfinite) ? AliCDBRunRange::Infinity() : fRunNumber;
161 man = AliCDBManager::Instance();
163 Log(kHLTInterfaceModule, " *** ERROR cannot obtain a CDB Manager reference.");
167 // contact local storage (HCDB)
168 local_hcdb = man->GetStorage(fHCDBPath.Data());
169 if (local_hcdb == 0) {
170 TString msg(" *** ERROR in initiating HCDB: ");
172 Log(kHLTInterfaceModule, msg.Data());
173 man->DestroyActiveStorages();
177 // taken from AliShuttle
178 if (! dynamic_cast<TObjString*> (metaData->GetProperty("RunUsed(TObjString)"))) {
179 TObjString runUsed = Form("%d", fRunNumber);
180 metaData->SetProperty("RunUsed(TObjString)", runUsed.Clone());
184 // Version is set to current run, it will be used later to transfer data to Grid
185 // Why using current run number as version number ???
186 AliCDBId entryID(path, startNumber, endNumber, fRunNumber, -1);
188 if (local_hcdb->Put(object, entryID, metaData)) {
191 TString msg(" *** Unable to store DCS data to HCDB: ");
192 msg += entryID.ToString();
193 Log(kHLTInterfaceModule, msg.Data());
196 man->DestroyActiveStorages();
202 Bool_t AliHLTPendolino::StoreReferenceData(const AliCDBPath& path,
203 TObject* /*object*/, AliCDBMetaData* /*metaData*/) {
204 // Disabled Function inherited from interface
205 TString msg(" ~~~ PredictProc tries to store reference data to '"
206 + path.GetPath() + "'. Discarding call in Pendolino.");
207 Log(kHLTInterfaceModule, msg.Data());
213 Bool_t AliHLTPendolino::StoreReferenceFile(const char* detector,
214 const char* localFile, const char* gridFileName) {
215 // Disabled Function inherited from interface
217 TString det(detector);
218 TString filename(localFile);
219 TString gridname(gridFileName);
220 msg = " ~~~ PredictProc (" + det + ") tries to store reference file (" +
221 filename + ") to '" + gridname +
222 "'. Discarding call in Pendolino.";
223 Log(kHLTInterfaceModule, msg.Data());
229 Bool_t AliHLTPendolino::StoreRunMetadataFile(const char* localFile,
230 const char* gridFileName) {
231 // Disabled Function inherited from interface
234 TString filename(localFile);
235 TString gridname(gridFileName);
236 msg = " ~~~ PredictProc tries to store 'run meta data' file (" +
237 filename + ") to '" + gridname + "'. Discarding call in Pendolino.";
238 Log(kHLTInterfaceModule, msg.Data());
244 const char* AliHLTPendolino::GetFile(Int_t system, const char* detector,
245 const char* id, const char* source) {
246 // Disabled Function inherited from interface
248 TString det(detector);
249 TString filename(id);
251 TString from(GetSystemName(system));
252 msg = " ~~~ PredictProc (" + det + ") requests file (" + filename + ") from '"
253 + src + "' at " + from + ". Discarding call in Pendolino.";
254 Log(kHLTInterfaceModule, msg.Data());
259 const char* AliHLTPendolino::GetTriggerConfiguration() {
260 // Disabled Function inherited from interface
262 msg = " ~~~ PredictProc tries to request Trigger configuration, this is disabled. Discarding call in Pendolino.";
263 Log(kHLTInterfaceModule, msg.Data());
268 const char* AliHLTPendolino::GetTriggerDetectorMask() {
269 // Disabled Function inherited from interface
271 msg = " ~~~ PredictProc tries to request Trigger configuration, this is disabled. Discarding call in Pendolino.";
272 Log(kHLTInterfaceModule, msg.Data());
278 TList* AliHLTPendolino::GetFileSources(Int_t system, const char* detector,
280 // Disabled Function inherited from interface
282 TString det(detector);
283 TString filename(id);
284 TString from(GetSystemName(system));
285 msg = " ~~~ PredictProc (" + det + ") requests file sources for (" + filename
286 + ") from '" + from + ". Discarding call in Pendolino.";
287 Log(kHLTInterfaceModule, msg.Data());
293 TList* AliHLTPendolino::GetFileIDs(Int_t system, const char* detector,
294 const char* source) {
295 // Disabled Function inherited from interface
297 TString det(detector);
298 TString filename(source);
299 TString from(GetSystemName(system));
300 msg = " ~~~ PredictProc (" + det + ") requests file IDs for (" + filename
301 + ") from '" + from + ". Discarding call in Pendolino.";
302 Log(kHLTInterfaceModule, msg.Data());
308 const char* AliHLTPendolino::GetRunParameter(const char* /*lbEntry*/) {
309 // getter for run parameter
312 // maybe using a parameter file, where these settings are stored at start up by
313 // the starting script and a dedicated class read and stores its content.
315 Log(kHLTInterfaceModule,
316 " ### GetRunParameter are not defined, yet. Feature will be available soon.");
321 Bool_t AliHLTPendolino::GetHLTStatus() {
322 // getter for HLT status
323 // since this is the Pendolino -> always true
328 AliCDBEntry* AliHLTPendolino::GetFromOCDB(const char* detector,
329 const AliCDBPath& path) {
330 // fetches entry from HCDB
331 AliCDBManager *man = AliCDBManager::Instance();
332 AliCDBEntry* entry = 0;
335 TString msg(" *** ERROR, cannot obtain a CDB Manager reference for: ");
337 Log(kHLTInterfaceModule, msg.Data());
341 AliCDBStorage *hcdb = man->GetStorage(fHCDBPath.Data());
343 TString msg(" *** ERROR, cannot acquire HCDB storage (");
344 msg += fHCDBPath + ") for fetching data for Pendolino.";
345 Log(kHLTInterfaceModule, msg.Data());
349 entry = hcdb->Get(path, fRunNumber);
352 TString msg(" ~~~ WARNING: no valid entry for '");
353 msg += path.GetPath() + "' in HCDB for run number ";
355 Log(kHLTInterfaceModule, msg.Data());
361 AliCDBEntry* entry = 0;
363 entry = dynamic_cast<AliCDBEntry*> (hcdb->Get(path, fRunNumber));
364 } catch (std::bad_cast) {
365 TString msg(" *** ERROR, bad cast of HCDB entry (");
366 msg += path.GetPath() + ") after fetching from HCDB.";
367 Log(kHLTInterfaceModule, msg.Data());
376 Bool_t AliHLTPendolino::includeAliCDBEntryInList(const TString& entryPath) {
377 // includes entry in Taxi list (objects to be fetched from OCDB)
378 Bool_t bRet = kFALSE;
384 filename = kTaxiListBaseFolder + "/" + kTaxiListFolderName +
386 Log(kHLTInterfaceModule, filename + " [DEBUG] filename");
388 infile.open(filename, ios_base::in);
389 if (infile.is_open()) {
390 char line[kMAX_LINE_LENGTH];
392 while (!infile.eof()) {
393 infile.getline(line, kMAX_LINE_LENGTH);
394 if (strncmp(line, entryPath.Data(), entryPath.Length()) == 0) {
395 // entry already exists, leave function after proper clean up
396 TString msg(" --- Entry '");
397 msg += entryPath + "' is already included in Taxi list file.";
398 Log(kHLTInterfaceModule, msg.Data());
405 // include entry to list
406 outfile.open(filename, ios_base::out | ios_base::app);
407 if (!outfile.is_open()) {
408 TString msg(" *** Unable to create Pendolino list file '");
409 msg += filename + "' for Taxi. Continueing without list update...";
410 Log(kHLTInterfaceModule, msg.Data());
413 // outfile.seekp(-1, ios::end);
415 outfile << "#HLT (Pendolino) - Run: " << fRunNumber << ", Time: " <<
416 ts.AsString() << endl;
417 outfile << entryPath.Data() << endl;
420 TString msg(" +++ Included missing entry '");
421 msg += entryPath + "' in Taxi list file.";
422 Log(kHLTInterfaceModule, msg.Data());
426 TString msg(" ~~~ Unable to open Pendolino list file '");
427 msg += filename + "' for Taxi. Creating new one.";
428 Log(kHLTInterfaceModule, msg.Data());
429 outfile.open(filename, ios_base::out);
431 if (outfile.is_open()) {
432 outfile << "# Automatic generated Taxi list." << endl;
433 outfile << "# It contains the OCDB entries required by the Pendolino."
434 << endl << "#" << endl;
435 outfile << "# !!! DON'T EDIT THIS FILE (if you don't know what you are doing) !!!"
437 outfile << "#HLT (Pendolino) - Run: " << fRunNumber << ", Time: " <<
438 ts.AsString() << endl;
439 outfile << entryPath.Data() << endl;
444 msg=" *** Unable to create Pendolino list file '";
445 msg += filename + "' for Taxi. Continueing without list update...";
446 Log(kHLTInterfaceModule, msg.Data());
454 void AliHLTPendolino::Log(const char* detector, const char* message) {
456 fpLogger->log(detector, message);
457 // refer data to a Pendolino Logger, which can take care of it
461 void AliHLTPendolino::RegisterPreprocessor(AliPreprocessor* preprocessor) {
462 // registers a PredictionProcessor
463 if (preprocessor == 0) {
464 Log(kHLTInterfaceModule,
465 " *** ERROR: Cannot register NULL pointer as PredictionProcessor.");
469 TString detector(preprocessor->GetName());
471 if (fPredictionProcessorMap.GetValue(detector.Data())) {
472 Log(kHLTInterfaceModule, " ~~~ Already registered PredictionProcessor '" +
473 detector + "'. Ignoring call.");
476 // store as AliPreprocessor* and make cast to AliHLTPredictionProcessorInterface*
477 // later, when accesing them.
478 fPredictionProcessorMap.Add(new TObjString(detector), preprocessor);
481 TString detector(preprocessor->GetName());
482 AliHLTPredictionProcessorInterface* predictProc = 0;
483 // UInt_t retVal = 0;
485 // TODO move this in seperated call outside RegisterPreprocessor(..)
486 // safety reason, since preprocessor is not completely generated yet
487 if (!preprocessor->ProcessDCS()) {
488 Log(kHLTInterfaceModule, " *** PredictionProcessor '" + detector +
489 "' not registered, because it will not process DCS values.");
492 Log(kHLTInterfaceModule, "Module Processes DCS values, Registering PredictionProc "
495 // don't use this check, if there are several PreProcs from one detector
496 // they will have all have different names
497 //if (GetDetPos(detector.Data()) < 0) {
498 // Log(kHLTInterfaceModule, " *** Invalid detector name: " + detector);
501 // Check if preprocessor is actually PredictionProcessor
504 predictProc = reinterpret_cast<AliHLTPredictionProcessorInterface*>
506 // Don't use dynamic_cast or C-style cast, they only rename the pointer/object,
507 // but don't import the extended members -> use reinterpret_cast. Maybe perform
508 // dynamic_cast check in other function, which is not called inside a C-tor
509 // of AliHLTPredictionProcessorInterface.
511 // ATTENTION: Don't call any functions of AliHLTPredictionProcessorInterface here
512 // the object has not been completely generated yet, only AliPreprocessor part
513 // is available. Call of these function should be performed in seperate call outside
514 // RegisterPreprocessor(..).)
516 } catch (std::bad_cast) {
517 // failed -> is not a AliHLTPredictionProcessorInterface implementation
518 // -> discarding call
519 Log(kHLTInterfaceModule, " *** Cannot register PredictionProcessor '" + detector +
520 "'. Does not implement the AliHLTPredictionProcessorInterface.");
522 } catch (std::exception& e) {
523 Log(kHLTInterfaceModule, " *** Exception in the registering of the PredictProc.");
526 if (fPredictionProcessorMap.GetValue(detector.Data())) {
527 Log(kHLTInterfaceModule, " ~~~ Already registered PredictionProcessor '" +
528 detector + "'. Ignoring call.");
532 fPredictionProcessorMap.Add(new TObjString(detector), predictProc);
537 UInt_t AliHLTPendolino::setToPredictMaking() {
538 // switches prdiction making on in all registered PredictioProcessors
541 // get an iterator for the map
542 TMapIter iter(&fPredictionProcessorMap, kIterForward);
543 AliHLTPredictionProcessorInterface* aPredict;
546 // get each key inside the map
547 while ((key = iter.Next())) {
548 TString detector = key->GetName();
551 // get value for the key
552 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*>
553 (fPredictionProcessorMap.GetValue(key));
556 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
558 "'. Does not implement the AliHLTPredictionProcessorInterface.");
561 // detector = aPredict->GetName();
563 if ((aPredict->ProcessDCS()) && (aPredict->makePrediction() == 0)) {
566 Log(kHLTInterfaceModule, " *** PredictionProcessor '" + detector
567 + "' does not allow DCS processing or failed to init prediction making.");
569 } catch (std::bad_cast) {
570 // failed -> is not a AliHLTPredictionProcessorInterface implementation
571 // -> discarding call
572 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
574 "'. Does not implement the AliHLTPredictionProcessorInterface.");
577 } catch (std::exception& e) {
578 Log(kHLTInterfaceModule, " *** Exception in call for makePrediction of "
587 Int_t AliHLTPendolino::setToPredictMaking(TString detector) {
588 // switches prediction making on in chosen PreditionProcessor
590 AliHLTPredictionProcessorInterface* aPredict = 0;
593 // get the value for the key
594 TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
597 Log(kHLTInterfaceModule, " *** No PredictionProcessor for '" +
598 detector + "' registered.");
599 return kHLTPendolinoModuleNotExisting;
602 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
605 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
607 "'. Does not implement the AliHLTPredictionProcessorInterface.");
608 return kHLTPendolinoNotPredictProc;
610 // detector = aPredict->GetName();
612 if (!((aPredict->ProcessDCS()) && (aPredict->makePrediction() == 0))) {
613 Log(kHLTInterfaceModule, " *** PredictionProcessor '" + detector +
614 "' does not allow DCS processing or failed to init prediction making.");
615 retVal = kHLTPendolinoNoDCS;
618 } catch (std::bad_cast) {
619 // failed -> is not a AliHLTPredictionProcessorInterface implementation
620 // -> discarding call
621 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
623 "'. Does not implement the AliHLTPredictionProcessorInterface.");
624 retVal = kHLTPendolinoBadCast;
626 } catch (std::exception& e) {
627 Log(kHLTInterfaceModule, " *** Exception in call for makePrediction of "
629 retVal = kHLTPendolinoException;
636 Int_t AliHLTPendolino::prepareDCSValues(TString detector, TMap* DCSValues) {
637 // function to prepare retrieved DCS values
639 AliHLTPredictionProcessorInterface* aPredict = 0;
642 // get the value for the key
643 TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
646 Log(kHLTInterfaceModule, " *** No PredictionProcessor for '" +
647 detector + "' registered.");
648 return kHLTPendolinoModuleNotExisting;
651 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
654 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
656 "'. Does not implement the AliHLTPredictionProcessorInterface.");
657 return kHLTPendolinoNotPredictProc;
660 retVal = aPredict->Process(DCSValues);
663 } catch (std::bad_cast) {
664 // failed -> is not a AliHLTPredictionProcessorInterface implementation
665 // -> discarding call
666 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
668 "'. Does not implement the AliHLTPredictionProcessorInterface.");
669 retVal = kHLTPendolinoBadCast;
671 } catch (std::exception& e) {
672 Log(kHLTInterfaceModule, " *** Exception in call prepareDCSValues of "
674 retVal = kHLTPendolinoException;
680 TMap* AliHLTPendolino::emulateDCSMap(TString detector, TString aliasName) {
681 // function to generate test data of given PredictionProcessor
683 AliHLTPredictionProcessorInterface* aPredict = 0;
686 // get the value for the key
687 TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
690 Log(kHLTInterfaceModule, " *** No PredictionProcessor for '" +
691 detector + "' registered.");
695 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
698 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
700 "'. Does not implement the AliHLTPredictionProcessorInterface.");
704 result = aPredict->produceTestData(aliasName);
707 } catch (std::bad_cast) {
708 // failed -> is not a AliHLTPredictionProcessorInterface implementation
709 // -> discarding call
710 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
712 "'. Does not implement the AliHLTPredictionProcessorInterface.");
714 } catch (std::exception& e) {
715 Log(kHLTInterfaceModule, " *** Exception in call emulateDCSMap of "
722 Int_t AliHLTPendolino::initPredictProc(TString detector, Int_t run,
723 UInt_t startTime, UInt_t endTime) {
724 // initializes given PredictionProcessor (defined by detector name)
726 AliHLTPredictionProcessorInterface* aPredict = 0;
729 // get the value for the key
730 TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
733 Log(kHLTInterfaceModule, " *** No PredictionProcessor for '" +
734 detector + "' registered.");
735 return kHLTPendolinoModuleNotExisting;
738 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
741 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
743 "'. Does not implement the AliHLTPredictionProcessorInterface.");
744 return kHLTPendolinoNotPredictProc;
747 // Initialize Prediction Processor
748 aPredict->Initialize(run, startTime, endTime);
750 } catch (std::bad_cast) {
751 // failed -> is not a AliHLTPredictionProcessorInterface implementation
752 // -> discarding call
753 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
755 "'. Does not implement the AliHLTPredictionProcessorInterface.");
756 retVal = kHLTPendolinoBadCast;
758 } catch (std::exception& e) {
759 Log(kHLTInterfaceModule, " *** Exception in call prepareDCSValues of "
761 retVal = kHLTPendolinoException;
768 #ifdef SHUTTLE_PRE_REV29388_INTERFACE
769 const UInt_t AliHLTPendolino::GetStartTimeDCSQuery()
771 UInt_t AliHLTPendolino::GetStartTimeDCSQuery()
777 #ifdef SHUTTLE_PRE_REV29388_INTERFACE
778 const UInt_t AliHLTPendolino::GetEndTimeDCSQuery()
780 UInt_t AliHLTPendolino::GetEndTimeDCSQuery()