e9a38ea3 |
1 | // $Header$ |
2 | |
3 | #include "TPCLoader.h" |
4 | #include "TPCData.h" |
5 | #include <Alieve/TPCSector2D.h> |
6 | #include <Alieve/TPCSector3D.h> |
84aff7a4 |
7 | #include <TEveManager.h> |
8 | #include <TEveGedEditor.h> |
e9a38ea3 |
9 | |
10 | #include <AliRawReaderRoot.h> |
11 | #include <AliTPCRawStream.h> |
12 | |
13 | #include <TSystem.h> |
e9a38ea3 |
14 | using namespace Alieve; |
15 | |
16 | //______________________________________________________________________ |
17 | // TPCLoader |
18 | // |
19 | |
20 | ClassImp(TPCLoader) |
21 | |
22 | TPCLoader::TPCLoader(const Text_t* n, const Text_t* t) : |
84aff7a4 |
23 | TEveElementList(n, t), |
e9a38ea3 |
24 | |
265ecb21 |
25 | fFile(), |
e9a38ea3 |
26 | fEvent(-1), |
8f50aad8 |
27 | fDoubleSR(kFALSE), |
e9a38ea3 |
28 | |
61eeeb0e |
29 | fTPCEquipementMap(), |
e9a38ea3 |
30 | fReader(0), |
31 | fData(0), |
32 | |
33 | fSec2Ds(36), |
e7c8d6ca |
34 | fSec3Ds(36), |
35 | |
265ecb21 |
36 | fSetInitSectorParams(kFALSE), |
b1e0b894 |
37 | fInitMinTime(0), fInitMaxTime(460), fInitThreshold(5), fInitMaxVal(128) |
38 | { |
39 | fData = new TPCData; |
40 | } |
e9a38ea3 |
41 | |
42 | TPCLoader::~TPCLoader() |
43 | { |
44 | delete fReader; |
45 | delete fData; |
46 | } |
47 | |
48 | /**************************************************************************/ |
49 | |
84aff7a4 |
50 | void TPCLoader::RemoveElementLocal(TEveElement* el) |
4a378d74 |
51 | { |
52 | for(Int_t i=0; i<36; ++i) { |
53 | if(fSec2Ds[i] == el) fSec2Ds[i] = 0; |
54 | if(fSec3Ds[i] == el) fSec3Ds[i] = 0; |
55 | } |
4a378d74 |
56 | } |
57 | |
32e219c2 |
58 | void TPCLoader::RemoveElementsLocal() |
4a378d74 |
59 | { |
60 | for(Int_t i=0; i<36; ++i) { |
61 | fSec2Ds[i] = 0; |
62 | fSec3Ds[i] = 0; |
63 | } |
4a378d74 |
64 | } |
65 | |
66 | /**************************************************************************/ |
e9a38ea3 |
67 | |
68 | void TPCLoader::SetData(TPCData* d) |
69 | { |
70 | delete fData; |
71 | fData = d; |
72 | } |
73 | |
74 | /**************************************************************************/ |
75 | |
76 | void TPCLoader::OpenFile() |
77 | { |
84aff7a4 |
78 | static const TEveException eH("TPCLoader::OpenFile "); |
e9a38ea3 |
79 | |
80 | if(gSystem->AccessPathName(fFile, kReadPermission)) |
81 | throw(eH + "can not read '" + fFile + "'."); |
82 | |
b1e0b894 |
83 | fData->DeleteAllSectors(); |
e9a38ea3 |
84 | |
85 | delete fReader; |
86 | fReader = 0; |
87 | fEvent = -1; |
88 | |
89 | fReader = new AliRawReaderRoot(fFile); |
61eeeb0e |
90 | if(fTPCEquipementMap != "") |
91 | fReader->LoadEquipmentIdsMap |
92 | (gSystem->ExpandPathName(fTPCEquipementMap.Data())); |
e9a38ea3 |
93 | |
94 | NextEvent(); |
95 | LoadEvent(); |
42c8253f |
96 | UpdateSectors(kTRUE); |
e9a38ea3 |
97 | } |
98 | |
99 | void TPCLoader::LoadEvent() |
100 | { |
84aff7a4 |
101 | static const TEveException eH("TPCLoader::LoadEvent "); |
e9a38ea3 |
102 | |
103 | if(fReader == 0) |
104 | throw(eH + "data file not opened."); |
105 | |
106 | printf("Now loading event %d\n", fEvent); |
107 | fReader->Reset(); |
108 | AliTPCRawStream input(fReader); |
109 | input.SetOldRCUFormat(kTRUE); |
61eeeb0e |
110 | fReader->Select("TPC"); |
e9a38ea3 |
111 | |
112 | fData->DropAllSectors(); |
113 | fData->LoadRaw(input, kTRUE, kTRUE); |
114 | } |
115 | |
116 | void TPCLoader::NextEvent(Bool_t rewindOnEnd) |
117 | { |
84aff7a4 |
118 | static const TEveException eH("TPCLoader::NextEvent "); |
e9a38ea3 |
119 | |
120 | if(fReader == 0) |
121 | throw(eH + "data file not opened."); |
122 | |
123 | if(fReader->NextEvent() == kTRUE) { |
124 | ++fEvent; |
125 | } else { |
126 | if(fEvent == -1) |
127 | throw(eH + "no events available."); |
128 | if(rewindOnEnd) { |
129 | printf("Reached end of stream (event=%d), rewinding to first event.\n", fEvent); |
130 | fReader->RewindEvents(); |
131 | fReader->NextEvent(); |
132 | fEvent = 0; |
133 | } else { |
134 | throw(eH + "last event reached."); |
135 | } |
136 | } |
137 | } |
138 | |
139 | void TPCLoader::GotoEvent(Int_t event) |
140 | { |
84aff7a4 |
141 | static const TEveException eH("TPCLoader::GotoEvent "); |
e9a38ea3 |
142 | |
143 | if(fReader == 0) |
144 | throw(eH + "data file not opened."); |
145 | |
146 | if(event == fEvent) |
147 | return; |
148 | Bool_t checkEnd; |
149 | if(event < fEvent) { |
150 | fReader->RewindEvents(); |
151 | fEvent = -1; |
152 | checkEnd = kFALSE; |
153 | } else { |
154 | checkEnd = kTRUE; |
155 | } |
156 | do { |
157 | NextEvent(); |
158 | } while(fEvent != event && !(checkEnd == kTRUE && fEvent == 0)); |
159 | LoadEvent(); |
160 | UpdateSectors(); |
161 | } |
162 | |
42c8253f |
163 | void* TPCLoader::LoopEvent(TPCLoader* loader) |
164 | { |
165 | loader->NextEvent(); |
166 | loader->LoadEvent(); |
167 | loader->UpdateSectors(); |
84aff7a4 |
168 | if (gEve->GetEditor()->GetModel() == loader) |
169 | gEve->EditElement(loader); |
42c8253f |
170 | return 0; |
171 | } |
172 | |
e9a38ea3 |
173 | /**************************************************************************/ |
174 | |
42c8253f |
175 | void TPCLoader::UpdateSectors(Bool_t dropNonPresent) |
e9a38ea3 |
176 | { |
84aff7a4 |
177 | gEve->DisableRedraw(); |
42c8253f |
178 | for(Int_t i=0; i<=35; ++i) |
179 | { |
180 | TPCSectorData* sd = fData->GetSectorData(i); |
181 | |
182 | // 2D sectors |
183 | if(fSec2Ds[i] != 0) |
184 | { |
185 | if (dropNonPresent && sd == 0) { |
84aff7a4 |
186 | gEve->RemoveElement(fSec2Ds[i], this); |
42c8253f |
187 | fSec2Ds[i] = 0; |
188 | } else { |
189 | fSec2Ds[i]->IncRTS(); |
32e219c2 |
190 | fSec2Ds[i]->ElementChanged(); |
42c8253f |
191 | } |
192 | } |
193 | else |
194 | { |
e9a38ea3 |
195 | if(sd != 0) { |
196 | TPCSector2D* s = new TPCSector2D(Form("Sector2D %d", i)); |
197 | fSec2Ds[i] = s; |
198 | s->SetSectorID(i); |
199 | s->SetDataSource(fData); |
8f50aad8 |
200 | |
201 | if(fDoubleSR) |
202 | s->SetMaxTime(1023); |
e9a38ea3 |
203 | |
e7c8d6ca |
204 | if(fSetInitSectorParams) { |
205 | s->SetMinTime(fInitMinTime); |
206 | s->SetMaxTime(fInitMaxTime); |
207 | s->SetThreshold(fInitThreshold); |
b1e0b894 |
208 | s->SetMaxVal(fInitMaxVal); |
e7c8d6ca |
209 | } |
75a20dc1 |
210 | |
601bca51 |
211 | s->SetAutoTrans(kTRUE); |
e9a38ea3 |
212 | s->SetFrameColor(36); |
213 | |
84aff7a4 |
214 | gEve->AddElement(s, this); |
e9a38ea3 |
215 | } |
216 | } |
217 | |
42c8253f |
218 | // 3D sectors |
219 | if(fSec3Ds[i] != 0) |
220 | { |
221 | if (dropNonPresent && sd == 0) { |
84aff7a4 |
222 | gEve->RemoveElement(fSec3Ds[i], this); |
42c8253f |
223 | fSec3Ds[i] = 0; |
224 | } else { |
225 | fSec3Ds[i]->IncRTS(); |
32e219c2 |
226 | fSec3Ds[i]->ElementChanged(); |
42c8253f |
227 | } |
e9a38ea3 |
228 | } |
229 | } |
84aff7a4 |
230 | gEve->Redraw3D(kTRUE, kFALSE); |
231 | gEve->EnableRedraw(); |
e9a38ea3 |
232 | } |
233 | |
c59e16e8 |
234 | void TPCLoader::ReloadSectors() |
235 | { |
236 | LoadEvent(); |
237 | UpdateSectors(); |
238 | } |
239 | |
e9a38ea3 |
240 | void TPCLoader::CreateSectors3D() |
241 | { |
84aff7a4 |
242 | gEve->DisableRedraw(); |
e9a38ea3 |
243 | for(Int_t i=0; i<=35; ++i) { |
244 | TPCSectorData* sd = fData->GetSectorData(i); |
245 | if(sd != 0 && fSec3Ds[i] == 0) { |
246 | TPCSector3D* s = new TPCSector3D(Form("Sector3D %d", i)); |
247 | fSec3Ds[i] = s; |
248 | s->SetSectorID(i); |
249 | s->SetDataSource(fData); |
8f50aad8 |
250 | |
251 | if(fDoubleSR) |
252 | s->SetDriftVel(2.273); |
253 | if(fSec2Ds[i] != 0) |
254 | s->CopyVizParams(*fSec2Ds[i]); |
e9a38ea3 |
255 | |
601bca51 |
256 | s->SetAutoTrans(kTRUE); |
e9a38ea3 |
257 | s->SetFrameColor(36); |
258 | |
84aff7a4 |
259 | gEve->AddElement(s, this); |
e9a38ea3 |
260 | } |
261 | } |
84aff7a4 |
262 | gEve->EnableRedraw(); |
e9a38ea3 |
263 | } |
264 | |
265 | void TPCLoader::DeleteSectors3D() |
266 | { |
84aff7a4 |
267 | gEve->DisableRedraw(); |
e9a38ea3 |
268 | for(Int_t i=0; i<=35; ++i) { |
84aff7a4 |
269 | TEveElement* re = fSec3Ds[i]; |
e9a38ea3 |
270 | if(re != 0) { |
84aff7a4 |
271 | gEve->RemoveElement(re, this); |
4a378d74 |
272 | // delete re; // Done automatically. |
e9a38ea3 |
273 | fSec3Ds[i] = 0; |
274 | } |
275 | } |
84aff7a4 |
276 | gEve->EnableRedraw(); |
e9a38ea3 |
277 | } |
e7c8d6ca |
278 | |
279 | /**************************************************************************/ |
280 | |
b1e0b894 |
281 | void TPCLoader::SetInitParams(Int_t mint, Int_t maxt, Int_t thr, Int_t maxval) |
e7c8d6ca |
282 | { |
283 | fSetInitSectorParams = kTRUE; |
284 | fInitMinTime = mint; |
285 | fInitMaxTime = maxt; |
286 | fInitThreshold = thr; |
b1e0b894 |
287 | fInitMaxVal = maxval; |
e7c8d6ca |
288 | } |