]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTSystem.cxx
adding common functionality for the magnetic field to the component interface
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTSystem.cxx
index ae4c318a1ecdf6b088b7325400aec67e7bc62320..c7385483abb3cd005668e52eb5cfb037f845fd55 100644 (file)
@@ -1,5 +1,4 @@
 // $Id$
-
 //**************************************************************************
 //* This file is property of and copyright by the ALICE HLT Project        * 
 //* ALICE Experiment at CERN, All rights reserved.                         *
@@ -40,9 +39,13 @@ using namespace std;
 #include "AliHLTOUT.h"
 #include "AliHLTOUTHandler.h"
 #include "AliHLTOUTTask.h"
+#include "AliHLTControlTask.h"
+#include "AliHLTDataBuffer.h"
+#include "AliHLTMisc.h"
 #include <TObjArray.h>
 #include <TObjString.h>
 #include <TStopwatch.h>
+#include <TList.h>
 //#include <TSystem.h>
 #include <TROOT.h>
 //#include <TInterpreter.h>
@@ -53,9 +56,11 @@ const char* AliHLTSystem::fgkHLTDefaultLibs[]= {
   "libAliHLTRCU.so", 
   "libAliHLTTPC.so", 
   //  "libAliHLTSample.so",
-  //"libAliHLTPHOS.so",
+  //  "libAliHLTPHOS.so",
   "libAliHLTMUON.so",
   "libAliHLTTRD.so",
+  "libAliHLTITS.so",
+  "libAliHLTGlobal.so",
   "libAliHLTTrigger.so",
   NULL
 };
@@ -63,7 +68,7 @@ const char* AliHLTSystem::fgkHLTDefaultLibs[]= {
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTSystem)
 
-AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel)
+AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel, const char* name)
   :
   fpComponentHandler(AliHLTComponentHandler::CreateHandler()),
   fpConfigurationHandler(AliHLTConfigurationHandler::CreateHandler()),
@@ -76,7 +81,10 @@ AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel)
   fpChainHandlers(NULL),
   fpEsdHandlers(NULL),
   fpProprietaryHandlers(NULL),
-  fpHLTOUTTask(NULL)
+  fpHLTOUTTask(NULL),
+  fpControlTask(NULL),
+  fName(name)
+  , fECSParams()
 {
   // see header file for class documentation
   // or
@@ -97,6 +105,7 @@ AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel)
     memset(&env, 0, sizeof(AliHLTAnalysisEnvironment));
     env.fStructSize=sizeof(AliHLTAnalysisEnvironment);
     env.fAllocMemoryFunc=AliHLTSystem::AllocMemory;
+    env.fGetEventDoneDataFunc=AliHLTSystem::AllocEventDoneData;
     env.fLoggingFunc=NULL;
     fpComponentHandler->SetEnvironment(&env);
     InitAliLogFunc(fpComponentHandler);
@@ -117,6 +126,7 @@ AliHLTSystem::~AliHLTSystem()
 {
   // see header file for class documentation
   fgNofInstances--;
+  CleanHLTOUT();
   CleanTaskList();
   AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler);
   if (fpConfigurationHandler) {
@@ -128,6 +138,9 @@ AliHLTSystem::~AliHLTSystem()
     fpComponentHandler->Destroy();
   }
   fpComponentHandler=NULL;
+
+  // note: fpHLTOUTTask and fpControlTask are deleted by
+  // CleanTaskList
 }
 
 int AliHLTSystem::fgNofInstances=0;
@@ -275,11 +288,14 @@ int AliHLTSystem::CleanTaskList()
 {
   // see header file for class documentation
   int iResult=0;
+  fpHLTOUTTask=NULL;
+  fpControlTask=NULL;
   TObjLink* lnk=NULL;
   while ((lnk=fTaskList.LastLink())!=NULL) {
     delete (lnk->GetObject());
     fTaskList.Remove(lnk);
   }
+
   return iResult;
 }
 
@@ -287,9 +303,24 @@ int AliHLTSystem::InsertTask(AliHLTTask* pTask)
 {
   // see header file for class documentation
   int iResult=0;
-  TObjLink *lnk = NULL;
-  if ((iResult=pTask->CheckDependencies())>0)
-    lnk=fTaskList.FirstLink();
+  if (fpControlTask==NULL) {
+    fpControlTask=new AliHLTControlTask;
+    if (!fpControlTask) return -ENOMEM;
+    fTaskList.AddFirst(fpControlTask);
+  }
+  TObjLink *controlLnk=NULL;
+  TObjLink *lnk = fTaskList.FirstLink();
+  assert(!lnk || lnk->GetObject()==fpControlTask || fpControlTask==NULL);
+  if (lnk && lnk->GetObject()==fpControlTask) {
+    if (pTask->GetConf() && pTask->GetConf()->GetFirstSource()==NULL) {
+      pTask->SetDependency(fpControlTask);
+      fpControlTask->SetTarget(pTask);
+    }
+    controlLnk=lnk;
+    lnk=lnk->Next();
+  }
+  if ((iResult=pTask->CheckDependencies())<=0)
+    lnk=NULL;
   while (lnk && iResult>0) {
     AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
     //HLTDebug("checking  \"%s\"", pCurr->GetName());
@@ -310,6 +341,8 @@ int AliHLTSystem::InsertTask(AliHLTTask* pTask)
   if (iResult==0) {
       if (lnk) {
        fTaskList.AddAfter(lnk, pTask);
+      } else if (controlLnk) {
+       fTaskList.AddAfter(controlLnk, pTask);
       } else {
        fTaskList.AddFirst(pTask);
       }
@@ -350,7 +383,7 @@ void AliHLTSystem::PrintTaskList()
   }
 }
 
-int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
+int AliHLTSystem::Run(Int_t iNofEvents, int bStop, AliHLTUInt64_t trgMask)
 {
   // see header file for class documentation
   int iResult=0;
@@ -361,7 +394,10 @@ int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
       if (fEventCount==0) {
        InitBenchmarking(fStopwatches);
       } else {
-       ResumeBenchmarking(fStopwatches);    
+       // Matthias Oct 11 2008 this is a bug
+       // By resuming the stopwatches at this point, all continued counting, but the
+       // starting and stopping is controlled by the AliHLTStopwatchGuard
+       //ResumeBenchmarking(fStopwatches);    
       }
       for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
        if (fpHLTOUTTask) {
@@ -371,7 +407,7 @@ int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
          // reset and prepare for new data
          fpHLTOUTTask->Reset();
        }
-       if ((iResult=ProcessTasks(i))>=0) {
+       if ((iResult=ProcessTasks(i, trgMask))>=0) {
          fGoodEvents++;
          iCount++;
        } else {
@@ -380,6 +416,7 @@ int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
          // currently ignored 
          iResult=0;
        }
+       AliHLTDataBuffer::SetGlobalEventCount(iCount);
       }
       fEventCount+=iNofEvents;
       if (bStop) StopTasks();
@@ -393,6 +430,7 @@ int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
     iResult=0; // do not propagate the error
   }
   ClearStatusFlags(kRunning);
+  AliHLTDataBuffer::PrintStatistics();
   return iResult;
 }
 
@@ -403,7 +441,7 @@ int AliHLTSystem::InitTasks()
   TObjLink *lnk=fTaskList.FirstLink();
 
   if (lnk==NULL) {
-    HLTWarning("Task list is empty, skipping HLT");
+    HLTInfo("Task list is empty, skipping HLT");
     return -126 /*ENOKEY*/;
   }
   while (lnk && iResult>=0) {
@@ -575,13 +613,13 @@ int AliHLTSystem::StartTasks()
     fEventCount=0;
     fGoodEvents=0;
     if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
-      HLTError("can not send SOR event");
+      HLTError("can not send SOR event: error %d", iResult);
     }
   }
   return iResult;
 }
 
-int AliHLTSystem::ProcessTasks(Int_t eventNo)
+int AliHLTSystem::ProcessTasks(Int_t eventNo, AliHLTUInt64_t trgMask)
 {
   // see header file for class documentation
   int iResult=0;
@@ -591,7 +629,7 @@ int AliHLTSystem::ProcessTasks(Int_t eventNo)
     TObject* obj=lnk->GetObject();
     if (obj) {
       AliHLTTask* pTask=(AliHLTTask*)obj;
-      iResult=pTask->ProcessTask(eventNo);
+      iResult=pTask->ProcessTask(eventNo, gkAliEventTypeData, trgMask);
 //       ProcInfo_t ProcInfo;
 //       gSystem->GetProcInfo(&ProcInfo);
 //       HLTInfo("task %s processed (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
@@ -617,6 +655,13 @@ int AliHLTSystem::StopTasks()
   if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
     HLTError("can not send EOR event");
   }
+
+  // cleanup blocks from the last event. This is a bit awkward. All output
+  // blocks from the chains need to be stored in the HLTOUT task. Though,
+  // we do not know, whether HLTOUT is going to be processed or not.
+  if (fpHLTOUTTask)
+    fpHLTOUTTask->Reset();
+
   TObjLink *lnk=fTaskList.FirstLink();
   while (lnk) {
     TObject* obj=lnk->GetObject();
@@ -639,26 +684,53 @@ int AliHLTSystem::StopTasks()
 int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
 {
   // see header file for class documentation
+  int iResult=0;
 
-  // disabled for the moment
-  return 0;
+  AliHLTComponentBlockDataList controlBlocks;
+  AliHLTComponentBlockData bd;
 
-  int iResult=0;
+  // run decriptor block of type kAliHLTDataTypeSOR/kAliHLTDataTypeEOR 
+  AliHLTComponent::FillBlockData(bd);
   AliHLTRunDesc runDesc;
   memset(&runDesc, 0, sizeof(AliHLTRunDesc));
   runDesc.fStructSize=sizeof(AliHLTRunDesc);
-  AliHLTDataSource::AliSpecialEventGuard g(&runDesc, dt, kAliHLTVoidDataSpec);
+  bd.fPtr=&runDesc;
+  bd.fSize=sizeof(AliHLTRunDesc);
+  bd.fDataType=dt;
+  bd.fSpecification=kAliHLTVoidDataSpec;
+  controlBlocks.push_back(bd);
+
+  // ECS parameter of type kAliHLTDataTypeECSParam
+  if (fECSParams.IsNull())
+    fECSParams="CTP_TRIGGER_CLASS=00:DUMMY-TRIGGER-ALL:00-01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17";
+  AliHLTComponent::FillBlockData(bd);
+  bd.fPtr=(void*)fECSParams.Data();
+  bd.fSize=fECSParams.Length()+1;
+  bd.fDataType=kAliHLTDataTypeECSParam;
+  bd.fSpecification=kAliHLTVoidDataSpec;
+  controlBlocks.push_back(bd);  
+
+  AliHLTControlTask::AliHLTControlEventGuard g(fpControlTask, controlBlocks);
   HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc);
   TObjLink *lnk=fTaskList.FirstLink();
   while (lnk && iResult>=0) {
     TObject* obj=lnk->GetObject();
     if (obj) {
       AliHLTTask* pTask=(AliHLTTask*)obj;
-      iResult=pTask->ProcessTask(-1);
+      AliHLTUInt32_t eventType=gkAliEventTypeUnknown;
+      if (dt==kAliHLTDataTypeSOR) eventType=gkAliEventTypeStartOfRun;
+      else if (dt==kAliHLTDataTypeEOR) eventType=gkAliEventTypeEndOfRun;
+      else HLTWarning("unknown control event %s", AliHLTComponent::DataType2Text(dt).c_str());
+      iResult=pTask->ProcessTask(-1, eventType);
     } else {
     }
     lnk = lnk->Next();
   }
+
+  // control events are not supposed to go into the HLTOUT
+  if (fpHLTOUTTask)
+    fpHLTOUTTask->Reset();
+
   HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
   return iResult;
 }
@@ -668,11 +740,12 @@ int AliHLTSystem::DeinitTasks()
   // see header file for class documentation
   int iResult=0;
   TObjLink *lnk=fTaskList.FirstLink();
-  while (lnk && iResult>=0) {
+  while (lnk) {
     TObject* obj=lnk->GetObject();
     if (obj) {
       AliHLTTask* pTask=(AliHLTTask*)obj;
-      iResult=pTask->Deinit();
+      int localRes=pTask->Deinit();
+      if (iResult>=0) iResult=localRes;
 //       ProcInfo_t ProcInfo;
 //       gSystem->GetProcInfo(&ProcInfo);
 //       HLTInfo("task %s cleaned (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
@@ -686,6 +759,44 @@ int AliHLTSystem::DeinitTasks()
   return iResult;
 }
 
+int AliHLTSystem::CleanHLTOUT()
+{
+  // see header file for class documentation
+  if (fpChainHandlers) {
+    AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
+    fpChainHandlers=NULL;
+    if (pHandlers) {
+      AliHLTOUT::InvalidateBlocks(*pHandlers);
+      AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
+    }
+    assert(pHandlers->size()==0);
+    delete pHandlers;
+  }
+
+  if (fpEsdHandlers) {
+    AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
+    fpEsdHandlers=NULL;
+    if (pHandlers) {
+      AliHLTOUT::InvalidateBlocks(*pHandlers);
+      AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
+    }
+    assert(pHandlers->size()==0);
+    delete pHandlers;
+  }
+
+  if (fpProprietaryHandlers) {
+    AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
+    fpProprietaryHandlers=NULL;
+    if (pHandlers) {
+      AliHLTOUT::InvalidateBlocks(*pHandlers);
+      AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
+    }
+    assert(pHandlers->size()==0);
+    delete pHandlers;
+  }
+  return 0;
+}
+
 void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
 {
   // see header file for class documentation
@@ -700,6 +811,21 @@ void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
   return p;
 }
 
+int AliHLTSystem::AllocEventDoneData( void* /*param*/, AliHLTEventID_t /*eventID*/, unsigned long size, AliHLTComponentEventDoneData** edd )
+{
+  // see header file for class documentation
+  unsigned long blocksize=sizeof(AliHLTComponentEventDoneData)+size;
+  void* block=AllocMemory(NULL, blocksize);
+  if (!block) return -ENOMEM;
+  memset(block, 0, blocksize);
+  *edd=reinterpret_cast<AliHLTComponentEventDoneData*>(block);
+  (*edd)->fStructSize=sizeof(AliHLTComponentEventDoneData);
+  (*edd)->fDataSize=size;
+  (*edd)->fData=reinterpret_cast<AliHLTUInt8_t*>(block)+sizeof(AliHLTComponentEventDoneData);
+  
+  return 0;
+}
+
 int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader, 
                              AliRawReader* rawReader)
 {
@@ -713,12 +839,14 @@ int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
        if (!CheckStatus(kError)) {
        StopTasks();
        DeinitTasks();
+       CleanHLTOUT();
        }
       } else {
       if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
+       AliHLTUInt64_t trgMask=AliHLTMisc::Instance().GetTriggerMask(rawReader);
        // the system always remains started after event processing, a specific
        // call with nofEvents==0 is needed to execute the stop sequence
-       if ((iResult=Run(nofEvents, 0))<0) SetStatusFlags(kError);
+       if ((iResult=Run(nofEvents, 0, trgMask))<0) SetStatusFlags(kError);
       }
       }
     } else {
@@ -787,14 +915,6 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
   AliHLTOUT::InvalidateBlocks(*pEsdHandlers);
   AliHLTOUT::InvalidateBlocks(*pProprietaryHandlers);
 
-  // first come first serve: the ESD of the first handler is also filled into
-  // the main ESD. Has to be changed later.
-  // currently, merging to the provided ESDs crashes at the level of the
-  // TTree::Fill in AliReconstruction, furthermore, the wrong ESD is passed
-  // by the framework
-  AliESDEvent* pMasterESD=NULL;
-  pMasterESD=esd;
-
   AliHLTComponentDataTypeList esdBlocks;
 
   for (iResult=pHLTOUT->SelectFirstDataBlock();
@@ -831,11 +951,7 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
          const AliHLTUInt8_t* pBuffer=NULL;
          AliHLTUInt32_t size=0;
          if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
-           pHLTOUT->WriteESD(pBuffer, size, dt);
-           if (pMasterESD) {
-             pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
-             pMasterESD=NULL;
-           }
+           pHLTOUT->WriteESD(pBuffer, size, dt, esd);
            pHLTOUT->ReleaseDataBuffer(pBuffer);
          }
          pHLTOUT->MarkDataBlockProcessed();
@@ -895,11 +1011,7 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
     if ((size=pHandler->GetProcessedData(pBuffer))>0) {
       AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*handler;
       AliHLTComponentDataType dt=desc;
-      pHLTOUT->WriteESD(pBuffer, size, dt);
-      if (pMasterESD) {
-       pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
-       pMasterESD=NULL;
-      }
+      pHLTOUT->WriteESD(pBuffer, size, dt, esd);
       pHandler->ReleaseProcessedData(pBuffer, size);
     }
     pHLTOUT->MarkDataBlocksProcessed(&(*handler));
@@ -977,7 +1089,7 @@ int AliHLTSystem::LoadComponentLibraries(const char* libraries)
       TString libs(libraries);
       TObjArray* pTokens=libs.Tokenize(" ");
       if (pTokens) {
-       int iEntries=pTokens->GetEntries();
+       int iEntries=pTokens->GetEntriesFast();
        for (int i=0; i<iEntries && iResult>=0; i++) {
          iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data());
        }
@@ -1049,7 +1161,7 @@ int AliHLTSystem::ScanOptions(const char* options)
     TString alloptions(options);
     TObjArray* pTokens=alloptions.Tokenize(" ");
     if (pTokens) {
-      int iEntries=pTokens->GetEntries();
+      int iEntries=pTokens->GetEntriesFast();
       for (int i=0; i<iEntries; i++) {
        TString token=(((TObjString*)pTokens->At(i))->GetString());
        if (token.Contains("loglevel=")) {
@@ -1104,6 +1216,8 @@ int AliHLTSystem::ScanOptions(const char* options)
              HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'");
            }
          }
+       } else if (token.BeginsWith("ECS=")) {
+         fECSParams=token.ReplaceAll("ECS=", "");
        } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
          libs+=token;
          libs+=" ";
@@ -1153,24 +1267,75 @@ int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runl
     return -EBUSY;
   }
   int iResult=0;
-  AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
+  AliHLTModuleAgent* pAgent=NULL;
+
+  // first check for the required libraries and load those
   TString extralibs;
-  while (pAgent && iResult>=0) {
+  for (pAgent=AliHLTModuleAgent::GetFirstAgent(); 
+       pAgent && iResult>=0;
+       pAgent=AliHLTModuleAgent::GetNextAgent()) {
     const char* deplibs=pAgent->GetRequiredComponentLibraries();
     if (deplibs) {
       HLTDebug("required libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
+      extralibs+=" ";
       extralibs+=deplibs;
     }
-    if (iResult>=0) {
-      HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
-      pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
-      pAgent=AliHLTModuleAgent::GetNextAgent();
-    }
   }
   if (iResult>=0) {
     iResult=LoadComponentLibraries(extralibs.Data());
   }
 
+  // in order to register the configurations in the correct sequence
+  // all agents need to be ordered with respect to the required
+  // libraries. Ordering relies on the naming convention
+  // libAliHLT<Module>.so
+  TList agents;
+  for (pAgent=AliHLTModuleAgent::GetFirstAgent(); 
+       pAgent && iResult>=0;
+       pAgent=AliHLTModuleAgent::GetNextAgent()) {
+    AliHLTModuleAgent* pPrevDep=NULL;
+    TString dependencies=pAgent->GetRequiredComponentLibraries();
+    TObjArray* pTokens=dependencies.Tokenize(" ");
+    if (pTokens) {
+      for (int n=0; n<pTokens->GetEntriesFast(); n++) {
+       TString module=((TObjString*)pTokens->At(n))->GetString();
+       HLTDebug("  checking %s", module.Data());
+       module.ReplaceAll("libAliHLT", "");
+       module.ReplaceAll(".so", "");
+       
+       for (AliHLTModuleAgent* pCurrent=dynamic_cast<AliHLTModuleAgent*>(pPrevDep==NULL?agents.First():agents.After(pPrevDep));
+            pCurrent!=NULL; pCurrent=dynamic_cast<AliHLTModuleAgent*>(agents.After(pCurrent))) {
+         HLTDebug("    checking %s == %s", module.Data(), pCurrent->GetModuleId());
+
+         if (module.CompareTo(pCurrent->GetModuleId())==0) {
+           pPrevDep=pCurrent;
+           break;
+         }
+       }
+      }
+      delete pTokens;
+    }
+
+    if (pPrevDep) {
+      // insert right after the last dependency
+      agents.AddAfter(pPrevDep, pAgent);
+      HLTDebug("insert %s after %s", pAgent->GetModuleId(), pPrevDep->GetModuleId());
+    } else {
+      // insert at the beginning
+      agents.AddFirst(pAgent);
+      HLTDebug("insert %s at beginning", pAgent->GetModuleId());
+    }
+  }
+
+  // now we load the configurations
+  if (agents.GetEntries()) {
+    TIter next(&agents);
+    while ((pAgent = dynamic_cast<AliHLTModuleAgent*>(next()))) {
+      HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
+      pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
+    }
+  }
+
   return iResult;
 }
 
@@ -1210,7 +1375,7 @@ int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader
   // build task list for chains
   TObjArray* pTokens=chains.Tokenize(" ");
   if (pTokens) {
-    int iEntries=pTokens->GetEntries();
+    int iEntries=pTokens->GetEntriesFast();
     for (int i=0; i<iEntries && iResult>=0; i++) {
       const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data();
       AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
@@ -1269,15 +1434,7 @@ int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader
       // there are components in the chain which produce data which need to be
       // piped to an HLTOUT sub-collection
       if (!fpHLTOUTTask) {
-       fpHLTOUTTask=new AliHLTOUTTask(chains.Data());
-       if (fpHLTOUTTask) {
-         if (fpHLTOUTTask->GetConf() && fpHLTOUTTask->GetConf()->SourcesResolved()>=0) {
-           iResult=InsertTask(fpHLTOUTTask);
-         } else {
-           HLTError("HLTOUT task (%s) sources not resolved", fpHLTOUTTask->GetName());
-           iResult=-ENOENT;
-         }
-       }
+       iResult=AddHLTOUTTask(chains.Data());
       }
     }
   }
@@ -1287,6 +1444,69 @@ int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader
   return iResult;
 }
 
+int AliHLTSystem::AddHLTOUTTask(const char* hltoutchains)
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (!hltoutchains || hltoutchains[0]==0) return 0;
+
+  // check chains for output
+  TString chains=hltoutchains;
+  TObjArray* pTokens=chains.Tokenize(" ");
+  if (pTokens) {
+    int iEntries=pTokens->GetEntriesFast();
+    for (int i=0; i<iEntries && iResult>=0; i++) {
+      const char* token=((TObjString*)pTokens->At(i))->GetString().Data();
+      AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(token);
+      if (pConf) {
+       TString cid=pConf->GetComponentID();
+       if (fpComponentHandler->HasOutputData(cid.Data())) {
+         continue;
+       }
+      } else {
+       HLTWarning("can not find configuration %s", token);
+      }
+      // remove from the list of hltout chains
+      chains.ReplaceAll(token, "");
+    }
+    delete pTokens;
+  }
+
+  // do not create the HLTOUT task if none of the chains have output
+  if (chains.IsNull()) return 0;
+
+  // indicate the task to be available
+  iResult=1;
+
+  if (fpHLTOUTTask) {
+    if (strcmp(chains.Data(), fpHLTOUTTask->GetSourceChains())==0) {
+      HLTWarning("HLTOUT task already added for chains \"%s\" %p", chains.Data(), fpHLTOUTTask);
+    } else {
+      HLTError("HLTOUT task already added for chains \"%s\" %p, ignoring new chains  \"%s\"",
+              fpHLTOUTTask->GetSourceChains(), fpHLTOUTTask, chains.Data());
+    }
+    return iResult;
+  }
+
+  fpHLTOUTTask=new AliHLTOUTTask(chains);
+  if (fpHLTOUTTask) {
+    if (fpHLTOUTTask->GetConf() && fpHLTOUTTask->GetConf()->SourcesResolved()>=0) {
+      iResult=InsertTask(fpHLTOUTTask);
+    } else {
+      HLTError("HLTOUT task (%s) sources not resolved", fpHLTOUTTask->GetName());
+      iResult=-ENOENT;
+    }
+
+    if (iResult<0) {
+      delete fpHLTOUTTask;
+    }
+
+  } else {
+    iResult=-ENOMEM;
+  }
+  return iResult;
+}
+
 int AliHLTSystem::CheckStatus(int flag)
 {
   // see header file for class documentation
@@ -1315,7 +1535,7 @@ int AliHLTSystem::ClearStatusFlags(int flags)
   return fState;
 }
 
-void* AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
+void (*AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol))()
 {
   // see header file for class documentation
   if (fpComponentHandler==NULL) return NULL;
@@ -1329,3 +1549,21 @@ void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level)
   if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
   if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);
 }
+
+int AliHLTSystem::LoggingVarargs(AliHLTComponentLogSeverity severity, 
+                                const char* originClass, const char* originFunc,
+                                const char* file, int line, ... ) const
+{
+  // see header file for function documentation
+  int iResult=0;
+
+  va_list args;
+  va_start(args, line);
+
+  if (!fName.IsNull())
+    AliHLTLogging::SetLogString(this, " (%p)", "%s_pfmt_: ", fName.Data());
+  iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, !fName.IsNull() /*append if non empty*/));
+  va_end(args);
+
+  return iResult;
+}