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