]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTMisc.h
7ddb8435327d3ff385ba95162292a368f93e5cbc
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTMisc.h
1 //-*- Mode: C++ -*-
2 // $Id$
3
4 #ifndef ALIHLTMISC_H
5 #define ALIHLTMISC_H
6 //* This file is property of and copyright by the ALICE HLT Project        * 
7 //* ALICE Experiment at CERN, All rights reserved.                         *
8 //* See cxx source for full Copyright notice                               */
9
10 /// @file   AliHLTMisc.h
11 /// @author Matthias Richter
12 /// @date   
13 /// @brief  Definition of various glue functions implemented in dynamically
14 ///         loaded libraries
15
16 #include "TObject.h"
17 #include "AliHLTStdIncludes.h"
18 #include "AliHLTDataTypes.h"
19 #include "AliHLTLogging.h"
20 #include "TClass.h"
21 #include "TSystem.h"
22
23 class AliCDBManager;
24 class AliCDBEntry;
25 class AliRawReader;
26 class AliHLTComponentDataType;
27 class AliHLTGlobalTriggerDecision;
28
29 class AliHLTMisc : public TObject {
30  public:
31   AliHLTMisc();
32   ~AliHLTMisc();
33
34   template<class T>
35   static T* LoadInstance(const T* dummy, const char* classname, const char* library);
36
37   static AliHLTMisc& Instance();
38
39   virtual int InitCDB(const char* cdbpath);
40
41   virtual int SetCDBRunNo(int runNo);
42
43   virtual AliCDBEntry* LoadOCDBEntry(const char* path, int runNo=-1, int version = -1, int subVersion = -1);
44
45   virtual TObject* ExtractObject(AliCDBEntry* entry);
46
47   virtual int InitMagneticField() const;
48
49   virtual AliHLTUInt64_t GetTriggerMask(AliRawReader* rawReader) const;
50
51   virtual Double_t GetBz();
52   virtual Double_t GetBz(const Double_t *r);
53   virtual void GetBxByBz(const Double_t r[3], Double_t b[3]);
54
55   virtual const TClass* IsAliESDHLTDecision() const;
56   virtual int Copy(const AliHLTGlobalTriggerDecision* pDecision, TObject* pESDHLTDecision) const;
57
58  private:
59   static AliHLTMisc* fgInstance;
60
61   ClassDef(AliHLTMisc, 0)
62 };
63
64 #define ALIHLTMISC_LIBRARY "libHLTrec.so"
65 #define ALIHLTMISC_INIT_CDB "AliHLTMiscInitCDB"
66 #define ALIHLTMISC_SET_CDB_RUNNO "AliHLTMiscSetCDBRunNo"
67
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71
72   /**
73    * Init the CDB access for the running instance.
74    * The method is used from the C wrapper interface utilized by the  on-line
75    * framework. The path of the (H)CDB is set to the specified path.<br>
76    * When running from AliRoot, the CDB path is set in the startup of the
77    * reconstruction.<br>
78    * If cdbpath is nil or empty and the CDB is not already initialized, the
79    * CDB storage is set to local://$ALICE_ROOT/OCDB and the run no to 0.
80    * @param cdbpath     path to the CDB
81    * @return neg. error code if failed
82    * @note function implemented in libHLTrec
83    */
84   int AliHLTMiscInitCDB(const char* cdbpath);
85   typedef int (*AliHLTMiscInitCDB_t)(const char* cdbpath);
86
87   /**
88    * Init the Run no for the CDB access.
89    * @param runNo       the run no
90    * @return neg. error code if failed
91    * @note function implemented in libHLTrec
92    */
93   int AliHLTMiscSetCDBRunNo(int runNo);
94   typedef int (*AliHLTMiscSetCDBRunNo_t)(int runNo);
95
96 #ifdef __cplusplus
97 }
98 #endif
99
100 template<class T>
101 T* AliHLTMisc::LoadInstance(const T* /*t*/, const char* classname, const char* library)
102 {
103   // see header file for function documentation
104   int iLibResult=0;
105   T* pInstance=NULL;
106   AliHLTLogging log;
107   TClass* pCl=NULL;
108   ROOT::NewFunc_t pNewFunc=NULL;
109   do {
110     pCl=TClass::GetClass(classname);
111   } while (!pCl && (iLibResult=gSystem->Load(library))==0);
112   if (iLibResult>=0) {
113     if (pCl && (pNewFunc=pCl->GetNew())!=NULL) {
114       void* p=(*pNewFunc)(NULL);
115       if (p) {
116         pInstance=reinterpret_cast<T*>(p);
117         if (!pInstance) {
118           log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "type cast (%s) to instance failed", classname);
119         }
120       } else {
121         log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not create instance of type %s from class descriptor", classname);
122       }
123     } else {
124       log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not find class descriptor %s", classname);
125     }
126   } else {
127     log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not load %s library in order to find class descriptor %s", library, classname);
128   }
129   return pInstance;
130 }
131
132 // direct printout of data type struct
133 ostream  &operator<<(ostream &str, const AliHLTComponentDataType&);
134
135 #endif //ALIHLTMISC_H