]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODHandler.cxx
Close the file in TerminateIO()
[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
27 #include "AliAODHandler.h"
28 #include "AliAODEvent.h"
29
30 ClassImp(AliAODHandler)
31
32 //______________________________________________________________________________
33 AliAODHandler::AliAODHandler() :
34     AliVEventHandler(),
35     fAODEvent(NULL),
36     fTreeA(NULL),
37     fFileA(NULL),
38     fName("")
39 {
40   // default constructor
41 }
42
43 //______________________________________________________________________________
44 AliAODHandler::AliAODHandler(const char* name, const char* title):
45     AliVEventHandler(name, title),
46     fAODEvent(NULL),
47     fTreeA(NULL),
48     fFileA(NULL),
49     fName("")
50 {
51 }
52
53 //______________________________________________________________________________
54 AliAODHandler::~AliAODHandler() 
55 {
56 // destructor
57 }
58
59
60 Bool_t AliAODHandler::InitIO(Option_t* opt)
61 {
62     // Initialize IO
63     //
64     // Create the AODevent object
65     fAODEvent = new AliAODEvent();
66     fAODEvent->CreateStdContent();
67     //
68     // File opening according to execution mode
69
70     if (!(strcmp(opt, "proof"))) {
71         // proof
72     } else {
73         // local and grid
74         fFileA = new TFile(fName, "RECREATE");
75     }
76     //
77     // Create the output tree
78     CreateTree();
79     
80     return kTRUE;
81 }
82
83 Bool_t AliAODHandler::FinishEvent()
84 {
85     // Fill data structures
86     FillTree();
87     fAODEvent->ClearStd();
88     
89     return kTRUE;
90 }
91
92 Bool_t AliAODHandler::Terminate()
93 {
94     // Terminate 
95     AddAODtoTreeUserInfo();
96     return kTRUE;
97 }
98
99 Bool_t AliAODHandler::TerminateIO()
100 {
101     // Terminate IO
102     fFileA->Close();
103     return kTRUE;
104 }
105
106
107 void AliAODHandler::CreateTree()
108 {
109     // Creates the AOD Tree
110     fTreeA = new TTree("aodTree", "AliAOD tree");
111     fTreeA->Branch(fAODEvent->GetList());
112 }
113
114 void AliAODHandler::FillTree()
115 {
116     // Fill the AOD Tree
117     fTreeA->Fill();
118 }
119
120
121 void AliAODHandler::AddAODtoTreeUserInfo()
122 {
123     // Add aod event to tree user info
124     fTreeA->GetUserInfo()->Add(fAODEvent);
125 }