3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /// @file AliHLTOUT.cxx
20 /// @author Matthias Richter
22 /// @brief The control class for HLTOUT data.
27 #include "AliHLTOUT.h"
28 #include "AliHLTMessage.h"
29 #include "AliHLTMisc.h"
37 /** ROOT macro for the implementation of ROOT specific class methods */
40 AliHLTOUT::AliHLTOUT()
42 fSearchDataType(kAliHLTVoidDataType),
43 fSearchSpecification(kAliHLTVoidDataSpec),
44 fSearchHandlerType(AliHLTModuleAgent::kUnknownOutput),
45 fFlags(kSkipProcessed),
53 , fpObjectBuffer(NULL)
54 , fObjectBufferSize(0)
55 , fCurrentEventId(kAliHLTVoidEventID)
57 // see header file for class documentation
59 // refer to README to build package
61 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
64 AliHLTOUT::~AliHLTOUT()
66 // see header file for class documentation
67 if (CheckStatusFlag(kIsSubCollection)) {
68 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "~AliHLTOUT" , __FILE__ , __LINE__ , "severe internal error: collection has not been released, potential crash due to invalid pointer");
72 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "data object has not been released, potential memory leak");
76 AliHLTOUT* AliHLTOUT::fgGlobalInstance=NULL;
80 // see header file for class documentation
83 // ignore if already initialized
84 if (fBlockDescList.size()>0) {
88 SetStatusFlag(kCollecting);
89 if ((iResult=GenerateIndex())>=0) {
90 if ((iResult=InitHandlers())>=0) {
93 ClearStatusFlag(kCollecting);
97 int AliHLTOUT::GetNofDataBlocks()
99 // see header file for class documentation
100 return fBlockDescList.size();
103 int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
104 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType,
107 // see header file for class documentation
110 fSearchSpecification=spec;
111 fSearchHandlerType=handlerType;
112 if (skipProcessed) SetStatusFlag(kSkipProcessed);
113 else ClearStatusFlag(kSkipProcessed);
114 return FindAndSelectDataBlock();
117 int AliHLTOUT::SelectNextDataBlock()
119 // see header file for class documentation
120 if (fCurrent>=fBlockDescList.size()) return -ENOENT;
122 return FindAndSelectDataBlock();
125 int AliHLTOUT::FindAndSelectDataBlock()
127 // see header file for class documentation
128 if (CheckStatusFlag(kLocked)) return -EPERM;
130 while (fCurrent<fBlockDescList.size() && iResult==-ENOENT) {
131 if (fBlockDescList[fCurrent]==fSearchDataType &&
132 (fSearchSpecification==kAliHLTVoidDataSpec || fBlockDescList[fCurrent]==fSearchSpecification) &&
133 (fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput || FindHandlerDesc(fCurrent)==fSearchHandlerType) &&
134 (!CheckStatusFlag(kBlockSelection) || fBlockDescList[fCurrent].IsSelected()) &&
135 (!CheckStatusFlag(kSkipProcessed) || !fBlockDescList[fCurrent].IsProcessed())) {
136 iResult=fBlockDescList[fCurrent].GetIndex();
137 // TODO: check the byte order on the current system and the byte order of the
138 // data block, print warning when mismatch and user did not check
139 //AliHLTOUTByteOrder blockBO=CheckByteOrder();
142 if (blockBO!=fByteOrder) {
143 SetStatusFlag(kByteOrderWarning);
147 ClearStatusFlag(kByteOrderChecked);
149 // TODO: check the alignment on the current system and the alignment of the
150 // data block, print warning when mismatch and user did not check
151 ClearStatusFlag(kAlignmentChecked);
160 int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
162 // see header file for class documentation
164 if (fCurrent<fBlockDescList.size()) {
166 dt=fBlockDescList[fCurrent];
167 spec=fBlockDescList[fCurrent];
172 const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::GetDataBlockHandlerDesc()
174 // see header file for class documentation
175 return FindHandlerDesc(fCurrent);
178 AliHLTModuleAgent::AliHLTOUTHandlerType AliHLTOUT::GetDataBlockHandlerType()
180 // see header file for class documentation
181 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=FindHandlerDesc(fCurrent);
182 AliHLTModuleAgent::AliHLTOUTHandlerType type=desc;
186 AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
188 // see header file for class documentation
189 if (fCurrent>=fBlockDescList.size()) return AliHLTOUTInvalidIndex;
190 return fBlockDescList[fCurrent].GetIndex();
193 int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
195 // see header file for class documentation
199 if (fCurrent<fBlockDescList.size()) {
200 if ((iResult=fBlockDescList[fCurrent].GetDataBuffer(pBuffer, size))>=0) {
207 int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
209 // see header file for class documentation
211 if (pBuffer==fpBuffer) {
214 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "ReleaseDataBuffer" , __FILE__ , __LINE__ , "buffer %p does not match the provided one %p", pBuffer, fpBuffer);
219 AliHLTModuleAgent* AliHLTOUT::GetAgent()
221 // see header file for class documentation
222 AliHLTModuleAgent* pAgent=NULL;
223 pAgent=FindHandlerDesc(fCurrent);
227 AliHLTOUTHandler* AliHLTOUT::GetHandler()
229 // see header file for class documentation
230 AliHLTOUTHandler* pHandler=NULL;
231 pHandler=FindHandlerDesc(fCurrent);
235 int AliHLTOUT::WriteESD(const AliHLTUInt8_t* /*pBuffer*/, AliHLTUInt32_t /*size*/, AliHLTComponentDataType /*dt*/, AliESDEvent* /*tgtesd*/) const
237 // see header file for class documentation
238 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "WriteESD" , __FILE__ , __LINE__ , "method not implemented in base class");
242 int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
244 // see header file for class documentation
245 if (!CheckStatusFlag(kCollecting)) return -EPERM;
247 fBlockDescList.push_back(desc);
251 AliHLTOUT::AliHLTOUTByteOrder AliHLTOUT::CheckByteOrder()
253 // see header file for class documentation
254 if (fCurrent<fBlockDescList.size()) {
255 SetStatusFlag(kByteOrderChecked);
256 AliHLTOUT::AliHLTOUTByteOrder order=CheckBlockByteOrder(fBlockDescList[fCurrent].GetIndex());
259 return kInvalidByteOrder;
262 int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType type)
264 // see header file for class documentation
265 if (fCurrent<fBlockDescList.size()) {
266 SetStatusFlag(kAlignmentChecked);
267 int alignment=CheckBlockAlignment(fBlockDescList[fCurrent].GetIndex(), type);
273 int AliHLTOUT::InitHandlers()
275 // see header file for class documentation
277 AliHLTOUTIndexList remnants;
279 for (int havedata=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); havedata>=0; havedata=SelectNextDataBlock()) {
281 remnants.push_back(GetDataBlockIndex());
282 AliHLTComponentDataType dt=kAliHLTVoidDataType;
283 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
284 if (GetDataBlockDescription(dt, spec)<0) break;
285 bool bHaveHandler=false;
286 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
287 AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
288 if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) {
289 AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
290 InsertHandler(fDataHandlers, entry);
295 sout << "adding handler for block " << AliHLTComponent::DataType2Text(dt).c_str()
296 << " 0x" << setfill('0') << setw(8) << hex << spec;
297 cout << sout.str() << endl;
302 if (!bHaveHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
303 // ESDs are handled by the framework
308 // warning if some of the data blocks are not selected by the kAliHLTAnyDataType
310 if (GetNofDataBlocks()>iCount) {
311 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "InitHandlers" , __FILE__ , __LINE__ , "incomplete data type in %d out of %d data block(s)", GetNofDataBlocks()-iCount, GetNofDataBlocks());
314 // warning if handler not found
315 if (remnants.size()>0) {
316 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "InitHandlers" , __FILE__ , __LINE__ , "no handlers found for %d data blocks out of %d", remnants.size(), iCount);
317 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
318 for (AliHLTOUTIndexList::iterator element=remnants.begin();
319 element!=remnants.end() && block!=fBlockDescList.end();
321 for (int trials=0; trials<2; trials++) {
323 // we start searching the index from the current position in the block list
324 if ((*block).GetIndex()==*element) break;
325 } while ((++block)!=fBlockDescList.end());
326 if (block==fBlockDescList.end()) {
327 // rewind and try again
328 block=fBlockDescList.begin();
331 assert(block!=fBlockDescList.end());
335 if (fbVerbose) Print();
340 int AliHLTOUT::InsertHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTOUTHandlerListEntry &entry)
342 // see header file for class documentation
344 AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
345 for (; element!=list.end();
347 if (entry==(*element)) break;
349 if (element==list.end()) {
350 list.push_back(entry);
352 element->AddIndex(const_cast<AliHLTOUTHandlerListEntry&>(entry));
357 int AliHLTOUT::FillHandlerList(AliHLTOUTHandlerListEntryVector& list, AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
359 // see header file for class documentation
361 for (iResult=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec, handlerType);
363 iResult=SelectNextDataBlock()) {
364 AliHLTComponentDataType dt=kAliHLTVoidDataType;
365 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
366 GetDataBlockDescription(dt, spec);
367 AliHLTOUTHandler* pHandler=GetHandler();
369 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "FillHandlerList" , __FILE__ , __LINE__ ,
370 "missing HLTOUT handler for block of type kChain: agent %s, data type %s, specification %#x, ... skipping data block",
371 GetAgent()?GetAgent()->GetModuleId():"invalid",
372 AliHLTComponent::DataType2Text(dt).c_str(), spec);
374 InsertHandler(list, GetDataBlockHandlerDesc());
377 // TODO: the return value of SelectFirst/NextDataBlock must be
378 // changed in order to avoid this check
379 if (iResult==-ENOENT) iResult=0;
384 int AliHLTOUT::RemoveEmptyDuplicateHandlers(AliHLTOUTHandlerListEntryVector& list)
386 // see header file for class documentation
388 AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
389 while (element!=list.end()) {
390 if (element->IsEmpty()) {
391 AliHLTOUTHandler* pHandler=*element;
392 AliHLTModuleAgent* pAgent=*element;
393 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*element;
394 if (FindHandler(list, desc)>=0) {
395 element=list.erase(element);
397 pAgent->DeleteOutputHandler(pHandler);
399 // we are already at the next element
408 int AliHLTOUT::FindHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc)
410 // see header file for class documentation
411 for (int i=0; i<(int)list.size(); i++) {
412 if (list[i]==desc) return i;
417 int AliHLTOUT::InvalidateBlocks(AliHLTOUTHandlerListEntryVector& list)
419 // see header file for class documentation
420 for (AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
423 element->InvalidateBlocks();
428 const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::FindHandlerDesc(AliHLTUInt32_t blockIndex)
430 // see header file for class documentation
431 if (blockIndex<fBlockDescList.size()) {
432 return fBlockDescList[blockIndex].GetHandlerDesc();
434 return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry);
437 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry()
444 // see header file for class documentation
447 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
448 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
449 AliHLTModuleAgent* pAgent,
450 AliHLTUInt32_t index)
453 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
457 // see header file for class documentation
458 *fpHandlerDesc=handlerDesc;
459 fBlocks.push_back(index);
462 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
464 fpHandler(src.fpHandler),
465 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
466 fpAgent(src.fpAgent),
469 // see header file for class documentation
470 *fpHandlerDesc=*src.fpHandlerDesc;
471 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
474 AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
476 // see header file for class documentation
477 if (fpHandlerDesc) delete fpHandlerDesc;
481 AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
483 // see header file for class documentation
484 fpHandler=src.fpHandler;
485 if (src.fpHandlerDesc)
486 *fpHandlerDesc=*src.fpHandlerDesc;
488 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
492 AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const
494 // see header file for class documentation
495 return (int)fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
498 bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
500 // see header file for class documentation
501 if (entry.fpHandler!=fpHandler || fpHandler==NULL) return false;
502 assert(entry.fpAgent==fpAgent);
503 if (entry.fpAgent!=fpAgent) return false;
507 bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const
509 // see header file for class documentation
510 if (!fpHandlerDesc) return false;
511 return *fpHandlerDesc==handlerType;
514 bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc) const
516 // see header file for class documentation
517 if (!fpHandlerDesc) return false;
518 return *fpHandlerDesc==desc;
521 void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTOUT::AliHLTOUTHandlerListEntry &desc)
523 // see header file for class documentation
524 AliHLTOUTIndexList::iterator element;
525 for (element=desc.fBlocks.begin(); element!=desc.fBlocks.end(); element++) {
530 void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
532 // see header file for class documentation
533 fBlocks.push_back(index);
536 bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index) const
538 // see header file for class documentation
539 AliHLTOUTIndexList::iterator element;
540 for (unsigned int i=0; i<fBlocks.size(); i++) {
541 if (fBlocks[i]==index) return true;
546 const AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;
548 AliHLTUInt64_t AliHLTOUT::ByteSwap64(AliHLTUInt64_t src)
550 // see header file for class documentation
551 return ((src & 0xFFULL) << 56) |
552 ((src & 0xFF00ULL) << 40) |
553 ((src & 0xFF0000ULL) << 24) |
554 ((src & 0xFF000000ULL) << 8) |
555 ((src & 0xFF00000000ULL) >> 8) |
556 ((src & 0xFF0000000000ULL) >> 24) |
557 ((src & 0xFF000000000000ULL) >> 40) |
558 ((src & 0xFF00000000000000ULL) >> 56);
561 AliHLTUInt32_t AliHLTOUT::ByteSwap32(AliHLTUInt32_t src)
563 // see header file for class documentation
564 return ((src & 0xFFULL) << 24) |
565 ((src & 0xFF00ULL) << 8) |
566 ((src & 0xFF0000ULL) >> 8) |
567 ((src & 0xFF000000ULL) >> 24);
570 AliHLTOUT* AliHLTOUT::New(AliRawReader* pRawReader)
572 // see header file for class documentation
573 AliHLTOUT* instance=AliHLTMisc::LoadInstance((AliHLTOUT*)0, "AliHLTOUTRawReader", "libHLTrec.so");
575 instance->SetParam(pRawReader);
580 AliHLTOUT* AliHLTOUT::New(TTree* pDigitTree, int event)
582 // see header file for class documentation
583 AliHLTOUT* instance=AliHLTMisc::LoadInstance((AliHLTOUT*)0, "AliHLTOUTDigitReader", "libHLTrec.so");
585 instance->SetParam(pDigitTree, event);
590 AliHLTOUT* AliHLTOUT::New(const char* filename, int event)
592 // see header file for class documentation
593 AliHLTOUT* instance=AliHLTMisc::LoadInstance((AliHLTOUT*)0, "AliHLTOUTDigitReader", "libHLTrec.so");
595 instance->SetParam(filename, event);
600 void AliHLTOUT::Delete(AliHLTOUT* pInstance)
602 // see header file for class documentation
603 if (!pInstance) return;
604 if (pInstance==fgGlobalInstance) return;
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) {
612 log.Logging(kHLTLogError, "AliHLTOUT::Delete", "HLTOUT handling", "potential memory leak: libHLTrec library not available, skipping destruction %p", pInstance);
619 void AliHLTOUT::SetParam(AliRawReader* /*pRawReader*/)
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.
627 fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
630 void AliHLTOUT::SetParam(TTree* /*pDigitTree*/, int /*event*/)
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.
638 fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
641 void AliHLTOUT::SetParam(const char* /*filename*/, int /*event*/)
643 // see header file for class documentation
644 // default implementation, we should never get here
645 // this function can only be called from the class itsself and
646 // is intended to be used with the New functions. If we get into
647 // the default implementation there is a class mismatch.
649 fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
652 int AliHLTOUT::SelectDataBlock()
654 // see header file for class documentation
656 if (fCurrent>=fBlockDescList.size()) return 0;
657 fBlockDescList[fCurrent].Select(true);
658 EnableBlockSelection();
662 int AliHLTOUT::SelectDataBlocks(const AliHLTOUTHandlerListEntry* pHandlerEntry)
664 // see header file for class documentation
666 if (!pHandlerEntry) return 0;
668 AliHLTModuleAgent* pAgent=*pHandlerEntry;
670 log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", "selecting blocks for handler %s", pAgent->GetModuleId());
671 AliHLTOUTBlockDescriptorVector::iterator element;
672 for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
673 block!=fBlockDescList.end();
675 if (block->GetHandlerDesc()==*pHandlerEntry && pHandlerEntry->HasIndex(block->GetIndex())) {
677 log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", " select block %s", AliHLTComponent::DataType2Text(*block).c_str());
679 log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", " skip block %s", AliHLTComponent::DataType2Text(*block).c_str());
680 block->Select(false);
683 EnableBlockSelection();
685 // Matthias 2009-07-03 bugfix: the fCurrent position was not reset at that
686 // place. Also I think the data type and specification must be set in order
687 // to make SelectFirst/NextDataBlock working on the selected collection
689 AliHLTModuleAgent::AliHLTOUTHandlerDesc pHandlerDesc=*pHandlerEntry;
690 fSearchDataType=pHandlerDesc;
691 fSearchSpecification=kAliHLTVoidDataSpec;
692 fSearchHandlerType=pHandlerDesc;
698 int AliHLTOUT::EnableBlockSelection()
700 // see header file for class documentation
701 SetStatusFlag(kBlockSelection);
705 int AliHLTOUT::DisableBlockSelection()
707 // see header file for class documentation
708 ClearStatusFlag(kBlockSelection);
712 int AliHLTOUT::ResetBlockSelection()
714 // see header file for class documentation
715 for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
716 block!=fBlockDescList.end();
718 block->Select(false);
723 int AliHLTOUT::MarkDataBlockProcessed()
725 // see header file for class documentation
727 if (fCurrent>=fBlockDescList.size()) return 0;
728 fBlockDescList[fCurrent].MarkProcessed();
732 int AliHLTOUT::MarkDataBlocksProcessed(const AliHLTOUTHandlerListEntry* pHandlerDesc)
734 // see header file for class documentation
736 if (!pHandlerDesc) return 0;
738 AliHLTOUTBlockDescriptorVector::iterator element;
739 for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
740 block!=fBlockDescList.end();
742 if (block->GetHandlerDesc()==*pHandlerDesc && pHandlerDesc->HasIndex(block->GetIndex()))
743 block->MarkProcessed();
749 int AliHLTOUT::AddSubCollection(AliHLTOUT* pCollection)
751 // see header file for class documentation
753 if (!pCollection) return 0;
755 SetStatusFlag(kCollecting);
757 for (index=pCollection->SelectFirstDataBlock();
759 index=pCollection->SelectNextDataBlock()) {
760 AliHLTComponentDataType dt=kAliHLTVoidDataType;
761 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
762 pCollection->GetDataBlockDescription(dt, spec);
763 AliHLTOUTBlockDescriptor desc(dt, spec, index, pCollection);
764 AddBlockDescriptor(desc);
768 if (CheckStatusFlag(kIsSubCollection)) {
769 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "AddSubCollection" , __FILE__ , __LINE__ , "HLTOUT object %p has already been added as sub-collection", pCollection);
771 pCollection->SetStatusFlag(kIsSubCollection);
774 ClearStatusFlag(kCollecting);
779 int AliHLTOUT::ReleaseSubCollection(AliHLTOUT* pCollection)
781 // see header file for class documentation
783 if (!pCollection) return 0;
785 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
786 while (block!=fBlockDescList.end()) {
787 if ((*block)==pCollection) {
788 block=fBlockDescList.erase(block);
793 pCollection->ClearStatusFlag(kIsSubCollection);
798 int AliHLTOUT::Reset()
800 // see header file for class documentation
802 AliHLTOUTPVector subCollections;
803 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
804 while (block!=fBlockDescList.end()) {
805 if (!((*block)==this)) {
806 AliHLTOUTPVector::iterator collection=subCollections.begin();
807 for (; collection!=subCollections.end(); collection++)
808 if((*block)==*collection) break;
809 if (collection==subCollections.end())
810 subCollections.push_back(block->GetCollection());
812 block=fBlockDescList.erase(block);
815 for (AliHLTOUTPVector::iterator collection=subCollections.begin();
816 collection!=subCollections.end(); collection++) {
817 (*collection)->Reset();
818 (*collection)->ClearStatusFlag(kIsSubCollection);
822 fCurrentEventId=kAliHLTVoidEventID;
827 int AliHLTOUT::ResetInput()
829 // default implementation, nothing to do
833 const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTBlockDescriptor::GetHandlerDesc()
835 // see header file for class documentation
837 AliHLTOUTHandlerListEntryVector::iterator element=fpCollection->fDataHandlers.begin();
838 while (element!=fpCollection->fDataHandlers.end()) {
839 if (element->HasIndex(GetIndex())) {
845 return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry);
848 TObject* AliHLTOUT::GetDataObject()
850 // see header file for class documentation
852 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "data object has not been released, potential memory leak");
853 ReleaseDataBuffer(fpObjectBuffer);
859 if (GetDataBuffer(fpObjectBuffer, fObjectBufferSize)>=0) {
860 fpDataObject=AliHLTMessage::Extract(fpObjectBuffer, fObjectBufferSize);
862 fLog.LoggingVarargs(kHLTLogError, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "can not fetch data buffer");
868 int AliHLTOUT::ReleaseDataObject(TObject* pObject)
870 // see header file for class documentation
871 if (!pObject) return -EINVAL;
872 if (pObject!=fpDataObject) {
873 fLog.LoggingVarargs(kHLTLogError, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "attempt to release wrong data object %p, expected %p", pObject, fpDataObject);
879 ReleaseDataBuffer(fpObjectBuffer);
886 void AliHLTOUT::SetEventId(AliHLTUInt64_t id)
888 // see header file for class documentation
889 if (fCurrentEventId!=kAliHLTVoidEventID && fCurrentEventId!=id) {
890 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "SetEventId" , __FILE__ , __LINE__ , "event id was already set to 0x%llx, setting now to 0x%llx", fCurrentEventId, id);
895 void AliHLTOUT::Print(const char* option) const
899 for (AliHLTOUTBlockDescriptorVector::const_iterator i=fBlockDescList.begin();
900 i!=fBlockDescList.end(); i++)
904 for (AliHLTOUTHandlerListEntryVector::const_iterator i=fDataHandlers.begin();
905 i!=fDataHandlers.end(); i++)
910 void AliHLTOUT::AliHLTOUTBlockDescriptor::Print(const char* /*option*/) const
914 sout << "AliHLTOUTBlockDescriptor index 0x" << setfill('0') << setw(8) << hex << right << fIndex
915 << ": " << AliHLTComponent::DataType2Text(fDataType).c_str()
916 << " 0x" << setfill('0') << setw(8) << hex << fSpecification
917 << " processed " << dec << fProcessed;
918 cout << sout.str() << endl;
921 void AliHLTOUT::AliHLTOUTHandlerListEntry::Print(const char* /*option*/) const
925 AliHLTModuleAgent::AliHLTOUTHandlerType type=AliHLTModuleAgent::kUnknownOutput;
926 AliHLTComponentDataType dt=kAliHLTVoidDataType;
927 if (this->fpHandlerDesc) {
928 type=*(this->fpHandlerDesc);
929 dt=*(this->fpHandlerDesc);
931 const char* stype="";
933 case AliHLTModuleAgent::kEsd: stype="ESD"; break;
934 case AliHLTModuleAgent::kRawReader: stype="RawReader"; break;
935 case AliHLTModuleAgent::kRawStream: stype="RawStream"; break;
936 case AliHLTModuleAgent::kChain: stype="Chain"; break;
937 case AliHLTModuleAgent::kProprietary: stype="Proprietary"; break;
938 default: stype="unknown";
940 sout << "HLTOUT handler: "
941 << " " << type << " (" << stype << ")"
942 << " " << AliHLTComponent::DataType2Text(dt).c_str();
943 cout << sout.str() << endl;