]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTMisc.h
coveritiy
[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 class TMap;
29
30 class AliHLTMisc : public TObject {
31  public:
32   AliHLTMisc();
33   ~AliHLTMisc();
34
35   template<class T>
36   static T* LoadInstance(const T* dummy, const char* classname, const char* library=NULL);
37
38   static AliHLTMisc& Instance();
39
40   virtual int InitCDB(const char* cdbpath);
41
42   virtual int SetCDBRunNo(int runNo);
43   virtual int GetCDBRunNo() const;
44
45   /// Load an OCDB object
46   virtual AliCDBEntry* LoadOCDBEntry(const char* path, int runNo=-1, int version = -1, int subVersion = -1) const;
47
48   // Extract the TObject instance from the CDB object
49   virtual TObject* ExtractObject(AliCDBEntry* entry) const;
50
51   /// check the availability of the OCDB entry descriptions in the TMap
52   ///  key : complete OCDB path of the entry
53   ///  value : auxiliary object - short description
54   virtual int CheckOCDBEntries(const TMap* const pMap) const;
55
56   virtual int InitMagneticField() const;
57
58   /// extract the triggermask from the rawreader
59   /// NOTE: not to be used in the online system
60   virtual AliHLTUInt64_t GetTriggerMask(AliRawReader* rawReader) const;
61
62   /// extract the timestamp from the rawreader
63   /// NOTE: not to be used in the online system, use AliHLTComponent::GetTimeStamp()
64   virtual AliHLTUInt32_t GetTimeStamp(AliRawReader* rawReader) const;
65
66   /// extract the event type from the rawreader
67   /// NOTE: not to be used in the online system
68   virtual AliHLTUInt32_t GetEventType(AliRawReader* rawReader) const;
69
70   virtual Double_t GetBz();
71   virtual Double_t GetBz(const Double_t *r);
72   virtual void GetBxByBz(const Double_t r[3], Double_t b[3]);
73
74   virtual const TClass* IsAliESDHLTDecision() const;
75   virtual int Copy(const AliHLTGlobalTriggerDecision* pDecision, TObject* pESDHLTDecision) const;
76
77   /// Init streamer info from ocdb entry
78   virtual int InitStreamerInfos(const char* ocdbEntry) const;
79
80   /// Init streamer info for a collection of classes
81   virtual int InitStreamerInfos(TObjArray* pSchemas) const;
82
83  private:
84   static AliHLTMisc* fgInstance;
85
86   ClassDef(AliHLTMisc, 0)
87 };
88
89 #define ALIHLTMISC_LIBRARY "libHLTrec.so"
90 #define ALIHLTMISC_INIT_CDB "AliHLTMiscInitCDB"
91 #define ALIHLTMISC_SET_CDB_RUNNO "AliHLTMiscSetCDBRunNo"
92
93 #ifdef __cplusplus
94 extern "C" {
95 #endif
96
97   /**
98    * Init the CDB access for the running instance.
99    * The method is used from the C wrapper interface utilized by the  on-line
100    * framework. The path of the (H)CDB is set to the specified path.<br>
101    * When running from AliRoot, the CDB path is set in the startup of the
102    * reconstruction.<br>
103    * If cdbpath is nil or empty and the CDB is not already initialized, the
104    * CDB storage is set to local://$ALICE_ROOT/OCDB and the run no to 0.
105    * @param cdbpath     path to the CDB
106    * @return neg. error code if failed
107    * @note function implemented in libHLTrec
108    */
109   int AliHLTMiscInitCDB(const char* cdbpath);
110   typedef int (*AliHLTMiscInitCDB_t)(const char* cdbpath);
111
112   /**
113    * Init the Run no for the CDB access.
114    * @param runNo       the run no
115    * @return neg. error code if failed
116    * @note function implemented in libHLTrec
117    */
118   int AliHLTMiscSetCDBRunNo(int runNo);
119   typedef int (*AliHLTMiscSetCDBRunNo_t)(int runNo);
120
121 #ifdef __cplusplus
122 }
123 #endif
124
125 template<class T>
126 T* AliHLTMisc::LoadInstance(const T* /*t*/, const char* classname, const char* library)
127 {
128   // see header file for function documentation
129   int iLibResult=0;
130   T* pInstance=NULL;
131   AliHLTLogging log;
132   TClass* pCl=NULL;
133   ROOT::NewFunc_t pNewFunc=NULL;
134   do {
135     pCl=TClass::GetClass(classname);
136   } while (!pCl && library!=NULL && (iLibResult=gSystem->Load(library))==0);
137   if (iLibResult>=0) {
138     if (pCl && (pNewFunc=pCl->GetNew())!=NULL) {
139       void* p=(*pNewFunc)(NULL);
140       if (p) {
141         pInstance=reinterpret_cast<T*>(p);
142       } else {
143         log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not create instance of type %s from class descriptor", classname);
144       }
145     } else {
146       log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not find TClass descriptor %s", classname);
147     }
148   } else {
149     log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not load %s library in order to find class descriptor %s", library, classname);
150   }
151   return pInstance;
152 }
153
154 // direct printout of data type struct
155 ostream  &operator<<(ostream &str, const AliHLTComponentDataType&);
156
157 #endif //ALIHLTMISC_H