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 * Artur Szostak <artursz@iafrica.com> *
9 * for The ALICE Off-line Project. *
11 * Permission to use, copy, modify and distribute this software and its *
12 * documentation strictly for non-commercial purposes is hereby granted *
13 * without fee, provided that the above copyright notice appears in all *
14 * copies and that both the copyright notice and this permission notice *
15 * appear in the supporting documentation. The authors make no claims *
16 * about the suitability of this software for any purpose. It is *
17 * provided "as is" without express or implied warranty. *
18 **************************************************************************/
20 ///////////////////////////////////////////////////////////////////////////////
22 // handler class for HLT analysis components //
24 ///////////////////////////////////////////////////////////////////////////////
33 #include "AliL3StandardIncludes.h"
34 #include "AliHLTComponentHandler.h"
35 #include "AliHLTComponent.h"
36 #include "AliHLTDataTypes.h"
37 #include "AliHLTSystem.h"
39 ClassImp(AliHLTComponentHandler)
41 AliHLTComponentHandler::AliHLTComponentHandler()
46 AliHLTComponentHandler::~AliHLTComponentHandler()
51 Int_t AliHLTComponentHandler::RegisterComponent(AliHLTComponent* pSample)
55 if (FindComponent(pSample->GetComponentID())==NULL) {
56 iResult=InsertComponent(pSample);
58 Logging(kHLTLogInfo, "BASE", "Component Handler", "component %s registered", pSample->GetComponentID());
61 // component already registered
62 Logging(kHLTLogInfo, "BASE", "Component Handler", "component %s already registered, skipped", pSample->GetComponentID());
71 int AliHLTComponentHandler::DeregisterComponent( const char* componentID )
76 Int_t AliHLTComponentHandler::ScheduleRegister(AliHLTComponent* pSample)
80 fScheduleList.push_back(pSample);
87 int AliHLTComponentHandler::CreateComponent(const Char_t* componentID, void* environ_param, int argc, const char** argv, AliHLTComponent*& component )
91 AliHLTComponent* pSample=FindComponent(componentID);
93 component=pSample->Spawn();
95 Logging(kHLTLogDebug, "BASE", "Component Handler", "component \"%s\" created (%p)", componentID, component);
96 component->Init(&fEnvironment, environ_param, argc, argv);
98 Logging(kHLTLogError, "BASE", "Component Handler", "can not spawn component \"%s\"", componentID);
102 Logging(kHLTLogWarning, "BASE", "Component Handler", "can not find component \"%s\"", componentID);
111 Int_t AliHLTComponentHandler::FindComponentIndex(const Char_t* componentID)
115 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
116 while (element!=fComponentList.end() && iResult>=0) {
117 if (strcmp(componentID, (*element)->GetComponentID())==0) {
123 if (element==fComponentList.end()) iResult=-ENOENT;
130 AliHLTComponent* AliHLTComponentHandler::FindComponent(const Char_t* componentID)
132 AliHLTComponent* pSample=NULL;
133 Int_t index=FindComponentIndex(componentID);
135 pSample=(AliHLTComponent*)fComponentList.at(index);
140 Int_t AliHLTComponentHandler::InsertComponent(AliHLTComponent* pSample)
144 fComponentList.push_back(pSample);
151 void AliHLTComponentHandler::List() {
152 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
154 while (element!=fComponentList.end()) {
155 Logging(kHLTLogInfo, "BASE", "Component Handler", "%d. %s", index++, (*element++)->GetComponentID());
159 void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv) {
161 memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment));
165 int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
169 AliHLTComponent::SetGlobalComponentHandler(this);
170 AliHLTLibHandle hLib=dlopen(libraryPath, RTLD_NOW);
172 AliHLTComponent::UnsetGlobalComponentHandler();
173 Logging(kHLTLogDebug, "BASE", "Component Handler", "library %s loaded", libraryPath);
174 fLibraryList.push_back(hLib);
175 vector<AliHLTComponent*>::iterator element=fScheduleList.begin();
176 int iSize=fScheduleList.size();
178 while (iSize-- > 0) {
179 element=fScheduleList.begin();
180 iLocalResult=RegisterComponent(*element);
181 if (iResult==0) iResult=iLocalResult;
182 fScheduleList.erase(element);
185 Logging(kHLTLogError, "BASE", "Component Handler", "can not load library %s", libraryPath);
186 Logging(kHLTLogError, "BASE", "Component Handler", "dlopen error: %s", dlerror());
195 int AliHLTComponentHandler::UnloadLibrary( const char* libraryPath )
201 int AliHLTComponentHandler::UnloadLibraries()
204 vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
205 while (element!=fLibraryList.end()) {