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