Additional protection. Do not issue AliFatal in case of corrupted data (cosmic test)
[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),
39 fInitMinTime(0), fInitMaxTime(460), fInitThreshold(5)
4a378d74 40{}
e9a38ea3 41
42TPCLoader::~TPCLoader()
43{
44 delete fReader;
45 delete fData;
46}
47
48/**************************************************************************/
49
4a378d74 50void TPCLoader::RemoveElementLocal(RenderElement* el)
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 58void 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
68void TPCLoader::SetData(TPCData* d)
69{
70 delete fData;
71 fData = d;
72}
73
74/**************************************************************************/
75
76void TPCLoader::OpenFile()
77{
78 static const Exc_t eH("TPCLoader::OpenFile ");
79
80 if(gSystem->AccessPathName(fFile, kReadPermission))
81 throw(eH + "can not read '" + fFile + "'.");
82
83 if(fData == 0)
84 fData = new TPCData;
42c8253f 85 else
86 fData->DeleteAllSectors();
e9a38ea3 87
88 delete fReader;
89 fReader = 0;
90 fEvent = -1;
91
92 fReader = new AliRawReaderRoot(fFile);
61eeeb0e 93 if(fTPCEquipementMap != "")
94 fReader->LoadEquipmentIdsMap
95 (gSystem->ExpandPathName(fTPCEquipementMap.Data()));
e9a38ea3 96
97 NextEvent();
98 LoadEvent();
42c8253f 99 UpdateSectors(kTRUE);
e9a38ea3 100}
101
102void TPCLoader::LoadEvent()
103{
104 static const Exc_t eH("TPCLoader::LoadEvent ");
105
106 if(fReader == 0)
107 throw(eH + "data file not opened.");
108
109 printf("Now loading event %d\n", fEvent);
110 fReader->Reset();
111 AliTPCRawStream input(fReader);
112 input.SetOldRCUFormat(kTRUE);
61eeeb0e 113 fReader->Select("TPC");
e9a38ea3 114
115 fData->DropAllSectors();
116 fData->LoadRaw(input, kTRUE, kTRUE);
117}
118
119void TPCLoader::NextEvent(Bool_t rewindOnEnd)
120{
121 static const Exc_t eH("TPCLoader::NextEvent ");
122
123 if(fReader == 0)
124 throw(eH + "data file not opened.");
125
126 if(fReader->NextEvent() == kTRUE) {
127 ++fEvent;
128 } else {
129 if(fEvent == -1)
130 throw(eH + "no events available.");
131 if(rewindOnEnd) {
132 printf("Reached end of stream (event=%d), rewinding to first event.\n", fEvent);
133 fReader->RewindEvents();
134 fReader->NextEvent();
135 fEvent = 0;
136 } else {
137 throw(eH + "last event reached.");
138 }
139 }
140}
141
142void TPCLoader::GotoEvent(Int_t event)
143{
144 static const Exc_t eH("TPCLoader::GotoEvent ");
145
146 if(fReader == 0)
147 throw(eH + "data file not opened.");
148
149 if(event == fEvent)
150 return;
151 Bool_t checkEnd;
152 if(event < fEvent) {
153 fReader->RewindEvents();
154 fEvent = -1;
155 checkEnd = kFALSE;
156 } else {
157 checkEnd = kTRUE;
158 }
159 do {
160 NextEvent();
161 } while(fEvent != event && !(checkEnd == kTRUE && fEvent == 0));
162 LoadEvent();
163 UpdateSectors();
164}
165
42c8253f 166void* TPCLoader::LoopEvent(TPCLoader* loader)
167{
168 loader->NextEvent();
169 loader->LoadEvent();
170 loader->UpdateSectors();
171 if (gReve->GetEditor()->GetModel() == loader)
172 gReve->EditRenderElement(loader);
173 return 0;
174}
175
e9a38ea3 176/**************************************************************************/
177
42c8253f 178void TPCLoader::UpdateSectors(Bool_t dropNonPresent)
e9a38ea3 179{
180 gReve->DisableRedraw();
42c8253f 181 for(Int_t i=0; i<=35; ++i)
182 {
183 TPCSectorData* sd = fData->GetSectorData(i);
184
185 // 2D sectors
186 if(fSec2Ds[i] != 0)
187 {
188 if (dropNonPresent && sd == 0) {
32e219c2 189 gReve->RemoveRenderElement(fSec2Ds[i], this);
42c8253f 190 fSec2Ds[i] = 0;
191 } else {
192 fSec2Ds[i]->IncRTS();
32e219c2 193 fSec2Ds[i]->ElementChanged();
42c8253f 194 }
195 }
196 else
197 {
e9a38ea3 198 if(sd != 0) {
199 TPCSector2D* s = new TPCSector2D(Form("Sector2D %d", i));
200 fSec2Ds[i] = s;
201 s->SetSectorID(i);
202 s->SetDataSource(fData);
8f50aad8 203
204 if(fDoubleSR)
205 s->SetMaxTime(1023);
e9a38ea3 206
e7c8d6ca 207 if(fSetInitSectorParams) {
208 s->SetMinTime(fInitMinTime);
209 s->SetMaxTime(fInitMaxTime);
210 s->SetThreshold(fInitThreshold);
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 }
42c8253f 232 gReve->Redraw3D(kFALSE, kTRUE);
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
283void TPCLoader::SetInitParams(Int_t mint, Int_t maxt, Int_t thr)
284{
285 fSetInitSectorParams = kTRUE;
286 fInitMinTime = mint;
287 fInitMaxTime = maxt;
288 fInitThreshold = thr;
289}