]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveDet/AliEveTPCLoader.cxx
No need for TGLObject.h (C.Holm)
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTPCLoader.cxx
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          *
7  * full copyright notice.                                                 *
8  **************************************************************************/
9
10 #include "AliEveTPCLoader.h"
11 #include "AliEveTPCData.h"
12 #include <EveDet/AliEveTPCSector2D.h>
13 #include <EveDet/AliEveTPCSector3D.h>
14 #include <TEveManager.h>
15 #include <TEveGedEditor.h>
16
17 #include <AliRawReaderRoot.h>
18 #include <AliTPCRawStream.h>
19
20 #include <TSystem.h>
21
22 //==============================================================================
23 //==============================================================================
24 // AliEveTPCLoader
25 //==============================================================================
26
27 //______________________________________________________________________________
28 //
29 // Front-end for stand-alone inspection of TPC raw-data.
30 // GUI is implemented in AliEveTPCLoaderEditor class.
31
32 ClassImp(AliEveTPCLoader)
33
34 AliEveTPCLoader::AliEveTPCLoader(const Text_t* n, const Text_t* t) :
35   TEveElementList(n, t),
36
37   fFile(),
38   fEvent(-1),
39   fDoubleSR(kFALSE),
40
41   fTPCEquipementMap(),
42   fReader(0),
43   fData(0),
44
45   fSec2Ds(36),
46   fSec3Ds(36),
47
48   fSetInitSectorParams(kFALSE),
49   fInitMinTime(0), fInitMaxTime(460), fInitThreshold(5), fInitMaxVal(128)
50 {
51   // Constructor.
52
53   fData = new AliEveTPCData;
54 }
55
56 AliEveTPCLoader::~AliEveTPCLoader()
57 {
58   // Destructor.
59
60   delete fReader;
61   delete fData;
62 }
63
64 /******************************************************************************/
65
66 void AliEveTPCLoader::RemoveElementLocal(TEveElement* el)
67 {
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;
75   }
76 }
77
78 void AliEveTPCLoader::RemoveElementsLocal()
79 {
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) {
84     fSec2Ds[i] = 0;
85     fSec3Ds[i] = 0;
86   }
87 }
88
89 /******************************************************************************/
90
91 void AliEveTPCLoader::SetData(AliEveTPCData* d)
92 {
93   // Set external TPC-data container. The old one is deleted.
94
95   delete fData;
96   fData = d;
97 }
98
99 /******************************************************************************/
100
101 void AliEveTPCLoader::OpenFile()
102 {
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
108   static const TEveException kEH("AliEveTPCLoader::OpenFile ");
109
110   if (gSystem->AccessPathName(fFile, kReadPermission))
111       throw(kEH + "can not read '" + fFile + "'.");
112
113   fData->DeleteAllSectors();
114
115   delete fReader;
116   fReader =  0;
117   fEvent  = -1;
118
119   fReader = new AliRawReaderRoot(fFile);
120   if (fTPCEquipementMap != "")
121     fReader->LoadEquipmentIdsMap
122       (gSystem->ExpandPathName(fTPCEquipementMap.Data()));
123
124   NextEvent();
125   LoadEvent();
126   UpdateSectors(kTRUE);
127 }
128
129 void AliEveTPCLoader::LoadEvent()
130 {
131   // Load an event.
132
133   static const TEveException kEH("AliEveTPCLoader::LoadEvent ");
134
135   if (fReader == 0)
136     throw(kEH + "data file not opened.");
137
138   printf("Now loading event %d\n", fEvent);
139   fReader->Reset();
140   AliTPCRawStream input(fReader);
141   fReader->Select("TPC");
142
143   fData->DropAllSectors();
144   fData->LoadRaw(input, kTRUE, kTRUE);
145 }
146
147 void AliEveTPCLoader::NextEvent(Bool_t rewindOnEnd)
148 {
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
153   static const TEveException kEH("AliEveTPCLoader::NextEvent ");
154
155   if (fReader == 0)
156     throw(kEH + "data file not opened.");
157
158   if (fReader->NextEvent() == kTRUE) {
159     ++fEvent;
160   } else {
161     if (fEvent == -1)
162       throw(kEH + "no events available.");
163     if (rewindOnEnd) {
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 {
169       throw(kEH + "last event reached.");
170     }
171   }
172 }
173
174 void AliEveTPCLoader::GotoEvent(Int_t event)
175 {
176   // Go to specified event.
177
178   static const TEveException kEH("AliEveTPCLoader::GotoEvent ");
179
180   if (fReader == 0)
181     throw(kEH + "data file not opened.");
182
183   if (event == fEvent)
184     return;
185   Bool_t checkEnd;
186   if (event < fEvent) {
187     fReader->RewindEvents();
188     fEvent = -1;
189     checkEnd = kFALSE;
190   } else {
191     checkEnd = kTRUE;
192   }
193   do {
194     NextEvent();
195   } while (fEvent != event && !(checkEnd == kTRUE && fEvent == 0));
196   LoadEvent();
197   UpdateSectors();
198 }
199
200 void* AliEveTPCLoader::LoopEvent(AliEveTPCLoader* loader)
201 {
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
206   loader->NextEvent();
207   loader->LoadEvent();
208   loader->UpdateSectors();
209   if (gEve->GetEditor()->GetModel() == loader)
210     gEve->EditElement(loader);
211   return 0;
212 }
213
214 /******************************************************************************/
215
216 void AliEveTPCLoader::UpdateSectors(Bool_t dropNonPresent)
217 {
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
222   gEve->DisableRedraw();
223   for (Int_t i=0; i<=35; ++i)
224   {
225     AliEveTPCSectorData* sd = fData->GetSectorData(i);
226
227     // 2D sectors
228     if (fSec2Ds[i] != 0)
229     {
230       if (dropNonPresent && sd == 0) {
231         gEve->RemoveElement(fSec2Ds[i], this);
232         fSec2Ds[i] = 0;
233       } else {
234         fSec2Ds[i]->IncRTS();
235         fSec2Ds[i]->ElementChanged();
236       }
237     }
238     else
239     {
240       if (sd != 0) {
241         AliEveTPCSector2D* s = new AliEveTPCSector2D(Form("Sector2D %d", i));
242         fSec2Ds[i] = s;
243         s->SetSectorID(i);
244         s->SetDataSource(fData);
245
246         if (fDoubleSR)
247           s->SetMaxTime(1023);
248
249         if (fSetInitSectorParams) {
250           s->SetMinTime(fInitMinTime);
251           s->SetMaxTime(fInitMaxTime);
252           s->SetThreshold(fInitThreshold);
253           s->SetMaxVal(fInitMaxVal);
254         }
255
256         s->SetAutoTrans(kTRUE);
257         s->SetFrameColor(36);
258
259         gEve->AddElement(s, this);
260       }
261     }
262
263     // 3D sectors
264     if (fSec3Ds[i] != 0)
265     {
266       if (dropNonPresent && sd == 0) {
267         gEve->RemoveElement(fSec3Ds[i], this);
268         fSec3Ds[i] = 0;
269       } else {
270         fSec3Ds[i]->IncRTS();
271         fSec3Ds[i]->ElementChanged();
272       }
273     }
274   }
275   gEve->Redraw3D(kTRUE, kFALSE);
276   gEve->EnableRedraw();
277 }
278
279 void AliEveTPCLoader::ReloadSectors()
280 {
281   // Reload current event and update sectors.
282
283   LoadEvent();
284   UpdateSectors();
285 }
286
287 void AliEveTPCLoader::CreateSectors3D()
288 {
289   // Create 3D representations of sectors.
290
291   gEve->DisableRedraw();
292   for (Int_t i=0; i<=35; ++i) {
293     AliEveTPCSectorData* sd = fData->GetSectorData(i);
294     if (sd != 0 && fSec3Ds[i] == 0) {
295       AliEveTPCSector3D* s = new AliEveTPCSector3D(Form("Sector3D %d", i));
296       fSec3Ds[i] = s;
297       s->SetSectorID(i);
298       s->SetDataSource(fData);
299
300       if (fDoubleSR)
301         s->SetDriftVel(2.273);
302       if (fSec2Ds[i] != 0)
303         s->CopyVizParams(*fSec2Ds[i]);
304
305       s->SetAutoTrans(kTRUE);
306       s->SetFrameColor(36);
307
308       gEve->AddElement(s, this);
309     }
310   }
311   gEve->EnableRedraw();
312 }
313
314 void AliEveTPCLoader::DeleteSectors3D()
315 {
316   // Delete 3D representations of sectors.
317
318   gEve->DisableRedraw();
319   for (Int_t i=0; i<=35; ++i) {
320     TEveElement* re = fSec3Ds[i];
321     if (re != 0) {
322       gEve->RemoveElement(re, this);
323       // delete re; // Done automatically.
324       fSec3Ds[i] = 0;
325     }
326   }
327   gEve->EnableRedraw();
328 }
329
330 /******************************************************************************/
331
332 void AliEveTPCLoader::SetInitParams(Int_t mint, Int_t maxt, Int_t thr, Int_t maxval)
333 {
334   // Set initial viualization parameters for 2D and 3D sector representations.
335
336   fSetInitSectorParams = kTRUE;
337   fInitMinTime   = mint;
338   fInitMaxTime   = maxt;
339   fInitThreshold = thr;
340   fInitMaxVal    = maxval;
341 }