]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAODHandler.cxx
ALICE interface to Pythia8
[u/mrichter/AliRoot.git] / STEER / AliAODHandler.cxx
CommitLineData
ec4af4c1 1/**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18//-------------------------------------------------------------------------
19// Implementation of the Virtual Event Handler Interface for AOD
20// Author: Andreas Morsch, CERN
21//-------------------------------------------------------------------------
22
052994fb 23
ec4af4c1 24#include <TTree.h>
e910dd36 25#include <TFile.h>
26
ec4af4c1 27#include "AliAODHandler.h"
28#include "AliAODEvent.h"
29
30ClassImp(AliAODHandler)
31
32//______________________________________________________________________________
33AliAODHandler::AliAODHandler() :
f3214a54 34 AliVEventHandler(),
78f7f935 35 fIsStandard(kTRUE),
ec4af4c1 36 fAODEvent(NULL),
e910dd36 37 fTreeA(NULL),
38 fFileA(NULL),
39 fName("")
ec4af4c1 40{
41 // default constructor
42}
43
44//______________________________________________________________________________
45AliAODHandler::AliAODHandler(const char* name, const char* title):
f3214a54 46 AliVEventHandler(name, title),
78f7f935 47 fIsStandard(kTRUE),
ec4af4c1 48 fAODEvent(NULL),
e910dd36 49 fTreeA(NULL),
50 fFileA(NULL),
51 fName("")
ec4af4c1 52{
53}
54
55//______________________________________________________________________________
56AliAODHandler::~AliAODHandler()
57{
6989bff3 58 delete fAODEvent;
59 if(fFileA){
60 // is already handled in TerminateIO
61 fFileA->Close();
62 delete fFileA;
63 }
64 delete fTreeA;
65 delete fName;
66 // destructor
ec4af4c1 67}
68
69
300d5701 70Bool_t AliAODHandler::Init(Option_t* opt)
ec4af4c1 71{
6989bff3 72 // Initialize IO
73 //
74 // Create the AODevent object
75 if(!fAODEvent){
ec4af4c1 76 fAODEvent = new AliAODEvent();
78f7f935 77 if (fIsStandard) fAODEvent->CreateStdContent();
6989bff3 78 }
79 //
80 // File opening according to execution mode
81
82 if (!(strcmp(opt, "proof"))) {
83 // proof
84 CreateTree(0);
85 } else {
86 // local and grid
26b9ac7a 87 TDirectory *owd = gDirectory;
6989bff3 88 fFileA = new TFile(fName, "RECREATE");
89 CreateTree(1);
26b9ac7a 90 owd->cd();
6989bff3 91 }
92 return kTRUE;
ec4af4c1 93}
94
5f380da9 95Bool_t AliAODHandler::FinishEvent()
ec4af4c1 96{
97 // Fill data structures
ec4af4c1 98 FillTree();
78f7f935 99 if (fIsStandard) fAODEvent->ResetStd();
ec4af4c1 100 return kTRUE;
101}
102
103Bool_t AliAODHandler::Terminate()
104{
105 // Terminate
106 AddAODtoTreeUserInfo();
107 return kTRUE;
108}
109
110Bool_t AliAODHandler::TerminateIO()
111{
112 // Terminate IO
21501411 113 if (fFileA) {
490e9023 114 fFileA->ls();
21501411 115 fFileA->Close();
116 delete fFileA;
117 }
ec4af4c1 118 return kTRUE;
119}
120
121
954526ed 122void AliAODHandler::CreateTree(Int_t flag)
ec4af4c1 123{
124 // Creates the AOD Tree
f3214a54 125 fTreeA = new TTree("aodTree", "AliAOD tree");
ec4af4c1 126 fTreeA->Branch(fAODEvent->GetList());
954526ed 127 if (flag == 0) fTreeA->SetDirectory(0);
ec4af4c1 128}
129
130void AliAODHandler::FillTree()
131{
132 // Fill the AOD Tree
133 fTreeA->Fill();
134}
135
136
137void AliAODHandler::AddAODtoTreeUserInfo()
138{
139 // Add aod event to tree user info
140 fTreeA->GetUserInfo()->Add(fAODEvent);
141}
490e9023 142
78f7f935 143void AliAODHandler::AddBranch(const char* cname, TObject* addobj)
490e9023 144{
145 // Add a new branch to the aod
146 TDirectory *owd = gDirectory;
147 if (fFileA) {
148 fFileA->cd();
149 }
78f7f935 150 fTreeA->Branch(addobj->GetName(), cname, &addobj);
490e9023 151 fAODEvent->AddObject(addobj);
152 owd->cd();
153}