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