]>
Commit | Line | Data |
---|---|---|
5a5a1232 | 1 | // $Header$ |
2 | ||
3 | #include "EventAlieve.h" | |
4 | #include <Reve/Reve.h> | |
d9e0d6c5 | 5 | #include <Reve/RGTopFrame.h> |
5a5a1232 | 6 | |
7 | #include <AliRunLoader.h> | |
93845f6c | 8 | #include <AliRun.h> |
5a5a1232 | 9 | #include <AliESD.h> |
3aecaefc | 10 | #include <AliESDfriend.h> |
93845f6c | 11 | #include <AliMagFMaps.h> |
5a5a1232 | 12 | |
13 | #include <TFile.h> | |
14 | #include <TTree.h> | |
90fa773e | 15 | #include <TObjString.h> |
5a5a1232 | 16 | |
17 | #include <TROOT.h> | |
18 | #include <TSystem.h> | |
90fa773e | 19 | #include <TCint.h> |
5a5a1232 | 20 | |
21 | using namespace Reve; | |
22 | using namespace Alieve; | |
23 | ||
24 | //______________________________________________________________________ | |
25 | // Event | |
26 | // | |
4852ff6f | 27 | // Provide interface for loading and navigating standard AliRoot data |
28 | // (AliRunLoader) and ESDs. | |
29 | // | |
30 | // Missing support for raw-data. For now this is handled individually | |
31 | // by each sub-detector. | |
32 | // | |
5a5a1232 | 33 | |
34 | ClassImp(Event) | |
35 | ||
36 | Event* Alieve::gEvent = 0; | |
37 | ||
753fdd1e | 38 | Bool_t Alieve::Event::fgUseRunLoader = kTRUE; |
39 | Bool_t Alieve::Event::fgUseESDTree = kTRUE; | |
40 | Bool_t Alieve::Event::fgAvoidExcOnOpen = kTRUE; | |
5a5a1232 | 41 | |
93845f6c | 42 | AliMagF* Alieve::Event::fgMagField = 0; |
43 | ||
44 | ||
753fdd1e | 45 | void Event::Initialize(Bool_t use_runloader, Bool_t use_esd, |
46 | Bool_t avoid_exc_on_open) | |
5a5a1232 | 47 | { |
48 | static const Exc_t eH("Event::Initialize "); | |
49 | ||
753fdd1e | 50 | fgUseRunLoader = use_runloader; |
51 | fgUseESDTree = use_esd; | |
52 | fgAvoidExcOnOpen = avoid_exc_on_open; | |
5a5a1232 | 53 | |
54 | /* | |
55 | if(fgUseRunLoader == false && fgUseESDTree == false) | |
56 | throw(eH + "should use at least one data source."); | |
57 | ||
58 | if(fgUseRunLoader) { | |
59 | AssertMacro("loadlibs.C"); | |
60 | } | |
61 | else if(fgUseESDTree) { | |
62 | gSystem->Load("libESD.so"); | |
63 | } | |
64 | */ | |
65 | } | |
66 | ||
67 | /**************************************************************************/ | |
68 | ||
6f0b0040 | 69 | Event::Event() : |
265ecb21 | 70 | EventBase(), |
71 | ||
72 | fPath (), fEventId (0), | |
73 | fRunLoader (0), | |
90fa773e | 74 | fESDFile (0), fESDTree (0), fESD (0), |
2cea771a | 75 | fESDfriend (0), fESDfriendExists(kFALSE) |
265ecb21 | 76 | {} |
5a5a1232 | 77 | |
6f0b0040 | 78 | Event::Event(TString path, Int_t ev) : |
79 | EventBase("AliEVE Event"), | |
265ecb21 | 80 | |
90fa773e | 81 | fPath (path), fEventId(-1), |
265ecb21 | 82 | fRunLoader (0), |
90fa773e | 83 | fESDFile (0), fESDTree (0), fESD (0), |
2cea771a | 84 | fESDfriend (0), fESDfriendExists(kFALSE) |
5a5a1232 | 85 | { |
5a5a1232 | 86 | Open(); |
90fa773e | 87 | if (ev >= 0) GotoEvent(ev); |
5a5a1232 | 88 | } |
89 | ||
90 | /**************************************************************************/ | |
91 | ||
92 | void Event::Open() | |
93 | { | |
94 | static const Exc_t eH("Event::Open "); | |
95 | ||
96 | gSystem->ExpandPathName(fPath); | |
97 | if(fPath[0] != '/') | |
98 | fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data()); | |
99 | ||
90fa773e | 100 | if(fgUseRunLoader) |
101 | { | |
5a5a1232 | 102 | TString ga_path(Form("%s/galice.root", fPath.Data())); |
90fa773e | 103 | if(gSystem->AccessPathName(ga_path, kReadPermission)) |
104 | { | |
753fdd1e | 105 | if (fgAvoidExcOnOpen) { |
106 | Warning(eH, "RunLoader not initialized."); | |
107 | goto end_run_loader; | |
108 | } else { | |
109 | throw(eH + "can not read '" + ga_path + "'."); | |
110 | } | |
111 | } | |
5a5a1232 | 112 | fRunLoader = AliRunLoader::Open(ga_path); |
113 | if(!fRunLoader) | |
114 | throw(eH + "failed opening ALICE run loader from '" + ga_path + "'."); | |
115 | { | |
116 | TString alice_path = fPath + "/"; | |
117 | fRunLoader->SetDirName(alice_path); | |
118 | } | |
1eaa5849 | 119 | if(fRunLoader->LoadgAlice() != 0) |
5a5a1232 | 120 | throw(eH + "failed loading gAlice."); |
cf94c7c2 | 121 | if(fRunLoader->LoadHeader() != 0) |
122 | throw(eH + "failed loading header."); | |
5a5a1232 | 123 | } |
753fdd1e | 124 | end_run_loader: |
5a5a1232 | 125 | |
90fa773e | 126 | if(fgUseESDTree) |
127 | { | |
5a5a1232 | 128 | TString p(Form("%s/AliESDs.root", fPath.Data())); |
90fa773e | 129 | if(gSystem->AccessPathName(p, kReadPermission)) |
130 | { | |
753fdd1e | 131 | if (fgAvoidExcOnOpen) { |
132 | Warning(eH, "ESD not initialized."); | |
133 | goto end_esd_loader; | |
134 | } else { | |
135 | throw(eH + "can not read '" + p + "'."); | |
136 | } | |
137 | } | |
5a5a1232 | 138 | fESDFile = new TFile(p); |
139 | if(fESDFile->IsZombie()) { | |
140 | delete fESDFile; fESDFile = 0; | |
141 | throw(eH + "failed opening ALICE ESD from '" + p + "'."); | |
142 | } | |
143 | ||
144 | fESDTree = (TTree*) fESDFile->Get("esdTree"); | |
145 | if(fESDTree == 0) | |
146 | throw(eH + "failed getting the esdTree."); | |
147 | fESDTree->SetBranchAddress("ESD", &fESD); | |
3aecaefc | 148 | |
938142f5 | 149 | // Check if ESDfriends exists and attach the branch |
3aecaefc | 150 | p = Form("%s/AliESDfriends.root", fPath.Data()); |
90fa773e | 151 | if(gSystem->AccessPathName(p, kReadPermission) == kFALSE) |
152 | { | |
2cea771a | 153 | fESDfriendExists = kTRUE; |
154 | fESDTree->SetBranchStatus ("ESDfriend*", 1); | |
155 | fESDTree->SetBranchAddress("ESDfriend.", &fESDfriend); | |
3aecaefc | 156 | } |
5a5a1232 | 157 | } |
158 | ||
90fa773e | 159 | end_esd_loader: |
1eaa5849 | 160 | SetName(Form("Event %d", fEventId)); |
5a5a1232 | 161 | SetTitle(fPath); |
162 | } | |
163 | ||
1eaa5849 | 164 | void Event::GotoEvent(Int_t event) |
165 | { | |
166 | static const Exc_t eH("Event::GotoEvent "); | |
167 | ||
1eaa5849 | 168 | Int_t maxEvent = 0; |
753fdd1e | 169 | if(fRunLoader) |
1eaa5849 | 170 | maxEvent = fRunLoader->GetNumberOfEvents() - 1; |
753fdd1e | 171 | else if(fESDTree) |
1eaa5849 | 172 | maxEvent = fESDTree->GetEntries() - 1; |
753fdd1e | 173 | else |
174 | throw(eH + "neither RunLoader nor ESD loaded."); | |
1eaa5849 | 175 | |
176 | if(event < 0 || event > maxEvent) | |
177 | throw(eH + Form("event %d not present, available range [%d, %d].", | |
178 | event, 0, maxEvent)); | |
179 | ||
d9e0d6c5 | 180 | RGTopFrame::RedrawDisabler rd(gReve); |
541e09b4 | 181 | gReve->Redraw3D(kFALSE, kTRUE); // Enforce drop of all logicals. |
d9e0d6c5 | 182 | |
1eaa5849 | 183 | DestroyElements(); |
184 | fEventId = event; | |
185 | SetName(Form("Event %d", fEventId)); | |
186 | UpdateItems(); | |
187 | ||
753fdd1e | 188 | if(fRunLoader) { |
1eaa5849 | 189 | if(fRunLoader->GetEvent(fEventId) != 0) |
190 | throw(eH + "failed getting required event."); | |
191 | } | |
192 | ||
753fdd1e | 193 | if(fESDTree) { |
2cea771a | 194 | delete fESD; fESD = 0; |
195 | delete fESDfriend; fESDfriend = 0; | |
196 | ||
1eaa5849 | 197 | if(fESDTree->GetEntry(fEventId) <= 0) |
198 | throw(eH + "failed getting required event from ESD."); | |
199 | ||
2cea771a | 200 | if (fESDfriendExists) |
1eaa5849 | 201 | fESD->SetESDfriend(fESDfriend); |
1eaa5849 | 202 | } |
90fa773e | 203 | |
204 | AfterNewEventLoaded(); | |
1eaa5849 | 205 | } |
206 | ||
5a5a1232 | 207 | void Event::Close() |
208 | { | |
2cea771a | 209 | if (fESDTree) { |
210 | delete fESD; fESD = 0; | |
211 | delete fESDfriend; fESDfriend = 0; | |
212 | ||
213 | delete fESDTree; fESDTree = 0; | |
214 | delete fESDFile; fESDFile = 0; | |
215 | } | |
5a5a1232 | 216 | } |
217 | ||
90fa773e | 218 | /**************************************************************************/ |
219 | ||
220 | void Event::AfterNewEventLoaded() | |
221 | { | |
222 | TIter next(&fNewEventCommands); | |
223 | TObject* o; | |
224 | while ((o = next())) { | |
225 | TObjString* s = dynamic_cast<TObjString*>(o); | |
226 | if (s) | |
227 | gInterpreter->ProcessLine(s->String()); | |
228 | } | |
229 | } | |
230 | ||
231 | void Event::AddNewEventCommand(const Text_t* cmd) | |
232 | { | |
233 | fNewEventCommands.Add(new TObjString(cmd)); | |
234 | } | |
235 | ||
5a5a1232 | 236 | /**************************************************************************/ |
237 | /**************************************************************************/ | |
238 | ||
239 | // Static convenience functions. | |
240 | ||
241 | AliRunLoader* Event::AssertRunLoader() | |
242 | { | |
243 | static const Exc_t eH("Event::AssertRunLoader "); | |
244 | ||
245 | if(gEvent == 0) | |
246 | throw(eH + "ALICE event not ready."); | |
247 | if(gEvent->fRunLoader == 0) | |
248 | throw(eH + "AliRunLoader not initialised."); | |
249 | return gEvent->fRunLoader; | |
250 | } | |
251 | ||
252 | AliESD* Event::AssertESD() | |
253 | { | |
254 | static const Exc_t eH("Event::AssertESD "); | |
255 | ||
256 | if(gEvent == 0) | |
257 | throw(eH + "ALICE event not ready."); | |
258 | if(gEvent->fESD == 0) | |
259 | throw(eH + "AliESD not initialised."); | |
260 | return gEvent->fESD; | |
261 | } | |
3aecaefc | 262 | |
263 | AliESDfriend* Event::AssertESDfriend() | |
264 | { | |
265 | static const Exc_t eH("Event::AssertESDfriend "); | |
266 | ||
267 | if(gEvent == 0) | |
268 | throw(eH + "ALICE event not ready."); | |
269 | if(gEvent->fESDfriend == 0) | |
270 | throw(eH + "AliESDfriend not initialised."); | |
271 | return gEvent->fESDfriend; | |
272 | } | |
93845f6c | 273 | |
274 | AliMagF* Event::AssertMagField() | |
275 | { | |
276 | if (fgMagField == 0) | |
277 | { | |
278 | if (gEvent && gEvent->fRunLoader && gEvent->fRunLoader->GetAliRun()) | |
279 | fgMagField = gEvent->fRunLoader->GetAliRun()->Field(); | |
280 | else | |
281 | fgMagField = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG); | |
282 | } | |
283 | return fgMagField; | |
284 | } |