]>
Commit | Line | Data |
---|---|---|
f23a6e1a | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
4 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
5 | * * | |
6 | * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * | |
7 | * Timm Steinbeck <timm@kip.uni-heidelberg.de> * | |
f23a6e1a | 8 | * for The ALICE Off-line Project. * |
9 | * * | |
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 | **************************************************************************/ | |
18 | ||
b22e91eb | 19 | /** @file AliHLTComponentHandler.cxx |
20 | @author Matthias Richter, Timm Steinbeck | |
21 | @date | |
22 | @brief Implementation of HLT component handler. */ | |
f23a6e1a | 23 | |
0c0c9d99 | 24 | #if __GNUC__>= 3 |
f23a6e1a | 25 | using namespace std; |
26 | #endif | |
53feaef5 | 27 | //#undef HAVE_DLFCN_H |
28 | #ifdef HAVE_DLFCN_H | |
f23a6e1a | 29 | #include <dlfcn.h> |
53feaef5 | 30 | #else |
31 | //#include <Riostream.h> | |
32 | #include <TSystem.h> | |
33 | #endif //HAVE_DLFCN_H | |
85869391 | 34 | #include "AliHLTStdIncludes.h" |
f23a6e1a | 35 | #include "AliHLTComponentHandler.h" |
36 | #include "AliHLTComponent.h" | |
37 | #include "AliHLTDataTypes.h" | |
38 | #include "AliHLTSystem.h" | |
39 | ||
9ce4bf4a | 40 | // the standard components |
41 | #include "AliHLTFilePublisher.h" | |
42 | #include "AliHLTFileWriter.h" | |
3cde846d | 43 | #include "AliHLTRootFileWriterComponent.h" |
9ce4bf4a | 44 | |
b22e91eb | 45 | /** ROOT macro for the implementation of ROOT specific class methods */ |
f23a6e1a | 46 | ClassImp(AliHLTComponentHandler) |
47 | ||
48 | AliHLTComponentHandler::AliHLTComponentHandler() | |
85869391 | 49 | : |
50 | fComponentList(), | |
51 | fScheduleList(), | |
52 | fLibraryList(), | |
9ce4bf4a | 53 | fEnvironment(), |
54 | fStandardList() | |
f23a6e1a | 55 | { |
70ed7d01 | 56 | // see header file for class documentation |
57 | // or | |
58 | // refer to README to build package | |
59 | // or | |
60 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
85869391 | 61 | memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment)); |
9ce4bf4a | 62 | AddStandardComponents(); |
f23a6e1a | 63 | } |
64 | ||
3cde846d | 65 | AliHLTComponentHandler::AliHLTComponentHandler(AliHLTComponentEnvironment* pEnv) |
66 | : | |
67 | fComponentList(), | |
68 | fScheduleList(), | |
69 | fLibraryList(), | |
70 | fEnvironment(), | |
71 | fStandardList() | |
72 | { | |
70ed7d01 | 73 | // see header file for class documentation |
3cde846d | 74 | if (pEnv) { |
75 | memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment)); | |
76 | AliHLTLogging::Init(pEnv->fLoggingFunc); | |
77 | } else | |
78 | memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment)); | |
79 | AddStandardComponents(); | |
80 | } | |
81 | ||
f23a6e1a | 82 | AliHLTComponentHandler::~AliHLTComponentHandler() |
83 | { | |
70ed7d01 | 84 | // see header file for class documentation |
f23a6e1a | 85 | UnloadLibraries(); |
9ce4bf4a | 86 | DeleteStandardComponents(); |
f23a6e1a | 87 | } |
88 | ||
fa760045 | 89 | int AliHLTComponentHandler::AnnounceVersion() |
90 | { | |
70ed7d01 | 91 | // see header file for class documentation |
fa760045 | 92 | int iResult=0; |
93 | #ifdef PACKAGE_STRING | |
94 | void HLTbaseCompileInfo( char*& date, char*& time); | |
95 | char* date=""; | |
96 | char* time=""; | |
97 | HLTbaseCompileInfo(date, time); | |
98 | if (!date) date="unknown"; | |
99 | if (!time) time="unknown"; | |
100 | HLTInfo("%s build on %s (%s)", PACKAGE_STRING, date, time); | |
101 | #else | |
102 | HLTInfo("ALICE High Level Trigger (embedded AliRoot build)"); | |
103 | #endif | |
104 | return iResult; | |
105 | } | |
106 | ||
f23a6e1a | 107 | Int_t AliHLTComponentHandler::RegisterComponent(AliHLTComponent* pSample) |
108 | { | |
70ed7d01 | 109 | // see header file for class documentation |
f23a6e1a | 110 | Int_t iResult=0; |
111 | if (pSample) { | |
112 | if (FindComponent(pSample->GetComponentID())==NULL) { | |
113 | iResult=InsertComponent(pSample); | |
114 | if (iResult>=0) { | |
85465857 | 115 | HLTInfo("component %s registered", pSample->GetComponentID()); |
f23a6e1a | 116 | } |
117 | } else { | |
118 | // component already registered | |
fa760045 | 119 | HLTDebug("component %s already registered, skipped", pSample->GetComponentID()); |
f23a6e1a | 120 | iResult=-EEXIST; |
121 | } | |
122 | } else { | |
123 | iResult=-EINVAL; | |
124 | } | |
125 | return iResult; | |
126 | } | |
127 | ||
128 | int AliHLTComponentHandler::DeregisterComponent( const char* componentID ) | |
129 | { | |
70ed7d01 | 130 | // see header file for class documentation |
53feaef5 | 131 | int iResult=0; |
132 | if (componentID) { | |
133 | } else { | |
134 | iResult=-EINVAL; | |
135 | } | |
136 | return iResult; | |
f23a6e1a | 137 | } |
138 | ||
139 | Int_t AliHLTComponentHandler::ScheduleRegister(AliHLTComponent* pSample) | |
140 | { | |
70ed7d01 | 141 | // see header file for class documentation |
f23a6e1a | 142 | Int_t iResult=0; |
143 | if (pSample) { | |
144 | fScheduleList.push_back(pSample); | |
145 | } else { | |
146 | iResult=-EINVAL; | |
147 | } | |
148 | return iResult; | |
149 | } | |
150 | ||
2d7ff710 | 151 | int AliHLTComponentHandler::CreateComponent(const char* componentID, void* pEnvParam, int argc, const char** argv, AliHLTComponent*& component ) |
f23a6e1a | 152 | { |
70ed7d01 | 153 | // see header file for class documentation |
f23a6e1a | 154 | int iResult=0; |
155 | if (componentID) { | |
156 | AliHLTComponent* pSample=FindComponent(componentID); | |
157 | if (pSample!=NULL) { | |
158 | component=pSample->Spawn(); | |
159 | if (component) { | |
85465857 | 160 | HLTDebug("component \"%s\" created (%p)", componentID, component); |
2d7ff710 | 161 | if ((iResult=component->Init(&fEnvironment, pEnvParam, argc, argv))!=0) { |
84645eb0 | 162 | HLTError("Initialization of component \"%s\" failed with error %d", componentID, iResult); |
163 | delete component; | |
164 | component=NULL; | |
165 | } | |
5ec8e281 | 166 | } else { |
85465857 | 167 | HLTError("can not spawn component \"%s\"", componentID); |
5ec8e281 | 168 | iResult=-ENOENT; |
f23a6e1a | 169 | } |
5ec8e281 | 170 | } else { |
85465857 | 171 | HLTWarning("can not find component \"%s\"", componentID); |
5ec8e281 | 172 | iResult=-ENOENT; |
f23a6e1a | 173 | } |
174 | } else { | |
175 | iResult=-EINVAL; | |
176 | } | |
177 | return iResult; | |
178 | } | |
179 | ||
db16520a | 180 | Int_t AliHLTComponentHandler::FindComponentIndex(const char* componentID) |
f23a6e1a | 181 | { |
70ed7d01 | 182 | // see header file for class documentation |
f23a6e1a | 183 | Int_t iResult=0; |
184 | if (componentID) { | |
185 | vector<AliHLTComponent*>::iterator element=fComponentList.begin(); | |
186 | while (element!=fComponentList.end() && iResult>=0) { | |
187 | if (strcmp(componentID, (*element)->GetComponentID())==0) { | |
188 | break; | |
189 | } | |
190 | element++; | |
191 | iResult++; | |
192 | } | |
193 | if (element==fComponentList.end()) iResult=-ENOENT; | |
194 | } else { | |
195 | iResult=-EINVAL; | |
196 | } | |
197 | return iResult; | |
198 | } | |
199 | ||
db16520a | 200 | AliHLTComponent* AliHLTComponentHandler::FindComponent(const char* componentID) |
f23a6e1a | 201 | { |
70ed7d01 | 202 | // see header file for class documentation |
f23a6e1a | 203 | AliHLTComponent* pSample=NULL; |
204 | Int_t index=FindComponentIndex(componentID); | |
205 | if (index>=0) { | |
206 | pSample=(AliHLTComponent*)fComponentList.at(index); | |
207 | } | |
208 | return pSample; | |
209 | } | |
210 | ||
211 | Int_t AliHLTComponentHandler::InsertComponent(AliHLTComponent* pSample) | |
212 | { | |
70ed7d01 | 213 | // see header file for class documentation |
f23a6e1a | 214 | Int_t iResult=0; |
215 | if (pSample!=NULL) { | |
216 | fComponentList.push_back(pSample); | |
217 | } else { | |
218 | iResult=-EINVAL; | |
219 | } | |
220 | return iResult; | |
221 | } | |
222 | ||
70ed7d01 | 223 | void AliHLTComponentHandler::List() |
224 | { | |
225 | // see header file for class documentation | |
f23a6e1a | 226 | vector<AliHLTComponent*>::iterator element=fComponentList.begin(); |
227 | int index=0; | |
228 | while (element!=fComponentList.end()) { | |
85465857 | 229 | HLTInfo("%d. %s", index++, (*element++)->GetComponentID()); |
f23a6e1a | 230 | } |
231 | } | |
232 | ||
70ed7d01 | 233 | void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv) |
234 | { | |
235 | // see header file for class documentation | |
f23a6e1a | 236 | if (pEnv) { |
237 | memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment)); | |
bb16cc41 | 238 | AliHLTLogging::Init(fEnvironment.fLoggingFunc); |
f23a6e1a | 239 | } |
240 | } | |
241 | ||
242 | int AliHLTComponentHandler::LoadLibrary( const char* libraryPath ) | |
243 | { | |
70ed7d01 | 244 | // see header file for class documentation |
f23a6e1a | 245 | int iResult=0; |
246 | if (libraryPath) { | |
247 | AliHLTComponent::SetGlobalComponentHandler(this); | |
53feaef5 | 248 | AliHLTLibHandle hLib=NULL; |
249 | #ifdef HAVE_DLFCN_H | |
250 | // use interface to the dynamic linking loader | |
251 | hLib=dlopen(libraryPath, RTLD_NOW); | |
252 | #else | |
253 | // use ROOT dynamic loader | |
254 | if (gSystem->Load(libraryPath)==0) { | |
255 | // create TString object to store library path and use pointer as handle | |
256 | hLib=reinterpret_cast<AliHLTLibHandle>(new TString(libraryPath)); | |
257 | } | |
258 | #endif //HAVE_DLFCN_H | |
f23a6e1a | 259 | if (hLib) { |
fa760045 | 260 | HLTInfo("library %s loaded", libraryPath); |
f23a6e1a | 261 | fLibraryList.push_back(hLib); |
9ce4bf4a | 262 | iResult=RegisterScheduledComponents(); |
f23a6e1a | 263 | } else { |
85465857 | 264 | HLTError("can not load library %s", libraryPath); |
53feaef5 | 265 | #ifdef HAVE_DLFCN_H |
85465857 | 266 | HLTError("dlopen error: %s", dlerror()); |
53feaef5 | 267 | #endif //HAVE_DLFCN_H |
0fe88043 | 268 | #ifdef __APPLE__ |
269 | iResult=-EFTYPE; | |
270 | #else | |
f23a6e1a | 271 | iResult=-ELIBACC; |
0fe88043 | 272 | #endif |
f23a6e1a | 273 | } |
2bbbadd1 | 274 | AliHLTComponent::UnsetGlobalComponentHandler(); |
f23a6e1a | 275 | } else { |
276 | iResult=-EINVAL; | |
277 | } | |
278 | return iResult; | |
279 | } | |
280 | ||
281 | int AliHLTComponentHandler::UnloadLibrary( const char* libraryPath ) | |
282 | { | |
70ed7d01 | 283 | // see header file for class documentation |
f23a6e1a | 284 | int iResult=0; |
53feaef5 | 285 | if (libraryPath) { |
286 | } else { | |
287 | iResult=-EINVAL; | |
288 | } | |
f23a6e1a | 289 | return iResult; |
290 | } | |
291 | ||
292 | int AliHLTComponentHandler::UnloadLibraries() | |
293 | { | |
70ed7d01 | 294 | // see header file for class documentation |
f23a6e1a | 295 | int iResult=0; |
296 | vector<AliHLTLibHandle>::iterator element=fLibraryList.begin(); | |
297 | while (element!=fLibraryList.end()) { | |
53feaef5 | 298 | #ifdef HAVE_DLFCN_H |
f23a6e1a | 299 | dlclose(*element); |
53feaef5 | 300 | #else |
301 | TString* libraryPath=reinterpret_cast<TString*>(*element); | |
302 | gSystem->Unload(libraryPath->Data()); | |
303 | delete libraryPath; | |
304 | #endif //HAVE_DLFCN_H | |
f23a6e1a | 305 | element++; |
306 | } | |
307 | return iResult; | |
308 | } | |
9ce4bf4a | 309 | |
310 | int AliHLTComponentHandler::AddStandardComponents() | |
311 | { | |
70ed7d01 | 312 | // see header file for class documentation |
9ce4bf4a | 313 | int iResult=0; |
314 | AliHLTComponent::SetGlobalComponentHandler(this); | |
315 | fStandardList.push_back(new AliHLTFilePublisher); | |
316 | fStandardList.push_back(new AliHLTFileWriter); | |
3cde846d | 317 | fStandardList.push_back(new AliHLTRootFileWriterComponent); |
9ce4bf4a | 318 | AliHLTComponent::UnsetGlobalComponentHandler(); |
319 | iResult=RegisterScheduledComponents(); | |
320 | return iResult; | |
321 | } | |
322 | ||
323 | int AliHLTComponentHandler::RegisterScheduledComponents() | |
324 | { | |
70ed7d01 | 325 | // see header file for class documentation |
9ce4bf4a | 326 | int iResult=0; |
327 | vector<AliHLTComponent*>::iterator element=fScheduleList.begin(); | |
328 | int iLocalResult=0; | |
329 | while (element!=fScheduleList.end()) { | |
330 | iLocalResult=RegisterComponent(*element); | |
331 | if (iResult==0) iResult=iLocalResult; | |
332 | fScheduleList.erase(element); | |
333 | element=fScheduleList.begin(); | |
334 | } | |
335 | return iResult; | |
336 | } | |
337 | ||
338 | int AliHLTComponentHandler::DeleteStandardComponents() | |
339 | { | |
70ed7d01 | 340 | // see header file for class documentation |
9ce4bf4a | 341 | int iResult=0; |
342 | vector<AliHLTComponent*>::iterator element=fStandardList.begin(); | |
343 | while (element!=fStandardList.end()) { | |
344 | DeregisterComponent((*element)->GetComponentID()); | |
345 | delete(*element); | |
346 | fStandardList.erase(element); | |
347 | element=fStandardList.begin(); | |
348 | } | |
349 | return iResult; | |
350 | } |