3 //**************************************************************************
4 //* This file is property of and copyright by the *
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 // 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.
52 TString args=arguments;
53 TObjArray* pTokens=args.Tokenize(" ");
55 int iEntries=pTokens->GetEntries();
56 for (int i=0; i<iEntries; i++) {
57 TString token=(((TObjString*)pTokens->At(i))->GetString());
58 if (token.Contains("chains=")) {
59 TString param=token.ReplaceAll("chains=", "");
60 fChains=param.ReplaceAll(",", " ");
62 if (!fOptions.IsNull()) fOptions+=" ";
71 AliHLTOUTHandlerChain::~AliHLTOUTHandlerChain()
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);
87 int AliHLTOUTHandlerChain::ProcessData(AliHLTOUT* pData)
89 // data processing function
90 if (!pData) return -EINVAL;
93 if (CheckStatus(kHandlerError)) {
94 HLTWarning("kChain handler '%s' in error state, skipping processing of associated HLTOUT blocks", fChains.Data());
98 if (!fpSystem && (iResult=InitSystem())<0) {
102 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
103 HLTWarning("kChain handler '%s': system in error state, skipping processing of associated HLTOUT blocks", fChains.Data());
107 // run one event and do not stop the chain
109 AliHLTOUT::AliHLTOUTGlobalInstanceGuard g(pData);
110 if ((iResult=fpSystem->Run(1,0))>=0) {
111 // sub-collection is going to be reset from the
112 // parent HLTOUT collection
113 AliHLTOUTTask* pTask=fpSystem->GetHLTOUTTask();
115 // either have the task or none of the chains controlled by the chain
116 // handler has output
117 assert(pTask || !fbHaveOutput);
119 AliHLTOUT* pSubCollection=dynamic_cast<AliHLTOUT*>(pTask);
120 pSubCollection->Init();
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 for (iResult=pSubCollection->SelectFirstDataBlock();
128 iResult=pSubCollection->SelectNextDataBlock()) {
129 AliHLTComponentDataType dt=kAliHLTVoidDataType;
130 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
131 pSubCollection->GetDataBlockDescription(dt, spec);
132 if (dt==kAliHLTDataTypeComponentStatistics) {
133 pSubCollection->MarkDataBlockProcessed();
136 pData->AddSubCollection(pSubCollection);
137 } else if (fbHaveOutput) {
138 // this is an error condition since task has been created and should
140 HLTError("can not get instance of HLTOUT task from HLT system %p", fpSystem);
148 int AliHLTOUTHandlerChain::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/)
150 //default implementation, nothing to do
154 int AliHLTOUTHandlerChain::InitSystem()
156 // initialize the AliHLTSystem instance
160 TString systemName="kChain_"; systemName+=fChains;
161 systemName.ReplaceAll(" ", "_");
162 fpSystem = new AliHLTSystem(GetGlobalLoggingLevel(), systemName);
164 if ((iResult=fpSystem->ScanOptions(fOptions.Data()))>=0) {
165 // load configurations if not specified by external macro
166 if (!fOptions.Contains("config="))
167 iResult=CreateConfigurations(fpSystem->GetConfigurationHandler());
170 iResult=fpSystem->BuildTaskList(fChains.Data());
173 // add AliHLTOUTTask on top of the configuartions in order to
175 // remember if task has been created (result>0)
176 fbHaveOutput=((iResult=fpSystem->AddHLTOUTTask(fChains.Data()))>0);
182 SetStatusFlag(kHandlerError);
183 if (fpSystem) delete fpSystem; fpSystem=NULL;