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