From 2b545cdd954e2cd5330c66dc3c0ef545025fdb72 Mon Sep 17 00:00:00 2001 From: richterm Date: Tue, 7 Jul 2009 16:58:58 +0000 Subject: [PATCH 1/1] Adding an abstract interface which provides OCDB functionality within the libHLTbase and the implementation in libHLTrec. Keeps the libHLTbase free from AliRoot dependencies. The AliHLTMisc methods can be extended later for other purposes. --- HLT/BASE/AliHLTMisc.cxx | 113 ++++++++++++++++++++++++ HLT/BASE/AliHLTMisc.h | 43 ++++++++-- HLT/BASE/HLTbaseLinkDef.h | 1 + HLT/libHLTbase.pkg | 2 +- HLT/libHLTrec.pkg | 2 +- HLT/rec/AliHLTMisc.cxx | 61 ------------- HLT/rec/AliHLTMiscImplementation.cxx | 123 +++++++++++++++++++++++++++ HLT/rec/AliHLTMiscImplementation.h | 36 ++++++++ 8 files changed, 311 insertions(+), 70 deletions(-) create mode 100644 HLT/BASE/AliHLTMisc.cxx delete mode 100644 HLT/rec/AliHLTMisc.cxx create mode 100644 HLT/rec/AliHLTMiscImplementation.cxx create mode 100644 HLT/rec/AliHLTMiscImplementation.h diff --git a/HLT/BASE/AliHLTMisc.cxx b/HLT/BASE/AliHLTMisc.cxx new file mode 100644 index 00000000000..9b7477fe7da --- /dev/null +++ b/HLT/BASE/AliHLTMisc.cxx @@ -0,0 +1,113 @@ +// $Id$ + +//************************************************************************** +//* This file is property of and copyright by the ALICE HLT Project * +//* ALICE Experiment at CERN, All rights reserved. * +//* * +//* Primary Authors: Matthias Richter * +//* for The ALICE HLT Project. * +//* * +//* Permission to use, copy, modify and distribute this software and its * +//* documentation strictly for non-commercial purposes is hereby granted * +//* without fee, provided that the above copyright notice appears in all * +//* copies and that both the copyright notice and this permission notice * +//* appear in the supporting documentation. The authors make no claims * +//* about the suitability of this software for any purpose. It is * +//* provided "as is" without express or implied warranty. * +//************************************************************************** + +/// @file AliHLTMisc.h +/// @author Matthias Richter +/// @date 2009-07-07 +/// @brief Definition of various glue functions implemented in dynamically +/// loaded libraries + +#include "AliHLTMisc.h" +#include "AliHLTLogging.h" +#include "TClass.h" +#include "TSystem.h" + +/** ROOT macro for the implementation of ROOT specific class methods */ +ClassImp(AliHLTMisc); + +AliHLTMisc::AliHLTMisc() +{ + // see header file for function documentation +} + +AliHLTMisc::~AliHLTMisc() +{ + // see header file for function documentation +} + +AliHLTMisc* AliHLTMisc::fgInstance=NULL; + +template +T* AliHLTMisc::LoadInstance(const T* /*t*/, const char* classname, const char* library) +{ + // see header file for function documentation + int iLibResult=0; + T* pInstance=NULL; + AliHLTLogging log; + TClass* pCl=NULL; + ROOT::NewFunc_t pNewFunc=NULL; + do { + pCl=TClass::GetClass(classname); + } while (!pCl && (iLibResult=gSystem->Load(library))==0); + if (iLibResult>=0) { + if (pCl && (pNewFunc=pCl->GetNew())!=NULL) { + void* p=(*pNewFunc)(NULL); + if (p) { + pInstance=reinterpret_cast(p); + if (!pInstance) { + log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "type cast (%s) to instance failed", classname); + } + } else { + log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not create instance of type %s from class descriptor", classname); + } + } else { + log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not find class descriptor %s", classname); + } + } else { + log.Logging(kHLTLogError, "AliHLTMisc::LoadInstance", "HLT Analysis", "can not load %s library in order to find class descriptor %s", library, classname); + } + return pInstance; +} + +AliHLTMisc& AliHLTMisc::Instance() +{ + // see header file for function documentation + if (!fgInstance) { + fgInstance=LoadInstance((AliHLTMisc*)NULL, "AliHLTMiscImplementation", ALIHLTMISC_LIBRARY); + } + if (!fgInstance) { + AliHLTLogging log; + fgInstance=new AliHLTMisc; + log.Logging(kHLTLogError, "AliHLTMisc::Instance", "HLT Analysis", "falling back to default AliHLTMisc instance"); + } + return *fgInstance; +} + +int AliHLTMisc::InitCDB(const char* /*cdbpath*/) +{ + // see header file for function documentation + return -EFAULT; +} + +int AliHLTMisc::SetCDBRunNo(int /*runNo*/) +{ + // see header file for function documentation + return -EFAULT; +} + +AliCDBEntry* AliHLTMisc::LoadOCDBEntry(const char* /*path*/, int /*runNo*/, int /*version*/, int /*subVersion*/) +{ + // see header file for function documentation + return NULL; +} + +TObject* AliHLTMisc::ExtractObject(AliCDBEntry* /*entry*/) +{ + // see header file for function documentation + return NULL; +} diff --git a/HLT/BASE/AliHLTMisc.h b/HLT/BASE/AliHLTMisc.h index 7c38a71c697..b86b0eed265 100644 --- a/HLT/BASE/AliHLTMisc.h +++ b/HLT/BASE/AliHLTMisc.h @@ -1,4 +1,5 @@ -// @(#) $Id$ +//-*- Mode: C++ -*- +// $Id$ #ifndef ALIHLTMISC_H #define ALIHLTMISC_H @@ -6,12 +7,40 @@ //* ALICE Experiment at CERN, All rights reserved. * //* See cxx source for full Copyright notice */ -/** @file AliHLTMisc.h - @author Matthias Richter - @date - @brief Definition of various glue functions implemented in dynamically - loaded libraries -*/ +/// @file AliHLTMisc.h +/// @author Matthias Richter +/// @date +/// @brief Definition of various glue functions implemented in dynamically +/// loaded libraries + +#include "TObject.h" + +class AliCDBManager; +class AliCDBEntry; + +class AliHLTMisc : public TObject { + public: + AliHLTMisc(); + ~AliHLTMisc(); + + template + static T* LoadInstance(const T* dummy, const char* classname, const char* library); + + static AliHLTMisc& Instance(); + + virtual int InitCDB(const char* cdbpath); + + virtual int SetCDBRunNo(int runNo); + + virtual AliCDBEntry* LoadOCDBEntry(const char* path, int runNo=-1, int version = -1, int subVersion = -1); + + virtual TObject* ExtractObject(AliCDBEntry* entry); + + private: + static AliHLTMisc* fgInstance; + + ClassDef(AliHLTMisc, 0) +}; #define ALIHLTMISC_LIBRARY "libHLTrec.so" #define ALIHLTMISC_INIT_CDB "AliHLTMiscInitCDB" diff --git a/HLT/BASE/HLTbaseLinkDef.h b/HLT/BASE/HLTbaseLinkDef.h index 3b69a1d7960..e2f2dc2df05 100644 --- a/HLT/BASE/HLTbaseLinkDef.h +++ b/HLT/BASE/HLTbaseLinkDef.h @@ -51,6 +51,7 @@ #pragma link C++ class AliHLTTriggerMenuItem+; #pragma link C++ class AliHLTTriggerMenuSymbol+; #pragma link C++ class AliHLTRunStatistics+; +#pragma link C++ class AliHLTMisc+; #pragma link C++ struct AliHLTComponentDataType+; #pragma link C++ struct AliHLTEventDDL+; #endif diff --git a/HLT/libHLTbase.pkg b/HLT/libHLTbase.pkg index c808e39c395..2f71242c8d7 100644 --- a/HLT/libHLTbase.pkg +++ b/HLT/libHLTbase.pkg @@ -5,6 +5,7 @@ include $(MODDIR)/hlt.conf CLASS_HDRS:= AliHLTComponent.h \ AliHLTComponentHandler.h \ + AliHLTMisc.h \ AliHLTSystem.h \ AliHLTReconstructorBase.h \ AliHLTPluginBase.h \ @@ -62,7 +63,6 @@ MODULE_HDRS:= $(CLASS_HDRS) \ AliHLTDataTypes.h \ AliHLTExternalTrackParam.h \ AliHLTCommonCDBEntries.h \ - AliHLTMisc.h \ AliHLT_C_Component_WrapperInterface.h \ AliHLTDefinitions.h \ AliHLTStdIncludes.h diff --git a/HLT/libHLTrec.pkg b/HLT/libHLTrec.pkg index 7c5e28e83a5..1e4d8e81fd7 100644 --- a/HLT/libHLTrec.pkg +++ b/HLT/libHLTrec.pkg @@ -9,10 +9,10 @@ CLASS_HDRS:= AliHLTReconstructor.h \ AliHLTEsdManagerImplementation.h \ AliHLTDAQInterfaceImplementation.h \ AliHLTOUTDigitReader.h \ + AliHLTMiscImplementation.h \ AliHLTOUTRawReader.h MODULE_SRCS:= AliHLTDynamicAliLog.cxx \ - AliHLTMisc.cxx \ $(CLASS_HDRS:.h=.cxx) MODULE_HDRS:= $(CLASS_HDRS) diff --git a/HLT/rec/AliHLTMisc.cxx b/HLT/rec/AliHLTMisc.cxx deleted file mode 100644 index 5d002c5d223..00000000000 --- a/HLT/rec/AliHLTMisc.cxx +++ /dev/null @@ -1,61 +0,0 @@ -// $Id$ - -/************************************************************************** - * This file is property of and copyright by the ALICE HLT Project * - * ALICE Experiment at CERN, All rights reserved. * - * * - * Primary Authors: Matthias Richter * - * for The ALICE HLT Project. * - * * - * Permission to use, copy, modify and distribute this software and its * - * documentation strictly for non-commercial purposes is hereby granted * - * without fee, provided that the above copyright notice appears in all * - * copies and that both the copyright notice and this permission notice * - * appear in the supporting documentation. The authors make no claims * - * about the suitability of this software for any purpose. It is * - * provided "as is" without express or implied warranty. * - **************************************************************************/ - -/** @file AliHLTMisc.cxx - @author Matthias Richter - @date - @brief Miscellaneous methods for the HLT AliRoot integration -*/ - -#include "AliHLTMisc.h" -#include "AliHLTLogging.h" -#include "AliCDBManager.h" - -int AliHLTMiscInitCDB(const char* cdbpath) -{ - int iResult=0; - AliCDBManager* pCDB = AliCDBManager::Instance(); - AliHLTLogging log; - if (!pCDB) { - log.Logging(kHLTLogError, "InitCDB", "CDB handling", "Could not get CDB instance"); - } else { - if (cdbpath && cdbpath[0]!=0) { - pCDB->SetDefaultStorage(cdbpath); - log.Logging(kHLTLogDebug, "InitCDB", "CDB handling", "CDB instance 0x%x", pCDB); - } else if (!pCDB->IsDefaultStorageSet()) { - const char* cdbUri="local://$ALICE_ROOT/OCDB"; - pCDB->SetDefaultStorage(cdbUri); - pCDB->SetRun(0); - log.Logging(kHLTLogInfo, "InitCDB", "CDB handling", "set default URI: %s", cdbUri); - } - } - return iResult; -} - -int AliHLTMiscSetCDBRunNo(int runNo) -{ - int iResult=0; - AliCDBManager* pCDB = AliCDBManager::Instance(); - AliHLTLogging log; - if (!pCDB) { - log.Logging(kHLTLogError, "InitCDB", "CDB handling", "Could not get CDB instance"); - } else { - pCDB->SetRun(runNo); - } - return iResult; -} diff --git a/HLT/rec/AliHLTMiscImplementation.cxx b/HLT/rec/AliHLTMiscImplementation.cxx new file mode 100644 index 00000000000..e61687d1768 --- /dev/null +++ b/HLT/rec/AliHLTMiscImplementation.cxx @@ -0,0 +1,123 @@ +// $Id$ + +//************************************************************************** +//* This file is property of and copyright by the ALICE HLT Project * +//* ALICE Experiment at CERN, All rights reserved. * +//* * +//* Primary Authors: Matthias Richter * +//* for The ALICE HLT Project. * +//* * +//* Permission to use, copy, modify and distribute this software and its * +//* documentation strictly for non-commercial purposes is hereby granted * +//* without fee, provided that the above copyright notice appears in all * +//* copies and that both the copyright notice and this permission notice * +//* appear in the supporting documentation. The authors make no claims * +//* about the suitability of this software for any purpose. It is * +//* provided "as is" without express or implied warranty. * +//************************************************************************** + +/// @file AliHLTMisc.cxx +/// @author Matthias Richter +/// @date +/// @brief Miscellaneous methods for the HLT AliRoot integration + +#include "AliHLTMiscImplementation.h" +#include "AliHLTLogging.h" +#include "AliCDBManager.h" +#include "AliCDBEntry.h" + +/** ROOT macro for the implementation of ROOT specific class methods */ +ClassImp(AliHLTMiscImplementation); + +AliHLTMiscImplementation::AliHLTMiscImplementation() +{ +} + +AliHLTMiscImplementation::~AliHLTMiscImplementation() +{ + // see header file for function documentation +} + +int AliHLTMiscImplementation::InitCDB(const char* cdbpath) +{ + // see header file for function documentation + int iResult=0; + AliCDBManager* pCDB = AliCDBManager::Instance(); + AliHLTLogging log; + if (!pCDB) { + log.Logging(kHLTLogError, "InitCDB", "CDB handling", "Could not get CDB instance"); + } else { + if (cdbpath && cdbpath[0]!=0) { + pCDB->SetDefaultStorage(cdbpath); + log.Logging(kHLTLogDebug, "InitCDB", "CDB handling", "CDB instance 0x%x", pCDB); + } else if (!pCDB->IsDefaultStorageSet()) { + const char* cdbUri="local://$ALICE_ROOT/OCDB"; + pCDB->SetDefaultStorage(cdbUri); + pCDB->SetRun(0); + log.Logging(kHLTLogInfo, "InitCDB", "CDB handling", "set default URI: %s", cdbUri); + } + } + return iResult; +} + +int AliHLTMiscImplementation::SetCDBRunNo(int runNo) +{ + // see header file for function documentation + int iResult=0; + AliCDBManager* pCDB = AliCDBManager::Instance(); + AliHLTLogging log; + if (!pCDB) { + log.Logging(kHLTLogError, "InitCDB", "CDB handling", "Could not get CDB instance"); + } else { + pCDB->SetRun(runNo); + } + return iResult; +} + +AliCDBEntry* AliHLTMiscImplementation::LoadOCDBEntry(const char* path, int runNo, int version, int subVersion) +{ + // see header file for function documentation + AliCDBManager::Instance()->UnloadFromCache(path); + return AliCDBManager::Instance()->Get(path, runNo, version, subVersion); +} + +TObject* AliHLTMiscImplementation::ExtractObject(AliCDBEntry* entry) +{ + // see header file for function documentation + if (!entry) return NULL; + return entry->GetObject(); +} + +int AliHLTMiscInitCDB(const char* cdbpath) +{ + int iResult=0; + AliCDBManager* pCDB = AliCDBManager::Instance(); + AliHLTLogging log; + if (!pCDB) { + log.Logging(kHLTLogError, "InitCDB", "CDB handling", "Could not get CDB instance"); + } else { + if (cdbpath && cdbpath[0]!=0) { + pCDB->SetDefaultStorage(cdbpath); + log.Logging(kHLTLogDebug, "InitCDB", "CDB handling", "CDB instance 0x%x", pCDB); + } else if (!pCDB->IsDefaultStorageSet()) { + const char* cdbUri="local://$ALICE_ROOT/OCDB"; + pCDB->SetDefaultStorage(cdbUri); + pCDB->SetRun(0); + log.Logging(kHLTLogInfo, "InitCDB", "CDB handling", "set default URI: %s", cdbUri); + } + } + return iResult; +} + +int AliHLTMiscSetCDBRunNo(int runNo) +{ + int iResult=0; + AliCDBManager* pCDB = AliCDBManager::Instance(); + AliHLTLogging log; + if (!pCDB) { + log.Logging(kHLTLogError, "InitCDB", "CDB handling", "Could not get CDB instance"); + } else { + pCDB->SetRun(runNo); + } + return iResult; +} diff --git a/HLT/rec/AliHLTMiscImplementation.h b/HLT/rec/AliHLTMiscImplementation.h new file mode 100644 index 00000000000..9cb1f67a172 --- /dev/null +++ b/HLT/rec/AliHLTMiscImplementation.h @@ -0,0 +1,36 @@ +//-*- Mode: C++ -*- +// $Id$ + +#ifndef ALIHLTMISCIMPLEMENTATION_H +#define ALIHLTMISCIMPLEMENTATION_H_H +//* This file is property of and copyright by the ALICE HLT Project * +//* ALICE Experiment at CERN, All rights reserved. * +//* See cxx source for full Copyright notice */ + +/// @file AliHLTMiscImplementation.h +/// @author Matthias Richter +/// @date 2009-07-07 +/// @brief Implementation of various glue functions implemented in dynamically +/// loaded libraries + +#include "AliHLTMisc.h" + +class AliHLTMiscImplementation : public AliHLTMisc +{ + public: + AliHLTMiscImplementation(); + ~AliHLTMiscImplementation(); + + int InitCDB(const char* cdbpath); + + int SetCDBRunNo(int runNo); + + AliCDBEntry* LoadOCDBEntry(const char* path, int runNo=-1, int version = -1, int subVersion = -1); + + TObject* ExtractObject(AliCDBEntry* entry); + private: + + ClassDef(AliHLTMiscImplementation, 0) +}; + +#endif //ALIHLTMISCIMPLEMENTATION_H -- 2.39.3