]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODHandler.cxx
Additional flags for AOD replication (Roberta Arnaldi, AM)
[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 #include <TString.h>
27
28 #include "AliAODHandler.h"
29 #include "AliAODEvent.h"
30
31 ClassImp(AliAODHandler)
32
33 //______________________________________________________________________________
34 AliAODHandler::AliAODHandler() :
35     AliVEventHandler(),
36     fIsStandard(kTRUE),
37     fNeedsHeaderReplication(kFALSE),
38     fNeedsTracksBranchReplication(kFALSE),
39     fNeedsVerticesBranchReplication(kFALSE),
40     fNeedsV0sBranchReplication(kFALSE),
41     fNeedsTrackletsBranchReplication(kFALSE),
42     fNeedsPMDClustersBranchReplication(kFALSE),
43     fNeedsJetsBranchReplication(kFALSE),
44     fNeedsFMDClustersBranchReplication(kFALSE),
45     fNeedsCaloClustersBranchReplication(kFALSE),
46     fAODIsReplicated(kFALSE),
47     fAODEvent(NULL),
48     fTreeA(NULL),
49     fFileA(NULL),
50     fFileName("")
51 {
52   // default constructor
53 }
54
55 //______________________________________________________________________________
56 AliAODHandler::AliAODHandler(const char* name, const char* title):
57     AliVEventHandler(name, title),
58     fIsStandard(kTRUE),
59     fNeedsHeaderReplication(kFALSE),
60     fNeedsTracksBranchReplication(kFALSE),
61     fNeedsVerticesBranchReplication(kFALSE),
62     fNeedsV0sBranchReplication(kFALSE),
63     fNeedsTrackletsBranchReplication(kFALSE),
64     fNeedsPMDClustersBranchReplication(kFALSE),
65     fNeedsJetsBranchReplication(kFALSE),
66     fNeedsFMDClustersBranchReplication(kFALSE),
67     fNeedsCaloClustersBranchReplication(kFALSE),
68     fAODIsReplicated(kFALSE),
69     fAODEvent(NULL),
70     fTreeA(NULL),
71     fFileA(NULL),
72     fFileName("")
73 {
74 }
75
76 //______________________________________________________________________________
77 AliAODHandler::~AliAODHandler() 
78 {
79   delete fAODEvent;
80   if(fFileA){
81     // is already handled in TerminateIO
82     fFileA->Close();
83     delete fFileA;
84   }
85   delete fTreeA;
86  // destructor
87 }
88
89 //______________________________________________________________________________
90 Bool_t AliAODHandler::Init(Option_t* opt)
91 {
92   // Initialize IO
93   //
94   // Create the AODevent object
95   if(!fAODEvent){
96     fAODEvent = new AliAODEvent();
97     if (fIsStandard) fAODEvent->CreateStdContent();
98   }
99   //
100   // File opening according to execution mode
101   TString option(opt);
102   option.ToLower();
103   if (option.Contains("proof")) {
104     // proof
105     if (option.Contains("special")) {
106        // File for tree already opened on slave -> merging via files
107        fFileA = gFile;
108        CreateTree(1);
109     } else {   
110        // Merging in memory
111        CreateTree(0);
112     }   
113   } else {
114     // local and grid
115     TDirectory *owd = gDirectory;
116     fFileA = new TFile(fFileName.Data(), "RECREATE");
117     CreateTree(1);
118     owd->cd();
119   }
120   return kTRUE;
121 }
122
123 Bool_t AliAODHandler::FinishEvent()
124 {
125     // Fill data structures
126     fAODEvent->MakeEntriesReferencable();
127     FillTree();
128     if (fIsStandard) fAODEvent->ResetStd();
129     // Reset AOD replication flag
130     fAODIsReplicated = kFALSE;
131     
132     return kTRUE;
133 }
134
135 //______________________________________________________________________________
136 Bool_t AliAODHandler::Terminate()
137 {
138     // Terminate 
139     AddAODtoTreeUserInfo();
140     return kTRUE;
141 }
142
143 //______________________________________________________________________________
144 Bool_t AliAODHandler::TerminateIO()
145 {
146     // Terminate IO
147     if (fFileA) {
148         fFileA->Close();
149         delete fFileA;
150     }
151     return kTRUE;
152 }
153
154 //______________________________________________________________________________
155 void AliAODHandler::CreateTree(Int_t flag)
156 {
157     // Creates the AOD Tree
158     fTreeA = new TTree("aodTree", "AliAOD tree");
159     fTreeA->Branch(fAODEvent->GetList());
160     if (flag == 0) fTreeA->SetDirectory(0);
161 }
162
163 //______________________________________________________________________________
164 void AliAODHandler::FillTree()
165 {
166     // Fill the AOD Tree
167     fTreeA->Fill();
168 }
169
170 //______________________________________________________________________________
171 void AliAODHandler::AddAODtoTreeUserInfo()
172 {
173     // Add aod event to tree user info
174     fTreeA->GetUserInfo()->Add(fAODEvent);
175 }
176
177 //______________________________________________________________________________
178 void AliAODHandler::AddBranch(const char* cname, void* addobj)
179 {
180     // Add a new branch to the aod 
181     TDirectory *owd = gDirectory;
182     if (fFileA) {
183         fFileA->cd();
184     }
185     char** apointer = (char**) addobj;
186     TObject* obj = (TObject*) *apointer;
187     fTreeA->Branch(obj->GetName(), cname, addobj);
188     fAODEvent->AddObject(obj);
189     owd->cd();
190 }
191
192 //______________________________________________________________________________
193 void AliAODHandler::SetOutputFileName(const char* fname)
194 {
195 // Set file name.
196    fFileName = fname;
197 }
198
199 //______________________________________________________________________________
200 const char *AliAODHandler::GetOutputFileName()
201 {
202 // Get file name.
203    return fFileName.Data();
204 }