]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTSystem.cxx
- AliHLTEsdManager: minor bufix -> correct error handling
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTSystem.cxx
index f4286bd846f0c980e3c06abf89b7682e265dd08b..fe2bcf30f85485212ef670580b5e84d32fcf98da 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
     @brief  Implementation of HLT module management.
 */
 
-// see header file for class documentation
-// or
-// refer to README to build package
-// or
-// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
-
 #if __GNUC__>= 3
 using namespace std;
 #endif
@@ -43,6 +37,8 @@ using namespace std;
 #include "AliHLTModuleAgent.h"
 #include "AliHLTOfflineInterface.h"
 #include "AliHLTDataSource.h"
+#include "AliHLTOUT.h"
+#include "AliHLTOUTHandler.h"
 #include <TObjArray.h>
 #include <TObjString.h>
 #include <TStopwatch.h>
@@ -59,6 +55,7 @@ const char* AliHLTSystem::fgkHLTDefaultLibs[]= {
   //"libAliHLTPHOS.so",
   //"libAliHLTMUON.so",
   "libAliHLTTRD.so",
+  "libAliHLTTrigger.so",
   NULL
 };
 
@@ -74,7 +71,8 @@ AliHLTSystem::AliHLTSystem()
   fChains(),
   fStopwatches(new TObjArray),
   fEventCount(-1),
-  fGoodEvents(-1)
+  fGoodEvents(-1),
+  bWriteGlobalEsd(false)
 {
   // see header file for class documentation
   // or
@@ -199,7 +197,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
@@ -353,7 +351,7 @@ int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
       if (fEventCount==0) {
        InitBenchmarking(fStopwatches);
       } else {
-       //ResumeBenchmarking(fStopwatches);    
+       ResumeBenchmarking(fStopwatches);    
       }
       for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
        if ((iResult=ProcessTasks(i))>=0) {
@@ -368,7 +366,7 @@ int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
       }
       fEventCount+=iNofEvents;
       if (bStop) StopTasks();
-      //else PauseBenchmarking(fStopwatches);
+      else PauseBenchmarking(fStopwatches);
     }
     if (bStop) DeinitTasks();
   }
@@ -471,7 +469,33 @@ int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
   return iResult;
 }
 
-int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean)
+int AliHLTSystem::PauseBenchmarking(TObjArray* pStopwatches) const
+{
+  // see header file for class documentation
+  if (pStopwatches==NULL) return 0;
+
+  for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
+    if (!pStopwatches->At(i)) continue;
+    TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
+    if (pSw) pSw->Stop();
+  }
+  return 0;
+}
+
+int AliHLTSystem::ResumeBenchmarking(TObjArray* pStopwatches) const
+{
+  // see header file for class documentation
+  if (pStopwatches==NULL) return 0;
+
+  for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
+    if (!pStopwatches->At(i)) continue;
+    TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
+    if (pSw) pSw->Continue();
+  }
+  return 0;
+}
+
+int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean) const
 {
   // see header file for class documentation
   int iInitialized=1;
@@ -485,7 +509,7 @@ int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean)
   }
 
   if (iInitialized!=0) {
-    HLTInfo("HLT statistics:\n"
+    HLTImportant("HLT statistics:\n"
            "    base:              R:%.3fs C:%.3fs\n"
            "    input:             R:%.3fs C:%.3fs\n"
            "    output:            R:%.3fs C:%.3fs\n"
@@ -530,6 +554,7 @@ int AliHLTSystem::StartTasks()
   if (iResult<0) {
     HLTError("can not start task list, error %d", iResult);
   } else {
+    SetStatusFlags(kStarted);
     fEventCount=0;
     fGoodEvents=0;
     if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
@@ -590,6 +615,7 @@ int AliHLTSystem::StopTasks()
     lnk = lnk->Next();
   }
   PrintBenchmarking(fStopwatches, 1 /*clean*/);
+  ClearStatusFlags(kStarted);
   return iResult;
 }
 
@@ -702,6 +728,118 @@ 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;
+
+  // 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;
+  if (bWriteGlobalEsd) pMasterESD=esd;
+  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);
+           if (pMasterESD) {
+             pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
+             pMasterESD=NULL;
+           }
+           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
+  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
@@ -837,6 +975,8 @@ int AliHLTSystem::ScanOptions(const char* options)
              HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'");
            }
          }
+       } else if (token.Contains("globalesd")) {
+         bWriteGlobalEsd=true;
        } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
          libs+=token;
          libs+=" ";