Added methods for finding a given module in the DDL map (F. Prino)
[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(),
ec4af4c1 35 fAODEvent(NULL),
e910dd36 36 fTreeA(NULL),
37 fFileA(NULL),
38 fName("")
ec4af4c1 39{
40 // default constructor
41}
42
43//______________________________________________________________________________
44AliAODHandler::AliAODHandler(const char* name, const char* title):
f3214a54 45 AliVEventHandler(name, title),
ec4af4c1 46 fAODEvent(NULL),
e910dd36 47 fTreeA(NULL),
48 fFileA(NULL),
49 fName("")
ec4af4c1 50{
51}
52
53//______________________________________________________________________________
54AliAODHandler::~AliAODHandler()
55{
6989bff3 56 delete fAODEvent;
57 if(fFileA){
58 // is already handled in TerminateIO
59 fFileA->Close();
60 delete fFileA;
61 }
62 delete fTreeA;
63 delete fName;
64 // destructor
ec4af4c1 65}
66
67
300d5701 68Bool_t AliAODHandler::Init(Option_t* opt)
ec4af4c1 69{
6989bff3 70 // Initialize IO
71 //
72 // Create the AODevent object
73 if(!fAODEvent){
ec4af4c1 74 fAODEvent = new AliAODEvent();
75 fAODEvent->CreateStdContent();
6989bff3 76 }
77 //
78 // File opening according to execution mode
79
80 if (!(strcmp(opt, "proof"))) {
81 // proof
82 CreateTree(0);
83 } else {
84 // local and grid
26b9ac7a 85 TDirectory *owd = gDirectory;
6989bff3 86 fFileA = new TFile(fName, "RECREATE");
87 CreateTree(1);
26b9ac7a 88 owd->cd();
6989bff3 89 }
90 return kTRUE;
ec4af4c1 91}
92
5f380da9 93Bool_t AliAODHandler::FinishEvent()
ec4af4c1 94{
95 // Fill data structures
ec4af4c1 96 FillTree();
6989bff3 97 fAODEvent->ResetStd();
ec4af4c1 98 return kTRUE;
99}
100
101Bool_t AliAODHandler::Terminate()
102{
103 // Terminate
104 AddAODtoTreeUserInfo();
105 return kTRUE;
106}
107
108Bool_t AliAODHandler::TerminateIO()
109{
110 // Terminate IO
21501411 111 if (fFileA) {
490e9023 112 fFileA->ls();
21501411 113 fFileA->Close();
114 delete fFileA;
115 }
ec4af4c1 116 return kTRUE;
117}
118
119
954526ed 120void AliAODHandler::CreateTree(Int_t flag)
ec4af4c1 121{
122 // Creates the AOD Tree
f3214a54 123 fTreeA = new TTree("aodTree", "AliAOD tree");
ec4af4c1 124 fTreeA->Branch(fAODEvent->GetList());
954526ed 125 if (flag == 0) fTreeA->SetDirectory(0);
ec4af4c1 126}
127
128void AliAODHandler::FillTree()
129{
130 // Fill the AOD Tree
131 fTreeA->Fill();
132}
133
134
135void AliAODHandler::AddAODtoTreeUserInfo()
136{
137 // Add aod event to tree user info
138 fTreeA->GetUserInfo()->Add(fAODEvent);
139}
490e9023 140
141void AliAODHandler::AddBranch(const char* bname, const char* cname, TObject* addobj)
142{
143 // Add a new branch to the aod
144 TDirectory *owd = gDirectory;
145 if (fFileA) {
146 fFileA->cd();
147 }
148 fTreeA->Branch(bname, cname, &addobj);
149 fAODEvent->AddObject(addobj);
150 owd->cd();
151}