]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/pendolino/AliHLTPendolino.cxx
Additional libraries to link hltdimserver
[u/mrichter/AliRoot.git] / HLT / pendolino / AliHLTPendolino.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Sebastian Bablok <Sebastian.Bablok@ift.uib.no>        *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
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 //**************************************************************************
18
19 //  @file   AliHLTPendolino.cxx
20 //  @author Sebastian Bablok
21 //  @date   
22 //  @brief  
23 //  @note   maintained by Matthias.Richter@ift.uib.no
24
25 #include "AliHLTPendolino.h"
26
27 #include "AliHLTPredictionProcessorInterface.h"
28 #include "AliHLTPendolinoLogger.h"
29 #include "AliHLTPendolinoLoggerOStream.h"
30 #include "AliHLTLogging.h"
31
32 #include <AliCDBPath.h>
33 #include <AliCDBEntry.h>
34 #include <AliCDBManager.h>
35 #include <AliCDBStorage.h>
36 #include <AliPreprocessor.h>
37 #include <AliCDBId.h>
38
39 #include <TObjString.h>
40 #include <TTimeStamp.h>
41
42 #include <fstream>
43 #include <stdexcept>
44 #include <cstdlib>
45
46
47 using namespace std;
48
49 ClassImp(AliHLTPendolino)
50
51
52 /** Static string to define a local storage for the OCDB contact. */
53 const TString AliHLTPendolino::fgkLocalStorageDefine = "local://";
54
55 const char* AliHLTPendolino::fgkHLTInterfaceModule = "Pendolino-Core";
56
57 const TString AliHLTPendolino::fgkTaxiListBaseFolder = getenv("ALIHLT_T_HCDBDIR"); 
58 //"/opt/T-HCDB/lists/lists-taxi/";
59
60 const TString AliHLTPendolino::fgkTaxiListFolderName = "lists/lists-taxi/";
61
62 const TString AliHLTPendolino::fgkTaxiListPendolino = "Pendolino.list";
63
64 const Int_t AliHLTPendolino::fgkMaxLineLength = 256;
65
66 const Int_t AliHLTPendolino::fgkHLTPendolinoException = -10;
67
68 const Int_t AliHLTPendolino::fgkHLTPendolinoBadCast = -9;
69
70 const Int_t AliHLTPendolino::fgkHLTPendolinoNotPredictProc = -8;
71
72 const Int_t AliHLTPendolino::fgkHLTPendolinoModuleNotExisting = -7;
73
74 const Int_t AliHLTPendolino::fgkHLTPendolinoNoDCS = -6;
75
76 //const Int_t AliHLTPendolino::
77
78
79
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 {
87   // see header file for class documentation
88   // or
89   // refer to README to build package
90   // or
91   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
92
93         // C-tor of AliHLTPendolino
94         fHCDBPath = fgkLocalStorageDefine + HCDBbase;
95         if (logger == 0) {
96                 fpLogger = new AliHLTPendolinoLoggerOStream();
97                 fOwnLogger = kTRUE;
98         } else {
99                 fpLogger = logger;
100                 fOwnLogger = kFALSE;
101         }
102 }
103
104
105 AliHLTPendolino::~AliHLTPendolino() {
106         // D-tor of AliHLTPendolino
107         // clean up registered PredicitonProcs
108     TMapIter iter(&fPredictionProcessorMap, kIterForward);
109     AliHLTPredictionProcessorInterface* aPredict;
110     TObject* key = 0;
111
112     // get each key inside the map
113     while ((key = iter.Next())) {
114         TString detector = key->GetName();
115
116         try {
117             // get value for the key
118             aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*>
119                     (fPredictionProcessorMap.GetValue(key));
120
121             if (aPredict == 0) {
122                 Log(fgkHLTInterfaceModule, 
123                                                 " *** ERROR, cannot delete registered processor '"
124                                                 + detector + "'; does not seem to be a PredictionProcessor.");
125                 continue;
126             }
127                         Log(fgkHLTInterfaceModule, " ### [DEBUG] deleting PredictProc '" + 
128                                         detector + "'.");
129                         delete aPredict;
130         } catch (std::bad_cast) {
131             // failed -> is not a AliHLTPredictionProcessorInterface implementation
132             // -> discarding call
133             Log(fgkHLTInterfaceModule, " *** ERROR, cannot delete registered processor '"
134                     + detector + "'; does not seem to be a PredictionProcessor..");
135             continue;
136
137         } catch (std::exception& e) {
138             Log(fgkHLTInterfaceModule, 
139                                         " *** Exception in call for deleting PrecitionProcessor '"
140                     + detector + "'.");
141             continue;
142         }
143     }
144         Log(fgkHLTInterfaceModule, " ### [DEBUG] Deleting of PredictionProcessors finished.");
145
146         // clean up logger
147         if ((fOwnLogger) && (fpLogger != 0)) {
148                 delete fpLogger;
149         }
150         
151 }
152
153
154 // inherited virtual functions, maybe use them from base class
155 Bool_t AliHLTPendolino::Store(const AliCDBPath& path, TObject* object,
156                         AliCDBMetaData* metaData, Int_t validityStart, 
157                         Bool_t validityInfinite) {
158         // stores a entry in HCDB
159         Bool_t retVal = kFALSE;
160         Int_t startNumber = 0;
161         Int_t endNumber = 0;
162         AliCDBManager* man = 0; 
163         AliCDBStorage* localHCDB = 0;   
164
165         startNumber = ((fRunNumber - validityStart) <= 0) ? 0 : (fRunNumber - validityStart);
166         endNumber = (validityInfinite) ? AliCDBRunRange::Infinity() : fRunNumber;
167
168         man = AliCDBManager::Instance();
169     if (man == 0) {
170                 Log(fgkHLTInterfaceModule, " *** ERROR cannot obtain a CDB Manager reference.");
171                 return kFALSE;
172         }
173
174     // contact local storage (HCDB)
175     localHCDB = man->GetStorage(fHCDBPath.Data());
176     if (localHCDB == 0) {
177                 TString msg(" *** ERROR in initiating HCDB: ");
178                 msg += fHCDBPath;
179         Log(fgkHLTInterfaceModule, msg.Data());
180         man->DestroyActiveStorages();
181         return kFALSE;
182     }
183
184         // taken from AliShuttle
185         if (! dynamic_cast<TObjString*> (metaData->GetProperty("RunUsed(TObjString)"))) {
186         TObjString runUsed = Form("%d", fRunNumber);
187         metaData->SetProperty("RunUsed(TObjString)", runUsed.Clone());
188     }
189
190
191     // Version is set to current run, it will be used later to transfer data to Grid
192     // Why using current run number as version number ???
193         AliCDBId entryID(path, startNumber, endNumber, fRunNumber, -1);
194         
195         if (localHCDB->Put(object, entryID, metaData)) {
196                 retVal = kTRUE;
197         } else {
198                 TString msg(" *** Unable to store DCS data to HCDB: ");
199                 msg += entryID.ToString();
200         Log(fgkHLTInterfaceModule, msg.Data());
201     }
202
203         man->DestroyActiveStorages();
204
205         return retVal;
206 }
207
208
209 Bool_t AliHLTPendolino::StoreReferenceData(const AliCDBPath& path,
210                                            TObject* /*object*/, AliCDBMetaData* /*metaData*/) {
211         // Disabled Function inherited from interface
212         TString msg(" ~~~ PredictProc tries to store reference data to '" 
213                         + path.GetPath() + "'. Discarding call in Pendolino.");
214         Log(fgkHLTInterfaceModule, msg.Data());
215
216         return kFALSE;
217 }
218
219
220 Bool_t AliHLTPendolino::StoreReferenceFile(const char* detector,
221                         const char* localFile, const char* gridFileName) {
222     // Disabled Function inherited from interface
223     TString msg;
224         TString det(detector);
225         TString filename(localFile);
226         TString gridname(gridFileName);
227         msg = " ~~~ PredictProc (" + det + ") tries to store reference file (" +
228                         filename + ") to '" + gridname + 
229                         "'. Discarding call in Pendolino.";
230     Log(fgkHLTInterfaceModule, msg.Data());
231
232     return kFALSE;
233 }
234
235
236 Bool_t AliHLTPendolino::StoreRunMetadataFile(const char* localFile,
237                         const char* gridFileName) {
238     // Disabled Function inherited from interface
239     TString msg;
240
241     TString filename(localFile);
242     TString gridname(gridFileName);
243     msg = " ~~~ PredictProc tries to store 'run meta data' file (" +
244             filename + ") to '" + gridname + "'. Discarding call in Pendolino.";
245     Log(fgkHLTInterfaceModule, msg.Data());
246
247     return kFALSE;
248 }
249
250
251 const char* AliHLTPendolino::GetFile(Int_t system, const char* detector,
252                         const char* id, const char* source) {
253     // Disabled Function inherited from interface
254     TString msg;
255         TString det(detector);
256         TString filename(id);
257         TString src(source);
258         TString from(GetSystemName(system));
259         msg = " ~~~ PredictProc (" + det + ") requests file (" + filename + ") from '" 
260                         + src + "' at " + from + ". Discarding call in Pendolino.";
261         Log(fgkHLTInterfaceModule, msg.Data());
262
263         return NULL;
264 }
265
266 const char* AliHLTPendolino::GetTriggerConfiguration() {
267     // Disabled Function inherited from interface
268     TString msg;
269     msg = " ~~~ PredictProc tries to request Trigger configuration, this is disabled. Discarding call in Pendolino.";
270         Log(fgkHLTInterfaceModule, msg.Data());
271
272         return NULL;
273 }
274
275 const char* AliHLTPendolino::GetTriggerDetectorMask() {
276     // Disabled Function inherited from interface
277     TString msg;
278     msg = " ~~~ PredictProc tries to request Trigger configuration, this is disabled. Discarding call in Pendolino.";
279         Log(fgkHLTInterfaceModule, msg.Data());
280
281         return NULL;
282 }
283
284
285 TList* AliHLTPendolino::GetFileSources(Int_t system, const char* detector,
286                         const char* id) {
287         // Disabled Function inherited from interface
288     TString msg;
289     TString det(detector);
290     TString filename(id);
291     TString from(GetSystemName(system));
292     msg = " ~~~ PredictProc (" + det + ") requests file sources for (" + filename 
293                         + ") from '" + from + ". Discarding call in Pendolino.";
294     Log(fgkHLTInterfaceModule, msg.Data());
295
296     return NULL;
297 }
298
299
300 TList* AliHLTPendolino::GetFileIDs(Int_t system, const char* detector,
301                         const char* source) {
302     // Disabled Function inherited from interface
303     TString msg;
304     TString det(detector);
305     TString filename(source);
306     TString from(GetSystemName(system));
307     msg = " ~~~ PredictProc (" + det + ") requests file IDs for (" + filename
308             + ") from '" + from + ". Discarding call in Pendolino.";
309     Log(fgkHLTInterfaceModule, msg.Data());
310
311     return NULL;
312 }
313
314
315 const char* AliHLTPendolino::GetRunParameter(const char* /*lbEntry*/) {
316         // getter for run parameter
317                 
318 // TODO
319 // maybe using a parameter file, where these settings are stored at start up by
320 // the starting script and a dedicated class read and stores its content.
321
322         Log(fgkHLTInterfaceModule, 
323                         " ### GetRunParameter are not defined, yet. Feature will be available soon.");
324         return NULL;
325 }
326
327
328 Bool_t AliHLTPendolino::GetHLTStatus() {
329         // getter for HLT status
330         // since this is the Pendolino -> always true
331         return kTRUE;
332 }
333
334
335 AliCDBEntry* AliHLTPendolino::GetFromOCDB(const char* detector,
336                         const AliCDBPath& path) {
337         // fetches entry from HCDB
338         AliCDBManager *man = AliCDBManager::Instance();
339         
340         if (man == 0) {
341                 TString msg(" *** ERROR, cannot obtain a CDB Manager reference for: ");
342                 msg += detector;
343                 Log(fgkHLTInterfaceModule, msg.Data());
344                 return NULL;
345         }
346
347         AliCDBStorage *hcdb = man->GetStorage(fHCDBPath.Data());
348         if (hcdb == 0) {
349                 TString msg(" *** ERROR, cannot acquire HCDB storage (");
350                 msg += fHCDBPath + ") for fetching data for Pendolino.";
351                 Log(fgkHLTInterfaceModule, msg.Data());
352                 return NULL;
353         }
354         
355         AliCDBEntry* entry=NULL;
356         try {
357           // exceptions for the loading of OCDB objects have been introduced in r61012 on
358           // Feb 20 2013. This allows to reduce this function to try and catch of AliCDBManager::Get
359           entry=hcdb->Get(path, fRunNumber);
360         }
361         catch (...) {
362           // for now we just ignore the exception and return NULL
363         }
364         return entry;
365         
366 /*
367         AliCDBEntry* entry = 0;
368         try {
369                 entry = dynamic_cast<AliCDBEntry*> (hcdb->Get(path, fRunNumber));
370         } catch (std::bad_cast) {
371                 TString msg(" *** ERROR, bad cast of HCDB entry (");
372                 msg += path.GetPath() + ") after fetching from HCDB.";
373                 Log(fgkHLTInterfaceModule, msg.Data());
374                 return NULL;
375         }
376         return entry;
377 */
378
379 }
380
381
382 Bool_t AliHLTPendolino::IncludeAliCDBEntryInList(const TString& entryPath) {
383         // includes entry in Taxi list (objects to be fetched from OCDB)
384         Bool_t bRet = kFALSE;
385         ifstream infile;
386         ofstream outfile;
387         TString filename;
388         TTimeStamp ts;
389
390         filename = fgkTaxiListBaseFolder + "/" + fgkTaxiListFolderName + 
391                         fgkTaxiListPendolino;
392         Log(fgkHLTInterfaceModule, filename + " [DEBUG] filename");
393
394         infile.open(filename, ios_base::in);
395         if (infile.is_open()) {
396                 char line[fgkMaxLineLength];
397
398                 while (!infile.eof()) {
399                         infile.getline(line, fgkMaxLineLength);
400                         if (strncmp(line, entryPath.Data(), entryPath.Length()) == 0) {
401                                         // entry already exists, leave function after proper clean up
402                                 TString msg(" --- Entry '");
403                                 msg += entryPath + "' is already included in Taxi list file.";
404                                 Log(fgkHLTInterfaceModule, msg.Data()); 
405                                 infile.close();
406                                 return kTRUE;
407                         }
408                 }
409                 infile.close();
410                 
411                 // include entry to list
412                 outfile.open(filename, ios_base::out | ios_base::app);
413                 if (!outfile.is_open()) {
414                         TString msg(" *** Unable to create Pendolino list file '");
415                         msg += filename + "' for Taxi. Continueing without list update...";
416                         Log(fgkHLTInterfaceModule, msg.Data());
417                         return kFALSE;
418                 }
419 //              outfile.seekp(-1, ios::end);
420                 outfile << endl;
421                 outfile << "#HLT (Pendolino) - Run: " << fRunNumber << ", Time: " <<
422                                 ts.AsString() << endl;
423                 outfile << entryPath.Data() << endl;
424                 outfile.close();
425
426                 TString msg(" +++ Included missing entry '");
427                 msg += entryPath + "' in Taxi list file.";
428                 Log(fgkHLTInterfaceModule, msg.Data());
429                 bRet = kTRUE;
430                 
431         } else {
432                 TString msg(" ~~~ Unable to open Pendolino list file '");
433                 msg += filename + "' for Taxi. Creating new one.";
434                 Log(fgkHLTInterfaceModule, msg.Data());
435                 outfile.open(filename, ios_base::out);
436                 
437                 if (outfile.is_open()) {
438                         outfile << "# Automatic generated Taxi list." << endl;
439                         outfile << "# It contains the OCDB entries required by the Pendolino." 
440                                         << endl << "#" << endl;
441                         outfile << "#    !!! DON'T EDIT THIS FILE (if you don't know what you are doing) !!!"
442                                         << endl << endl;
443                         outfile << "#HLT (Pendolino) - Run: " << fRunNumber << ", Time: " << 
444                                         ts.AsString() << endl;
445                         outfile << entryPath.Data() << endl;
446                         outfile.close();
447                         bRet = kTRUE;
448                 
449                 } else {
450                         msg=" *** Unable to create Pendolino list file '";
451                         msg += filename + "' for Taxi. Continueing without list update...";
452                         Log(fgkHLTInterfaceModule, msg.Data());
453                 }       
454         }
455         
456         return bRet;
457 }
458
459
460 void AliHLTPendolino::Log(const char* detector, const char* message) {
461         // logging function
462         if (fpLogger) fpLogger->log(detector, message);
463         // refer data to a Pendolino Logger, which can take care of it
464 }
465
466
467 void AliHLTPendolino::RegisterPreprocessor(AliPreprocessor* preprocessor) {
468         // registers a PredictionProcessor
469         if (preprocessor == 0) {
470                 Log(fgkHLTInterfaceModule, 
471                                 " *** ERROR: Cannot register NULL pointer as PredictionProcessor.");
472                 return; 
473         }
474
475     TString detector(preprocessor->GetName());
476
477     if (fPredictionProcessorMap.GetValue(detector.Data())) {
478         Log(fgkHLTInterfaceModule, " ~~~ Already registered PredictionProcessor '" +
479                 detector + "'. Ignoring call.");
480         return;
481     }
482         // store as AliPreprocessor* and make cast to AliHLTPredictionProcessorInterface*
483         // later, when accesing them.
484     fPredictionProcessorMap.Add(new TObjString(detector), preprocessor);
485
486 /*      
487         TString detector(preprocessor->GetName());
488         AliHLTPredictionProcessorInterface* predictProc = 0;
489 //      UInt_t retVal = 0;
490
491         // TODO move this in seperated call outside RegisterPreprocessor(..)
492         // safety reason, since preprocessor is not completely generated yet
493         if (!preprocessor->ProcessDCS()) {
494                 Log(fgkHLTInterfaceModule, " *** PredictionProcessor '" + detector +
495                                 "' not registered, because it will not process DCS values.");
496                 return;
497         }
498         Log(fgkHLTInterfaceModule, "Module Processes DCS values, Registering PredictionProc " 
499                         + detector);
500         
501         // don't use this check, if there are several PreProcs from one detector
502         // they will have all have different names
503         //if (GetDetPos(detector.Data()) < 0) {
504         //      Log(fgkHLTInterfaceModule, "   *** Invalid detector name: " + detector);
505         //}
506
507         // Check if preprocessor is actually PredictionProcessor
508         try {
509
510                 predictProc = reinterpret_cast<AliHLTPredictionProcessorInterface*> 
511                                 (preprocessor);
512 // Don't use dynamic_cast or C-style cast, they only rename the pointer/object, 
513 // but don't import the extended members -> use reinterpret_cast. Maybe perform 
514 // dynamic_cast check in  other function, which is not called inside a C-tor 
515 // of AliHLTPredictionProcessorInterface.
516                 
517 // ATTENTION: Don't call any functions of AliHLTPredictionProcessorInterface here
518 // the object has not been completely generated yet, only AliPreprocessor part
519 // is available. Call of these function should be performed in seperate call outside
520 // RegisterPreprocessor(..).)
521
522         } catch (std::bad_cast) { 
523                 // failed -> is not a AliHLTPredictionProcessorInterface implementation
524                 // -> discarding call
525                 Log(fgkHLTInterfaceModule, " *** Cannot register PredictionProcessor '" + detector +
526                                 "'. Does not implement the AliHLTPredictionProcessorInterface.");
527                 return;
528         } catch (std::exception& e) {
529                 Log(fgkHLTInterfaceModule, " *** Exception in the registering of the PredictProc.");            
530         }
531
532         if (fPredictionProcessorMap.GetValue(detector.Data())) {
533                 Log(fgkHLTInterfaceModule, " ~~~ Already registered PredictionProcessor '" +
534                                 detector + "'. Ignoring call.");
535                 return;
536         }
537
538         fPredictionProcessorMap.Add(new TObjString(detector), predictProc);
539 */
540 }
541
542
543 UInt_t AliHLTPendolino::SetToPredictMaking() {
544         // switches prdiction making on in all registered PredictioProcessors
545         UInt_t retVal = 0;
546
547         // get an iterator for the map
548         TMapIter iter(&fPredictionProcessorMap, kIterForward);
549         AliHLTPredictionProcessorInterface* aPredict;
550         TObject* key = 0;       
551         
552         // get each key inside the map
553         while ((key = iter.Next())) {
554                 TString detector = key->GetName();
555                 
556                 try {
557                         // get value for the key
558                         aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*>
559                                         (fPredictionProcessorMap.GetValue(key));
560                 
561                         if (aPredict == 0) {
562                                 Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
563                                                 + detector +
564                                                 "'. Does not implement the AliHLTPredictionProcessorInterface.");
565                                 continue;
566                         }
567 //                      detector = aPredict->GetName();
568                         
569                         if ((aPredict->ProcessDCS()) && (aPredict->makePrediction() == 0)) {
570                                 retVal++;
571                         } else {
572                                 Log(fgkHLTInterfaceModule, " *** PredictionProcessor '" + detector
573                                                 + "' does not allow DCS processing or failed to init prediction making.");
574                         }
575                 } catch (std::bad_cast) {
576                 // failed -> is not a AliHLTPredictionProcessorInterface implementation
577             // -> discarding call
578                 Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '" 
579                                         + detector +
580                     "'. Does not implement the AliHLTPredictionProcessorInterface.");
581                 continue;
582
583                 } catch (std::exception& e) {
584                         Log(fgkHLTInterfaceModule, " *** Exception in call for makePrediction of " 
585                                         + detector + ".");
586                         continue;
587                 }
588         }
589         return retVal;
590 }
591
592
593 Int_t AliHLTPendolino::setToPredictMaking(TString detector) {
594         // switches prediction making on in chosen PreditionProcessor
595         Int_t retVal = 0;
596         AliHLTPredictionProcessorInterface* aPredict = 0;
597         
598         try {
599                 // get the value for the key
600                 TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
601
602                 if (object == 0) {
603                         Log(fgkHLTInterfaceModule, " *** No PredictionProcessor for '" +
604                                         detector + "' registered.");
605                         return fgkHLTPendolinoModuleNotExisting;
606                 }
607                                 
608                 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
609
610                 if (aPredict == 0) {
611                         Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
612                                         + detector +
613                                         "'. Does not implement the AliHLTPredictionProcessorInterface.");
614                         return fgkHLTPendolinoNotPredictProc;
615                 }
616 //            detector = aPredict->GetName();
617
618                 if (!((aPredict->ProcessDCS()) && (aPredict->makePrediction() == 0))) {
619                         Log(fgkHLTInterfaceModule, " *** PredictionProcessor '" + detector +
620                                         "' does not allow DCS processing or failed to init prediction making.");
621                         retVal = fgkHLTPendolinoNoDCS;
622                 }
623                 
624         } catch (std::bad_cast) {
625                 // failed -> is not a AliHLTPredictionProcessorInterface implementation
626                 // -> discarding call
627                 Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
628                                 + detector +
629                                 "'. Does not implement the AliHLTPredictionProcessorInterface.");
630                 retVal = fgkHLTPendolinoBadCast;
631
632         } catch (std::exception& e) {
633                 Log(fgkHLTInterfaceModule, " *** Exception in call for makePrediction of "
634                                 + detector + ".");
635                 retVal = fgkHLTPendolinoException;
636     }
637         
638     return retVal;
639 }
640
641
642 Int_t AliHLTPendolino::PrepareDCSValues(TString detector, TMap* DCSValues) {
643         // function to prepare retrieved DCS values
644         Int_t retVal = 0;
645         AliHLTPredictionProcessorInterface* aPredict = 0;
646
647         try {
648                 // get the value for the key
649                 TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
650                 
651                 if (object == 0) {
652                         Log(fgkHLTInterfaceModule, " *** No PredictionProcessor for '" +
653                                         detector + "' registered.");
654                         return fgkHLTPendolinoModuleNotExisting;
655                 }
656                                 
657                 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
658
659                 if (aPredict == 0) {
660                         Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
661                                         + detector +
662                                         "'. Does not implement the AliHLTPredictionProcessorInterface.");
663                         return fgkHLTPendolinoNotPredictProc;
664                 }
665
666                 retVal = aPredict->Process(DCSValues);
667
668
669         } catch (std::bad_cast) {
670                 // failed -> is not a AliHLTPredictionProcessorInterface implementation
671                 // -> discarding call
672                 Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
673                                 + detector +
674                                 "'. Does not implement the AliHLTPredictionProcessorInterface.");
675                 retVal = fgkHLTPendolinoBadCast;
676
677         } catch (std::exception& e) {
678                 Log(fgkHLTInterfaceModule, " *** Exception in call prepareDCSValues of "
679                                 + detector + ".");
680                 retVal = fgkHLTPendolinoException;
681         }
682         
683         return retVal;  
684 }
685
686 TMap* AliHLTPendolino::EmulateDCSMap(TString detector, TString aliasName) {
687         // function to generate test data of given PredictionProcessor
688         TMap* result = NULL;
689         AliHLTPredictionProcessorInterface* aPredict = 0;
690
691     try {
692         // get the value for the key
693         TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
694
695         if (object == 0) {
696             Log(fgkHLTInterfaceModule, " *** No PredictionProcessor for '" +
697                     detector + "' registered.");
698             return result;
699         }
700
701         aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
702
703         if (aPredict == 0) {
704             Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
705                     + detector +
706                     "'. Does not implement the AliHLTPredictionProcessorInterface.");
707             return result;
708         }
709
710         result = aPredict->produceTestData(aliasName);
711
712
713     } catch (std::bad_cast) {
714         // failed -> is not a AliHLTPredictionProcessorInterface implementation
715         // -> discarding call
716         Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
717                 + detector +
718                 "'. Does not implement the AliHLTPredictionProcessorInterface.");
719
720     } catch (std::exception& e) {
721         Log(fgkHLTInterfaceModule, " *** Exception in call emulateDCSMap of "
722                 + detector + ".");
723     }
724         return result;
725 }
726
727
728 Int_t AliHLTPendolino::initPredictProc(TString detector, Int_t run, 
729                         UInt_t startTime, UInt_t endTime) {
730         // initializes given PredictionProcessor (defined by detector name)
731     Int_t retVal = 0;
732     AliHLTPredictionProcessorInterface* aPredict = 0;
733
734     try {
735         // get the value for the key
736         TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
737
738         if (object == 0) {
739             Log(fgkHLTInterfaceModule, " *** No PredictionProcessor for '" +
740                     detector + "' registered.");
741             return fgkHLTPendolinoModuleNotExisting;
742         }
743
744         aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
745
746         if (aPredict == 0) {
747             Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
748                     + detector +
749                     "'. Does not implement the AliHLTPredictionProcessorInterface.");
750             return fgkHLTPendolinoNotPredictProc;
751         }
752                 
753                 // Initialize Prediction Processor
754                 aPredict->Initialize(run, startTime, endTime);
755
756     } catch (std::bad_cast) {
757         // failed -> is not a AliHLTPredictionProcessorInterface implementation
758         // -> discarding call
759         Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
760                 + detector +
761                 "'. Does not implement the AliHLTPredictionProcessorInterface.");
762         retVal = fgkHLTPendolinoBadCast;
763
764     } catch (std::exception& e) {
765         Log(fgkHLTInterfaceModule, " *** Exception in call prepareDCSValues of "
766                 + detector + ".");
767         retVal = fgkHLTPendolinoException;
768     }
769
770     return retVal;
771 }
772
773
774 UInt_t AliHLTPendolino::GetStartTimeDCSQuery()
775 {
776         return fStartTime;
777 }
778
779 UInt_t AliHLTPendolino::GetEndTimeDCSQuery()
780 {
781         return fEndTime;
782 }
783
784 void AliHLTPendolino::Log(const char* name , const char* message, UInt_t level)
785 {
786   // overloaded function of the shuttle interface
787   // translate into HLT log message
788   AliHLTLogging log;
789   AliHLTComponentLogSeverity severity=kHLTLogInfo;
790   switch (level) {
791   case 1: severity=kHLTLogBenchmark; break;
792   case 2: severity=kHLTLogDebug; break;
793   case 3: severity=kHLTLogInfo; break;
794   case 4: severity=kHLTLogWarning; break;
795   default: severity=kHLTLogError;
796   }
797   log.LoggingVarargs(severity, "AliHLTPendolino", name , __FILE__ , __LINE__ , message);
798 }
799
800 // this global object is not for use, it just makes sure that
801 // AliHLTPendolino can be instantiated. In case of missing virtual
802 // functions a compilation error will indicate potential problems in
803 // the pendolino macros
804 AliHLTPendolino gAliHLTPendolino(0,"");