#include <cerrno>
#include <cassert>
#include "AliHLTOUT.h"
#include "AliHLTMessage.h"
#include "AliHLTMisc.h"
#include "TSystem.h"
#include "TClass.h"
#include "TROOT.h"
#include <sstream>
#include <iomanip>
using std::cout;
ClassImp(AliHLTOUT)
AliHLTOUT::AliHLTOUT()
:
fSearchDataType(kAliHLTVoidDataType),
fSearchSpecification(kAliHLTVoidDataSpec),
fSearchHandlerType(AliHLTModuleAgent::kUnknownOutput),
fFlags(kSkipProcessed),
fBlockDescList(),
fCurrent(0),
fpBuffer(NULL),
fDataHandlers(),
fbVerbose(false),
fLog()
, fpDataObject(NULL)
, fpObjectBuffer(NULL)
, fObjectBufferSize(0)
, fCurrentEventId(kAliHLTVoidEventID)
{
}
AliHLTOUT::~AliHLTOUT()
{
if (CheckStatusFlag(kIsSubCollection)) {
fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "~AliHLTOUT" , __FILE__ , __LINE__ , "severe internal error: collection has not been released, potential crash due to invalid pointer");
}
if (fpDataObject) {
fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "data object has not been released, potential memory leak");
}
fpDataObject=NULL;
}
AliHLTOUT* AliHLTOUT::fgGlobalInstance=NULL;
int AliHLTOUT::Init()
{
int iResult=0;
if (fBlockDescList.size()>0) {
return 0;
}
SetStatusFlag(kCollecting);
if ((iResult=GenerateIndex())>=0) {
if ((iResult=InitHandlers())>=0) {
}
}
ClearStatusFlag(kCollecting);
return iResult;
}
int AliHLTOUT::GetNofDataBlocks()
{
return fBlockDescList.size();
}
int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec,
AliHLTModuleAgent::AliHLTOUTHandlerType handlerType,
bool skipProcessed)
{
fCurrent=0;
fSearchDataType=dt;
fSearchSpecification=spec;
fSearchHandlerType=handlerType;
if (skipProcessed) SetStatusFlag(kSkipProcessed);
else ClearStatusFlag(kSkipProcessed);
return FindAndSelectDataBlock();
}
int AliHLTOUT::SelectNextDataBlock()
{
if (fCurrent>=fBlockDescList.size()) return -ENOENT;
fCurrent++;
return FindAndSelectDataBlock();
}
int AliHLTOUT::FindAndSelectDataBlock()
{
if (CheckStatusFlag(kLocked)) return -EPERM;
int iResult=-ENOENT;
while (fCurrent<fBlockDescList.size() && iResult==-ENOENT) {
if (fBlockDescList[fCurrent]==fSearchDataType &&
(fSearchSpecification==kAliHLTVoidDataSpec || fBlockDescList[fCurrent]==fSearchSpecification) &&
(fSearchHandlerType==AliHLTModuleAgent::kUnknownOutput || FindHandlerDesc(fCurrent)==fSearchHandlerType) &&
(!CheckStatusFlag(kBlockSelection) || fBlockDescList[fCurrent].IsSelected()) &&
(!CheckStatusFlag(kSkipProcessed) || !fBlockDescList[fCurrent].IsProcessed())) {
iResult=fBlockDescList[fCurrent].GetIndex();
CheckByteOrder();
ClearStatusFlag(kByteOrderChecked);
ClearStatusFlag(kAlignmentChecked);
break;
}
fCurrent++;
}
return iResult;
}
int AliHLTOUT::GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec)
{
int iResult=-ENOENT;
if (fCurrent<fBlockDescList.size()) {
iResult=0;
dt=fBlockDescList[fCurrent];
spec=fBlockDescList[fCurrent];
}
return iResult;
}
const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::GetDataBlockHandlerDesc()
{
return FindHandlerDesc(fCurrent);
}
AliHLTModuleAgent::AliHLTOUTHandlerType AliHLTOUT::GetDataBlockHandlerType()
{
AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=FindHandlerDesc(fCurrent);
AliHLTModuleAgent::AliHLTOUTHandlerType type=desc;
return type;
}
AliHLTUInt32_t AliHLTOUT::GetDataBlockIndex()
{
if (fCurrent>=fBlockDescList.size()) return AliHLTOUTInvalidIndex;
return fBlockDescList[fCurrent].GetIndex();
}
int AliHLTOUT::GetDataBuffer(AliHLTComponentBlockData& desc)
{
int iResult=-ENOENT;
if (fCurrent<fBlockDescList.size()) {
AliHLTComponent::FillBlockData(desc);
if ((iResult=fBlockDescList[fCurrent].GetDataBuffer(fpBuffer, desc.fSize))>=0) {
desc.fPtr=const_cast<void*>(reinterpret_cast<const void*>(fpBuffer));
desc.fDataType=fBlockDescList[fCurrent];
desc.fSpecification=fBlockDescList[fCurrent];
}
}
return iResult;
}
int AliHLTOUT::GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)
{
int iResult=-ENOENT;
pBuffer=NULL;
size=0;
if (fCurrent<fBlockDescList.size()) {
if ((iResult=fBlockDescList[fCurrent].GetDataBuffer(fpBuffer, size))>=0) {
pBuffer=fpBuffer;
}
}
return iResult;
}
int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer)
{
int iResult=0;
if (pBuffer==fpBuffer) {
fpBuffer=NULL;
} else {
fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "ReleaseDataBuffer" , __FILE__ , __LINE__ , "buffer %p does not match the provided one %p", pBuffer, fpBuffer);
}
return iResult;
}
AliHLTModuleAgent* AliHLTOUT::GetAgent()
{
AliHLTModuleAgent* pAgent=NULL;
pAgent=FindHandlerDesc(fCurrent);
return pAgent;
}
AliHLTOUTHandler* AliHLTOUT::GetHandler()
{
AliHLTOUTHandler* pHandler=NULL;
pHandler=FindHandlerDesc(fCurrent);
return pHandler;
}
int AliHLTOUT::WriteESD(const AliHLTUInt8_t* , AliHLTUInt32_t , AliHLTComponentDataType , AliESDEvent* ) const
{
fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "WriteESD" , __FILE__ , __LINE__ , "method not implemented in base class");
return -ENOSYS;
}
int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc)
{
if (!CheckStatusFlag(kCollecting)) return -EPERM;
int iResult=0;
fBlockDescList.push_back(desc);
return iResult;
}
AliHLTOUT::AliHLTOUTByteOrder AliHLTOUT::CheckByteOrder()
{
if (fCurrent<fBlockDescList.size()) {
SetStatusFlag(kByteOrderChecked);
AliHLTOUT::AliHLTOUTByteOrder order=CheckBlockByteOrder(fBlockDescList[fCurrent].GetIndex());
return order;
}
return kInvalidByteOrder;
}
int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType type)
{
if (fCurrent<fBlockDescList.size()) {
SetStatusFlag(kAlignmentChecked);
int alignment=CheckBlockAlignment(fBlockDescList[fCurrent].GetIndex(), type);
return alignment;
}
return -ENOENT;
}
int AliHLTOUT::InitHandlers()
{
int iResult=0;
AliHLTOUTIndexList remnants;
int iCount=0;
for (int havedata=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec); havedata>=0; havedata=SelectNextDataBlock()) {
iCount++;
remnants.push_back(GetDataBlockIndex());
AliHLTComponentDataType dt=kAliHLTVoidDataType;
AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
if (GetDataBlockDescription(dt, spec)<0) break;
bool bHaveHandler=false;
for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); pAgent && iResult>=0; pAgent=AliHLTModuleAgent::GetNextAgent()) {
AliHLTModuleAgent::AliHLTOUTHandlerDesc handlerDesc;
if (pAgent->GetHandlerDescription(dt, spec, handlerDesc)>0) {
AliHLTOUTHandlerListEntry entry(pAgent->GetOutputHandler(dt, spec), handlerDesc, pAgent, GetDataBlockIndex());
InsertHandler(fDataHandlers, entry);
remnants.pop_back();
bHaveHandler=true;
if (fbVerbose) {
stringstream sout;
sout << "adding handler for block " << AliHLTComponent::DataType2Text(dt).c_str()
<< " 0x" << setfill('0') << setw(8) << hex << spec;
cout << sout.str() << endl;
}
break;
}
}
if (!bHaveHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
remnants.pop_back();
}
}
if (GetNofDataBlocks()>iCount) {
fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "InitHandlers" , __FILE__ , __LINE__ , "incomplete data type in %d out of %d data block(s)", GetNofDataBlocks()-iCount, GetNofDataBlocks());
}
if (remnants.size()>0) {
fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "InitHandlers" , __FILE__ , __LINE__ , "no handlers found for %d data blocks out of %d", remnants.size(), iCount);
AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
for (AliHLTOUTIndexList::iterator element=remnants.begin();
element!=remnants.end() && block!=fBlockDescList.end();
element++) {
for (int trials=0; trials<2; trials++) {
do {
if ((*block).GetIndex()==*element) break;
} while ((++block)!=fBlockDescList.end());
if (block==fBlockDescList.end()) {
block=fBlockDescList.begin();
}
}
assert(block!=fBlockDescList.end());
}
}
if (fbVerbose) Print();
return iResult;
}
int AliHLTOUT::InsertHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTOUTHandlerListEntry &entry)
{
int iResult=0;
AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
for (; element!=list.end();
element++) {
if (entry==(*element)) break;
}
if (element==list.end()) {
list.push_back(entry);
} else {
element->AddIndex(const_cast<AliHLTOUTHandlerListEntry&>(entry));
}
return iResult;
}
int AliHLTOUT::FillHandlerList(AliHLTOUTHandlerListEntryVector& list, AliHLTModuleAgent::AliHLTOUTHandlerType handlerType)
{
int iResult=0;
for (iResult=SelectFirstDataBlock(kAliHLTAnyDataType, kAliHLTVoidDataSpec, handlerType);
iResult>=0;
iResult=SelectNextDataBlock()) {
AliHLTComponentDataType dt=kAliHLTVoidDataType;
AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
GetDataBlockDescription(dt, spec);
AliHLTOUTHandler* pHandler=GetHandler();
if (!pHandler) {
fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "FillHandlerList" , __FILE__ , __LINE__ ,
"missing HLTOUT handler for block of type kChain: agent %s, data type %s, specification %#x, ... skipping data block",
GetAgent()?GetAgent()->GetModuleId():"invalid",
AliHLTComponent::DataType2Text(dt).c_str(), spec);
} else {
InsertHandler(list, GetDataBlockHandlerDesc());
}
}
if (iResult==-ENOENT) iResult=0;
return iResult;
}
int AliHLTOUT::RemoveEmptyDuplicateHandlers(AliHLTOUTHandlerListEntryVector& list)
{
int iResult=0;
AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
while (element!=list.end()) {
if (element->IsEmpty()) {
AliHLTOUTHandler* pHandler=*element;
AliHLTModuleAgent* pAgent=*element;
AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*element;
if (FindHandler(list, desc)>=0) {
element=list.erase(element);
if (pAgent) {
pAgent->DeleteOutputHandler(pHandler);
}
continue;
}
}
element++;
}
return iResult;
}
int AliHLTOUT::FindHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc)
{
for (int i=0; i<(int)list.size(); i++) {
if (list[i]==desc) return i;
}
return -ENOENT;
}
int AliHLTOUT::InvalidateBlocks(AliHLTOUTHandlerListEntryVector& list)
{
for (AliHLTOUTHandlerListEntryVector::iterator element=list.begin();
element!=list.end();
element++) {
element->InvalidateBlocks();
}
return 0;
}
const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::FindHandlerDesc(AliHLTUInt32_t blockIndex)
{
if (blockIndex<fBlockDescList.size()) {
return fBlockDescList[blockIndex].GetHandlerDesc();
}
return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::VoidHandlerListEntry());
}
AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry()
:
fpHandler(NULL),
fpHandlerDesc(NULL),
fpAgent(NULL),
fBlocks()
{
}
AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
AliHLTModuleAgent* pAgent,
AliHLTUInt32_t index)
:
fpHandler(pHandler),
fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
fpAgent(pAgent),
fBlocks()
{
*fpHandlerDesc=handlerDesc;
fBlocks.push_back(index);
}
AliHLTOUT::AliHLTOUTHandlerListEntry::AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src)
:
fpHandler(src.fpHandler),
fpHandlerDesc(new AliHLTModuleAgent::AliHLTOUTHandlerDesc),
fpAgent(src.fpAgent),
fBlocks()
{
*fpHandlerDesc=*src.fpHandlerDesc;
fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
}
AliHLTOUT::AliHLTOUTHandlerListEntry::~AliHLTOUTHandlerListEntry()
{
if (fpHandlerDesc) delete fpHandlerDesc;
fpHandlerDesc=NULL;
}
AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTHandlerListEntry::operator=(const AliHLTOUTHandlerListEntry& src)
{
if (this==&src) return *this;
fpHandler=src.fpHandler;
if (src.fpHandlerDesc)
*fpHandlerDesc=*src.fpHandlerDesc;
fpAgent=src.fpAgent;
fBlocks.assign(src.fBlocks.begin(), src.fBlocks.end());
return *this;
}
AliHLTUInt32_t AliHLTOUT::AliHLTOUTHandlerListEntry::operator[](int i) const
{
return (int)fBlocks.size()>i?fBlocks[i]:AliHLTOUTInvalidIndex;
}
bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTOUTHandlerListEntry& entry) const
{
if (entry.fpHandler!=fpHandler || fpHandler==NULL) return false;
assert(entry.fpAgent==fpAgent);
if (entry.fpAgent!=fpAgent) return false;
return true;
}
bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const
{
if (!fpHandlerDesc) return false;
return *fpHandlerDesc==handlerType;
}
bool AliHLTOUT::AliHLTOUTHandlerListEntry::operator==(const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc) const
{
if (!fpHandlerDesc) return false;
return *fpHandlerDesc==desc;
}
void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(const AliHLTOUT::AliHLTOUTHandlerListEntry &desc)
{
AliHLTOUTIndexList::const_iterator element;
for (element=desc.fBlocks.begin(); element!=desc.fBlocks.end(); element++) {
AddIndex(*element);
}
}
void AliHLTOUT::AliHLTOUTHandlerListEntry::AddIndex(AliHLTUInt32_t index)
{
fBlocks.push_back(index);
}
bool AliHLTOUT::AliHLTOUTHandlerListEntry::HasIndex(AliHLTUInt32_t index) const
{
AliHLTOUTIndexList::iterator element;
for (unsigned int i=0; i<fBlocks.size(); i++) {
if (fBlocks[i]==index) return true;
}
return false;
}
const AliHLTOUT::AliHLTOUTHandlerListEntry AliHLTOUT::AliHLTOUTHandlerListEntry::fgkVoidHandlerListEntry;
AliHLTUInt64_t AliHLTOUT::ByteSwap64(AliHLTUInt64_t src)
{
return ((src & 0xFFULL) << 56) |
((src & 0xFF00ULL) << 40) |
((src & 0xFF0000ULL) << 24) |
((src & 0xFF000000ULL) << 8) |
((src & 0xFF00000000ULL) >> 8) |
((src & 0xFF0000000000ULL) >> 24) |
((src & 0xFF000000000000ULL) >> 40) |
((src & 0xFF00000000000000ULL) >> 56);
}
AliHLTUInt32_t AliHLTOUT::ByteSwap32(AliHLTUInt32_t src)
{
return ((src & 0xFFULL) << 24) |
((src & 0xFF00ULL) << 8) |
((src & 0xFF0000ULL) >> 8) |
((src & 0xFF000000ULL) >> 24);
}
AliHLTOUT* AliHLTOUT::New(AliRawReader* pRawReader)
{
AliHLTOUT* instance=AliHLTMisc::LoadInstance((AliHLTOUT*)0, "AliHLTOUTRawReader", "libHLTrec.so");
if (instance) {
instance->SetParam(pRawReader);
}
return instance;
}
AliHLTOUT* AliHLTOUT::New(TTree* pDigitTree, int event)
{
AliHLTOUT* instance=AliHLTMisc::LoadInstance((AliHLTOUT*)0, "AliHLTOUTDigitReader", "libHLTrec.so");
if (instance) {
instance->SetParam(pDigitTree, event);
}
return instance;
}
AliHLTOUT* AliHLTOUT::New(const char* filename, int event)
{
AliHLTOUT* instance=AliHLTMisc::LoadInstance((AliHLTOUT*)0, "AliHLTOUTDigitReader", "libHLTrec.so");
if (instance) {
instance->SetParam(filename, event);
}
return instance;
}
void AliHLTOUT::Delete(AliHLTOUT* pInstance)
{
if (!pInstance) return;
if (pInstance==fgGlobalInstance) return;
TClass* pCl1=TClass::GetClass("AliHLTOUTRawReader");
TClass* pCl2=TClass::GetClass("AliHLTOUTDigitReader");
if (!pCl1 && !pCl2) {
AliHLTLogging log;
log.Logging(kHLTLogError, "AliHLTOUT::Delete", "HLTOUT handling", "potential memory leak: libHLTrec library not available, skipping destruction %p", pInstance);
return;
}
delete pInstance;
}
void AliHLTOUT::SetParam(AliRawReader* )
{
assert(0);
fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
}
void AliHLTOUT::SetParam(TTree* , int )
{
assert(0);
fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
}
void AliHLTOUT::SetParam(const char* , int )
{
assert(0);
fLog.LoggingVarargs(kHLTLogFatal, "AliHLTOUT", "SetParam" , __FILE__ , __LINE__ , "severe internal error: class mismatch");
}
int AliHLTOUT::SelectDataBlock()
{
int iResult=0;
if (fCurrent>=fBlockDescList.size()) return 0;
fBlockDescList[fCurrent].Select(true);
EnableBlockSelection();
return iResult;
}
int AliHLTOUT::SelectDataBlocks(const AliHLTOUTHandlerListEntry* pHandlerEntry)
{
int iResult=0;
if (!pHandlerEntry) return 0;
AliHLTModuleAgent* pAgent=*pHandlerEntry;
AliHLTLogging log;
log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", "selecting blocks for handler %s", pAgent->GetModuleId());
AliHLTOUTBlockDescriptorVector::iterator element;
for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
block!=fBlockDescList.end();
block++) {
if (block->GetHandlerDesc()==*pHandlerEntry && pHandlerEntry->HasIndex(block->GetIndex())) {
block->Select(true);
log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", " select block %s", AliHLTComponent::DataType2Text(*block).c_str());
} else {
log.Logging(kHLTLogDebug, "AliHLTOUT::SelectDataBlocks", "HLTOUT handling", " skip block %s", AliHLTComponent::DataType2Text(*block).c_str());
block->Select(false);
}
}
EnableBlockSelection();
AliHLTModuleAgent::AliHLTOUTHandlerDesc pHandlerDesc=*pHandlerEntry;
fSearchDataType=pHandlerDesc;
fSearchSpecification=kAliHLTVoidDataSpec;
fSearchHandlerType=pHandlerDesc;
fCurrent=0;
return iResult;
}
int AliHLTOUT::EnableBlockSelection()
{
SetStatusFlag(kBlockSelection);
return 0;
}
int AliHLTOUT::DisableBlockSelection()
{
ClearStatusFlag(kBlockSelection);
return 0;
}
int AliHLTOUT::ResetBlockSelection()
{
for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
block!=fBlockDescList.end();
block++) {
block->Select(false);
}
return 0;
}
int AliHLTOUT::MarkDataBlockProcessed()
{
int iResult=0;
if (fCurrent>=fBlockDescList.size()) return 0;
fBlockDescList[fCurrent].MarkProcessed();
return iResult;
}
int AliHLTOUT::MarkDataBlocksProcessed(const AliHLTOUTHandlerListEntry* pHandlerDesc)
{
int iResult=0;
if (!pHandlerDesc) return 0;
AliHLTOUTBlockDescriptorVector::iterator element;
for (AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
block!=fBlockDescList.end();
block++) {
if (block->GetHandlerDesc()==*pHandlerDesc && pHandlerDesc->HasIndex(block->GetIndex()))
block->MarkProcessed();
}
return iResult;
}
int AliHLTOUT::AddSubCollection(AliHLTOUT* pCollection)
{
int iResult=0;
if (!pCollection) return 0;
SetStatusFlag(kCollecting);
int index=-1;
for (index=pCollection->SelectFirstDataBlock();
index>=0;
index=pCollection->SelectNextDataBlock()) {
AliHLTComponentDataType dt=kAliHLTVoidDataType;
AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
pCollection->GetDataBlockDescription(dt, spec);
AliHLTOUTBlockDescriptor desc(dt, spec, index, pCollection);
AddBlockDescriptor(desc);
iResult++;
}
if (iResult>0) {
if (CheckStatusFlag(kIsSubCollection)) {
fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "AddSubCollection" , __FILE__ , __LINE__ , "HLTOUT object %p has already been added as sub-collection", pCollection);
} else {
pCollection->SetStatusFlag(kIsSubCollection);
}
}
ClearStatusFlag(kCollecting);
return iResult;
}
int AliHLTOUT::ReleaseSubCollection(AliHLTOUT* pCollection)
{
int iResult=0;
if (!pCollection) return 0;
AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
while (block!=fBlockDescList.end()) {
if ((*block)==pCollection) {
block=fBlockDescList.erase(block);
continue;
}
block++;
}
pCollection->ClearStatusFlag(kIsSubCollection);
return iResult;
}
int AliHLTOUT::Reset()
{
int iResult=0;
AliHLTOUTPVector subCollections;
AliHLTOUTBlockDescriptorVector::iterator block=fBlockDescList.begin();
while (block!=fBlockDescList.end()) {
if (!((*block)==this)) {
AliHLTOUTPVector::iterator collection=subCollections.begin();
for (; collection!=subCollections.end(); collection++)
if((*block)==*collection) break;
if (collection==subCollections.end())
subCollections.push_back(block->GetCollection());
}
block=fBlockDescList.erase(block);
}
for (AliHLTOUTPVector::iterator collection=subCollections.begin();
collection!=subCollections.end(); collection++) {
(*collection)->Reset();
(*collection)->ClearStatusFlag(kIsSubCollection);
}
ResetInput();
fCurrentEventId=kAliHLTVoidEventID;
return iResult;
}
int AliHLTOUT::ResetInput()
{
return 0;
}
const AliHLTOUT::AliHLTOUTHandlerListEntry& AliHLTOUT::AliHLTOUTBlockDescriptor::GetHandlerDesc()
{
if (fpCollection) {
AliHLTOUTHandlerListEntryVector::iterator element=fpCollection->fDataHandlers.begin();
while (element!=fpCollection->fDataHandlers.end()) {
if (element->HasIndex(GetIndex())) {
return *element;
}
element++;
}
}
return const_cast<AliHLTOUT::AliHLTOUTHandlerListEntry&>(AliHLTOUT::AliHLTOUTHandlerListEntry::VoidHandlerListEntry());
}
TObject* AliHLTOUT::GetDataObject()
{
if (fpDataObject) {
fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "data object has not been released, potential memory leak");
ReleaseDataBuffer(fpObjectBuffer);
}
fpObjectBuffer=NULL;
fObjectBufferSize=0;
fpDataObject=NULL;
if (GetDataBuffer(fpObjectBuffer, fObjectBufferSize)>=0) {
fpDataObject=AliHLTMessage::Extract(fpObjectBuffer, fObjectBufferSize);
} else {
fLog.LoggingVarargs(kHLTLogError, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "can not fetch data buffer");
}
return fpDataObject;
}
int AliHLTOUT::ReleaseDataObject(TObject* pObject)
{
if (!pObject) return -EINVAL;
if (pObject!=fpDataObject) {
fLog.LoggingVarargs(kHLTLogError, "AliHLTOUT", "GetDataObject" , __FILE__ , __LINE__ , "attempt to release wrong data object %p, expected %p", pObject, fpDataObject);
return -EINVAL;
}
delete fpDataObject;
fpDataObject=NULL;
ReleaseDataBuffer(fpObjectBuffer);
fpObjectBuffer=NULL;
fObjectBufferSize=0;
return 0;
}
void AliHLTOUT::SetEventId(AliHLTUInt64_t id)
{
if (fCurrentEventId!=kAliHLTVoidEventID && fCurrentEventId!=id) {
fLog.LoggingVarargs(kHLTLogWarning, "AliHLTOUT", "SetEventId" , __FILE__ , __LINE__ , "event id was already set to 0x%llx, setting now to 0x%llx", fCurrentEventId, id);
}
fCurrentEventId=id;
}
void AliHLTOUT::Print(const char* option) const
{
{
for (AliHLTOUTBlockDescriptorVector::const_iterator i=fBlockDescList.begin();
i!=fBlockDescList.end(); i++)
i->Print(option);
}
{
for (AliHLTOUTHandlerListEntryVector::const_iterator i=fDataHandlers.begin();
i!=fDataHandlers.end(); i++)
i->Print(option);
}
}
void AliHLTOUT::AliHLTOUTBlockDescriptor::Print(const char* ) const
{
stringstream sout;
sout << "AliHLTOUTBlockDescriptor index 0x" << setfill('0') << setw(8) << hex << right << fIndex
<< ": " << AliHLTComponent::DataType2Text(fDataType).c_str()
<< " 0x" << setfill('0') << setw(8) << hex << fSpecification
<< " processed " << dec << fProcessed;
cout << sout.str() << endl;
}
void AliHLTOUT::AliHLTOUTHandlerListEntry::Print(const char* ) const
{
stringstream sout;
AliHLTModuleAgent::AliHLTOUTHandlerType type=AliHLTModuleAgent::kUnknownOutput;
AliHLTComponentDataType dt=kAliHLTVoidDataType;
if (this->fpHandlerDesc) {
type=*(this->fpHandlerDesc);
dt=*(this->fpHandlerDesc);
}
const char* stype="";
switch(type) {
case AliHLTModuleAgent::kEsd: stype="ESD"; break;
case AliHLTModuleAgent::kRawReader: stype="RawReader"; break;
case AliHLTModuleAgent::kRawStream: stype="RawStream"; break;
case AliHLTModuleAgent::kChain: stype="Chain"; break;
case AliHLTModuleAgent::kProprietary: stype="Proprietary"; break;
default: stype="unknown";
}
sout << "HLTOUT handler: "
<< " " << type << " (" << stype << ")"
<< " " << AliHLTComponent::DataType2Text(dt).c_str();
cout << sout.str() << endl;
}