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