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)
59 // The control class for HLTOUT data
60 // see header file for class documentation
61 // author Matthias Richter
64 AliHLTOUT::~AliHLTOUT()
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 // get number of data blocks
100 return fBlockDescList.size();
103 int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
104 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType,
107 // select the first data block according to data type, specification and
111 fSearchSpecification=spec;
112 fSearchHandlerType=handlerType;
113 if (skipProcessed) SetStatusFlag(kSkipProcessed);
114 else ClearStatusFlag(kSkipProcessed);
115 return FindAndSelectDataBlock();
118 int AliHLTOUT::SelectNextDataBlock()
120 // select next data block according to selection criteria specified
121 // for SelectFirstDataBlock
122 if (fCurrent>=fBlockDescList.size()) return -ENOENT;
124 return FindAndSelectDataBlock();
127 int AliHLTOUT::FindAndSelectDataBlock()
129 // Select data block according to data type and specification, internal function
130 // invoked by SelectFirstDataBlock/SelectNextDataBlock
131 if (CheckStatusFlag(kLocked)) return -EPERM;
133 while (fCurrent<fBlockDescList.size() && iResult==-ENOENT) {
134 if (fBlockDescList[fCurrent]==fSearchDataType &&
135 (fSearchSpecification==kAliHLTVoidDataSpec || fBlockDescList[fCurrent]==fSearchSpecification) &&
136 (fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput || FindHandlerDesc(fCurrent)==fSearchHandlerType) &&
137 (!CheckStatusFlag(kBlockSelection) || fBlockDescList[fCurrent].IsSelected()) &&
138 (!CheckStatusFlag(kSkipProcessed) || !fBlockDescList[fCurrent].IsProcessed())) {
139 iResult=fBlockDescList[fCurrent].GetIndex();
140 // TODO: check the byte order on the current system and the byte order of the
141 // data block, print warning when mismatch and user did not check
142 //AliHLTOUTByteOrder blockBO=CheckByteOrder();
145 if (blockBO!=fByteOrder) {
146 SetStatusFlag(kByteOrderWarning);
150 ClearStatusFlag(kByteOrderChecked);
152 // TODO: check the alignment on the current system and the alignment of the
153 // data block, print warning when mismatch and user did not check
154 ClearStatusFlag(kAlignmentChecked);
163 int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
165 // fill data type and specification
167 if (fCurrent<fBlockDescList.size()) {
169 dt=fBlockDescList[fCurrent];
170 spec=fBlockDescList[fCurrent];
175 const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::GetDataBlockHandlerDesc()
177 // Get handler descriptor of the selected data block.
178 return FindHandlerDesc(fCurrent);
181 AliHLTModuleAgent::AliHLTOUTHandlerType AliHLTOUT::GetDataBlockHandlerType()
183 // Get handler type of the selected data block.
184 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=FindHandlerDesc(fCurrent);
185 AliHLTModuleAgent::AliHLTOUTHandlerType type=desc;
189 AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
191 // Get the index of the current data block.
192 if (fCurrent>=fBlockDescList.size()) return AliHLTOUTInvalidIndex;
193 return fBlockDescList[fCurrent].GetIndex();
196 int AliHLTOUT::GetDataBuffer(AliHLTComponentBlockData& desc)
198 // fill block data descriptor and select the current data buffer
199 // buffer has to be released using ReleaseDataBuffer
201 if (fCurrent<fBlockDescList.size()) {
202 AliHLTComponent::FillBlockData(desc);
203 if ((iResult=fBlockDescList[fCurrent].GetDataBuffer(fpBuffer, desc.fSize))>=0) {
204 desc.fPtr=const_cast<void*>(reinterpret_cast<const void*>(fpBuffer));
205 desc.fDataType=fBlockDescList[fCurrent];
206 desc.fSpecification=fBlockDescList[fCurrent];
212 int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
214 // select and return the current data buffer
215 // buffer has to be released using ReleaseDataBuffer
219 if (fCurrent<fBlockDescList.size()) {
220 if ((iResult=fBlockDescList[fCurrent].GetDataBuffer(fpBuffer, size))>=0) {
227 int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
229 // release data buffer, previously returned by GetDataBuffer
231 if (pBuffer==fpBuffer) {
234 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "ReleaseDataBuffer" , __FILE__ , __LINE__ , "buffer %p does not match the provided one %p", pBuffer, fpBuffer);
239 AliHLTModuleAgent* AliHLTOUT::GetAgent()
241 // get module agent of the selected data block
242 AliHLTModuleAgent* pAgent=NULL;
243 pAgent=FindHandlerDesc(fCurrent);
247 AliHLTOUTHandler* AliHLTOUT::GetHandler()
249 // get HLTOUT handler of the selected data block
250 AliHLTOUTHandler* pHandler=NULL;
251 pHandler=FindHandlerDesc(fCurrent);
255 int AliHLTOUT::WriteESD(const AliHLTUInt8_t* /*pBuffer*/, AliHLTUInt32_t /*size*/, AliHLTComponentDataType /*dt*/, AliESDEvent* /*tgtesd*/) const
257 // default function, child must overload
258 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "WriteESD" , __FILE__ , __LINE__ , "method not implemented in base class");
262 int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
264 // add new block descriptor
265 if (!CheckStatusFlag(kCollecting)) return -EPERM;
267 fBlockDescList.push_back(desc);
271 AliHLTOUT::AliHLTOUTByteOrder AliHLTOUT::CheckByteOrder()
273 // check the byte order of the current data block
274 // NOTE: this functionality has not been tested and development was hardly finished
275 if (fCurrent<fBlockDescList.size()) {
276 SetStatusFlag(kByteOrderChecked);
277 AliHLTOUT::AliHLTOUTByteOrder order=CheckBlockByteOrder(fBlockDescList[fCurrent].GetIndex());
280 return kInvalidByteOrder;
283 int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType type)
285 // check alignment of the current data block
286 // NOTE: this functionality has not been tested and development was hardly finished
287 if (fCurrent<fBlockDescList.size()) {
288 SetStatusFlag(kAlignmentChecked);
289 int alignment=CheckBlockAlignment(fBlockDescList[fCurrent].GetIndex(), type);
295 int AliHLTOUT::InitHandlers()
297 // init handlers for all registered blocks
299 AliHLTOUTIndexList remnants;
301 for (int havedata=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); havedata>=0; havedata=SelectNextDataBlock()) {
303 remnants.push_back(GetDataBlockIndex());
304 AliHLTComponentDataType dt=kAliHLTVoidDataType;
305 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
306 if (GetDataBlockDescription(dt, spec)<0) break;
307 bool bHaveHandler=false;
308 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
309 AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
310 if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) {
311 AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
312 InsertHandler(fDataHandlers, entry);
317 sout << "adding handler for block " << AliHLTComponent::DataType2Text(dt).c_str()
318 << " 0x" << setfill('0') << setw(8) << hex << spec;
319 cout << sout.str() << endl;
324 if (!bHaveHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
325 // ESDs are handled by the framework
330 // warning if some of the data blocks are not selected by the kAliHLTAnyDataType
332 if (GetNofDataBlocks()>iCount) {
333 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "InitHandlers" , __FILE__ , __LINE__ , "incomplete data type in %d out of %d data block(s)", GetNofDataBlocks()-iCount, GetNofDataBlocks());
336 // warning if handler not found
337 if (remnants.size()>0) {
338 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "InitHandlers" , __FILE__ , __LINE__ , "no handlers found for %d data blocks out of %d", remnants.size(), iCount);
339 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
340 for (AliHLTOUTIndexList::iterator element=remnants.begin();
341 element!=remnants.end() && block!=fBlockDescList.end();
343 for (int trials=0; trials<2; trials++) {
345 // we start searching the index from the current position in the block list
346 if ((*block).GetIndex()==*element) break;
347 } while ((++block)!=fBlockDescList.end());
348 if (block==fBlockDescList.end()) {
349 // rewind and try again
350 block=fBlockDescList.begin();
353 assert(block!=fBlockDescList.end());
357 if (fbVerbose) Print();
362 int AliHLTOUT::InsertHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTOUTHandlerListEntry &entry)
364 // insert handler into list, called from child implementations
366 AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
367 for (; element!=list.end();
369 if (entry==(*element)) break;
371 if (element==list.end()) {
372 list.push_back(entry);
374 element->AddIndex(const_cast<AliHLTOUTHandlerListEntry&>(entry));
379 int AliHLTOUT::FillHandlerList(AliHLTOUTHandlerListEntryVector& list, AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
381 // fill a list according to specified handler type
383 for (iResult=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec, handlerType);
385 iResult=SelectNextDataBlock()) {
386 AliHLTComponentDataType dt=kAliHLTVoidDataType;
387 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
388 GetDataBlockDescription(dt, spec);
389 AliHLTOUTHandler* pHandler=GetHandler();
391 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "FillHandlerList" , __FILE__ , __LINE__ ,
392 "missing HLTOUT handler for block of type kChain: agent %s, data type %s, specification %#x, ... skipping data block",
393 GetAgent()?GetAgent()->GetModuleId():"invalid",
394 AliHLTComponent::DataType2Text(dt).c_str(), spec);
396 InsertHandler(list, GetDataBlockHandlerDesc());
399 // TODO: the return value of SelectFirst/NextDataBlock must be
400 // changed in order to avoid this check
401 if (iResult==-ENOENT) iResult=0;
406 int AliHLTOUT::RemoveEmptyDuplicateHandlers(AliHLTOUTHandlerListEntryVector& list)
408 // remove empty handlers from list
410 AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
411 while (element!=list.end()) {
412 if (element->IsEmpty()) {
413 AliHLTOUTHandler* pHandler=*element;
414 AliHLTModuleAgent* pAgent=*element;
415 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*element;
416 if (FindHandler(list, desc)>=0) {
417 element=list.erase(element);
419 pAgent->DeleteOutputHandler(pHandler);
421 // we are already at the next element
430 int AliHLTOUT::FindHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc)
432 // find handler according to descriptor
433 for (int i=0; i<(int)list.size(); i++) {
434 if (list[i]==desc) return i;
439 int AliHLTOUT::InvalidateBlocks(AliHLTOUTHandlerListEntryVector& list)
441 // invalidate all handlers in a list
442 for (AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
445 element->InvalidateBlocks();
450 const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::FindHandlerDesc(AliHLTUInt32_t blockIndex)
452 // get handler description
453 if (blockIndex<fBlockDescList.size()) {
454 return fBlockDescList[blockIndex].GetHandlerDesc();
456 return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry);
459 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry()
466 // default constructor
469 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
470 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
471 AliHLTModuleAgent* pAgent,
472 AliHLTUInt32_t index)
475 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
480 *fpHandlerDesc=handlerDesc;
481 fBlocks.push_back(index);
484 AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
486 fpHandler(src.fpHandler),
487 fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
488 fpAgent(src.fpAgent),
492 *fpHandlerDesc=*src.fpHandlerDesc;
493 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
496 AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
499 if (fpHandlerDesc) delete fpHandlerDesc;
503 AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
505 // assignment operator
506 if (this==&src) return *this;
507 fpHandler=src.fpHandler;
508 if (src.fpHandlerDesc)
509 *fpHandlerDesc=*src.fpHandlerDesc;
511 fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
515 AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const
518 return (int)fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
521 bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
523 // comparison operator
524 if (entry.fpHandler!=fpHandler || fpHandler==NULL) return false;
525 assert(entry.fpAgent==fpAgent);
526 if (entry.fpAgent!=fpAgent) return false;
530 bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const
532 // comparison operator
533 if (!fpHandlerDesc) return false;
534 return *fpHandlerDesc==handlerType;
537 bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc) const
539 // comparison operator
540 if (!fpHandlerDesc) return false;
541 return *fpHandlerDesc==desc;
544 void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTOUT::AliHLTOUTHandlerListEntry &desc)
546 // add block index, a handler can serve multiple blocks
547 AliHLTOUTIndexList::iterator element;
548 for (element=desc.fBlocks.begin(); element!=desc.fBlocks.end(); element++) {
553 void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
555 // add block index, a handler can serve multiple blocks
556 fBlocks.push_back(index);
559 bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index) const
561 // check if handler serves the specified block
562 AliHLTOUTIndexList::iterator element;
563 for (unsigned int i=0; i<fBlocks.size(); i++) {
564 if (fBlocks[i]==index) return true;
569 const AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;
571 AliHLTUInt64_t AliHLTOUT::ByteSwap64(AliHLTUInt64_t src)
573 // swap a 64 bit number
574 return ((src & 0xFFULL) << 56) |
575 ((src & 0xFF00ULL) << 40) |
576 ((src & 0xFF0000ULL) << 24) |
577 ((src & 0xFF000000ULL) << 8) |
578 ((src & 0xFF00000000ULL) >> 8) |
579 ((src & 0xFF0000000000ULL) >> 24) |
580 ((src & 0xFF000000000000ULL) >> 40) |
581 ((src & 0xFF00000000000000ULL) >> 56);
584 AliHLTUInt32_t AliHLTOUT::ByteSwap32(AliHLTUInt32_t src)
586 // swap a 32 bit number
587 return ((src & 0xFFULL) << 24) |
588 ((src & 0xFF00ULL) << 8) |
589 ((src & 0xFF0000ULL) >> 8) |
590 ((src & 0xFF000000ULL) >> 24);
593 AliHLTOUT* AliHLTOUT::New(AliRawReader* pRawReader)
595 // transparently create HLTOUT implementation for AliRawReader
596 AliHLTOUT* instance=AliHLTMisc::LoadInstance((AliHLTOUT*)0, "AliHLTOUTRawReader", "libHLTrec.so");
598 instance->SetParam(pRawReader);
603 AliHLTOUT* AliHLTOUT::New(TTree* pDigitTree, int event)
605 // transparently create HLTOUT implementation for digit tree
606 AliHLTOUT* instance=AliHLTMisc::LoadInstance((AliHLTOUT*)0, "AliHLTOUTDigitReader", "libHLTrec.so");
608 instance->SetParam(pDigitTree, event);
613 AliHLTOUT* AliHLTOUT::New(const char* filename, int event)
615 // transparently create HLTOUT implementation for raw file
616 AliHLTOUT* instance=AliHLTMisc::LoadInstance((AliHLTOUT*)0, "AliHLTOUTDigitReader", "libHLTrec.so");
618 instance->SetParam(filename, event);
623 void AliHLTOUT::Delete(AliHLTOUT* pInstance)
625 // delete the HLTOUT instance
626 // check if the library is still there in order to have the
627 // destructor available
629 if (!pInstance) return;
630 if (pInstance==fgGlobalInstance) return;
632 TClass* pCl1=TClass::GetClass("AliHLTOUTRawReader");
633 TClass* pCl2=TClass::GetClass("AliHLTOUTDigitReader");
634 if (!pCl1 && !pCl2) {
636 log.Logging(kHLTLogError, "AliHLTOUT::Delete", "HLTOUT handling", "potential memory leak: libHLTrec library not available, skipping destruction %p", pInstance);
643 void AliHLTOUT::SetParam(AliRawReader* /*pRawReader*/)
645 // see header file for class documentation
646 // default implementation, we should never get here
647 // this function can only be called from the class itsself and
648 // is intended to be used with the New functions. If we get into
649 // the default implementation there is a class mismatch.
651 fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
654 void AliHLTOUT::SetParam(TTree* /*pDigitTree*/, int /*event*/)
656 // see header file for class documentation
657 // default implementation, we should never get here
658 // this function can only be called from the class itsself and
659 // is intended to be used with the New functions. If we get into
660 // the default implementation there is a class mismatch.
662 fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
665 void AliHLTOUT::SetParam(const char* /*filename*/, int /*event*/)
667 // see header file for class documentation
668 // default implementation, we should never get here
669 // this function can only be called from the class itsself and
670 // is intended to be used with the New functions. If we get into
671 // the default implementation there is a class mismatch.
673 fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
676 int AliHLTOUT::SelectDataBlock()
678 // mark the current data block for processing
680 if (fCurrent>=fBlockDescList.size()) return 0;
681 fBlockDescList[fCurrent].Select(true);
682 EnableBlockSelection();
686 int AliHLTOUT::SelectDataBlocks(const AliHLTOUTHandlerListEntry* pHandlerEntry)
688 // mark all data blocks served by specified handler for processing
690 if (!pHandlerEntry) return 0;
692 AliHLTModuleAgent* pAgent=*pHandlerEntry;
694 log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", "selecting blocks for handler %s", pAgent->GetModuleId());
695 AliHLTOUTBlockDescriptorVector::iterator element;
696 for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
697 block!=fBlockDescList.end();
699 if (block->GetHandlerDesc()==*pHandlerEntry && pHandlerEntry->HasIndex(block->GetIndex())) {
701 log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", " select block %s", AliHLTComponent::DataType2Text(*block).c_str());
703 log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", " skip block %s", AliHLTComponent::DataType2Text(*block).c_str());
704 block->Select(false);
707 EnableBlockSelection();
709 // Matthias 2009-07-03 bugfix: the fCurrent position was not reset at that
710 // place. Also I think the data type and specification must be set in order
711 // to make SelectFirst/NextDataBlock working on the selected collection
713 AliHLTModuleAgent::AliHLTOUTHandlerDesc pHandlerDesc=*pHandlerEntry;
714 fSearchDataType=pHandlerDesc;
715 fSearchSpecification=kAliHLTVoidDataSpec;
716 fSearchHandlerType=pHandlerDesc;
722 int AliHLTOUT::EnableBlockSelection()
724 // enable block selection, in this mode only the blocks marked for
725 // processing can be accessed
726 SetStatusFlag(kBlockSelection);
730 int AliHLTOUT::DisableBlockSelection()
732 // disable block selection
733 ClearStatusFlag(kBlockSelection);
737 int AliHLTOUT::ResetBlockSelection()
739 // reset the 'selected' flag for all blocks
740 for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
741 block!=fBlockDescList.end();
743 block->Select(false);
748 int AliHLTOUT::MarkDataBlockProcessed()
750 // mark the current data block as 'processed'
752 if (fCurrent>=fBlockDescList.size()) return 0;
753 fBlockDescList[fCurrent].MarkProcessed();
757 int AliHLTOUT::MarkDataBlocksProcessed(const AliHLTOUTHandlerListEntry* pHandlerDesc)
759 // mark all data blocks served by handler as processed
761 if (!pHandlerDesc) return 0;
763 AliHLTOUTBlockDescriptorVector::iterator element;
764 for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
765 block!=fBlockDescList.end();
767 if (block->GetHandlerDesc()==*pHandlerDesc && pHandlerDesc->HasIndex(block->GetIndex()))
768 block->MarkProcessed();
774 int AliHLTOUT::AddSubCollection(AliHLTOUT* pCollection)
776 // add a sub-collection to the HLTOUT instance
777 // all blocks of the sub-collection are accessed transparently through the master instance
779 if (!pCollection) return 0;
781 SetStatusFlag(kCollecting);
783 for (index=pCollection->SelectFirstDataBlock();
785 index=pCollection->SelectNextDataBlock()) {
786 AliHLTComponentDataType dt=kAliHLTVoidDataType;
787 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
788 pCollection->GetDataBlockDescription(dt, spec);
789 AliHLTOUTBlockDescriptor desc(dt, spec, index, pCollection);
790 AddBlockDescriptor(desc);
794 if (CheckStatusFlag(kIsSubCollection)) {
795 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "AddSubCollection" , __FILE__ , __LINE__ , "HLTOUT object %p has already been added as sub-collection", pCollection);
797 pCollection->SetStatusFlag(kIsSubCollection);
800 ClearStatusFlag(kCollecting);
805 int AliHLTOUT::ReleaseSubCollection(AliHLTOUT* pCollection)
807 // release a sub-collection
809 if (!pCollection) return 0;
811 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
812 while (block!=fBlockDescList.end()) {
813 if ((*block)==pCollection) {
814 block=fBlockDescList.erase(block);
819 pCollection->ClearStatusFlag(kIsSubCollection);
824 int AliHLTOUT::Reset()
826 // reset HLTOUT instance
827 // clears all blocks and handler descriptions
829 AliHLTOUTPVector subCollections;
830 AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
831 while (block!=fBlockDescList.end()) {
832 if (!((*block)==this)) {
833 AliHLTOUTPVector::iterator collection=subCollections.begin();
834 for (; collection!=subCollections.end(); collection++)
835 if((*block)==*collection) break;
836 if (collection==subCollections.end())
837 subCollections.push_back(block->GetCollection());
839 block=fBlockDescList.erase(block);
842 for (AliHLTOUTPVector::iterator collection=subCollections.begin();
843 collection!=subCollections.end(); collection++) {
844 (*collection)->Reset();
845 (*collection)->ClearStatusFlag(kIsSubCollection);
849 fCurrentEventId=kAliHLTVoidEventID;
854 int AliHLTOUT::ResetInput()
856 // default implementation, nothing to do
860 const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTBlockDescriptor::GetHandlerDesc()
862 // see header file for class documentation
864 AliHLTOUTHandlerListEntryVector::iterator element=fpCollection->fDataHandlers.begin();
865 while (element!=fpCollection->fDataHandlers.end()) {
866 if (element->HasIndex(GetIndex())) {
872 return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry);
875 TObject* AliHLTOUT::GetDataObject()
877 // check if the current block encodes a ROOT object and expand it
879 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "data object has not been released, potential memory leak");
880 ReleaseDataBuffer(fpObjectBuffer);
886 if (GetDataBuffer(fpObjectBuffer, fObjectBufferSize)>=0) {
887 fpDataObject=AliHLTMessage::Extract(fpObjectBuffer, fObjectBufferSize);
889 fLog.LoggingVarargs(kHLTLogError, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "can not fetch data buffer");
895 int AliHLTOUT::ReleaseDataObject(TObject* pObject)
897 // release a ROOT object previously expanded from the currentr data block
898 if (!pObject) return -EINVAL;
899 if (pObject!=fpDataObject) {
900 fLog.LoggingVarargs(kHLTLogError, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "attempt to release wrong data object %p, expected %p", pObject, fpDataObject);
906 ReleaseDataBuffer(fpObjectBuffer);
913 void AliHLTOUT::SetEventId(AliHLTUInt64_t id)
916 if (fCurrentEventId!=kAliHLTVoidEventID && fCurrentEventId!=id) {
917 fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "SetEventId" , __FILE__ , __LINE__ , "event id was already set to 0x%llx, setting now to 0x%llx", fCurrentEventId, id);
922 void AliHLTOUT::Print(const char* option) const
926 for (AliHLTOUTBlockDescriptorVector::const_iterator i=fBlockDescList.begin();
927 i!=fBlockDescList.end(); i++)
931 for (AliHLTOUTHandlerListEntryVector::const_iterator i=fDataHandlers.begin();
932 i!=fDataHandlers.end(); i++)
937 void AliHLTOUT::AliHLTOUTBlockDescriptor::Print(const char* /*option*/) const
941 sout << "AliHLTOUTBlockDescriptor index 0x" << setfill('0') << setw(8) << hex << right << fIndex
942 << ": " << AliHLTComponent::DataType2Text(fDataType).c_str()
943 << " 0x" << setfill('0') << setw(8) << hex << fSpecification
944 << " processed " << dec << fProcessed;
945 cout << sout.str() << endl;
948 void AliHLTOUT::AliHLTOUTHandlerListEntry::Print(const char* /*option*/) const
952 AliHLTModuleAgent::AliHLTOUTHandlerType type=AliHLTModuleAgent::kUnknownOutput;
953 AliHLTComponentDataType dt=kAliHLTVoidDataType;
954 if (this->fpHandlerDesc) {
955 type=*(this->fpHandlerDesc);
956 dt=*(this->fpHandlerDesc);
958 const char* stype="";
960 case AliHLTModuleAgent::kEsd: stype="ESD"; break;
961 case AliHLTModuleAgent::kRawReader: stype="RawReader"; break;
962 case AliHLTModuleAgent::kRawStream: stype="RawStream"; break;
963 case AliHLTModuleAgent::kChain: stype="Chain"; break;
964 case AliHLTModuleAgent::kProprietary: stype="Proprietary"; break;
965 default: stype="unknown";
967 sout << "HLTOUT handler: "
968 << " " << type << " (" << stype << ")"
969 << " " << AliHLTComponent::DataType2Text(dt).c_str();
970 cout << sout.str() << endl;