From 5ec8e2819798e0700c86758de9f7163623a4b02d Mon Sep 17 00:00:00 2001 From: richterm Date: Mon, 22 Aug 2005 14:18:02 +0000 Subject: [PATCH] adaption to new logging class, added functionality to AliHLTSystem to build a task list from configurations --- HLT/BASE/AliHLTComponent.cxx | 9 -- HLT/BASE/AliHLTComponent.h | 4 +- HLT/BASE/AliHLTComponentHandler.cxx | 16 ++- HLT/BASE/AliHLTComponentHandler.h | 4 +- HLT/BASE/AliHLTDataTypes.h | 4 +- HLT/BASE/AliHLTLogging.cxx | 2 +- HLT/BASE/AliHLTLogging.h | 4 +- HLT/BASE/AliHLTSystem.cxx | 188 +++++++++++++++++++++------- HLT/BASE/AliHLTSystem.h | 63 +++++++--- HLT/BASE/HLTbaseLinkDef.h | 4 + HLT/BASE/Makefile | 3 +- 11 files changed, 215 insertions(+), 86 deletions(-) diff --git a/HLT/BASE/AliHLTComponent.cxx b/HLT/BASE/AliHLTComponent.cxx index bceb18de49b..ef5983bcb37 100644 --- a/HLT/BASE/AliHLTComponent.cxx +++ b/HLT/BASE/AliHLTComponent.cxx @@ -64,12 +64,3 @@ int AliHLTComponent::Deinit() iResult=DoDeinit(); return iResult; } - -int AliHLTComponent::Logging( AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* format, ... ) { - if (fEnvironment.fLoggingFunc) { - va_list args; - va_start(args, format); - return (*fEnvironment.fLoggingFunc)(fEnvironment.fParam, severity, origin, keyword, AliHLTSystem::BuildLogString(format, args )); - } - return -ENOSYS; -} diff --git a/HLT/BASE/AliHLTComponent.h b/HLT/BASE/AliHLTComponent.h index 1ce466ac0c6..62ab2df00f7 100644 --- a/HLT/BASE/AliHLTComponent.h +++ b/HLT/BASE/AliHLTComponent.h @@ -10,13 +10,14 @@ */ #include +#include "AliHLTLogging.h" #include "AliHLTDataTypes.h" #include "AliHLTDefinitions.h" #include "TObject.h" class AliHLTComponentHandler; -class AliHLTComponent { +class AliHLTComponent : public AliHLTLogging { public: AliHLTComponent(); virtual ~AliHLTComponent(); @@ -101,7 +102,6 @@ class AliHLTComponent { return -ENOSYS; } - int Logging( AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message, ... ); private: static AliHLTComponentHandler* fpComponentHandler; diff --git a/HLT/BASE/AliHLTComponentHandler.cxx b/HLT/BASE/AliHLTComponentHandler.cxx index 8e361d7054b..7dfeef0f026 100644 --- a/HLT/BASE/AliHLTComponentHandler.cxx +++ b/HLT/BASE/AliHLTComponentHandler.cxx @@ -92,8 +92,15 @@ int AliHLTComponentHandler::CreateComponent(const Char_t* componentID, void* env if (pSample!=NULL) { component=pSample->Spawn(); if (component) { + Logging(kHLTLogDebug, "BASE", "Component Handler", "component \"%s\" created (%p)", componentID, component); component->Init(&fEnvironment, environ_param, argc, argv); + } else { + Logging(kHLTLogError, "BASE", "Component Handler", "can not spawn component \"%s\"", componentID); + iResult=-ENOENT; } + } else { + Logging(kHLTLogWarning, "BASE", "Component Handler", "can not find component \"%s\"", componentID); + iResult=-ENOENT; } } else { iResult=-EINVAL; @@ -201,12 +208,3 @@ int AliHLTComponentHandler::UnloadLibraries() } return iResult; } - -int AliHLTComponentHandler::Logging(AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* format, ... ) { - if (fEnvironment.fLoggingFunc) { - va_list args; - va_start(args, format); - return (*fEnvironment.fLoggingFunc)( fEnvironment.fParam, severity, origin, keyword, AliHLTSystem::BuildLogString(format, args)); - } - return -ENOSYS; -} diff --git a/HLT/BASE/AliHLTComponentHandler.h b/HLT/BASE/AliHLTComponentHandler.h index 3876fe6a5b2..c853f5520a3 100644 --- a/HLT/BASE/AliHLTComponentHandler.h +++ b/HLT/BASE/AliHLTComponentHandler.h @@ -11,6 +11,7 @@ #include "TObject.h" #include "AliHLTDataTypes.h" +#include "AliHLTLogging.h" class AliHLTComponent; struct AliHLTComponentEnvironment; @@ -18,7 +19,7 @@ struct AliHLTComponent_DataType; typedef void* AliHLTLibHandle; -class AliHLTComponentHandler { +class AliHLTComponentHandler : public AliHLTLogging { public: AliHLTComponentHandler(); virtual ~AliHLTComponentHandler(); @@ -55,7 +56,6 @@ class AliHLTComponentHandler { */ void List(); protected: - int Logging( AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message, ... ); private: /* find a component diff --git a/HLT/BASE/AliHLTDataTypes.h b/HLT/BASE/AliHLTDataTypes.h index 14149b39f5a..7591a1ded50 100644 --- a/HLT/BASE/AliHLTDataTypes.h +++ b/HLT/BASE/AliHLTDataTypes.h @@ -72,6 +72,8 @@ extern "C" { void* fData; }; + typedef int (*AliHLTfctLogging)( void* param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message ); + struct AliHLTComponentEnvironment { AliHLTUInt32_t fStructSize; @@ -82,7 +84,7 @@ extern "C" { #endif int (*fMakeOutputDataBlockListFunc)( void* param, const vector& blocks, AliHLTUInt32_t* blockCount, AliHLTComponent_BlockData** outputBlocks ); int (*fGetEventDoneDataFunc)( void* param, AliHLTEventID_t eventID, unsigned long size, AliHLTComponent_EventDoneData** edd ); - int (*fLoggingFunc)( void* param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message ); + AliHLTfctLogging fLoggingFunc; }; } diff --git a/HLT/BASE/AliHLTLogging.cxx b/HLT/BASE/AliHLTLogging.cxx index 21363afebd3..18b3cda09bc 100644 --- a/HLT/BASE/AliHLTLogging.cxx +++ b/HLT/BASE/AliHLTLogging.cxx @@ -40,7 +40,7 @@ char AliHLTLogging::fLogBuffer[LOG_BUFFER_SIZE]=""; char AliHLTLogging::fOriginBuffer[LOG_BUFFER_SIZE]=""; AliHLTComponent_LogSeverity AliHLTLogging::fGlobalLogFilter=(AliHLTComponent_LogSeverity)0; -fctLogging AliHLTLogging::fLoggingFunc=NULL; +AliHLTfctLogging AliHLTLogging::fLoggingFunc=NULL; AliHLTLogging::AliHLTLogging() { diff --git a/HLT/BASE/AliHLTLogging.h b/HLT/BASE/AliHLTLogging.h index 63be1cb6f50..14ffce782ea 100644 --- a/HLT/BASE/AliHLTLogging.h +++ b/HLT/BASE/AliHLTLogging.h @@ -32,7 +32,7 @@ public: */ AliHLTComponent_LogSeverity SetLocalLogLevel(AliHLTComponent_LogSeverity iLogFilter) {fLocalLogFilter=iLogFilter; return fLocalLogFilter;} - static int Init(fctLogging pFun) { fLoggingFunc=pFun; return 0;} + static int Init(AliHLTfctLogging pFun) { fLoggingFunc=pFun; return 0;} // genaral logging function // @@ -58,7 +58,7 @@ private: AliHLTComponent_LogSeverity fLocalLogFilter; static char fLogBuffer[LOG_BUFFER_SIZE]; static char fOriginBuffer[LOG_BUFFER_SIZE]; - static fctLogging fLoggingFunc; + static AliHLTfctLogging fLoggingFunc; ClassDef(AliHLTLogging, 0) }; diff --git a/HLT/BASE/AliHLTSystem.cxx b/HLT/BASE/AliHLTSystem.cxx index 5d6429d5828..45851efbcea 100644 --- a/HLT/BASE/AliHLTSystem.cxx +++ b/HLT/BASE/AliHLTSystem.cxx @@ -33,20 +33,24 @@ using namespace std; #include "AliHLTSystem.h" #include "AliHLTComponentHandler.h" #include "AliHLTComponent.h" +#include "AliHLTConfiguration.h" ClassImp(AliHLTSystem) -char AliHLTSystem::fLogBuffer[LOG_BUFFER_SIZE]=""; - AliHLTSystem::AliHLTSystem() { fpComponentHandler=new AliHLTComponentHandler(); if (fpComponentHandler) { AliHLTComponentEnvironment env; memset(&env, 0, sizeof(AliHLTComponentEnvironment)); - env.fLoggingFunc=AliHLTSystem::Logging; + env.fLoggingFunc=AliHLTLogging::Message; fpComponentHandler->SetEnvironment(&env); + + // init logging function in AliHLTLogging + Init(AliHLTLogging::Message); } + DebugMsg("create hlt object %s %p", "AliHLTSystem", this); + DebugMsg("done"); } @@ -54,54 +58,150 @@ AliHLTSystem::~AliHLTSystem() { } -int AliHLTSystem::Logging(void *param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message) { +int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf) +{ + int iResult=0; + return iResult; +} + +// int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec) +// { +// int iResult=0; +// return iResult; +// } + +int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf) +{ + int iResult=0; + return iResult; +} + +int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf) +{ int iResult=0; - const char* strSeverity=""; - switch (severity) { - case kHLTLogBenchmark: - strSeverity="benchmark"; - break; - case kHLTLogDebug: - strSeverity="debug"; - break; - case kHLTLogInfo: - strSeverity="info"; - break; - case kHLTLogWarning: - strSeverity="warning"; - break; - case kHLTLogError: - strSeverity="error"; - break; - case kHLTLogFatal: - strSeverity="fatal"; - break; - default: - break; + if (pConf) { + AliHLTTask* pTask=NULL; + if ((pTask=FindTask(pConf->GetName()))!=NULL) { + if (pTask->GetConf()!=pConf) { + Logging(kHLTLogError, "BASE", "AliHLTSystem", "configuration missmatch, there is already a task with configuration name \"%s\", but it is different. Most likely configuration %p is not registered properly", pConf->GetName(), pConf); + iResult=-EEXIST; + pTask=NULL; + } + } else if (pConf->SourcesResolved(1)!=1) { + Logging(kHLTLogError, "BASE", "AliHLTSystem", "configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName()); + iResult=-ENOLINK; + } else { + pTask=new AliHLTTask(pConf, NULL); + if (pTask==NULL) { + iResult=-ENOMEM; + } + } + if (pTask) { + // check for ring dependencies + if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) { + Logging(kHLTLogError, "BASE", "AliHLTSystem", "detected ring dependency for configuration \"%s\"", pTask->GetName()); + pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/); + Logging(kHLTLogError, "BASE", "AliHLTSystem", "aborted ..."); + iResult=-ELOOP; + } + if (iResult>=0) { + // check whether all dependencies are already in the task list + // create the missing ones + fTaskList.Add(pTask); + AliHLTConfiguration* pDep=pConf->GetFirstSource(); + while (pDep!=NULL && iResult>=0) { + if (FindTask(pDep->GetName())==NULL) { + iResult=BuildTaskList(pDep); + } + pDep=pConf->GetNextSource(); + } + fTaskList.Remove(pTask); + + // insert the task and set the cross-links + if (iResult>=0) { + iResult=InsertTask(pTask); + } + } else { + delete pTask; + pTask=NULL; + } + } + } else { + iResult=-EINVAL; } - cout << "HLT Log " << strSeverity << ": " << origin << " (" << keyword << ") " << message << endl; return iResult; } -const char* AliHLTSystem::BuildLogString(const char *format, va_list ap) { - int tgtLen=0; - int iBufferSize=LOG_BUFFER_SIZE; - char* tgtBuffer=fLogBuffer; - tgtBuffer[tgtLen]=0; - - tgtLen = snprintf(tgtBuffer, iBufferSize, LOG_PREFIX); // add logging prefix - if (tgtLen>=0) { - tgtBuffer+=tgtLen; iBufferSize-=tgtLen; - tgtLen = vsnprintf(tgtBuffer, iBufferSize, format, ap); - if (tgtLen>0) { - tgtBuffer+=tgtLen; -// if (tgtLenGetObject()); + } + return iResult; +} + +int AliHLTSystem::InsertTask(AliHLTTask* pTask) +{ + int iResult=0; + TObjLink *lnk = NULL; + if ((iResult=pTask->CheckDependencies())>0) + lnk=fTaskList.FirstLink(); + while (lnk && iResult>0) { + AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject(); + //Logging(kHLTLogDebug, "BASE", "AliHLTSystem", "checking \"%s\"", pCurr->GetName()); + iResult=pTask->Depends(pCurr); + if (iResult>0) { + iResult=pTask->SetDependency(pCurr); + pCurr->SetTarget(pTask); + Logging(kHLTLogDebug, "BASE", "AliHLTSystem", "set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName()); } + if (pCurr->Depends(pTask)) { + // ring dependency + Logging(kHLTLogError, "BASE", "AliHLTSystem", "ring dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName()); + iResult=-ELOOP; + } else if ((iResult=pTask->CheckDependencies())>0) { + lnk = lnk->Next(); + } + } + if (iResult==0) { + if (lnk) { + fTaskList.AddAfter(lnk, pTask); + } else { + fTaskList.AddFirst(pTask); + } + Logging(kHLTLogDebug, "BASE", "AliHLTSystem", "task \"%s\" inserted", pTask->GetName()); + } else if (iResult>0) { + Logging(kHLTLogError, "BASE", "AliHLTSystem", "can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult); + iResult=-ENOLINK; } - return fLogBuffer; + return iResult; } +AliHLTTask* AliHLTSystem::FindTask(const char* id) +{ + AliHLTTask* pTask=NULL; + if (id) { + pTask=(AliHLTTask*)fTaskList.FindObject(id); + } + return pTask; +} +void AliHLTSystem::PrintTaskList() +{ + TObjLink *lnk = NULL; + Logging(kHLTLogInfo, "BASE", "AliHLTSystem", "Task List"); + lnk=fTaskList.FirstLink(); + while (lnk) { + TObject* obj=lnk->GetObject(); + if (obj) { + Logging(kHLTLogInfo, "BASE", "AliHLTSystem", " %s - status:", obj->GetName()); + AliHLTTask* pTask=(AliHLTTask*)obj; + pTask->PrintStatus(); + } else { + } + lnk = lnk->Next(); + } +} diff --git a/HLT/BASE/AliHLTSystem.h b/HLT/BASE/AliHLTSystem.h index b9885577982..d1357d19d5a 100644 --- a/HLT/BASE/AliHLTSystem.h +++ b/HLT/BASE/AliHLTSystem.h @@ -11,29 +11,62 @@ #include "AliL3RootTypes.h" -#include "AliHLTDataTypes.h" -#include -class AliHLTComponentHandler; +#include "AliHLTLogging.h" +#include -#define LOG_BUFFER_SIZE 100 // global logging buffer -#define LOG_PREFIX " " // logging prefix, for later extensions +class AliHLTComponentHandler; +class AliHLTConfiguration; +class AliHLTTask; -class AliHLTSystem { -public: +class AliHLTSystem : public AliHLTLogging { + public: AliHLTSystem(); virtual ~AliHLTSystem(); - Int_t SetLogLevel(Int_t iLogLevel) {return fLogLevel;} - static int Logging(void * param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message); - static const char* BuildLogString(const char *format, va_list ap); AliHLTComponentHandler* fpComponentHandler; -protected: -private: - Int_t fLogLevel; - static char fLogBuffer[LOG_BUFFER_SIZE]; + /* add a configuration to the end of the list + */ + int AddConfiguration(AliHLTConfiguration* pConf); + + /* add a configuration to the list after the specified configuration + */ + int InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec); + + /* remove a configuration from the list + */ + int DeleteConfiguration(AliHLTConfiguration* pConf); + + /* build a task list from the configuration list + */ + int BuildTaskList(AliHLTConfiguration* pConf); + + int CleanTaskList(); + + int InsertTask(AliHLTTask* pTask); + + AliHLTTask* FindTask(const char* id); + + void PrintTaskList(); + + /* run the task list + */ + int Run(); + + protected: + int ProcessTask(); + int StartEvent(); + int ProcessEvent(); + int StopEvent(); + + private: + TList fConfList; + int fbListChanged; + + TList fTaskList; - ClassDef(AliHLTSystem, 0) + private: + ClassDef(AliHLTSystem, 0); }; #endif diff --git a/HLT/BASE/HLTbaseLinkDef.h b/HLT/BASE/HLTbaseLinkDef.h index 7e55e67d8da..0a65e1bcdef 100644 --- a/HLT/BASE/HLTbaseLinkDef.h +++ b/HLT/BASE/HLTbaseLinkDef.h @@ -10,6 +10,10 @@ #pragma link C++ class AliHLTComponentHandler; #pragma link C++ class AliHLTProcessor; #pragma link C++ class AliHLTSystem; +#pragma link C++ class AliHLTConfiguration; +#pragma link C++ class AliHLTConfigurationHandler; +#pragma link C++ class AliHLTTask; +#pragma link C++ class AliHLTLogging; #endif diff --git a/HLT/BASE/Makefile b/HLT/BASE/Makefile index 3006a95c6bb..6424aa026eb 100644 --- a/HLT/BASE/Makefile +++ b/HLT/BASE/Makefile @@ -17,7 +17,8 @@ include $(ALIHLT_TOPDIR)/Makefile.conf SRCS = AliHLTComponent.cxx AliHLTComponentHandler.cxx \ AliHLTSystem.cxx AliHLT_C_Component_WrapperInterface.cxx \ - AliHLTProcessor.cxx + AliHLTProcessor.cxx AliHLTConfiguration.cxx \ + AliHLTLogging.cxx SRCS += $(EXTRA_SRCS) -- 2.39.3