New class TPCLoader providing (graphical) interface for navigation through the TPC...
[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
26 fEvent(-1),
27
28 fReader(0),
29 fData(0),
30
31 fSec2Ds(36),
32 fSec3Ds(36)
33{
34 SetMainColorPtr(0);
35}
36
37TPCLoader::~TPCLoader()
38{
39 delete fReader;
40 delete fData;
41}
42
43/**************************************************************************/
44
45
46void TPCLoader::SetData(TPCData* d)
47{
48 delete fData;
49 fData = d;
50}
51
52/**************************************************************************/
53
54void TPCLoader::OpenFile()
55{
56 static const Exc_t eH("TPCLoader::OpenFile ");
57
58 if(gSystem->AccessPathName(fFile, kReadPermission))
59 throw(eH + "can not read '" + fFile + "'.");
60
61 if(fData == 0)
62 fData = new TPCData;
63
64 delete fReader;
65 fReader = 0;
66 fEvent = -1;
67
68 fReader = new AliRawReaderRoot(fFile);
69 fReader->LoadEquipmentIdsMap
70 (gSystem->ExpandPathName("$(ALICE_ROOT)/TPC/mapping/EquipmentIdMap.data"));
71
72 NextEvent();
73 LoadEvent();
74 UpdateSectors();
75}
76
77void TPCLoader::LoadEvent()
78{
79 static const Exc_t eH("TPCLoader::LoadEvent ");
80
81 if(fReader == 0)
82 throw(eH + "data file not opened.");
83
84 printf("Now loading event %d\n", fEvent);
85 fReader->Reset();
86 AliTPCRawStream input(fReader);
87 input.SetOldRCUFormat(kTRUE);
88 fReader->Select(0);
89
90 fData->DropAllSectors();
91 fData->LoadRaw(input, kTRUE, kTRUE);
92}
93
94void TPCLoader::NextEvent(Bool_t rewindOnEnd)
95{
96 static const Exc_t eH("TPCLoader::NextEvent ");
97
98 if(fReader == 0)
99 throw(eH + "data file not opened.");
100
101 if(fReader->NextEvent() == kTRUE) {
102 ++fEvent;
103 } else {
104 if(fEvent == -1)
105 throw(eH + "no events available.");
106 if(rewindOnEnd) {
107 printf("Reached end of stream (event=%d), rewinding to first event.\n", fEvent);
108 fReader->RewindEvents();
109 fReader->NextEvent();
110 fEvent = 0;
111 } else {
112 throw(eH + "last event reached.");
113 }
114 }
115}
116
117void TPCLoader::GotoEvent(Int_t event)
118{
119 static const Exc_t eH("TPCLoader::GotoEvent ");
120
121 if(fReader == 0)
122 throw(eH + "data file not opened.");
123
124 if(event == fEvent)
125 return;
126 Bool_t checkEnd;
127 if(event < fEvent) {
128 fReader->RewindEvents();
129 fEvent = -1;
130 checkEnd = kFALSE;
131 } else {
132 checkEnd = kTRUE;
133 }
134 do {
135 NextEvent();
136 } while(fEvent != event && !(checkEnd == kTRUE && fEvent == 0));
137 LoadEvent();
138 UpdateSectors();
139}
140
141/**************************************************************************/
142
143void TPCLoader::UpdateSectors()
144{
145 gReve->DisableRedraw();
146 for(Int_t i=0; i<=35; ++i) {
147 if(fSec2Ds[i] != 0) {
148 fSec2Ds[i]->IncRTS();
149 } else {
150 TPCSectorData* sd = fData->GetSectorData(i);
151 if(sd != 0) {
152 TPCSector2D* s = new TPCSector2D(Form("Sector2D %d", i));
153 fSec2Ds[i] = s;
154 s->SetSectorID(i);
155 s->SetDataSource(fData);
156 s->SetMinTime(0);
157 s->SetMaxTime(1023);
158
159 s->SetTrans(kTRUE);
160 s->SetFrameColor(36);
161
162 gReve->AddRenderElement(s);
163 gReve->DrawRenderElement(s);
164 }
165 }
166
167 if(fSec3Ds[i] != 0) {
168 fSec3Ds[i]->IncRTS();
169 }
170 }
171 gReve->EnableRedraw();
172}
173
174void TPCLoader::CreateSectors3D()
175{
176 gReve->DisableRedraw();
177 for(Int_t i=0; i<=35; ++i) {
178 TPCSectorData* sd = fData->GetSectorData(i);
179 if(sd != 0 && fSec3Ds[i] == 0) {
180 TPCSector3D* s = new TPCSector3D(Form("Sector3D %d", i));
181 fSec3Ds[i] = s;
182 s->SetSectorID(i);
183 s->SetDataSource(fData);
184 s->SetMinTime(0);
185 s->SetMaxTime(1023);
186
187 s->SetTrans(kTRUE);
188 s->SetFrameColor(36);
189
190 gReve->AddRenderElement(s);
191 gReve->DrawRenderElement(s);
192 }
193 }
194 gReve->EnableRedraw();
195}
196
197void TPCLoader::DeleteSectors3D()
198{
199 gReve->DisableRedraw();
200 for(Int_t i=0; i<=35; ++i) {
201 RenderElement* re = fSec3Ds[i];
202 if(re != 0) {
203 gReve->UndrawRenderElement(re);
204 delete re;
205 fSec3Ds[i] = 0;
206 }
207 }
208 gReve->EnableRedraw();
209}