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