]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/pendolino/AliHLTPendolino.cxx
typo corrected, leading to compile errors on some systems
[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         if (hcdb->GetLatestVersion(path.GetPath(), fRunNumber)<0) {
356                 return NULL;
357         }
358
359         return hcdb->Get(path, fRunNumber);
360
361         
362 /*
363         AliCDBEntry* entry = 0;
364         try {
365                 entry = dynamic_cast<AliCDBEntry*> (hcdb->Get(path, fRunNumber));
366         } catch (std::bad_cast) {
367                 TString msg(" *** ERROR, bad cast of HCDB entry (");
368                 msg += path.GetPath() + ") after fetching from HCDB.";
369                 Log(fgkHLTInterfaceModule, msg.Data());
370                 return NULL;
371         }
372         return entry;
373 */
374
375 }
376
377
378 Bool_t AliHLTPendolino::IncludeAliCDBEntryInList(const TString& entryPath) {
379         // includes entry in Taxi list (objects to be fetched from OCDB)
380         Bool_t bRet = kFALSE;
381         ifstream infile;
382         ofstream outfile;
383         TString filename;
384         TTimeStamp ts;
385
386         filename = fgkTaxiListBaseFolder + "/" + fgkTaxiListFolderName + 
387                         fgkTaxiListPendolino;
388         Log(fgkHLTInterfaceModule, filename + " [DEBUG] filename");
389
390         infile.open(filename, ios_base::in);
391         if (infile.is_open()) {
392                 char line[fgkMaxLineLength];
393
394                 while (!infile.eof()) {
395                         infile.getline(line, fgkMaxLineLength);
396                         if (strncmp(line, entryPath.Data(), entryPath.Length()) == 0) {
397                                         // entry already exists, leave function after proper clean up
398                                 TString msg(" --- Entry '");
399                                 msg += entryPath + "' is already included in Taxi list file.";
400                                 Log(fgkHLTInterfaceModule, msg.Data()); 
401                                 infile.close();
402                                 return kTRUE;
403                         }
404                 }
405                 infile.close();
406                 
407                 // include entry to list
408                 outfile.open(filename, ios_base::out | ios_base::app);
409                 if (!outfile.is_open()) {
410                         TString msg(" *** Unable to create Pendolino list file '");
411                         msg += filename + "' for Taxi. Continueing without list update...";
412                         Log(fgkHLTInterfaceModule, msg.Data());
413                         return kFALSE;
414                 }
415 //              outfile.seekp(-1, ios::end);
416                 outfile << endl;
417                 outfile << "#HLT (Pendolino) - Run: " << fRunNumber << ", Time: " <<
418                                 ts.AsString() << endl;
419                 outfile << entryPath.Data() << endl;
420                 outfile.close();
421
422                 TString msg(" +++ Included missing entry '");
423                 msg += entryPath + "' in Taxi list file.";
424                 Log(fgkHLTInterfaceModule, msg.Data());
425                 bRet = kTRUE;
426                 
427         } else {
428                 TString msg(" ~~~ Unable to open Pendolino list file '");
429                 msg += filename + "' for Taxi. Creating new one.";
430                 Log(fgkHLTInterfaceModule, msg.Data());
431                 outfile.open(filename, ios_base::out);
432                 
433                 if (outfile.is_open()) {
434                         outfile << "# Automatic generated Taxi list." << endl;
435                         outfile << "# It contains the OCDB entries required by the Pendolino." 
436                                         << endl << "#" << endl;
437                         outfile << "#    !!! DON'T EDIT THIS FILE (if you don't know what you are doing) !!!"
438                                         << endl << endl;
439                         outfile << "#HLT (Pendolino) - Run: " << fRunNumber << ", Time: " << 
440                                         ts.AsString() << endl;
441                         outfile << entryPath.Data() << endl;
442                         outfile.close();
443                         bRet = kTRUE;
444                 
445                 } else {
446                         msg=" *** Unable to create Pendolino list file '";
447                         msg += filename + "' for Taxi. Continueing without list update...";
448                         Log(fgkHLTInterfaceModule, msg.Data());
449                 }       
450         }
451         
452         return bRet;
453 }
454
455
456 void AliHLTPendolino::Log(const char* detector, const char* message) {
457         // logging function
458         if (fpLogger) fpLogger->log(detector, message);
459         // refer data to a Pendolino Logger, which can take care of it
460 }
461
462
463 void AliHLTPendolino::RegisterPreprocessor(AliPreprocessor* preprocessor) {
464         // registers a PredictionProcessor
465         if (preprocessor == 0) {
466                 Log(fgkHLTInterfaceModule, 
467                                 " *** ERROR: Cannot register NULL pointer as PredictionProcessor.");
468                 return; 
469         }
470
471     TString detector(preprocessor->GetName());
472
473     if (fPredictionProcessorMap.GetValue(detector.Data())) {
474         Log(fgkHLTInterfaceModule, " ~~~ Already registered PredictionProcessor '" +
475                 detector + "'. Ignoring call.");
476         return;
477     }
478         // store as AliPreprocessor* and make cast to AliHLTPredictionProcessorInterface*
479         // later, when accesing them.
480     fPredictionProcessorMap.Add(new TObjString(detector), preprocessor);
481
482 /*      
483         TString detector(preprocessor->GetName());
484         AliHLTPredictionProcessorInterface* predictProc = 0;
485 //      UInt_t retVal = 0;
486
487         // TODO move this in seperated call outside RegisterPreprocessor(..)
488         // safety reason, since preprocessor is not completely generated yet
489         if (!preprocessor->ProcessDCS()) {
490                 Log(fgkHLTInterfaceModule, " *** PredictionProcessor '" + detector +
491                                 "' not registered, because it will not process DCS values.");
492                 return;
493         }
494         Log(fgkHLTInterfaceModule, "Module Processes DCS values, Registering PredictionProc " 
495                         + detector);
496         
497         // don't use this check, if there are several PreProcs from one detector
498         // they will have all have different names
499         //if (GetDetPos(detector.Data()) < 0) {
500         //      Log(fgkHLTInterfaceModule, "   *** Invalid detector name: " + detector);
501         //}
502
503         // Check if preprocessor is actually PredictionProcessor
504         try {
505
506                 predictProc = reinterpret_cast<AliHLTPredictionProcessorInterface*> 
507                                 (preprocessor);
508 // Don't use dynamic_cast or C-style cast, they only rename the pointer/object, 
509 // but don't import the extended members -> use reinterpret_cast. Maybe perform 
510 // dynamic_cast check in  other function, which is not called inside a C-tor 
511 // of AliHLTPredictionProcessorInterface.
512                 
513 // ATTENTION: Don't call any functions of AliHLTPredictionProcessorInterface here
514 // the object has not been completely generated yet, only AliPreprocessor part
515 // is available. Call of these function should be performed in seperate call outside
516 // RegisterPreprocessor(..).)
517
518         } catch (std::bad_cast) { 
519                 // failed -> is not a AliHLTPredictionProcessorInterface implementation
520                 // -> discarding call
521                 Log(fgkHLTInterfaceModule, " *** Cannot register PredictionProcessor '" + detector +
522                                 "'. Does not implement the AliHLTPredictionProcessorInterface.");
523                 return;
524         } catch (std::exception& e) {
525                 Log(fgkHLTInterfaceModule, " *** Exception in the registering of the PredictProc.");            
526         }
527
528         if (fPredictionProcessorMap.GetValue(detector.Data())) {
529                 Log(fgkHLTInterfaceModule, " ~~~ Already registered PredictionProcessor '" +
530                                 detector + "'. Ignoring call.");
531                 return;
532         }
533
534         fPredictionProcessorMap.Add(new TObjString(detector), predictProc);
535 */
536 }
537
538
539 UInt_t AliHLTPendolino::SetToPredictMaking() {
540         // switches prdiction making on in all registered PredictioProcessors
541         UInt_t retVal = 0;
542
543         // get an iterator for the map
544         TMapIter iter(&fPredictionProcessorMap, kIterForward);
545         AliHLTPredictionProcessorInterface* aPredict;
546         TObject* key = 0;       
547         
548         // get each key inside the map
549         while ((key = iter.Next())) {
550                 TString detector = key->GetName();
551                 
552                 try {
553                         // get value for the key
554                         aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*>
555                                         (fPredictionProcessorMap.GetValue(key));
556                 
557                         if (aPredict == 0) {
558                                 Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
559                                                 + detector +
560                                                 "'. Does not implement the AliHLTPredictionProcessorInterface.");
561                                 continue;
562                         }
563 //                      detector = aPredict->GetName();
564                         
565                         if ((aPredict->ProcessDCS()) && (aPredict->makePrediction() == 0)) {
566                                 retVal++;
567                         } else {
568                                 Log(fgkHLTInterfaceModule, " *** PredictionProcessor '" + detector
569                                                 + "' does not allow DCS processing or failed to init prediction making.");
570                         }
571                 } catch (std::bad_cast) {
572                 // failed -> is not a AliHLTPredictionProcessorInterface implementation
573             // -> discarding call
574                 Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '" 
575                                         + detector +
576                     "'. Does not implement the AliHLTPredictionProcessorInterface.");
577                 continue;
578
579                 } catch (std::exception& e) {
580                         Log(fgkHLTInterfaceModule, " *** Exception in call for makePrediction of " 
581                                         + detector + ".");
582                         continue;
583                 }
584         }
585         return retVal;
586 }
587
588
589 Int_t AliHLTPendolino::setToPredictMaking(TString detector) {
590         // switches prediction making on in chosen PreditionProcessor
591         Int_t retVal = 0;
592         AliHLTPredictionProcessorInterface* aPredict = 0;
593         
594         try {
595                 // get the value for the key
596                 TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
597
598                 if (object == 0) {
599                         Log(fgkHLTInterfaceModule, " *** No PredictionProcessor for '" +
600                                         detector + "' registered.");
601                         return fgkHLTPendolinoModuleNotExisting;
602                 }
603                                 
604                 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
605
606                 if (aPredict == 0) {
607                         Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
608                                         + detector +
609                                         "'. Does not implement the AliHLTPredictionProcessorInterface.");
610                         return fgkHLTPendolinoNotPredictProc;
611                 }
612 //            detector = aPredict->GetName();
613
614                 if (!((aPredict->ProcessDCS()) && (aPredict->makePrediction() == 0))) {
615                         Log(fgkHLTInterfaceModule, " *** PredictionProcessor '" + detector +
616                                         "' does not allow DCS processing or failed to init prediction making.");
617                         retVal = fgkHLTPendolinoNoDCS;
618                 }
619                 
620         } catch (std::bad_cast) {
621                 // failed -> is not a AliHLTPredictionProcessorInterface implementation
622                 // -> discarding call
623                 Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
624                                 + detector +
625                                 "'. Does not implement the AliHLTPredictionProcessorInterface.");
626                 retVal = fgkHLTPendolinoBadCast;
627
628         } catch (std::exception& e) {
629                 Log(fgkHLTInterfaceModule, " *** Exception in call for makePrediction of "
630                                 + detector + ".");
631                 retVal = fgkHLTPendolinoException;
632     }
633         
634     return retVal;
635 }
636
637
638 Int_t AliHLTPendolino::PrepareDCSValues(TString detector, TMap* DCSValues) {
639         // function to prepare retrieved DCS values
640         Int_t retVal = 0;
641         AliHLTPredictionProcessorInterface* aPredict = 0;
642
643         try {
644                 // get the value for the key
645                 TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
646                 
647                 if (object == 0) {
648                         Log(fgkHLTInterfaceModule, " *** No PredictionProcessor for '" +
649                                         detector + "' registered.");
650                         return fgkHLTPendolinoModuleNotExisting;
651                 }
652                                 
653                 aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
654
655                 if (aPredict == 0) {
656                         Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
657                                         + detector +
658                                         "'. Does not implement the AliHLTPredictionProcessorInterface.");
659                         return fgkHLTPendolinoNotPredictProc;
660                 }
661
662                 retVal = aPredict->Process(DCSValues);
663
664
665         } catch (std::bad_cast) {
666                 // failed -> is not a AliHLTPredictionProcessorInterface implementation
667                 // -> discarding call
668                 Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
669                                 + detector +
670                                 "'. Does not implement the AliHLTPredictionProcessorInterface.");
671                 retVal = fgkHLTPendolinoBadCast;
672
673         } catch (std::exception& e) {
674                 Log(fgkHLTInterfaceModule, " *** Exception in call prepareDCSValues of "
675                                 + detector + ".");
676                 retVal = fgkHLTPendolinoException;
677         }
678         
679         return retVal;  
680 }
681
682 TMap* AliHLTPendolino::EmulateDCSMap(TString detector, TString aliasName) {
683         // function to generate test data of given PredictionProcessor
684         TMap* result = NULL;
685         AliHLTPredictionProcessorInterface* aPredict = 0;
686
687     try {
688         // get the value for the key
689         TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
690
691         if (object == 0) {
692             Log(fgkHLTInterfaceModule, " *** No PredictionProcessor for '" +
693                     detector + "' registered.");
694             return result;
695         }
696
697         aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
698
699         if (aPredict == 0) {
700             Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
701                     + detector +
702                     "'. Does not implement the AliHLTPredictionProcessorInterface.");
703             return result;
704         }
705
706         result = aPredict->produceTestData(aliasName);
707
708
709     } catch (std::bad_cast) {
710         // failed -> is not a AliHLTPredictionProcessorInterface implementation
711         // -> discarding call
712         Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
713                 + detector +
714                 "'. Does not implement the AliHLTPredictionProcessorInterface.");
715
716     } catch (std::exception& e) {
717         Log(fgkHLTInterfaceModule, " *** Exception in call emulateDCSMap of "
718                 + detector + ".");
719     }
720         return result;
721 }
722
723
724 Int_t AliHLTPendolino::initPredictProc(TString detector, Int_t run, 
725                         UInt_t startTime, UInt_t endTime) {
726         // initializes given PredictionProcessor (defined by detector name)
727     Int_t retVal = 0;
728     AliHLTPredictionProcessorInterface* aPredict = 0;
729
730     try {
731         // get the value for the key
732         TObject* object = fPredictionProcessorMap.GetValue(detector.Data());
733
734         if (object == 0) {
735             Log(fgkHLTInterfaceModule, " *** No PredictionProcessor for '" +
736                     detector + "' registered.");
737             return fgkHLTPendolinoModuleNotExisting;
738         }
739
740         aPredict = dynamic_cast<AliHLTPredictionProcessorInterface*> (object);
741
742         if (aPredict == 0) {
743             Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
744                     + detector +
745                     "'. Does not implement the AliHLTPredictionProcessorInterface.");
746             return fgkHLTPendolinoNotPredictProc;
747         }
748                 
749                 // Initialize Prediction Processor
750                 aPredict->Initialize(run, startTime, endTime);
751
752     } catch (std::bad_cast) {
753         // failed -> is not a AliHLTPredictionProcessorInterface implementation
754         // -> discarding call
755         Log(fgkHLTInterfaceModule, " *** Cannot use PredictionProcessor '"
756                 + detector +
757                 "'. Does not implement the AliHLTPredictionProcessorInterface.");
758         retVal = fgkHLTPendolinoBadCast;
759
760     } catch (std::exception& e) {
761         Log(fgkHLTInterfaceModule, " *** Exception in call prepareDCSValues of "
762                 + detector + ".");
763         retVal = fgkHLTPendolinoException;
764     }
765
766     return retVal;
767 }
768
769
770 #ifdef SHUTTLE_PRE_REV29388_INTERFACE
771 const UInt_t AliHLTPendolino::GetStartTimeDCSQuery()
772 #else
773 UInt_t AliHLTPendolino::GetStartTimeDCSQuery()
774 #endif
775 {
776         return fStartTime;
777 }
778
779 #ifdef SHUTTLE_PRE_REV29388_INTERFACE
780 const UInt_t AliHLTPendolino::GetEndTimeDCSQuery()
781 #else
782 UInt_t AliHLTPendolino::GetEndTimeDCSQuery()
783 #endif
784 {
785         return fEndTime;
786 }
787
788 void AliHLTPendolino::Log(const char* name , const char* message, UInt_t level)
789 {
790   // overloaded function of the shuttle interface
791   // translate into HLT log message
792   AliHLTLogging log;
793   AliHLTComponentLogSeverity severity=kHLTLogInfo;
794   switch (level) {
795   case 1: severity=kHLTLogBenchmark; break;
796   case 2: severity=kHLTLogDebug; break;
797   case 3: severity=kHLTLogInfo; break;
798   case 4: severity=kHLTLogWarning; break;
799   default: severity=kHLTLogError;
800   }
801   log.LoggingVarargs(severity, "AliHLTPendolino", name , __FILE__ , __LINE__ , message);
802 }
803
804 // this global object is not for use, it just makes sure that
805 // AliHLTPendolino can be instantiated. In case of missing virtual
806 // functions a compilation error will indicate potential problems in
807 // the pendolino macros
808 AliHLTPendolino gAliHLTPendolino(0,"");