]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
logging class extended and macros for easy log messages introduced, code changed...
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 26 Aug 2005 08:40:50 +0000 (08:40 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 26 Aug 2005 08:40:50 +0000 (08:40 +0000)
HLT/BASE/AliHLTComponentHandler.cxx
HLT/BASE/AliHLTConfiguration.cxx
HLT/BASE/AliHLTConfiguration.h
HLT/BASE/AliHLTDataTypes.h
HLT/BASE/AliHLTLogging.cxx
HLT/BASE/AliHLTLogging.h
HLT/BASE/AliHLTSystem.cxx
HLT/BASE/AliHLTSystem.h

index 7dfeef0f02662fdf30cbb4a6543ee835d05bf51b..b59ab3ff4a175f596cfe7748fbeb8898ccfb45c6 100644 (file)
@@ -55,11 +55,11 @@ Int_t AliHLTComponentHandler::RegisterComponent(AliHLTComponent* pSample)
     if (FindComponent(pSample->GetComponentID())==NULL) {
       iResult=InsertComponent(pSample);
       if (iResult>=0) {
-       Logging(kHLTLogInfo, "BASE", "Component Handler", "component %s registered", pSample->GetComponentID());
+       HLTInfo("component %s registered", pSample->GetComponentID());
       }
     } else {
       // component already registered
-      Logging(kHLTLogInfo, "BASE", "Component Handler", "component %s already registered, skipped", pSample->GetComponentID());
+      HLTInfo("component %s already registered, skipped", pSample->GetComponentID());
       iResult=-EEXIST;
     }
   } else {
@@ -92,14 +92,14 @@ 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);
+       HLTDebug("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);
+       HLTError("can not spawn component \"%s\"", componentID);
        iResult=-ENOENT;
       }
     } else {
-      Logging(kHLTLogWarning, "BASE", "Component Handler", "can not find component \"%s\"", componentID);
+      HLTWarning("can not find component \"%s\"", componentID);
       iResult=-ENOENT;
     }
   } else {
@@ -152,7 +152,7 @@ void AliHLTComponentHandler::List() {
   vector<AliHLTComponent*>::iterator element=fComponentList.begin();
   int index=0;
   while (element!=fComponentList.end()) {
-    Logging(kHLTLogInfo, "BASE", "Component Handler", "%d. %s", index++, (*element++)->GetComponentID());
+    HLTInfo("%d. %s", index++, (*element++)->GetComponentID());
   }
 }
 
@@ -170,7 +170,7 @@ int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
     AliHLTLibHandle hLib=dlopen(libraryPath, RTLD_NOW);
     if (hLib) {
       AliHLTComponent::UnsetGlobalComponentHandler();
-      Logging(kHLTLogDebug, "BASE", "Component Handler", "library %s loaded", libraryPath);
+      HLTDebug("library %s loaded", libraryPath);
       fLibraryList.push_back(hLib);
       vector<AliHLTComponent*>::iterator element=fScheduleList.begin();
       int iSize=fScheduleList.size();
@@ -182,8 +182,8 @@ int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
        fScheduleList.erase(element);
       }
     } else {
-      Logging(kHLTLogError, "BASE", "Component Handler", "can not load library %s", libraryPath);
-      Logging(kHLTLogError, "BASE", "Component Handler", "dlopen error: %s", dlerror());
+      HLTError("can not load library %s", libraryPath);
+      HLTError("dlopen error: %s", dlerror());
       iResult=-ELIBACC;
     }
   } else {
index 530b34c834b9bb8f94fbd191f283e25470c85d1f..d1351c6071606fde7a86b315e87a31dc9c9f7825 100644 (file)
@@ -34,6 +34,10 @@ using namespace std;
 
 ClassImp(AliHLTConfiguration)
 
+/* the global configuration handler which is used to automatically register the configuration
+ */
+AliHLTConfigurationHandler* AliHLTConfiguration::fConfigurationHandler=NULL;
+
 AliHLTConfiguration::AliHLTConfiguration()
 { 
   fID=NULL;
@@ -58,14 +62,20 @@ AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component,
     fNofSources=-1;
     fArguments=arguments;
     fListSrcElement=fListSources.begin();
-    AliHLTConfigurationHandler::RegisterConfiguration(this);
+    if (fConfigurationHandler) {
+      fConfigurationHandler->RegisterConfiguration(this);
+    } else {
+      HLTError("no configuration handler set, abort registration");
+    }
   }
 }
 
 AliHLTConfiguration::~AliHLTConfiguration()
 {
-  if (AliHLTConfigurationHandler::FindConfiguration(fID)!=NULL) {
-    AliHLTConfigurationHandler::RemoveConfiguration(this);
+  if (fConfigurationHandler) {
+    if (fConfigurationHandler->FindConfiguration(fID)!=NULL) {
+      fConfigurationHandler->RemoveConfiguration(this);
+    }
   }
   if (fArgv != NULL) {
     if (fArgc>0) {
@@ -78,6 +88,23 @@ AliHLTConfiguration::~AliHLTConfiguration()
   }
 }
 
+int AliHLTConfiguration::GlobalInit(AliHLTConfigurationHandler* pHandler)
+{
+  int iResult=0;
+  if (fConfigurationHandler!=NULL) {
+    fConfigurationHandler->Logging(kHLTLogWarning, "AliHLTConfiguration::GlobalInit", HLT_DEFAULT_LOG_KEYWORD, "configuration handler already initialized, overriding object %p", fConfigurationHandler);
+  }
+  fConfigurationHandler=pHandler;
+  return iResult;
+}
+
+int AliHLTConfiguration::GlobalDeinit()
+{
+  int iResult=0;
+  fConfigurationHandler=NULL;
+  return iResult;
+}
+
 const char* AliHLTConfiguration::GetName() const {
   if (fID)
     return fID;
@@ -129,8 +156,8 @@ int AliHLTConfiguration::SourcesResolved(int bAuto)
 {
   int iResult=0;
   if (fNofSources>=0 || bAuto && (iResult=ExtractSources())>=0) {
-    //Logging(kHLTLogDebug, "BASE", "Configuration", "fNofSources=%d", fNofSources);
-    //Logging(kHLTLogDebug, "BASE", "Configuration", "list size = %d", fListSources.size());
+    //HLTDebug("fNofSources=%d", fNofSources);
+    //HLTDebug("list size = %d", fListSources.size());
     iResult=fNofSources==(int)fListSources.size();
   }
   return iResult;
@@ -160,16 +187,17 @@ int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf)
 
 void AliHLTConfiguration::PrintStatus()
 {
-  Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", "status of configuration \"%s\" (%p)", GetName(), this);
-  if (fComponent) Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", "  - component: \"%s\"", fComponent);
-  else Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", "  - component string invalid");
-  if (fStringSources) Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", "  - sources: \"%s\"", fStringSources);
-  else Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", "  - no sources");
+  HLTLogKeyword("configuration status");
+  HLTMessage("status of configuration \"%s\" (%p)", GetName(), this);
+  if (fComponent) HLTMessage("  - component: \"%s\"", fComponent);
+  else HLTMessage("  - component string invalid");
+  if (fStringSources) HLTMessage("  - sources: \"%s\"", fStringSources);
+  else HLTMessage("  - no sources");
   if (SourcesResolved(1)<=0)
-    Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", "    there are unresolved sources");
+    HLTMessage("    there are unresolved sources");
   AliHLTConfiguration* pSrc=GetFirstSource();
   while (pSrc) {
-    Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", "    source \"%s\" (%p) resolved", pSrc->GetName(), pSrc);
+    HLTMessage("    source \"%s\" (%p) resolved", pSrc->GetName(), pSrc);
     pSrc=GetNextSource();
   }
 }
@@ -197,14 +225,19 @@ int AliHLTConfiguration::ExtractSources()
     if ((iResult=InterpreteString(fStringSources, tgtList))>=0) {
       fNofSources=tgtList.size();
       vector<char*>::iterator element=tgtList.begin();
-      while ((element=tgtList.begin())!=tgtList.end() && iResult>=0) {
-       AliHLTConfiguration* pConf=AliHLTConfigurationHandler::FindConfiguration(*element);
-       if (pConf) {
-         Logging(kHLTLogDebug, "BASE", "Configuration", "source \"%s\" inserted", pConf->GetName());
-         fListSources.push_back(pConf);
-       } else {
-         Logging(kHLTLogError, "BASE", "Configuration", "can not find source \"%s\"", (*element));
-         iResult=-ENOENT;
+      while ((element=tgtList.begin())!=tgtList.end()) {
+       if (fConfigurationHandler) {
+         AliHLTConfiguration* pConf=fConfigurationHandler->FindConfiguration(*element);
+         if (pConf) {
+           HLTDebug("source \"%s\" inserted", pConf->GetName());
+           fListSources.push_back(pConf);
+         } else {
+           HLTError("can not find source \"%s\"", (*element));
+           iResult=-ENOENT;
+         }
+       } else if (iResult>=0) {
+         iResult=-EFAULT;
+         HLTFatal("global configuration handler not initialized, can not resolve sources");
        }
        delete[] (*element);
        tgtList.erase(element);
@@ -222,14 +255,14 @@ int AliHLTConfiguration::ExtractArguments()
     vector<char*> tgtList;
     if ((iResult=InterpreteString(fArguments, tgtList))>=0) {
       fArgc=tgtList.size();
-      //Logging(kHLTLogDebug, "BASE", "Configuration", "found %d arguments", fArgc);
+      //HLTDebug("found %d arguments", fArgc);
       if (fArgc>0) {
        fArgv = new char*[fArgc];
        if (fArgv) {
          vector<char*>::iterator element=tgtList.begin();
          int i=0;
          while (element!=tgtList.end()) {
-           //Logging(kHLTLogDebug, "BASE", "Configuration Handler", "assign arguments %d (%s)", i, *element);
+           //HLTDebug("assign arguments %d (%s)", i, *element);
            fArgv[i++]=(*element);
            element++;
          }
@@ -246,7 +279,7 @@ int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argLis
 {
   int iResult=0;
   if (arg) {
-    //Logging(kHLTLogDebug, "BASE", "Configuration Handler", "interprete \"%s\"", arg);
+    //HLTDebug("interprete \"%s\"", arg);
     int i=0;
     int prec=-1;
     do {
@@ -256,7 +289,7 @@ int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argLis
          if (pEntry) {
            strncpy(pEntry, &arg[prec], i-prec);
            pEntry[i-prec]=0; // terminate string
-           //Logging(kHLTLogDebug, "BASE", "Configuration Handler", "create string \"%s\", insert at %d", pEntry, argList.size());
+           //HLTDebug("create string \"%s\", insert at %d", pEntry, argList.size());
            argList.push_back(pEntry);
          } else 
            iResult=-ENOMEM;
@@ -333,7 +366,7 @@ int AliHLTTask::Init(AliHLTConfiguration* fConf, AliHLTComponentHandler* pCH)
        iResult=pCH->CreateComponent(fConf->GetComponentID(), NULL, argc, argv, fpComponent);
        if (fpComponent) {
        } else {
-         Logging(kHLTLogError, "BASE", "AliHLTTask", "can not find component \"%s\"", fConf->GetComponentID());
+         HLTError("can not find component \"%s\"", fConf->GetComponentID());
        }
       }
     }
@@ -400,6 +433,7 @@ int AliHLTTask::FollowDependency(const char* id, TList* pTgtList)
 
 void AliHLTTask::PrintDependencyTree(const char* id, int bFromConfiguration)
 {
+  HLTLogKeyword("task dependencies");
   int iResult=0;
   TList tgtList;
   if (bFromConfiguration) {
@@ -410,7 +444,7 @@ void AliHLTTask::PrintDependencyTree(const char* id, int bFromConfiguration)
   } else
     iResult=FollowDependency(id, &tgtList);
   if (iResult>0) {
-    Logging(kHLTLogInfo, "BASE", "AliHLTTask", "     task \"%s\": dependency level %d ", GetName(), iResult);
+    HLTMessage("     task \"%s\": dependency level %d ", GetName(), iResult);
     TObjLink* lnk=tgtList.FirstLink();
     int i=iResult;
     char* pSpace = new char[iResult+1];
@@ -419,7 +453,7 @@ void AliHLTTask::PrintDependencyTree(const char* id, int bFromConfiguration)
       pSpace[i]=0;
       while (lnk) {
        TObject* obj=lnk->GetObject();
-       Logging(kHLTLogInfo, "BASE", "AliHLTTask", "     %s^-- %s ", &pSpace[i--], obj->GetName());
+       HLTMessage("     %s^-- %s ", &pSpace[i--], obj->GetName());
        lnk=lnk->Next();
       }
       delete [] pSpace;
@@ -456,7 +490,7 @@ int AliHLTTask::CheckDependencies()
   AliHLTConfiguration* pSrc=fpConfiguration->GetFirstSource();
   while (pSrc) {
     if (FindDependency(pSrc->GetName())==NULL) {
-      //Logging(kHLTLogDebug, "BASE", "AliHLTTask", "dependency \"%s\" unresolved", pSrc->GetName());
+      //HLTDebug("dependency \"%s\" unresolved", pSrc->GetName());
       iResult++;
     }
     pSrc=fpConfiguration->GetNextSource();
@@ -472,9 +506,9 @@ int AliHLTTask::Depends(AliHLTTask* pTask)
     if (fpConfiguration) {
       iResult=fpConfiguration->GetSource(pTask->GetName())!=NULL;
       if (iResult>0) {
-       //Logging(kHLTLogDebug, "BASE", "AliHLTTask", "task  \"%s\" depends on \"%s\"", GetName(), pTask->GetName());
+       //HLTDebug("task  \"%s\" depends on \"%s\"", GetName(), pTask->GetName());
       } else {
-       //Logging(kHLTLogDebug, "BASE", "AliHLTTask", "task  \"%s\" independend of \"%s\"", GetName(), pTask->GetName());
+       //HLTDebug("task  \"%s\" independend of \"%s\"", GetName(), pTask->GetName());
       }
     } else {
       iResult=-EFAULT;
@@ -531,10 +565,11 @@ int AliHLTTask::ClearSourceBlocks()
 
 void AliHLTTask::PrintStatus()
 {
+  HLTLogKeyword("task properties");
   if (fpComponent) {
-    Logging(kHLTLogInfo, "BASE", "AliHLTTask", "     component: %s (%p)", fpComponent->GetComponentID(), fpComponent);
+    HLTMessage("     component: %s (%p)", fpComponent->GetComponentID(), fpComponent);
   } else {
-    Logging(kHLTLogInfo, "BASE", "AliHLTTask", "     no component set!");
+    HLTMessage("     no component set!");
   }
   if (fpConfiguration) {
     AliHLTConfiguration* pSrc=fpConfiguration->GetFirstSource();
@@ -542,17 +577,17 @@ void AliHLTTask::PrintStatus()
       const char* pQualifier="unresolved";
       if (FindDependency(pSrc->GetName()))
        pQualifier="resolved";
-      Logging(kHLTLogInfo, "BASE", "AliHLTTask", "     source: %s (%s)", pSrc->GetName(), pQualifier);
+      HLTMessage("     source: %s (%s)", pSrc->GetName(), pQualifier);
       pSrc=fpConfiguration->GetNextSource();
     }
     TObjLink* lnk = fListTargets.FirstLink();
     while (lnk) {
       TObject *obj = lnk->GetObject();
-      Logging(kHLTLogInfo, "BASE", "AliHLTTask", "     target: %s", obj->GetName());
+      HLTMessage("     target: %s", obj->GetName());
       lnk = lnk->Next();
     }
   } else {
-    Logging(kHLTLogInfo, "BASE", "AliHLTTask", "     task \"%s\" not initialized", GetName());
+    HLTMessage("     task \"%s\" not initialized", GetName());
   }
 }
 
@@ -573,7 +608,7 @@ AliHLTConfigurationHandler::~AliHLTConfigurationHandler()
   while (lnk) {
     TObject* obj=lnk->GetObject();
     if (fListConfigurations.FindObject(obj->GetName())==NULL) {
-      Logging(kHLTLogDebug, "BASE", "Configuration Handler", "delete dynamic configuration \"%s\"", obj->GetName());
+      HLTDebug("delete dynamic configuration \"%s\"", obj->GetName());
       delete obj;
     }
     lnk=lnk->Next();
@@ -586,7 +621,7 @@ int AliHLTConfigurationHandler::RegisterConfiguration(AliHLTConfiguration* pConf
   if (pConf) {
     if (FindConfiguration(pConf->GetName()) == NULL) {
       fListConfigurations.Add(pConf);
-      //Logging(kHLTLogDebug, "BASE", "Configuration Handler", "configuration \"%s\" registered", pConf->GetName());
+      //HLTDebug("configuration \"%s\" registered", pConf->GetName());
 
       // mark all configurations with unresolved dependencies for re-evaluation
       TObjLink* lnk=fListConfigurations.FirstLink();
@@ -599,7 +634,7 @@ int AliHLTConfigurationHandler::RegisterConfiguration(AliHLTConfiguration* pConf
       }
     } else {
       iResult=-EEXIST;
-      Logging(kHLTLogWarning, "BASE", "Configuration Handler", "configuration \"%s\" already registered", pConf->GetName());
+      HLTWarning("configuration \"%s\" already registered", pConf->GetName());
     }
   } else {
     iResult=-EINVAL;
@@ -622,7 +657,7 @@ int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char*
       fListDynamicConfigurations.Add(pConf);
     }
   } else {
-    Logging(kHLTLogError, "BASE", "Configuration Handler", "system error: object allocation failed");
+    HLTError("system error: object allocation failed");
     iResult=-ENOMEM;
   }
   return iResult;
@@ -630,11 +665,12 @@ int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char*
 
 void AliHLTConfigurationHandler::PrintConfigurations()
 {
-  Logging(kHLTLogInfo, "BASE", "Configuration Handler", "registered configurations:");
+  HLTLogKeyword("configuration listing");
+  HLTMessage("registered configurations:");
   TObjLink *lnk = fListConfigurations.FirstLink();
   while (lnk) {
     TObject *obj = lnk->GetObject();
-    Logging(kHLTLogInfo, "BASE", "Configuration Handler", "  %s", obj->GetName());
+    HLTMessage("  %s", obj->GetName());
     lnk = lnk->Next();
   }
 }
@@ -647,7 +683,7 @@ int AliHLTConfigurationHandler::RemoveConfiguration(const char* id)
     if ((pConf=FindConfiguration(id))!=NULL) {
       iResult=RemoveConfiguration(pConf);
     } else {
-      Logging(kHLTLogWarning, "BASE", "Configuration Handler", "can not find configuration \"%s\"", id);
+      HLTWarning("can not find configuration \"%s\"", id);
       iResult=-ENOENT;
     }
   } else {
index 02c9527cca9c449314ada2c32aa474b17e739572..3add3f60e4b9425b355b2e527c37532a2c9d89c5 100644 (file)
@@ -15,7 +15,7 @@
 #include "AliHLTDataTypes.h"
 #include "AliHLTLogging.h"
 
-
+class AliHLTConfigurationHandler;
 /*****************************************************************************************************
  *
  * AliHLTConfiguration
@@ -39,6 +39,13 @@ class AliHLTConfiguration : public TObject, public AliHLTLogging {
   AliHLTConfiguration(const char* id, const char* component, const char* sources, const char* arguments);
   virtual ~AliHLTConfiguration();
 
+  /****************************************************************************************************
+   * global initialization
+   */
+  static int GlobalInit(AliHLTConfigurationHandler* pHandler);
+
+  static int GlobalDeinit();
+
   /****************************************************************************************************
    * properties
    */
@@ -91,7 +98,6 @@ class AliHLTConfiguration : public TObject, public AliHLTLogging {
 
  protected:
   
-  //int Logging( AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
 
  private:
   /* extract the source configurations from the sources string
@@ -118,6 +124,8 @@ class AliHLTConfiguration : public TObject, public AliHLTLogging {
   int fArgc;                        // number of arguments
   char** fArgv;                     // argument array
 
+  static AliHLTConfigurationHandler* fConfigurationHandler;
+
   ClassDef(AliHLTConfiguration, 0);
 };
 
@@ -247,20 +255,20 @@ class AliHLTConfigurationHandler : public AliHLTLogging {
    */
 
   // register a configuration to the global list of configurations
-  static int RegisterConfiguration(AliHLTConfiguration* pConf);
+  int RegisterConfiguration(AliHLTConfiguration* pConf);
 
   // create a configuration and register it
-  static int CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments);
+  int CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments);
 
   // remove a configuration from the global list
-  static int RemoveConfiguration(AliHLTConfiguration* pConf);
-  static int RemoveConfiguration(const char* id);
+  int RemoveConfiguration(AliHLTConfiguration* pConf);
+  int RemoveConfiguration(const char* id);
 
   // find a configuration from the global list
-  static AliHLTConfiguration* FindConfiguration(const char* id);
+  AliHLTConfiguration* FindConfiguration(const char* id);
 
   // print the registered configurations to the logging function
-  static void PrintConfigurations();
+  void PrintConfigurations();
 
 
  private:
index 7591a1ded50f23962b934d2302563aeae51a2a53..93249b17c6e0c029b30d7d8bb852c8e9d39989e0 100644 (file)
@@ -20,7 +20,7 @@ extern "C" {
 
   typedef AliHLTUInt64_t AliHLTEventID_t;
 
-  enum AliHLTComponent_LogSeverity { kHLTLogNone=0, kHLTLogBenchmark=1, kHLTLogDebug=2, kHLTLogInfo=4, kHLTLogWarning=8, kHLTLogError=16, kHLTLogFatal=32 };
+  enum AliHLTComponent_LogSeverity { kHLTLogNone=0, kHLTLogBenchmark=1, kHLTLogDebug=2, kHLTLogInfo=4, kHLTLogWarning=8, kHLTLogError=16, kHLTLogFatal=32, kHLTLogAll=0x3f, kHLTLogDefault=0x39 };
 
   struct AliHLTComponent_EventData
   {
index 18b3cda09bc0d558b97238e9477a8208651d8241..519359965f40b4c9badc871cba9fcfbbe7676acb 100644 (file)
@@ -39,11 +39,15 @@ ClassImp(AliHLTLogging)
 char AliHLTLogging::fLogBuffer[LOG_BUFFER_SIZE]="";
 char AliHLTLogging::fOriginBuffer[LOG_BUFFER_SIZE]="";
 
-AliHLTComponent_LogSeverity AliHLTLogging::fGlobalLogFilter=(AliHLTComponent_LogSeverity)0;
+AliHLTComponent_LogSeverity AliHLTLogging::fGlobalLogFilter=kHLTLogAll;
 AliHLTfctLogging AliHLTLogging::fLoggingFunc=NULL;
 
 AliHLTLogging::AliHLTLogging()
 {
+  fpDefaultKeyword=NULL;
+  fpCurrentKeyword=NULL;
+  //fLocalLogFilter=kHLTLogDefault;
+  fLocalLogFilter=kHLTLogAll;
 }
 
 
@@ -76,7 +80,10 @@ int AliHLTLogging::Message(void *param, AliHLTComponent_LogSeverity severity, co
   default:
     break;
   }
-  cout << "HLT Log " << strSeverity << ": " << origin << " (" << keyword << ") " << message << endl;
+  cout << "HLT Log " << strSeverity << ": " << origin << " " << message;
+  if (strcmp(keyword, HLT_DEFAULT_LOG_KEYWORD)!=0)
+    cout << " (" << keyword << ")";
+  cout << endl;
   return iResult;
 }
 
@@ -86,7 +93,9 @@ const char* AliHLTLogging::BuildLogString(const char *format, va_list ap) {
   char* tgtBuffer=fLogBuffer;
   tgtBuffer[tgtLen]=0;
 
+#if (defined LOG_PREFIX)
   tgtLen = snprintf(tgtBuffer, iBufferSize, LOG_PREFIX); // add logging prefix
+#endif
   if (tgtLen>=0) {
     tgtBuffer+=tgtLen; iBufferSize-=tgtLen;
     tgtLen = vsnprintf(tgtBuffer, iBufferSize, format, ap);
@@ -102,59 +111,63 @@ const char* AliHLTLogging::BuildLogString(const char *format, va_list ap) {
 }
 
 int AliHLTLogging::Logging(AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* format, ... ) {
-  va_list args;
-  va_start(args, format);
-  if (fLoggingFunc) {
-    return (*fLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
-  } else {
-    return Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
+  int iResult=CheckFilter(severity);
+  if (iResult>0) {
+    va_list args;
+    va_start(args, format);
+    if (fLoggingFunc) {
+      iResult = (*fLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
+    } else {
+      iResult = Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
+    }
   }
-  return -ENOSYS;
+  return iResult;
 }
 
 int AliHLTLogging::LoggingVarargs( AliHLTComponent_LogSeverity severity, const char* origin_class, const char* origin_func,  ... )
 {
-  int iResult=0;
-  int iMaxSize=LOG_BUFFER_SIZE-1;
-  int iPos=0;
-  const char* separator="";
-  fOriginBuffer[iPos]=0;
-  if (origin_class) {
-    if ((int)strlen(origin_class)<iMaxSize-iPos) {
-      strcpy(&fOriginBuffer[iPos], origin_class);
-      iPos+=strlen(origin_class);
-      separator="::";
+  int iResult=CheckFilter(severity);
+  if (iResult>0) {
+    int iMaxSize=LOG_BUFFER_SIZE-1;
+    int iPos=0;
+    const char* separator="";
+    fOriginBuffer[iPos]=0;
+    if (origin_class) {
+      if ((int)strlen(origin_class)<iMaxSize-iPos) {
+       strcpy(&fOriginBuffer[iPos], origin_class);
+       iPos+=strlen(origin_class);
+       separator="::";
+      }
     }
-  }
-  if (origin_func) {
-    if ((int)strlen(origin_func)+(int)strlen(separator)<iMaxSize-iPos) {
-      strcpy(&fOriginBuffer[iPos], separator);
-      iPos+=strlen(separator);
-      strcpy(&fOriginBuffer[iPos], origin_func);
-      iPos+=strlen(origin_func);
+    if (origin_func) {
+      if ((int)strlen(origin_func)+(int)strlen(separator)<iMaxSize-iPos) {
+       strcpy(&fOriginBuffer[iPos], separator);
+       iPos+=strlen(separator);
+       strcpy(&fOriginBuffer[iPos], origin_func);
+       iPos+=strlen(origin_func);
+      }
     }
+    va_list args;
+    va_start(args, origin_func);
+    const char* format = va_arg(args, const char*);
+
+    const char* message=format;
+    char* qualifier=NULL;
+    if ((qualifier=strchr(format, '%'))!=NULL) {
+      message=AliHLTLogging::BuildLogString(format, args);
+    }
+    if (fLoggingFunc) {
+      iResult=(*fLoggingFunc)(NULL/*fParam*/, severity, fOriginBuffer, GetKeyword(), message);
+    } else {
+      iResult=Message(NULL/*fParam*/, severity, fOriginBuffer, GetKeyword(), message);
+    }
+    va_end(args);
   }
-  va_list args;
-  va_start(args, origin_func);
-  const char* format = va_arg(args, const char*);
-
-  const char* message=format;
-  char* qualifier=NULL;
-  const char* keyword="no key";
-  if ((qualifier=strchr(format, '%'))!=NULL) {
-    message=AliHLTLogging::BuildLogString(format, args);
-  }
-  if (fLoggingFunc) {
-    iResult=(*fLoggingFunc)(NULL/*fParam*/, severity, fOriginBuffer, keyword, message);
-  } else {
-    iResult=Message(NULL/*fParam*/, severity, fOriginBuffer, keyword, message);
-  }
-  va_end(args);
   return iResult;
 }
 
 int AliHLTLogging::CheckFilter(AliHLTComponent_LogSeverity severity)
 {
-  int iResult=1;
+  int iResult=severity==kHLTLogNone || (severity&fGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0;
   return iResult;
 }
index 14ffce782ea5bc35dbcc043cf434c07a5a43e368..bc6b59469151b45d391cfd3115162c3236b1adb8 100644 (file)
 #include <stdio.h>
 
 #define LOG_BUFFER_SIZE 100 // global logging buffer
-#define LOG_PREFIX ""       // logging prefix, for later extensions
+//#define LOG_PREFIX ""       // logging prefix, for later extensions
 
-#define DebugMsg( ... ) LoggingVarargs(kHLTLogDebug, this->Class_Name() , __func__ ,  __VA_ARGS__ )
+
+/* the logging macros can be used inside methods of classes which inherit from 
+ * AliHLTLogging
+ */
+// HLTMessage is not filtered
+#define HLTMessage( ... )   LoggingVarargs(kHLTLogNone,      NULL , NULL ,  __VA_ARGS__ )
+
+// the following macros are filtered by the Global and Local Log Filter
+#define HLTBenchmark( ... ) LoggingVarargs(kHLTLogBenchmark, this->Class_Name() , __func__ ,  __VA_ARGS__ )
+#define HLTDebug( ... )     LoggingVarargs(kHLTLogDebug,     this->Class_Name() , __func__ ,  __VA_ARGS__ )
+#define HLTInfo( ... )      LoggingVarargs(kHLTLogInfo,      this->Class_Name() , __func__ ,  __VA_ARGS__ )
+#define HLTWarning( ... )   LoggingVarargs(kHLTLogWarning,   this->Class_Name() , __func__ ,  __VA_ARGS__ )
+#define HLTError( ... )     LoggingVarargs(kHLTLogError,     this->Class_Name() , __func__ ,  __VA_ARGS__ )
+#define HLTFatal( ... )     LoggingVarargs(kHLTLogFatal,     this->Class_Name() , __func__ ,  __VA_ARGS__ )
+
+// helper macro to set the keyword
+#define HLTLogKeyword(a)    AliHLTKeyword __hltlog_tmpkey__LINE__(this, a)
+
+#define HLT_DEFAULT_LOG_KEYWORD "no key"
 
 class AliHLTLogging {
 public:
   AliHLTLogging();
   virtual ~AliHLTLogging();
 
-  /* logging filter for all objects
-   */
+  // logging filter for all objects
+  //
   static AliHLTComponent_LogSeverity SetGlobalLogLevel(AliHLTComponent_LogSeverity iLogFilter) {fGlobalLogFilter=iLogFilter; return fGlobalLogFilter;}
 
-  /* logging filter for individual object
-   */
+  // logging filter for individual object
+  //
   AliHLTComponent_LogSeverity SetLocalLogLevel(AliHLTComponent_LogSeverity iLogFilter) {fLocalLogFilter=iLogFilter; return fLocalLogFilter;}
+
+  // set the default key word
+  // the keyword is intended to simplify the use of logging macros
+  // 
+  void SetDefaultKeyword(const char* keyword) { fpDefaultKeyword=keyword; }
+
+  // set a temporary keyword
+  // returns the old key value
+  const char* SetKeyword(const char* keyword) 
+    { 
+      const char* currentKeyword=fpCurrentKeyword;
+      fpCurrentKeyword=keyword;
+      return currentKeyword; 
+    }
+
+  // get the current keyword
+  //
+  const char* GetKeyword()
+    {
+      if (fpCurrentKeyword) return fpCurrentKeyword;
+      else if (fpDefaultKeyword) return fpDefaultKeyword;
+      return HLT_DEFAULT_LOG_KEYWORD;
+    }
   
   static int Init(AliHLTfctLogging pFun) { fLoggingFunc=pFun; return 0;}
 
   // genaral logging function
   //
-  static int Logging( AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
+  int Logging( AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
 
   // logging function with two origin parameters, used by the log macros
   //
@@ -59,8 +100,44 @@ private:
   static char fLogBuffer[LOG_BUFFER_SIZE];
   static char fOriginBuffer[LOG_BUFFER_SIZE];
   static AliHLTfctLogging fLoggingFunc;
+  const char* fpDefaultKeyword;
+  const char* fpCurrentKeyword;
 
   ClassDef(AliHLTLogging, 0)
 };
+
+/* the class AliHLTKeyword is a simple helper class used by the HLTLogKeyword macro
+ * HLTLogKeyword("a keyword") creates an object of AliHLTKeyword which sets the keyword for the logging class
+ * the object is destroyed automatically when the current scope is left and so the keyword is set
+ * to the original value
+ */
+class AliHLTKeyword {
+ public:
+  AliHLTKeyword()
+    {
+      fpParent=NULL;
+      fpOriginal=NULL;
+    }
+
+  AliHLTKeyword(AliHLTLogging* parent, const char* keyword)
+    {
+      fpOriginal=NULL;
+      if (parent) {
+       fpParent=parent;
+       fpOriginal=fpParent->SetKeyword(keyword);
+      }
+    }
+
+  ~AliHLTKeyword()
+    {
+      if (fpParent) {
+       fpParent->SetKeyword(fpOriginal);
+      }
+    }
+
+ private:
+  AliHLTLogging* fpParent;
+  const char* fpOriginal;
+};
 #endif
 
index 45851efbcea49f266d19644dd179b4da1c9eface..c619c39d65fbf2a84f1743cd23e5e99990c43df0 100644 (file)
@@ -48,14 +48,30 @@ AliHLTSystem::AliHLTSystem()
 
     // init logging function in AliHLTLogging
     Init(AliHLTLogging::Message);
+  } else {
+    HLTFatal("can not create Component Handler");
+  }
+  fpConfigurationHandler=new AliHLTConfigurationHandler();
+  if (fpConfigurationHandler) {
+    AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
+  } else {
+    HLTFatal("can not create Configuration Handler");
   }
-  DebugMsg("create hlt object %s %p", "AliHLTSystem", this);
-  DebugMsg("done");
 }
 
 
 AliHLTSystem::~AliHLTSystem()
 {
+    AliHLTConfiguration::GlobalDeinit();
+    if (fpConfigurationHandler) {
+      delete fpConfigurationHandler;
+    }
+    fpConfigurationHandler=NULL;
+
+    if (fpComponentHandler) {
+      delete fpComponentHandler;
+    }
+    fpComponentHandler=NULL;
 }
 
 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
@@ -83,12 +99,12 @@ int AliHLTSystem::BuildTaskList(AliHLTConfiguration* 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);
+       HLTError("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());
+       HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
        iResult=-ENOLINK;
     } else {
       pTask=new AliHLTTask(pConf, NULL);
@@ -99,9 +115,9 @@ int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
     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());
+       HLTError("detected ring dependency for configuration \"%s\"", pTask->GetName());
        pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
-       Logging(kHLTLogError, "BASE", "AliHLTSystem", "aborted ...");
+       HLTError("aborted ...");
        iResult=-ELOOP;
       }
       if (iResult>=0) {
@@ -151,16 +167,16 @@ int AliHLTSystem::InsertTask(AliHLTTask* pTask)
     lnk=fTaskList.FirstLink();
   while (lnk && iResult>0) {
     AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
-    //Logging(kHLTLogDebug, "BASE", "AliHLTSystem", "checking  \"%s\"", pCurr->GetName());
+    //HLTDebug("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());
+      HLTDebug("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());
+      HLTError("ring dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
       iResult=-ELOOP;
     } else if ((iResult=pTask->CheckDependencies())>0) {
       lnk = lnk->Next();
@@ -172,9 +188,9 @@ int AliHLTSystem::InsertTask(AliHLTTask* pTask)
       } else {
        fTaskList.AddFirst(pTask);
       }
-      Logging(kHLTLogDebug, "BASE", "AliHLTSystem", "task \"%s\" inserted", pTask->GetName());
+      HLTDebug("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);
+    HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
     iResult=-ENOLINK;
   }
   return iResult;
@@ -191,13 +207,14 @@ AliHLTTask* AliHLTSystem::FindTask(const char* id)
 
 void AliHLTSystem::PrintTaskList()
 {
+  HLTLogKeyword("task list");
   TObjLink *lnk = NULL;
-  Logging(kHLTLogInfo, "BASE", "AliHLTSystem", "Task List");
+  HLTMessage("Task List");
   lnk=fTaskList.FirstLink();
   while (lnk) {
     TObject* obj=lnk->GetObject();
     if (obj) {
-      Logging(kHLTLogInfo, "BASE", "AliHLTSystem", "  %s - status:", obj->GetName());
+      HLTMessage("  %s - status:", obj->GetName());
       AliHLTTask* pTask=(AliHLTTask*)obj;
       pTask->PrintStatus();
     } else {
index d1357d19d5ad74978c8a6a8477ab2c2d9a6587cd..b166dcd95473cf06d482f18c833df4e5b23fc041 100644 (file)
@@ -16,6 +16,7 @@
 
 class AliHLTComponentHandler;
 class AliHLTConfiguration;
+class AliHLTConfigurationHandler;
 class AliHLTTask;
 
 class AliHLTSystem : public AliHLTLogging {
@@ -24,6 +25,7 @@ class AliHLTSystem : public AliHLTLogging {
   virtual ~AliHLTSystem();
 
   AliHLTComponentHandler* fpComponentHandler;
+  AliHLTConfigurationHandler* fpConfigurationHandler;
 
   /* add a configuration to the end of the list
    */