2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
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 **************************************************************************/
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>
17 #include <AliRawReaderRoot.h>
18 #include <AliTPCRawStream.h>
23 //______________________________________________________________________________
25 // Front-end for stand-alone inspection of TPC raw-data.
26 // GUI is implemented in AliEveTPCLoaderEditor class.
28 ClassImp(AliEveTPCLoader)
30 AliEveTPCLoader::AliEveTPCLoader(const Text_t* n, const Text_t* t) :
31 TEveElementList(n, t),
44 fSetInitSectorParams(kFALSE),
45 fInitMinTime(0), fInitMaxTime(460), fInitThreshold(5), fInitMaxVal(128)
49 fData = new AliEveTPCData;
52 AliEveTPCLoader::~AliEveTPCLoader()
60 /******************************************************************************/
62 void AliEveTPCLoader::RemoveElementLocal(TEveElement* el)
64 // Local removal an element, virtual from TEveElement.
65 // Need to search for it in visual sector representations and remove
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;
74 void AliEveTPCLoader::RemoveElementsLocal()
76 // Local removal of all elements, virtual from TEveElement.
77 // Must remove all visual sector representations.
79 for (Int_t i=0; i<36; ++i) {
85 /******************************************************************************/
87 void AliEveTPCLoader::SetData(AliEveTPCData* d)
89 // Set external TPC-data container. The old one is deleted.
95 /******************************************************************************/
97 void AliEveTPCLoader::OpenFile()
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
104 static const TEveException eH("AliEveTPCLoader::OpenFile ");
106 if (gSystem->AccessPathName(fFile, kReadPermission))
107 throw(eH + "can not read '" + fFile + "'.");
109 fData->DeleteAllSectors();
115 fReader = new AliRawReaderRoot(fFile);
116 if (fTPCEquipementMap != "")
117 fReader->LoadEquipmentIdsMap
118 (gSystem->ExpandPathName(fTPCEquipementMap.Data()));
122 UpdateSectors(kTRUE);
125 void AliEveTPCLoader::LoadEvent()
129 static const TEveException eH("AliEveTPCLoader::LoadEvent ");
132 throw(eH + "data file not opened.");
134 printf("Now loading event %d\n", fEvent);
136 AliTPCRawStream input(fReader);
137 input.SetOldRCUFormat(kTRUE);
138 fReader->Select("TPC");
140 fData->DropAllSectors();
141 fData->LoadRaw(input, kTRUE, kTRUE);
144 void AliEveTPCLoader::NextEvent(Bool_t rewindOnEnd)
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.
150 static const TEveException eH("AliEveTPCLoader::NextEvent ");
153 throw(eH + "data file not opened.");
155 if (fReader->NextEvent() == kTRUE) {
159 throw(eH + "no events available.");
161 printf("Reached end of stream (event=%d), rewinding to first event.\n", fEvent);
162 fReader->RewindEvents();
163 fReader->NextEvent();
166 throw(eH + "last event reached.");
171 void AliEveTPCLoader::GotoEvent(Int_t event)
173 // Go to specified event.
175 static const TEveException eH("AliEveTPCLoader::GotoEvent ");
178 throw(eH + "data file not opened.");
183 if (event < fEvent) {
184 fReader->RewindEvents();
192 } while (fEvent != event && !(checkEnd == kTRUE && fEvent == 0));
197 void* AliEveTPCLoader::LoopEvent(AliEveTPCLoader* loader)
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().
205 loader->UpdateSectors();
206 if (gEve->GetEditor()->GetModel() == loader)
207 gEve->EditElement(loader);
211 /******************************************************************************/
213 void AliEveTPCLoader::UpdateSectors(Bool_t dropNonPresent)
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.
219 gEve->DisableRedraw();
220 for (Int_t i=0; i<=35; ++i)
222 AliEveTPCSectorData* sd = fData->GetSectorData(i);
227 if (dropNonPresent && sd == 0) {
228 gEve->RemoveElement(fSec2Ds[i], this);
231 fSec2Ds[i]->IncRTS();
232 fSec2Ds[i]->ElementChanged();
238 AliEveTPCSector2D* s = new AliEveTPCSector2D(Form("Sector2D %d", i));
241 s->SetDataSource(fData);
246 if (fSetInitSectorParams) {
247 s->SetMinTime(fInitMinTime);
248 s->SetMaxTime(fInitMaxTime);
249 s->SetThreshold(fInitThreshold);
250 s->SetMaxVal(fInitMaxVal);
253 s->SetAutoTrans(kTRUE);
254 s->SetFrameColor(36);
256 gEve->AddElement(s, this);
263 if (dropNonPresent && sd == 0) {
264 gEve->RemoveElement(fSec3Ds[i], this);
267 fSec3Ds[i]->IncRTS();
268 fSec3Ds[i]->ElementChanged();
272 gEve->Redraw3D(kTRUE, kFALSE);
273 gEve->EnableRedraw();
276 void AliEveTPCLoader::ReloadSectors()
278 // Reload current event and update sectors.
284 void AliEveTPCLoader::CreateSectors3D()
286 // Create 3D representations of sectors.
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));
295 s->SetDataSource(fData);
298 s->SetDriftVel(2.273);
300 s->CopyVizParams(*fSec2Ds[i]);
302 s->SetAutoTrans(kTRUE);
303 s->SetFrameColor(36);
305 gEve->AddElement(s, this);
308 gEve->EnableRedraw();
311 void AliEveTPCLoader::DeleteSectors3D()
313 // Delete 3D representations of sectors.
315 gEve->DisableRedraw();
316 for (Int_t i=0; i<=35; ++i) {
317 TEveElement* re = fSec3Ds[i];
319 gEve->RemoveElement(re, this);
320 // delete re; // Done automatically.
324 gEve->EnableRedraw();
327 /******************************************************************************/
329 void AliEveTPCLoader::SetInitParams(Int_t mint, Int_t maxt, Int_t thr, Int_t maxval)
331 // Set initial viualization parameters for 2D and 3D sector representations.
333 fSetInitSectorParams = kTRUE;
336 fInitThreshold = thr;
337 fInitMaxVal = maxval;