3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /** @file AliHLTOUTHandlerChain.cxx
20 @author Matthias Richter
22 @brief HLTOUT handler of type kChain.
25 #include "AliHLTOUTHandlerChain.h"
26 #include "AliHLTOUT.h"
27 #include "AliHLTSystem.h"
28 #include "AliHLTOUTTask.h"
30 #include "TObjString.h"
31 #include "TObjArray.h"
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTOUTHandlerChain)
37 AliHLTOUTHandlerChain::AliHLTOUTHandlerChain(const char* arguments)
44 // see header file for class documentation
46 // refer to README to build package
48 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
50 TString args=arguments;
51 TObjArray* pTokens=args.Tokenize(" ");
53 int iEntries=pTokens->GetEntries();
54 for (int i=0; i<iEntries; i++) {
55 TString token=(((TObjString*)pTokens->At(i))->GetString());
56 if (token.Contains("chains=")) {
57 TString param=token.ReplaceAll("chains=", "");
58 fChains=param.ReplaceAll(",", " ");
60 if (!fOptions.IsNull()) fOptions+=" ";
69 AliHLTOUTHandlerChain::~AliHLTOUTHandlerChain()
71 // see header file for class documentation
73 // TODO: the EOR is currenttly not send because the reconstruction
74 // chian is not stopped. Trying it here gives an error, there is
75 // some state mismatch in AliHLTSystem. Probably due to the fact,
76 // that the AliHLTSystem::Reconstruct method is not used
77 // if (!fpSystem->CheckStatus(AliHLTSystem::kError)) {
78 // // send specific 'event' to execute the stop sequence
79 // fpSystem->Reconstruct(0, NULL, NULL);
85 int AliHLTOUTHandlerChain::ProcessData(AliHLTOUT* pData)
87 // see header file for class documentation
88 if (!pData) return -EINVAL;
91 if (CheckStatus(kHandlerError)) {
92 HLTWarning("kChain handler '%s' in error state, skipping processing of associated HLTOUT blocks", fChains.Data());
96 if (!fpSystem && (iResult=InitSystem())<0) {
100 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
101 HLTWarning("kChain handler '%s': system in error state, skipping processing of associated HLTOUT blocks", fChains.Data());
105 // run one event and do not stop the chain
107 AliHLTOUT::AliHLTOUTGlobalInstanceGuard g(pData);
108 if ((iResult=fpSystem->Run(1,0))>=0) {
109 // sub-collection is going to be reset from the
110 // parent HLTOUT collection
111 AliHLTOUTTask* pTask=fpSystem->GetHLTOUTTask();
113 // either have the task or none of the chains controlled by the chain
114 // handler has output
115 assert(pTask || !fbHaveOutput);
117 AliHLTOUT* pSubCollection=dynamic_cast<AliHLTOUT*>(pTask);
118 pSubCollection->Init();
120 // filter out some data blocks which should not be processed
121 // in the next stage:
122 // 1. we are not interested in the component statistics
123 // produced in the HLTOUT handler chain
124 for (iResult=pSubCollection->SelectFirstDataBlock();
126 iResult=pSubCollection->SelectNextDataBlock()) {
127 AliHLTComponentDataType dt=kAliHLTVoidDataType;
128 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
129 pSubCollection->GetDataBlockDescription(dt, spec);
130 if (dt==kAliHLTDataTypeComponentStatistics) {
131 pSubCollection->MarkDataBlockProcessed();
134 pData->AddSubCollection(pSubCollection);
135 } else if (fbHaveOutput) {
136 // this is an error condition since task has been created and should
138 HLTError("can not get instance of HLTOUT task from HLT system %p", fpSystem);
146 int AliHLTOUTHandlerChain::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/)
148 //default implementation, nothing to do
152 int AliHLTOUTHandlerChain::InitSystem()
154 // see header file for class documentation
158 TString systemName="kChain_"; systemName+=fChains;
159 systemName.ReplaceAll(" ", "_");
160 fpSystem = new AliHLTSystem(GetGlobalLoggingLevel(), systemName);
162 if ((iResult=fpSystem->ScanOptions(fOptions.Data()))>=0) {
163 // load configurations if not specified by external macro
164 if (!fOptions.Contains("config="))
165 iResult=CreateConfigurations(fpSystem->GetConfigurationHandler());
168 iResult=fpSystem->BuildTaskList(fChains.Data());
171 // add AliHLTOUTTask on top of the configuartions in order to
173 // remember if task has been created (result>0)
174 fbHaveOutput=((iResult=fpSystem->AddHLTOUTTask(fChains.Data()))>0);
180 SetStatusFlag(kHandlerError);
181 if (fpSystem) delete fpSystem; fpSystem=NULL;