]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODHandler.cxx
Bug fix: corrected file name (Levente)
[u/mrichter/AliRoot.git] / STEER / AliAODHandler.cxx
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
23
24 #include <TTree.h>
25 #include <TFile.h>
26
27 #include "AliAODHandler.h"
28 #include "AliAODEvent.h"
29
30 ClassImp(AliAODHandler)
31
32 //______________________________________________________________________________
33 AliAODHandler::AliAODHandler() :
34     AliVEventHandler(),
35     fIsStandard(kTRUE),
36     fAODEvent(NULL),
37     fTreeA(NULL),
38     fFileA(NULL),
39     fName("")
40 {
41   // default constructor
42 }
43
44 //______________________________________________________________________________
45 AliAODHandler::AliAODHandler(const char* name, const char* title):
46     AliVEventHandler(name, title),
47     fIsStandard(kTRUE),
48     fAODEvent(NULL),
49     fTreeA(NULL),
50     fFileA(NULL),
51     fName("")
52 {
53 }
54
55 //______________________________________________________________________________
56 AliAODHandler::~AliAODHandler() 
57 {
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
67 }
68
69
70 Bool_t AliAODHandler::Init(Option_t* opt)
71 {
72   // Initialize IO
73   //
74   // Create the AODevent object
75   if(!fAODEvent){
76     fAODEvent = new AliAODEvent();
77     if (fIsStandard) fAODEvent->CreateStdContent();
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
87     TDirectory *owd = gDirectory;
88     fFileA = new TFile(fName, "RECREATE");
89     CreateTree(1);
90     owd->cd();
91   }
92   return kTRUE;
93 }
94
95 Bool_t AliAODHandler::FinishEvent()
96 {
97     // Fill data structures
98     fAODEvent->MakeEntriesReferencable();
99     FillTree();
100     if (fIsStandard) fAODEvent->ResetStd();
101     return kTRUE;
102 }
103
104 Bool_t AliAODHandler::Terminate()
105 {
106     // Terminate 
107     AddAODtoTreeUserInfo();
108     return kTRUE;
109 }
110
111 Bool_t AliAODHandler::TerminateIO()
112 {
113     // Terminate IO
114     if (fFileA) {
115         fFileA->ls();
116         fFileA->Close();
117         delete fFileA;
118     }
119     return kTRUE;
120 }
121
122
123 void AliAODHandler::CreateTree(Int_t flag)
124 {
125     // Creates the AOD Tree
126     fTreeA = new TTree("aodTree", "AliAOD tree");
127     fTreeA->Branch(fAODEvent->GetList());
128     if (flag == 0) fTreeA->SetDirectory(0);
129 }
130
131 void AliAODHandler::FillTree()
132 {
133     // Fill the AOD Tree
134     fTreeA->Fill();
135 }
136
137
138 void AliAODHandler::AddAODtoTreeUserInfo()
139 {
140     // Add aod event to tree user info
141     fTreeA->GetUserInfo()->Add(fAODEvent);
142 }
143
144 void AliAODHandler::AddBranch(const char* cname, TObject* addobj)
145 {
146     // Add a new branch to the aod 
147     TDirectory *owd = gDirectory;
148     if (fFileA) {
149         fFileA->cd();
150     }
151     fTreeA->Branch(addobj->GetName(), cname, &addobj);
152     fAODEvent->AddObject(addobj);
153     owd->cd();
154 }