]>
Commit | Line | Data |
---|---|---|
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 | ||
16 | using namespace Reve; | |
17 | using namespace Alieve; | |
18 | ||
19 | //______________________________________________________________________ | |
20 | // Event | |
21 | // | |
22 | ||
23 | ClassImp(Event) | |
24 | ||
25 | Event* Alieve::gEvent = 0; | |
26 | ||
753fdd1e | 27 | Bool_t Alieve::Event::fgUseRunLoader = kTRUE; |
28 | Bool_t Alieve::Event::fgUseESDTree = kTRUE; | |
29 | Bool_t Alieve::Event::fgAvoidExcOnOpen = kTRUE; | |
5a5a1232 | 30 | |
753fdd1e | 31 | void 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 | 55 | Event::Event() : |
265ecb21 | 56 | EventBase(), |
57 | ||
58 | fPath (), fEventId (0), | |
59 | fRunLoader (0), | |
60 | fESDFile (0), fESDTree (0), fESD (0), | |
61 | fESDfriendFile (0), fESDfriendTree (0), fESDfriend (0) | |
62 | {} | |
5a5a1232 | 63 | |
6f0b0040 | 64 | Event::Event(TString path, Int_t ev) : |
65 | EventBase("AliEVE Event"), | |
265ecb21 | 66 | |
67 | fPath (path), fEventId(ev), | |
68 | fRunLoader (0), | |
69 | fESDFile (0), fESDTree (0), fESD (0), | |
70 | fESDfriendFile (0), fESDfriendTree (0), fESDfriend (0) | |
5a5a1232 | 71 | { |
5a5a1232 | 72 | Open(); |
73 | } | |
74 | ||
75 | /**************************************************************************/ | |
76 | ||
77 | void Event::Open() | |
78 | { | |
79 | static const Exc_t eH("Event::Open "); | |
80 | ||
81 | gSystem->ExpandPathName(fPath); | |
82 | if(fPath[0] != '/') | |
83 | fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data()); | |
84 | ||
85 | if(fgUseRunLoader) { | |
86 | TString ga_path(Form("%s/galice.root", fPath.Data())); | |
753fdd1e | 87 | if(gSystem->AccessPathName(ga_path, kReadPermission)) { |
88 | if (fgAvoidExcOnOpen) { | |
89 | Warning(eH, "RunLoader not initialized."); | |
90 | goto end_run_loader; | |
91 | } else { | |
92 | throw(eH + "can not read '" + ga_path + "'."); | |
93 | } | |
94 | } | |
5a5a1232 | 95 | fRunLoader = AliRunLoader::Open(ga_path); |
96 | if(!fRunLoader) | |
97 | throw(eH + "failed opening ALICE run loader from '" + ga_path + "'."); | |
98 | { | |
99 | TString alice_path = fPath + "/"; | |
100 | fRunLoader->SetDirName(alice_path); | |
101 | } | |
1eaa5849 | 102 | if(fRunLoader->LoadgAlice() != 0) |
5a5a1232 | 103 | throw(eH + "failed loading gAlice."); |
cf94c7c2 | 104 | if(fRunLoader->LoadHeader() != 0) |
105 | throw(eH + "failed loading header."); | |
5a5a1232 | 106 | |
1eaa5849 | 107 | if(fRunLoader->GetEvent(fEventId) != 0) |
5a5a1232 | 108 | throw(eH + "failed getting required event."); |
5a5a1232 | 109 | } |
753fdd1e | 110 | end_run_loader: |
5a5a1232 | 111 | |
112 | if(fgUseESDTree) { | |
113 | TString p(Form("%s/AliESDs.root", fPath.Data())); | |
753fdd1e | 114 | if(gSystem->AccessPathName(p, kReadPermission)) { |
115 | if (fgAvoidExcOnOpen) { | |
116 | Warning(eH, "ESD not initialized."); | |
117 | goto end_esd_loader; | |
118 | } else { | |
119 | throw(eH + "can not read '" + p + "'."); | |
120 | } | |
121 | } | |
5a5a1232 | 122 | fESDFile = new TFile(p); |
123 | if(fESDFile->IsZombie()) { | |
124 | delete fESDFile; fESDFile = 0; | |
125 | throw(eH + "failed opening ALICE ESD from '" + p + "'."); | |
126 | } | |
127 | ||
128 | fESDTree = (TTree*) fESDFile->Get("esdTree"); | |
129 | if(fESDTree == 0) | |
130 | throw(eH + "failed getting the esdTree."); | |
131 | fESDTree->SetBranchAddress("ESD", &fESD); | |
132 | if(fESDTree->GetEntry(fEventId) <= 0) | |
3aecaefc | 133 | throw(eH + "failed getting required event from ESD."); |
134 | ||
135 | // Check if ESDfriends exists and load it | |
136 | p = Form("%s/AliESDfriends.root", fPath.Data()); | |
137 | if(gSystem->AccessPathName(p, kReadPermission) == kFALSE) { | |
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 | ||
151 | fESD->SetESDfriend(fESDfriend); | |
152 | } | |
5a5a1232 | 153 | } |
753fdd1e | 154 | end_esd_loader: |
5a5a1232 | 155 | |
1eaa5849 | 156 | SetName(Form("Event %d", fEventId)); |
5a5a1232 | 157 | SetTitle(fPath); |
158 | } | |
159 | ||
1eaa5849 | 160 | void Event::GotoEvent(Int_t event) |
161 | { | |
162 | static const Exc_t eH("Event::GotoEvent "); | |
163 | ||
1eaa5849 | 164 | Int_t maxEvent = 0; |
753fdd1e | 165 | if(fRunLoader) |
1eaa5849 | 166 | maxEvent = fRunLoader->GetNumberOfEvents() - 1; |
753fdd1e | 167 | else if(fESDTree) |
1eaa5849 | 168 | maxEvent = fESDTree->GetEntries() - 1; |
753fdd1e | 169 | else |
170 | throw(eH + "neither RunLoader nor ESD loaded."); | |
1eaa5849 | 171 | |
172 | if(event < 0 || event > maxEvent) | |
173 | throw(eH + Form("event %d not present, available range [%d, %d].", | |
174 | event, 0, maxEvent)); | |
175 | ||
176 | DestroyElements(); | |
177 | fEventId = event; | |
178 | SetName(Form("Event %d", fEventId)); | |
179 | UpdateItems(); | |
180 | ||
753fdd1e | 181 | if(fRunLoader) { |
1eaa5849 | 182 | if(fRunLoader->GetEvent(fEventId) != 0) |
183 | throw(eH + "failed getting required event."); | |
184 | } | |
185 | ||
753fdd1e | 186 | if(fESDTree) { |
1eaa5849 | 187 | if(fESDTree->GetEntry(fEventId) <= 0) |
188 | throw(eH + "failed getting required event from ESD."); | |
189 | ||
190 | if(fESDfriendTree != 0) { | |
191 | if(fESDfriendTree->GetEntry(fEventId) <= 0) | |
192 | throw(eH + "failed getting required event from ESDfriend."); | |
193 | ||
194 | fESD->SetESDfriend(fESDfriend); | |
195 | } | |
196 | } | |
197 | } | |
198 | ||
5a5a1232 | 199 | void Event::Close() |
200 | { | |
3aecaefc | 201 | |
5a5a1232 | 202 | } |
203 | ||
204 | /**************************************************************************/ | |
205 | /**************************************************************************/ | |
206 | ||
207 | // Static convenience functions. | |
208 | ||
209 | AliRunLoader* Event::AssertRunLoader() | |
210 | { | |
211 | static const Exc_t eH("Event::AssertRunLoader "); | |
212 | ||
213 | if(gEvent == 0) | |
214 | throw(eH + "ALICE event not ready."); | |
215 | if(gEvent->fRunLoader == 0) | |
216 | throw(eH + "AliRunLoader not initialised."); | |
217 | return gEvent->fRunLoader; | |
218 | } | |
219 | ||
220 | AliESD* Event::AssertESD() | |
221 | { | |
222 | static const Exc_t eH("Event::AssertESD "); | |
223 | ||
224 | if(gEvent == 0) | |
225 | throw(eH + "ALICE event not ready."); | |
226 | if(gEvent->fESD == 0) | |
227 | throw(eH + "AliESD not initialised."); | |
228 | return gEvent->fESD; | |
229 | } | |
3aecaefc | 230 | |
231 | AliESDfriend* Event::AssertESDfriend() | |
232 | { | |
233 | static const Exc_t eH("Event::AssertESDfriend "); | |
234 | ||
235 | if(gEvent == 0) | |
236 | throw(eH + "ALICE event not ready."); | |
237 | if(gEvent->fESDfriend == 0) | |
238 | throw(eH + "AliESDfriend not initialised."); | |
239 | return gEvent->fESDfriend; | |
240 | } |