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. */
29 #include "AliHLTStdIncludes.h"
30 #include "AliHLTComponentHandler.h"
31 #include "AliHLTComponent.h"
32 #include "AliHLTDataTypes.h"
33 #include "AliHLTSystem.h"
35 /** ROOT macro for the implementation of ROOT specific class methods */
36 ClassImp(AliHLTComponentHandler)
38 AliHLTComponentHandler::AliHLTComponentHandler()
45 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
48 AliHLTComponentHandler::~AliHLTComponentHandler()
53 int AliHLTComponentHandler::AnnounceVersion()
57 void HLTbaseCompileInfo( char*& date, char*& time);
60 HLTbaseCompileInfo(date, time);
61 if (!date) date="unknown";
62 if (!time) time="unknown";
63 HLTInfo("%s build on %s (%s)", PACKAGE_STRING, date, time);
65 HLTInfo("ALICE High Level Trigger (embedded AliRoot build)");
70 Int_t AliHLTComponentHandler::RegisterComponent(AliHLTComponent* pSample)
74 if (FindComponent(pSample->GetComponentID())==NULL) {
75 iResult=InsertComponent(pSample);
77 HLTInfo("component %s registered", pSample->GetComponentID());
80 // component already registered
81 HLTDebug("component %s already registered, skipped", pSample->GetComponentID());
90 int AliHLTComponentHandler::DeregisterComponent( const char* componentID )
95 Int_t AliHLTComponentHandler::ScheduleRegister(AliHLTComponent* pSample)
99 fScheduleList.push_back(pSample);
106 int AliHLTComponentHandler::CreateComponent(const char* componentID, void* pEnv, int argc, const char** argv, AliHLTComponent*& component )
110 AliHLTComponent* pSample=FindComponent(componentID);
112 component=pSample->Spawn();
114 HLTDebug("component \"%s\" created (%p)", componentID, component);
115 component->Init(&fEnvironment, pEnv, argc, argv);
117 HLTError("can not spawn component \"%s\"", componentID);
121 HLTWarning("can not find component \"%s\"", componentID);
130 Int_t AliHLTComponentHandler::FindComponentIndex(const char* componentID)
134 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
135 while (element!=fComponentList.end() && iResult>=0) {
136 if (strcmp(componentID, (*element)->GetComponentID())==0) {
142 if (element==fComponentList.end()) iResult=-ENOENT;
149 AliHLTComponent* AliHLTComponentHandler::FindComponent(const char* componentID)
151 AliHLTComponent* pSample=NULL;
152 Int_t index=FindComponentIndex(componentID);
154 pSample=(AliHLTComponent*)fComponentList.at(index);
159 Int_t AliHLTComponentHandler::InsertComponent(AliHLTComponent* pSample)
163 fComponentList.push_back(pSample);
170 void AliHLTComponentHandler::List() {
171 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
173 while (element!=fComponentList.end()) {
174 HLTInfo("%d. %s", index++, (*element++)->GetComponentID());
178 void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv) {
180 memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment));
181 AliHLTLogging::Init(fEnvironment.fLoggingFunc);
185 int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
189 AliHLTComponent::SetGlobalComponentHandler(this);
190 AliHLTLibHandle hLib=dlopen(libraryPath, RTLD_NOW);
192 AliHLTComponent::UnsetGlobalComponentHandler();
193 HLTInfo("library %s loaded", libraryPath);
194 fLibraryList.push_back(hLib);
195 vector<AliHLTComponent*>::iterator element=fScheduleList.begin();
196 int iSize=fScheduleList.size();
198 while (iSize-- > 0) {
199 element=fScheduleList.begin();
200 iLocalResult=RegisterComponent(*element);
201 if (iResult==0) iResult=iLocalResult;
202 fScheduleList.erase(element);
205 HLTError("can not load library %s", libraryPath);
206 HLTError("dlopen error: %s", dlerror());
215 int AliHLTComponentHandler::UnloadLibrary( const char* libraryPath )
221 int AliHLTComponentHandler::UnloadLibraries()
224 vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
225 while (element!=fLibraryList.end()) {