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