//* provided "as is" without express or implied warranty. *
//**************************************************************************
-/** @file AliHLTEsdManagerImplementation.cxx
- @author Matthias Richter
- @date
- @brief Manager for merging and writing of HLT ESDs
-*/
+/// @file AliHLTEsdManagerImplementation.cxx
+/// @author Matthias Richter
+/// @date
+/// @brief Manager for merging and writing of HLT ESDs
+/// This is an implementation of the abstract interface AliHLTEsdManager
#include "AliHLTEsdManagerImplementation.h"
#include "AliHLTComponent.h"
#include "TTree.h"
#include "TClass.h"
#include "TObject.h"
-#include "TObjectTable.h"
-#include "TSystem.h"
-#include "TChain.h"
#include "TList.h"
const float kAliESDVZERODefaultTime = -1024.;
}
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;
-#endif //HAVE_NOT_ESD_COPY
}
// Matthias 2009-06-06: writing of individual ESD files for the different origins was a
// see header file for class documentation
int iResult=0;
-#ifndef HAVE_NOT_ESD_COPY
if (fName.IsNull()) {
// this is the first event, create the file name
fName="";
fpTree->GetUserInfo()->Clear();
}
}
-#else //HAVE_NOT_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
- // used for filling.
- // Unfortunately the following code crashes at the second event.
- // The expert on the ESD (Christian Klein Boesig) does not have
- // a solution either. It seems to be a problem in ROOT.
- // TTree* dummy=new TTree("dummy","dummy");
- // dummy->SetDirectory(0);
- // pESD->WriteToTree(dummy);
- // dummy->Fill();
- // dummy->GetUserInfo()->Add(pESD);
- // fpEsd->ReadFromTree(dummy);
- // dummy->GetEvent(0);
- // fpEsd->WriteToTree(fpTree);
- // fpTree->Fill();
- // dummy->GetUserInfo()->Clear();
- // delete dummy;
- //
- // The only way is via TChain, which is working on files only at the
- // time of writing.
- // We use temporary files for the new event to be copied into the
- // existing tree.
- //
- if (fName.IsNull()) {
- // this is the first event, create the file on disk and write ESD
- 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";
- }
-
- if (!gSystem->AccessPathName(fName)) {
- // file exists, delete
- TString shellcmd="rm -f ";
- shellcmd+=fName;
- gSystem->Exec(shellcmd);
- }
- }
-
- TChain chain("esdTree");
- TList cleanup;
- cleanup.SetOwner();
-
- int nofCurrentEvents=0;
- if (iResult>=0) {
- if (!gSystem->AccessPathName(fName)) {
- // these are the other events, use the target file and temporary files to merge
- // with TChain
- chain.Add(fName);
-
- if (eventno>=0) {
- TFile file(fName);
- if (!file.IsZombie()) {
- TTree* pSrcTree;
- file.GetObject("esdTree", pSrcTree);
- if (pSrcTree) {
- nofCurrentEvents=pSrcTree->GetEntries();
- }
- file.Close();
- }
- }
- }
- }
-
- // synchronize and add empty events
- if (nofCurrentEvents<eventno) {
- iResult=1; // indicate files to merge
- TTree* pTgtTree=new TTree("esdTree", "Tree with HLT ESD objects");
- if (pTgtTree) {
- pTgtTree->SetDirectory(0);
- AliESDEvent* pTmpESD=new AliESDEvent;
- if (pTmpESD) {
- TString tmpfilename;
- FILE* pTmpFile=gSystem->TempFileName(tmpfilename);
- if (pTmpFile) {
- fclose(pTmpFile);
- pTmpFile=NULL;
- cleanup.Add(new TObjString(tmpfilename));
- TFile emptyevents(tmpfilename, "RECREATE");
- if (!emptyevents.IsZombie()) {
- pTmpESD->CreateStdContent();
- pTmpESD->WriteToTree(pTgtTree);
- HLTDebug("adding %d empty events to file %s", eventno-nofCurrentEvents, fName.Data());
- for (int i=nofCurrentEvents; i<eventno; i++) {
- pTgtTree->Fill();
- }
- pTgtTree->GetUserInfo()->Add(pTmpESD);
- emptyevents.cd();
- pTgtTree->Write();
- emptyevents.Close();
- chain.Add(tmpfilename);
- pTgtTree->GetUserInfo()->Clear();
- }
- }
- delete pTmpESD;
- } else {
- iResult=-ENOMEM;
- }
- delete pTgtTree;
- } else {
- iResult=-ENOMEM;
- }
- }
-
- if (iResult>=0 && pSrcESD) {
- // add the new event to the chain
- iResult=1; // indicate files to merge
- TString tmpfilename=WriteTempFile(pSrcESD);
- if (!tmpfilename.IsNull()) {
- chain.Add(tmpfilename);
- cleanup.Add(new TObjString(tmpfilename));
- }
- }
-
- if (iResult>0) {
- // build temporary file name for chain output
- TString tgtName;
- FILE* pTmpFile=gSystem->TempFileName(tgtName);
- if (pTmpFile) {
- fclose(pTmpFile);
- pTmpFile=NULL;
-
- // there have been problems with the memory consumption when using
- // TChain::Merge
- // 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; event<nofEvents; event++) {
-// chain.GetEntry(event);
-// pTgtTree->Fill();
-// }
-
-// 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 ";
- shellcmd+=tgtName + " " + fName;
- if (gSystem->Exec(shellcmd)==0) {
- HLTDebug("renaming %s to %s", tgtName.Data(), fName.Data());
- } else {
- HLTError("can not rename temporary file %s to %s", tgtName.Data(), fName.Data());
- }
- } else {
- HLTError("can not get temporary file name from system");
- iResult=-EBADF;
- }
- }
-
- // delete temporary files
- // the list objects are cleaned up by the TList destructor as the
- // list is owner
- TIter entry(&cleanup);
- while (TObject* pObj=entry.Next()) {
- if (dynamic_cast<TObjString*>(pObj)) {
- TString shellcmd="rm -f ";
- shellcmd+=(dynamic_cast<TObjString*>(pObj))->GetString();
- gSystem->Exec(shellcmd);
- }
- }
-#endif //HAVE_NOT_ESD_COPY
return iResult;
}
-TString AliHLTEsdManagerImplementation::AliHLTEsdListEntry::WriteTempFile(AliESDEvent* pESD) const
-{
- // see header file for class documentation
- int iResult=0;
- TString tmpfilename;
- FILE* pTmpFile=gSystem->TempFileName(tmpfilename);
- if (pTmpFile) {
- fclose(pTmpFile);
- pTmpFile=NULL;
-
- TFile file(tmpfilename, "RECREATE");
- if (!file.IsZombie()) {
- TTree* pTree=AliHLTEsdManagerImplementation::EmbedIntoTree(pESD);
- if (pTree) {
- file.cd();
- if (pTree->Write()>0) {
- } else {
- HLTError("can not write esd tree to temporary file %s", tmpfilename.Data());
- }
-
- pTree->GetUserInfo()->Clear();
- delete pTree;
- } else {
- iResult=-ENOMEM;
- }
- file.Close();
- } else {
- HLTError("can not open file %s", tmpfilename.Data());
- iResult=-EBADF;
- }
- } else {
- HLTError("can not get temporary file name from system");
- iResult=-EBADF;
- }
-
- if (iResult<0) {
- if (gSystem->AccessPathName(tmpfilename)==0) {
- TString shellcmd="rm -f ";
- shellcmd+=tmpfilename;
- gSystem->Exec(shellcmd);
- }
- tmpfilename="";
- }
- return tmpfilename;
-}
-
void AliHLTEsdManagerImplementation::AliHLTEsdListEntry::SetDirectory(const char* directory)
{
// see header file for class documentation
fDirectory=directory;
}
-void AliHLTEsdManagerImplementation::AliHLTEsdListEntry::Delete()
-{
- // see header file for class documentation
- if (fName.IsNull()) return;
- if (gSystem->AccessPathName(fName)!=0) return;
-
- TString shellcmd="rm -f ";
- shellcmd+=fName;
- gSystem->Exec(shellcmd);
- fName="";
-}
-
const char* AliHLTEsdManagerImplementation::AliHLTEsdListEntry::GetFileName() const
{
// see header file for class documentation