]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTComponentHandler.cxx
implementing cleanup functionality to use the same instance in multiple calls
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponentHandler.cxx
CommitLineData
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
28cd9358 20/// @file AliHLTComponentHandler.cxx
21/// @author Matthias Richter, Timm Steinbeck
22/// @date
23/// @brief Implementation of HLT component handler.
24///
f23a6e1a 25
7bcd6cad 26// see header file for class documentation
27// or
28// refer to README to build package
29// or
30// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
31
0c0c9d99 32#if __GNUC__>= 3
f23a6e1a 33using namespace std;
34#endif
53feaef5 35//#undef HAVE_DLFCN_H
36#ifdef HAVE_DLFCN_H
f23a6e1a 37#include <dlfcn.h>
53feaef5 38#else
39//#include <Riostream.h>
40#include <TSystem.h>
41#endif //HAVE_DLFCN_H
5df0cbb9 42//#include "AliHLTStdIncludes.h"
f23a6e1a 43#include "AliHLTComponentHandler.h"
44#include "AliHLTComponent.h"
45#include "AliHLTDataTypes.h"
f3506ea2 46#include "AliHLTModuleAgent.h"
5df0cbb9 47#include "TString.h"
f23a6e1a 48
b22e91eb 49/** ROOT macro for the implementation of ROOT specific class methods */
f23a6e1a 50ClassImp(AliHLTComponentHandler)
51
52AliHLTComponentHandler::AliHLTComponentHandler()
85869391 53 :
54 fComponentList(),
55 fScheduleList(),
56 fLibraryList(),
9ce4bf4a 57 fEnvironment(),
620fcee6 58 fOwnedComponents(),
45c0a780 59 fLibraryMode(kDynamic),
60 fRunDesc(kAliHLTVoidRunDesc),
61 fRunType(NULL)
f23a6e1a 62{
70ed7d01 63 // see header file for class documentation
64 // or
65 // refer to README to build package
66 // or
67 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
a3c9b745 68 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
69 fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
9ce4bf4a 70 AddStandardComponents();
f23a6e1a 71}
72
a3c9b745 73AliHLTComponentHandler::AliHLTComponentHandler(AliHLTAnalysisEnvironment* pEnv)
3cde846d 74 :
298ef463 75 AliHLTLogging(),
3cde846d 76 fComponentList(),
77 fScheduleList(),
78 fLibraryList(),
79 fEnvironment(),
620fcee6 80 fOwnedComponents(),
45c0a780 81 fLibraryMode(kDynamic),
82 fRunDesc(kAliHLTVoidRunDesc),
83 fRunType(NULL)
3cde846d 84{
70ed7d01 85 // see header file for class documentation
3cde846d 86 if (pEnv) {
a3c9b745 87 memcpy(&fEnvironment, pEnv, sizeof(AliHLTAnalysisEnvironment));
fa274626 88 if (pEnv->fLoggingFunc) {
89 // the AliHLTLogging::Init method also sets the stream output
90 // and notification handler to AliLog. This should only be done
91 // if the logging environment contains a logging function
92 // for redirection
93 AliHLTLogging::Init(pEnv->fLoggingFunc);
94 }
f3506ea2 95 } else {
a3c9b745 96 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
97 fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
f3506ea2 98 }
99 //#ifndef __DEBUG
100 //SetLocalLoggingLevel(kHLTLogError);
101 //#else
102 //SetLocalLoggingLevel(kHLTLogInfo);
103 //#endif
104
3cde846d 105 AddStandardComponents();
106}
107
f23a6e1a 108AliHLTComponentHandler::~AliHLTComponentHandler()
109{
70ed7d01 110 // see header file for class documentation
cbd84228 111 DeleteOwnedComponents();
a742f6f8 112 UnloadLibraries();
45c0a780 113 if (fRunType) delete [] fRunType;
114 fRunType=NULL;
f23a6e1a 115}
116
b005ef92 117AliHLTComponentHandler* AliHLTComponentHandler::fgpInstance=NULL;
118int AliHLTComponentHandler::fgNofInstances=0;
119
120AliHLTComponentHandler* AliHLTComponentHandler::CreateHandler()
121{
122 // see header file for class documentation
123 if (!fgpInstance) fgpInstance=new AliHLTComponentHandler;
124 fgNofInstances++;
125 return fgpInstance;
126}
127
128int AliHLTComponentHandler::Destroy()
129{
153e7db5 130 // destroy/delete 'this', checks if 'this' pointer is the global instance,
131 // reduce the instance counter and delete if there are no instances left
132 // IMPORTANT: the object must be considered self-destroyed after the function
b005ef92 133 int nofInstances=0;
134 if (fgpInstance==this) {
153e7db5 135 nofInstances=--fgNofInstances;
b005ef92 136 }
153e7db5 137 if (fgNofInstances==0) fgpInstance=NULL;
b005ef92 138 if (nofInstances==0) delete this;
139 return nofInstances;
140}
141
fa760045 142int AliHLTComponentHandler::AnnounceVersion()
143{
70ed7d01 144 // see header file for class documentation
fa760045 145 int iResult=0;
146#ifdef PACKAGE_STRING
179be78e 147 extern void HLTbaseCompileInfo( const char*& date, const char*& time);
148 const char* date="";
149 const char* time="";
fa760045 150 HLTbaseCompileInfo(date, time);
151 if (!date) date="unknown";
152 if (!time) time="unknown";
b2065764 153 HLTImportant("%s build on %s (%s)", PACKAGE_STRING, date, time);
fa760045 154#else
b2065764 155 HLTImportant("ALICE High Level Trigger build on %s (%s) (embedded AliRoot build)", __DATE__, __TIME__);
fa760045 156#endif
157 return iResult;
158}
159
f3506ea2 160Int_t AliHLTComponentHandler::AddComponent(AliHLTComponent* pSample)
161{
162 // see header file for class documentation
163 Int_t iResult=0;
cbd84228 164 if (pSample==NULL) return -EINVAL;
f3506ea2 165 if ((iResult=RegisterComponent(pSample))>=0) {
cbd84228 166 //HLTDebug("sample %s (%p) managed by handler", pSample->GetComponentID(), pSample);
f3506ea2 167 fOwnedComponents.push_back(pSample);
168 }
169 return iResult;
170}
171
f23a6e1a 172Int_t AliHLTComponentHandler::RegisterComponent(AliHLTComponent* pSample)
173{
70ed7d01 174 // see header file for class documentation
f23a6e1a 175 Int_t iResult=0;
176 if (pSample) {
177 if (FindComponent(pSample->GetComponentID())==NULL) {
178 iResult=InsertComponent(pSample);
179 if (iResult>=0) {
85465857 180 HLTInfo("component %s registered", pSample->GetComponentID());
f23a6e1a 181 }
182 } else {
183 // component already registered
fa760045 184 HLTDebug("component %s already registered, skipped", pSample->GetComponentID());
f23a6e1a 185 iResult=-EEXIST;
186 }
187 } else {
188 iResult=-EINVAL;
189 }
190 return iResult;
191}
192
193int AliHLTComponentHandler::DeregisterComponent( const char* componentID )
194{
70ed7d01 195 // see header file for class documentation
5df0cbb9 196
53feaef5 197 int iResult=0;
198 if (componentID) {
5df0cbb9 199 HLTWarning("not yet implemented, please notify the developers if you need this function");
53feaef5 200 } else {
201 iResult=-EINVAL;
202 }
203 return iResult;
f23a6e1a 204}
205
206Int_t AliHLTComponentHandler::ScheduleRegister(AliHLTComponent* pSample)
207{
70ed7d01 208 // see header file for class documentation
f23a6e1a 209 Int_t iResult=0;
210 if (pSample) {
211 fScheduleList.push_back(pSample);
212 } else {
213 iResult=-EINVAL;
214 }
215 return iResult;
216}
217
9a0ef890 218int AliHLTComponentHandler::CreateComponent(const char* componentID, void* pEnvParam, int argc, const char** argv, AliHLTComponent*& component)
219{
220 // see header file for class documentation
221 int iResult=CreateComponent(componentID, component);
222 if (iResult>=0 && component) {
223 HLTDebug("component \"%s\" created (%p)", componentID, component);
224 if ((iResult=component->Init(&fEnvironment, pEnvParam, argc, argv))!=0) {
225 HLTError("Initialization of component \"%s\" failed with error %d", componentID, iResult);
226 delete component;
227 component=NULL;
228 }
229 }
230 return iResult;
231}
232
233int AliHLTComponentHandler::CreateComponent(const char* componentID, AliHLTComponent*& component )
f23a6e1a 234{
70ed7d01 235 // see header file for class documentation
f23a6e1a 236 int iResult=0;
237 if (componentID) {
238 AliHLTComponent* pSample=FindComponent(componentID);
239 if (pSample!=NULL) {
240 component=pSample->Spawn();
241 if (component) {
85465857 242 HLTDebug("component \"%s\" created (%p)", componentID, component);
5ec8e281 243 } else {
85465857 244 HLTError("can not spawn component \"%s\"", componentID);
5ec8e281 245 iResult=-ENOENT;
f23a6e1a 246 }
5ec8e281 247 } else {
85465857 248 HLTWarning("can not find component \"%s\"", componentID);
5ec8e281 249 iResult=-ENOENT;
f23a6e1a 250 }
251 } else {
252 iResult=-EINVAL;
253 }
254 return iResult;
255}
256
db16520a 257Int_t AliHLTComponentHandler::FindComponentIndex(const char* componentID)
f23a6e1a 258{
70ed7d01 259 // see header file for class documentation
f23a6e1a 260 Int_t iResult=0;
261 if (componentID) {
7bcd6cad 262 AliHLTComponentPList::iterator element=fComponentList.begin();
f23a6e1a 263 while (element!=fComponentList.end() && iResult>=0) {
264 if (strcmp(componentID, (*element)->GetComponentID())==0) {
265 break;
266 }
267 element++;
268 iResult++;
269 }
270 if (element==fComponentList.end()) iResult=-ENOENT;
271 } else {
272 iResult=-EINVAL;
273 }
274 return iResult;
275}
276
db16520a 277AliHLTComponent* AliHLTComponentHandler::FindComponent(const char* componentID)
f23a6e1a 278{
70ed7d01 279 // see header file for class documentation
f23a6e1a 280 AliHLTComponent* pSample=NULL;
281 Int_t index=FindComponentIndex(componentID);
282 if (index>=0) {
283 pSample=(AliHLTComponent*)fComponentList.at(index);
284 }
285 return pSample;
286}
287
288Int_t AliHLTComponentHandler::InsertComponent(AliHLTComponent* pSample)
289{
70ed7d01 290 // see header file for class documentation
f23a6e1a 291 Int_t iResult=0;
292 if (pSample!=NULL) {
293 fComponentList.push_back(pSample);
294 } else {
295 iResult=-EINVAL;
296 }
297 return iResult;
298}
299
70ed7d01 300void AliHLTComponentHandler::List()
301{
302 // see header file for class documentation
7bcd6cad 303 AliHLTComponentPList::iterator element=fComponentList.begin();
f23a6e1a 304 int index=0;
305 while (element!=fComponentList.end()) {
85465857 306 HLTInfo("%d. %s", index++, (*element++)->GetComponentID());
f23a6e1a 307 }
308}
309
f3506ea2 310int AliHLTComponentHandler::HasOutputData( const char* componentID)
311{
312 // see header file for class documentation
313 int iResult=0;
314 AliHLTComponent* pSample=FindComponent(componentID);
315 if (pSample) {
316 AliHLTComponent::TComponentType ct=AliHLTComponent::kUnknown;
317 ct=pSample->GetComponentType();
318 iResult=(ct==AliHLTComponent::kSource || ct==AliHLTComponent::kProcessor);
319 } else {
320 iResult=-ENOENT;
321 }
322 return iResult;
323}
324
a3c9b745 325void AliHLTComponentHandler::SetEnvironment(AliHLTAnalysisEnvironment* pEnv)
70ed7d01 326{
327 // see header file for class documentation
f23a6e1a 328 if (pEnv) {
a3c9b745 329 memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
330 memcpy(&fEnvironment, pEnv, pEnv->fStructSize<sizeof(AliHLTAnalysisEnvironment)?pEnv->fStructSize:sizeof(AliHLTAnalysisEnvironment));
331 fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
fa274626 332 if (fEnvironment.fLoggingFunc) {
333 // the AliHLTLogging::Init method also sets the stream output
334 // and notification handler to AliLog. This should only be done
335 // if the logging environment contains a logging function
336 // for redirection
337 AliHLTLogging::Init(fEnvironment.fLoggingFunc);
338 }
f23a6e1a 339 }
340}
341
dba03d72 342AliHLTComponentHandler::TLibraryMode AliHLTComponentHandler::SetLibraryMode(TLibraryMode mode)
343{
344 // see header file for class documentation
345 TLibraryMode old=fLibraryMode;
346 fLibraryMode=mode;
347 return old;
348}
349
f3506ea2 350int AliHLTComponentHandler::LoadLibrary( const char* libraryPath, int bActivateAgents)
f23a6e1a 351{
70ed7d01 352 // see header file for class documentation
f23a6e1a 353 int iResult=0;
354 if (libraryPath) {
7dbfa7c9 355 TString libName=libraryPath;
356 int slash=-1;
357 while ((slash=libName.Index("/"))>=0) {
358 libName=libName.Remove(0, slash+1);
359 }
360 libName.ReplaceAll(".so","");
f3506ea2 361
362 // set the global component handler for static component registration
f23a6e1a 363 AliHLTComponent::SetGlobalComponentHandler(this);
f3506ea2 364
c215072c 365 AliHLTLibHandle hLib;
d4a18597 366 AliHLTLibHandle* phSearch=FindLibrary(libraryPath);
85f0cede 367 const char* loadtype="";
53feaef5 368#ifdef HAVE_DLFCN_H
369 // use interface to the dynamic linking loader
13398559 370
371 // exeption does not help in Root context, the Root exeption
372 // handler always catches the exeption before. Have to find out
373 // how exeptions can be used in Root
374 /*try*/ {
f3506ea2 375 hLib.fHandle=dlopen(libraryPath, RTLD_NOW);
376 loadtype="dlopen";
377 }
13398559 378 /*
f3506ea2 379 catch (...) {
380 // error message printed further down
381 loadtype="dlopen exeption";
382 }
13398559 383 */
53feaef5 384#else
385 // use ROOT dynamic loader
c215072c 386 // check if the library was already loaded, as Load returns
387 // 'failure' if the library was already loaded
13398559 388 /*try*/ {
d4a18597 389 if (phSearch) {
390 int* pRootHandle=reinterpret_cast<int*>(phSearch->fHandle);
c215072c 391 (*pRootHandle)++;
392 HLTDebug("instance %d of library %s loaded", (*pRootHandle), libraryPath);
5df0cbb9 393 hLib.fHandle=pRootHandle;
c215072c 394 }
395
107e2b1c 396 if (hLib.fHandle==NULL && gSystem->Load(libraryPath)>=0) {
c215072c 397 int* pRootHandle=new int;
398 if (pRootHandle) *pRootHandle=1;
5df0cbb9 399 hLib.fHandle=pRootHandle;
85f0cede 400 //HLTDebug("library %s loaded via gSystem", libraryPath);
53feaef5 401 }
85f0cede 402 loadtype="gSystem";
f3506ea2 403 }
13398559 404 /*
f3506ea2 405 catch (...) {
406 // error message printed further down
407 loadtype="gSystem exeption";
408 }
13398559 409 */
53feaef5 410#endif //HAVE_DLFCN_H
5df0cbb9 411 if (hLib.fHandle!=NULL) {
c215072c 412 // create TString object to store library path and use pointer as handle
5df0cbb9 413 hLib.fName=new TString(libraryPath);
dba03d72 414 hLib.fMode=fLibraryMode;
c215072c 415 fLibraryList.insert(fLibraryList.begin(), hLib);
d4a18597 416 if (!phSearch) {
179be78e 417 typedef void (*CompileInfo)(const char*& date, const char*& time);
842fd76a 418 CompileInfo fctInfo=(CompileInfo)FindSymbol(libraryPath, "CompileInfo");
7dbfa7c9 419 const char* date="";
420 const char* time="";
421 const char* buildOn="";
842fd76a 422 if (fctInfo) {
7dbfa7c9 423 buildOn=" build on ";
842fd76a 424 (*fctInfo)(date, time);
425 if (!date) date="unknown";
426 if (!time) time="unknown";
842fd76a 427 }
7dbfa7c9 428 HLTImportant("using %s plugin%s%s %s (%s%s)", libraryPath, buildOn, date, time, hLib.fMode==kStatic?"persistent, ":"", loadtype);
d4a18597 429 }
f3506ea2 430
431 // static registration of components when library is loaded
9ce4bf4a 432 iResult=RegisterScheduledComponents();
f3506ea2 433
f23a6e1a 434 } else {
f3506ea2 435 HLTError("can not load library %s (%s)", libraryPath, loadtype);
53feaef5 436#ifdef HAVE_DLFCN_H
85465857 437 HLTError("dlopen error: %s", dlerror());
53feaef5 438#endif //HAVE_DLFCN_H
0fe88043 439#ifdef __APPLE__
440 iResult=-EFTYPE;
441#else
f23a6e1a 442 iResult=-ELIBACC;
0fe88043 443#endif
f23a6e1a 444 }
2bbbadd1 445 AliHLTComponent::UnsetGlobalComponentHandler();
f3506ea2 446
447 if (iResult>=0) {
448 // alternative dynamic registration by library agents
449 // !!! has to be done after UnsetGlobalComponentHandler
7dbfa7c9 450 if (bActivateAgents) ActivateAgents(libName.Data());
f3506ea2 451 }
452
f23a6e1a 453 } else {
454 iResult=-EINVAL;
455 }
456 return iResult;
457}
458
459int AliHLTComponentHandler::UnloadLibrary( const char* libraryPath )
460{
70ed7d01 461 // see header file for class documentation
f23a6e1a 462 int iResult=0;
53feaef5 463 if (libraryPath) {
a742f6f8 464 vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
465 while (element!=fLibraryList.end()) {
5df0cbb9 466 TString* pName=reinterpret_cast<TString*>((*element).fName);
a742f6f8 467 if (pName->CompareTo(libraryPath)==0) {
468 UnloadLibrary(*element);
469 fLibraryList.erase(element);
470 break;
471 }
472 element++;
473 }
53feaef5 474 } else {
475 iResult=-EINVAL;
476 }
f23a6e1a 477 return iResult;
478}
479
a742f6f8 480int AliHLTComponentHandler::UnloadLibrary(AliHLTComponentHandler::AliHLTLibHandle &handle)
f23a6e1a 481{
70ed7d01 482 // see header file for class documentation
f23a6e1a 483 int iResult=0;
a742f6f8 484 fgAliLoggingFunc=NULL;
5df0cbb9 485 TString* pName=reinterpret_cast<TString*>(handle.fName);
dba03d72 486 if (handle.fMode!=kStatic) {
53feaef5 487#ifdef HAVE_DLFCN_H
13398559 488 // exeption does not help in Root context, the Root exeption
489 // handler always catches the exeption before. Have to find out
490 // how exeptions can be used in Root
491
492 /*try*/ {
f3506ea2 493 dlclose(handle.fHandle);
494 }
13398559 495 /*
f3506ea2 496 catch (...) {
497 HLTError("exeption caught during dlclose of library %s", pName!=NULL?pName->Data():"");
498 }
13398559 499 */
53feaef5 500#else
5df0cbb9 501 int* pCount=reinterpret_cast<int*>(handle.fHandle);
a742f6f8 502 if (--(*pCount)==0) {
c215072c 503 if (pName) {
a7222a6d 504 /** Matthias 26.04.2007
505 * I spent about a week to investigate a bug which seems to be in ROOT.
506 * Under certain circumstances, TSystem::Unload crashes. The crash occured
507 * for the first time, when libAliHLTUtil was loaded from AliHLTSystem right
508 * after the ComponentHandler was created. It does not occur when dlopen is
509 * used.
510 * It has most likely to do with the garbage collection and automatic
511 * cleanup in ROOT. The crash occurs when ROOT is terminated and before
512 * an instance of AliHLTSystem was created.
513 * root [0] AliHLTSystem gHLT
514 * It does not occur when the instance was created dynamically (but not even
515 * deleted)
516 * root [0] AliHLTSystem* gHLT=new AliHLTSystem
517 *
518 * For that reason, the libraries are not unloaded here, even though there
519 * will be memory leaks.
a742f6f8 520 gSystem->Unload(pName->Data());
a7222a6d 521 */
a742f6f8 522 }
523 else {
524 HLTError("missing library name, can not unload");
c215072c 525 }
a742f6f8 526 delete pCount;
527 }
528#endif //HAVE_DLFCN_H
a742f6f8 529 if (pName) {
530 HLTDebug("unload library %s", pName->Data());
a742f6f8 531 } else {
532 HLTWarning("missing name for unloaded library");
533 }
dba03d72 534 }
535 handle.fName=NULL;
536 handle.fHandle=NULL;
537 if (pName) {
538 delete pName;
539 }
a742f6f8 540 pName=NULL;
541 return iResult;
542}
543
544int AliHLTComponentHandler::UnloadLibraries()
545{
546 // see header file for class documentation
547 int iResult=0;
548 vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
549 while (element!=fLibraryList.end()) {
550 UnloadLibrary(*element);
c215072c 551 fLibraryList.erase(element);
552 element=fLibraryList.begin();
f23a6e1a 553 }
554 return iResult;
555}
9ce4bf4a 556
f331e6c5 557AliHLTfctVoid AliHLTComponentHandler::FindSymbol(const char* library, const char* symbol)
85f0cede 558{
559 // see header file for class documentation
560 AliHLTLibHandle* hLib=FindLibrary(library);
561 if (hLib==NULL) return NULL;
d93ec7ca 562 void (*pFunc)()=NULL;
85f0cede 563#ifdef HAVE_DLFCN_H
d93ec7ca 564 pFunc=(void (*)())dlsym(hLib->fHandle, symbol);
85f0cede 565#else
5df0cbb9 566 TString* name=reinterpret_cast<TString*>(hLib->fName);
d93ec7ca 567 pFunc=(void (*)())gSystem->DynFindSymbol(name->Data(), symbol);
85f0cede 568#endif
569 return pFunc;
570}
571
572AliHLTComponentHandler::AliHLTLibHandle* AliHLTComponentHandler::FindLibrary(const char* library)
573{
574 // see header file for class documentation
575 AliHLTLibHandle* hLib=NULL;
576 vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
577 while (element!=fLibraryList.end()) {
5df0cbb9 578 TString* name=reinterpret_cast<TString*>((*element).fName);
85f0cede 579 if (name->CompareTo(library)==0) {
580 hLib=&(*element);
581 break;
582 }
583 element++;
584 }
585 return hLib;
586}
587
9ce4bf4a 588int AliHLTComponentHandler::AddStandardComponents()
589{
70ed7d01 590 // see header file for class documentation
9ce4bf4a 591 int iResult=0;
592 AliHLTComponent::SetGlobalComponentHandler(this);
9ce4bf4a 593 AliHLTComponent::UnsetGlobalComponentHandler();
594 iResult=RegisterScheduledComponents();
595 return iResult;
596}
597
598int AliHLTComponentHandler::RegisterScheduledComponents()
599{
70ed7d01 600 // see header file for class documentation
9ce4bf4a 601 int iResult=0;
7bcd6cad 602 AliHLTComponentPList::iterator element=fScheduleList.begin();
9ce4bf4a 603 int iLocalResult=0;
604 while (element!=fScheduleList.end()) {
605 iLocalResult=RegisterComponent(*element);
606 if (iResult==0) iResult=iLocalResult;
607 fScheduleList.erase(element);
608 element=fScheduleList.begin();
609 }
610 return iResult;
611}
612
7dbfa7c9 613int AliHLTComponentHandler::ActivateAgents(const char* library, const char* blackList)
f3506ea2 614{
615 // see header file for class documentation
7dbfa7c9 616 vector<AliHLTModuleAgent*> agents;
617 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
9ebd6403 618 pAgent!=NULL;
7dbfa7c9 619 pAgent=AliHLTModuleAgent::GetNextAgent()) {
620
621 // check if we found the agent for the specified library
622 if (library) {
623 TString check="libAliHLT"; check+=pAgent->GetModuleId();
624 if (check.CompareTo(library)==0) {
625 agents.clear();
626 agents.push_back(pAgent);
627 break;
f3506ea2 628 }
7dbfa7c9 629 }
630
631 // check if the current agent is in the black list
632 if (blackList) {
585525d0 633 const char* found=strstr(blackList, pAgent->GetModuleId());
7dbfa7c9 634 if (found) {
635 found+=strlen(pAgent->GetModuleId());
636 // skip this agent as it is in the blacklist
637 if (*found==0 or *found==' ') continue;
f3506ea2 638 }
639 }
7dbfa7c9 640 agents.push_back(pAgent);
641 }
f3506ea2 642
7dbfa7c9 643 for (vector<AliHLTModuleAgent*>::iterator element=agents.begin();
644 element!=agents.end(); element++) {
645 (*element)->ActivateComponentHandler(this);
f3506ea2 646 }
7dbfa7c9 647
648 return agents.size();
f3506ea2 649}
650
cbd84228 651int AliHLTComponentHandler::DeleteOwnedComponents()
9ce4bf4a 652{
70ed7d01 653 // see header file for class documentation
9ce4bf4a 654 int iResult=0;
7bcd6cad 655 AliHLTComponentPList::iterator element=fOwnedComponents.begin();
f3506ea2 656 while (element!=fOwnedComponents.end()) {
5df0cbb9 657 //DeregisterComponent((*element)->GetComponentID());
13398559 658 // exeption does not help in Root context, the Root exeption
659 // handler always catches the exeption before. Have to find out
660 // how exeptions can be used in Root
661 /*try*/ {
cbd84228 662 delete *element;
663 }
13398559 664 /*
cbd84228 665 catch (...) {
666 HLTError("delete managed sample %p", *element);
667 }
13398559 668 */
f3506ea2 669 fOwnedComponents.erase(element);
670 element=fOwnedComponents.begin();
9ce4bf4a 671 }
672 return iResult;
673}
45c0a780 674
675int AliHLTComponentHandler::SetRunDescription(const AliHLTRunDesc* desc, const char* runType)
676{
677 // see header file for class documentation
678 if (!desc) return -EINVAL;
679 if (desc->fStructSize!=sizeof(AliHLTRunDesc)) {
680 HLTError("invalid size of RunDesc struct (%ul)", desc->fStructSize);
681 return -EINVAL;
682 }
683
684 memcpy(&fRunDesc, desc, sizeof(AliHLTRunDesc));
685 if (runType) {
686 if (fRunType) delete [] fRunType;
687 fRunType=new char[sizeof(runType)+1];
688 if (fRunType) {
689 strcpy(fRunType, runType);
690 }
691 }
692 return 0;
693}