]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAODHandler.cxx
Include cstdlib (gcc 4.3.0)
[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>
7970f4ac 26#include <TString.h>
e910dd36 27
ec4af4c1 28#include "AliAODHandler.h"
29#include "AliAODEvent.h"
30
31ClassImp(AliAODHandler)
32
33//______________________________________________________________________________
34AliAODHandler::AliAODHandler() :
f3214a54 35 AliVEventHandler(),
78f7f935 36 fIsStandard(kTRUE),
7c3a9fbf 37 fNeedsHeaderReplication(kFALSE),
ec4af4c1 38 fAODEvent(NULL),
e910dd36 39 fTreeA(NULL),
40 fFileA(NULL),
7970f4ac 41 fFileName("")
ec4af4c1 42{
43 // default constructor
44}
45
46//______________________________________________________________________________
47AliAODHandler::AliAODHandler(const char* name, const char* title):
f3214a54 48 AliVEventHandler(name, title),
78f7f935 49 fIsStandard(kTRUE),
7c3a9fbf 50 fNeedsHeaderReplication(kFALSE),
ec4af4c1 51 fAODEvent(NULL),
e910dd36 52 fTreeA(NULL),
53 fFileA(NULL),
7970f4ac 54 fFileName("")
ec4af4c1 55{
56}
57
58//______________________________________________________________________________
59AliAODHandler::~AliAODHandler()
60{
6989bff3 61 delete fAODEvent;
62 if(fFileA){
63 // is already handled in TerminateIO
64 fFileA->Close();
65 delete fFileA;
66 }
67 delete fTreeA;
6989bff3 68 // destructor
ec4af4c1 69}
70
7970f4ac 71//______________________________________________________________________________
300d5701 72Bool_t AliAODHandler::Init(Option_t* opt)
ec4af4c1 73{
6989bff3 74 // Initialize IO
75 //
76 // Create the AODevent object
77 if(!fAODEvent){
ec4af4c1 78 fAODEvent = new AliAODEvent();
78f7f935 79 if (fIsStandard) fAODEvent->CreateStdContent();
6989bff3 80 }
81 //
82 // File opening according to execution mode
7970f4ac 83 TString option(opt);
84 option.ToLower();
85 if (option.Contains("proof")) {
6989bff3 86 // proof
7970f4ac 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 }
6989bff3 95 } else {
96 // local and grid
26b9ac7a 97 TDirectory *owd = gDirectory;
7970f4ac 98 fFileA = new TFile(fFileName.Data(), "RECREATE");
6989bff3 99 CreateTree(1);
26b9ac7a 100 owd->cd();
6989bff3 101 }
102 return kTRUE;
ec4af4c1 103}
104
5f380da9 105Bool_t AliAODHandler::FinishEvent()
ec4af4c1 106{
107 // Fill data structures
f4e5f8d5 108 fAODEvent->MakeEntriesReferencable();
ec4af4c1 109 FillTree();
78f7f935 110 if (fIsStandard) fAODEvent->ResetStd();
ec4af4c1 111 return kTRUE;
112}
113
7970f4ac 114//______________________________________________________________________________
ec4af4c1 115Bool_t AliAODHandler::Terminate()
116{
117 // Terminate
118 AddAODtoTreeUserInfo();
119 return kTRUE;
120}
121
7970f4ac 122//______________________________________________________________________________
ec4af4c1 123Bool_t AliAODHandler::TerminateIO()
124{
125 // Terminate IO
21501411 126 if (fFileA) {
127 fFileA->Close();
128 delete fFileA;
129 }
ec4af4c1 130 return kTRUE;
131}
132
7970f4ac 133//______________________________________________________________________________
954526ed 134void AliAODHandler::CreateTree(Int_t flag)
ec4af4c1 135{
136 // Creates the AOD Tree
f3214a54 137 fTreeA = new TTree("aodTree", "AliAOD tree");
ec4af4c1 138 fTreeA->Branch(fAODEvent->GetList());
954526ed 139 if (flag == 0) fTreeA->SetDirectory(0);
ec4af4c1 140}
141
7970f4ac 142//______________________________________________________________________________
ec4af4c1 143void AliAODHandler::FillTree()
144{
145 // Fill the AOD Tree
146 fTreeA->Fill();
147}
148
7970f4ac 149//______________________________________________________________________________
ec4af4c1 150void AliAODHandler::AddAODtoTreeUserInfo()
151{
152 // Add aod event to tree user info
153 fTreeA->GetUserInfo()->Add(fAODEvent);
154}
490e9023 155
7970f4ac 156//______________________________________________________________________________
0134949d 157void AliAODHandler::AddBranch(const char* cname, void* addobj)
490e9023 158{
159 // Add a new branch to the aod
160 TDirectory *owd = gDirectory;
161 if (fFileA) {
162 fFileA->cd();
163 }
0134949d 164 char** apointer = (char**) addobj;
165 TObject* obj = (TObject*) *apointer;
166 fTreeA->Branch(obj->GetName(), cname, addobj);
167 fAODEvent->AddObject(obj);
490e9023 168 owd->cd();
169}
7970f4ac 170
171//______________________________________________________________________________
172void AliAODHandler::SetOutputFileName(const char* fname)
173{
174// Set file name.
175 fFileName = fname;
176}
177
178//______________________________________________________________________________
179const char *AliAODHandler::GetOutputFileName()
180{
181// Get file name.
182 return fFileName.Data();
183}