]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTOUTHandlerChain.cxx
- bugfix HLTOUT processing: handler execution for sub-collections
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUTHandlerChain.cxx
CommitLineData
7131ea63 1// $Id$
2
3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
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
33/** ROOT macro for the implementation of ROOT specific class methods */
34ClassImp(AliHLTOUTHandlerChain)
35
36AliHLTOUTHandlerChain::AliHLTOUTHandlerChain(const char* arguments)
37 :
38 fChains(),
39 fOptions(),
40 fpSystem(NULL),
41 fpTask(NULL)
42{
43 // see header file for class documentation
44 // or
45 // refer to README to build package
46 // or
47 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
48 if (arguments) {
49 TString args=arguments;
50 TObjArray* pTokens=args.Tokenize(" ");
51 if (pTokens) {
52 int iEntries=pTokens->GetEntries();
53 for (int i=0; i<iEntries; i++) {
54 TString token=(((TObjString*)pTokens->At(i))->GetString());
55 if (token.Contains("chains=")) {
56 TString param=token.ReplaceAll("chains=", "");
57 fChains=param.ReplaceAll(",", " ");
58 } else {
59 if (!fOptions.IsNull()) fOptions+=" ";
60 fOptions+=token;
61 }
62 }
63 delete pTokens;
64 }
65 }
66}
67
68AliHLTOUTHandlerChain::~AliHLTOUTHandlerChain()
69{
70 // see header file for class documentation
71 if (fpSystem) {
72 delete fpSystem;
73 }
74}
75
76int AliHLTOUTHandlerChain::ProcessData(AliHLTOUT* pData)
77{
78 // see header file for class documentation
79 if (!pData) return -EINVAL;
80 int iResult=0;
81
82 if (CheckStatus(kHandlerError)) {
83 HLTWarning("kChain handler '%s' in error state, skipping processing of associated HLTOUT blocks", fChains.Data());
84 return -EPERM;
85 }
86
87 if (!fpSystem && (iResult=InitSystem())<0) {
88 return iResult;
89 }
90
f3c1d403 91 if (fpSystem->CheckStatus(AliHLTSystem::kError) || !fpTask) {
7131ea63 92 HLTWarning("kChain handler '%s': system in error state, skipping processing of associated HLTOUT blocks", fChains.Data());
93 return -EACCES;
94 }
95
96 // run one event and do not stop the chain
f3c1d403 97 fpTask->Reset();
7131ea63 98 {
99 AliHLTOUT::AliHLTOUTGlobalInstanceGuard g(pData);
100 if ((iResult=fpSystem->Run(1,0))>=0) {
101 // sub-collection is going to be reset from the
102 // parent HLTOUT collection
103 AliHLTOUT* pSubCollection=dynamic_cast<AliHLTOUT*>(fpTask);
104 pSubCollection->Init();
105 pData->AddSubCollection(pSubCollection);
106 } else {
107 fpTask->Reset();
108 }
109 }
110
111 return iResult;
112}
113
114int AliHLTOUTHandlerChain::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/)
115{
116 //default implementation, nothing to do
117 return 0;
118}
119
120int AliHLTOUTHandlerChain::InitSystem()
121{
122 // see header file for class documentation
123 int iResult=0;
124 if (!fpSystem) {
125 // init AliHLTSystem
126 fpSystem = new AliHLTSystem(GetGlobalLoggingLevel());
127 if (fpSystem) {
128 if ((iResult=fpSystem->ScanOptions(fOptions.Data()))>=0) {
129 // load configurations if not specified by external macro
130 if (!fOptions.Contains("config="))
131 iResult=CreateConfigurations(fpSystem->fpConfigurationHandler);
132
133 if (iResult>=0) {
134 iResult=fpSystem->BuildTaskList(fChains.Data());
135 }
136
137 // add AliHLTOUTTask on top of the configuartions in order to
138 // collect the data
139 fpTask=new AliHLTOUTTask(fChains.Data());
140 }
141 } else {
142 iResult=-ENOMEM;
143 }
144 if (iResult>=0 && fpSystem && fpTask) {
145 if (fpTask->GetConf() && fpTask->GetConf()->SourcesResolved()>=0) {
146 iResult=fpSystem->InsertTask(fpTask);
147 } else {
148 HLTError("HLTOUT task (%s) sources not resolved", fpTask->GetName());
149 iResult=-ENOENT;
150 }
151 }
152 if (iResult<0 || !fpTask) {
153 SetStatusFlag(kHandlerError);
154 if (fpSystem) delete fpSystem; fpSystem=NULL;
155 if (fpTask) delete fpTask; fpTask=NULL;
156 }
157 }
158 return iResult;
159}