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