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