]>
Commit | Line | Data |
---|---|---|
f23a6e1a | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
9be2600f | 4 | * This file is property of and copyright by the ALICE HLT Project * |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
f23a6e1a | 6 | * * |
9be2600f | 7 | * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * |
8 | * Timm Steinbeck <timm@kip.uni-heidelberg.de> * | |
9 | * for The ALICE HLT Project. * | |
f23a6e1a | 10 | * * |
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 | **************************************************************************/ | |
19 | ||
b22e91eb | 20 | /** @file AliHLTComponentHandler.cxx |
21 | @author Matthias Richter, Timm Steinbeck | |
22 | @date | |
23 | @brief Implementation of HLT component handler. */ | |
f23a6e1a | 24 | |
0c0c9d99 | 25 | #if __GNUC__>= 3 |
f23a6e1a | 26 | using namespace std; |
27 | #endif | |
53feaef5 | 28 | //#undef HAVE_DLFCN_H |
29 | #ifdef HAVE_DLFCN_H | |
f23a6e1a | 30 | #include <dlfcn.h> |
53feaef5 | 31 | #else |
32 | //#include <Riostream.h> | |
33 | #include <TSystem.h> | |
34 | #endif //HAVE_DLFCN_H | |
5df0cbb9 | 35 | //#include "AliHLTStdIncludes.h" |
f23a6e1a | 36 | #include "AliHLTComponentHandler.h" |
37 | #include "AliHLTComponent.h" | |
38 | #include "AliHLTDataTypes.h" | |
f3506ea2 | 39 | #include "AliHLTModuleAgent.h" |
5df0cbb9 | 40 | #include "TString.h" |
f23a6e1a | 41 | |
b22e91eb | 42 | /** ROOT macro for the implementation of ROOT specific class methods */ |
f23a6e1a | 43 | ClassImp(AliHLTComponentHandler) |
44 | ||
45 | AliHLTComponentHandler::AliHLTComponentHandler() | |
85869391 | 46 | : |
47 | fComponentList(), | |
48 | fScheduleList(), | |
49 | fLibraryList(), | |
9ce4bf4a | 50 | fEnvironment(), |
f3506ea2 | 51 | fOwnedComponents() |
f23a6e1a | 52 | { |
70ed7d01 | 53 | // see header file for class documentation |
54 | // or | |
55 | // refer to README to build package | |
56 | // or | |
57 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
85869391 | 58 | memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment)); |
9ce4bf4a | 59 | AddStandardComponents(); |
f23a6e1a | 60 | } |
61 | ||
3cde846d | 62 | AliHLTComponentHandler::AliHLTComponentHandler(AliHLTComponentEnvironment* pEnv) |
63 | : | |
298ef463 | 64 | AliHLTLogging(), |
3cde846d | 65 | fComponentList(), |
66 | fScheduleList(), | |
67 | fLibraryList(), | |
68 | fEnvironment(), | |
f3506ea2 | 69 | fOwnedComponents() |
3cde846d | 70 | { |
70ed7d01 | 71 | // see header file for class documentation |
3cde846d | 72 | if (pEnv) { |
73 | memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment)); | |
fa274626 | 74 | if (pEnv->fLoggingFunc) { |
75 | // the AliHLTLogging::Init method also sets the stream output | |
76 | // and notification handler to AliLog. This should only be done | |
77 | // if the logging environment contains a logging function | |
78 | // for redirection | |
79 | AliHLTLogging::Init(pEnv->fLoggingFunc); | |
80 | } | |
f3506ea2 | 81 | } else { |
3cde846d | 82 | memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment)); |
f3506ea2 | 83 | } |
84 | //#ifndef __DEBUG | |
85 | //SetLocalLoggingLevel(kHLTLogError); | |
86 | //#else | |
87 | //SetLocalLoggingLevel(kHLTLogInfo); | |
88 | //#endif | |
89 | ||
3cde846d | 90 | AddStandardComponents(); |
91 | } | |
92 | ||
f23a6e1a | 93 | AliHLTComponentHandler::~AliHLTComponentHandler() |
94 | { | |
70ed7d01 | 95 | // see header file for class documentation |
cbd84228 | 96 | DeleteOwnedComponents(); |
a742f6f8 | 97 | UnloadLibraries(); |
f23a6e1a | 98 | } |
99 | ||
fa760045 | 100 | int AliHLTComponentHandler::AnnounceVersion() |
101 | { | |
70ed7d01 | 102 | // see header file for class documentation |
fa760045 | 103 | int iResult=0; |
104 | #ifdef PACKAGE_STRING | |
105 | void HLTbaseCompileInfo( char*& date, char*& time); | |
106 | char* date=""; | |
107 | char* time=""; | |
108 | HLTbaseCompileInfo(date, time); | |
109 | if (!date) date="unknown"; | |
110 | if (!time) time="unknown"; | |
111 | HLTInfo("%s build on %s (%s)", PACKAGE_STRING, date, time); | |
112 | #else | |
a742f6f8 | 113 | HLTInfo("ALICE High Level Trigger build on %s (%s) (embedded AliRoot build)", __DATE__, __TIME__); |
fa760045 | 114 | #endif |
115 | return iResult; | |
116 | } | |
117 | ||
f3506ea2 | 118 | Int_t AliHLTComponentHandler::AddComponent(AliHLTComponent* pSample) |
119 | { | |
120 | // see header file for class documentation | |
121 | Int_t iResult=0; | |
cbd84228 | 122 | if (pSample==NULL) return -EINVAL; |
f3506ea2 | 123 | if ((iResult=RegisterComponent(pSample))>=0) { |
cbd84228 | 124 | //HLTDebug("sample %s (%p) managed by handler", pSample->GetComponentID(), pSample); |
f3506ea2 | 125 | fOwnedComponents.push_back(pSample); |
126 | } | |
127 | return iResult; | |
128 | } | |
129 | ||
f23a6e1a | 130 | Int_t AliHLTComponentHandler::RegisterComponent(AliHLTComponent* pSample) |
131 | { | |
70ed7d01 | 132 | // see header file for class documentation |
f23a6e1a | 133 | Int_t iResult=0; |
134 | if (pSample) { | |
135 | if (FindComponent(pSample->GetComponentID())==NULL) { | |
136 | iResult=InsertComponent(pSample); | |
137 | if (iResult>=0) { | |
85465857 | 138 | HLTInfo("component %s registered", pSample->GetComponentID()); |
f23a6e1a | 139 | } |
140 | } else { | |
141 | // component already registered | |
fa760045 | 142 | HLTDebug("component %s already registered, skipped", pSample->GetComponentID()); |
f23a6e1a | 143 | iResult=-EEXIST; |
144 | } | |
145 | } else { | |
146 | iResult=-EINVAL; | |
147 | } | |
148 | return iResult; | |
149 | } | |
150 | ||
151 | int AliHLTComponentHandler::DeregisterComponent( const char* componentID ) | |
152 | { | |
70ed7d01 | 153 | // see header file for class documentation |
5df0cbb9 | 154 | |
53feaef5 | 155 | int iResult=0; |
156 | if (componentID) { | |
5df0cbb9 | 157 | HLTWarning("not yet implemented, please notify the developers if you need this function"); |
53feaef5 | 158 | } else { |
159 | iResult=-EINVAL; | |
160 | } | |
161 | return iResult; | |
f23a6e1a | 162 | } |
163 | ||
164 | Int_t AliHLTComponentHandler::ScheduleRegister(AliHLTComponent* pSample) | |
165 | { | |
70ed7d01 | 166 | // see header file for class documentation |
f23a6e1a | 167 | Int_t iResult=0; |
168 | if (pSample) { | |
169 | fScheduleList.push_back(pSample); | |
170 | } else { | |
171 | iResult=-EINVAL; | |
172 | } | |
173 | return iResult; | |
174 | } | |
175 | ||
2d7ff710 | 176 | int AliHLTComponentHandler::CreateComponent(const char* componentID, void* pEnvParam, int argc, const char** argv, AliHLTComponent*& component ) |
f23a6e1a | 177 | { |
70ed7d01 | 178 | // see header file for class documentation |
f23a6e1a | 179 | int iResult=0; |
180 | if (componentID) { | |
181 | AliHLTComponent* pSample=FindComponent(componentID); | |
182 | if (pSample!=NULL) { | |
183 | component=pSample->Spawn(); | |
184 | if (component) { | |
85465857 | 185 | HLTDebug("component \"%s\" created (%p)", componentID, component); |
2d7ff710 | 186 | if ((iResult=component->Init(&fEnvironment, pEnvParam, argc, argv))!=0) { |
84645eb0 | 187 | HLTError("Initialization of component \"%s\" failed with error %d", componentID, iResult); |
188 | delete component; | |
189 | component=NULL; | |
190 | } | |
5ec8e281 | 191 | } else { |
85465857 | 192 | HLTError("can not spawn component \"%s\"", componentID); |
5ec8e281 | 193 | iResult=-ENOENT; |
f23a6e1a | 194 | } |
5ec8e281 | 195 | } else { |
85465857 | 196 | HLTWarning("can not find component \"%s\"", componentID); |
5ec8e281 | 197 | iResult=-ENOENT; |
f23a6e1a | 198 | } |
199 | } else { | |
200 | iResult=-EINVAL; | |
201 | } | |
202 | return iResult; | |
203 | } | |
204 | ||
db16520a | 205 | Int_t AliHLTComponentHandler::FindComponentIndex(const char* componentID) |
f23a6e1a | 206 | { |
70ed7d01 | 207 | // see header file for class documentation |
f23a6e1a | 208 | Int_t iResult=0; |
209 | if (componentID) { | |
210 | vector<AliHLTComponent*>::iterator element=fComponentList.begin(); | |
211 | while (element!=fComponentList.end() && iResult>=0) { | |
212 | if (strcmp(componentID, (*element)->GetComponentID())==0) { | |
213 | break; | |
214 | } | |
215 | element++; | |
216 | iResult++; | |
217 | } | |
218 | if (element==fComponentList.end()) iResult=-ENOENT; | |
219 | } else { | |
220 | iResult=-EINVAL; | |
221 | } | |
222 | return iResult; | |
223 | } | |
224 | ||
db16520a | 225 | AliHLTComponent* AliHLTComponentHandler::FindComponent(const char* componentID) |
f23a6e1a | 226 | { |
70ed7d01 | 227 | // see header file for class documentation |
f23a6e1a | 228 | AliHLTComponent* pSample=NULL; |
229 | Int_t index=FindComponentIndex(componentID); | |
230 | if (index>=0) { | |
231 | pSample=(AliHLTComponent*)fComponentList.at(index); | |
232 | } | |
233 | return pSample; | |
234 | } | |
235 | ||
236 | Int_t AliHLTComponentHandler::InsertComponent(AliHLTComponent* pSample) | |
237 | { | |
70ed7d01 | 238 | // see header file for class documentation |
f23a6e1a | 239 | Int_t iResult=0; |
240 | if (pSample!=NULL) { | |
241 | fComponentList.push_back(pSample); | |
242 | } else { | |
243 | iResult=-EINVAL; | |
244 | } | |
245 | return iResult; | |
246 | } | |
247 | ||
70ed7d01 | 248 | void AliHLTComponentHandler::List() |
249 | { | |
250 | // see header file for class documentation | |
f23a6e1a | 251 | vector<AliHLTComponent*>::iterator element=fComponentList.begin(); |
252 | int index=0; | |
253 | while (element!=fComponentList.end()) { | |
85465857 | 254 | HLTInfo("%d. %s", index++, (*element++)->GetComponentID()); |
f23a6e1a | 255 | } |
256 | } | |
257 | ||
f3506ea2 | 258 | int AliHLTComponentHandler::HasOutputData( const char* componentID) |
259 | { | |
260 | // see header file for class documentation | |
261 | int iResult=0; | |
262 | AliHLTComponent* pSample=FindComponent(componentID); | |
263 | if (pSample) { | |
264 | AliHLTComponent::TComponentType ct=AliHLTComponent::kUnknown; | |
265 | ct=pSample->GetComponentType(); | |
266 | iResult=(ct==AliHLTComponent::kSource || ct==AliHLTComponent::kProcessor); | |
267 | } else { | |
268 | iResult=-ENOENT; | |
269 | } | |
270 | return iResult; | |
271 | } | |
272 | ||
70ed7d01 | 273 | void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv) |
274 | { | |
275 | // see header file for class documentation | |
f23a6e1a | 276 | if (pEnv) { |
277 | memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment)); | |
fa274626 | 278 | if (fEnvironment.fLoggingFunc) { |
279 | // the AliHLTLogging::Init method also sets the stream output | |
280 | // and notification handler to AliLog. This should only be done | |
281 | // if the logging environment contains a logging function | |
282 | // for redirection | |
283 | AliHLTLogging::Init(fEnvironment.fLoggingFunc); | |
284 | } | |
f23a6e1a | 285 | } |
286 | } | |
287 | ||
dba03d72 | 288 | AliHLTComponentHandler::TLibraryMode AliHLTComponentHandler::SetLibraryMode(TLibraryMode mode) |
289 | { | |
290 | // see header file for class documentation | |
291 | TLibraryMode old=fLibraryMode; | |
292 | fLibraryMode=mode; | |
293 | return old; | |
294 | } | |
295 | ||
f3506ea2 | 296 | int AliHLTComponentHandler::LoadLibrary( const char* libraryPath, int bActivateAgents) |
f23a6e1a | 297 | { |
70ed7d01 | 298 | // see header file for class documentation |
f23a6e1a | 299 | int iResult=0; |
300 | if (libraryPath) { | |
f3506ea2 | 301 | // first activate all agents which are already loaded |
302 | if (bActivateAgents) ActivateAgents(); | |
303 | ||
304 | // set the global component handler for static component registration | |
f23a6e1a | 305 | AliHLTComponent::SetGlobalComponentHandler(this); |
f3506ea2 | 306 | |
c215072c | 307 | AliHLTLibHandle hLib; |
85f0cede | 308 | const char* loadtype=""; |
53feaef5 | 309 | #ifdef HAVE_DLFCN_H |
310 | // use interface to the dynamic linking loader | |
f3506ea2 | 311 | try { |
312 | hLib.fHandle=dlopen(libraryPath, RTLD_NOW); | |
313 | loadtype="dlopen"; | |
314 | } | |
315 | catch (...) { | |
316 | // error message printed further down | |
317 | loadtype="dlopen exeption"; | |
318 | } | |
53feaef5 | 319 | #else |
320 | // use ROOT dynamic loader | |
c215072c | 321 | // check if the library was already loaded, as Load returns |
322 | // 'failure' if the library was already loaded | |
f3506ea2 | 323 | try { |
85f0cede | 324 | AliHLTLibHandle* pLib=FindLibrary(libraryPath); |
325 | if (pLib) { | |
5df0cbb9 | 326 | int* pRootHandle=reinterpret_cast<int*>(pLib->fHandle); |
c215072c | 327 | (*pRootHandle)++; |
328 | HLTDebug("instance %d of library %s loaded", (*pRootHandle), libraryPath); | |
5df0cbb9 | 329 | hLib.fHandle=pRootHandle; |
c215072c | 330 | } |
331 | ||
5df0cbb9 | 332 | if (hLib.fHandle==NULL && gSystem->Load(libraryPath)==0) { |
c215072c | 333 | int* pRootHandle=new int; |
334 | if (pRootHandle) *pRootHandle=1; | |
5df0cbb9 | 335 | hLib.fHandle=pRootHandle; |
85f0cede | 336 | //HLTDebug("library %s loaded via gSystem", libraryPath); |
53feaef5 | 337 | } |
85f0cede | 338 | loadtype="gSystem"; |
f3506ea2 | 339 | } |
340 | catch (...) { | |
341 | // error message printed further down | |
342 | loadtype="gSystem exeption"; | |
343 | } | |
53feaef5 | 344 | #endif //HAVE_DLFCN_H |
5df0cbb9 | 345 | if (hLib.fHandle!=NULL) { |
c215072c | 346 | // create TString object to store library path and use pointer as handle |
5df0cbb9 | 347 | hLib.fName=new TString(libraryPath); |
dba03d72 | 348 | hLib.fMode=fLibraryMode; |
349 | HLTInfo("library %s loaded (%s%s)", libraryPath, hLib.fMode==kStatic?"persistent, ":"", loadtype); | |
c215072c | 350 | fLibraryList.insert(fLibraryList.begin(), hLib); |
842fd76a | 351 | typedef void (*CompileInfo)( char*& date, char*& time); |
352 | CompileInfo fctInfo=(CompileInfo)FindSymbol(libraryPath, "CompileInfo"); | |
353 | if (fctInfo) { | |
354 | char* date=""; | |
355 | char* time=""; | |
356 | (*fctInfo)(date, time); | |
357 | if (!date) date="unknown"; | |
358 | if (!time) time="unknown"; | |
359 | HLTInfo("build on %s (%s)", date, time); | |
360 | } else { | |
361 | HLTInfo("no build info available (possible AliRoot embedded build)"); | |
362 | } | |
f3506ea2 | 363 | |
364 | // static registration of components when library is loaded | |
9ce4bf4a | 365 | iResult=RegisterScheduledComponents(); |
f3506ea2 | 366 | |
f23a6e1a | 367 | } else { |
f3506ea2 | 368 | HLTError("can not load library %s (%s)", libraryPath, loadtype); |
53feaef5 | 369 | #ifdef HAVE_DLFCN_H |
85465857 | 370 | HLTError("dlopen error: %s", dlerror()); |
53feaef5 | 371 | #endif //HAVE_DLFCN_H |
0fe88043 | 372 | #ifdef __APPLE__ |
373 | iResult=-EFTYPE; | |
374 | #else | |
f23a6e1a | 375 | iResult=-ELIBACC; |
0fe88043 | 376 | #endif |
f23a6e1a | 377 | } |
2bbbadd1 | 378 | AliHLTComponent::UnsetGlobalComponentHandler(); |
f3506ea2 | 379 | |
380 | if (iResult>=0) { | |
381 | // alternative dynamic registration by library agents | |
382 | // !!! has to be done after UnsetGlobalComponentHandler | |
383 | if (bActivateAgents) ActivateAgents(); | |
384 | } | |
385 | ||
f23a6e1a | 386 | } else { |
387 | iResult=-EINVAL; | |
388 | } | |
389 | return iResult; | |
390 | } | |
391 | ||
392 | int AliHLTComponentHandler::UnloadLibrary( const char* libraryPath ) | |
393 | { | |
70ed7d01 | 394 | // see header file for class documentation |
f23a6e1a | 395 | int iResult=0; |
53feaef5 | 396 | if (libraryPath) { |
a742f6f8 | 397 | vector<AliHLTLibHandle>::iterator element=fLibraryList.begin(); |
398 | while (element!=fLibraryList.end()) { | |
5df0cbb9 | 399 | TString* pName=reinterpret_cast<TString*>((*element).fName); |
a742f6f8 | 400 | if (pName->CompareTo(libraryPath)==0) { |
401 | UnloadLibrary(*element); | |
402 | fLibraryList.erase(element); | |
403 | break; | |
404 | } | |
405 | element++; | |
406 | } | |
53feaef5 | 407 | } else { |
408 | iResult=-EINVAL; | |
409 | } | |
f23a6e1a | 410 | return iResult; |
411 | } | |
412 | ||
a742f6f8 | 413 | int AliHLTComponentHandler::UnloadLibrary(AliHLTComponentHandler::AliHLTLibHandle &handle) |
f23a6e1a | 414 | { |
70ed7d01 | 415 | // see header file for class documentation |
f23a6e1a | 416 | int iResult=0; |
a742f6f8 | 417 | fgAliLoggingFunc=NULL; |
5df0cbb9 | 418 | TString* pName=reinterpret_cast<TString*>(handle.fName); |
dba03d72 | 419 | if (handle.fMode!=kStatic) { |
53feaef5 | 420 | #ifdef HAVE_DLFCN_H |
f3506ea2 | 421 | try { |
422 | dlclose(handle.fHandle); | |
423 | } | |
424 | catch (...) { | |
425 | HLTError("exeption caught during dlclose of library %s", pName!=NULL?pName->Data():""); | |
426 | } | |
53feaef5 | 427 | #else |
5df0cbb9 | 428 | int* pCount=reinterpret_cast<int*>(handle.fHandle); |
a742f6f8 | 429 | if (--(*pCount)==0) { |
c215072c | 430 | if (pName) { |
a7222a6d | 431 | /** Matthias 26.04.2007 |
432 | * I spent about a week to investigate a bug which seems to be in ROOT. | |
433 | * Under certain circumstances, TSystem::Unload crashes. The crash occured | |
434 | * for the first time, when libAliHLTUtil was loaded from AliHLTSystem right | |
435 | * after the ComponentHandler was created. It does not occur when dlopen is | |
436 | * used. | |
437 | * It has most likely to do with the garbage collection and automatic | |
438 | * cleanup in ROOT. The crash occurs when ROOT is terminated and before | |
439 | * an instance of AliHLTSystem was created. | |
440 | * root [0] AliHLTSystem gHLT | |
441 | * It does not occur when the instance was created dynamically (but not even | |
442 | * deleted) | |
443 | * root [0] AliHLTSystem* gHLT=new AliHLTSystem | |
444 | * | |
445 | * For that reason, the libraries are not unloaded here, even though there | |
446 | * will be memory leaks. | |
a742f6f8 | 447 | gSystem->Unload(pName->Data()); |
a7222a6d | 448 | */ |
a742f6f8 | 449 | } |
450 | else { | |
451 | HLTError("missing library name, can not unload"); | |
c215072c | 452 | } |
a742f6f8 | 453 | delete pCount; |
454 | } | |
455 | #endif //HAVE_DLFCN_H | |
a742f6f8 | 456 | if (pName) { |
457 | HLTDebug("unload library %s", pName->Data()); | |
a742f6f8 | 458 | } else { |
459 | HLTWarning("missing name for unloaded library"); | |
460 | } | |
dba03d72 | 461 | } |
462 | handle.fName=NULL; | |
463 | handle.fHandle=NULL; | |
464 | if (pName) { | |
465 | delete pName; | |
466 | } | |
a742f6f8 | 467 | pName=NULL; |
468 | return iResult; | |
469 | } | |
470 | ||
471 | int AliHLTComponentHandler::UnloadLibraries() | |
472 | { | |
473 | // see header file for class documentation | |
474 | int iResult=0; | |
475 | vector<AliHLTLibHandle>::iterator element=fLibraryList.begin(); | |
476 | while (element!=fLibraryList.end()) { | |
477 | UnloadLibrary(*element); | |
c215072c | 478 | fLibraryList.erase(element); |
479 | element=fLibraryList.begin(); | |
f23a6e1a | 480 | } |
481 | return iResult; | |
482 | } | |
9ce4bf4a | 483 | |
85f0cede | 484 | void* AliHLTComponentHandler::FindSymbol(const char* library, const char* symbol) |
485 | { | |
486 | // see header file for class documentation | |
487 | AliHLTLibHandle* hLib=FindLibrary(library); | |
488 | if (hLib==NULL) return NULL; | |
489 | void* pFunc=NULL; | |
490 | #ifdef HAVE_DLFCN_H | |
5df0cbb9 | 491 | pFunc=dlsym(hLib->fHandle, symbol); |
85f0cede | 492 | #else |
5df0cbb9 | 493 | TString* name=reinterpret_cast<TString*>(hLib->fName); |
85f0cede | 494 | pFunc=gSystem->DynFindSymbol(name->Data(), symbol); |
495 | #endif | |
496 | return pFunc; | |
497 | } | |
498 | ||
499 | AliHLTComponentHandler::AliHLTLibHandle* AliHLTComponentHandler::FindLibrary(const char* library) | |
500 | { | |
501 | // see header file for class documentation | |
502 | AliHLTLibHandle* hLib=NULL; | |
503 | vector<AliHLTLibHandle>::iterator element=fLibraryList.begin(); | |
504 | while (element!=fLibraryList.end()) { | |
5df0cbb9 | 505 | TString* name=reinterpret_cast<TString*>((*element).fName); |
85f0cede | 506 | if (name->CompareTo(library)==0) { |
507 | hLib=&(*element); | |
508 | break; | |
509 | } | |
510 | element++; | |
511 | } | |
512 | return hLib; | |
513 | } | |
514 | ||
9ce4bf4a | 515 | int AliHLTComponentHandler::AddStandardComponents() |
516 | { | |
70ed7d01 | 517 | // see header file for class documentation |
9ce4bf4a | 518 | int iResult=0; |
519 | AliHLTComponent::SetGlobalComponentHandler(this); | |
9ce4bf4a | 520 | AliHLTComponent::UnsetGlobalComponentHandler(); |
521 | iResult=RegisterScheduledComponents(); | |
522 | return iResult; | |
523 | } | |
524 | ||
525 | int AliHLTComponentHandler::RegisterScheduledComponents() | |
526 | { | |
70ed7d01 | 527 | // see header file for class documentation |
9ce4bf4a | 528 | int iResult=0; |
529 | vector<AliHLTComponent*>::iterator element=fScheduleList.begin(); | |
530 | int iLocalResult=0; | |
531 | while (element!=fScheduleList.end()) { | |
532 | iLocalResult=RegisterComponent(*element); | |
533 | if (iResult==0) iResult=iLocalResult; | |
534 | fScheduleList.erase(element); | |
535 | element=fScheduleList.begin(); | |
536 | } | |
537 | return iResult; | |
538 | } | |
539 | ||
f3506ea2 | 540 | int AliHLTComponentHandler::ActivateAgents(const AliHLTModuleAgent** blackList, int size) |
541 | { | |
542 | // see header file for class documentation | |
543 | int iResult=0; | |
544 | AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); | |
545 | while (pAgent && iResult>=0) { | |
546 | if (blackList) { | |
547 | int i=0; | |
548 | for (; i<size; i++) { | |
549 | if (blackList[i]==pAgent) break; | |
550 | } | |
551 | if (i<size) { | |
552 | // this agent was in the list | |
553 | pAgent=AliHLTModuleAgent::GetNextAgent(); | |
554 | continue; | |
555 | } | |
556 | } | |
557 | ||
558 | pAgent->ActivateComponentHandler(this); | |
559 | pAgent=AliHLTModuleAgent::GetNextAgent(); | |
560 | } | |
561 | return iResult; | |
562 | } | |
563 | ||
cbd84228 | 564 | int AliHLTComponentHandler::DeleteOwnedComponents() |
9ce4bf4a | 565 | { |
70ed7d01 | 566 | // see header file for class documentation |
9ce4bf4a | 567 | int iResult=0; |
f3506ea2 | 568 | vector<AliHLTComponent*>::iterator element=fOwnedComponents.begin(); |
569 | while (element!=fOwnedComponents.end()) { | |
5df0cbb9 | 570 | //DeregisterComponent((*element)->GetComponentID()); |
cbd84228 | 571 | try { |
572 | delete *element; | |
573 | } | |
574 | catch (...) { | |
575 | HLTError("delete managed sample %p", *element); | |
576 | } | |
f3506ea2 | 577 | fOwnedComponents.erase(element); |
578 | element=fOwnedComponents.begin(); | |
9ce4bf4a | 579 | } |
580 | return iResult; | |
581 | } |