]>
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 | } | |
98 | if(fRunLoader->LoadgAlice() != 0) { | |
99 | throw(eH + "failed loading gAlice."); | |
100 | } | |
101 | ||
102 | if(fRunLoader->GetEvent(fEventId) != 0) { | |
103 | throw(eH + "failed getting required event."); | |
104 | } | |
105 | } | |
106 | ||
107 | if(fgUseESDTree) { | |
108 | TString p(Form("%s/AliESDs.root", fPath.Data())); | |
3aecaefc | 109 | if(gSystem->AccessPathName(p, kReadPermission)) |
110 | throw(eH + "can not read '" + p + "'."); | |
5a5a1232 | 111 | fESDFile = new TFile(p); |
112 | if(fESDFile->IsZombie()) { | |
113 | delete fESDFile; fESDFile = 0; | |
114 | throw(eH + "failed opening ALICE ESD from '" + p + "'."); | |
115 | } | |
116 | ||
117 | fESDTree = (TTree*) fESDFile->Get("esdTree"); | |
118 | if(fESDTree == 0) | |
119 | throw(eH + "failed getting the esdTree."); | |
120 | fESDTree->SetBranchAddress("ESD", &fESD); | |
121 | if(fESDTree->GetEntry(fEventId) <= 0) | |
3aecaefc | 122 | throw(eH + "failed getting required event from ESD."); |
123 | ||
124 | // Check if ESDfriends exists and load it | |
125 | p = Form("%s/AliESDfriends.root", fPath.Data()); | |
126 | if(gSystem->AccessPathName(p, kReadPermission) == kFALSE) { | |
127 | fESDfriendFile = new TFile(p); | |
128 | if(fESDfriendFile->IsZombie()) { | |
129 | delete fESDfriendFile; fESDfriendFile = 0; | |
130 | throw(eH + "failed opening ALICE ESDfriend from '" + p + "'."); | |
131 | } | |
132 | ||
133 | fESDfriendTree = (TTree*) fESDfriendFile->Get("esdFriendTree"); | |
134 | if(fESDfriendTree == 0) | |
135 | throw(eH + "failed getting the esdFriendTree."); | |
136 | fESDfriendTree->SetBranchAddress("ESDfriend", &fESDfriend); | |
137 | if(fESDfriendTree->GetEntry(fEventId) <= 0) | |
138 | throw(eH + "failed getting required event from ESDfriend."); | |
139 | ||
140 | fESD->SetESDfriend(fESDfriend); | |
141 | } | |
5a5a1232 | 142 | } |
143 | ||
144 | SetName(Form("Event%d", fEventId)); | |
145 | SetTitle(fPath); | |
146 | } | |
147 | ||
148 | void Event::Close() | |
149 | { | |
3aecaefc | 150 | |
5a5a1232 | 151 | } |
152 | ||
153 | /**************************************************************************/ | |
154 | /**************************************************************************/ | |
155 | ||
156 | // Static convenience functions. | |
157 | ||
158 | AliRunLoader* Event::AssertRunLoader() | |
159 | { | |
160 | static const Exc_t eH("Event::AssertRunLoader "); | |
161 | ||
162 | if(gEvent == 0) | |
163 | throw(eH + "ALICE event not ready."); | |
164 | if(gEvent->fRunLoader == 0) | |
165 | throw(eH + "AliRunLoader not initialised."); | |
166 | return gEvent->fRunLoader; | |
167 | } | |
168 | ||
169 | AliESD* Event::AssertESD() | |
170 | { | |
171 | static const Exc_t eH("Event::AssertESD "); | |
172 | ||
173 | if(gEvent == 0) | |
174 | throw(eH + "ALICE event not ready."); | |
175 | if(gEvent->fESD == 0) | |
176 | throw(eH + "AliESD not initialised."); | |
177 | return gEvent->fESD; | |
178 | } | |
3aecaefc | 179 | |
180 | AliESDfriend* Event::AssertESDfriend() | |
181 | { | |
182 | static const Exc_t eH("Event::AssertESDfriend "); | |
183 | ||
184 | if(gEvent == 0) | |
185 | throw(eH + "ALICE event not ready."); | |
186 | if(gEvent->fESDfriend == 0) | |
187 | throw(eH + "AliESDfriend not initialised."); | |
188 | return gEvent->fESDfriend; | |
189 | } |