]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTSystem.cxx
- changes according to coding conventions and documentation
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTSystem.cxx
index 22cca740a5f4b943034bfdbb6c17aeb72881c8f2..23567ba2fa4ed0c6a5f30d4064821a3f84d61225 100644 (file)
@@ -4,8 +4,6 @@
  * 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   *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-///////////////////////////////////////////////////////////////////////////////
-//                                                                           //
-// global HLT module management                                              //
-//                                                                           //
-///////////////////////////////////////////////////////////////////////////////
+/** @file   AliHLTSystem.cxx
+    @author Matthias Richter
+    @date   
+    @brief  Implementation of HLT module management.
+*/
 
-#if __GNUC__== 3
+#if __GNUC__>= 3
 using namespace std;
 #endif
 
-#include <errno.h>
-#include <string.h>
-#include "AliL3StandardIncludes.h"
+#include "AliHLTStdIncludes.h"
 #include "AliHLTSystem.h"
 #include "AliHLTComponentHandler.h"
 #include "AliHLTComponent.h"
 #include "AliHLTConfiguration.h"
+#include "AliHLTConfigurationHandler.h"
+#include "AliHLTTask.h"
+#include "TString.h"
 
+/** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTSystem)
 
 AliHLTSystem::AliHLTSystem()
+  :
+  fpComponentHandler(new AliHLTComponentHandler()),
+  fpConfigurationHandler(new AliHLTConfigurationHandler()),
+  fTaskList()
 {
-  fpComponentHandler=new AliHLTComponentHandler();
   if (fpComponentHandler) {
     AliHLTComponentEnvironment env;
     memset(&env, 0, sizeof(AliHLTComponentEnvironment));
@@ -51,7 +54,6 @@ AliHLTSystem::AliHLTSystem()
   } else {
     HLTFatal("can not create Component Handler");
   }
-  fpConfigurationHandler=new AliHLTConfigurationHandler();
   if (fpConfigurationHandler) {
     AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
   } else {
@@ -59,36 +61,67 @@ AliHLTSystem::AliHLTSystem()
   }
 }
 
+AliHLTSystem::AliHLTSystem(const AliHLTSystem&)
+  :
+  AliHLTLogging(),
+  fpComponentHandler(NULL),
+  fpConfigurationHandler(NULL),
+  fTaskList()
+{
+  HLTFatal("copy constructor untested");
+}
+
+AliHLTSystem& AliHLTSystem::operator=(const AliHLTSystem&)
+{ 
+  HLTFatal("assignment operator untested");
+  return *this;
+}
 
 AliHLTSystem::~AliHLTSystem()
 {
-    AliHLTConfiguration::GlobalDeinit();
-    if (fpConfigurationHandler) {
-      delete fpConfigurationHandler;
-    }
-    fpConfigurationHandler=NULL;
-
-    if (fpComponentHandler) {
-      delete fpComponentHandler;
-    }
-    fpComponentHandler=NULL;
+  CleanTaskList();
+  AliHLTConfiguration::GlobalDeinit();
+  if (fpConfigurationHandler) {
+    delete fpConfigurationHandler;
+  }
+  fpConfigurationHandler=NULL;
+  
+  if (fpComponentHandler) {
+    delete fpComponentHandler;
+  }
+  fpComponentHandler=NULL;
 }
 
 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
 {
   int iResult=0;
+  if (pConf) {
+  } else {
+    iResult=-EINVAL;
+  }
   return iResult;
 }
 
 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
 {
   int iResult=0;
+  if (pConf) {
+    if (pPrec) {
+      // find the position
+    }
+  } else {
+    iResult=-EINVAL;
+  }
   return iResult;
 }
 
 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
 {
   int iResult=0;
+  if (pConf) {
+  } else {
+    iResult=-EINVAL;
+  }
   return iResult;
 }
 
@@ -107,15 +140,15 @@ int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
        HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
        iResult=-ENOLINK;
     } else {
-      pTask=new AliHLTTask(pConf, NULL);
+      pTask=new AliHLTTask(pConf);
       if (pTask==NULL) {
        iResult=-ENOMEM;
       }
     }
     if (pTask) {
-      // check for ring dependencies
+      // check for circular dependencies
       if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
-       HLTError("detected ring dependency for configuration \"%s\"", pTask->GetName());
+       HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
        pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
        HLTError("aborted ...");
        iResult=-ELOOP;
@@ -123,6 +156,11 @@ int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
       if (iResult>=0) {
        // check whether all dependencies are already in the task list
        // create the missing ones
+       // this step is an iterative process which calls this function again for the missing
+       // configurations, in order to avoid the currently processed task to be created
+       // again it is added to the list temporarily and removed afterwards
+       // This is of high importance to preserve the order of the tasks. Furthermore, the
+       // InsertTask method has to be used in order to set all the cross links right 
        fTaskList.Add(pTask);
        AliHLTConfiguration* pDep=pConf->GetFirstSource();
        while (pDep!=NULL && iResult>=0) {
@@ -131,6 +169,7 @@ int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
          }
          pDep=pConf->GetNextSource();
        }
+       // remove the temporarily added task
        fTaskList.Remove(pTask);
 
        // insert the task and set the cross-links
@@ -175,8 +214,8 @@ int AliHLTSystem::InsertTask(AliHLTTask* pTask)
       HLTDebug("set dependency  \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
     }
     if (pCurr->Depends(pTask)) {
-      // ring dependency
-      HLTError("ring dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
+      // circular dependency
+      HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
       iResult=-ELOOP;
     } else if ((iResult=pTask->CheckDependencies())>0) {
       lnk = lnk->Next();
@@ -223,10 +262,93 @@ void AliHLTSystem::PrintTaskList()
   }
 }
 
-int AliHLTSystem::Run() 
+void AliHLTSystem::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) {
+  TString msg;
+  msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
+  for ( unsigned i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
+   if (dt.fID[i]!=0) msg+=dt.fID[i];
+   else msg+="\\0";
+  }
+  msg+="\" Origin=\"";
+  for ( unsigned i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
+   if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
+   else msg+="\\0";
+  }
+  msg+="\"";
+  HLTMessage(msg.Data());
+}
+
+int AliHLTSystem::Run(Int_t iNofEvents) 
 {
   int iResult=0;
-  HLTError("function not yet implemented");
-  iResult=-ENOSYS;
+  if ((iResult=StartTasks())>=0) {
+    for (int i=0; i<iNofEvents && iResult>=0; i++) {
+      iResult=ProcessTasks(i);
+      if (iResult>=0) {
+       HLTInfo("Event %d successfully finished (%d)", i, iResult);
+       iResult=0;
+      } else {
+       HLTError("Processing of event %d failed (%d)", i, iResult);
+       // TODO: define different running modes to either ignore errors in
+       // event processing or not
+       // currently ignored 
+       iResult=0;
+      }
+    }
+    StopTasks();
+  } else {
+    HLTError("can not start task list");
+  }
+  return iResult;
+}
+
+int AliHLTSystem::StartTasks()
+{
+  int iResult=0;
+  TObjLink *lnk=fTaskList.FirstLink();
+  while (lnk && iResult>=0) {
+    TObject* obj=lnk->GetObject();
+    if (obj) {
+      AliHLTTask* pTask=(AliHLTTask*)obj;
+      iResult=pTask->StartRun();
+    } else {
+    }
+    lnk = lnk->Next();
+  }
+  if (iResult<0) {
+  }
+  return iResult;
+}
+
+int AliHLTSystem::ProcessTasks(Int_t eventNo)
+{
+  int iResult=0;
+  HLTDebug("processing event no %d", eventNo);
+  TObjLink *lnk=fTaskList.FirstLink();
+  while (lnk && iResult>=0) {
+    TObject* obj=lnk->GetObject();
+    if (obj) {
+      AliHLTTask* pTask=(AliHLTTask*)obj;
+      iResult=pTask->ProcessTask();
+    } else {
+    }
+    lnk = lnk->Next();
+  }
+  return iResult;
+}
+
+int AliHLTSystem::StopTasks()
+{
+  int iResult=0;
+  TObjLink *lnk=fTaskList.FirstLink();
+  while (lnk && iResult>=0) {
+    TObject* obj=lnk->GetObject();
+    if (obj) {
+      AliHLTTask* pTask=(AliHLTTask*)obj;
+      iResult=pTask->EndRun();
+    } else {
+    }
+    lnk = lnk->Next();
+  }
   return iResult;
 }