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>
22 //==============================================================================
23 //==============================================================================
25 //==============================================================================
27 //______________________________________________________________________________
29 // Front-end for stand-alone inspection of TPC raw-data.
30 // GUI is implemented in AliEveTPCLoaderEditor class.
32 ClassImp(AliEveTPCLoader)
34 AliEveTPCLoader::AliEveTPCLoader(const Text_t* n, const Text_t* t) :
35 TEveElementList(n, t),
48 fSetInitSectorParams(kFALSE),
49 fInitMinTime(0), fInitMaxTime(460), fInitThreshold(5), fInitMaxVal(128)
53 fData = new AliEveTPCData;
56 AliEveTPCLoader::~AliEveTPCLoader()
64 /******************************************************************************/
66 void AliEveTPCLoader::RemoveElementLocal(TEveElement* el)
68 // Local removal an element, virtual from TEveElement.
69 // Need to search for it in visual sector representations and remove
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;
78 void AliEveTPCLoader::RemoveElementsLocal()
80 // Local removal of all elements, virtual from TEveElement.
81 // Must remove all visual sector representations.
83 for (Int_t i=0; i<36; ++i) {
89 /******************************************************************************/
91 void AliEveTPCLoader::SetData(AliEveTPCData* d)
93 // Set external TPC-data container. The old one is deleted.
99 /******************************************************************************/
101 void AliEveTPCLoader::OpenFile()
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
108 static const TEveException kEH("AliEveTPCLoader::OpenFile ");
110 if (gSystem->AccessPathName(fFile, kReadPermission))
111 throw(kEH + "can not read '" + fFile + "'.");
113 fData->DeleteAllSectors();
119 fReader = new AliRawReaderRoot(fFile);
120 if (fTPCEquipementMap != "")
121 fReader->LoadEquipmentIdsMap
122 (gSystem->ExpandPathName(fTPCEquipementMap.Data()));
126 UpdateSectors(kTRUE);
129 void AliEveTPCLoader::LoadEvent()
133 static const TEveException kEH("AliEveTPCLoader::LoadEvent ");
136 throw(kEH + "data file not opened.");
138 printf("Now loading event %d\n", fEvent);
140 AliTPCRawStream input(fReader);
141 fReader->Select("TPC");
143 fData->DropAllSectors();
144 fData->LoadRaw(input, kTRUE, kTRUE);
147 void AliEveTPCLoader::NextEvent(Bool_t rewindOnEnd)
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.
153 static const TEveException kEH("AliEveTPCLoader::NextEvent ");
156 throw(kEH + "data file not opened.");
158 if (fReader->NextEvent() == kTRUE) {
162 throw(kEH + "no events available.");
164 printf("Reached end of stream (event=%d), rewinding to first event.\n", fEvent);
165 fReader->RewindEvents();
166 fReader->NextEvent();
169 throw(kEH + "last event reached.");
174 void AliEveTPCLoader::GotoEvent(Int_t event)
176 // Go to specified event.
178 static const TEveException kEH("AliEveTPCLoader::GotoEvent ");
181 throw(kEH + "data file not opened.");
186 if (event < fEvent) {
187 fReader->RewindEvents();
195 } while (fEvent != event && !(checkEnd == kTRUE && fEvent == 0));
200 void* AliEveTPCLoader::LoopEvent(AliEveTPCLoader* loader)
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().
208 loader->UpdateSectors();
209 if (gEve->GetEditor()->GetModel() == loader)
210 gEve->EditElement(loader);
214 /******************************************************************************/
216 void AliEveTPCLoader::UpdateSectors(Bool_t dropNonPresent)
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.
222 gEve->DisableRedraw();
223 for (Int_t i=0; i<=35; ++i)
225 AliEveTPCSectorData* sd = fData->GetSectorData(i);
230 if (dropNonPresent && sd == 0) {
231 gEve->RemoveElement(fSec2Ds[i], this);
234 fSec2Ds[i]->IncRTS();
235 fSec2Ds[i]->ElementChanged();
241 AliEveTPCSector2D* s = new AliEveTPCSector2D(Form("Sector2D %d", i));
244 s->SetDataSource(fData);
249 if (fSetInitSectorParams) {
250 s->SetMinTime(fInitMinTime);
251 s->SetMaxTime(fInitMaxTime);
252 s->SetThreshold(fInitThreshold);
253 s->SetMaxVal(fInitMaxVal);
256 s->SetAutoTrans(kTRUE);
257 s->SetFrameColor(36);
259 gEve->AddElement(s, this);
266 if (dropNonPresent && sd == 0) {
267 gEve->RemoveElement(fSec3Ds[i], this);
270 fSec3Ds[i]->IncRTS();
271 fSec3Ds[i]->ElementChanged();
275 gEve->Redraw3D(kTRUE, kFALSE);
276 gEve->EnableRedraw();
279 void AliEveTPCLoader::ReloadSectors()
281 // Reload current event and update sectors.
287 void AliEveTPCLoader::CreateSectors3D()
289 // Create 3D representations of sectors.
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));
298 s->SetDataSource(fData);
301 s->SetDriftVel(2.273);
303 s->CopyVizParams(*fSec2Ds[i]);
305 s->SetAutoTrans(kTRUE);
306 s->SetFrameColor(36);
308 gEve->AddElement(s, this);
311 gEve->EnableRedraw();
314 void AliEveTPCLoader::DeleteSectors3D()
316 // Delete 3D representations of sectors.
318 gEve->DisableRedraw();
319 for (Int_t i=0; i<=35; ++i) {
320 TEveElement* re = fSec3Ds[i];
322 gEve->RemoveElement(re, this);
323 // delete re; // Done automatically.
327 gEve->EnableRedraw();
330 /******************************************************************************/
332 void AliEveTPCLoader::SetInitParams(Int_t mint, Int_t maxt, Int_t thr, Int_t maxval)
334 // Set initial viualization parameters for 2D and 3D sector representations.
336 fSetInitSectorParams = kTRUE;
339 fInitThreshold = thr;
340 fInitMaxVal = maxval;