From 57584811bad404a82788a1bdb27c03b28350f9a6 Mon Sep 17 00:00:00 2001 From: richterm Date: Sun, 26 Oct 2008 14:13:34 +0000 Subject: [PATCH] first implementation of ESD merging (not matching!) on the level of TClonesArrays, other ESD objects currently ignored --- HLT/BASE/AliHLTEsdManager.h | 11 ++ HLT/BASE/AliHLTSystem.cxx | 20 +--- HLT/rec/AliHLTEsdManagerImplementation.cxx | 114 +++++++++------------ HLT/rec/AliHLTEsdManagerImplementation.h | 18 ++-- 4 files changed, 70 insertions(+), 93 deletions(-) diff --git a/HLT/BASE/AliHLTEsdManager.h b/HLT/BASE/AliHLTEsdManager.h index bfcff87c4f9..9ab47f03cc5 100644 --- a/HLT/BASE/AliHLTEsdManager.h +++ b/HLT/BASE/AliHLTEsdManager.h @@ -68,6 +68,17 @@ class AliHLTEsdManager : public AliHLTLogging { virtual int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt, AliESDEvent* tgtesd=NULL, int eventno=-1)=0; + /** + * Merge content of source ESD into the target ESD. + * Merging is done on the level of objects in the ESD and for the + * moment it's only implemented for the TClonesArrays. In that case it's + * easy to detect whether the object is empty or not. + * + * \b Note: The function can not match entries of the same type, like e.g. + * tracks from the 'Tracks' member. + */ + virtual int Merge(AliESDEvent* pTgt, AliESDEvent* pSrc) const =0; + /** * Align all ESD to the same number of events. * The function adds empty events to all ESD files if their event number diff --git a/HLT/BASE/AliHLTSystem.cxx b/HLT/BASE/AliHLTSystem.cxx index 7e23c4da8d0..de3d4ab7e87 100644 --- a/HLT/BASE/AliHLTSystem.cxx +++ b/HLT/BASE/AliHLTSystem.cxx @@ -870,14 +870,6 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd) AliHLTOUT::InvalidateBlocks(*pEsdHandlers); AliHLTOUT::InvalidateBlocks(*pProprietaryHandlers); - // first come first serve: the ESD of the first handler is also filled into - // the main ESD. Has to be changed later. - // currently, merging to the provided ESDs crashes at the level of the - // TTree::Fill in AliReconstruction, furthermore, the wrong ESD is passed - // by the framework - AliESDEvent* pMasterESD=NULL; - pMasterESD=esd; - AliHLTComponentDataTypeList esdBlocks; for (iResult=pHLTOUT->SelectFirstDataBlock(); @@ -914,11 +906,7 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd) const AliHLTUInt8_t* pBuffer=NULL; AliHLTUInt32_t size=0; if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) { - pHLTOUT->WriteESD(pBuffer, size, dt); - if (pMasterESD) { - pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD); - pMasterESD=NULL; - } + pHLTOUT->WriteESD(pBuffer, size, dt, esd); pHLTOUT->ReleaseDataBuffer(pBuffer); } pHLTOUT->MarkDataBlockProcessed(); @@ -978,11 +966,7 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd) if ((size=pHandler->GetProcessedData(pBuffer))>0) { AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*handler; AliHLTComponentDataType dt=desc; - pHLTOUT->WriteESD(pBuffer, size, dt); - if (pMasterESD) { - pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD); - pMasterESD=NULL; - } + pHLTOUT->WriteESD(pBuffer, size, dt, esd); pHandler->ReleaseProcessedData(pBuffer, size); } pHLTOUT->MarkDataBlocksProcessed(&(*handler)); diff --git a/HLT/rec/AliHLTEsdManagerImplementation.cxx b/HLT/rec/AliHLTEsdManagerImplementation.cxx index 5ac70e35075..3f0df73ec5e 100644 --- a/HLT/rec/AliHLTEsdManagerImplementation.cxx +++ b/HLT/rec/AliHLTEsdManagerImplementation.cxx @@ -111,39 +111,30 @@ int AliHLTEsdManagerImplementation::WriteESD(const AliHLTUInt8_t* pBuffer, AliHL if (pESD) { AliHLTEsdListEntry* entry=Find(dt); if (!entry) { - AliHLTEsdListEntry* newEntry=new AliHLTEsdListEntry(dt); - if (!fDirectory.IsNull()) { - newEntry->SetDirectory(fDirectory); + if ((entry=new AliHLTEsdListEntry(dt))!=NULL) { + if (!fDirectory.IsNull()) { + entry->SetDirectory(fDirectory); + } + fESDs.push_back(entry); } - fESDs.push_back(newEntry); } - if (tgtesd) { -#if 0 // later extension !defined(HAVE_NOT_ESD_NONSTD) - entry=Find(dt); - if (entry) { - entry->CopyNonEmptyObjects(tgtesd, pESD); - } else { - HLTError("internal mismatch, can not create list entry"); - iResult=-ENOMEM; - } -#elif !defined(HAVE_NOT_ESD_COPY) - *tgtesd=*pESD; + if (entry) { + if (tgtesd) { +#if !defined(HAVE_NOT_ESD_COPY) + Merge(tgtesd, pESD); #else //HAVE_NOT_ESD_COPY - static bool warningPrinted=false; - if (!warningPrinted) { - HLTWarning("old version of AliESDEvent does not provide assignment operator, skip merging to global hltEsd"); - } - warningPrinted=true; + static bool warningPrinted=false; + if (!warningPrinted) { + HLTWarning("old version of AliESDEvent does not provide assignment operator, skip merging to global hltEsd"); + } + warningPrinted=true; #endif //HAVE_NOT_ESD_COPY - } else { - entry=Find(dt); - if (entry) { + } entry->WriteESD(pESD, eventno); } else { HLTError("internal mismatch, can not create list entry"); iResult=-ENOMEM; } - } } else { HLTWarning("data block %s is not of class type AliESDEvent, ignoring ...", AliHLTComponent::DataType2Text(dt).c_str()); } @@ -639,81 +630,68 @@ const char* AliHLTEsdManagerImplementation::AliHLTEsdListEntry::GetPrefix() return fPrefix.Data(); } -int AliHLTEsdManagerImplementation::AliHLTEsdListEntry::CopyNonEmptyObjects(AliESDEvent* pTgt, AliESDEvent* pSrc) +int AliHLTEsdManagerImplementation::Merge(AliESDEvent* pTgt, AliESDEvent* pSrc) const { // see header file for class documentation int iResult=0; if (!pTgt || !pSrc) return -EINVAL; - const char* defaultPrefix="HLT"; TIter next(pSrc->GetList()); TObject* pSrcObject=NULL; TString name; + static int warningCount=0; while ((pSrcObject=next())) { if(!pSrcObject->InheritsFrom("TCollection")){ // simple objects } else if(pSrcObject->InheritsFrom("TClonesArray")){ TClonesArray* pTClA=dynamic_cast(pSrcObject); if (pTClA!=NULL && pTClA->GetEntriesFast()>0) { - bool bMakeNewName=true; - name=defaultPrefix; - name+=pTClA->GetName(); + name=pTClA->GetName(); TObject* pTgtObject=pTgt->GetList()->FindObject(name); TClonesArray* pTgtArray=NULL; - if (bMakeNewName=(pTgtObject!=NULL) && pTgtObject->InheritsFrom("TClonesArray")){ + if (pTgtObject!=NULL && pTgtObject->InheritsFrom("TClonesArray")){ pTgtArray=dynamic_cast(pTgtObject); if (pTgtArray) { TString classType=pTClA->Class()->GetName(); if (classType.CompareTo(pTgtArray->Class()->GetName())==0) { if (pTgtArray->GetEntries()==0) { - bMakeNewName=false; + pTgtArray->ExpandCreate(pTClA->GetEntries()); + for(int i=0; iGetEntriesFast(); ++i){ + (*pTClA)[i]->Copy(*((*pTgtArray)[i])); + } } else { - HLTWarning("TClonesArray \"%s\" in target ESD %p is already filled with %d entries", - name.Data(), pTgt, pTgtArray->GetEntries()); + if (warningCount++<10) { + HLTWarning("TClonesArray \"%s\" in target ESD %p is already filled with %d entries", + name.Data(), pTgt, pTgtArray->GetEntries()); + } + iResult=-EBUSY; } } else { - HLTWarning("TClonesArray \"%s\" exists in target ESD %p, but describes incompatible class type %s instead of %s", - name.Data(), pTgt, pTgtArray->GetClass()->GetName(), pTClA->GetClass()->GetName()); + if (warningCount++<10) { + HLTWarning("TClonesArray \"%s\" exists in target ESD %p, but describes incompatible class type %s instead of %s", + name.Data(), pTgt, pTgtArray->GetClass()->GetName(), pTClA->GetClass()->GetName()); + } + iResult=-EBUSY; } } else { - HLTError("internal error: dynamic cast failed for object %s %p", pTgtObject->GetName(), pTgtObject); + if (warningCount++<10) { + HLTError("internal error: dynamic cast failed for object %s %p", pTgtObject->GetName(), pTgtObject); + } + iResult=-EBUSY; } } else if (pTgtObject) { - HLTWarning("object \"%s\" does already exist in target ESD %p, but is %s rather than TClonesArray", - name.Data(), pTgt, pTgtObject->Class()->GetName()); - // TODO: temporary solution, think about a general naming scheme and add - // the name as property of AliHLTEsdListEntry - } - - if (bMakeNewName) { - pTgtArray=NULL; - int count=1; - while (pTgt->GetList()->FindObject(name)) { - name.Form("%sESD_%s", GetPrefix(), pTClA->GetName()); - if (count++>1) { - name+=Form("%d", count); - } + if (warningCount++<10) { + HLTWarning("object \"%s\" does already exist in target ESD %p, but is %s rather than TClonesArray" + " skipping data", + name.Data(), pTgt, pTgtObject->Class()->GetName()); } - HLTWarning("adding new TClonesArray \"%s\" because of conflicts", name.Data()); - } - - if (pTgtArray) { - pTgtArray->ExpandCreate(pTClA->GetEntries()); - HLTInfo("Expanding TClonesArray \"%s\" to %d elements", pTgtArray->GetClass()->GetName(), pTClA->GetEntries()); + iResult=-EBUSY; } else { - pTgtArray=new TClonesArray(pTClA->GetClass(), pTClA->GetEntries()); - pTgtArray->ExpandCreate(pTClA->GetEntries()); - pTgtArray->SetName(name); - pTgt->AddObject(pTgtArray); - HLTInfo("Adding TClonesArray \"%s\" with %d elements to ESD %p", name.Data(), pTClA->GetEntries(), pTgt); - } - - if (pTgtArray) { - for(int i=0; iGetEntriesFast(); ++i){ - (*pTClA)[i]->Copy(*((*pTgtArray)[i])); + if (warningCount++<10) { + HLTWarning("object \"%s\" does not exist in target ESD %p, data can not be copied because it will be lost when filling the tree", + name.Data(), pTgt); } - } else { - iResult=-ENOMEM; + iResult=-ENOENT; } } } diff --git a/HLT/rec/AliHLTEsdManagerImplementation.h b/HLT/rec/AliHLTEsdManagerImplementation.h index a8c553048de..a6a1d3c6cfa 100644 --- a/HLT/rec/AliHLTEsdManagerImplementation.h +++ b/HLT/rec/AliHLTEsdManagerImplementation.h @@ -55,6 +55,17 @@ class AliHLTEsdManagerImplementation : public AliHLTEsdManager { int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt, AliESDEvent* tgtesd=NULL, int eventno=-1); + /** + * Merge content of source ESD into the target ESD. + * Merging is done on the level of objects in the ESD and for the + * moment it's only implemented for the TClonesArrays. In that case it's + * easy to detect whether the object is empty or not. + * + * \b Note: The function can not match entries of the same type, like e.g. + * tracks from the 'Tracks' member. + */ + int Merge(AliESDEvent* pTgt, AliESDEvent* pSrc) const; + /** * Align all ESD to the same number of events. * The function adds empty events to all ESD files if their event number @@ -107,13 +118,6 @@ class AliHLTEsdManagerImplementation : public AliHLTEsdManager { */ int WriteESD(AliESDEvent* pESD, int eventno=-1); - /** - * Copy non-empty objects of the source ESD to the target ESD. - * The first implementation just copies the entries of type TClonesArray which - * are not empty. - */ - int CopyNonEmptyObjects(AliESDEvent* pTgt, AliESDEvent* pSrc); - /** * Set the target directory for the ESD file. */ -- 2.39.3