]>
Commit | Line | Data |
---|---|---|
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" | |
19b5c321 | 32 | #include <cassert> |
7131ea63 | 33 | |
34 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
35 | ClassImp(AliHLTOUTHandlerChain) | |
36 | ||
37 | AliHLTOUTHandlerChain::AliHLTOUTHandlerChain(const char* arguments) | |
38 | : | |
39 | fChains(), | |
40 | fOptions(), | |
41 | fpSystem(NULL), | |
19b5c321 | 42 | fbHaveOutput(false) |
7131ea63 | 43 | { |
44 | // see header file for class documentation | |
45 | // or | |
46 | // refer to README to build package | |
47 | // or | |
48 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
49 | if (arguments) { | |
50 | TString args=arguments; | |
51 | TObjArray* pTokens=args.Tokenize(" "); | |
52 | if (pTokens) { | |
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(",", " "); | |
59 | } else { | |
60 | if (!fOptions.IsNull()) fOptions+=" "; | |
61 | fOptions+=token; | |
62 | } | |
63 | } | |
64 | delete pTokens; | |
65 | } | |
66 | } | |
67 | } | |
68 | ||
69 | AliHLTOUTHandlerChain::~AliHLTOUTHandlerChain() | |
70 | { | |
71 | // see header file for class documentation | |
72 | if (fpSystem) { | |
a472be38 | 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); | |
80 | // } | |
7131ea63 | 81 | delete fpSystem; |
82 | } | |
83 | } | |
84 | ||
85 | int AliHLTOUTHandlerChain::ProcessData(AliHLTOUT* pData) | |
86 | { | |
87 | // see header file for class documentation | |
88 | if (!pData) return -EINVAL; | |
89 | int iResult=0; | |
90 | ||
91 | if (CheckStatus(kHandlerError)) { | |
92 | HLTWarning("kChain handler '%s' in error state, skipping processing of associated HLTOUT blocks", fChains.Data()); | |
93 | return -EPERM; | |
94 | } | |
95 | ||
96 | if (!fpSystem && (iResult=InitSystem())<0) { | |
97 | return iResult; | |
98 | } | |
99 | ||
19b5c321 | 100 | if (fpSystem->CheckStatus(AliHLTSystem::kError)) { |
7131ea63 | 101 | HLTWarning("kChain handler '%s': system in error state, skipping processing of associated HLTOUT blocks", fChains.Data()); |
102 | return -EACCES; | |
103 | } | |
104 | ||
105 | // run one event and do not stop the chain | |
106 | { | |
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 | |
19b5c321 | 111 | AliHLTOUTTask* pTask=fpSystem->GetHLTOUTTask(); |
112 | ||
113 | // either have the task or none of the chains controlled by the chain | |
114 | // handler has output | |
115 | assert(pTask || !fbHaveOutput); | |
116 | if (pTask) { | |
117 | AliHLTOUT* pSubCollection=dynamic_cast<AliHLTOUT*>(pTask); | |
7131ea63 | 118 | pSubCollection->Init(); |
f75868b3 | 119 | |
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(); | |
125 | iResult>=0; | |
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(); | |
132 | } | |
133 | } | |
7131ea63 | 134 | pData->AddSubCollection(pSubCollection); |
19b5c321 | 135 | } else if (fbHaveOutput) { |
136 | // this is an error condition since task has been created and should | |
137 | // be available | |
138 | HLTError("can not get instance of HLTOUT task from HLT system %p", fpSystem); | |
139 | } | |
7131ea63 | 140 | } |
141 | } | |
142 | ||
143 | return iResult; | |
144 | } | |
145 | ||
146 | int AliHLTOUTHandlerChain::CreateConfigurations(AliHLTConfigurationHandler* /*handler*/) | |
147 | { | |
148 | //default implementation, nothing to do | |
149 | return 0; | |
150 | } | |
151 | ||
152 | int AliHLTOUTHandlerChain::InitSystem() | |
153 | { | |
154 | // see header file for class documentation | |
155 | int iResult=0; | |
156 | if (!fpSystem) { | |
157 | // init AliHLTSystem | |
19b5c321 | 158 | TString systemName="kChain_"; systemName+=fChains; |
159 | systemName.ReplaceAll(" ", "_"); | |
160 | fpSystem = new AliHLTSystem(GetGlobalLoggingLevel(), systemName); | |
7131ea63 | 161 | if (fpSystem) { |
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->fpConfigurationHandler); | |
166 | ||
167 | if (iResult>=0) { | |
168 | iResult=fpSystem->BuildTaskList(fChains.Data()); | |
169 | } | |
170 | ||
171 | // add AliHLTOUTTask on top of the configuartions in order to | |
172 | // collect the data | |
19b5c321 | 173 | // remember if task has been created (result>0) |
174 | fbHaveOutput=((iResult=fpSystem->AddHLTOUTTask(fChains.Data()))>0); | |
7131ea63 | 175 | } |
176 | } else { | |
177 | iResult=-ENOMEM; | |
178 | } | |
19b5c321 | 179 | if (iResult<0) { |
7131ea63 | 180 | SetStatusFlag(kHandlerError); |
181 | if (fpSystem) delete fpSystem; fpSystem=NULL; | |
7131ea63 | 182 | } |
183 | } | |
184 | return iResult; | |
185 | } |