]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTSystem.cxx
Minor cleanup of code.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTSystem.cxx
index 4aea57cbb43c6847856e57c36821b94b2f4b343c..510b8f42a691ab2e0938f5c7e3be6375eb0e1c4e 100644 (file)
@@ -1,20 +1,20 @@
 // $Id$
 
-/**************************************************************************
- * This file is property of and copyright by the ALICE HLT Project        * 
- * ALICE Experiment at CERN, All rights reserved.                         *
- *                                                                        *
- * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
- *                  for The ALICE HLT 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.                  *
- **************************************************************************/
+//**************************************************************************
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//*                                                                        *
+//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
+//*                  for The ALICE HLT 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.                  *
+//**************************************************************************
 
 /** @file   AliHLTSystem.cxx
     @author Matthias Richter
@@ -36,21 +36,26 @@ using namespace std;
 #include "AliHLTTask.h"
 #include "AliHLTModuleAgent.h"
 #include "AliHLTOfflineInterface.h"
+#include "AliHLTDataSource.h"
+#include "AliHLTOUT.h"
+#include "AliHLTOUTHandler.h"
 #include <TObjArray.h>
 #include <TObjString.h>
 #include <TStopwatch.h>
 //#include <TSystem.h>
 #include <TROOT.h>
-#include <TInterpreter.h>
+//#include <TInterpreter.h>
 
 /** HLT default component libraries */
-const char* kHLTDefaultLibs[]= {
+const char* AliHLTSystem::fgkHLTDefaultLibs[]= {
   "libAliHLTUtil.so", 
+  "libAliHLTRCU.so", 
   "libAliHLTTPC.so", 
   //  "libAliHLTSample.so",
   //"libAliHLTPHOS.so",
   //"libAliHLTMUON.so",
   "libAliHLTTRD.so",
+  "libAliHLTTrigger.so",
   NULL
 };
 
@@ -119,8 +124,11 @@ int AliHLTSystem::fgNofInstances=0;
 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
 {
   // see header file for class documentation
+  HLTLogKeyword("configuration handling");
   int iResult=0;
   if (pConf) {
+    HLTError("function not yet implemented");
+    iResult=-ENOSYS;
   } else {
     iResult=-EINVAL;
   }
@@ -130,10 +138,13 @@ int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
 {
   // see header file for class documentation
+  HLTLogKeyword("configuration handling");
   int iResult=0;
   if (pConf) {
     if (pPrec) {
       // find the position
+      HLTError("function not yet implemented");
+      iResult=-ENOSYS;
     }
   } else {
     iResult=-EINVAL;
@@ -144,8 +155,11 @@ int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfigur
 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
 {
   // see header file for class documentation
+  HLTLogKeyword("configuration handling");
   int iResult=0;
   if (pConf) {
+    HLTError("function not yet implemented");
+    iResult=-ENOSYS;
   } else {
     iResult=-EINVAL;
   }
@@ -182,7 +196,7 @@ int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
     AliHLTTask* pTask=NULL;
     if ((pTask=FindTask(pConf->GetName()))!=NULL) {
       if (pTask->GetConf()!=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);
+       HLTError("configuration mismatch, 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;
       }
       // task for this configuration exists, terminate
@@ -371,7 +385,7 @@ int AliHLTSystem::InitTasks()
   TObjLink *lnk=fTaskList.FirstLink();
 
   if (lnk==NULL) {
-    HLTWarning("Task list is empty, aborting ...");
+    HLTWarning("Task list is empty, skipping HLT");
     return -126 /*ENOKEY*/;
   }
   while (lnk && iResult>=0) {
@@ -515,6 +529,9 @@ int AliHLTSystem::StartTasks()
   } else {
     fEventCount=0;
     fGoodEvents=0;
+    if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
+      HLTError("can not send SOR event");
+    }
   }
   return iResult;
 }
@@ -539,7 +556,7 @@ int AliHLTSystem::ProcessTasks(Int_t eventNo)
   }
 
   if (iResult>=0) {
-    HLTInfo("Event %d successfully finished (%d)", eventNo, iResult);
+    HLTImportant("Event %d successfully finished (%d)", eventNo, iResult);
     iResult=0;
   } else {
     HLTError("Processing of event %d failed (%d)", eventNo, iResult);
@@ -552,12 +569,16 @@ int AliHLTSystem::StopTasks()
 {
   // see header file for class documentation
   int iResult=0;
+  if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
+    HLTError("can not send EOR event");
+  }
   TObjLink *lnk=fTaskList.FirstLink();
-  while (lnk && iResult>=0) {
+  while (lnk) {
     TObject* obj=lnk->GetObject();
     if (obj) {
       AliHLTTask* pTask=(AliHLTTask*)obj;
-      iResult=pTask->EndRun();
+      int locResult=pTask->EndRun();
+      if (iResult>=0 && locResult<0) iResult=locResult;
 //       ProcInfo_t ProcInfo;
 //       gSystem->GetProcInfo(&ProcInfo);
 //       HLTInfo("task %s stopped (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
@@ -569,6 +590,33 @@ int AliHLTSystem::StopTasks()
   return iResult;
 }
 
+int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
+{
+  // see header file for class documentation
+
+  // disabled for the moment
+  return 0;
+
+  int iResult=0;
+  AliHLTRunDesc runDesc;
+  memset(&runDesc, 0, sizeof(AliHLTRunDesc));
+  runDesc.fStructSize=sizeof(AliHLTRunDesc);
+  AliHLTDataSource::AliSpecialEventGuard g(&runDesc, dt, kAliHLTVoidDataSpec);
+  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);
+    } else {
+    }
+    lnk = lnk->Next();
+  }
+  HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
+  return iResult;
+}
+
 int AliHLTSystem::DeinitTasks()
 {
   // see header file for class documentation
@@ -651,6 +699,109 @@ int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd
   return iResult;
 }
 
+int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (!pHLTOUT) return -EINVAL;
+
+  HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
+  AliHLTOUT::AliHLTOUTHandlerListEntryVector esdHandlers;
+  for (iResult=pHLTOUT->SelectFirstDataBlock();
+       iResult>=0;
+       iResult=pHLTOUT->SelectNextDataBlock()) {
+    AliHLTComponentDataType dt=kAliHLTVoidDataType;
+    AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
+    pHLTOUT->GetDataBlockDescription(dt, spec);
+    AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
+    AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
+    if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
+      handlerType=AliHLTModuleAgent::kEsd;
+    }
+    const char* pMsg="invalid";
+    switch (handlerType) {
+    case AliHLTModuleAgent::kEsd:
+      {
+       if (pHandler) {
+         // preprocess and write later
+         AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
+         pHandler->ProcessData(pHLTOUT);
+         pHLTOUT->InsertHandler(esdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
+       } else {
+         // write directly
+         const AliHLTUInt8_t* pBuffer=NULL;
+         AliHLTUInt32_t size=0;
+         if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
+           pHLTOUT->WriteESD(pBuffer, size, dt);
+           pHLTOUT->ReleaseDataBuffer(pBuffer);
+         }
+       }
+      }
+      break;
+    case AliHLTModuleAgent::kRawReader:
+      // handled in the AliRawReaderHLT
+      break;
+    case AliHLTModuleAgent::kRawStream:
+      HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x",
+                pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
+                AliHLTComponent::DataType2Text(dt).c_str(), spec);
+      break;
+    case AliHLTModuleAgent::kChain:
+      HLTWarning("HLTOUT handler type 'kChain' not yet implemented: agent %s, data type %s, specification %#x",
+                pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
+                AliHLTComponent::DataType2Text(dt).c_str(), spec);
+      break;
+    case AliHLTModuleAgent::kProprietary:
+      HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x",
+                pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
+                AliHLTComponent::DataType2Text(dt).c_str(), spec);
+      if (pHandler) {
+       AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
+       int res=pHandler->ProcessData(pHLTOUT);
+       if (res<0) {
+         HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x",
+                    res, pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
+                    AliHLTComponent::DataType2Text(dt).c_str(), spec);
+       }
+      }
+      break;
+    case AliHLTModuleAgent::kUnknownOutput:
+      pMsg="unknown";
+      // fall trough intended
+    default:
+      HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block",
+                pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
+                AliHLTComponent::DataType2Text(dt).c_str(), spec);
+    }
+  }
+  // TODO: the return value of SelectFirst/NextDataBlock must be
+  // changed in order to avoid this check
+  if (iResult==-ENOENT) iResult=0;
+
+  AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator esdHandler;
+  // write all postponed esd data blocks
+  // first come first serve: the ESD of the first handler is also filled into
+  // the main ESD. Has to be changed later.
+  AliESDEvent* pMasterESD=esd;
+  for (esdHandler=esdHandlers.begin(); esdHandler!=esdHandlers.end() && iResult>=0; esdHandler++) {
+    AliHLTOUTHandler* pHandler=*esdHandler;
+    const AliHLTUInt8_t* pBuffer=NULL;
+    AliHLTUInt32_t size=0;
+    if ((size=pHandler->GetProcessedData(pBuffer))>0) {
+      AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*esdHandler;
+      AliHLTComponentDataType dt=desc;
+      pHLTOUT->WriteESD(pBuffer, size, dt);
+      if (pMasterESD) {
+       pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
+       pMasterESD=NULL;
+      }
+      pHandler->ReleaseProcessedData(pBuffer, size);
+    }
+  }
+
+  return iResult;
+}
+
 int AliHLTSystem::LoadComponentLibraries(const char* libraries)
 {
   // see header file for class documentation
@@ -727,7 +878,7 @@ int AliHLTSystem::ScanOptions(const char* options)
   // see header file for class documentation
   int iResult=0;
   if (options) {
-    AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
+    //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
     TString libs("");
     TString alloptions(options);
     TObjArray* pTokens=alloptions.Tokenize(" ");
@@ -798,7 +949,7 @@ int AliHLTSystem::ScanOptions(const char* options)
 
     if (iResult>=0) {
       if (libs.IsNull()) {
-       const char** deflib=kHLTDefaultLibs;
+       const char** deflib=fgkHLTDefaultLibs;
        while (*deflib) {
          libs+=*deflib++;
          libs+=" ";
@@ -870,7 +1021,7 @@ int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader
   TString chains;
   if (fChains.Length()>0) {
     chains=fChains;
-    HLTInfo("custom reconstruction chain: %s", chains.Data());
+    HLTImportant("custom reconstruction chain: %s", chains.Data());
   } else {
     AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
     while ((pAgent || fChains.Length()>0) && iResult>=0) {
@@ -972,6 +1123,7 @@ void* AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
 
 void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level) 
 {
+  // see header file for class documentation
   SetLocalLoggingLevel(level);
   if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
   if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);