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