3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 /** @file AliHLTComponentHandler.cxx
20 @author Matthias Richter, Timm Steinbeck
22 @brief Implementation of HLT component handler. */
31 //#include <Riostream.h>
34 #include "AliHLTStdIncludes.h"
35 #include "AliHLTComponentHandler.h"
36 #include "AliHLTComponent.h"
37 #include "AliHLTDataTypes.h"
38 #include "AliHLTSystem.h"
40 /** ROOT macro for the implementation of ROOT specific class methods */
41 ClassImp(AliHLTComponentHandler)
43 AliHLTComponentHandler::AliHLTComponentHandler()
50 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
53 AliHLTComponentHandler::~AliHLTComponentHandler()
58 int AliHLTComponentHandler::AnnounceVersion()
62 void HLTbaseCompileInfo( char*& date, char*& time);
65 HLTbaseCompileInfo(date, time);
66 if (!date) date="unknown";
67 if (!time) time="unknown";
68 HLTInfo("%s build on %s (%s)", PACKAGE_STRING, date, time);
70 HLTInfo("ALICE High Level Trigger (embedded AliRoot build)");
75 Int_t AliHLTComponentHandler::RegisterComponent(AliHLTComponent* pSample)
79 if (FindComponent(pSample->GetComponentID())==NULL) {
80 iResult=InsertComponent(pSample);
82 HLTInfo("component %s registered", pSample->GetComponentID());
85 // component already registered
86 HLTDebug("component %s already registered, skipped", pSample->GetComponentID());
95 int AliHLTComponentHandler::DeregisterComponent( const char* componentID )
105 Int_t AliHLTComponentHandler::ScheduleRegister(AliHLTComponent* pSample)
109 fScheduleList.push_back(pSample);
116 int AliHLTComponentHandler::CreateComponent(const char* componentID, void* pEnvParam, int argc, const char** argv, AliHLTComponent*& component )
120 AliHLTComponent* pSample=FindComponent(componentID);
122 component=pSample->Spawn();
124 HLTDebug("component \"%s\" created (%p)", componentID, component);
125 if ((iResult=component->Init(&fEnvironment, pEnvParam, argc, argv))!=0) {
126 HLTError("Initialization of component \"%s\" failed with error %d", componentID, iResult);
131 HLTError("can not spawn component \"%s\"", componentID);
135 HLTWarning("can not find component \"%s\"", componentID);
144 Int_t AliHLTComponentHandler::FindComponentIndex(const char* componentID)
148 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
149 while (element!=fComponentList.end() && iResult>=0) {
150 if (strcmp(componentID, (*element)->GetComponentID())==0) {
156 if (element==fComponentList.end()) iResult=-ENOENT;
163 AliHLTComponent* AliHLTComponentHandler::FindComponent(const char* componentID)
165 AliHLTComponent* pSample=NULL;
166 Int_t index=FindComponentIndex(componentID);
168 pSample=(AliHLTComponent*)fComponentList.at(index);
173 Int_t AliHLTComponentHandler::InsertComponent(AliHLTComponent* pSample)
177 fComponentList.push_back(pSample);
184 void AliHLTComponentHandler::List() {
185 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
187 while (element!=fComponentList.end()) {
188 HLTInfo("%d. %s", index++, (*element++)->GetComponentID());
192 void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv) {
194 memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment));
195 AliHLTLogging::Init(fEnvironment.fLoggingFunc);
199 int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
203 AliHLTComponent::SetGlobalComponentHandler(this);
204 AliHLTLibHandle hLib=NULL;
206 // use interface to the dynamic linking loader
207 hLib=dlopen(libraryPath, RTLD_NOW);
209 // use ROOT dynamic loader
210 if (gSystem->Load(libraryPath)==0) {
211 // create TString object to store library path and use pointer as handle
212 hLib=reinterpret_cast<AliHLTLibHandle>(new TString(libraryPath));
214 #endif //HAVE_DLFCN_H
216 HLTInfo("library %s loaded", libraryPath);
217 fLibraryList.push_back(hLib);
218 vector<AliHLTComponent*>::iterator element=fScheduleList.begin();
219 int iSize=fScheduleList.size();
221 while (iSize-- > 0) {
222 element=fScheduleList.begin();
223 iLocalResult=RegisterComponent(*element);
224 if (iResult==0) iResult=iLocalResult;
225 fScheduleList.erase(element);
228 HLTError("can not load library %s", libraryPath);
230 HLTError("dlopen error: %s", dlerror());
231 #endif //HAVE_DLFCN_H
238 AliHLTComponent::UnsetGlobalComponentHandler();
245 int AliHLTComponentHandler::UnloadLibrary( const char* libraryPath )
255 int AliHLTComponentHandler::UnloadLibraries()
258 vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
259 while (element!=fLibraryList.end()) {
263 TString* libraryPath=reinterpret_cast<TString*>(*element);
264 gSystem->Unload(libraryPath->Data());
266 #endif //HAVE_DLFCN_H