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