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