Implementation of kChain HLTOUT handler
[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
91 if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
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
97 {
98 AliHLTOUT::AliHLTOUTGlobalInstanceGuard g(pData);
99 if ((iResult=fpSystem->Run(1,0))>=0) {
100 // sub-collection is going to be reset from the
101 // parent HLTOUT collection
102 AliHLTOUT* pSubCollection=dynamic_cast<AliHLTOUT*>(fpTask);
103 pSubCollection->Init();
104 pData->AddSubCollection(pSubCollection);
105 } else {
106 fpTask->Reset();
107 }
108 }
109
110 return iResult;
111}
112
113int AliHLTOUTHandlerChain::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/)
114{
115 //default implementation, nothing to do
116 return 0;
117}
118
119int AliHLTOUTHandlerChain::InitSystem()
120{
121 // see header file for class documentation
122 int iResult=0;
123 if (!fpSystem) {
124 // init AliHLTSystem
125 fpSystem = new AliHLTSystem(GetGlobalLoggingLevel());
126 if (fpSystem) {
127 if ((iResult=fpSystem->ScanOptions(fOptions.Data()))>=0) {
128 // load configurations if not specified by external macro
129 if (!fOptions.Contains("config="))
130 iResult=CreateConfigurations(fpSystem->fpConfigurationHandler);
131
132 if (iResult>=0) {
133 iResult=fpSystem->BuildTaskList(fChains.Data());
134 }
135
136 // add AliHLTOUTTask on top of the configuartions in order to
137 // collect the data
138 fpTask=new AliHLTOUTTask(fChains.Data());
139 }
140 } else {
141 iResult=-ENOMEM;
142 }
143 if (iResult>=0 && fpSystem && fpTask) {
144 if (fpTask->GetConf() && fpTask->GetConf()->SourcesResolved()>=0) {
145 iResult=fpSystem->InsertTask(fpTask);
146 } else {
147 HLTError("HLTOUT task (%s) sources not resolved", fpTask->GetName());
148 iResult=-ENOENT;
149 }
150 }
151 if (iResult<0 || !fpTask) {
152 SetStatusFlag(kHandlerError);
153 if (fpSystem) delete fpSystem; fpSystem=NULL;
154 if (fpTask) delete fpTask; fpTask=NULL;
155 }
156 }
157 return iResult;
158}