]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTOUTHandlerChain.cxx
Updated macro for K* in pA analysis
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUTHandlerChain.cxx
index 954e2a281d0bb01bb7d52321eca4850e0c3e117c..1b82a62d0243d8c394d703197113ddfbacaf1499 100644 (file)
@@ -1,7 +1,7 @@
 // $Id$
 
 //**************************************************************************
-//* This file is property of and copyright by the ALICE HLT Project        * 
+//* This file is property of and copyright by the                          * 
 //* ALICE Experiment at CERN, All rights reserved.                         *
 //*                                                                        *
 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
 //* provided "as is" without express or implied warranty.                  *
 //**************************************************************************
 
-/** @file   AliHLTOUTHandlerChain.cxx
-    @author Matthias Richter
-    @date   24.06.2008
-    @brief  HLTOUT handler of type kChain.
-*/
+/// @file   AliHLTOUTHandlerChain.cxx
+/// @author Matthias Richter
+/// @date   24.06.2008
+/// @brief  HLTOUT handler of type kChain.
+///
 
 #include "AliHLTOUTHandlerChain.h"
 #include "AliHLTOUT.h"
@@ -29,6 +29,7 @@
 #include "TString.h"
 #include "TObjString.h"
 #include "TObjArray.h"
+#include <cassert>
 
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTOUTHandlerChain)
@@ -38,13 +39,15 @@ AliHLTOUTHandlerChain::AliHLTOUTHandlerChain(const char* arguments)
   fChains(),
   fOptions(),
   fpSystem(NULL),
-  fpTask(NULL)
+  fbHaveOutput(false)
 { 
-  // see header file for class documentation
-  // or
-  // refer to README to build package
-  // or
-  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+  // The handler implements the kChain processing of HLTOUT data.
+  // The ids of the chains to be run during processing are provided
+  // as parameter to the constructor. The AliHLTModuleAgent
+  // can just create a new instance and specify the chains in order
+  // to define the HLTOUT handling of type kChain for a certain data
+  // block. The same instance can be returned for multiple data blocks.
+  // The handler will run once on all data blocks.
   if (arguments) {
     TString args=arguments;
     TObjArray* pTokens=args.Tokenize(" ");
@@ -67,15 +70,23 @@ AliHLTOUTHandlerChain::AliHLTOUTHandlerChain(const char* arguments)
 
 AliHLTOUTHandlerChain::~AliHLTOUTHandlerChain()
 {
-  // see header file for class documentation
+  // destructor
   if (fpSystem) {
+    // TODO: the EOR is currenttly not send because the reconstruction
+    // chian is not stopped. Trying it here gives an error, there is
+    // some state mismatch in AliHLTSystem. Probably due to the fact,
+    // that the AliHLTSystem::Reconstruct method is not used
+//     if (!fpSystem->CheckStatus(AliHLTSystem::kError)) {
+//       // send specific 'event' to execute the stop sequence
+//       fpSystem->Reconstruct(0, NULL, NULL);
+//     }
     delete fpSystem;
   }
 }
 
 int AliHLTOUTHandlerChain::ProcessData(AliHLTOUT* pData)
 {
-  // see header file for class documentation
+  // data processing function
   if (!pData) return -EINVAL;
   int iResult=0;
 
@@ -88,23 +99,46 @@ int AliHLTOUTHandlerChain::ProcessData(AliHLTOUT* pData)
     return iResult;
   }
 
-  if (fpSystem->CheckStatus(AliHLTSystem::kError) || !fpTask) {
+  if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
     HLTWarning("kChain handler '%s': system in error state, skipping processing of associated HLTOUT blocks", fChains.Data());
     return -EACCES;
   }
 
   // run one event and do not stop the chain
-  fpTask->Reset();
   {
     AliHLTOUT::AliHLTOUTGlobalInstanceGuard g(pData);
     if ((iResult=fpSystem->Run(1,0))>=0) {
       // sub-collection is going to be reset from the
       // parent HLTOUT collection
-      AliHLTOUT* pSubCollection=dynamic_cast<AliHLTOUT*>(fpTask);
+      AliHLTOUTTask* pTask=fpSystem->GetHLTOUTTask();
+
+      // either have the task or none of the chains controlled by the chain
+      // handler has output
+      assert(pTask || !fbHaveOutput);
+      if (pTask) {
+      AliHLTOUT* pSubCollection=dynamic_cast<AliHLTOUT*>(pTask);
       pSubCollection->Init();
+
+      // filter out some data blocks which should not be processed
+      // in the next stage:
+      // 1. we are not interested in the component statistics
+      //    produced in the HLTOUT handler chain
+      for (iResult=pSubCollection->SelectFirstDataBlock();
+          iResult>=0;
+          iResult=pSubCollection->SelectNextDataBlock()) {
+       AliHLTComponentDataType dt=kAliHLTVoidDataType;
+       AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
+       pSubCollection->GetDataBlockDescription(dt, spec);
+       if (dt==kAliHLTDataTypeComponentStatistics) {
+         pSubCollection->MarkDataBlockProcessed();
+       }
+      }
       pData->AddSubCollection(pSubCollection);
-    } else {
-      fpTask->Reset();
+      } else if (fbHaveOutput) {
+       // this is an error condition since task has been created and should
+       // be available
+       HLTError("can not get instance of HLTOUT task from HLT system %p", fpSystem);
+      }
     }
   }
 
@@ -119,16 +153,18 @@ int AliHLTOUTHandlerChain::CreateConfigurations(AliHLTConfigurationHandler* /*ha
 
 int AliHLTOUTHandlerChain::InitSystem()
 {
-  // see header file for class documentation
+  // initialize the AliHLTSystem instance
   int iResult=0;
   if (!fpSystem) {
     // init AliHLTSystem
-    fpSystem = new AliHLTSystem(GetGlobalLoggingLevel());
+    TString systemName="kChain_"; systemName+=fChains;
+    systemName.ReplaceAll(" ", "_");
+    fpSystem = new AliHLTSystem(GetGlobalLoggingLevel(), systemName);
     if (fpSystem) {
       if ((iResult=fpSystem->ScanOptions(fOptions.Data()))>=0) {
        // load configurations if not specified by external macro
        if (!fOptions.Contains("config="))
-         iResult=CreateConfigurations(fpSystem->fpConfigurationHandler);
+         iResult=CreateConfigurations(fpSystem->GetConfigurationHandler());
 
        if (iResult>=0) {
          iResult=fpSystem->BuildTaskList(fChains.Data());
@@ -136,23 +172,15 @@ int AliHLTOUTHandlerChain::InitSystem()
 
        // add AliHLTOUTTask on top of the configuartions in order to
        // collect the data
-       fpTask=new AliHLTOUTTask(fChains.Data());
+       // remember if task has been created (result>0)
+       fbHaveOutput=((iResult=fpSystem->AddHLTOUTTask(fChains.Data()))>0);
       }
     } else {
       iResult=-ENOMEM;
     }
-    if (iResult>=0 && fpSystem && fpTask) {
-      if (fpTask->GetConf() && fpTask->GetConf()->SourcesResolved()>=0) {
-       iResult=fpSystem->InsertTask(fpTask);
-      } else {
-       HLTError("HLTOUT task (%s) sources not resolved", fpTask->GetName());
-       iResult=-ENOENT;
-      }
-    }
-    if (iResult<0 || !fpTask) {
+    if (iResult<0) {
       SetStatusFlag(kHandlerError);
       if (fpSystem) delete fpSystem; fpSystem=NULL;
-      if (fpTask) delete fpTask; fpTask=NULL;
     }
   }
   return iResult;