]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTMisc.h
ALIROOT-5600 - skip non-participating detector modules
[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                          * 
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 struct AliHLTComponentDataType;
27 class AliHLTGlobalTriggerDecision;
28 class TMap;
29
30 /**
31  * @class AliHLTMisc
32  * Abstract interface of various glue functions implemented in dynamically
33  * loaded libraries.
34  *
35  * The HLT base library is independent from AliRoot and binds AliRoot
36  * functionality via dynamic libraries. The provided methods can be used
37  * from any module library without introducing additional dependencies.
38  */
39 class AliHLTMisc : public TObject {
40  public:
41   AliHLTMisc();
42   ~AliHLTMisc();
43
44   /// dynamically load a class from a library
45   template<class T>
46   static T* LoadInstance(const T* dummy, const char* classname, const char* library=NULL);
47
48   /// the global instance of the interface implementation
49   static AliHLTMisc& Instance();
50
51   /// init the CDB patch
52   virtual int InitCDB(const char* cdbpath);
53
54   /// init the CDB run number
55   virtual int SetCDBRunNo(int runNo);
56   /// get the run number from CDB manager
57   virtual int GetCDBRunNo() const;
58
59   /// Load an OCDB object
60   virtual AliCDBEntry* LoadOCDBEntry(const char* path, int runNo=-1) const;
61
62   // Extract the TObject instance from the CDB object
63   virtual TObject* ExtractObject(AliCDBEntry* entry) const;
64
65   /// check the availability of the OCDB entry descriptions in the TMap
66   ///  key : complete OCDB path of the entry
67   ///  value : auxiliary object - short description
68   virtual int CheckOCDBEntries(const TMap* const pMap) const;
69
70   /// init the global magnetic field
71   virtual int InitMagneticField() const;
72
73   /// extract the triggermask from the rawreader
74   /// NOTE: not to be used in the online system
75   virtual AliHLTTriggerMask_t GetTriggerMask(AliRawReader* rawReader) const;
76
77   /// extract the timestamp from the rawreader
78   /// NOTE: not to be used in the online system, use AliHLTComponent::GetTimeStamp()
79   virtual AliHLTUInt32_t GetTimeStamp(AliRawReader* rawReader) const;
80
81   /// extract the event type from the rawreader
82   /// NOTE: not to be used in the online system
83   virtual AliHLTUInt32_t GetEventType(AliRawReader* rawReader) const;
84
85   virtual Double_t GetBz();
86   virtual Double_t GetBz(const Double_t *r);
87   virtual void GetBxByBz(const Double_t r[3], Double_t b[3]);
88
89   virtual const TClass* IsAliESDHLTDecision() const;
90   
91   using TObject::Copy;  // Needed since the declaration of AliHLTMisc::Copy below is ambiguous to the compiler.
92   
93   virtual int Copy(const AliHLTGlobalTriggerDecision* pDecision, TObject* pESDHLTDecision) const;
94
95   /// Init streamer info from ocdb entry
96   virtual int InitStreamerInfos(const char* ocdbEntry) const;
97
98   /// Init streamer info for a collection of classes
99   virtual int InitStreamerInfos(TObjArray* pSchemas) const;
100
101   /// merge streamer info entries from source array to target array
102   /// add all existing infos if not existing in the current one, or having
103   /// different class version
104   /// return 1 if target array has been changed
105   virtual int MergeStreamerInfo(TObjArray* tgt, const TObjArray* src, int iVerbosity=0) const;
106
107   /// set the online mode flag of AliESDtrack
108   virtual void SetAliESDtrackOnlineModeFlag(bool mode) const;
109
110   /// get status of the online mode flag of AliESDtrack
111   virtual bool GetAliESDtrackOnlineModeFlag() const;
112
113   /// guard class for switching offline software to online mode
114   class AliOnlineGuard {
115   public:
116     AliOnlineGuard(bool mode=true);
117     ~AliOnlineGuard();
118
119   private:
120     bool fMode; //! old value to be restored
121   };
122
123  private:
124   static AliHLTMisc* fgInstance; //! global instance
125
126   ClassDef(AliHLTMisc, 0)
127 };
128
129 #define ALIHLTMISC_LIBRARY "libHLTrec.so"
130 #define ALIHLTMISC_INIT_CDB "AliHLTMiscInitCDB"
131 #define ALIHLTMISC_SET_CDB_RUNNO "AliHLTMiscSetCDBRunNo"
132
133 #ifdef __cplusplus
134 extern "C" {
135 #endif
136
137   /**
138    * Init the CDB access for the running instance.
139    * The method is used from the C wrapper interface utilized by the  on-line
140    * framework. The path of the (H)CDB is set to the specified path.<br>
141    * When running from AliRoot, the CDB path is set in the startup of the
142    * reconstruction.<br>
143    * If cdbpath is nil or empty and the CDB is not already initialized, the
144    * CDB storage is set to local://$ALICE_ROOT/OCDB and the run no to 0.
145    * @param cdbpath     path to the CDB
146    * @return neg. error code if failed
147    * @note function implemented in libHLTrec
148    */
149   int AliHLTMiscInitCDB(const char* cdbpath);
150   typedef int (*AliHLTMiscInitCDB_t)(const char* cdbpath);
151
152   /**
153    * Init the Run no for the CDB access.
154    * @param runNo       the run no
155    * @return neg. error code if failed
156    * @note function implemented in libHLTrec
157    */
158   int AliHLTMiscSetCDBRunNo(int runNo);
159   typedef int (*AliHLTMiscSetCDBRunNo_t)(int runNo);
160
161 #ifdef __cplusplus
162 }
163 #endif
164
165 template<class T>
166 T* AliHLTMisc::LoadInstance(const T* /*t*/, const char* classname, const char* library)
167 {
168   /// dynamically load a class from a library
169   int iLibResult=0;
170   T* pInstance=NULL;
171   AliHLTLogging log;
172   TClass* pCl=NULL;
173   ROOT::NewFunc_t pNewFunc=NULL;
174   do {
175     pCl=TClass::GetClass(classname);
176   } while (!pCl && library!=NULL && (iLibResult=gSystem->Load(library))==0);
177   if (iLibResult>=0) {
178     if (pCl && (pNewFunc=pCl->GetNew())!=NULL) {
179       void* p=(*pNewFunc)(NULL);
180       if (p) {
181         pInstance=reinterpret_cast<T*>(p);
182       } else {
183         log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not create instance of type %s from class descriptor", classname);
184       }
185     } else {
186       log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not find TClass descriptor %s", classname);
187     }
188   } else {
189     log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not load %s library in order to find class descriptor %s", library, classname);
190   }
191   return pInstance;
192 }
193
194 // direct printout of data type struct
195 ostream  &operator<<(ostream &str, const AliHLTComponentDataType&);
196
197 #endif //ALIHLTMISC_H