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