In TrackGL::ProcessSelection(): make model-track emit Clicked signal.
[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
753fdd1e 27Bool_t Alieve::Event::fgUseRunLoader = kTRUE;
28Bool_t Alieve::Event::fgUseESDTree = kTRUE;
29Bool_t Alieve::Event::fgAvoidExcOnOpen = kTRUE;
5a5a1232 30
753fdd1e 31void Event::Initialize(Bool_t use_runloader, Bool_t use_esd,
32 Bool_t avoid_exc_on_open)
5a5a1232 33{
34 static const Exc_t eH("Event::Initialize ");
35
753fdd1e 36 fgUseRunLoader = use_runloader;
37 fgUseESDTree = use_esd;
38 fgAvoidExcOnOpen = avoid_exc_on_open;
5a5a1232 39
40 /*
41 if(fgUseRunLoader == false && fgUseESDTree == false)
42 throw(eH + "should use at least one data source.");
43
44 if(fgUseRunLoader) {
45 AssertMacro("loadlibs.C");
46 }
47 else if(fgUseESDTree) {
48 gSystem->Load("libESD.so");
49 }
50 */
51}
52
53/**************************************************************************/
54
6f0b0040 55Event::Event() :
265ecb21 56 EventBase(),
57
58 fPath (), fEventId (0),
59 fRunLoader (0),
60 fESDFile (0), fESDTree (0), fESD (0),
2cea771a 61 /* fESDfriendFile (0), fESDfriendTree (0), */
62 fESDfriend (0), fESDfriendExists(kFALSE)
265ecb21 63{}
5a5a1232 64
6f0b0040 65Event::Event(TString path, Int_t ev) :
66 EventBase("AliEVE Event"),
265ecb21 67
68 fPath (path), fEventId(ev),
69 fRunLoader (0),
70 fESDFile (0), fESDTree (0), fESD (0),
2cea771a 71 /* fESDfriendFile (0), fESDfriendTree (0), */
72 fESDfriend (0), fESDfriendExists(kFALSE)
5a5a1232 73{
5a5a1232 74 Open();
75}
76
77/**************************************************************************/
78
79void Event::Open()
80{
81 static const Exc_t eH("Event::Open ");
82
83 gSystem->ExpandPathName(fPath);
84 if(fPath[0] != '/')
85 fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data());
86
87 if(fgUseRunLoader) {
88 TString ga_path(Form("%s/galice.root", fPath.Data()));
753fdd1e 89 if(gSystem->AccessPathName(ga_path, kReadPermission)) {
90 if (fgAvoidExcOnOpen) {
91 Warning(eH, "RunLoader not initialized.");
92 goto end_run_loader;
93 } else {
94 throw(eH + "can not read '" + ga_path + "'.");
95 }
96 }
5a5a1232 97 fRunLoader = AliRunLoader::Open(ga_path);
98 if(!fRunLoader)
99 throw(eH + "failed opening ALICE run loader from '" + ga_path + "'.");
100 {
101 TString alice_path = fPath + "/";
102 fRunLoader->SetDirName(alice_path);
103 }
1eaa5849 104 if(fRunLoader->LoadgAlice() != 0)
5a5a1232 105 throw(eH + "failed loading gAlice.");
cf94c7c2 106 if(fRunLoader->LoadHeader() != 0)
107 throw(eH + "failed loading header.");
5a5a1232 108
1eaa5849 109 if(fRunLoader->GetEvent(fEventId) != 0)
5a5a1232 110 throw(eH + "failed getting required event.");
5a5a1232 111 }
753fdd1e 112end_run_loader:
5a5a1232 113
114 if(fgUseESDTree) {
115 TString p(Form("%s/AliESDs.root", fPath.Data()));
753fdd1e 116 if(gSystem->AccessPathName(p, kReadPermission)) {
117 if (fgAvoidExcOnOpen) {
118 Warning(eH, "ESD not initialized.");
119 goto end_esd_loader;
120 } else {
121 throw(eH + "can not read '" + p + "'.");
122 }
123 }
5a5a1232 124 fESDFile = new TFile(p);
125 if(fESDFile->IsZombie()) {
126 delete fESDFile; fESDFile = 0;
127 throw(eH + "failed opening ALICE ESD from '" + p + "'.");
128 }
129
130 fESDTree = (TTree*) fESDFile->Get("esdTree");
131 if(fESDTree == 0)
132 throw(eH + "failed getting the esdTree.");
133 fESDTree->SetBranchAddress("ESD", &fESD);
3aecaefc 134
938142f5 135 // Check if ESDfriends exists and attach the branch
3aecaefc 136 p = Form("%s/AliESDfriends.root", fPath.Data());
137 if(gSystem->AccessPathName(p, kReadPermission) == kFALSE) {
2cea771a 138 //fESDfriendFile = new TFile(p);
139 //if(fESDfriendFile->IsZombie()) {
140 //delete fESDfriendFile; fESDfriendFile = 0;
141 //throw(eH + "failed opening ALICE ESDfriend from '" + p + "'.");
142 //}
143
144 //fESDfriendTree = (TTree*) fESDfriendFile->Get("esdFriendTree");
145 //if(fESDfriendTree == 0)
146 // throw(eH + "failed getting the esdFriendTree.");
147 //fESDfriendTree->SetBranchAddress("ESDfriend", &fESDfriend);
148 //if(fESDfriendTree->GetEntry(fEventId) <= 0)
149 //throw(eH + "failed getting required event from ESDfriend.");
150
2cea771a 151 fESDfriendExists = kTRUE;
152 fESDTree->SetBranchStatus ("ESDfriend*", 1);
153 fESDTree->SetBranchAddress("ESDfriend.", &fESDfriend);
938142f5 154
3aecaefc 155 }
938142f5 156
157 if(fESDTree->GetEntry(fEventId) <= 0)
158 throw(eH + "failed getting required event from ESD.");
159
160 if (fESDfriendExists)
161 fESD->SetESDfriend(fESDfriend);
5a5a1232 162 }
753fdd1e 163end_esd_loader:
5a5a1232 164
1eaa5849 165 SetName(Form("Event %d", fEventId));
5a5a1232 166 SetTitle(fPath);
167}
168
1eaa5849 169void Event::GotoEvent(Int_t event)
170{
171 static const Exc_t eH("Event::GotoEvent ");
172
1eaa5849 173 Int_t maxEvent = 0;
753fdd1e 174 if(fRunLoader)
1eaa5849 175 maxEvent = fRunLoader->GetNumberOfEvents() - 1;
753fdd1e 176 else if(fESDTree)
1eaa5849 177 maxEvent = fESDTree->GetEntries() - 1;
753fdd1e 178 else
179 throw(eH + "neither RunLoader nor ESD loaded.");
1eaa5849 180
181 if(event < 0 || event > maxEvent)
182 throw(eH + Form("event %d not present, available range [%d, %d].",
183 event, 0, maxEvent));
184
185 DestroyElements();
186 fEventId = event;
187 SetName(Form("Event %d", fEventId));
188 UpdateItems();
189
753fdd1e 190 if(fRunLoader) {
1eaa5849 191 if(fRunLoader->GetEvent(fEventId) != 0)
192 throw(eH + "failed getting required event.");
193 }
194
753fdd1e 195 if(fESDTree) {
2cea771a 196 delete fESD; fESD = 0;
197 delete fESDfriend; fESDfriend = 0;
198
1eaa5849 199 if(fESDTree->GetEntry(fEventId) <= 0)
200 throw(eH + "failed getting required event from ESD.");
201
2cea771a 202 //if(fESDfriendTree != 0) {
203 // if(fESDfriendTree->GetEntry(fEventId) <= 0)
204 // throw(eH + "failed getting required event from ESDfriend.");
1eaa5849 205
2cea771a 206 if (fESDfriendExists)
1eaa5849 207 fESD->SetESDfriend(fESDfriend);
1eaa5849 208 }
209}
210
5a5a1232 211void Event::Close()
212{
2cea771a 213 if (fESDTree) {
214 delete fESD; fESD = 0;
215 delete fESDfriend; fESDfriend = 0;
216
217 delete fESDTree; fESDTree = 0;
218 delete fESDFile; fESDFile = 0;
219 }
5a5a1232 220}
221
222/**************************************************************************/
223/**************************************************************************/
224
225// Static convenience functions.
226
227AliRunLoader* Event::AssertRunLoader()
228{
229 static const Exc_t eH("Event::AssertRunLoader ");
230
231 if(gEvent == 0)
232 throw(eH + "ALICE event not ready.");
233 if(gEvent->fRunLoader == 0)
234 throw(eH + "AliRunLoader not initialised.");
235 return gEvent->fRunLoader;
236}
237
238AliESD* Event::AssertESD()
239{
240 static const Exc_t eH("Event::AssertESD ");
241
242 if(gEvent == 0)
243 throw(eH + "ALICE event not ready.");
244 if(gEvent->fESD == 0)
245 throw(eH + "AliESD not initialised.");
246 return gEvent->fESD;
247}
3aecaefc 248
249AliESDfriend* Event::AssertESDfriend()
250{
251 static const Exc_t eH("Event::AssertESDfriend ");
252
253 if(gEvent == 0)
254 throw(eH + "ALICE event not ready.");
255 if(gEvent->fESDfriend == 0)
256 throw(eH + "AliESDfriend not initialised.");
257 return gEvent->fESDfriend;
258}