]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Alieve/AliEveTPCLoader.cxx
Normalize all separator comments to width 80.
[u/mrichter/AliRoot.git] / EVE / Alieve / 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 <Alieve/AliEveTPCSector2D.h>
13 #include <Alieve/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 ClassImp(AliEveTPCLoader)
28
29 AliEveTPCLoader::AliEveTPCLoader(const Text_t* n, const Text_t* t) :
30   TEveElementList(n, t),
31
32   fFile(),
33   fEvent(-1),
34   fDoubleSR(kFALSE),
35
36   fTPCEquipementMap(),
37   fReader(0),
38   fData(0),
39
40   fSec2Ds(36),
41   fSec3Ds(36),
42
43   fSetInitSectorParams(kFALSE),
44   fInitMinTime(0), fInitMaxTime(460), fInitThreshold(5), fInitMaxVal(128)
45 {
46   fData = new AliEveTPCData;
47 }
48
49 AliEveTPCLoader::~AliEveTPCLoader()
50 {
51   delete fReader;
52   delete fData;
53 }
54
55 /******************************************************************************/
56
57 void AliEveTPCLoader::RemoveElementLocal(TEveElement* el)
58 {
59   for(Int_t i=0; i<36; ++i) {
60     if(fSec2Ds[i] == el) fSec2Ds[i] = 0;
61     if(fSec3Ds[i] == el) fSec3Ds[i] = 0;
62   }
63 }
64
65 void AliEveTPCLoader::RemoveElementsLocal()
66 {
67   for(Int_t i=0; i<36; ++i) {
68     fSec2Ds[i] = 0;
69     fSec3Ds[i] = 0;
70   }
71 }
72
73 /******************************************************************************/
74
75 void AliEveTPCLoader::SetData(AliEveTPCData* d)
76 {
77   delete fData;
78   fData = d;
79 }
80
81 /******************************************************************************/
82
83 void AliEveTPCLoader::OpenFile()
84 {
85   static const TEveException eH("AliEveTPCLoader::OpenFile ");
86
87   if(gSystem->AccessPathName(fFile, kReadPermission))
88       throw(eH + "can not read '" + fFile + "'.");
89
90   fData->DeleteAllSectors();
91
92   delete fReader;
93   fReader =  0;
94   fEvent  = -1;
95
96   fReader = new AliRawReaderRoot(fFile);
97   if(fTPCEquipementMap != "")
98     fReader->LoadEquipmentIdsMap
99       (gSystem->ExpandPathName(fTPCEquipementMap.Data()));
100
101   NextEvent();
102   LoadEvent();
103   UpdateSectors(kTRUE);
104 }
105
106 void AliEveTPCLoader::LoadEvent()
107 {
108   static const TEveException eH("AliEveTPCLoader::LoadEvent ");
109
110   if(fReader == 0)
111     throw(eH + "data file not opened.");
112
113   printf("Now loading event %d\n", fEvent);
114   fReader->Reset();
115   AliTPCRawStream input(fReader);
116   input.SetOldRCUFormat(kTRUE);
117   fReader->Select("TPC");
118
119   fData->DropAllSectors();
120   fData->LoadRaw(input, kTRUE, kTRUE);
121 }
122
123 void AliEveTPCLoader::NextEvent(Bool_t rewindOnEnd)
124 {
125   static const TEveException eH("AliEveTPCLoader::NextEvent ");
126
127   if(fReader == 0)
128     throw(eH + "data file not opened.");
129
130   if(fReader->NextEvent() == kTRUE) {
131     ++fEvent;
132   } else {
133     if(fEvent == -1)
134       throw(eH + "no events available.");
135     if(rewindOnEnd) {
136       printf("Reached end of stream (event=%d), rewinding to first event.\n", fEvent);
137       fReader->RewindEvents();
138       fReader->NextEvent();
139       fEvent = 0;
140     } else {
141       throw(eH + "last event reached.");
142     }
143   }
144 }
145
146 void AliEveTPCLoader::GotoEvent(Int_t event)
147 {
148   static const TEveException eH("AliEveTPCLoader::GotoEvent ");
149
150   if(fReader == 0)
151     throw(eH + "data file not opened.");
152
153   if(event == fEvent)
154     return;
155   Bool_t checkEnd;
156   if(event < fEvent) {
157     fReader->RewindEvents();
158     fEvent = -1;
159     checkEnd = kFALSE;
160   } else {
161     checkEnd = kTRUE;
162   }
163   do {
164     NextEvent();
165   } while(fEvent != event && !(checkEnd == kTRUE && fEvent == 0));
166   LoadEvent();
167   UpdateSectors();
168 }
169
170 void* AliEveTPCLoader::LoopEvent(AliEveTPCLoader* loader)
171 {
172   loader->NextEvent();
173   loader->LoadEvent();
174   loader->UpdateSectors();
175   if (gEve->GetEditor()->GetModel() == loader)
176     gEve->EditElement(loader);
177   return 0;
178 }
179
180 /******************************************************************************/
181
182 void AliEveTPCLoader::UpdateSectors(Bool_t dropNonPresent)
183 {
184   gEve->DisableRedraw();
185   for(Int_t i=0; i<=35; ++i)
186   {
187     AliEveTPCSectorData* sd = fData->GetSectorData(i);
188
189     // 2D sectors
190     if(fSec2Ds[i] != 0)
191     {
192       if (dropNonPresent && sd == 0) {
193         gEve->RemoveElement(fSec2Ds[i], this);
194         fSec2Ds[i] = 0;
195       } else {
196         fSec2Ds[i]->IncRTS();
197         fSec2Ds[i]->ElementChanged();
198       }
199     }
200     else
201     {
202       if(sd != 0) {
203         AliEveTPCSector2D* s = new AliEveTPCSector2D(Form("Sector2D %d", i));
204         fSec2Ds[i] = s;
205         s->SetSectorID(i);
206         s->SetDataSource(fData);
207
208         if(fDoubleSR)
209           s->SetMaxTime(1023);
210
211         if(fSetInitSectorParams) {
212           s->SetMinTime(fInitMinTime);
213           s->SetMaxTime(fInitMaxTime);
214           s->SetThreshold(fInitThreshold);
215           s->SetMaxVal(fInitMaxVal);
216         }
217
218         s->SetAutoTrans(kTRUE);
219         s->SetFrameColor(36);
220
221         gEve->AddElement(s, this);
222       }
223     }
224
225     // 3D sectors
226     if(fSec3Ds[i] != 0)
227     {
228       if (dropNonPresent && sd == 0) {
229         gEve->RemoveElement(fSec3Ds[i], this);
230         fSec3Ds[i] = 0;
231       } else {
232         fSec3Ds[i]->IncRTS();
233         fSec3Ds[i]->ElementChanged();
234       }
235     }
236   }
237   gEve->Redraw3D(kTRUE, kFALSE);
238   gEve->EnableRedraw();
239 }
240
241 void AliEveTPCLoader::ReloadSectors()
242 {
243   LoadEvent();
244   UpdateSectors();
245 }
246
247 void AliEveTPCLoader::CreateSectors3D()
248 {
249   gEve->DisableRedraw();
250   for(Int_t i=0; i<=35; ++i) {
251     AliEveTPCSectorData* sd = fData->GetSectorData(i);
252     if(sd != 0 && fSec3Ds[i] == 0) {
253       AliEveTPCSector3D* s = new AliEveTPCSector3D(Form("Sector3D %d", i));
254       fSec3Ds[i] = s;
255       s->SetSectorID(i);
256       s->SetDataSource(fData);
257
258       if(fDoubleSR)
259         s->SetDriftVel(2.273);
260       if(fSec2Ds[i] != 0)
261         s->CopyVizParams(*fSec2Ds[i]);
262
263       s->SetAutoTrans(kTRUE);
264       s->SetFrameColor(36);
265
266       gEve->AddElement(s, this);
267     }
268   }
269   gEve->EnableRedraw();
270 }
271
272 void AliEveTPCLoader::DeleteSectors3D()
273 {
274   gEve->DisableRedraw();
275   for(Int_t i=0; i<=35; ++i) {
276     TEveElement* re = fSec3Ds[i];
277     if(re != 0) {
278       gEve->RemoveElement(re, this);
279       // delete re; // Done automatically.
280       fSec3Ds[i] = 0;
281     }
282   }
283   gEve->EnableRedraw();
284 }
285
286 /******************************************************************************/
287
288 void AliEveTPCLoader::SetInitParams(Int_t mint, Int_t maxt, Int_t thr, Int_t maxval)
289 {
290   fSetInitSectorParams = kTRUE;
291   fInitMinTime   = mint;
292   fInitMaxTime   = maxt;
293   fInitThreshold = thr;
294   fInitMaxVal    = maxval;
295 }