Fixed operator+ functions for exceptions (forgot to change them when migrated from...
[u/mrichter/AliRoot.git] / EVE / Alieve / EventAlieve.cxx
CommitLineData
5a5a1232 1// $Header$
2
3#include "EventAlieve.h"
4#include <Reve/Reve.h>
5
6#include <AliRunLoader.h>
7#include <AliESD.h>
3aecaefc 8#include <AliESDfriend.h>
5a5a1232 9
10#include <TFile.h>
11#include <TTree.h>
12
13#include <TROOT.h>
14#include <TSystem.h>
15
16using namespace Reve;
17using namespace Alieve;
18
19//______________________________________________________________________
20// Event
21//
22
23ClassImp(Event)
24
25Event* Alieve::gEvent = 0;
26
27Bool_t Alieve::Event::fgUseRunLoader = true;
28Bool_t Alieve::Event::fgUseESDTree = true;
29
30void Event::Initialize(Bool_t use_runloader, Bool_t use_esd)
31{
32 static const Exc_t eH("Event::Initialize ");
33
34 fgUseRunLoader = use_runloader;
35 fgUseESDTree = use_esd;
36
37 /*
38 if(fgUseRunLoader == false && fgUseESDTree == false)
39 throw(eH + "should use at least one data source.");
40
41 if(fgUseRunLoader) {
42 AssertMacro("loadlibs.C");
43 }
44 else if(fgUseESDTree) {
45 gSystem->Load("libESD.so");
46 }
47 */
48}
49
50/**************************************************************************/
51
6f0b0040 52Event::Event() :
265ecb21 53 EventBase(),
54
55 fPath (), fEventId (0),
56 fRunLoader (0),
57 fESDFile (0), fESDTree (0), fESD (0),
58 fESDfriendFile (0), fESDfriendTree (0), fESDfriend (0)
59{}
5a5a1232 60
6f0b0040 61Event::Event(TString path, Int_t ev) :
62 EventBase("AliEVE Event"),
265ecb21 63
64 fPath (path), fEventId(ev),
65 fRunLoader (0),
66 fESDFile (0), fESDTree (0), fESD (0),
67 fESDfriendFile (0), fESDfriendTree (0), fESDfriend (0)
5a5a1232 68{
5a5a1232 69 Open();
70}
71
72/**************************************************************************/
73
74void Event::Open()
75{
76 static const Exc_t eH("Event::Open ");
77
78 gSystem->ExpandPathName(fPath);
79 if(fPath[0] != '/')
80 fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data());
81
82 if(fgUseRunLoader) {
83 TString ga_path(Form("%s/galice.root", fPath.Data()));
84 if(gSystem->AccessPathName(ga_path, kReadPermission))
85 throw(eH + "can not read '" + ga_path + "'.");
86 fRunLoader = AliRunLoader::Open(ga_path);
87 if(!fRunLoader)
88 throw(eH + "failed opening ALICE run loader from '" + ga_path + "'.");
89 {
90 TString alice_path = fPath + "/";
91 fRunLoader->SetDirName(alice_path);
92 }
1eaa5849 93 if(fRunLoader->LoadgAlice() != 0)
5a5a1232 94 throw(eH + "failed loading gAlice.");
cf94c7c2 95 if(fRunLoader->LoadHeader() != 0)
96 throw(eH + "failed loading header.");
5a5a1232 97
1eaa5849 98 if(fRunLoader->GetEvent(fEventId) != 0)
5a5a1232 99 throw(eH + "failed getting required event.");
5a5a1232 100 }
101
102 if(fgUseESDTree) {
103 TString p(Form("%s/AliESDs.root", fPath.Data()));
3aecaefc 104 if(gSystem->AccessPathName(p, kReadPermission))
105 throw(eH + "can not read '" + p + "'.");
5a5a1232 106 fESDFile = new TFile(p);
107 if(fESDFile->IsZombie()) {
108 delete fESDFile; fESDFile = 0;
109 throw(eH + "failed opening ALICE ESD from '" + p + "'.");
110 }
111
112 fESDTree = (TTree*) fESDFile->Get("esdTree");
113 if(fESDTree == 0)
114 throw(eH + "failed getting the esdTree.");
115 fESDTree->SetBranchAddress("ESD", &fESD);
116 if(fESDTree->GetEntry(fEventId) <= 0)
3aecaefc 117 throw(eH + "failed getting required event from ESD.");
118
119 // Check if ESDfriends exists and load it
120 p = Form("%s/AliESDfriends.root", fPath.Data());
121 if(gSystem->AccessPathName(p, kReadPermission) == kFALSE) {
122 fESDfriendFile = new TFile(p);
123 if(fESDfriendFile->IsZombie()) {
124 delete fESDfriendFile; fESDfriendFile = 0;
125 throw(eH + "failed opening ALICE ESDfriend from '" + p + "'.");
126 }
127
128 fESDfriendTree = (TTree*) fESDfriendFile->Get("esdFriendTree");
129 if(fESDfriendTree == 0)
130 throw(eH + "failed getting the esdFriendTree.");
131 fESDfriendTree->SetBranchAddress("ESDfriend", &fESDfriend);
132 if(fESDfriendTree->GetEntry(fEventId) <= 0)
133 throw(eH + "failed getting required event from ESDfriend.");
134
135 fESD->SetESDfriend(fESDfriend);
136 }
5a5a1232 137 }
138
1eaa5849 139 SetName(Form("Event %d", fEventId));
5a5a1232 140 SetTitle(fPath);
141}
142
1eaa5849 143void Event::GotoEvent(Int_t event)
144{
145 static const Exc_t eH("Event::GotoEvent ");
146
147 if(fgUseRunLoader && fRunLoader == 0)
148 throw(eH + "RunLoader not initialized.");
149
150 if(fgUseESDTree && fESDTree == 0)
151 throw(eH + "ESDTree not initialized.");
152
153 Int_t maxEvent = 0;
154 if(fgUseRunLoader)
155 maxEvent = fRunLoader->GetNumberOfEvents() - 1;
156 else if(fgUseESDTree)
157 maxEvent = fESDTree->GetEntries() - 1;
158
159 if(event < 0 || event > maxEvent)
160 throw(eH + Form("event %d not present, available range [%d, %d].",
161 event, 0, maxEvent));
162
163 DestroyElements();
164 fEventId = event;
165 SetName(Form("Event %d", fEventId));
166 UpdateItems();
167
168 if(fgUseRunLoader) {
169 if(fRunLoader->GetEvent(fEventId) != 0)
170 throw(eH + "failed getting required event.");
171 }
172
173 if(fgUseESDTree) {
174 if(fESDTree->GetEntry(fEventId) <= 0)
175 throw(eH + "failed getting required event from ESD.");
176
177 if(fESDfriendTree != 0) {
178 if(fESDfriendTree->GetEntry(fEventId) <= 0)
179 throw(eH + "failed getting required event from ESDfriend.");
180
181 fESD->SetESDfriend(fESDfriend);
182 }
183 }
184}
185
5a5a1232 186void Event::Close()
187{
3aecaefc 188
5a5a1232 189}
190
191/**************************************************************************/
192/**************************************************************************/
193
194// Static convenience functions.
195
196AliRunLoader* Event::AssertRunLoader()
197{
198 static const Exc_t eH("Event::AssertRunLoader ");
199
200 if(gEvent == 0)
201 throw(eH + "ALICE event not ready.");
202 if(gEvent->fRunLoader == 0)
203 throw(eH + "AliRunLoader not initialised.");
204 return gEvent->fRunLoader;
205}
206
207AliESD* Event::AssertESD()
208{
209 static const Exc_t eH("Event::AssertESD ");
210
211 if(gEvent == 0)
212 throw(eH + "ALICE event not ready.");
213 if(gEvent->fESD == 0)
214 throw(eH + "AliESD not initialised.");
215 return gEvent->fESD;
216}
3aecaefc 217
218AliESDfriend* Event::AssertESDfriend()
219{
220 static const Exc_t eH("Event::AssertESDfriend ");
221
222 if(gEvent == 0)
223 throw(eH + "ALICE event not ready.");
224 if(gEvent->fESDfriend == 0)
225 throw(eH + "AliESDfriend not initialised.");
226 return gEvent->fESDfriend;
227}