LCOV - code coverage report
Current view: top level - HLT/BASE - AliHLTOUTHandlerChain.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 82 1.2 %
Date: 2016-06-14 17:26:59 Functions: 1 9 11.1 %

          Line data    Source code
       1             : // $Id$
       2             : 
       3             : //**************************************************************************
       4             : //* This file is property of and copyright by the                          * 
       5             : //* ALICE Experiment at CERN, All rights reserved.                         *
       6             : //*                                                                        *
       7             : //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
       8             : //*                  for The ALICE HLT Project.                            *
       9             : //*                                                                        *
      10             : //* Permission to use, copy, modify and distribute this software and its   *
      11             : //* documentation strictly for non-commercial purposes is hereby granted   *
      12             : //* without fee, provided that the above copyright notice appears in all   *
      13             : //* copies and that both the copyright notice and this permission notice   *
      14             : //* appear in the supporting documentation. The authors make no claims     *
      15             : //* about the suitability of this software for any purpose. It is          *
      16             : //* provided "as is" without express or implied warranty.                  *
      17             : //**************************************************************************
      18             : 
      19             : /// @file   AliHLTOUTHandlerChain.cxx
      20             : /// @author Matthias Richter
      21             : /// @date   24.06.2008
      22             : /// @brief  HLTOUT handler of type kChain.
      23             : ///
      24             : 
      25             : #include "AliHLTOUTHandlerChain.h"
      26             : #include "AliHLTOUT.h"
      27             : #include "AliHLTSystem.h"
      28             : #include "AliHLTOUTTask.h"
      29             : #include "TString.h"
      30             : #include "TObjString.h"
      31             : #include "TObjArray.h"
      32             : #include <cassert>
      33             : 
      34             : /** ROOT macro for the implementation of ROOT specific class methods */
      35         126 : ClassImp(AliHLTOUTHandlerChain)
      36             : 
      37           0 : AliHLTOUTHandlerChain::AliHLTOUTHandlerChain(const char* arguments)
      38             :   :
      39           0 :   fChains(),
      40           0 :   fOptions(),
      41           0 :   fpSystem(NULL),
      42           0 :   fbHaveOutput(false)
      43           0 : { 
      44             :   // The handler implements the kChain processing of HLTOUT data.
      45             :   // The ids of the chains to be run during processing are provided
      46             :   // as parameter to the constructor. The AliHLTModuleAgent
      47             :   // can just create a new instance and specify the chains in order
      48             :   // to define the HLTOUT handling of type kChain for a certain data
      49             :   // block. The same instance can be returned for multiple data blocks.
      50             :   // The handler will run once on all data blocks.
      51           0 :   if (arguments) {
      52           0 :     TString args=arguments;
      53           0 :     TObjArray* pTokens=args.Tokenize(" ");
      54           0 :     if (pTokens) {
      55           0 :       int iEntries=pTokens->GetEntries();
      56           0 :       for (int i=0; i<iEntries; i++) {
      57           0 :         TString token=(((TObjString*)pTokens->At(i))->GetString());
      58           0 :         if (token.Contains("chains=")) {
      59           0 :           TString param=token.ReplaceAll("chains=", "");
      60           0 :           fChains=param.ReplaceAll(",", " ");
      61           0 :         } else {
      62           0 :           if (!fOptions.IsNull()) fOptions+=" ";
      63           0 :           fOptions+=token;
      64             :         }
      65           0 :       }
      66           0 :       delete pTokens;
      67           0 :     }
      68           0 :   } 
      69           0 : }
      70             : 
      71             : AliHLTOUTHandlerChain::~AliHLTOUTHandlerChain()
      72           0 : {
      73             :   // destructor
      74           0 :   if (fpSystem) {
      75             :     // TODO: the EOR is currenttly not send because the reconstruction
      76             :     // chian is not stopped. Trying it here gives an error, there is
      77             :     // some state mismatch in AliHLTSystem. Probably due to the fact,
      78             :     // that the AliHLTSystem::Reconstruct method is not used
      79             : //     if (!fpSystem->CheckStatus(AliHLTSystem::kError)) {
      80             : //       // send specific 'event' to execute the stop sequence
      81             : //       fpSystem->Reconstruct(0, NULL, NULL);
      82             : //     }
      83           0 :     delete fpSystem;
      84             :   }
      85           0 : }
      86             : 
      87             : int AliHLTOUTHandlerChain::ProcessData(AliHLTOUT* pData)
      88             : {
      89             :   // data processing function
      90           0 :   if (!pData) return -EINVAL;
      91             :   int iResult=0;
      92             : 
      93           0 :   if (CheckStatus(kHandlerError)) {
      94           0 :     HLTWarning("kChain handler '%s' in error state, skipping processing of associated HLTOUT blocks", fChains.Data());
      95           0 :     return -EPERM;
      96             :   }
      97             : 
      98           0 :   if (!fpSystem && (iResult=InitSystem())<0) {
      99           0 :     return iResult;
     100             :   }
     101             : 
     102           0 :   if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
     103           0 :     HLTWarning("kChain handler '%s': system in error state, skipping processing of associated HLTOUT blocks", fChains.Data());
     104           0 :     return -EACCES;
     105             :   }
     106             : 
     107             :   // run one event and do not stop the chain
     108             :   {
     109           0 :     AliHLTOUT::AliHLTOUTGlobalInstanceGuard g(pData);
     110           0 :     if ((iResult=fpSystem->Run(1,0))>=0) {
     111             :       // sub-collection is going to be reset from the
     112             :       // parent HLTOUT collection
     113           0 :       AliHLTOUTTask* pTask=fpSystem->GetHLTOUTTask();
     114             : 
     115             :       // either have the task or none of the chains controlled by the chain
     116             :       // handler has output
     117           0 :       assert(pTask || !fbHaveOutput);
     118           0 :       if (pTask) {
     119           0 :       AliHLTOUT* pSubCollection=dynamic_cast<AliHLTOUT*>(pTask);
     120           0 :       pSubCollection->Init();
     121             : 
     122             :       // filter out some data blocks which should not be processed
     123             :       // in the next stage:
     124             :       // 1. we are not interested in the component statistics
     125             :       //    produced in the HLTOUT handler chain
     126           0 :       for (iResult=pSubCollection->SelectFirstDataBlock();
     127           0 :            iResult>=0;
     128           0 :            iResult=pSubCollection->SelectNextDataBlock()) {
     129           0 :         AliHLTComponentDataType dt=kAliHLTVoidDataType;
     130           0 :         AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
     131           0 :         pSubCollection->GetDataBlockDescription(dt, spec);
     132           0 :         if (dt==kAliHLTDataTypeComponentStatistics) {
     133           0 :           pSubCollection->MarkDataBlockProcessed();
     134             :         }
     135           0 :       }
     136           0 :       pData->AddSubCollection(pSubCollection);
     137           0 :       } else if (fbHaveOutput) {
     138             :         // this is an error condition since task has been created and should
     139             :         // be available
     140           0 :         HLTError("can not get instance of HLTOUT task from HLT system %p", fpSystem);
     141             :       }
     142           0 :     }
     143           0 :   }
     144             : 
     145           0 :   return iResult;
     146           0 : }
     147             : 
     148             : int AliHLTOUTHandlerChain::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/)
     149             : {
     150             :   //default implementation, nothing to do
     151           0 :   return 0;
     152             : }
     153             : 
     154             : int AliHLTOUTHandlerChain::InitSystem()
     155             : {
     156             :   // initialize the AliHLTSystem instance
     157             :   int iResult=0;
     158           0 :   if (!fpSystem) {
     159             :     // init AliHLTSystem
     160           0 :     TString systemName="kChain_"; systemName+=fChains;
     161           0 :     systemName.ReplaceAll(" ", "_");
     162           0 :     fpSystem = new AliHLTSystem(GetGlobalLoggingLevel(), systemName);
     163           0 :     if (fpSystem) {
     164           0 :       if ((iResult=fpSystem->ScanOptions(fOptions.Data()))>=0) {
     165             :         // load configurations if not specified by external macro
     166           0 :         if (!fOptions.Contains("config="))
     167           0 :           iResult=CreateConfigurations(fpSystem->GetConfigurationHandler());
     168             : 
     169           0 :         if (iResult>=0) {
     170           0 :           iResult=fpSystem->BuildTaskList(fChains.Data());
     171           0 :         }
     172             : 
     173             :         // add AliHLTOUTTask on top of the configuartions in order to
     174             :         // collect the data
     175             :         // remember if task has been created (result>0)
     176           0 :         fbHaveOutput=((iResult=fpSystem->AddHLTOUTTask(fChains.Data()))>0);
     177           0 :       }
     178             :     } else {
     179             :       iResult=-ENOMEM;
     180             :     }
     181           0 :     if (iResult<0) {
     182           0 :       SetStatusFlag(kHandlerError);
     183           0 :       if (fpSystem) delete fpSystem; fpSystem=NULL;
     184           0 :     }
     185           0 :   }
     186           0 :   return iResult;
     187           0 : }

Generated by: LCOV version 1.11