]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTOUT.cxx
reverting r27483 partially in order to cope with bug of the PubSub framework
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUT.cxx
CommitLineData
62bb3cd4 1// $Id$
2
0f1882a7 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//**************************************************************************
62bb3cd4 18
19/** @file AliHLTOUT.cxx
20 @author Matthias Richter
21 @date
0f1882a7 22 @brief The control class for HLTOUT data.
23*/
62bb3cd4 24
4de7334f 25#include <cerrno>
5db0e774 26#include <cassert>
62bb3cd4 27#include "AliHLTOUT.h"
c1292031 28#include "TSystem.h"
29#include "TClass.h"
30#include "TROOT.h"
62bb3cd4 31
32/** ROOT macro for the implementation of ROOT specific class methods */
33ClassImp(AliHLTOUT)
34
35AliHLTOUT::AliHLTOUT()
4de7334f 36 :
37 fSearchDataType(kAliHLTVoidDataType),
38 fSearchSpecification(kAliHLTVoidDataSpec),
44dc7683 39 fSearchHandlerType(AliHLTModuleAgent::kUnknownOutput),
0f1882a7 40 fFlags(kSkipProcessed),
4de7334f 41 fBlockDescList(),
0f1882a7 42 fCurrent(0),
5db0e774 43 fpBuffer(NULL),
44dc7683 44 fDataHandlers(),
b005ef92 45 fbVerbose(true),
46 fLog()
4de7334f 47{
62bb3cd4 48 // see header file for class documentation
49 // or
50 // refer to README to build package
51 // or
52 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
53}
54
55AliHLTOUT::~AliHLTOUT()
4de7334f 56{
57 // see header file for class documentation
0f1882a7 58 if (CheckStatusFlag(kIsSubCollection)) {
b005ef92 59 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "~AliHLTOUT" , __FILE__ , __LINE__ , "severe internal error: collection has not been released, potential crash due to invalid pointer");
0f1882a7 60 }
4de7334f 61}
b005ef92 62AliHLTOUT* AliHLTOUT::fgGlobalInstance=NULL;
4de7334f 63
5db0e774 64int AliHLTOUT::Init()
65{
66 // see header file for class documentation
67 int iResult=0;
f3c1d403 68
69 // ignore if already initialized
70 if (fBlockDescList.size()>0) {
71 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "Init" , __FILE__ , __LINE__ , "instance %p already initialized, skipping ...", this);
72 return 0;
73 }
74
18b56222 75 SetStatusFlag(kCollecting);
5db0e774 76 if ((iResult=GenerateIndex())>=0) {
77 if ((iResult=InitHandlers())>=0) {
78 }
79 }
18b56222 80 ClearStatusFlag(kCollecting);
5db0e774 81 return iResult;
82}
83
4de7334f 84int AliHLTOUT::GetNofDataBlocks()
85{
86 // see header file for class documentation
87 return fBlockDescList.size();
88}
89
5db0e774 90int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
0f1882a7 91 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType,
92 bool skipProcessed)
4de7334f 93{
94 // see header file for class documentation
0f1882a7 95 fCurrent=0;
4de7334f 96 fSearchDataType=dt;
97 fSearchSpecification=spec;
44dc7683 98 fSearchHandlerType=handlerType;
0f1882a7 99 if (skipProcessed) SetStatusFlag(kSkipProcessed);
100 else ClearStatusFlag(kSkipProcessed);
049b43b2 101 return FindAndSelectDataBlock();
4de7334f 102}
103
104int AliHLTOUT::SelectNextDataBlock()
105{
106 // see header file for class documentation
0f1882a7 107 if (fCurrent>=fBlockDescList.size()) return -ENOENT;
049b43b2 108 fCurrent++;
109 return FindAndSelectDataBlock();
110}
111
112int AliHLTOUT::FindAndSelectDataBlock()
113{
114 // see header file for class documentation
115 if (CheckStatusFlag(kLocked)) return -EPERM;
4de7334f 116 int iResult=-ENOENT;
0f1882a7 117 while (fCurrent<fBlockDescList.size() && iResult==-ENOENT) {
118 if (fBlockDescList[fCurrent]==fSearchDataType &&
119 (fSearchSpecification==kAliHLTVoidDataSpec || fBlockDescList[fCurrent]==fSearchSpecification) &&
512302d3 120 (fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput || FindHandlerDesc(fCurrent)==fSearchHandlerType) &&
0f1882a7 121 (!CheckStatusFlag(kBlockSelection) || fBlockDescList[fCurrent].IsSelected()) &&
122 (!CheckStatusFlag(kSkipProcessed) || !fBlockDescList[fCurrent].IsProcessed())) {
123 iResult=fBlockDescList[fCurrent].GetIndex();
049b43b2 124 // TODO: check the byte order on the current system and the byte order of the
c5123824 125 // data block, print warning when mismatch and user did not check
13398559 126 //AliHLTOUTByteOrder blockBO=CheckByteOrder();
06f53caf 127 CheckByteOrder();
049b43b2 128 /*
129 if (blockBO!=fByteOrder) {
130 SetStatusFlag(kByteOrderWarning);
131
132 }
133 */
134 ClearStatusFlag(kByteOrderChecked);
135
136 // TODO: check the alignment on the current system and the alignment of the
c5123824 137 // data block, print warning when mismatch and user did not check
049b43b2 138 ClearStatusFlag(kAlignmentChecked);
18b56222 139
140 break;
4de7334f 141 }
049b43b2 142 fCurrent++;
4de7334f 143 }
144 return iResult;
145}
146
147int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
148{
149 // see header file for class documentation
150 int iResult=-ENOENT;
0f1882a7 151 if (fCurrent<fBlockDescList.size()) {
4de7334f 152 iResult=0;
0f1882a7 153 dt=fBlockDescList[fCurrent];
154 spec=fBlockDescList[fCurrent];
4de7334f 155 }
156 return iResult;
157}
158
c5123824 159const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::GetDataBlockHandlerDesc()
160{
161 // see header file for class documentation
512302d3 162 return FindHandlerDesc(fCurrent);
c5123824 163}
164
165AliHLTModuleAgent::AliHLTOUTHandlerType AliHLTOUT::GetDataBlockHandlerType()
166{
167 // see header file for class documentation
512302d3 168 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=FindHandlerDesc(fCurrent);
c5123824 169 AliHLTModuleAgent::AliHLTOUTHandlerType type=desc;
170 return type;
171}
172
5db0e774 173AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
174{
175 // see header file for class documentation
0f1882a7 176 if (fCurrent>=fBlockDescList.size()) return AliHLTOUTInvalidIndex;
177 return fBlockDescList[fCurrent].GetIndex();
5db0e774 178}
179
4de7334f 180int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
181{
182 // see header file for class documentation
183 int iResult=-ENOENT;
184 pBuffer=NULL;
185 size=0;
0f1882a7 186 if (fCurrent<fBlockDescList.size()) {
187 if ((iResult=fBlockDescList[fCurrent].GetDataBuffer(pBuffer, size))>=0) {
4de7334f 188 fpBuffer=pBuffer;
189 }
190 }
191 return iResult;
192}
193
194int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
195{
196 // see header file for class documentation
197 int iResult=0;
198 if (pBuffer==fpBuffer) {
199 fpBuffer=NULL;
200 } else {
b005ef92 201 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "ReleaseDataBuffer" , __FILE__ , __LINE__ , "buffer %p does not match the provided one %p", pBuffer, fpBuffer);
4de7334f 202 }
203 return iResult;
204}
205
c5123824 206AliHLTModuleAgent* AliHLTOUT::GetAgent()
207{
208 // see header file for class documentation
209 AliHLTModuleAgent* pAgent=NULL;
512302d3 210 pAgent=FindHandlerDesc(fCurrent);
c5123824 211 return pAgent;
212}
213
626bfcc1 214AliHLTOUTHandler* AliHLTOUT::GetHandler()
215{
216 // see header file for class documentation
217 AliHLTOUTHandler* pHandler=NULL;
512302d3 218 pHandler=FindHandlerDesc(fCurrent);
626bfcc1 219 return pHandler;
220}
221
c5123824 222int AliHLTOUT::WriteESD(const AliHLTUInt8_t* /*pBuffer*/, AliHLTUInt32_t /*size*/, AliHLTComponentDataType /*dt*/, AliESDEvent* /*tgtesd*/) const
223{
224 // see header file for class documentation
b005ef92 225 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "WriteESD" , __FILE__ , __LINE__ , "method not implemented in base class");
c5123824 226 return -ENOSYS;
227}
228
4de7334f 229int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
230{
62bb3cd4 231 // see header file for class documentation
049b43b2 232 if (!CheckStatusFlag(kCollecting)) return -EPERM;
4de7334f 233 int iResult=0;
234 fBlockDescList.push_back(desc);
235 return iResult;
62bb3cd4 236}
049b43b2 237
13398559 238AliHLTOUT::AliHLTOUTByteOrder AliHLTOUT::CheckByteOrder()
049b43b2 239{
5db0e774 240 // see header file for class documentation
0f1882a7 241 if (fCurrent<fBlockDescList.size()) {
049b43b2 242 SetStatusFlag(kByteOrderChecked);
0f1882a7 243 AliHLTOUT::AliHLTOUTByteOrder order=CheckBlockByteOrder(fBlockDescList[fCurrent].GetIndex());
049b43b2 244 return order;
245 }
246 return kInvalidByteOrder;
247}
248
13398559 249int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType type)
049b43b2 250{
5db0e774 251 // see header file for class documentation
0f1882a7 252 if (fCurrent<fBlockDescList.size()) {
049b43b2 253 SetStatusFlag(kAlignmentChecked);
0f1882a7 254 int alignment=CheckBlockAlignment(fBlockDescList[fCurrent].GetIndex(), type);
049b43b2 255 return alignment;
256 }
257 return -ENOENT;
258}
5db0e774 259
260int AliHLTOUT::InitHandlers()
261{
262 // see header file for class documentation
263 int iResult=0;
264 AliHLTOUTIndexList remnants;
44dc7683 265 int iCount=0;
a3ef3c1d 266 for (int havedata=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); havedata>=0; havedata=SelectNextDataBlock()) {
44dc7683 267 iCount++;
5db0e774 268 remnants.push_back(GetDataBlockIndex());
269 AliHLTComponentDataType dt=kAliHLTVoidDataType;
270 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
e94eb049 271 if (GetDataBlockDescription(dt, spec)<0) break;
f94e8c27 272 bool bHaveHandler=false;
5db0e774 273 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
274 AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
626bfcc1 275 if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) {
5db0e774 276 AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
c5123824 277 InsertHandler(fDataHandlers, entry);
5db0e774 278 remnants.pop_back();
f94e8c27 279 bHaveHandler=true;
5db0e774 280 break;
281 }
282 }
f94e8c27 283 if (!bHaveHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
284 // ESDs are handled by the framework
285 remnants.pop_back();
286 }
5db0e774 287 }
44dc7683 288
289 // warning if some of the data blocks are not selected by the kAliHLTAnyDataType
290 // criterion
291 if (GetNofDataBlocks()>iCount) {
b005ef92 292 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "InitHandlers" , __FILE__ , __LINE__ , "incomplete data type in %d out of %d data block(s)", GetNofDataBlocks()-iCount, GetNofDataBlocks());
44dc7683 293 }
294
295 // warning if handler not found
5db0e774 296 if (remnants.size()>0) {
b005ef92 297 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "InitHandlers" , __FILE__ , __LINE__ , "no handlers found for %d data blocks out of %d", remnants.size(), iCount);
13398559 298 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
5db0e774 299 for (AliHLTOUTIndexList::iterator element=remnants.begin(); element!=remnants.end(); element++) {
300 for (int trials=0; trials<2; trials++) {
301 do {
302 // we start searching the index from the current position in the block list
303 if ((*block).GetIndex()==*element) break;
304 } while ((++block)!=fBlockDescList.end());
305 if (block==fBlockDescList.end()) {
306 // rewind and try again
307 block=fBlockDescList.begin();
308 }
309 }
310 assert(block!=fBlockDescList.end());
311 if (block!=fBlockDescList.end()) {
b005ef92 312 //HLTDebug(" %s", AliHLTComponent::DataType2Text((AliHLTComponentDataType)*block).c_str());
5db0e774 313 }
314 }
315 }
316 return iResult;
317}
318
c5123824 319int AliHLTOUT::InsertHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTOUTHandlerListEntry &entry)
5db0e774 320{
321 // see header file for class documentation
322 int iResult=0;
c5123824 323 AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
b005ef92 324 for (; element!=list.end();
325 element++) {
5db0e774 326 if (entry==(*element)) break;
5db0e774 327 }
c5123824 328 if (element==list.end()) {
329 list.push_back(entry);
5db0e774 330 } else {
a3ef3c1d 331 element->AddIndex(const_cast<AliHLTOUTHandlerListEntry&>(entry));
5db0e774 332 }
333 return iResult;
334}
335
b005ef92 336int AliHLTOUT::FillHandlerList(AliHLTOUTHandlerListEntryVector& list, AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
337{
338 // see header file for class documentation
339 int iResult=0;
340 for (iResult=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec, handlerType);
341 iResult>=0;
342 iResult=SelectNextDataBlock()) {
343 AliHLTComponentDataType dt=kAliHLTVoidDataType;
344 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
345 GetDataBlockDescription(dt, spec);
346 AliHLTOUTHandler* pHandler=GetHandler();
347 if (!pHandler) {
348 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "FillHandlerList" , __FILE__ , __LINE__ ,
349 "missing HLTOUT handler for block of type kChain: agent %s, data type %s, specification %#x, ... skipping data block",
350 GetAgent()?GetAgent()->GetModuleId():"invalid",
351 AliHLTComponent::DataType2Text(dt).c_str(), spec);
352 } else {
353 InsertHandler(list, GetDataBlockHandlerDesc());
354 }
355 }
356 // TODO: the return value of SelectFirst/NextDataBlock must be
357 // changed in order to avoid this check
358 if (iResult==-ENOENT) iResult=0;
359
360 return iResult;
361}
362
363int AliHLTOUT::RemoveEmptyDuplicateHandlers(AliHLTOUTHandlerListEntryVector& list)
364{
365 // see header file for class documentation
366 int iResult=0;
367 AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
368 while (element!=list.end()) {
369 if (element->IsEmpty()) {
370 AliHLTOUTHandler* pHandler=*element;
371 AliHLTModuleAgent* pAgent=*element;
372 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*element;
373 if (FindHandler(list, desc)>=0) {
374 element=list.erase(element);
375 if (pAgent) {
376 pAgent->DeleteOutputHandler(pHandler);
377 }
378 // we are already at the next element
379 continue;
380 }
381 }
382 element++;
383 }
384 return iResult;
385}
386
387int AliHLTOUT::FindHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc)
388{
389 // see header file for class documentation
390 for (int i=0; i<(int)list.size(); i++) {
391 if (list[i]==desc) return i;
392 }
393 return -ENOENT;
394}
395
396int AliHLTOUT::InvalidateBlocks(AliHLTOUTHandlerListEntryVector& list)
397{
398 // see header file for class documentation
399 for (AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
400 element!=list.end();
401 element++) {
402 element->InvalidateBlocks();
403 }
404 return 0;
405}
406
44dc7683 407const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::FindHandlerDesc(AliHLTUInt32_t blockIndex)
626bfcc1 408{
409 // see header file for class documentation
f3c1d403 410 if (blockIndex<fBlockDescList.size()) {
411 return fBlockDescList[blockIndex].GetHandlerDesc();
626bfcc1 412 }
44dc7683 413 return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry);
626bfcc1 414}
415
416AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry()
417 :
418 fpHandler(NULL),
419 fpHandlerDesc(NULL),
420 fpAgent(NULL),
421 fBlocks()
422{
423 // see header file for class documentation
424}
425
5db0e774 426AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
427 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
428 AliHLTModuleAgent* pAgent,
429 AliHLTUInt32_t index)
430 :
431 fpHandler(pHandler),
626bfcc1 432 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
5db0e774 433 fpAgent(pAgent),
434 fBlocks()
435{
436 // see header file for class documentation
626bfcc1 437 *fpHandlerDesc=handlerDesc;
5db0e774 438 fBlocks.push_back(index);
439}
440
441AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
442 :
443 fpHandler(src.fpHandler),
626bfcc1 444 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
5db0e774 445 fpAgent(src.fpAgent),
446 fBlocks()
447{
448 // see header file for class documentation
626bfcc1 449 *fpHandlerDesc=*src.fpHandlerDesc;
5db0e774 450 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
451}
452
fb24bec7 453AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
454{
455 // see header file for class documentation
626bfcc1 456 if (fpHandlerDesc) delete fpHandlerDesc;
457 fpHandlerDesc=NULL;
fb24bec7 458}
459
5db0e774 460AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
461{
462 // see header file for class documentation
463 fpHandler=src.fpHandler;
44dc7683 464 if (src.fpHandlerDesc)
465 *fpHandlerDesc=*src.fpHandlerDesc;
5db0e774 466 fpAgent=src.fpAgent;
467 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
468 return *this;
469}
470
18b56222 471AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const
472{
473 // see header file for class documentation
b0914d2e 474 return (int)fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
5db0e774 475}
476
fb24bec7 477bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
478{
18b56222 479 // see header file for class documentation
a3ef3c1d 480 if (entry.fpHandler!=fpHandler || fpHandler==NULL) return false;
481 assert(entry.fpAgent==fpAgent);
482 if (entry.fpAgent!=fpAgent) return false;
483 return true;
484}
485
44dc7683 486bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const
487{
488 // see header file for class documentation
489 if (!fpHandlerDesc) return false;
490 return *fpHandlerDesc==handlerType;
491}
492
b005ef92 493bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc) const
494{
495 // see header file for class documentation
496 if (!fpHandlerDesc) return false;
497 return *fpHandlerDesc==desc;
498}
499
a3ef3c1d 500void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTOUT::AliHLTOUTHandlerListEntry &desc)
501{
502 // see header file for class documentation
503 AliHLTOUTIndexList::iterator element;
504 for (element=desc.fBlocks.begin(); element!=desc.fBlocks.end(); element++) {
505 AddIndex(*element);
506 }
fb24bec7 507}
508
18b56222 509void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
510{
511 // see header file for class documentation
5db0e774 512 fBlocks.push_back(index);
513}
626bfcc1 514
0f1882a7 515bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index) const
200853e2 516{
517 // see header file for class documentation
a3ef3c1d 518 AliHLTOUTIndexList::iterator element;
0f1882a7 519 for (unsigned int i=0; i<fBlocks.size(); i++) {
520 if (fBlocks[i]==index) return true;
a3ef3c1d 521 }
200853e2 522 return false;
523}
524
626bfcc1 525const AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;
44dc7683 526
ff3b6fed 527AliHLTUInt64_t AliHLTOUT::ByteSwap64(AliHLTUInt64_t src)
44dc7683 528{
529 // see header file for class documentation
530 return ((src & 0xFFULL) << 56) |
531 ((src & 0xFF00ULL) << 40) |
532 ((src & 0xFF0000ULL) << 24) |
533 ((src & 0xFF000000ULL) << 8) |
534 ((src & 0xFF00000000ULL) >> 8) |
535 ((src & 0xFF0000000000ULL) >> 24) |
536 ((src & 0xFF000000000000ULL) >> 40) |
537 ((src & 0xFF00000000000000ULL) >> 56);
538}
539
ff3b6fed 540AliHLTUInt32_t AliHLTOUT::ByteSwap32(AliHLTUInt32_t src)
44dc7683 541{
542 // see header file for class documentation
543 return ((src & 0xFFULL) << 24) |
544 ((src & 0xFF00ULL) << 8) |
545 ((src & 0xFF0000ULL) >> 8) |
546 ((src & 0xFF000000ULL) >> 24);
547}
c1292031 548
549AliHLTOUT* AliHLTOUT::New(AliRawReader* pRawReader)
550{
551 // see header file for class documentation
552 AliHLTOUT* instance=New("AliHLTOUTRawReader");
553 if (instance) {
554 instance->SetParam(pRawReader);
555 }
556 return instance;
557}
558
559AliHLTOUT* AliHLTOUT::New(TTree* pDigitTree, int event)
560{
561 // see header file for class documentation
562 AliHLTOUT* instance=New("AliHLTOUTDigitReader");
563 if (instance) {
564 instance->SetParam(pDigitTree, event);
565 }
566 return instance;
567}
568
569AliHLTOUT* AliHLTOUT::New(const char* classname)
570{
571 // see header file for class documentation
572 int iLibResult=0;
573 AliHLTOUT* instance=NULL;
574 AliHLTLogging log;
575 TClass* pCl=NULL;
576 ROOT::NewFunc_t pNewFunc=NULL;
577 do {
578 pCl=TClass::GetClass(classname);
579 } while (!pCl && (iLibResult=gSystem->Load("libHLTRec.so"))==0);
580 if (iLibResult>=0) {
581 if (pCl && (pNewFunc=pCl->GetNew())!=NULL) {
582 void* p=(*pNewFunc)(NULL);
583 if (p) {
584 instance=reinterpret_cast<AliHLTOUT*>(p);
585 if (!instance) {
586 log.Logging(kHLTLogError, "AliHLTOUT::New", "HLTOUT handling", "type cast to AliHLTOUT instance failed");
587 }
588 } else {
589 log.Logging(kHLTLogError, "AliHLTOUT::New", "HLTOUT handling", "can not create AliHLTOUT instance from class descriptor");
590 }
591 } else {
592 log.Logging(kHLTLogError, "AliHLTOUT::New", "HLTOUT handling", "can not find AliHLTOUT class descriptor");
593 }
594 } else {
595 log.Logging(kHLTLogError, "AliHLTOUT::New", "HLTOUT handling", "can not load libHLTrec library");
596 }
597 return instance;
598}
599
600void AliHLTOUT::Delete(AliHLTOUT* pInstance)
601{
602 // see header file for class documentation
603 if (!pInstance) return;
b005ef92 604 if (pInstance==fgGlobalInstance) return;
c1292031 605
606 // check if the library is still there in order to have the
607 // destructor available
608 TClass* pCl1=TClass::GetClass("AliHLTOUTRawReader");
609 TClass* pCl2=TClass::GetClass("AliHLTOUTDigitReader");
610 if (!pCl1 && !pCl2) {
611 AliHLTLogging log;
612 log.Logging(kHLTLogError, "AliHLTOUT::Delete", "HLTOUT handling", "potential memory leak: libHLTrec library not available, skipping destruction %p", pInstance);
613 return;
614 }
615
616 delete pInstance;
617}
618
619void AliHLTOUT::SetParam(AliRawReader* /*pRawReader*/)
620{
621 // see header file for class documentation
622 // default implementation, we should never get here
623 // this function can only be called from the class itsself and
624 // is intended to be used with the New functions. If we get into
625 // the default implementation there is a class mismatch.
626 assert(0);
b005ef92 627 fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
c1292031 628}
629
630void AliHLTOUT::SetParam(TTree* /*pDigitTree*/, int /*event*/)
631{
632 // see header file for class documentation
633 // default implementation, we should never get here
634 // this function can only be called from the class itsself and
635 // is intended to be used with the New functions. If we get into
636 // the default implementation there is a class mismatch.
637 assert(0);
b005ef92 638 fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
c1292031 639}
0f1882a7 640
641int AliHLTOUT::SelectDataBlock()
642{
643 // see header file for class documentation
644 int iResult=0;
645 if (fCurrent>=fBlockDescList.size()) return 0;
646 fBlockDescList[fCurrent].Select(true);
647 EnableBlockSelection();
648 return iResult;
649}
650
651int AliHLTOUT::SelectDataBlocks(const AliHLTOUTHandlerListEntry* pHandlerDesc)
652{
653 // see header file for class documentation
654 int iResult=0;
655 if (!pHandlerDesc) return 0;
656
657 AliHLTOUTBlockDescriptorVector::iterator element;
658 for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
659 block!=fBlockDescList.end();
660 block++) {
f3c1d403 661 if (block->GetHandlerDesc()==*pHandlerDesc && pHandlerDesc->HasIndex(block->GetIndex()))
0f1882a7 662 block->Select(true);
663 else
664 block->Select(false);
665 }
666 EnableBlockSelection();
667
668 return iResult;
669}
670
671int AliHLTOUT::EnableBlockSelection()
672{
673 // see header file for class documentation
674 SetStatusFlag(kBlockSelection);
675 return 0;
676}
677
678int AliHLTOUT::DisableBlockSelection()
679{
680 // see header file for class documentation
681 ClearStatusFlag(kBlockSelection);
682 return 0;
683}
684
685int AliHLTOUT::ResetBlockSelection()
686{
687 // see header file for class documentation
688 for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
689 block!=fBlockDescList.end();
690 block++) {
691 block->Select(false);
692 }
693 return 0;
694}
695
696int AliHLTOUT::MarkDataBlockProcessed()
697{
698 // see header file for class documentation
699 int iResult=0;
700 if (fCurrent>=fBlockDescList.size()) return 0;
701 fBlockDescList[fCurrent].MarkProcessed();
702 return iResult;
703}
704
705int AliHLTOUT::MarkDataBlocksProcessed(const AliHLTOUTHandlerListEntry* pHandlerDesc)
706{
707 // see header file for class documentation
708 int iResult=0;
709 if (!pHandlerDesc) return 0;
710
711 AliHLTOUTBlockDescriptorVector::iterator element;
712 for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
713 block!=fBlockDescList.end();
714 block++) {
f3c1d403 715 if (block->GetHandlerDesc()==*pHandlerDesc && pHandlerDesc->HasIndex(block->GetIndex()))
0f1882a7 716 block->MarkProcessed();
717 }
718
719 return iResult;
720}
721
722int AliHLTOUT::AddSubCollection(AliHLTOUT* pCollection)
723{
724 // see header file for class documentation
725 int iResult=0;
726 if (!pCollection) return 0;
727
d4a18597 728 SetStatusFlag(kCollecting);
0f1882a7 729 int index=-1;
730 for (index=pCollection->SelectFirstDataBlock();
731 index>=0;
732 index=pCollection->SelectNextDataBlock()) {
733 AliHLTComponentDataType dt=kAliHLTVoidDataType;
734 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
735 pCollection->GetDataBlockDescription(dt, spec);
736 AliHLTOUTBlockDescriptor desc(dt, spec, index, pCollection);
737 AddBlockDescriptor(desc);
738 iResult++;
739 }
740 if (iResult>0) {
4562bf66 741 if (CheckStatusFlag(kIsSubCollection)) {
742 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "AddSubCollection" , __FILE__ , __LINE__ , "HLTOUT object %p has already been added as sub-collection", pCollection);
743 } else {
744 pCollection->SetStatusFlag(kIsSubCollection);
745 }
0f1882a7 746 }
d4a18597 747 ClearStatusFlag(kCollecting);
0f1882a7 748
749 return iResult;
750}
751
752int AliHLTOUT::ReleaseSubCollection(AliHLTOUT* pCollection)
753{
754 // see header file for class documentation
755 int iResult=0;
756 if (!pCollection) return 0;
757
b005ef92 758 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
759 while (block!=fBlockDescList.end()) {
0f1882a7 760 if ((*block)==pCollection) {
b005ef92 761 block=fBlockDescList.erase(block);
762 continue;
0f1882a7 763 }
b005ef92 764 block++;
0f1882a7 765 }
4562bf66 766 pCollection->ClearStatusFlag(kIsSubCollection);
0f1882a7 767
768 return iResult;
769}
b005ef92 770
771int AliHLTOUT::Reset()
772{
773 // see header file for class documentation
774 int iResult=0;
775 AliHLTOUTPVector subCollections;
776 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
777 while (block!=fBlockDescList.end()) {
d4a18597 778 if (!((*block)==this)) {
b005ef92 779 AliHLTOUTPVector::iterator collection=subCollections.begin();
780 for (; collection!=subCollections.end(); collection++)
781 if((*block)==*collection) break;
782 if (collection==subCollections.end())
783 subCollections.push_back(block->GetCollection());
784 }
785 block=fBlockDescList.erase(block);
786 }
787
788 for (AliHLTOUTPVector::iterator collection=subCollections.begin();
4562bf66 789 collection!=subCollections.end(); collection++) {
b005ef92 790 (*collection)->Reset();
4562bf66 791 (*collection)->ClearStatusFlag(kIsSubCollection);
792 }
b005ef92 793
794 ResetInput();
795
796 return iResult;
797}
798
799int AliHLTOUT::ResetInput()
800{
801 // default implementation, nothing to do
802 return 0;
803}
f3c1d403 804
805const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTBlockDescriptor::GetHandlerDesc()
806{
807 // see header file for class documentation
808 if (fpCollection) {
809 AliHLTOUTHandlerListEntryVector::iterator element=fpCollection->fDataHandlers.begin();
810 while (element!=fpCollection->fDataHandlers.end()) {
811 if (element->HasIndex(GetIndex())) {
812 return *element;
813 }
814 element++;
815 }
816 }
817 return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry);
818}