// $Id$
-/**************************************************************************
- * This file is property of and copyright by the ALICE HLT Project *
- * ALICE Experiment at CERN, All rights reserved. *
- * *
- * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
- * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
- * for The ALICE HLT Project. *
- * *
- * Permission to use, copy, modify and distribute this software and its *
- * documentation strictly for non-commercial purposes is hereby granted *
- * without fee, provided that the above copyright notice appears in all *
- * copies and that both the copyright notice and this permission notice *
- * appear in the supporting documentation. The authors make no claims *
- * about the suitability of this software for any purpose. It is *
- * provided "as is" without express or implied warranty. *
- **************************************************************************/
-
-/** @file AliHLTComponentHandler.cxx
- @author Matthias Richter, Timm Steinbeck
- @date
- @brief Implementation of HLT component handler. */
-
-// see header file for class documentation
-// or
-// refer to README to build package
-// or
-// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
-
-#if __GNUC__>= 3
-using namespace std;
-#endif
+//**************************************************************************
+//* This file is property of and copyright by the *
+//* ALICE Experiment at CERN, All rights reserved. *
+//* *
+//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
+//* Timm Steinbeck <timm@kip.uni-heidelberg.de> *
+//* for The ALICE HLT Project. *
+//* *
+//* Permission to use, copy, modify and distribute this software and its *
+//* documentation strictly for non-commercial purposes is hereby granted *
+//* without fee, provided that the above copyright notice appears in all *
+//* copies and that both the copyright notice and this permission notice *
+//* appear in the supporting documentation. The authors make no claims *
+//* about the suitability of this software for any purpose. It is *
+//* provided "as is" without express or implied warranty. *
+//**************************************************************************
+
+/// @file AliHLTComponentHandler.cxx
+/// @author Matthias Richter, Timm Steinbeck
+/// @date
+/// @brief Implementation of HLT component handler.
+///
+
//#undef HAVE_DLFCN_H
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
//#include <Riostream.h>
#include <TSystem.h>
#endif //HAVE_DLFCN_H
-//#include "AliHLTStdIncludes.h"
#include "AliHLTComponentHandler.h"
#include "AliHLTComponent.h"
#include "AliHLTDataTypes.h"
fLibraryList(),
fEnvironment(),
fOwnedComponents(),
- fLibraryMode(kDynamic)
+ fLibraryMode(kDynamic),
+ fRunDesc(kAliHLTVoidRunDesc),
+ fRunType(NULL)
{
// see header file for class documentation
// or
// refer to README to build package
// or
// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
- memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
+ memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
+ fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
AddStandardComponents();
}
-AliHLTComponentHandler::AliHLTComponentHandler(AliHLTComponentEnvironment* pEnv)
+AliHLTComponentHandler::AliHLTComponentHandler(AliHLTAnalysisEnvironment* pEnv)
:
AliHLTLogging(),
fComponentList(),
fLibraryList(),
fEnvironment(),
fOwnedComponents(),
- fLibraryMode(kDynamic)
+ fLibraryMode(kDynamic),
+ fRunDesc(kAliHLTVoidRunDesc),
+ fRunType(NULL)
{
- // see header file for class documentation
+ // constructor with environment
if (pEnv) {
- memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment));
+ memcpy(&fEnvironment, pEnv, sizeof(AliHLTAnalysisEnvironment));
if (pEnv->fLoggingFunc) {
// the AliHLTLogging::Init method also sets the stream output
// and notification handler to AliLog. This should only be done
AliHLTLogging::Init(pEnv->fLoggingFunc);
}
} else {
- memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
+ memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
+ fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
}
//#ifndef __DEBUG
//SetLocalLoggingLevel(kHLTLogError);
AliHLTComponentHandler::~AliHLTComponentHandler()
{
- // see header file for class documentation
+ // destructor
DeleteOwnedComponents();
UnloadLibraries();
+ if (fRunType) delete [] fRunType;
+ fRunType=NULL;
}
AliHLTComponentHandler* AliHLTComponentHandler::fgpInstance=NULL;
AliHLTComponentHandler* AliHLTComponentHandler::CreateHandler()
{
- // see header file for class documentation
+ // create global instance of handler
if (!fgpInstance) fgpInstance=new AliHLTComponentHandler;
fgNofInstances++;
return fgpInstance;
int AliHLTComponentHandler::Destroy()
{
- // see header file for class documentation
+ // destroy/delete 'this', checks if 'this' pointer is the global instance,
+ // reduce the instance counter and delete if there are no instances left
+ // IMPORTANT: the object must be considered self-destroyed after the function
int nofInstances=0;
if (fgpInstance==this) {
- nofInstances=fgNofInstances--;
+ nofInstances=--fgNofInstances;
}
+ if (fgNofInstances==0) fgpInstance=NULL;
if (nofInstances==0) delete this;
return nofInstances;
}
int AliHLTComponentHandler::AnnounceVersion()
{
- // see header file for class documentation
+ // printout for version
int iResult=0;
#ifdef PACKAGE_STRING
- void HLTbaseCompileInfo( char*& date, char*& time);
- char* date="";
- char* time="";
+ extern void HLTbaseCompileInfo( const char*& date, const char*& time);
+ const char* date="";
+ const char* time="";
HLTbaseCompileInfo(date, time);
if (!date) date="unknown";
if (!time) time="unknown";
Int_t AliHLTComponentHandler::AddComponent(AliHLTComponent* pSample)
{
- // see header file for class documentation
+ // add and register a component, handler becomes owner
Int_t iResult=0;
if (pSample==NULL) return -EINVAL;
if ((iResult=RegisterComponent(pSample))>=0) {
Int_t AliHLTComponentHandler::RegisterComponent(AliHLTComponent* pSample)
{
- // see header file for class documentation
+ // register a component, handler creates clone of sample
Int_t iResult=0;
if (pSample) {
if (FindComponent(pSample->GetComponentID())==NULL) {
int AliHLTComponentHandler::DeregisterComponent( const char* componentID )
{
- // see header file for class documentation
+ // deregister component
int iResult=0;
if (componentID) {
Int_t AliHLTComponentHandler::ScheduleRegister(AliHLTComponent* pSample)
{
- // see header file for class documentation
+ // schedule registration
Int_t iResult=0;
if (pSample) {
fScheduleList.push_back(pSample);
return iResult;
}
-int AliHLTComponentHandler::CreateComponent(const char* componentID, void* pEnvParam, int argc, const char** argv, AliHLTComponent*& component, const char* cdbPath )
+int AliHLTComponentHandler::CreateComponent(const char* componentID, void* pEnvParam, int argc, const char** argv, AliHLTComponent*& component)
{
- // see header file for class documentation
+ // create a component
+ int iResult=CreateComponent(componentID, component);
+ if (iResult>=0 && component) {
+ HLTDebug("component \"%s\" created (%p)", componentID, component);
+ if ((iResult=component->Init(&fEnvironment, pEnvParam, argc, argv))!=0) {
+ HLTError("Initialization of component \"%s\" failed with error %d", componentID, iResult);
+ delete component;
+ component=NULL;
+ }
+ }
+ return iResult;
+}
+
+int AliHLTComponentHandler::CreateComponent(const char* componentID, AliHLTComponent*& component )
+{
+ // create a component
int iResult=0;
if (componentID) {
AliHLTComponent* pSample=FindComponent(componentID);
component=pSample->Spawn();
if (component) {
HLTDebug("component \"%s\" created (%p)", componentID, component);
- component->InitCDB(cdbPath, this);
- if ((iResult=component->Init(&fEnvironment, pEnvParam, argc, argv))!=0) {
- HLTError("Initialization of component \"%s\" failed with error %d", componentID, iResult);
- delete component;
- component=NULL;
- }
} else {
HLTError("can not spawn component \"%s\"", componentID);
iResult=-ENOENT;
Int_t AliHLTComponentHandler::FindComponentIndex(const char* componentID)
{
- // see header file for class documentation
+ // find component by ID in the list and return index
Int_t iResult=0;
if (componentID) {
AliHLTComponentPList::iterator element=fComponentList.begin();
AliHLTComponent* AliHLTComponentHandler::FindComponent(const char* componentID)
{
- // see header file for class documentation
+ // find component sample by ID
AliHLTComponent* pSample=NULL;
Int_t index=FindComponentIndex(componentID);
if (index>=0) {
Int_t AliHLTComponentHandler::InsertComponent(AliHLTComponent* pSample)
{
- // see header file for class documentation
+ // insert a component sample in the list
Int_t iResult=0;
if (pSample!=NULL) {
fComponentList.push_back(pSample);
void AliHLTComponentHandler::List()
{
- // see header file for class documentation
+ // print list content
+ // TODO: implement Print()
AliHLTComponentPList::iterator element=fComponentList.begin();
int index=0;
while (element!=fComponentList.end()) {
int AliHLTComponentHandler::HasOutputData( const char* componentID)
{
- // see header file for class documentation
+ // check if a component has output data
int iResult=0;
AliHLTComponent* pSample=FindComponent(componentID);
if (pSample) {
return iResult;
}
-void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv)
+void AliHLTComponentHandler::SetEnvironment(AliHLTAnalysisEnvironment* pEnv)
{
- // see header file for class documentation
+ // set global environment
if (pEnv) {
- memcpy(&fEnvironment, pEnv, sizeof(AliHLTComponentEnvironment));
+ memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
+ memcpy(&fEnvironment, pEnv, pEnv->fStructSize<sizeof(AliHLTAnalysisEnvironment)?pEnv->fStructSize:sizeof(AliHLTAnalysisEnvironment));
+ fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
if (fEnvironment.fLoggingFunc) {
// the AliHLTLogging::Init method also sets the stream output
// and notification handler to AliLog. This should only be done
AliHLTComponentHandler::TLibraryMode AliHLTComponentHandler::SetLibraryMode(TLibraryMode mode)
{
- // see header file for class documentation
+ // set library mode
TLibraryMode old=fLibraryMode;
fLibraryMode=mode;
return old;
int AliHLTComponentHandler::LoadLibrary( const char* libraryPath, int bActivateAgents)
{
- // see header file for class documentation
+ // load a library
int iResult=0;
if (libraryPath) {
- // first activate all agents which are already loaded
- if (bActivateAgents) ActivateAgents();
+ TString libName=libraryPath;
+ int slash=-1;
+ while ((slash=libName.Index("/"))>=0) {
+ libName=libName.Remove(0, slash+1);
+ }
+ libName.ReplaceAll(".so","");
// set the global component handler for static component registration
AliHLTComponent::SetGlobalComponentHandler(this);
hLib.fMode=fLibraryMode;
fLibraryList.insert(fLibraryList.begin(), hLib);
if (!phSearch) {
- HLTImportant("library %s loaded (%s%s)", libraryPath, hLib.fMode==kStatic?"persistent, ":"", loadtype);
- typedef void (*CompileInfo)( char*& date, char*& time);
+ typedef void (*CompileInfo)(const char*& date, const char*& time);
CompileInfo fctInfo=(CompileInfo)FindSymbol(libraryPath, "CompileInfo");
+ const char* date="";
+ const char* time="";
+ const char* buildOn="";
if (fctInfo) {
- char* date="";
- char* time="";
+ buildOn=" build on ";
(*fctInfo)(date, time);
if (!date) date="unknown";
if (!time) time="unknown";
- HLTImportant("build on %s (%s)", date, time);
- } else {
- HLTImportant("no build info available (possible AliRoot embedded build)");
}
+ HLTImportant("using %s plugin%s%s %s (%s%s)", libraryPath, buildOn, date, time, hLib.fMode==kStatic?"persistent, ":"", loadtype);
}
// static registration of components when library is loaded
if (iResult>=0) {
// alternative dynamic registration by library agents
// !!! has to be done after UnsetGlobalComponentHandler
- if (bActivateAgents) ActivateAgents();
+ if (bActivateAgents) ActivateAgents(libName.Data());
}
} else {
int AliHLTComponentHandler::UnloadLibrary( const char* libraryPath )
{
- // see header file for class documentation
+ // unload a library
int iResult=0;
if (libraryPath) {
vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
int AliHLTComponentHandler::UnloadLibrary(AliHLTComponentHandler::AliHLTLibHandle &handle)
{
- // see header file for class documentation
+ // unload a library
int iResult=0;
fgAliLoggingFunc=NULL;
TString* pName=reinterpret_cast<TString*>(handle.fName);
int AliHLTComponentHandler::UnloadLibraries()
{
- // see header file for class documentation
+ // unload all libraries
int iResult=0;
vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
while (element!=fLibraryList.end()) {
return iResult;
}
-void* AliHLTComponentHandler::FindSymbol(const char* library, const char* symbol)
+AliHLTfctVoid AliHLTComponentHandler::FindSymbol(const char* library, const char* symbol)
{
- // see header file for class documentation
+ // find symbol in library
AliHLTLibHandle* hLib=FindLibrary(library);
if (hLib==NULL) return NULL;
- void* pFunc=NULL;
+ void (*pFunc)()=NULL;
#ifdef HAVE_DLFCN_H
- pFunc=dlsym(hLib->fHandle, symbol);
+ pFunc=(void (*)())dlsym(hLib->fHandle, symbol);
#else
TString* name=reinterpret_cast<TString*>(hLib->fName);
- pFunc=gSystem->DynFindSymbol(name->Data(), symbol);
+ pFunc=(void (*)())gSystem->DynFindSymbol(name->Data(), symbol);
#endif
return pFunc;
}
AliHLTComponentHandler::AliHLTLibHandle* AliHLTComponentHandler::FindLibrary(const char* library)
{
- // see header file for class documentation
+ // find a library by name
AliHLTLibHandle* hLib=NULL;
vector<AliHLTLibHandle>::iterator element=fLibraryList.begin();
while (element!=fLibraryList.end()) {
int AliHLTComponentHandler::AddStandardComponents()
{
- // see header file for class documentation
+ // TODO: not quite clear what was the meaning behind this function
int iResult=0;
AliHLTComponent::SetGlobalComponentHandler(this);
AliHLTComponent::UnsetGlobalComponentHandler();
int AliHLTComponentHandler::RegisterScheduledComponents()
{
- // see header file for class documentation
+ // register all scheduled components
int iResult=0;
AliHLTComponentPList::iterator element=fScheduleList.begin();
int iLocalResult=0;
return iResult;
}
-int AliHLTComponentHandler::ActivateAgents(const AliHLTModuleAgent** blackList, int size)
+int AliHLTComponentHandler::ActivateAgents(const char* library, const char* blackList)
{
- // see header file for class documentation
- int iResult=0;
- AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
- while (pAgent && iResult>=0) {
- if (blackList) {
- int i=0;
- for (; i<size; i++) {
- if (blackList[i]==pAgent) break;
+ // activate module agents
+ vector<AliHLTModuleAgent*> agents;
+ for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
+ pAgent!=NULL;
+ pAgent=AliHLTModuleAgent::GetNextAgent()) {
+
+ // check if we found the agent for the specified library
+ if (library) {
+ TString check="libAliHLT"; check+=pAgent->GetModuleId();
+ if (check.CompareTo(library)==0) {
+ agents.clear();
+ agents.push_back(pAgent);
+ break;
}
- if (i<size) {
- // this agent was in the list
- pAgent=AliHLTModuleAgent::GetNextAgent();
- continue;
+ }
+
+ // check if the current agent is in the black list
+ if (blackList) {
+ const char* found=strstr(blackList, pAgent->GetModuleId());
+ if (found) {
+ found+=strlen(pAgent->GetModuleId());
+ // skip this agent as it is in the blacklist
+ if (*found==0 or *found==' ') continue;
}
}
+ agents.push_back(pAgent);
+ }
- pAgent->ActivateComponentHandler(this);
- pAgent=AliHLTModuleAgent::GetNextAgent();
+ for (vector<AliHLTModuleAgent*>::iterator element=agents.begin();
+ element!=agents.end(); element++) {
+ (*element)->ActivateComponentHandler(this);
}
- return iResult;
+
+ return agents.size();
}
int AliHLTComponentHandler::DeleteOwnedComponents()
{
- // see header file for class documentation
+ // delete all component samples owned by the handler
int iResult=0;
AliHLTComponentPList::iterator element=fOwnedComponents.begin();
while (element!=fOwnedComponents.end()) {
}
return iResult;
}
+
+int AliHLTComponentHandler::SetRunDescription(const AliHLTRunDesc* desc, const char* runType)
+{
+ // set global run description
+ if (!desc) return -EINVAL;
+ if (desc->fStructSize!=sizeof(AliHLTRunDesc)) {
+ HLTError("invalid size of RunDesc struct (%ul)", desc->fStructSize);
+ return -EINVAL;
+ }
+
+ memcpy(&fRunDesc, desc, sizeof(AliHLTRunDesc));
+ if (runType) {
+ if (fRunType) delete [] fRunType;
+ fRunType=new char[sizeof(runType)+1];
+ if (fRunType) {
+ strcpy(fRunType, runType);
+ }
+ }
+ return 0;
+}