#include "AliGenDPMjetEventHeader.h"
#include "AliGenPythiaEventHeader.h"
#include "AliGenCocktailEventHeader.h"
-
-
+#include "AliCodeTimer.h"
+#include "AliAODBranchReplicator.h"
+#include "Riostream.h"
ClassImp(AliAODHandler)
AliVEventHandler(),
fIsStandard(kTRUE),
fFillAOD(kTRUE),
+ fFillAODRun(kTRUE),
+ fFillExtension(kTRUE),
fNeedsHeaderReplication(kFALSE),
fNeedsTracksBranchReplication(kFALSE),
fNeedsVerticesBranchReplication(kFALSE),
fNeedsV0sBranchReplication(kFALSE),
+ fNeedsCascadesBranchReplication(kFALSE),
fNeedsTrackletsBranchReplication(kFALSE),
fNeedsPMDClustersBranchReplication(kFALSE),
fNeedsJetsBranchReplication(kFALSE),
fNeedsFMDClustersBranchReplication(kFALSE),
fNeedsCaloClustersBranchReplication(kFALSE),
fNeedsMCParticlesBranchReplication(kFALSE),
+ fNeedsDimuonsBranchReplication(kFALSE),
fAODIsReplicated(kFALSE),
fAODEvent(NULL),
fMCEventH(NULL),
fTreeA(NULL),
fFileA(NULL),
fFileName(""),
- fExtensions(NULL)
+ fExtensions(NULL),
+ fFilters(NULL)
{
// default constructor
}
AliVEventHandler(name, title),
fIsStandard(kTRUE),
fFillAOD(kTRUE),
+ fFillAODRun(kTRUE),
+ fFillExtension(kTRUE),
fNeedsHeaderReplication(kFALSE),
fNeedsTracksBranchReplication(kFALSE),
fNeedsVerticesBranchReplication(kFALSE),
fNeedsV0sBranchReplication(kFALSE),
+ fNeedsCascadesBranchReplication(kFALSE),
fNeedsTrackletsBranchReplication(kFALSE),
fNeedsPMDClustersBranchReplication(kFALSE),
fNeedsJetsBranchReplication(kFALSE),
fNeedsFMDClustersBranchReplication(kFALSE),
fNeedsCaloClustersBranchReplication(kFALSE),
fNeedsMCParticlesBranchReplication(kFALSE),
+ fNeedsDimuonsBranchReplication(kFALSE),
fAODIsReplicated(kFALSE),
fAODEvent(NULL),
fMCEventH(NULL),
fTreeA(NULL),
fFileA(NULL),
fFileName(""),
- fExtensions(NULL)
+ fExtensions(NULL),
+ fFilters(NULL)
{
+// Normal constructor.
}
//______________________________________________________________________________
AliAODHandler::~AliAODHandler()
{
// Destructor.
+
delete fAODEvent;
- if(fFileA){
+
+ if (fFileA)
+ {
// is already handled in TerminateIO
fFileA->Close();
delete fFileA;
+ fTreeA = 0;
}
delete fTreeA;
- if (fExtensions) delete fExtensions;
+ delete fExtensions;
+ delete fFilters;
}
//______________________________________________________________________________
// Initialize IO
//
// Create the AODevent object
- if(!fAODEvent){
+
+ Bool_t createStdAOD = fIsStandard || fFillAOD;
+ if(!fAODEvent && createStdAOD){
fAODEvent = new AliAODEvent();
- if (fIsStandard) fAODEvent->CreateStdContent();
+ if (fIsStandard)
+ fAODEvent->CreateStdContent();
}
//
// File opening according to execution mode
TString option(opt);
option.ToLower();
- TDirectory *owd = gDirectory;
- if (option.Contains("proof")) {
- // proof
- // Merging via files. Need to access analysis manager via interpreter.
- gROOT->ProcessLine(Form("AliAnalysisManager::GetAnalysisManager()->OpenProofFile(\"%s\", \"RECREATE\");", fFileName.Data()));
- gROOT->ProcessLine(Form("AliAnalysisManager::GetAnalysisManager()->GetCommonOutputContainer()->SetFile((TFile*)0x%lx);", gFile));
- fFileA = gFile;
- } else {
- // local and grid
- fFileA = new TFile(fFileName.Data(), "RECREATE");
- }
- CreateTree(1);
- owd->cd();
+ if (createStdAOD) {
+ TDirectory *owd = gDirectory;
+ if (option.Contains("proof")) {
+ // proof
+ // Merging via files. Need to access analysis manager via interpreter.
+ gROOT->ProcessLine(Form("AliAnalysisDataContainer *c_common_out = AliAnalysisManager::GetAnalysisManager()->GetCommonOutputContainer();"));
+ gROOT->ProcessLine(Form("AliAnalysisManager::GetAnalysisManager()->OpenProofFile(c_common_out, \"RECREATE\");"));
+ fFileA = gFile;
+ } else {
+ // local and grid
+ fFileA = new TFile(fFileName.Data(), "RECREATE");
+ }
+ CreateTree(1);
+ owd->cd();
+ }
if (fExtensions) {
TIter next(fExtensions);
AliAODExtension *ext;
while ((ext=(AliAODExtension*)next())) ext->Init(option);
}
+ if (fFilters) {
+ TIter nextf(fFilters);
+ AliAODExtension *filteredAOD;
+ while ((filteredAOD=(AliAODExtension*)nextf())) {
+ filteredAOD->SetEvent(fAODEvent);
+ filteredAOD->Init(option);
+ }
+ }
+
return kTRUE;
}
+//______________________________________________________________________________
+void AliAODHandler::Print(Option_t* opt) const
+{
+ // Print info about this object
+
+ cout << opt << Form("IsStandard %d filename=%s",fIsStandard,fFileName.Data()) << endl;
+
+ if ( fExtensions )
+ {
+ cout << opt << fExtensions->GetEntries() << " extensions :" << endl;
+ PrintExtensions(*fExtensions);
+ }
+ if ( fFilters )
+ {
+ cout << opt << fFilters->GetEntries() << " filters :" << endl;
+ PrintExtensions(*fFilters);
+ }
+}
+
+//______________________________________________________________________________
+void AliAODHandler::PrintExtensions(const TObjArray& array) const
+{
+ // Show the list of aod extensions
+ TIter next(&array);
+ AliAODExtension* ext(0x0);
+ while ( ( ext = static_cast<AliAODExtension*>(next()) ) )
+ {
+ ext->Print(" ");
+ }
+}
+
//______________________________________________________________________________
void AliAODHandler::StoreMCParticles(){
// has to passed to the AOD Handler by this task
// (doing this in the steering macro would not work on PROOF)
+ if (!fAODEvent) return;
TClonesArray *mcarray = (TClonesArray*)fAODEvent->FindListObject(AliAODMCParticle::StdBranchName());
if(!mcarray)return;
- mcarray->Delete();
AliAODMCHeader *mcHeader = (AliAODMCHeader*)fAODEvent->FindListObject(AliAODMCHeader::StdBranchName());
if(!mcHeader)return;
- mcHeader->Reset();
-
// Get the MC Infos.. Handler needs to be set before
// while adding the branch
// This needs to be done, not to depend on the AnalysisManager
AliAODMCParticle mcpart_tmp(mcpart,i,flag);
+ mcpart_tmp.SetStatus(mcpart->Particle()->GetStatusCode());
//
Int_t d0 = mcpart_tmp.GetDaughter(0);
Int_t d1 = mcpart_tmp.GetDaughter(1);
if(fMCEventH->IsParticleSelected(m))mcpart_tmp.SetMother(fMCEventH->GetNewLabel(m));
else AliError(Form("PROBLEM Mother not selected %d \n", m));
}
-
+
new (l[j++]) AliAODMCParticle(mcpart_tmp);
}
for(int it = 0; it < fAODEvent->GetNTracks();++it){
AliAODTrack *track = fAODEvent->GetTrack(it);
- Int_t label = TMath::Abs(track->GetLabel());
+ Int_t sign = 1;
+ Int_t label = track->GetLabel();
+ if(label<0){ // preserve the sign for later usage
+ label *= -1;
+ sign = -1;
+ }
+
if (label >= AliMCEvent::BgLabelOffset()) label = mcEvent->BgLabelToIndex(label);
-
-
if(label > np || track->GetLabel() == 0){
AliWarning(Form("Wrong ESD track label %5d (%5d)",track->GetLabel(), label));
}
if(fMCEventH->GetNewLabel(label) == 0){
AliWarning(Form("New label not found for %5d (%5d)",track->GetLabel(), label));
}
- track->SetLabel(fMCEventH->GetNewLabel(label));
+ track->SetLabel(sign*fMCEventH->GetNewLabel(label));
}
}
// AOD calo cluster
TClonesArray *clusters = fAODEvent->GetCaloClusters();
if(clusters){
- for (Int_t iClust = 0;iClust < fAODEvent->GetNCaloClusters(); ++iClust) {
+ for (Int_t iClust = 0;iClust < fAODEvent->GetNumberOfCaloClusters(); ++iClust) {
AliAODCaloCluster * cluster = fAODEvent->GetCaloCluster(iClust);
- UInt_t nLabel = cluster->GetNLabel();
+ UInt_t nLabel = cluster->GetNLabels();
// Ugly but do not want to fragment memory by creating
// new Int_t (nLabel)
Int_t* labels = const_cast<Int_t*>(cluster->GetLabels());
if (labels){
for(UInt_t i = 0;i < nLabel;++i){
- labels[i] = fMCEventH->GetNewLabel(cluster->GetLabel(i));
+ labels[i] = fMCEventH->GetNewLabel(cluster->GetLabelAt(i));
}
}
// cluster->SetLabels(labels,nLabel);
Bool_t AliAODHandler::FinishEvent()
{
// Fill data structures
- if(fFillAOD){
- fAODEvent->MakeEntriesReferencable();
- StoreMCParticles();
- FillTree();
+
+ if(fFillAOD && fFillAODRun && fAODEvent){
+ fAODEvent->MakeEntriesReferencable();
+ fTreeA->BranchRef();
+ FillTree();
+ }
+
+ if ((fFillAOD && fFillAODRun) || fFillExtension) {
if (fExtensions) {
TIter next(fExtensions);
AliAODExtension *ext;
- while ((ext=(AliAODExtension*)next())) {
- ext->GetAOD()->MakeEntriesReferencable();
- ext->GetTree()->Fill();
+ while ((ext=(AliAODExtension*)next())) ext->FinishEvent();
+ }
+ if (fFilters) {
+ TIter nextf(fFilters);
+ AliAODExtension *ext;
+ while ((ext=(AliAODExtension*)nextf())) {
+ ext->FinishEvent();
}
}
+ }
+
+ if (fIsStandard)
+ {
+ fAODEvent->ResetStd();
}
-
- if (fIsStandard) fAODEvent->ResetStd();
+
+ if (fAODEvent)
+ {
+ TClonesArray *mcarray = static_cast<TClonesArray*>(fAODEvent->FindListObject(AliAODMCParticle::StdBranchName()));
+ if(mcarray) mcarray->Delete();
+
+ AliAODMCHeader *mcHeader = static_cast<AliAODMCHeader*>(fAODEvent->FindListObject(AliAODMCHeader::StdBranchName()));
+ if(mcHeader) mcHeader->Reset();
+ }
+
// Reset AOD replication flag
fAODIsReplicated = kFALSE;
return kTRUE;
{
// Terminate
AddAODtoTreeUserInfo();
- if (fExtensions) {
- TIter next(fExtensions);
- AliAODExtension *ext;
- while ((ext=(AliAODExtension*)next())) ext->GetTree()->GetUserInfo()->Add(ext->GetAOD());
- }
+
+ TIter nextF(fFilters);
+ AliAODExtension *ext;
+ while ((ext=static_cast<AliAODExtension*>(nextF())))
+ {
+ ext->AddAODtoTreeUserInfo();
+ }
+
+ TIter nextE(fExtensions);
+ while ((ext=static_cast<AliAODExtension*>(nextE())))
+ {
+ ext->AddAODtoTreeUserInfo();
+ }
+
return kTRUE;
}
{
// Terminate IO
if (fFileA) {
+ fFileA->Write();
fFileA->Close();
delete fFileA;
fFileA = 0;
+ // When closing the file, the tree is also deleted.
+ fTreeA = 0;
}
- if (fExtensions) {
- TIter next(fExtensions);
- AliAODExtension *ext;
- while ((ext=(AliAODExtension*)next())) ext->TerminateIO();
+
+ TIter nextF(fFilters);
+ AliAODExtension *ext;
+ while ((ext=static_cast<AliAODExtension*>(nextF())))
+ {
+ ext->TerminateIO();
}
+
+ TIter nextE(fExtensions);
+ while ((ext=static_cast<AliAODExtension*>(nextE())))
+ {
+ ext->TerminateIO();
+ }
+
return kTRUE;
}
//______________________________________________________________________________
void AliAODHandler::FillTree()
{
+
// Fill the AOD Tree
- fTreeA->Fill();
+ fTreeA->Fill();
}
//______________________________________________________________________________
void AliAODHandler::AddAODtoTreeUserInfo()
{
// Add aod event to tree user info
- fTreeA->GetUserInfo()->Add(fAODEvent);
+ if (fTreeA) fTreeA->GetUserInfo()->Add(fAODEvent);
+ // Now the tree owns our fAODEvent...
+ fAODEvent = 0;
}
//______________________________________________________________________________
void AliAODHandler::AddBranch(const char* cname, void* addobj, const char* filename)
{
- // Add a new branch to the aod. Added optional filename parameter if the
- // branch should be written to a separate file.
- if (strlen(filename)) {
- AliAODExtension *ext = AddExtension(filename);
- ext->AddBranch(cname, addobj);
- return;
- }
- TDirectory *owd = gDirectory;
- if (fFileA) {
- fFileA->cd();
- }
- char** apointer = (char**) addobj;
- TObject* obj = (TObject*) *apointer;
-
- fAODEvent->AddObject(obj);
-
- const Int_t kSplitlevel = 99; // default value in TTree::Branch()
- const Int_t kBufsize = 32000; // default value in TTree::Branch()
+ // Add a new branch to the aod. Added optional filename parameter if the
+ // branch should be written to a separate file.
+
+ if (strlen(filename))
+ {
+ AliAODExtension *ext = AddExtension(filename);
+ ext->AddBranch(cname, addobj);
+ return;
+ }
+
+ // Add branch to all filters
+ // Add branch to all filters
+ if (fFilters) {
+ TIter next(fFilters);
+ AliAODExtension *ext;
+ while ((ext=(AliAODExtension*)next())) ext->AddBranch(cname, addobj);
+ }
+
+ TDirectory *owd = gDirectory;
+ if (fFileA)
+ {
+ fFileA->cd();
+ }
- if (!fTreeA->FindBranch(obj->GetName())) {
- // Do the same as if we book via
- // TTree::Branch(TCollection*)
-
- fTreeA->Bronch(obj->GetName(), cname, fAODEvent->GetList()->GetObjectRef(obj),
- kBufsize, kSplitlevel - 1);
- // fTreeA->Branch(obj->GetName(), cname, addobj);
- }
- owd->cd();
+ char** apointer = (char**) addobj;
+ TObject* obj = (TObject*) *apointer;
+
+ fAODEvent->AddObject(obj);
+
+ const Int_t kSplitlevel = 99; // default value in TTree::Branch()
+ const Int_t kBufsize = 32000; // default value in TTree::Branch()
+
+ if (!fTreeA->FindBranch(obj->GetName()))
+ {
+ // Do the same as if we book via
+ // TTree::Branch(TCollection*)
+
+ fTreeA->Bronch(obj->GetName(), cname, fAODEvent->GetList()->GetObjectRef(obj),
+ kBufsize, kSplitlevel - 1);
+ }
+ owd->cd();
}
//______________________________________________________________________________
AliAODExtension *AliAODHandler::AddExtension(const char *filename, const char *title)
{
-// Add an AOD extension with some branches in a different file.
- TString fname(filename);
- if (!fname.EndsWith(".root")) fname += ".root";
- if (!fExtensions) {
- fExtensions = new TObjArray();
- fExtensions->SetOwner();
- }
- AliAODExtension *ext = (AliAODExtension*)fExtensions->FindObject(fname);
- if (!ext) {
- ext = new AliAODExtension(fname, title);
- fExtensions->Add(ext);
- }
- return ext;
+ // Add an AOD extension with some branches in a different file.
+
+ TString fname(filename);
+ if (!fname.EndsWith(".root")) fname += ".root";
+ if (!fExtensions) {
+ fExtensions = new TObjArray();
+ fExtensions->SetOwner();
+ }
+ AliAODExtension *ext = (AliAODExtension*)fExtensions->FindObject(fname);
+ if (!ext) {
+ ext = new AliAODExtension(fname, title);
+ fExtensions->Add(ext);
+ }
+ return ext;
}
-
+
+//______________________________________________________________________________
+AliAODExtension *AliAODHandler::GetExtension(const char *filename) const
+{
+ // Getter for AOD extensions via file name.
+ if (!fExtensions) return NULL;
+ return (AliAODExtension*)fExtensions->FindObject(filename);
+}
+
+//______________________________________________________________________________
+AliAODExtension *AliAODHandler::AddFilteredAOD(const char *filename, const char *filtername)
+{
+ // Add an AOD extension that can write only AOD events that pass a user filter.
+ if (!fFilters) {
+ fFilters = new TObjArray();
+ fFilters->SetOwner();
+ }
+ AliAODExtension *filter = (AliAODExtension*)fFilters->FindObject(filename);
+ if (!filter) {
+ filter = new AliAODExtension(filename, filtername, kTRUE);
+ fFilters->Add(filter);
+ }
+ return filter;
+}
+
+//______________________________________________________________________________
+AliAODExtension *AliAODHandler::GetFilteredAOD(const char *filename) const
+{
+ // Getter for AOD filters via file name.
+ if (!fFilters) return NULL;
+ return (AliAODExtension*)fFilters->FindObject(filename);
+}
+
//______________________________________________________________________________
void AliAODHandler::SetOutputFileName(const char* fname)
{
return fFileName.Data();
}
+//______________________________________________________________________________
+const char *AliAODHandler::GetExtraOutputs() const
+{
+ // Get extra outputs as a string separated by commas.
+ static TString eoutputs;
+ eoutputs = "";
+ TObject *obj;
+ if (fExtensions) {
+ TIter next1(fExtensions);
+ while ((obj=next1())) {
+ if (!eoutputs.IsNull()) eoutputs += ",";
+ eoutputs += obj->GetName();
+ }
+ }
+ if (fFilters) {
+ TIter next2(fFilters);
+ while ((obj=next2())) {
+ if (!eoutputs.IsNull()) eoutputs += ",";
+ eoutputs += obj->GetName();
+ }
+ }
+ return eoutputs.Data();
+}
+
+//______________________________________________________________________________
+Bool_t AliAODHandler::HasExtensions() const
+{
+ // Whether or not we manage extensions
+
+ if ( fExtensions && fExtensions->GetEntries()>0 ) return kTRUE;
+
+ return kFALSE;
+}
+
//______________________________________________________________________________
void AliAODHandler::SetMCHeaderInfo(AliAODMCHeader *mcHeader,AliGenEventHeader *genHeader){
}
-ClassImp(AliAODExtension)
-
-//-------------------------------------------------------------------------
-// Support class for AOD extensions. This is created by the user analysis
-// that requires a separate file for some AOD branches. The name of the
-// AliAODExtension object is the file name where the AOD branches will be
-// stored.
-//-------------------------------------------------------------------------
-
-//______________________________________________________________________________
-AliAODExtension::~AliAODExtension()
-{
-// Destructor.
- delete fAODEvent;
- if(fFileE){
- // is already handled in TerminateIO
- fFileE->Close();
- delete fFileE;
- }
- delete fTreeE;
-}
-
-//______________________________________________________________________________
-void AliAODExtension::AddBranch(const char* cname, void* addobj)
-{
- // Add a new branch to the aod
- if (!fAODEvent) {
- char type[20];
- gROOT->ProcessLine(Form("TString s_tmp; AliAnalysisManager::GetAnalysisManager()->GetAnalysisTypeString(s_tmp); sprintf((char*)0x%lx, \"%%s\", s_tmp.Data());", type));
- Init(type);
- }
- TDirectory *owd = gDirectory;
- if (fFileE) {
- fFileE->cd();
- }
- char** apointer = (char**) addobj;
- TObject* obj = (TObject*) *apointer;
-
- fAODEvent->AddObject(obj);
-
- const Int_t kSplitlevel = 99; // default value in TTree::Branch()
- const Int_t kBufsize = 32000; // default value in TTree::Branch()
-
- if (!fTreeE->FindBranch(obj->GetName())) {
- // Do the same as if we book via
- // TTree::Branch(TCollection*)
-
- fTreeE->Bronch(obj->GetName(), cname, fAODEvent->GetList()->GetObjectRef(obj),
- kBufsize, kSplitlevel - 1);
- // fTreeA->Branch(obj->GetName(), cname, addobj);
- }
- owd->cd();
-}
-
-//______________________________________________________________________________
-Bool_t AliAODExtension::Init(Option_t *option)
-{
-// Initialize IO.
- if(!fAODEvent) fAODEvent = new AliAODEvent();
- TDirectory *owd = gDirectory;
- TString opt(option);
- opt.ToLower();
- if (opt.Contains("proof")) {
- // proof
- // Merging via files. Need to access analysis manager via interpreter.
- gROOT->ProcessLine(Form("AliAnalysisManager::GetAnalysisManager()->OpenProofFile(\"%s\", \"RECREATE\");", fName.Data()));
- fFileE = gFile;
- } else {
- fFileE = new TFile(GetName(), "RECREATE");
- }
- fTreeE = new TTree("aodTree", "AliAOD tree");
- fTreeE->Branch(fAODEvent->GetList());
- owd->cd();
- return kTRUE;
-}
-
-//______________________________________________________________________________
-Bool_t AliAODExtension::TerminateIO()
-{
- // Terminate IO
- if (fFileE) {
- fFileE->Write();
- fFileE->Close();
- delete fFileE;
- fFileE = 0;
- }
- return kTRUE;
-}