Fixes for inconsistent types in BinarySearch
[u/mrichter/AliRoot.git] / EVE / EveDet / 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"
cb4245bb 12#include <EveDet/AliEveTPCSector2D.h>
13#include <EveDet/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
57ffa5fb 23//______________________________________________________________________________
e9a38ea3 24//
a97abca8 25// Front-end for stand-alone inspection of TPC raw-data.
26// GUI is implemented in AliEveTPCLoaderEditor class.
e9a38ea3 27
d810d0de 28ClassImp(AliEveTPCLoader)
e9a38ea3 29
d810d0de 30AliEveTPCLoader::AliEveTPCLoader(const Text_t* n, const Text_t* t) :
84aff7a4 31 TEveElementList(n, t),
e9a38ea3 32
265ecb21 33 fFile(),
e9a38ea3 34 fEvent(-1),
8f50aad8 35 fDoubleSR(kFALSE),
e9a38ea3 36
61eeeb0e 37 fTPCEquipementMap(),
e9a38ea3 38 fReader(0),
39 fData(0),
40
41 fSec2Ds(36),
e7c8d6ca 42 fSec3Ds(36),
43
265ecb21 44 fSetInitSectorParams(kFALSE),
b1e0b894 45 fInitMinTime(0), fInitMaxTime(460), fInitThreshold(5), fInitMaxVal(128)
46{
a97abca8 47 // Constructor.
48
d810d0de 49 fData = new AliEveTPCData;
b1e0b894 50}
e9a38ea3 51
d810d0de 52AliEveTPCLoader::~AliEveTPCLoader()
e9a38ea3 53{
a97abca8 54 // Destructor.
55
e9a38ea3 56 delete fReader;
57 delete fData;
58}
59
57ffa5fb 60/******************************************************************************/
e9a38ea3 61
d810d0de 62void AliEveTPCLoader::RemoveElementLocal(TEveElement* el)
4a378d74 63{
a97abca8 64 // Local removal an element, virtual from TEveElement.
65 // Need to search for it in visual sector representations and remove
66 // it there as well.
67
68 for (Int_t i=0; i<36; ++i) {
69 if (fSec2Ds[i] == el) fSec2Ds[i] = 0;
70 if (fSec3Ds[i] == el) fSec3Ds[i] = 0;
4a378d74 71 }
4a378d74 72}
73
d810d0de 74void AliEveTPCLoader::RemoveElementsLocal()
4a378d74 75{
a97abca8 76 // Local removal of all elements, virtual from TEveElement.
77 // Must remove all visual sector representations.
78
79 for (Int_t i=0; i<36; ++i) {
4a378d74 80 fSec2Ds[i] = 0;
81 fSec3Ds[i] = 0;
82 }
4a378d74 83}
84
57ffa5fb 85/******************************************************************************/
e9a38ea3 86
d810d0de 87void AliEveTPCLoader::SetData(AliEveTPCData* d)
e9a38ea3 88{
a97abca8 89 // Set external TPC-data container. The old one is deleted.
90
e9a38ea3 91 delete fData;
92 fData = d;
93}
94
57ffa5fb 95/******************************************************************************/
e9a38ea3 96
d810d0de 97void AliEveTPCLoader::OpenFile()
e9a38ea3 98{
a97abca8 99 // Open the raw-data file, as set in fFile data-member.
100 // Raw-reader is also created and attached to the file.
101 // First event is loaded and all sectors for which the data-exists
102 // are created.
103
d810d0de 104 static const TEveException eH("AliEveTPCLoader::OpenFile ");
e9a38ea3 105
a97abca8 106 if (gSystem->AccessPathName(fFile, kReadPermission))
e9a38ea3 107 throw(eH + "can not read '" + fFile + "'.");
108
b1e0b894 109 fData->DeleteAllSectors();
e9a38ea3 110
111 delete fReader;
112 fReader = 0;
113 fEvent = -1;
114
115 fReader = new AliRawReaderRoot(fFile);
a97abca8 116 if (fTPCEquipementMap != "")
61eeeb0e 117 fReader->LoadEquipmentIdsMap
118 (gSystem->ExpandPathName(fTPCEquipementMap.Data()));
e9a38ea3 119
120 NextEvent();
121 LoadEvent();
42c8253f 122 UpdateSectors(kTRUE);
e9a38ea3 123}
124
d810d0de 125void AliEveTPCLoader::LoadEvent()
e9a38ea3 126{
a97abca8 127 // Load an event.
128
d810d0de 129 static const TEveException eH("AliEveTPCLoader::LoadEvent ");
e9a38ea3 130
a97abca8 131 if (fReader == 0)
e9a38ea3 132 throw(eH + "data file not opened.");
133
134 printf("Now loading event %d\n", fEvent);
135 fReader->Reset();
136 AliTPCRawStream input(fReader);
137 input.SetOldRCUFormat(kTRUE);
61eeeb0e 138 fReader->Select("TPC");
e9a38ea3 139
140 fData->DropAllSectors();
51346b82 141 fData->LoadRaw(input, kTRUE, kTRUE);
e9a38ea3 142}
143
d810d0de 144void AliEveTPCLoader::NextEvent(Bool_t rewindOnEnd)
e9a38ea3 145{
a97abca8 146 // Go o the next event.
147 // When the last event is reached and rewindOnEnd is true, the file
148 // is rewound back to the first event. Otherwise an exception is thrown.
149
d810d0de 150 static const TEveException eH("AliEveTPCLoader::NextEvent ");
e9a38ea3 151
a97abca8 152 if (fReader == 0)
e9a38ea3 153 throw(eH + "data file not opened.");
154
a97abca8 155 if (fReader->NextEvent() == kTRUE) {
e9a38ea3 156 ++fEvent;
157 } else {
a97abca8 158 if (fEvent == -1)
e9a38ea3 159 throw(eH + "no events available.");
a97abca8 160 if (rewindOnEnd) {
e9a38ea3 161 printf("Reached end of stream (event=%d), rewinding to first event.\n", fEvent);
162 fReader->RewindEvents();
163 fReader->NextEvent();
164 fEvent = 0;
165 } else {
166 throw(eH + "last event reached.");
167 }
168 }
169}
170
d810d0de 171void AliEveTPCLoader::GotoEvent(Int_t event)
e9a38ea3 172{
a97abca8 173 // Go to specified event.
174
d810d0de 175 static const TEveException eH("AliEveTPCLoader::GotoEvent ");
e9a38ea3 176
a97abca8 177 if (fReader == 0)
e9a38ea3 178 throw(eH + "data file not opened.");
179
a97abca8 180 if (event == fEvent)
e9a38ea3 181 return;
182 Bool_t checkEnd;
a97abca8 183 if (event < fEvent) {
e9a38ea3 184 fReader->RewindEvents();
185 fEvent = -1;
186 checkEnd = kFALSE;
187 } else {
188 checkEnd = kTRUE;
189 }
190 do {
191 NextEvent();
a97abca8 192 } while (fEvent != event && !(checkEnd == kTRUE && fEvent == 0));
e9a38ea3 193 LoadEvent();
194 UpdateSectors();
195}
196
d810d0de 197void* AliEveTPCLoader::LoopEvent(AliEveTPCLoader* loader)
42c8253f 198{
a97abca8 199 // Loop to next event on given loader. Static member to be used for
200 // external control during animations.
201 // Calls NextEvent(), LoadEvent() and UpdateSectors().
202
42c8253f 203 loader->NextEvent();
204 loader->LoadEvent();
205 loader->UpdateSectors();
84aff7a4 206 if (gEve->GetEditor()->GetModel() == loader)
207 gEve->EditElement(loader);
42c8253f 208 return 0;
209}
210
57ffa5fb 211/******************************************************************************/
e9a38ea3 212
d810d0de 213void AliEveTPCLoader::UpdateSectors(Bool_t dropNonPresent)
e9a38ea3 214{
a97abca8 215 // Update visual representations of sectors.
216 // If dropNonPresent is true, the sectors for which there is no data in
217 // the current event are removed.
218
84aff7a4 219 gEve->DisableRedraw();
a97abca8 220 for (Int_t i=0; i<=35; ++i)
42c8253f 221 {
d810d0de 222 AliEveTPCSectorData* sd = fData->GetSectorData(i);
42c8253f 223
224 // 2D sectors
a97abca8 225 if (fSec2Ds[i] != 0)
42c8253f 226 {
227 if (dropNonPresent && sd == 0) {
84aff7a4 228 gEve->RemoveElement(fSec2Ds[i], this);
42c8253f 229 fSec2Ds[i] = 0;
230 } else {
231 fSec2Ds[i]->IncRTS();
32e219c2 232 fSec2Ds[i]->ElementChanged();
42c8253f 233 }
234 }
235 else
236 {
a97abca8 237 if (sd != 0) {
d810d0de 238 AliEveTPCSector2D* s = new AliEveTPCSector2D(Form("Sector2D %d", i));
e9a38ea3 239 fSec2Ds[i] = s;
240 s->SetSectorID(i);
241 s->SetDataSource(fData);
8f50aad8 242
a97abca8 243 if (fDoubleSR)
8f50aad8 244 s->SetMaxTime(1023);
e9a38ea3 245
a97abca8 246 if (fSetInitSectorParams) {
e7c8d6ca 247 s->SetMinTime(fInitMinTime);
248 s->SetMaxTime(fInitMaxTime);
249 s->SetThreshold(fInitThreshold);
b1e0b894 250 s->SetMaxVal(fInitMaxVal);
e7c8d6ca 251 }
75a20dc1 252
601bca51 253 s->SetAutoTrans(kTRUE);
e9a38ea3 254 s->SetFrameColor(36);
255
84aff7a4 256 gEve->AddElement(s, this);
e9a38ea3 257 }
258 }
259
42c8253f 260 // 3D sectors
a97abca8 261 if (fSec3Ds[i] != 0)
42c8253f 262 {
263 if (dropNonPresent && sd == 0) {
84aff7a4 264 gEve->RemoveElement(fSec3Ds[i], this);
42c8253f 265 fSec3Ds[i] = 0;
266 } else {
267 fSec3Ds[i]->IncRTS();
32e219c2 268 fSec3Ds[i]->ElementChanged();
42c8253f 269 }
e9a38ea3 270 }
271 }
84aff7a4 272 gEve->Redraw3D(kTRUE, kFALSE);
273 gEve->EnableRedraw();
e9a38ea3 274}
275
d810d0de 276void AliEveTPCLoader::ReloadSectors()
c59e16e8 277{
a97abca8 278 // Reload current event and update sectors.
279
c59e16e8 280 LoadEvent();
281 UpdateSectors();
282}
283
d810d0de 284void AliEveTPCLoader::CreateSectors3D()
e9a38ea3 285{
a97abca8 286 // Create 3D representations of sectors.
287
84aff7a4 288 gEve->DisableRedraw();
a97abca8 289 for (Int_t i=0; i<=35; ++i) {
d810d0de 290 AliEveTPCSectorData* sd = fData->GetSectorData(i);
a97abca8 291 if (sd != 0 && fSec3Ds[i] == 0) {
d810d0de 292 AliEveTPCSector3D* s = new AliEveTPCSector3D(Form("Sector3D %d", i));
e9a38ea3 293 fSec3Ds[i] = s;
294 s->SetSectorID(i);
295 s->SetDataSource(fData);
8f50aad8 296
a97abca8 297 if (fDoubleSR)
8f50aad8 298 s->SetDriftVel(2.273);
a97abca8 299 if (fSec2Ds[i] != 0)
8f50aad8 300 s->CopyVizParams(*fSec2Ds[i]);
e9a38ea3 301
601bca51 302 s->SetAutoTrans(kTRUE);
e9a38ea3 303 s->SetFrameColor(36);
304
84aff7a4 305 gEve->AddElement(s, this);
e9a38ea3 306 }
307 }
84aff7a4 308 gEve->EnableRedraw();
e9a38ea3 309}
310
d810d0de 311void AliEveTPCLoader::DeleteSectors3D()
e9a38ea3 312{
a97abca8 313 // Delete 3D representations of sectors.
314
84aff7a4 315 gEve->DisableRedraw();
a97abca8 316 for (Int_t i=0; i<=35; ++i) {
84aff7a4 317 TEveElement* re = fSec3Ds[i];
a97abca8 318 if (re != 0) {
84aff7a4 319 gEve->RemoveElement(re, this);
4a378d74 320 // delete re; // Done automatically.
e9a38ea3 321 fSec3Ds[i] = 0;
322 }
323 }
84aff7a4 324 gEve->EnableRedraw();
e9a38ea3 325}
e7c8d6ca 326
57ffa5fb 327/******************************************************************************/
e7c8d6ca 328
d810d0de 329void AliEveTPCLoader::SetInitParams(Int_t mint, Int_t maxt, Int_t thr, Int_t maxval)
e7c8d6ca 330{
a97abca8 331 // Set initial viualization parameters for 2D and 3D sector representations.
332
e7c8d6ca 333 fSetInitSectorParams = kTRUE;
334 fInitMinTime = mint;
335 fInitMaxTime = maxt;
336 fInitThreshold = thr;
b1e0b894 337 fInitMaxVal = maxval;
e7c8d6ca 338}