various fixes in the HLTOUT treatment
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUT.cxx
CommitLineData
62bb3cd4 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 AliHLTOUT.cxx
20 @author Matthias Richter
21 @date
22 @brief The control class for HLTOUT data. */
23
4de7334f 24// see header file for class documentation
25// or
26// refer to README to build package
27// or
28// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62bb3cd4 29
4de7334f 30#include <cerrno>
5db0e774 31#include <cassert>
62bb3cd4 32#include "AliHLTOUT.h"
33
34/** ROOT macro for the implementation of ROOT specific class methods */
35ClassImp(AliHLTOUT)
36
37AliHLTOUT::AliHLTOUT()
4de7334f 38 :
39 fSearchDataType(kAliHLTVoidDataType),
40 fSearchSpecification(kAliHLTVoidDataSpec),
049b43b2 41 fFlags(0),
4de7334f 42 fBlockDescList(),
43 fCurrent(fBlockDescList.begin()),
5db0e774 44 fpBuffer(NULL),
45 fDataHandlers()
4de7334f 46{
62bb3cd4 47 // see header file for class documentation
48 // or
49 // refer to README to build package
50 // or
51 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
52}
53
4b113031 54// definitions from ALICE internal note ALICE-INT-2002-010
55const unsigned char AliHLTOUT::fgkCDHStatusWord=4;
56const unsigned char AliHLTOUT::fgkCDHStatusFlagsOffset=12;
57
58// definitions from ALICE internal note ALICE-INT-2006-XXX
59const unsigned char AliHLTOUT::fgkCDHFlagsHLTDecision=6;
60const unsigned char AliHLTOUT::fgkCDHFlagsHLTPayload=7;
61
62bb3cd4 62AliHLTOUT::~AliHLTOUT()
4de7334f 63{
64 // see header file for class documentation
65}
66
5db0e774 67int AliHLTOUT::Init()
68{
69 // see header file for class documentation
70 int iResult=0;
18b56222 71 SetStatusFlag(kCollecting);
5db0e774 72 if ((iResult=GenerateIndex())>=0) {
73 if ((iResult=InitHandlers())>=0) {
74 }
75 }
18b56222 76 ClearStatusFlag(kCollecting);
5db0e774 77 return iResult;
78}
79
4de7334f 80int AliHLTOUT::GetNofDataBlocks()
81{
82 // see header file for class documentation
83 return fBlockDescList.size();
84}
85
5db0e774 86int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
87 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
4de7334f 88{
89 // see header file for class documentation
049b43b2 90 if (CheckStatusFlag(kLocked)) return -EPERM;
4de7334f 91 fCurrent=fBlockDescList.begin();
92 fSearchDataType=dt;
93 fSearchSpecification=spec;
5db0e774 94 //fSearchHandlerType=handlerType;
049b43b2 95 return FindAndSelectDataBlock();
4de7334f 96}
97
98int AliHLTOUT::SelectNextDataBlock()
99{
100 // see header file for class documentation
049b43b2 101 if (CheckStatusFlag(kLocked)) return -EPERM;
18b56222 102 if (fCurrent==fBlockDescList.end()) return -ENOENT;
049b43b2 103 fCurrent++;
104 return FindAndSelectDataBlock();
105}
106
107int AliHLTOUT::FindAndSelectDataBlock()
108{
109 // see header file for class documentation
110 if (CheckStatusFlag(kLocked)) return -EPERM;
4de7334f 111 int iResult=-ENOENT;
112 while (fCurrent!=fBlockDescList.end() && iResult==-ENOENT) {
d8f5c9fe 113 if ((*fCurrent)==fSearchDataType &&
5db0e774 114 fSearchSpecification==kAliHLTVoidDataSpec || (*fCurrent)==fSearchSpecification &&
115 1/*fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput*/) {
18b56222 116 iResult=fCurrent->GetIndex();
049b43b2 117 // TODO: check the byte order on the current system and the byte order of the
118 // data block, print warning when missmatch and user did not check
d76bc02a 119 //AliHLTOUTByteOrder_t blockBO=CheckByteOrder();
06f53caf 120 CheckByteOrder();
049b43b2 121 /*
122 if (blockBO!=fByteOrder) {
123 SetStatusFlag(kByteOrderWarning);
124
125 }
126 */
127 ClearStatusFlag(kByteOrderChecked);
128
129 // TODO: check the alignment on the current system and the alignment of the
130 // data block, print warning when missmatch and user did not check
131 ClearStatusFlag(kAlignmentChecked);
18b56222 132
133 break;
4de7334f 134 }
049b43b2 135 fCurrent++;
4de7334f 136 }
137 return iResult;
138}
139
140int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
141{
142 // see header file for class documentation
143 int iResult=-ENOENT;
144 if (fCurrent!=fBlockDescList.end()) {
145 iResult=0;
146 dt=(*fCurrent);
147 spec=(*fCurrent);
148 }
149 return iResult;
150}
151
5db0e774 152AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
153{
154 // see header file for class documentation
18b56222 155 if (fCurrent==fBlockDescList.end()) return AliHLTOUTInvalidIndex;
156 return fCurrent->GetIndex();
5db0e774 157}
158
4de7334f 159int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
160{
161 // see header file for class documentation
162 int iResult=-ENOENT;
163 pBuffer=NULL;
164 size=0;
165 if (fCurrent!=fBlockDescList.end()) {
166 if ((iResult=GetDataBuffer((*fCurrent).GetIndex(), pBuffer, size))>=0) {
167 fpBuffer=pBuffer;
168 }
169 }
170 return iResult;
171}
172
173int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
174{
175 // see header file for class documentation
176 int iResult=0;
177 if (pBuffer==fpBuffer) {
178 fpBuffer=NULL;
179 } else {
180 HLTWarning("buffer %p does not match the provided one %p", pBuffer, fpBuffer);
181 }
182 return iResult;
183}
184
185int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
186{
62bb3cd4 187 // see header file for class documentation
049b43b2 188 if (!CheckStatusFlag(kCollecting)) return -EPERM;
4de7334f 189 int iResult=0;
190 fBlockDescList.push_back(desc);
191 return iResult;
62bb3cd4 192}
049b43b2 193
194AliHLTOUT::AliHLTOUTByteOrder_t AliHLTOUT::CheckByteOrder()
195{
5db0e774 196 // see header file for class documentation
049b43b2 197 if (fCurrent!=fBlockDescList.end()) {
198 SetStatusFlag(kByteOrderChecked);
199 AliHLTOUT::AliHLTOUTByteOrder_t order=CheckBlockByteOrder((*fCurrent).GetIndex());
200 return order;
201 }
202 return kInvalidByteOrder;
203}
204
205int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType_t type)
206{
5db0e774 207 // see header file for class documentation
049b43b2 208 if (fCurrent!=fBlockDescList.end()) {
209 SetStatusFlag(kAlignmentChecked);
210 int alignment=CheckBlockAlignment((*fCurrent).GetIndex(), type);
211 return alignment;
212 }
213 return -ENOENT;
214}
5db0e774 215
216int AliHLTOUT::InitHandlers()
217{
218 // see header file for class documentation
219 int iResult=0;
220 AliHLTOUTIndexList remnants;
18b56222 221 for (iResult=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); iResult>=0; iResult=SelectNextDataBlock()) {
5db0e774 222 remnants.push_back(GetDataBlockIndex());
223 AliHLTComponentDataType dt=kAliHLTVoidDataType;
224 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
225 if ((iResult=GetDataBlockDescription(dt, spec))<0) break;
226 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
227 AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
228 if (pAgent->GetHandlerDescription(dt, spec, &handlerDesc)>0) {
229 AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
230 iResult=InsertHandler(entry);
231 remnants.pop_back();
232 break;
233 }
234 }
235 }
236 if (remnants.size()>0) {
237 HLTWarning("no handlers found for %d data blocks out of %d", remnants.size(), GetNofDataBlocks());
238 vector<AliHLTOUTBlockDescriptor>::iterator block=fBlockDescList.begin();
239 for (AliHLTOUTIndexList::iterator element=remnants.begin(); element!=remnants.end(); element++) {
240 for (int trials=0; trials<2; trials++) {
241 do {
242 // we start searching the index from the current position in the block list
243 if ((*block).GetIndex()==*element) break;
244 } while ((++block)!=fBlockDescList.end());
245 if (block==fBlockDescList.end()) {
246 // rewind and try again
247 block=fBlockDescList.begin();
248 }
249 }
250 assert(block!=fBlockDescList.end());
251 if (block!=fBlockDescList.end()) {
252 HLTDebug(" %s", AliHLTComponent::DataType2Text((AliHLTComponentDataType)*block).c_str());
253 }
254 }
255 }
256 return iResult;
257}
258
259int AliHLTOUT::InsertHandler(const AliHLTOUTHandlerListEntry &entry)
260{
261 // see header file for class documentation
262 int iResult=0;
263 vector<AliHLTOUTHandlerListEntry>::iterator element=fDataHandlers.begin();
264 while (element!=fDataHandlers.end()) {
265 if (entry==(*element)) break;
266 element++;
267 }
268 if (element==fDataHandlers.end()) {
269 fDataHandlers.push_back(entry);
270 } else {
271
272 }
273 return iResult;
274}
275
276AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
277 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
278 AliHLTModuleAgent* pAgent,
279 AliHLTUInt32_t index)
280 :
281 fpHandler(pHandler),
282 fHandlerDesc(handlerDesc),
283 fpAgent(pAgent),
284 fBlocks()
285{
286 // see header file for class documentation
287 fBlocks.push_back(index);
288}
289
290AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
291 :
292 fpHandler(src.fpHandler),
293 fHandlerDesc(src.fHandlerDesc),
294 fpAgent(src.fpAgent),
295 fBlocks()
296{
297 // see header file for class documentation
298 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
299}
300
fb24bec7 301AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
302{
303 // see header file for class documentation
304}
305
5db0e774 306AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
307{
308 // see header file for class documentation
309 fpHandler=src.fpHandler;
310 fHandlerDesc=src.fHandlerDesc;
311 fpAgent=src.fpAgent;
312 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
313 return *this;
314}
315
18b56222 316AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const
317{
318 // see header file for class documentation
5db0e774 319 return fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
320}
321
fb24bec7 322bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
323{
18b56222 324 // see header file for class documentation
325 assert(0); // not yet implemented
fb24bec7 326 return false;
327}
328
18b56222 329void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
330{
331 // see header file for class documentation
5db0e774 332 fBlocks.push_back(index);
333}