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 if ((iResult=component->Init(&fEnvironment, pEnv, argc, argv))!=0) {
116 HLTError("Initialization of component \"%s\" failed with error %d", componentID, iResult);
121 HLTError("can not spawn component \"%s\"", componentID);
125 HLTWarning("can not find component \"%s\"", componentID);
134 Int_t AliHLTComponentHandler::FindComponentIndex(const char* componentID)
138 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
139 while (element!=fComponentList.end() && iResult>=0) {
140 if (strcmp(componentID, (*element)->GetComponentID())==0) {
146 if (element==fComponentList.end()) iResult=-ENOENT;
153 AliHLTComponent* AliHLTComponentHandler::FindComponent(const char* componentID)
155 AliHLTComponent* pSample=NULL;
156 Int_t index=FindComponentIndex(componentID);
158 pSample=(AliHLTComponent*)fComponentList.at(index);
163 Int_t AliHLTComponentHandler::InsertComponent(AliHLTComponent* pSample)
167 fComponentList.push_back(pSample);
174 void AliHLTComponentHandler::List() {
175 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
177 while (element!=fComponentList.end()) {
178 HLTInfo("%d. %s", index++, (*element++)->GetComponentID());
182 void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv) {
184 memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment));
185 AliHLTLogging::Init(fEnvironment.fLoggingFunc);
189 int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
193 AliHLTComponent::SetGlobalComponentHandler(this);
194 AliHLTLibHandle hLib=dlopen(libraryPath, RTLD_NOW);
196 AliHLTComponent::UnsetGlobalComponentHandler();
197 HLTInfo("library %s loaded", libraryPath);
198 fLibraryList.push_back(hLib);
199 vector<AliHLTComponent*>::iterator element=fScheduleList.begin();
200 int iSize=fScheduleList.size();
202 while (iSize-- > 0) {
203 element=fScheduleList.begin();
204 iLocalResult=RegisterComponent(*element);
205 if (iResult==0) iResult=iLocalResult;
206 fScheduleList.erase(element);
209 HLTError("can not load library %s", libraryPath);
210 HLTError("dlopen error: %s", dlerror());
219 int AliHLTComponentHandler::UnloadLibrary( const char* libraryPath )
225 int AliHLTComponentHandler::UnloadLibraries()
228 vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
229 while (element!=fLibraryList.end()) {