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 // the standard components
41 #include "AliHLTFilePublisher.h"
42 #include "AliHLTFileWriter.h"
43 #include "AliHLTRootFilePublisherComponent.h"
44 #include "AliHLTRootFileWriterComponent.h"
46 /** ROOT macro for the implementation of ROOT specific class methods */
47 ClassImp(AliHLTComponentHandler)
49 AliHLTComponentHandler::AliHLTComponentHandler()
57 // see header file for class documentation
59 // refer to README to build package
61 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
63 AddStandardComponents();
66 AliHLTComponentHandler::AliHLTComponentHandler(AliHLTComponentEnvironment* pEnv)
74 // see header file for class documentation
76 memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment));
77 AliHLTLogging::Init(pEnv->fLoggingFunc);
79 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
80 AddStandardComponents();
83 AliHLTComponentHandler::~AliHLTComponentHandler()
85 // see header file for class documentation
87 DeleteStandardComponents();
90 int AliHLTComponentHandler::AnnounceVersion()
92 // see header file for class documentation
95 void HLTbaseCompileInfo( char*& date, char*& time);
98 HLTbaseCompileInfo(date, time);
99 if (!date) date="unknown";
100 if (!time) time="unknown";
101 HLTInfo("%s build on %s (%s)", PACKAGE_STRING, date, time);
103 HLTInfo("ALICE High Level Trigger (embedded AliRoot build)");
108 Int_t AliHLTComponentHandler::RegisterComponent(AliHLTComponent* pSample)
110 // see header file for class documentation
113 if (FindComponent(pSample->GetComponentID())==NULL) {
114 iResult=InsertComponent(pSample);
116 HLTInfo("component %s registered", pSample->GetComponentID());
119 // component already registered
120 HLTDebug("component %s already registered, skipped", pSample->GetComponentID());
129 int AliHLTComponentHandler::DeregisterComponent( const char* componentID )
131 // see header file for class documentation
140 Int_t AliHLTComponentHandler::ScheduleRegister(AliHLTComponent* pSample)
142 // see header file for class documentation
145 fScheduleList.push_back(pSample);
152 int AliHLTComponentHandler::CreateComponent(const char* componentID, void* pEnvParam, int argc, const char** argv, AliHLTComponent*& component )
154 // see header file for class documentation
157 AliHLTComponent* pSample=FindComponent(componentID);
159 component=pSample->Spawn();
161 HLTDebug("component \"%s\" created (%p)", componentID, component);
162 if ((iResult=component->Init(&fEnvironment, pEnvParam, argc, argv))!=0) {
163 HLTError("Initialization of component \"%s\" failed with error %d", componentID, iResult);
168 HLTError("can not spawn component \"%s\"", componentID);
172 HLTWarning("can not find component \"%s\"", componentID);
181 Int_t AliHLTComponentHandler::FindComponentIndex(const char* componentID)
183 // see header file for class documentation
186 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
187 while (element!=fComponentList.end() && iResult>=0) {
188 if (strcmp(componentID, (*element)->GetComponentID())==0) {
194 if (element==fComponentList.end()) iResult=-ENOENT;
201 AliHLTComponent* AliHLTComponentHandler::FindComponent(const char* componentID)
203 // see header file for class documentation
204 AliHLTComponent* pSample=NULL;
205 Int_t index=FindComponentIndex(componentID);
207 pSample=(AliHLTComponent*)fComponentList.at(index);
212 Int_t AliHLTComponentHandler::InsertComponent(AliHLTComponent* pSample)
214 // see header file for class documentation
217 fComponentList.push_back(pSample);
224 void AliHLTComponentHandler::List()
226 // see header file for class documentation
227 vector<AliHLTComponent*>::iterator element=fComponentList.begin();
229 while (element!=fComponentList.end()) {
230 HLTInfo("%d. %s", index++, (*element++)->GetComponentID());
234 void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv)
236 // see header file for class documentation
238 memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment));
239 AliHLTLogging::Init(fEnvironment.fLoggingFunc);
243 int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
245 // see header file for class documentation
248 AliHLTComponent::SetGlobalComponentHandler(this);
249 AliHLTLibHandle hLib=NULL;
251 // use interface to the dynamic linking loader
252 hLib=dlopen(libraryPath, RTLD_NOW);
254 // use ROOT dynamic loader
255 if (gSystem->Load(libraryPath)==0) {
256 // create TString object to store library path and use pointer as handle
257 hLib=reinterpret_cast<AliHLTLibHandle>(new TString(libraryPath));
259 #endif //HAVE_DLFCN_H
261 HLTInfo("library %s loaded", libraryPath);
262 fLibraryList.push_back(hLib);
263 iResult=RegisterScheduledComponents();
265 HLTError("can not load library %s", libraryPath);
267 HLTError("dlopen error: %s", dlerror());
268 #endif //HAVE_DLFCN_H
275 AliHLTComponent::UnsetGlobalComponentHandler();
282 int AliHLTComponentHandler::UnloadLibrary( const char* libraryPath )
284 // see header file for class documentation
293 int AliHLTComponentHandler::UnloadLibraries()
295 // see header file for class documentation
297 vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
298 while (element!=fLibraryList.end()) {
302 TString* libraryPath=reinterpret_cast<TString*>(*element);
303 gSystem->Unload(libraryPath->Data());
305 #endif //HAVE_DLFCN_H
311 int AliHLTComponentHandler::AddStandardComponents()
313 // see header file for class documentation
315 AliHLTComponent::SetGlobalComponentHandler(this);
316 fStandardList.push_back(new AliHLTFilePublisher);
317 fStandardList.push_back(new AliHLTFileWriter);
318 fStandardList.push_back(new AliHLTRootFilePublisherComponent);
319 fStandardList.push_back(new AliHLTRootFileWriterComponent);
320 AliHLTComponent::UnsetGlobalComponentHandler();
321 iResult=RegisterScheduledComponents();
325 int AliHLTComponentHandler::RegisterScheduledComponents()
327 // see header file for class documentation
329 vector<AliHLTComponent*>::iterator element=fScheduleList.begin();
331 while (element!=fScheduleList.end()) {
332 iLocalResult=RegisterComponent(*element);
333 if (iResult==0) iResult=iLocalResult;
334 fScheduleList.erase(element);
335 element=fScheduleList.begin();
340 int AliHLTComponentHandler::DeleteStandardComponents()
342 // see header file for class documentation
344 vector<AliHLTComponent*>::iterator element=fStandardList.begin();
345 while (element!=fStandardList.end()) {
346 DeregisterComponent((*element)->GetComponentID());
348 fStandardList.erase(element);
349 element=fStandardList.begin();