]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTOUT.cxx
General AliHLTComponent data types for ROOT objects added
[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),
44dc7683 41 fSearchHandlerType(AliHLTModuleAgent::kUnknownOutput),
049b43b2 42 fFlags(0),
4de7334f 43 fBlockDescList(),
44 fCurrent(fBlockDescList.begin()),
5db0e774 45 fpBuffer(NULL),
44dc7683 46 fDataHandlers(),
47 fbVerbose(true)
4de7334f 48{
62bb3cd4 49 // see header file for class documentation
50 // or
51 // refer to README to build package
52 // or
53 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
54}
55
56AliHLTOUT::~AliHLTOUT()
4de7334f 57{
58 // see header file for class documentation
59}
60
5db0e774 61int AliHLTOUT::Init()
62{
63 // see header file for class documentation
64 int iResult=0;
18b56222 65 SetStatusFlag(kCollecting);
5db0e774 66 if ((iResult=GenerateIndex())>=0) {
67 if ((iResult=InitHandlers())>=0) {
68 }
69 }
18b56222 70 ClearStatusFlag(kCollecting);
5db0e774 71 return iResult;
72}
73
4de7334f 74int AliHLTOUT::GetNofDataBlocks()
75{
76 // see header file for class documentation
77 return fBlockDescList.size();
78}
79
5db0e774 80int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
44dc7683 81 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
4de7334f 82{
83 // see header file for class documentation
049b43b2 84 if (CheckStatusFlag(kLocked)) return -EPERM;
4de7334f 85 fCurrent=fBlockDescList.begin();
86 fSearchDataType=dt;
87 fSearchSpecification=spec;
44dc7683 88 fSearchHandlerType=handlerType;
049b43b2 89 return FindAndSelectDataBlock();
4de7334f 90}
91
92int AliHLTOUT::SelectNextDataBlock()
93{
94 // see header file for class documentation
049b43b2 95 if (CheckStatusFlag(kLocked)) return -EPERM;
18b56222 96 if (fCurrent==fBlockDescList.end()) return -ENOENT;
049b43b2 97 fCurrent++;
98 return FindAndSelectDataBlock();
99}
100
101int AliHLTOUT::FindAndSelectDataBlock()
102{
103 // see header file for class documentation
104 if (CheckStatusFlag(kLocked)) return -EPERM;
4de7334f 105 int iResult=-ENOENT;
106 while (fCurrent!=fBlockDescList.end() && iResult==-ENOENT) {
d8f5c9fe 107 if ((*fCurrent)==fSearchDataType &&
44dc7683 108 (fSearchSpecification==kAliHLTVoidDataSpec || (*fCurrent)==fSearchSpecification) &&
109 (fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput || FindHandlerDesc(fCurrent->GetIndex())==fSearchHandlerType)) {
18b56222 110 iResult=fCurrent->GetIndex();
049b43b2 111 // TODO: check the byte order on the current system and the byte order of the
112 // data block, print warning when missmatch and user did not check
13398559 113 //AliHLTOUTByteOrder blockBO=CheckByteOrder();
06f53caf 114 CheckByteOrder();
049b43b2 115 /*
116 if (blockBO!=fByteOrder) {
117 SetStatusFlag(kByteOrderWarning);
118
119 }
120 */
121 ClearStatusFlag(kByteOrderChecked);
122
123 // TODO: check the alignment on the current system and the alignment of the
124 // data block, print warning when missmatch and user did not check
125 ClearStatusFlag(kAlignmentChecked);
18b56222 126
127 break;
4de7334f 128 }
049b43b2 129 fCurrent++;
4de7334f 130 }
131 return iResult;
132}
133
134int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
135{
136 // see header file for class documentation
137 int iResult=-ENOENT;
138 if (fCurrent!=fBlockDescList.end()) {
139 iResult=0;
140 dt=(*fCurrent);
141 spec=(*fCurrent);
142 }
143 return iResult;
144}
145
5db0e774 146AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
147{
148 // see header file for class documentation
18b56222 149 if (fCurrent==fBlockDescList.end()) return AliHLTOUTInvalidIndex;
150 return fCurrent->GetIndex();
5db0e774 151}
152
4de7334f 153int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
154{
155 // see header file for class documentation
156 int iResult=-ENOENT;
157 pBuffer=NULL;
158 size=0;
159 if (fCurrent!=fBlockDescList.end()) {
e94eb049 160 if ((iResult=GetDataBuffer(fCurrent->GetIndex(), pBuffer, size))>=0) {
4de7334f 161 fpBuffer=pBuffer;
162 }
163 }
164 return iResult;
165}
166
167int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
168{
169 // see header file for class documentation
170 int iResult=0;
171 if (pBuffer==fpBuffer) {
172 fpBuffer=NULL;
173 } else {
174 HLTWarning("buffer %p does not match the provided one %p", pBuffer, fpBuffer);
175 }
176 return iResult;
177}
178
626bfcc1 179AliHLTOUTHandler* AliHLTOUT::GetHandler()
180{
181 // see header file for class documentation
182 AliHLTOUTHandler* pHandler=NULL;
183 pHandler=FindHandlerDesc(GetDataBlockIndex());
184 return pHandler;
185}
186
4de7334f 187int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
188{
62bb3cd4 189 // see header file for class documentation
049b43b2 190 if (!CheckStatusFlag(kCollecting)) return -EPERM;
4de7334f 191 int iResult=0;
192 fBlockDescList.push_back(desc);
193 return iResult;
62bb3cd4 194}
049b43b2 195
13398559 196AliHLTOUT::AliHLTOUTByteOrder AliHLTOUT::CheckByteOrder()
049b43b2 197{
5db0e774 198 // see header file for class documentation
049b43b2 199 if (fCurrent!=fBlockDescList.end()) {
200 SetStatusFlag(kByteOrderChecked);
13398559 201 AliHLTOUT::AliHLTOUTByteOrder order=CheckBlockByteOrder((*fCurrent).GetIndex());
049b43b2 202 return order;
203 }
204 return kInvalidByteOrder;
205}
206
13398559 207int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType type)
049b43b2 208{
5db0e774 209 // see header file for class documentation
049b43b2 210 if (fCurrent!=fBlockDescList.end()) {
211 SetStatusFlag(kAlignmentChecked);
212 int alignment=CheckBlockAlignment((*fCurrent).GetIndex(), type);
213 return alignment;
214 }
215 return -ENOENT;
216}
5db0e774 217
218int AliHLTOUT::InitHandlers()
219{
220 // see header file for class documentation
221 int iResult=0;
222 AliHLTOUTIndexList remnants;
44dc7683 223 int iCount=0;
a3ef3c1d 224 for (int havedata=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); havedata>=0; havedata=SelectNextDataBlock()) {
44dc7683 225 iCount++;
5db0e774 226 remnants.push_back(GetDataBlockIndex());
227 AliHLTComponentDataType dt=kAliHLTVoidDataType;
228 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
e94eb049 229 if (GetDataBlockDescription(dt, spec)<0) break;
5db0e774 230 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
231 AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
626bfcc1 232 if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) {
5db0e774 233 AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
e94eb049 234 InsertHandler(entry);
5db0e774 235 remnants.pop_back();
236 break;
237 }
238 }
239 }
44dc7683 240
241 // warning if some of the data blocks are not selected by the kAliHLTAnyDataType
242 // criterion
243 if (GetNofDataBlocks()>iCount) {
244 HLTWarning("incomplete data type in %d out of %d data block(s)", GetNofDataBlocks()-iCount, iCount);
245 }
246
247 // warning if handler not found
5db0e774 248 if (remnants.size()>0) {
44dc7683 249 HLTWarning("no handlers found for %d data blocks out of %d", remnants.size(), iCount);
13398559 250 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
5db0e774 251 for (AliHLTOUTIndexList::iterator element=remnants.begin(); element!=remnants.end(); element++) {
252 for (int trials=0; trials<2; trials++) {
253 do {
254 // we start searching the index from the current position in the block list
255 if ((*block).GetIndex()==*element) break;
256 } while ((++block)!=fBlockDescList.end());
257 if (block==fBlockDescList.end()) {
258 // rewind and try again
259 block=fBlockDescList.begin();
260 }
261 }
262 assert(block!=fBlockDescList.end());
263 if (block!=fBlockDescList.end()) {
264 HLTDebug(" %s", AliHLTComponent::DataType2Text((AliHLTComponentDataType)*block).c_str());
265 }
266 }
267 }
268 return iResult;
269}
270
271int AliHLTOUT::InsertHandler(const AliHLTOUTHandlerListEntry &entry)
272{
273 // see header file for class documentation
274 int iResult=0;
13398559 275 AliHLTOUTHandlerListEntryVector::iterator element=fDataHandlers.begin();
5db0e774 276 while (element!=fDataHandlers.end()) {
277 if (entry==(*element)) break;
278 element++;
279 }
280 if (element==fDataHandlers.end()) {
281 fDataHandlers.push_back(entry);
282 } else {
a3ef3c1d 283 element->AddIndex(const_cast<AliHLTOUTHandlerListEntry&>(entry));
5db0e774 284 }
285 return iResult;
286}
287
44dc7683 288const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::FindHandlerDesc(AliHLTUInt32_t blockIndex)
626bfcc1 289{
290 // see header file for class documentation
13398559 291 AliHLTOUTHandlerListEntryVector::iterator element=fDataHandlers.begin();
626bfcc1 292 while (element!=fDataHandlers.end()) {
293 if (element->HasIndex(blockIndex)) {
294 return *element;
295 }
296 element++;
297 }
44dc7683 298 return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry);
626bfcc1 299}
300
301AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry()
302 :
303 fpHandler(NULL),
304 fpHandlerDesc(NULL),
305 fpAgent(NULL),
306 fBlocks()
307{
308 // see header file for class documentation
309}
310
5db0e774 311AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
312 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
313 AliHLTModuleAgent* pAgent,
314 AliHLTUInt32_t index)
315 :
316 fpHandler(pHandler),
626bfcc1 317 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
5db0e774 318 fpAgent(pAgent),
319 fBlocks()
320{
321 // see header file for class documentation
626bfcc1 322 *fpHandlerDesc=handlerDesc;
5db0e774 323 fBlocks.push_back(index);
324}
325
326AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
327 :
328 fpHandler(src.fpHandler),
626bfcc1 329 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
5db0e774 330 fpAgent(src.fpAgent),
331 fBlocks()
332{
333 // see header file for class documentation
626bfcc1 334 *fpHandlerDesc=*src.fpHandlerDesc;
5db0e774 335 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
336}
337
fb24bec7 338AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
339{
340 // see header file for class documentation
626bfcc1 341 if (fpHandlerDesc) delete fpHandlerDesc;
342 fpHandlerDesc=NULL;
fb24bec7 343}
344
5db0e774 345AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
346{
347 // see header file for class documentation
348 fpHandler=src.fpHandler;
44dc7683 349 if (src.fpHandlerDesc)
350 *fpHandlerDesc=*src.fpHandlerDesc;
5db0e774 351 fpAgent=src.fpAgent;
352 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
353 return *this;
354}
355
18b56222 356AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const
357{
358 // see header file for class documentation
b0914d2e 359 return (int)fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
5db0e774 360}
361
fb24bec7 362bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
363{
18b56222 364 // see header file for class documentation
a3ef3c1d 365 if (entry.fpHandler!=fpHandler || fpHandler==NULL) return false;
366 assert(entry.fpAgent==fpAgent);
367 if (entry.fpAgent!=fpAgent) return false;
368 return true;
369}
370
44dc7683 371bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const
372{
373 // see header file for class documentation
374 if (!fpHandlerDesc) return false;
375 return *fpHandlerDesc==handlerType;
376}
377
a3ef3c1d 378void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTOUT::AliHLTOUTHandlerListEntry &desc)
379{
380 // see header file for class documentation
381 AliHLTOUTIndexList::iterator element;
382 for (element=desc.fBlocks.begin(); element!=desc.fBlocks.end(); element++) {
383 AddIndex(*element);
384 }
fb24bec7 385}
386
18b56222 387void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
388{
389 // see header file for class documentation
5db0e774 390 fBlocks.push_back(index);
391}
626bfcc1 392
200853e2 393bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index)
394{
395 // see header file for class documentation
a3ef3c1d 396 AliHLTOUTIndexList::iterator element;
397 for (element=fBlocks.begin(); element!=fBlocks.end(); element++) {
398 if (*element==index) return true;
399 }
200853e2 400 return false;
401}
402
626bfcc1 403const AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;
44dc7683 404
ff3b6fed 405AliHLTUInt64_t AliHLTOUT::ByteSwap64(AliHLTUInt64_t src)
44dc7683 406{
407 // see header file for class documentation
408 return ((src & 0xFFULL) << 56) |
409 ((src & 0xFF00ULL) << 40) |
410 ((src & 0xFF0000ULL) << 24) |
411 ((src & 0xFF000000ULL) << 8) |
412 ((src & 0xFF00000000ULL) >> 8) |
413 ((src & 0xFF0000000000ULL) >> 24) |
414 ((src & 0xFF000000000000ULL) >> 40) |
415 ((src & 0xFF00000000000000ULL) >> 56);
416}
417
ff3b6fed 418AliHLTUInt32_t AliHLTOUT::ByteSwap32(AliHLTUInt32_t src)
44dc7683 419{
420 // see header file for class documentation
421 return ((src & 0xFFULL) << 24) |
422 ((src & 0xFF00ULL) << 8) |
423 ((src & 0xFF0000ULL) >> 8) |
424 ((src & 0xFF000000ULL) >> 24);
425}