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