fScheduleList(),
fLibraryList(),
fEnvironment(),
- fOwnedComponents()
+ fOwnedComponents(),
+ 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(),
fScheduleList(),
fLibraryList(),
fEnvironment(),
- fOwnedComponents()
+ fOwnedComponents(),
+ fLibraryMode(kDynamic),
+ fRunDesc(kAliHLTVoidRunDesc),
+ fRunType(NULL)
{
// see header file for class documentation
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);
// see header file for class documentation
DeleteOwnedComponents();
UnloadLibraries();
+ if (fRunType) delete [] fRunType;
+ fRunType=NULL;
+}
+
+AliHLTComponentHandler* AliHLTComponentHandler::fgpInstance=NULL;
+int AliHLTComponentHandler::fgNofInstances=0;
+
+AliHLTComponentHandler* AliHLTComponentHandler::CreateHandler()
+{
+ // see header file for class documentation
+ if (!fgpInstance) fgpInstance=new AliHLTComponentHandler;
+ fgNofInstances++;
+ return fgpInstance;
+}
+
+int AliHLTComponentHandler::Destroy()
+{
+ // see header file for class documentation
+ int nofInstances=0;
+ if (fgpInstance==this) {
+ nofInstances=fgNofInstances--;
+ }
+ if (nofInstances==0) delete this;
+ return nofInstances;
}
int AliHLTComponentHandler::AnnounceVersion()
// see header file for class documentation
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";
- HLTInfo("%s build on %s (%s)", PACKAGE_STRING, date, time);
+ HLTImportant("%s build on %s (%s)", PACKAGE_STRING, date, time);
#else
- HLTInfo("ALICE High Level Trigger build on %s (%s) (embedded AliRoot build)", __DATE__, __TIME__);
+ HLTImportant("ALICE High Level Trigger build on %s (%s) (embedded AliRoot build)", __DATE__, __TIME__);
#endif
return iResult;
}
return iResult;
}
-int AliHLTComponentHandler::CreateComponent(const char* componentID, void* pEnvParam, int argc, const char** argv, AliHLTComponent*& component )
+int AliHLTComponentHandler::CreateComponent(const char* componentID, void* pEnvParam, int argc, const char** argv, AliHLTComponent*& component)
+{
+ // see header file for class documentation
+ 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 )
{
// see header file for class documentation
int iResult=0;
component=pSample->Spawn();
if (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;
- }
} else {
HLTError("can not spawn component \"%s\"", componentID);
iResult=-ENOENT;
return iResult;
}
-void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv)
+void AliHLTComponentHandler::SetEnvironment(AliHLTAnalysisEnvironment* pEnv)
{
// see header file for class documentation
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
// see header file for class documentation
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);
AliHLTLibHandle hLib;
+ AliHLTLibHandle* phSearch=FindLibrary(libraryPath);
const char* loadtype="";
#ifdef HAVE_DLFCN_H
// use interface to the dynamic linking loader
- try {
+
+ // exeption does not help in Root context, the Root exeption
+ // handler always catches the exeption before. Have to find out
+ // how exeptions can be used in Root
+ /*try*/ {
hLib.fHandle=dlopen(libraryPath, RTLD_NOW);
loadtype="dlopen";
}
+ /*
catch (...) {
// error message printed further down
loadtype="dlopen exeption";
}
+ */
#else
// use ROOT dynamic loader
// check if the library was already loaded, as Load returns
// 'failure' if the library was already loaded
- try {
- AliHLTLibHandle* pLib=FindLibrary(libraryPath);
- if (pLib) {
- int* pRootHandle=reinterpret_cast<int*>(pLib->fHandle);
+ /*try*/ {
+ if (phSearch) {
+ int* pRootHandle=reinterpret_cast<int*>(phSearch->fHandle);
(*pRootHandle)++;
HLTDebug("instance %d of library %s loaded", (*pRootHandle), libraryPath);
hLib.fHandle=pRootHandle;
}
- if (hLib.fHandle==NULL && gSystem->Load(libraryPath)==0) {
+ if (hLib.fHandle==NULL && gSystem->Load(libraryPath)>=0) {
int* pRootHandle=new int;
if (pRootHandle) *pRootHandle=1;
hLib.fHandle=pRootHandle;
}
loadtype="gSystem";
}
+ /*
catch (...) {
// error message printed further down
loadtype="gSystem exeption";
}
+ */
#endif //HAVE_DLFCN_H
if (hLib.fHandle!=NULL) {
// create TString object to store library path and use pointer as handle
hLib.fName=new TString(libraryPath);
hLib.fMode=fLibraryMode;
- HLTInfo("library %s loaded (%s%s)", libraryPath, hLib.fMode==kStatic?"persistent, ":"", loadtype);
fLibraryList.insert(fLibraryList.begin(), hLib);
- typedef void (*CompileInfo)( char*& date, char*& time);
+ if (!phSearch) {
+ 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";
- HLTInfo("build on %s (%s)", date, time);
- } else {
- HLTInfo("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 {
TString* pName=reinterpret_cast<TString*>(handle.fName);
if (handle.fMode!=kStatic) {
#ifdef HAVE_DLFCN_H
- try {
+ // exeption does not help in Root context, the Root exeption
+ // handler always catches the exeption before. Have to find out
+ // how exeptions can be used in Root
+
+ /*try*/ {
dlclose(handle.fHandle);
}
+ /*
catch (...) {
HLTError("exeption caught during dlclose of library %s", pName!=NULL?pName->Data():"");
}
+ */
#else
int* pCount=reinterpret_cast<int*>(handle.fHandle);
if (--(*pCount)==0) {
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
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;
}
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;
+ vector<AliHLTModuleAgent*> agents;
+ for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
+ pAgent && iResult>=0;
+ 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()
AliHLTComponentPList::iterator element=fOwnedComponents.begin();
while (element!=fOwnedComponents.end()) {
//DeregisterComponent((*element)->GetComponentID());
- try {
+ // exeption does not help in Root context, the Root exeption
+ // handler always catches the exeption before. Have to find out
+ // how exeptions can be used in Root
+ /*try*/ {
delete *element;
}
+ /*
catch (...) {
HLTError("delete managed sample %p", *element);
}
+ */
fOwnedComponents.erase(element);
element=fOwnedComponents.begin();
}
return iResult;
}
+
+int AliHLTComponentHandler::SetRunDescription(const AliHLTRunDesc* desc, const char* runType)
+{
+ // see header file for class documentation
+ 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;
+}