LCOV - code coverage report
Current view: top level - HLT/BASE - AliHLTComponentHandler.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 190 284 66.9 %
Date: 2016-06-14 17:26:59 Functions: 26 36 72.2 %

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

Generated by: LCOV version 1.11