From 83cb7e1df33120b2ea06b9ef855afac9646b8a82 Mon Sep 17 00:00:00 2001 From: richterm Date: Fri, 9 May 2008 15:50:10 +0000 Subject: [PATCH] using the new ESD assignment operator to merge ESDs --- HLT/BASE/AliHLTModulePreprocessor.cxx | 34 +++---- HLT/BASE/AliHLTSystem.cxx | 13 +-- HLT/BASE/AliHLTSystem.h | 10 +- HLT/configure.ac | 16 +++- HLT/rec/AliHLTEsdManager.cxx | 130 ++++++++++++++++++++------ HLT/rec/AliHLTEsdManager.h | 19 +++- 6 files changed, 160 insertions(+), 62 deletions(-) diff --git a/HLT/BASE/AliHLTModulePreprocessor.cxx b/HLT/BASE/AliHLTModulePreprocessor.cxx index 924cbfd41cb..cbbde3e9a94 100644 --- a/HLT/BASE/AliHLTModulePreprocessor.cxx +++ b/HLT/BASE/AliHLTModulePreprocessor.cxx @@ -32,6 +32,23 @@ ClassImp(AliHLTModulePreprocessor) +AliHLTModulePreprocessor::AliHLTModulePreprocessor() + : + fpInterface(NULL), + fActiveDetectors(0) +{ + // see header file for class documentation + // or + // refer to README to build package + // or + // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt +} + +AliHLTModulePreprocessor::~AliHLTModulePreprocessor() +{ + // see header file for function documentation +} + const Int_t AliHLTModulePreprocessor::kNDetectors = 21; const char* AliHLTModulePreprocessor::fgkDetectorName[kNDetectors] = @@ -59,23 +76,6 @@ const char* AliHLTModulePreprocessor::fgkDetectorName[kNDetectors] = "HLT" }; -AliHLTModulePreprocessor::AliHLTModulePreprocessor() - : - fpInterface(NULL), - fActiveDetectors(0) -{ - // see header file for class documentation - // or - // refer to README to build package - // or - // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt -} - -AliHLTModulePreprocessor::~AliHLTModulePreprocessor() -{ - // see header file for function documentation -} - void AliHLTModulePreprocessor::SetShuttleInterface(AliHLTShuttleInterface* pInterface) { assert(fpInterface==NULL || fpInterface==pInterface || pInterface==NULL); diff --git a/HLT/BASE/AliHLTSystem.cxx b/HLT/BASE/AliHLTSystem.cxx index fe2bcf30f85..804a3258a00 100644 --- a/HLT/BASE/AliHLTSystem.cxx +++ b/HLT/BASE/AliHLTSystem.cxx @@ -62,7 +62,7 @@ const char* AliHLTSystem::fgkHLTDefaultLibs[]= { /** ROOT macro for the implementation of ROOT specific class methods */ ClassImp(AliHLTSystem) -AliHLTSystem::AliHLTSystem() +AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel) : fpComponentHandler(new AliHLTComponentHandler()), fpConfigurationHandler(new AliHLTConfigurationHandler()), @@ -71,8 +71,7 @@ AliHLTSystem::AliHLTSystem() fChains(), fStopwatches(new TObjArray), fEventCount(-1), - fGoodEvents(-1), - bWriteGlobalEsd(false) + fGoodEvents(-1) { // see header file for class documentation // or @@ -83,8 +82,8 @@ AliHLTSystem::AliHLTSystem() if (fgNofInstances++>0) HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time"); - SetGlobalLoggingLevel(kHLTLogDefault); - SetFrameworkLog(kHLTLogDefault); + SetGlobalLoggingLevel(loglevel); + SetFrameworkLog(loglevel); if (fpComponentHandler) { AliHLTComponentEnvironment env; memset(&env, 0, sizeof(AliHLTComponentEnvironment)); @@ -743,7 +742,7 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd) // TTree::Fill in AliReconstruction, furthermore, the wrong ESD is passed // by the framework AliESDEvent* pMasterESD=NULL; - if (bWriteGlobalEsd) pMasterESD=esd; + pMasterESD=esd; for (iResult=pHLTOUT->SelectFirstDataBlock(); iResult>=0; iResult=pHLTOUT->SelectNextDataBlock()) { @@ -975,8 +974,6 @@ int AliHLTSystem::ScanOptions(const char* options) HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'"); } } - } else if (token.Contains("globalesd")) { - bWriteGlobalEsd=true; } else if (token.BeginsWith("lib") && token.EndsWith(".so")) { libs+=token; libs+=" "; diff --git a/HLT/BASE/AliHLTSystem.h b/HLT/BASE/AliHLTSystem.h index a3f10cca8c0..70e17196926 100644 --- a/HLT/BASE/AliHLTSystem.h +++ b/HLT/BASE/AliHLTSystem.h @@ -47,7 +47,7 @@ class TStopwatch; class AliHLTSystem : public AliHLTLogging { public: /** default constructor */ - AliHLTSystem(); + AliHLTSystem(AliHLTComponentLogSeverity loglevel=kHLTLogDefault); /** destructor */ virtual ~AliHLTSystem(); @@ -451,16 +451,10 @@ class AliHLTSystem : public AliHLTLogging { /** number of events processed successfully */ int fGoodEvents; //!transient - /** switch whether to write to the global hltesd or not - * since this causes a crash outside the HLT code this - * can be enabled by the 'globalesd' argument - */ - bool bWriteGlobalEsd; //!transient - /** array of default libraries */ static const char* fgkHLTDefaultLibs[]; //!transient - ClassDef(AliHLTSystem, 6); + ClassDef(AliHLTSystem, 7); }; #endif diff --git a/HLT/configure.ac b/HLT/configure.ac index 7e603eafda1..e95e1c2e046 100644 --- a/HLT/configure.ac +++ b/HLT/configure.ac @@ -252,6 +252,20 @@ if test ! "x$have_aliroot" = "xno" ; then ALIROOT_LIBS= fi + dnl + dnl ESD copy function added May 9 2008 rev 25667 + dnl + have_esd_copy=no + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], + [AliESDEvent esd1; + AliESDEvent esd2; + esd2=esd1;])], + [AC_DEFINE(HAVE_ESD_COPY) + have_esd_copy=yes], + []) + AC_MSG_CHECKING(for ESD assignment operator) + AC_MSG_RESULT([$have_esd_copy]) + dnl dnl required header files and libraries for modules dnl @@ -284,7 +298,7 @@ if test ! "x$have_aliroot" = "xno" ; then [have_alitpc=no ALITPC_LIBS= ]) fi - AC_MSG_RESULT($have_alitpc) + AC_MSG_RESULT([$have_alitpc]) fi AC_CHECK_HEADERS([AliTPCCalibPulser.h], [], [AC_DEFINE(HAVE_NOT_ALITPCCALIBPULSER)]) AC_CHECK_HEADERS([AliTPCCalibPedestal.h], [], [AC_DEFINE(HAVE_NOT_ALITPCCALIBPEDESTAL)]) diff --git a/HLT/rec/AliHLTEsdManager.cxx b/HLT/rec/AliHLTEsdManager.cxx index 970fd6ff160..b97e27ec88e 100644 --- a/HLT/rec/AliHLTEsdManager.cxx +++ b/HLT/rec/AliHLTEsdManager.cxx @@ -117,6 +117,9 @@ int AliHLTEsdManager::WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size fESDs.push_back(newEntry); } if (tgtesd) { +#ifdef HAVE_ESD_COPY + *tgtesd=*pESD; +#else TTree* pTmpTree=AliHLTEsdManager::EmbedIntoTree(pESD); if (pTmpTree) { tgtesd->ReadFromTree(pTmpTree); @@ -127,6 +130,7 @@ int AliHLTEsdManager::WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size } else { iResult=-ENOMEM; } +#endif } else { entry=Find(dt); if (entry) { @@ -214,7 +218,10 @@ AliHLTEsdManager::AliHLTEsdListEntry::AliHLTEsdListEntry(AliHLTComponentDataType : fName(), fDirectory(), - fDt(dt) + fDt(dt), + fpFile(NULL), + fpTree(NULL), + fpEsd(NULL) { // see header file for class documentation } @@ -232,6 +239,73 @@ bool AliHLTEsdManager::AliHLTEsdListEntry::operator==(AliHLTComponentDataType dt int AliHLTEsdManager::AliHLTEsdListEntry::WriteESD(AliESDEvent* pSrcESD, int eventno) { + // see header file for class documentation + int iResult=0; +#ifdef HAVE_ESD_COPY + if (fName.IsNull()) { + // this is the first event, create the file name + TString origin; + origin.Insert(0, fDt.fOrigin, kAliHLTComponentDataTypefOriginSize); + origin.Remove(TString::kTrailing, ' '); + origin.ToUpper(); + fName=""; + if (!fDirectory.IsNull()) { + fName+=fDirectory; fName+="/"; + } + fName+="AliHLT"; fName+=origin; + if (fDt!=kAliHLTDataTypeESDObject && + fDt!=kAliHLTDataTypeESDTree) { + + HLTWarning("non-standard ESD type %s", AliHLTComponent::DataType2Text(fDt).c_str()); + TString id; + id.Insert(0, fDt.fID, kAliHLTComponentDataTypefIDsize); + id.Remove(TString::kTrailing, ' '); + id.ToUpper(); + fName+="_"; fName+=id; fName+=".root"; + } else { + fName+="ESDs.root"; + } + + fpFile=new TFile(fName, "RECREATE"); + fpTree=new TTree("esdTree", "Tree with HLT ESD objects"); + fpEsd=new AliESDEvent; + if (fpEsd) { + fpEsd->CreateStdContent(); + if (fpTree) { + fpEsd->WriteToTree(fpTree); + } + } + } + + if (fpFile && fpTree && fpEsd) { + // synchronize and add empty events + fpEsd->Reset(); + int nofCurrentEvents=fpTree->GetEntries(); + if (nofCurrentEventsFill(); + } + } + + if (iResult>=0 && pSrcESD) { + *fpEsd=*pSrcESD; + fpTree->Fill(); + iResult=1; // indicate tree to be written + } + + if (iResult>0) { + fpFile->cd(); + fpTree->GetUserInfo()->Add(fpEsd); + fpTree->Write(fpTree->GetName(),TObject::kOverwrite); + fpTree->GetUserInfo()->Clear(); + } + } +#else //HAVE_ESD_COPY + // this is the old workaround, necessary for older AliRoot versions + // version<=v4-12-Release + // we need to copy the ESD, I did not find an approptiate // method, the workaround is to save the ESD in a temporary // tree, read the content back into the ESD structure @@ -256,7 +330,6 @@ int AliHLTEsdManager::AliHLTEsdListEntry::WriteESD(AliESDEvent* pSrcESD, int eve // We use temporary files for the new event to be copied into the // existing tree. // - int iResult=0; if (fName.IsNull()) { // this is the first event, create the file on disk and write ESD TString origin; @@ -374,31 +447,33 @@ int AliHLTEsdManager::AliHLTEsdListEntry::WriteESD(AliESDEvent* pSrcESD, int eve // there have been problems with the memory consumption when using // TChain::Merge - //chain.Merge(tgtName); - TFile tgtFile(tgtName, "RECREATE"); - TTree* pTgtTree=new TTree("esdTree", "Tree with HLT ESD objects"); - AliESDEvent* pTgtESD=new AliESDEvent; - if (pTgtTree && pTgtESD) { - pTgtESD->ReadFromTree(&chain); - pTgtESD->WriteToTree(pTgtTree); - - int nofEvents=chain.GetEntries(); - for (int event=0; eventFill(); - } - - pTgtTree->GetUserInfo()->Add(pTgtESD); - tgtFile.cd(); - pTgtTree->Write(); - pTgtTree->GetUserInfo()->Clear(); - } else { - iResult=-ENOMEM; - } - - if (pTgtTree) delete pTgtTree; - if (pTgtESD) delete pTgtESD; - tgtFile.Close(); + // but using a separate loop soemtimes crashes in AliESDEvent::ReadFromTree + // since this is for backward compatiblity only, we take the TChain::Merge + chain.Merge(tgtName); +// TFile tgtFile(tgtName, "RECREATE"); +// TTree* pTgtTree=new TTree("esdTree", "Tree with HLT ESD objects"); +// AliESDEvent* pTgtESD=new AliESDEvent; +// if (pTgtTree && pTgtESD) { +// pTgtESD->ReadFromTree(&chain); +// pTgtESD->WriteToTree(pTgtTree); + +// int nofEvents=chain.GetEntries(); +// for (int event=0; eventFill(); +// } + +// pTgtTree->GetUserInfo()->Add(pTgtESD); +// tgtFile.cd(); +// pTgtTree->Write(); +// pTgtTree->GetUserInfo()->Clear(); +// } else { +// iResult=-ENOMEM; +// } + +// if (pTgtTree) delete pTgtTree; +// if (pTgtESD) delete pTgtESD; +// tgtFile.Close(); // rename the merged file to the original file TString shellcmd="mv "; @@ -425,6 +500,7 @@ int AliHLTEsdManager::AliHLTEsdListEntry::WriteESD(AliESDEvent* pSrcESD, int eve gSystem->Exec(shellcmd); } } +#endif //HAVE_ESD_COPY return iResult; } diff --git a/HLT/rec/AliHLTEsdManager.h b/HLT/rec/AliHLTEsdManager.h index ace5212b6e9..122fd81592b 100644 --- a/HLT/rec/AliHLTEsdManager.h +++ b/HLT/rec/AliHLTEsdManager.h @@ -24,6 +24,17 @@ class TFile; /** * @class AliHLTEsdManager + * Tool to write and merge HLT ESD objects. + * + * HLT components can produce ESD output. The ESD objects are sent via + * a TMessage like mechanism as part of the HLTOUT data. This class retrieves + * streamed AliESDEvent objects from an HLT output block. An ESD object can be + * copied to a global ESD provided by the caller or to files. The name of the + * ROOT files follows the scheme AliHLTDETESDs.root where DET denotes a detector. + * E.g. the ESD from a data block of type {ESD_TREE,TPC} will be added to the + * file AliHLTTPCESDs.root. + * + * @ingroup alihlt_out */ class AliHLTEsdManager : public AliHLTLogging { public: @@ -138,6 +149,12 @@ class AliHLTEsdManager : public AliHLTLogging { TString fDirectory; //!transient /** data type of the corresponding block */ AliHLTComponentDataType fDt; //!transient + /** the root file for this esd */ + TFile* fpFile; //!transient + /** the tree for this esd */ + TTree* fpTree; //!transient + /** the esd to fill into the tree */ + AliESDEvent* fpEsd; //!transient }; typedef vector AliHLTEsdPList; @@ -153,7 +170,7 @@ class AliHLTEsdManager : public AliHLTLogging { /** target directory */ TString fDirectory; //!transient - ClassDef(AliHLTEsdManager, 0) + ClassDef(AliHLTEsdManager, 1) }; #endif -- 2.39.3