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());
269 TList* AliHLTPendolino::GetFileSources(Int_t system, const char* detector,
271 // Disabled Function inherited from interface
273 TString det(detector);
274 TString filename(id);
275 TString from(GetSystemName(system));
276 msg = " ~~~ PredictProc (" + det + ") requests file sources for (" + filename
277 + ") from '" + from + ". Discarding call in Pendolino.";
278 Log(kHLTInterfaceModule, msg.Data());
284 TList* AliHLTPendolino::GetFileIDs(Int_t system, const char* detector,
285 const char* source) {
286 // Disabled Function inherited from interface
288 TString det(detector);
289 TString filename(source);
290 TString from(GetSystemName(system));
291 msg = " ~~~ PredictProc (" + det + ") requests file IDs for (" + filename
292 + ") from '" + from + ". Discarding call in Pendolino.";
293 Log(kHLTInterfaceModule, msg.Data());
299 const char* AliHLTPendolino::GetRunParameter(const char* /*lbEntry*/) {
300 // getter for run parameter
303 // maybe using a parameter file, where these settings are stored at start up by
304 // the starting script and a dedicated class read and stores its content.
306 Log(kHLTInterfaceModule,
307 " ### GetRunParameter are not defined, yet. Feature will be available soon.");
312 Bool_t AliHLTPendolino::GetHLTStatus() {
313 // getter for HLT status
314 // since this is the Pendolino -> always true
319 AliCDBEntry* AliHLTPendolino::GetFromOCDB(const char* detector,
320 const AliCDBPath& path) {
321 // fetches entry from HCDB
322 AliCDBManager *man = AliCDBManager::Instance();
323 AliCDBEntry* entry = 0;
326 TString msg(" *** ERROR, cannot obtain a CDB Manager reference for: ");
328 Log(kHLTInterfaceModule, msg.Data());
332 AliCDBStorage *hcdb = man->GetStorage(fHCDBPath.Data());
334 TString msg(" *** ERROR, cannot acquire HCDB storage (");
335 msg += fHCDBPath + ") for fetching data for Pendolino.";
336 Log(kHLTInterfaceModule, msg.Data());
340 entry = hcdb->Get(path, fRunNumber);
343 TString msg(" ~~~ WARNING: no valid entry for '");
344 msg += path.GetPath() + "' in HCDB for run number ";
346 Log(kHLTInterfaceModule, msg.Data());
352 AliCDBEntry* entry = 0;
354 entry = dynamic_cast<AliCDBEntry*> (hcdb->Get(path, fRunNumber));
355 } catch (std::bad_cast) {
356 TString msg(" *** ERROR, bad cast of HCDB entry (");
357 msg += path.GetPath() + ") after fetching from HCDB.";
358 Log(kHLTInterfaceModule, msg.Data());
367 Bool_t AliHLTPendolino::includeAliCDBEntryInList(const TString& entryPath) {
368 // includes entry in Taxi list (objects to be fetched from OCDB)
369 Bool_t bRet = kFALSE;
375 filename = kTaxiListBaseFolder + "/" + kTaxiListFolderName +
377 Log(kHLTInterfaceModule, filename + " [DEBUG] filename");
379 infile.open(filename, ios_base::in);
380 if (infile.is_open()) {
381 char line[kMAX_LINE_LENGTH];
383 while (!infile.eof()) {
384 infile.getline(line, kMAX_LINE_LENGTH);
385 if (strncmp(line, entryPath.Data(), entryPath.Length()) == 0) {
386 // entry already exists, leave function after proper clean up
387 TString msg(" --- Entry '");
388 msg += entryPath + "' is already included in Taxi list file.";
389 Log(kHLTInterfaceModule, msg.Data());
396 // include entry to list
397 outfile.open(filename, ios_base::out | ios_base::app);
398 if (!outfile.is_open()) {
399 TString msg(" *** Unable to create Pendolino list file '");
400 msg += filename + "' for Taxi. Continueing without list update...";
401 Log(kHLTInterfaceModule, msg.Data());
404 // outfile.seekp(-1, ios::end);
406 outfile << "#HLT (Pendolino) - Run: " << fRunNumber << ", Time: " <<
407 ts.AsString() << endl;
408 outfile << entryPath.Data() << endl;
411 TString msg(" +++ Included missing entry '");
412 msg += entryPath + "' in Taxi list file.";
413 Log(kHLTInterfaceModule, msg.Data());
417 TString msg(" ~~~ Unable to open Pendolino list file '");
418 msg += filename + "' for Taxi. Creating new one.";
419 Log(kHLTInterfaceModule, msg.Data());
420 outfile.open(filename, ios_base::out);
422 if (outfile.is_open()) {
423 outfile << "# Automatic generated Taxi list." << endl;
424 outfile << "# It contains the OCDB entries required by the Pendolino."
425 << endl << "#" << endl;
426 outfile << "# !!! DON'T EDIT THIS FILE (if you don't know what you are doing) !!!"
428 outfile << "#HLT (Pendolino) - Run: " << fRunNumber << ", Time: " <<
429 ts.AsString() << endl;
430 outfile << entryPath.Data() << endl;
435 msg=" *** Unable to create Pendolino list file '";
436 msg += filename + "' for Taxi. Continueing without list update...";
437 Log(kHLTInterfaceModule, msg.Data());
445 void AliHLTPendolino::Log(const char* detector, const char* message) {
447 fpLogger->log(detector, message);
448 // refer data to a Pendolino Logger, which can take care of it
452 void AliHLTPendolino::RegisterPreprocessor(AliPreprocessor* preprocessor) {
453 // registers a PredictionProcessor
454 if (preprocessor == 0) {
455 Log(kHLTInterfaceModule,
456 " *** ERROR: Cannot register NULL pointer as PredictionProcessor.");
460 TString detector(preprocessor->GetName());
462 if (fPredictionProcessorMap.GetValue(detector.Data())) {
463 Log(kHLTInterfaceModule, " ~~~ Already registered PredictionProcessor '" +
464 detector + "'. Ignoring call.");
467 // store as AliPreprocessor* and make cast to AliHLTPredictionProcessorInterface*
468 // later, when accesing them.
469 fPredictionProcessorMap.Add(new TObjString(detector), preprocessor);
472 TString detector(preprocessor->GetName());
473 AliHLTPredictionProcessorInterface* predictProc = 0;
474 // UInt_t retVal = 0;
476 // TODO move this in seperated call outside RegisterPreprocessor(..)
477 // safety reason, since preprocessor is not completely generated yet
478 if (!preprocessor->ProcessDCS()) {
479 Log(kHLTInterfaceModule, " *** PredictionProcessor '" + detector +
480 "' not registered, because it will not process DCS values.");
483 Log(kHLTInterfaceModule, "Module Processes DCS values, Registering PredictionProc "
486 // don't use this check, if there are several PreProcs from one detector
487 // they will have all have different names
488 //if (GetDetPos(detector.Data()) < 0) {
489 // Log(kHLTInterfaceModule, " *** Invalid detector name: " + detector);
492 // Check if preprocessor is actually PredictionProcessor
495 predictProc = reinterpret_cast<AliHLTPredictionProcessorInterface*>
497 // Don't use dynamic_cast or C-style cast, they only rename the pointer/object,
498 // but don't import the extended members -> use reinterpret_cast. Maybe perform
499 // dynamic_cast check in other function, which is not called inside a C-tor
500 // of AliHLTPredictionProcessorInterface.
502 // ATTENTION: Don't call any functions of AliHLTPredictionProcessorInterface here
503 // the object has not been completely generated yet, only AliPreprocessor part
504 // is available. Call of these function should be performed in seperate call outside
505 // RegisterPreprocessor(..).)
507 } catch (std::bad_cast) {
508 // failed -> is not a AliHLTPredictionProcessorInterface implementation
509 // -> discarding call
510 Log(kHLTInterfaceModule, " *** Cannot register PredictionProcessor '" + detector +
511 "'. Does not implement the AliHLTPredictionProcessorInterface.");
513 } catch (std::exception& e) {
514 Log(kHLTInterfaceModule, " *** Exception in the registering of the PredictProc.");
517 if (fPredictionProcessorMap.GetValue(detector.Data())) {
518 Log(kHLTInterfaceModule, " ~~~ Already registered PredictionProcessor '" +
519 detector + "'. Ignoring call.");
523 fPredictionProcessorMap.Add(new TObjString(detector), predictProc);
528 UInt_t AliHLTPendolino::setToPredictMaking() {
529 // switches prdiction making on in all registered PredictioProcessors
532 // get an iterator for the map
533 TMapIter iter(&fPredictionProcessorMap, kIterForward);
534 AliHLTPredictionProcessorInterface* aPredict;
537 // get each key inside the map
538 while ((key = iter.Next())) {
539 TString detector = key->GetName();
542 // get value for the key
543 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*>
544 (fPredictionProcessorMap.GetValue(key));
547 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
549 "'. Does not implement the AliHLTPredictionProcessorInterface.");
552 // detector = aPredict->GetName();
554 if ((aPredict->ProcessDCS()) && (aPredict->makePrediction() == 0)) {
557 Log(kHLTInterfaceModule, " *** PredictionProcessor '" + detector
558 + "' does not allow DCS processing or failed to init prediction making.");
560 } catch (std::bad_cast) {
561 // failed -> is not a AliHLTPredictionProcessorInterface implementation
562 // -> discarding call
563 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
565 "'. Does not implement the AliHLTPredictionProcessorInterface.");
568 } catch (std::exception& e) {
569 Log(kHLTInterfaceModule, " *** Exception in call for makePrediction of "
578 Int_t AliHLTPendolino::setToPredictMaking(TString detector) {
579 // switches prediction making on in chosen PreditionProcessor
581 AliHLTPredictionProcessorInterface* aPredict = 0;
584 // get the value for the key
585 TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
588 Log(kHLTInterfaceModule, " *** No PredictionProcessor for '" +
589 detector + "' registered.");
590 return kHLTPendolinoModuleNotExisting;
593 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
596 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
598 "'. Does not implement the AliHLTPredictionProcessorInterface.");
599 return kHLTPendolinoNotPredictProc;
601 // detector = aPredict->GetName();
603 if (!((aPredict->ProcessDCS()) && (aPredict->makePrediction() == 0))) {
604 Log(kHLTInterfaceModule, " *** PredictionProcessor '" + detector +
605 "' does not allow DCS processing or failed to init prediction making.");
606 retVal = kHLTPendolinoNoDCS;
609 } catch (std::bad_cast) {
610 // failed -> is not a AliHLTPredictionProcessorInterface implementation
611 // -> discarding call
612 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
614 "'. Does not implement the AliHLTPredictionProcessorInterface.");
615 retVal = kHLTPendolinoBadCast;
617 } catch (std::exception& e) {
618 Log(kHLTInterfaceModule, " *** Exception in call for makePrediction of "
620 retVal = kHLTPendolinoException;
627 Int_t AliHLTPendolino::prepareDCSValues(TString detector, TMap* DCSValues) {
628 // function to prepare retrieved DCS values
630 AliHLTPredictionProcessorInterface* aPredict = 0;
633 // get the value for the key
634 TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
637 Log(kHLTInterfaceModule, " *** No PredictionProcessor for '" +
638 detector + "' registered.");
639 return kHLTPendolinoModuleNotExisting;
642 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
645 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
647 "'. Does not implement the AliHLTPredictionProcessorInterface.");
648 return kHLTPendolinoNotPredictProc;
651 retVal = aPredict->Process(DCSValues);
654 } catch (std::bad_cast) {
655 // failed -> is not a AliHLTPredictionProcessorInterface implementation
656 // -> discarding call
657 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
659 "'. Does not implement the AliHLTPredictionProcessorInterface.");
660 retVal = kHLTPendolinoBadCast;
662 } catch (std::exception& e) {
663 Log(kHLTInterfaceModule, " *** Exception in call prepareDCSValues of "
665 retVal = kHLTPendolinoException;
671 TMap* AliHLTPendolino::emulateDCSMap(TString detector, TString aliasName) {
672 // function to generate test data of given PredictionProcessor
674 AliHLTPredictionProcessorInterface* aPredict = 0;
677 // get the value for the key
678 TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
681 Log(kHLTInterfaceModule, " *** No PredictionProcessor for '" +
682 detector + "' registered.");
686 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
689 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
691 "'. Does not implement the AliHLTPredictionProcessorInterface.");
695 result = aPredict->produceTestData(aliasName);
698 } catch (std::bad_cast) {
699 // failed -> is not a AliHLTPredictionProcessorInterface implementation
700 // -> discarding call
701 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
703 "'. Does not implement the AliHLTPredictionProcessorInterface.");
705 } catch (std::exception& e) {
706 Log(kHLTInterfaceModule, " *** Exception in call emulateDCSMap of "
713 Int_t AliHLTPendolino::initPredictProc(TString detector, Int_t run,
714 UInt_t startTime, UInt_t endTime) {
715 // initializes given PredictionProcessor (defined by detector name)
717 AliHLTPredictionProcessorInterface* aPredict = 0;
720 // get the value for the key
721 TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
724 Log(kHLTInterfaceModule, " *** No PredictionProcessor for '" +
725 detector + "' registered.");
726 return kHLTPendolinoModuleNotExisting;
729 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
732 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
734 "'. Does not implement the AliHLTPredictionProcessorInterface.");
735 return kHLTPendolinoNotPredictProc;
738 // Initialize Prediction Processor
739 aPredict->Initialize(run, startTime, endTime);
741 } catch (std::bad_cast) {
742 // failed -> is not a AliHLTPredictionProcessorInterface implementation
743 // -> discarding call
744 Log(kHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
746 "'. Does not implement the AliHLTPredictionProcessorInterface.");
747 retVal = kHLTPendolinoBadCast;
749 } catch (std::exception& e) {
750 Log(kHLTInterfaceModule, " *** Exception in call prepareDCSValues of "
752 retVal = kHLTPendolinoException;
759 CONST_PROPERTY UInt_t AliHLTPendolino::GetStartTimeDCSQuery() {
763 CONST_PROPERTY UInt_t AliHLTPendolino::GetEndTimeDCSQuery() {