]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTOUT.cxx
- HLT simulation writes digit data in addition to raw data
[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
c5123824 112 // data block, print warning when mismatch 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
c5123824 124 // data block, print warning when mismatch and user did not check
049b43b2 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
c5123824 146const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::GetDataBlockHandlerDesc()
147{
148 // see header file for class documentation
149 return FindHandlerDesc(GetDataBlockIndex());
150}
151
152AliHLTModuleAgent::AliHLTOUTHandlerType AliHLTOUT::GetDataBlockHandlerType()
153{
154 // see header file for class documentation
155 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=FindHandlerDesc(GetDataBlockIndex());
156 AliHLTModuleAgent::AliHLTOUTHandlerType type=desc;
157 return type;
158}
159
5db0e774 160AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
161{
162 // see header file for class documentation
18b56222 163 if (fCurrent==fBlockDescList.end()) return AliHLTOUTInvalidIndex;
164 return fCurrent->GetIndex();
5db0e774 165}
166
4de7334f 167int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
168{
169 // see header file for class documentation
170 int iResult=-ENOENT;
171 pBuffer=NULL;
172 size=0;
173 if (fCurrent!=fBlockDescList.end()) {
e94eb049 174 if ((iResult=GetDataBuffer(fCurrent->GetIndex(), pBuffer, size))>=0) {
4de7334f 175 fpBuffer=pBuffer;
176 }
177 }
178 return iResult;
179}
180
181int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
182{
183 // see header file for class documentation
184 int iResult=0;
185 if (pBuffer==fpBuffer) {
186 fpBuffer=NULL;
187 } else {
188 HLTWarning("buffer %p does not match the provided one %p", pBuffer, fpBuffer);
189 }
190 return iResult;
191}
192
c5123824 193AliHLTModuleAgent* AliHLTOUT::GetAgent()
194{
195 // see header file for class documentation
196 AliHLTModuleAgent* pAgent=NULL;
197 pAgent=FindHandlerDesc(GetDataBlockIndex());
198 return pAgent;
199}
200
626bfcc1 201AliHLTOUTHandler* AliHLTOUT::GetHandler()
202{
203 // see header file for class documentation
204 AliHLTOUTHandler* pHandler=NULL;
205 pHandler=FindHandlerDesc(GetDataBlockIndex());
206 return pHandler;
207}
208
c5123824 209int AliHLTOUT::WriteESD(const AliHLTUInt8_t* /*pBuffer*/, AliHLTUInt32_t /*size*/, AliHLTComponentDataType /*dt*/, AliESDEvent* /*tgtesd*/) const
210{
211 // see header file for class documentation
212 HLTWarning("method not implemented in base class");
213 return -ENOSYS;
214}
215
4de7334f 216int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
217{
62bb3cd4 218 // see header file for class documentation
049b43b2 219 if (!CheckStatusFlag(kCollecting)) return -EPERM;
4de7334f 220 int iResult=0;
221 fBlockDescList.push_back(desc);
222 return iResult;
62bb3cd4 223}
049b43b2 224
13398559 225AliHLTOUT::AliHLTOUTByteOrder AliHLTOUT::CheckByteOrder()
049b43b2 226{
5db0e774 227 // see header file for class documentation
049b43b2 228 if (fCurrent!=fBlockDescList.end()) {
229 SetStatusFlag(kByteOrderChecked);
13398559 230 AliHLTOUT::AliHLTOUTByteOrder order=CheckBlockByteOrder((*fCurrent).GetIndex());
049b43b2 231 return order;
232 }
233 return kInvalidByteOrder;
234}
235
13398559 236int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType type)
049b43b2 237{
5db0e774 238 // see header file for class documentation
049b43b2 239 if (fCurrent!=fBlockDescList.end()) {
240 SetStatusFlag(kAlignmentChecked);
241 int alignment=CheckBlockAlignment((*fCurrent).GetIndex(), type);
242 return alignment;
243 }
244 return -ENOENT;
245}
5db0e774 246
247int AliHLTOUT::InitHandlers()
248{
249 // see header file for class documentation
250 int iResult=0;
251 AliHLTOUTIndexList remnants;
44dc7683 252 int iCount=0;
a3ef3c1d 253 for (int havedata=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); havedata>=0; havedata=SelectNextDataBlock()) {
44dc7683 254 iCount++;
5db0e774 255 remnants.push_back(GetDataBlockIndex());
256 AliHLTComponentDataType dt=kAliHLTVoidDataType;
257 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
e94eb049 258 if (GetDataBlockDescription(dt, spec)<0) break;
5db0e774 259 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
260 AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
626bfcc1 261 if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) {
5db0e774 262 AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
c5123824 263 InsertHandler(fDataHandlers, entry);
5db0e774 264 remnants.pop_back();
265 break;
266 }
267 }
268 }
44dc7683 269
270 // warning if some of the data blocks are not selected by the kAliHLTAnyDataType
271 // criterion
272 if (GetNofDataBlocks()>iCount) {
273 HLTWarning("incomplete data type in %d out of %d data block(s)", GetNofDataBlocks()-iCount, iCount);
274 }
275
276 // warning if handler not found
5db0e774 277 if (remnants.size()>0) {
44dc7683 278 HLTWarning("no handlers found for %d data blocks out of %d", remnants.size(), iCount);
13398559 279 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
5db0e774 280 for (AliHLTOUTIndexList::iterator element=remnants.begin(); element!=remnants.end(); element++) {
281 for (int trials=0; trials<2; trials++) {
282 do {
283 // we start searching the index from the current position in the block list
284 if ((*block).GetIndex()==*element) break;
285 } while ((++block)!=fBlockDescList.end());
286 if (block==fBlockDescList.end()) {
287 // rewind and try again
288 block=fBlockDescList.begin();
289 }
290 }
291 assert(block!=fBlockDescList.end());
292 if (block!=fBlockDescList.end()) {
293 HLTDebug(" %s", AliHLTComponent::DataType2Text((AliHLTComponentDataType)*block).c_str());
294 }
295 }
296 }
297 return iResult;
298}
299
c5123824 300int AliHLTOUT::InsertHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTOUTHandlerListEntry &entry)
5db0e774 301{
302 // see header file for class documentation
303 int iResult=0;
c5123824 304 AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
305 while (element!=list.end()) {
5db0e774 306 if (entry==(*element)) break;
307 element++;
308 }
c5123824 309 if (element==list.end()) {
310 list.push_back(entry);
5db0e774 311 } else {
a3ef3c1d 312 element->AddIndex(const_cast<AliHLTOUTHandlerListEntry&>(entry));
5db0e774 313 }
314 return iResult;
315}
316
44dc7683 317const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::FindHandlerDesc(AliHLTUInt32_t blockIndex)
626bfcc1 318{
319 // see header file for class documentation
13398559 320 AliHLTOUTHandlerListEntryVector::iterator element=fDataHandlers.begin();
626bfcc1 321 while (element!=fDataHandlers.end()) {
322 if (element->HasIndex(blockIndex)) {
323 return *element;
324 }
325 element++;
326 }
44dc7683 327 return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry);
626bfcc1 328}
329
330AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry()
331 :
332 fpHandler(NULL),
333 fpHandlerDesc(NULL),
334 fpAgent(NULL),
335 fBlocks()
336{
337 // see header file for class documentation
338}
339
5db0e774 340AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
341 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
342 AliHLTModuleAgent* pAgent,
343 AliHLTUInt32_t index)
344 :
345 fpHandler(pHandler),
626bfcc1 346 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
5db0e774 347 fpAgent(pAgent),
348 fBlocks()
349{
350 // see header file for class documentation
626bfcc1 351 *fpHandlerDesc=handlerDesc;
5db0e774 352 fBlocks.push_back(index);
353}
354
355AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
356 :
357 fpHandler(src.fpHandler),
626bfcc1 358 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
5db0e774 359 fpAgent(src.fpAgent),
360 fBlocks()
361{
362 // see header file for class documentation
626bfcc1 363 *fpHandlerDesc=*src.fpHandlerDesc;
5db0e774 364 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
365}
366
fb24bec7 367AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
368{
369 // see header file for class documentation
626bfcc1 370 if (fpHandlerDesc) delete fpHandlerDesc;
371 fpHandlerDesc=NULL;
fb24bec7 372}
373
5db0e774 374AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
375{
376 // see header file for class documentation
377 fpHandler=src.fpHandler;
44dc7683 378 if (src.fpHandlerDesc)
379 *fpHandlerDesc=*src.fpHandlerDesc;
5db0e774 380 fpAgent=src.fpAgent;
381 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
382 return *this;
383}
384
18b56222 385AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const
386{
387 // see header file for class documentation
b0914d2e 388 return (int)fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
5db0e774 389}
390
fb24bec7 391bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
392{
18b56222 393 // see header file for class documentation
a3ef3c1d 394 if (entry.fpHandler!=fpHandler || fpHandler==NULL) return false;
395 assert(entry.fpAgent==fpAgent);
396 if (entry.fpAgent!=fpAgent) return false;
397 return true;
398}
399
44dc7683 400bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const
401{
402 // see header file for class documentation
403 if (!fpHandlerDesc) return false;
404 return *fpHandlerDesc==handlerType;
405}
406
a3ef3c1d 407void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTOUT::AliHLTOUTHandlerListEntry &desc)
408{
409 // see header file for class documentation
410 AliHLTOUTIndexList::iterator element;
411 for (element=desc.fBlocks.begin(); element!=desc.fBlocks.end(); element++) {
412 AddIndex(*element);
413 }
fb24bec7 414}
415
18b56222 416void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
417{
418 // see header file for class documentation
5db0e774 419 fBlocks.push_back(index);
420}
626bfcc1 421
200853e2 422bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index)
423{
424 // see header file for class documentation
a3ef3c1d 425 AliHLTOUTIndexList::iterator element;
426 for (element=fBlocks.begin(); element!=fBlocks.end(); element++) {
427 if (*element==index) return true;
428 }
200853e2 429 return false;
430}
431
626bfcc1 432const AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;
44dc7683 433
ff3b6fed 434AliHLTUInt64_t AliHLTOUT::ByteSwap64(AliHLTUInt64_t src)
44dc7683 435{
436 // see header file for class documentation
437 return ((src & 0xFFULL) << 56) |
438 ((src & 0xFF00ULL) << 40) |
439 ((src & 0xFF0000ULL) << 24) |
440 ((src & 0xFF000000ULL) << 8) |
441 ((src & 0xFF00000000ULL) >> 8) |
442 ((src & 0xFF0000000000ULL) >> 24) |
443 ((src & 0xFF000000000000ULL) >> 40) |
444 ((src & 0xFF00000000000000ULL) >> 56);
445}
446
ff3b6fed 447AliHLTUInt32_t AliHLTOUT::ByteSwap32(AliHLTUInt32_t src)
44dc7683 448{
449 // see header file for class documentation
450 return ((src & 0xFFULL) << 24) |
451 ((src & 0xFF00ULL) << 8) |
452 ((src & 0xFF0000ULL) >> 8) |
453 ((src & 0xFF000000ULL) >> 24);
454}