base class for logging functions and configuration scheme created
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 22 Aug 2005 14:11:35 +0000 (14:11 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 22 Aug 2005 14:11:35 +0000 (14:11 +0000)
HLT/BASE/AliHLTConfiguration.cxx [new file with mode: 0644]
HLT/BASE/AliHLTConfiguration.h [new file with mode: 0644]
HLT/BASE/AliHLTLogging.cxx [new file with mode: 0644]
HLT/BASE/AliHLTLogging.h [new file with mode: 0644]

diff --git a/HLT/BASE/AliHLTConfiguration.cxx b/HLT/BASE/AliHLTConfiguration.cxx
new file mode 100644 (file)
index 0000000..530b34c
--- /dev/null
@@ -0,0 +1,688 @@
+// $Id$
+
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: Matthias Richter <Matthias.Richter@ift.uib.no>                *
+ *          for The ALICE Off-line 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.                  *
+ **************************************************************************/
+
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+// HLT configuration handling                                             //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#if __GNUC__== 3
+using namespace std;
+#endif
+
+#include <errno.h>
+#include "AliHLTConfiguration.h"
+#include "AliHLTComponent.h"
+#include "AliHLTComponentHandler.h"
+#include <iostream>
+#include <string.h>
+
+ClassImp(AliHLTConfiguration)
+
+AliHLTConfiguration::AliHLTConfiguration()
+{ 
+  fID=NULL;
+  fComponent=NULL;
+  fStringSources=NULL;
+  fNofSources=-1;
+  fArguments=NULL;
+  fArgc=-1;
+  fArgv=NULL;
+  fListSrcElement=fListSources.begin();
+}
+
+AliHLTConfiguration::AliHLTConfiguration(const char* id, const char* component, const char* sources, const char* arguments)
+{
+  fArgc=-1;
+  fArgv=NULL;
+  
+  if (id && component) {
+    fID=id;
+    fComponent=component;
+    fStringSources=sources;
+    fNofSources=-1;
+    fArguments=arguments;
+    fListSrcElement=fListSources.begin();
+    AliHLTConfigurationHandler::RegisterConfiguration(this);
+  }
+}
+
+AliHLTConfiguration::~AliHLTConfiguration()
+{
+  if (AliHLTConfigurationHandler::FindConfiguration(fID)!=NULL) {
+    AliHLTConfigurationHandler::RemoveConfiguration(this);
+  }
+  if (fArgv != NULL) {
+    if (fArgc>0) {
+      for (int i=0; i<fArgc; i++) {
+       delete[] fArgv[i];
+      }
+    }
+    delete[] fArgv;
+    fArgv=NULL;
+  }
+}
+
+const char* AliHLTConfiguration::GetName() const {
+  if (fID)
+    return fID;
+  return TObject::GetName();
+}
+
+AliHLTConfiguration* AliHLTConfiguration::GetSource(const char* id)
+{
+  AliHLTConfiguration* pSrc=NULL;
+  if (id) {
+    // first check the current element
+    if (fListSrcElement!=fListSources.end() && strcmp(id, (*fListSrcElement)->GetName())==0) {
+      pSrc=*fListSrcElement;
+      } else {
+      // check the list
+
+      pSrc=GetFirstSource();
+      while (pSrc) {
+       if (strcmp(id, pSrc->GetName())==0)
+         break;
+       pSrc=GetNextSource();
+      }
+    }
+  }
+  return pSrc;
+}
+
+AliHLTConfiguration* AliHLTConfiguration::GetFirstSource()
+{
+  AliHLTConfiguration* pSrc=NULL;
+  if (fNofSources>=0 || ExtractSources()) {
+    fListSrcElement=fListSources.begin();
+    if (fListSrcElement!=fListSources.end()) pSrc=*fListSrcElement;
+  } 
+  return pSrc;
+}
+
+AliHLTConfiguration* AliHLTConfiguration::GetNextSource()
+{
+  AliHLTConfiguration* pSrc=NULL;
+  if (fNofSources>0) {
+    if (fListSrcElement!=fListSources.end() && (++fListSrcElement)!=fListSources.end()) 
+      pSrc=*fListSrcElement;
+  } 
+  return pSrc;
+}
+
+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());
+    iResult=fNofSources==(int)fListSources.size();
+  }
+  return iResult;
+}
+
+int AliHLTConfiguration::InvalidateSource(AliHLTConfiguration* pConf)
+{
+  int iResult=0;
+  if (pConf) {
+    vector<AliHLTConfiguration*>::iterator element=fListSources.begin();
+    while (element!=fListSources.end()) {
+      if (*element==pConf) {
+       fListSources.erase(element);
+       fListSrcElement=fListSources.end();
+       // there is no need to re-evaluate until there was a new configuration registered
+       // -> postpone the invalidation, its done in AliHLTConfigurationHandler::RegisterConfiguration
+       //InvalidateSources();
+       break;
+      }
+      element++;
+    }
+  } else {
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
+
+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");
+  if (SourcesResolved(1)<=0)
+    Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", "    there are unresolved sources");
+  AliHLTConfiguration* pSrc=GetFirstSource();
+  while (pSrc) {
+    Logging(kHLTLogInfo, "BASE", "AliHLTConfiguration", "    source \"%s\" (%p) resolved", pSrc->GetName(), pSrc);
+    pSrc=GetNextSource();
+  }
+}
+
+int AliHLTConfiguration::GetArguments(int* pArgc, const char*** pArgv)
+{
+  int iResult=0;
+  if (pArgc && pArgv) {
+    *pArgc=fArgc;
+    *pArgv=(const char**)fArgv;
+  } else {
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
+
+
+int AliHLTConfiguration::ExtractSources()
+{
+  int iResult=0;
+  fNofSources=0;
+  if (fStringSources!=NULL) {
+    vector<char*> tgtList;
+    fListSources.clear();
+    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;
+       }
+       delete[] (*element);
+       tgtList.erase(element);
+      }
+      fListSrcElement=fListSources.begin();
+    }
+  }
+  return iResult;
+}
+
+int AliHLTConfiguration::ExtractArguments()
+{
+  int iResult=0;
+  if (fArguments!=NULL) {
+    vector<char*> tgtList;
+    if ((iResult=InterpreteString(fArguments, tgtList))>=0) {
+      fArgc=tgtList.size();
+      //Logging(kHLTLogDebug, "BASE", "Configuration", "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);
+           fArgv[i++]=(*element);
+           element++;
+         }
+       } else {
+         iResult=-ENOMEM;
+       }
+      }
+    }
+  }
+  return iResult;
+}
+
+int AliHLTConfiguration::InterpreteString(const char* arg, vector<char*>& argList)
+{
+  int iResult=0;
+  if (arg) {
+    //Logging(kHLTLogDebug, "BASE", "Configuration Handler", "interprete \"%s\"", arg);
+    int i=0;
+    int prec=-1;
+    do {
+      if (arg[i]==0 || arg[i]==' ') {
+       if (prec>=0) {
+         char* pEntry= new char[i-prec+1];
+         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());
+           argList.push_back(pEntry);
+         } else 
+           iResult=-ENOMEM;
+         prec=-1;
+       }
+      } else if (prec==-1) prec=i;
+    } while (arg[i++]!=0 && iResult>=0); 
+  } else {
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
+
+int AliHLTConfiguration::FollowDependency(const char* id, TList* pTgtList)
+{
+  int iResult=0;
+  if (id) {
+    AliHLTConfiguration* pDep=NULL;
+    if ((pDep=GetSource(id))!=NULL) {
+      if (pTgtList) pTgtList->Add(pDep);
+      iResult++;
+    } else {
+      pDep=GetFirstSource();
+      while (pDep && iResult==0) {
+       if ((iResult=pDep->FollowDependency(id, pTgtList))>0) {
+         if (pTgtList) pTgtList->AddFirst(pDep);
+         iResult++;
+       }
+       pDep=GetNextSource();
+      }
+    }
+  } else {
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ClassImp(AliHLTTask)
+
+AliHLTTask::AliHLTTask()
+{
+  fpConfiguration=NULL;
+  fpComponent=NULL;
+  fpBlockDataArray=NULL;
+}
+
+AliHLTTask::AliHLTTask(AliHLTConfiguration* fConf, AliHLTComponentHandler* pCH)
+{
+  fpConfiguration=NULL;
+  fpComponent=NULL;
+  fpBlockDataArray=NULL;
+  Init(fConf, pCH);
+}
+
+AliHLTTask::~AliHLTTask()
+{
+  if (fpComponent) delete fpComponent;
+  fpComponent=NULL;
+  if (fpBlockDataArray) delete[] fpBlockDataArray;
+  fpBlockDataArray=NULL;
+}
+
+int AliHLTTask::Init(AliHLTConfiguration* fConf, AliHLTComponentHandler* pCH)
+{
+  int iResult=0;
+  if (fConf) {
+    fpConfiguration=fConf;
+    if (pCH) {
+      int argc=0;
+      const char** argv=NULL;
+      if ((iResult=fConf->GetArguments(&argc, &argv))>=0) {
+       iResult=pCH->CreateComponent(fConf->GetComponentID(), NULL, argc, argv, fpComponent);
+       if (fpComponent) {
+       } else {
+         Logging(kHLTLogError, "BASE", "AliHLTTask", "can not find component \"%s\"", fConf->GetComponentID());
+       }
+      }
+    }
+  } else {
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
+
+const char *AliHLTTask::GetName() const
+{
+  if (fpConfiguration)
+    return fpConfiguration->GetName();
+  return TObject::GetName();
+}
+
+AliHLTConfiguration* AliHLTTask::GetConf()
+{
+  return fpConfiguration;
+}
+
+AliHLTComponent* AliHLTTask::GetComponent()
+{
+  return fpComponent;
+}
+
+AliHLTTask* AliHLTTask::FindDependency(const char* id)
+{
+  AliHLTTask* pTask=NULL;
+  if (id) {
+    pTask=(AliHLTTask*)fListDependencies.FindObject(id);
+  }
+  return pTask;
+}
+
+int AliHLTTask::FollowDependency(const char* id, TList* pTgtList)
+{
+  int iResult=0;
+  if (id) {
+    AliHLTTask* pDep=NULL;
+    if ((pDep=(AliHLTTask*)fListDependencies.FindObject(id))!=NULL) {
+      if (pTgtList) pTgtList->Add(pDep);
+      iResult++;
+    } else {
+      TObjLink* lnk=fListDependencies.FirstLink();
+      while (lnk && iResult==0) {
+       pDep=(AliHLTTask*)lnk->GetObject();
+       if (pDep) {
+         if ((iResult=pDep->FollowDependency(id, pTgtList))>0) {
+           if (pTgtList) pTgtList->AddFirst(pDep);
+           iResult++;
+         }
+       } else {
+         iResult=-EFAULT;
+       }
+       lnk=lnk->Next();
+      }
+    }
+  } else {
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
+
+void AliHLTTask::PrintDependencyTree(const char* id, int bFromConfiguration)
+{
+  int iResult=0;
+  TList tgtList;
+  if (bFromConfiguration) {
+    if (fpConfiguration)
+      iResult=fpConfiguration->FollowDependency(id, &tgtList);
+    else
+      iResult=-EFAULT;
+  } else
+    iResult=FollowDependency(id, &tgtList);
+  if (iResult>0) {
+    Logging(kHLTLogInfo, "BASE", "AliHLTTask", "     task \"%s\": dependency level %d ", GetName(), iResult);
+    TObjLink* lnk=tgtList.FirstLink();
+    int i=iResult;
+    char* pSpace = new char[iResult+1];
+    if (pSpace) {
+      memset(pSpace, 32, iResult);
+      pSpace[i]=0;
+      while (lnk) {
+       TObject* obj=lnk->GetObject();
+       Logging(kHLTLogInfo, "BASE", "AliHLTTask", "     %s^-- %s ", &pSpace[i--], obj->GetName());
+       lnk=lnk->Next();
+      }
+      delete [] pSpace;
+    } else {
+      iResult=-ENOMEM;
+    }
+  }
+}
+
+int AliHLTTask::InsertBlockData(AliHLTComponent_BlockData* pBlock, AliHLTTask* pSource)
+{
+  int iResult=0;
+  return iResult;
+}
+
+int AliHLTTask::SetDependency(AliHLTTask* pDep)
+{
+  int iResult=0;
+  if (pDep) {
+    if (FindDependency(pDep->GetName())==NULL) {
+      fListDependencies.Add(pDep);
+    } else {
+      iResult=-EEXIST;
+    }
+  } else {
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
+
+int AliHLTTask::CheckDependencies()
+{
+  int iResult=0;
+  AliHLTConfiguration* pSrc=fpConfiguration->GetFirstSource();
+  while (pSrc) {
+    if (FindDependency(pSrc->GetName())==NULL) {
+      //Logging(kHLTLogDebug, "BASE", "AliHLTTask", "dependency \"%s\" unresolved", pSrc->GetName());
+      iResult++;
+    }
+    pSrc=fpConfiguration->GetNextSource();
+  }
+  return iResult;
+}
+
+
+int AliHLTTask::Depends(AliHLTTask* pTask)
+{
+  int iResult=0;
+  if (pTask) {
+    if (fpConfiguration) {
+      iResult=fpConfiguration->GetSource(pTask->GetName())!=NULL;
+      if (iResult>0) {
+       //Logging(kHLTLogDebug, "BASE", "AliHLTTask", "task  \"%s\" depends on \"%s\"", GetName(), pTask->GetName());
+      } else {
+       //Logging(kHLTLogDebug, "BASE", "AliHLTTask", "task  \"%s\" independend of \"%s\"", GetName(), pTask->GetName());
+      }
+    } else {
+      iResult=-EFAULT;
+    }
+  } else {
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
+
+AliHLTTask* AliHLTTask::FindTarget(const char* id)
+{
+  AliHLTTask* pTask=NULL;
+  if (id) {
+    pTask=(AliHLTTask*)fListTargets.FindObject(id);
+  }
+  return pTask;
+}
+
+int AliHLTTask::SetTarget(AliHLTTask* pTgt)
+{
+  int iResult=0;
+  if (pTgt) {
+    if (FindTarget(pTgt->GetName())==NULL) {
+      fListTargets.Add(pTgt);
+    } else {
+      iResult=-EEXIST;
+    }
+  } else {
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
+
+int AliHLTTask::BuildBlockDataArray(AliHLTComponent_BlockData*& pTgt)
+{
+  int iResult=0;
+  return iResult;
+}
+
+
+// int AliHLTTask::ProcessTask(...)
+// {
+//   int iResult=0;
+//   return iResult;
+// }
+
+
+int AliHLTTask::ClearSourceBlocks()
+{
+  int iResult=0;
+  return iResult;
+}
+
+void AliHLTTask::PrintStatus()
+{
+  if (fpComponent) {
+    Logging(kHLTLogInfo, "BASE", "AliHLTTask", "     component: %s (%p)", fpComponent->GetComponentID(), fpComponent);
+  } else {
+    Logging(kHLTLogInfo, "BASE", "AliHLTTask", "     no component set!");
+  }
+  if (fpConfiguration) {
+    AliHLTConfiguration* pSrc=fpConfiguration->GetFirstSource();
+    while (pSrc) {
+      const char* pQualifier="unresolved";
+      if (FindDependency(pSrc->GetName()))
+       pQualifier="resolved";
+      Logging(kHLTLogInfo, "BASE", "AliHLTTask", "     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());
+      lnk = lnk->Next();
+    }
+  } else {
+    Logging(kHLTLogInfo, "BASE", "AliHLTTask", "     task \"%s\" not initialized", GetName());
+  }
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+TList AliHLTConfigurationHandler::fListConfigurations;
+TList AliHLTConfigurationHandler::fListDynamicConfigurations;
+
+ClassImp(AliHLTConfigurationHandler)
+
+AliHLTConfigurationHandler::AliHLTConfigurationHandler()
+{
+}
+
+AliHLTConfigurationHandler::~AliHLTConfigurationHandler()
+{
+  TObjLink* lnk=fListDynamicConfigurations.FirstLink();
+  while (lnk) {
+    TObject* obj=lnk->GetObject();
+    if (fListConfigurations.FindObject(obj->GetName())==NULL) {
+      Logging(kHLTLogDebug, "BASE", "Configuration Handler", "delete dynamic configuration \"%s\"", obj->GetName());
+      delete obj;
+    }
+    lnk=lnk->Next();
+  }
+}
+
+int AliHLTConfigurationHandler::RegisterConfiguration(AliHLTConfiguration* pConf)
+{
+  int iResult=0;
+  if (pConf) {
+    if (FindConfiguration(pConf->GetName()) == NULL) {
+      fListConfigurations.Add(pConf);
+      //Logging(kHLTLogDebug, "BASE", "Configuration Handler", "configuration \"%s\" registered", pConf->GetName());
+
+      // mark all configurations with unresolved dependencies for re-evaluation
+      TObjLink* lnk=fListConfigurations.FirstLink();
+      while (lnk) {
+       AliHLTConfiguration* pSrc=(AliHLTConfiguration*)lnk->GetObject();
+       if (pSrc && pSrc!=pConf && pSrc->SourcesResolved()!=1) {
+         pSrc->InvalidateSources();
+       }
+       lnk=lnk->Next();
+      }
+    } else {
+      iResult=-EEXIST;
+      Logging(kHLTLogWarning, "BASE", "Configuration Handler", "configuration \"%s\" already registered", pConf->GetName());
+    }
+  } else {
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
+
+int AliHLTConfigurationHandler::CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments)
+{
+  int iResult=0;
+  AliHLTConfiguration* pConf= new AliHLTConfiguration(id, component, sources, arguments);
+  if (pConf) {
+    // the configuration will be registered automatically, if this failes the configuration
+    // is missing -> delete it
+    if (FindConfiguration(id)==NULL) {
+      delete pConf;
+      pConf=NULL;
+      iResult=-EEXIST;
+    } else {
+      fListDynamicConfigurations.Add(pConf);
+    }
+  } else {
+    Logging(kHLTLogError, "BASE", "Configuration Handler", "system error: object allocation failed");
+    iResult=-ENOMEM;
+  }
+  return iResult;
+}
+
+void AliHLTConfigurationHandler::PrintConfigurations()
+{
+  Logging(kHLTLogInfo, "BASE", "Configuration Handler", "registered configurations:");
+  TObjLink *lnk = fListConfigurations.FirstLink();
+  while (lnk) {
+    TObject *obj = lnk->GetObject();
+    Logging(kHLTLogInfo, "BASE", "Configuration Handler", "  %s", obj->GetName());
+    lnk = lnk->Next();
+  }
+}
+
+int AliHLTConfigurationHandler::RemoveConfiguration(const char* id)
+{
+  int iResult=0;
+  if (id) {
+    AliHLTConfiguration* pConf=NULL;
+    if ((pConf=FindConfiguration(id))!=NULL) {
+      iResult=RemoveConfiguration(pConf);
+    } else {
+      Logging(kHLTLogWarning, "BASE", "Configuration Handler", "can not find configuration \"%s\"", id);
+      iResult=-ENOENT;
+    }
+  } else {
+    iResult=-EINVAL;
+  }
+  return iResult;
+}
+
+int AliHLTConfigurationHandler::RemoveConfiguration(AliHLTConfiguration* pConf)
+{
+  int iResult=0;
+  if (pConf) {
+    // remove the configuration from the list
+    fListConfigurations.Remove(pConf);
+    // remove cross links in the remaining configurations
+    TObjLink* lnk=fListConfigurations.FirstLink();
+    while (lnk && iResult>=0) {
+      AliHLTConfiguration* pRem=(AliHLTConfiguration*)lnk->GetObject();
+      if (pRem) {
+       pRem->InvalidateSource(pConf);
+      } else {
+       iResult=-EFAULT;
+      }
+      lnk=lnk->Next();
+    }
+  }
+  return iResult;
+}
+
+AliHLTConfiguration* AliHLTConfigurationHandler::FindConfiguration(const char* id)
+{
+  AliHLTConfiguration* pConf=NULL;
+  if (id) {
+    pConf=(AliHLTConfiguration*)fListConfigurations.FindObject(id); 
+  }
+  return pConf;
+}
+
diff --git a/HLT/BASE/AliHLTConfiguration.h b/HLT/BASE/AliHLTConfiguration.h
new file mode 100644 (file)
index 0000000..02c9527
--- /dev/null
@@ -0,0 +1,273 @@
+// @(#) $Id$
+
+#ifndef ALIHLTCONFIGURATION_H
+#define ALIHLTCONFIGURATION_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* AliHLTConfiguration
+   base class for HLT configurations
+ */
+
+#include <errno.h>
+#include <TObject.h>
+#include <TList.h>
+#include "AliHLTDataTypes.h"
+#include "AliHLTLogging.h"
+
+
+/*****************************************************************************************************
+ *
+ * AliHLTConfiguration
+ *
+ * this class describes a certain configuration af an HLT processing step by the following parameters:
+ *  - a unique id string/name
+ *  - the id of the component
+ *  - the ids of the configurations it requires input from
+ *  - the arguments, which are passed to the component when it is initialized
+ *
+ * The setup of a configuration requires simply the creation of a global object of class AliHLTConfiguration.
+ * The Configuration is automatically registered in the list of available configurations. The list is used
+ * by the handler to resolve the dependencies upon other configurations. Hierarchies can be built up in
+ * an easy way.
+ *
+ * A configuration is interpreted by the Configuration Handler and transformed into a Task List.
+ */
+class AliHLTConfiguration : public TObject, public AliHLTLogging {
+ public:
+  AliHLTConfiguration();
+  AliHLTConfiguration(const char* id, const char* component, const char* sources, const char* arguments);
+  virtual ~AliHLTConfiguration();
+
+  /****************************************************************************************************
+   * properties
+   */
+
+  // configuration id, a unique name
+  // overridden TObject function in order to return the configuration name instead of the class name
+  // enables use of TList standard functions
+  const char *GetName() const;
+
+  // id of the component
+  const char* GetComponentID();
+
+  // print status info
+  void PrintStatus();
+
+  // get a certain source
+  AliHLTConfiguration* GetSource(const char* id);
+
+  // try to find a dependency recursively in the list of sources
+  // parameter:
+  //   id - the source to search for
+  //   pTgtList - (optional) target list to receive the dependency tree
+  // result:
+  //   0 if not found
+  //   n found in the n-th level
+  //   dependency list in the target list  
+  int FollowDependency(const char* id, TList* pTgtList=NULL);
+
+  // get the number of resolved sources
+  int GetNofSources() {return fListSources.size();}
+
+  // 1 if all sources are resolved
+  // try to resolve if bAuto==1 
+  int SourcesResolved(int bAuto=0);
+
+  // start iteration and get the first source
+  AliHLTConfiguration* GetFirstSource();
+
+  // continue iteration and get the next source
+  AliHLTConfiguration* GetNextSource();
+
+  // invalidate a dependency and mark the configuration to be re-evaluted 
+  int InvalidateSource(AliHLTConfiguration* pConf);
+
+  // mark the configuration to be re-evaluted 
+  int InvalidateSources() {fNofSources=-1; return 0;}
+
+  // return the arguments array
+  int GetArguments(int* pArgc, const char*** pArgv);
+
+ protected:
+  
+  //int Logging( AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
+
+ private:
+  /* extract the source configurations from the sources string
+   */
+  int ExtractSources();
+
+  /* extract arguments from the argument string
+   */
+  int ExtractArguments();
+
+  /* helper function to build a vector from an argument string
+   */
+  int InterpreteString(const char* arg, vector<char*>& argList);
+
+  const char* fID;                  // id of this configuration
+  const char* fComponent;           // component id of this configuration
+
+  const char* fStringSources;                             // the 'sources' string as passed to the constructor
+  int fNofSources;
+  vector<AliHLTConfiguration*> fListSources;              // list of sources
+  vector<AliHLTConfiguration*>::iterator fListSrcElement; // iterator for the above list
+
+  const char* fArguments;           // the arguments string as passed to the constructor
+  int fArgc;                        // number of arguments
+  char** fArgv;                     // argument array
+
+  ClassDef(AliHLTConfiguration, 0);
+};
+
+struct AliHLTComponent_BlockData;
+class AliHLTComponent;
+class AliHLTComponentHandler;
+
+/*****************************************************************************************************
+ *
+ * AliHLTTask
+ *
+ * 
+ */
+class AliHLTTask : public TObject, public AliHLTLogging {
+ public:
+  AliHLTTask();
+  AliHLTTask(AliHLTConfiguration* fConf, AliHLTComponentHandler* pCH);
+  virtual ~AliHLTTask();
+
+  /* initialize the task
+   */
+  int Init(AliHLTConfiguration* fConf, AliHLTComponentHandler* pCH);
+
+  // overridden TObject function in order to return the configuration name instead of the class name
+  // enables use of TList standard functions
+  const char *GetName() const;
+
+  /* return pointer to configuration
+   */
+  AliHLTConfiguration* GetConf();
+
+  /* return pointer to configuration
+   */
+  AliHLTComponent* GetComponent();
+
+  /* find a dependency with name/id 
+   */
+  AliHLTTask* FindDependency(const char* id);
+
+  /* insert block data to the list
+   * the data has to come from a task the current one depend on
+   * result:
+   *    -EEXIST : the block data from this task has already been inserted
+   *    -ENOENT : no dependencies to the task the data is coming from
+   */
+  int InsertBlockData(AliHLTComponent_BlockData* pBlock, AliHLTTask* pSource);
+
+  /* add a dependency for the task
+   */
+  int SetDependency(AliHLTTask* pDep);
+
+  /* return number of unresolved dependencies
+   */
+  int CheckDependencies();
+
+  /* 1 if the current task depends upon pTask
+   * 0 if no dependency
+   */
+  int Depends(AliHLTTask* pTask);
+
+  /* find a target
+   */
+  AliHLTTask* FindTarget(const char* id);
+
+  /* insert task into target list
+   */
+  int SetTarget(AliHLTTask* pDep);
+
+  // build a monolithic array of block data
+  // result: array size, pointer to array in the target pTgt
+  //
+  int BuildBlockDataArray(AliHLTComponent_BlockData*& pTgt);
+
+  /* process the task if all dependencies are resolved
+   * reset the source block data list
+   */
+  //int ProcessTask(...);
+
+  // clear the list of source data blocks
+  // the list of source data blocks has to be cleared at the beginning of 
+  // a new event
+  int ClearSourceBlocks();
+
+  // print the status of the task with component, dependencies and targets
+  void PrintStatus();
+
+  // search task dependency list recursively to find a dependency 
+  // parameter:
+  //   id - the task to search for
+  //   pTgtList - (optional) target list to receive the dependency tree
+  // result:
+  //   0 if not found
+  //   n found in the n-th level
+  //   dependency list in the target list  
+  int FollowDependency(const char* id, TList* pTgtList=NULL);
+
+  // print the tree for a certain dependency either from the task or configuration list
+  // each task posseses two "link lists": The configurations are the the origin of the 
+  // task list. In case of an error during the built of the task list, the dependencies 
+  // for the task list might be incomplete. In this case the configurations can give 
+  // infomation on the error reason  
+  // parameter:
+  //   id - the dependency to search for
+  //   bFromConfiguration (default=0) - if 0 the task dependency list is used, if one the configuration list is used
+  void PrintDependencyTree(const char* id, int bFromConfiguration=0);
+
+ private:
+  AliHLTConfiguration* fpConfiguration;
+  AliHLTComponent* fpComponent;
+  vector<AliHLTComponent_BlockData*> fSources;
+  TList fListTargets;
+  TList fListDependencies;
+
+  AliHLTComponent_BlockData* fpBlockDataArray;
+
+  ClassDef(AliHLTTask, 0);
+};
+
+class AliHLTConfigurationHandler : public AliHLTLogging {
+ public:
+  AliHLTConfigurationHandler();
+  AliHLTConfigurationHandler(AliHLTConfiguration* pConf);
+  virtual ~AliHLTConfigurationHandler();
+
+  /****************************************************************************************************
+   * registration
+   */
+
+  // register a configuration to the global list of configurations
+  static 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);
+
+  // remove a configuration from the global list
+  static int RemoveConfiguration(AliHLTConfiguration* pConf);
+  static int RemoveConfiguration(const char* id);
+
+  // find a configuration from the global list
+  static AliHLTConfiguration* FindConfiguration(const char* id);
+
+  // print the registered configurations to the logging function
+  static void PrintConfigurations();
+
+
+ private:
+  static TList fListConfigurations; // the list of registered configurations
+  static TList fListDynamicConfigurations; // the list of dynamic configurations (for proper cleanup)
+
+  ClassDef(AliHLTConfigurationHandler, 0);
+};
+
+#endif
diff --git a/HLT/BASE/AliHLTLogging.cxx b/HLT/BASE/AliHLTLogging.cxx
new file mode 100644 (file)
index 0000000..21363af
--- /dev/null
@@ -0,0 +1,160 @@
+// $Id: 
+
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Authors: Matthias Richter <Matthias.Richter@ift.uib.no>                *
+ *          Timm Steinbeck <timm@kip.uni-heidelberg.de>                   *
+ *          Artur Szostak <artursz@iafrica.com>                           *
+ *          for The ALICE Off-line 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.                  *
+ **************************************************************************/
+
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+// HLT logging tools                                                         //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#if __GNUC__== 3
+using namespace std;
+#endif
+
+#include <errno.h>
+//#include <string.h>
+#include "AliL3StandardIncludes.h"
+#include "AliHLTLogging.h"
+#include <stdarg.h>
+#include <string.h>
+
+ClassImp(AliHLTLogging)
+
+char AliHLTLogging::fLogBuffer[LOG_BUFFER_SIZE]="";
+char AliHLTLogging::fOriginBuffer[LOG_BUFFER_SIZE]="";
+
+AliHLTComponent_LogSeverity AliHLTLogging::fGlobalLogFilter=(AliHLTComponent_LogSeverity)0;
+fctLogging AliHLTLogging::fLoggingFunc=NULL;
+
+AliHLTLogging::AliHLTLogging()
+{
+}
+
+
+AliHLTLogging::~AliHLTLogging()
+{
+}
+
+int AliHLTLogging::Message(void *param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message) {
+  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;
+  }
+  cout << "HLT Log " << strSeverity << ": " << origin << " (" << keyword << ") " << message << endl;
+  return iResult;
+}
+
+const char* AliHLTLogging::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 (tgtLen<LOG_BUFFER_SIZE-1) {
+//     *tgtBuffer++='\n'; // add newline if space in buffer
+//      }
+      *tgtBuffer=0; // terminate the buffer
+    }
+  }
+  return fLogBuffer;
+}
+
+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 ));
+  }
+  return -ENOSYS;
+}
+
+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="::";
+    }
+  }
+  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;
+  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;
+  return iResult;
+}
diff --git a/HLT/BASE/AliHLTLogging.h b/HLT/BASE/AliHLTLogging.h
new file mode 100644 (file)
index 0000000..63be1cb
--- /dev/null
@@ -0,0 +1,66 @@
+// @(#) $Id: 
+
+#ifndef ALIHLTLOGGING_H
+#define ALIHLTLOGGING_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* AliHLTLogging
+   the HLT logging methods
+ */
+
+
+#include "AliHLTDataTypes.h"
+#include <TObject.h>
+#include <stdio.h>
+
+#define LOG_BUFFER_SIZE 100 // global logging buffer
+#define LOG_PREFIX ""       // logging prefix, for later extensions
+
+#define DebugMsg( ... ) LoggingVarargs(kHLTLogDebug, this->Class_Name() , __func__ ,  __VA_ARGS__ )
+
+class AliHLTLogging {
+public:
+  AliHLTLogging();
+  virtual ~AliHLTLogging();
+
+  /* logging filter for all objects
+   */
+  static AliHLTComponent_LogSeverity SetGlobalLogLevel(AliHLTComponent_LogSeverity iLogFilter) {fGlobalLogFilter=iLogFilter; return fGlobalLogFilter;}
+
+  /* logging filter for individual object
+   */
+  AliHLTComponent_LogSeverity SetLocalLogLevel(AliHLTComponent_LogSeverity iLogFilter) {fLocalLogFilter=iLogFilter; return fLocalLogFilter;}
+  
+  static int Init(fctLogging pFun) { fLoggingFunc=pFun; return 0;}
+
+  // genaral logging function
+  //
+  static 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
+  //
+  int LoggingVarargs( AliHLTComponent_LogSeverity severity, const char* origin_class, const char* origin_func,  ... );
+
+  // apply filter, return 1 if message should pass
+  //
+  int CheckFilter(AliHLTComponent_LogSeverity severity);
+
+  static int Message(void * param, AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message);
+
+  static const char* BuildLogString(const char *format, va_list ap);
+
+  virtual void* GetParameter() {return NULL;}
+protected:
+
+private:
+  static  AliHLTComponent_LogSeverity fGlobalLogFilter;
+  AliHLTComponent_LogSeverity fLocalLogFilter;
+  static char fLogBuffer[LOG_BUFFER_SIZE];
+  static char fOriginBuffer[LOG_BUFFER_SIZE];
+  static fctLogging fLoggingFunc;
+
+  ClassDef(AliHLTLogging, 0)
+};
+#endif
+