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