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 <AliTPCRawStreamV3.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),
50 fCutOnEta(kFALSE), fEtaMax(1.5), fEtaMin(-1.5)
54 fData = new AliEveTPCData;
57 AliEveTPCLoader::~AliEveTPCLoader()
65 /******************************************************************************/
67 void AliEveTPCLoader::RemoveElementLocal(TEveElement* el)
69 // Local removal an element, virtual from TEveElement.
70 // Need to search for it in visual sector representations and remove
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;
79 void AliEveTPCLoader::RemoveElementsLocal()
81 // Local removal of all elements, virtual from TEveElement.
82 // Must remove all visual sector representations.
84 for (Int_t i=0; i<36; ++i) {
90 /******************************************************************************/
92 void AliEveTPCLoader::SetData(AliEveTPCData* d)
94 // Set external TPC-data container. The old one is deleted.
100 /******************************************************************************/
102 void AliEveTPCLoader::OpenFile()
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
109 static const TEveException kEH("AliEveTPCLoader::OpenFile ");
111 if (gSystem->AccessPathName(fFile, kReadPermission))
112 throw(kEH + "can not read '" + fFile + "'.");
114 fData->DeleteAllSectors();
120 fReader = new AliRawReaderRoot(fFile);
121 if (fTPCEquipementMap != "")
122 fReader->LoadEquipmentIdsMap
123 (gSystem->ExpandPathName(fTPCEquipementMap.Data()));
127 UpdateSectors(kTRUE);
130 void AliEveTPCLoader::LoadEvent()
134 static const TEveException kEH("AliEveTPCLoader::LoadEvent ");
137 throw(kEH + "data file not opened.");
139 printf("Now loading event %d\n", fEvent);
141 AliTPCRawStreamV3 input(fReader);
142 fReader->Select("TPC");
144 fData->DropAllSectors();
145 fData->LoadRaw(input, kTRUE, kTRUE);
148 void AliEveTPCLoader::NextEvent(Bool_t rewindOnEnd)
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.
154 static const TEveException kEH("AliEveTPCLoader::NextEvent ");
157 throw(kEH + "data file not opened.");
159 if (fReader->NextEvent() == kTRUE) {
163 throw(kEH + "no events available.");
165 printf("Reached end of stream (event=%d), rewinding to first event.\n", fEvent);
166 fReader->RewindEvents();
167 fReader->NextEvent();
170 throw(kEH + "last event reached.");
175 void AliEveTPCLoader::GotoEvent(Int_t event)
177 // Go to specified event.
179 static const TEveException kEH("AliEveTPCLoader::GotoEvent ");
182 throw(kEH + "data file not opened.");
187 if (event < fEvent) {
188 fReader->RewindEvents();
196 } while (fEvent != event && !(checkEnd == kTRUE && fEvent == 0));
201 void* AliEveTPCLoader::LoopEvent(AliEveTPCLoader* loader)
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().
209 loader->UpdateSectors();
210 if (gEve->GetEditor()->GetModel() == loader)
211 gEve->EditElement(loader);
215 /******************************************************************************/
217 void AliEveTPCLoader::UpdateSectors(Bool_t dropNonPresent)
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.
223 gEve->DisableRedraw();
224 for (Int_t i=0; i<=35; ++i)
226 AliEveTPCSectorData* sd = fData->GetSectorData(i);
231 if (dropNonPresent && sd == 0) {
232 gEve->RemoveElement(fSec2Ds[i], this);
235 fSec2Ds[i]->IncRTS();
236 fSec2Ds[i]->ElementChanged();
242 AliEveTPCSector2D* s = new AliEveTPCSector2D(Form("Sector2D %d", i));
245 s->SetDataSource(fData);
250 if (fSetInitSectorParams) {
251 s->SetMinTime(fInitMinTime);
252 s->SetMaxTime(fInitMaxTime);
253 s->SetThreshold(fInitThreshold);
254 s->SetMaxVal(fInitMaxVal);
257 s->SetAutoTrans(kTRUE);
258 s->SetFrameColor(36);
260 gEve->AddElement(s, this);
267 if (dropNonPresent && sd == 0) {
268 gEve->RemoveElement(fSec3Ds[i], this);
271 fSec3Ds[i]->SetCutOnEta(fCutOnEta);
272 fSec3Ds[i]->SetEtaMax(fEtaMax);
273 fSec3Ds[i]->SetEtaMin(fEtaMin);
274 fSec3Ds[i]->IncRTS();
275 fSec3Ds[i]->ElementChanged();
279 gEve->Redraw3D(kTRUE, kFALSE);
280 gEve->EnableRedraw();
283 void AliEveTPCLoader::ReloadSectors()
285 // Reload current event and update sectors.
291 void AliEveTPCLoader::CreateSectors3D()
293 // Create 3D representations of sectors.
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));
302 s->SetDataSource(fData);
303 s->SetCutOnEta(fCutOnEta);
304 s->SetEtaMax(fEtaMax);
305 s->SetEtaMin(fEtaMin);
308 s->SetDriftVel(2.273);
310 s->CopyVizParams(fSec2Ds[i]);
312 s->SetAutoTrans(kTRUE);
313 s->SetFrameColor(36);
315 gEve->AddElement(s, this);
318 gEve->EnableRedraw();
321 void AliEveTPCLoader::DeleteSectors3D()
323 // Delete 3D representations of sectors.
325 gEve->DisableRedraw();
326 for (Int_t i=0; i<=35; ++i) {
327 TEveElement* re = fSec3Ds[i];
329 gEve->RemoveElement(re, this);
330 // delete re; // Done automatically.
334 gEve->EnableRedraw();
337 /******************************************************************************/
339 void AliEveTPCLoader::SetInitParams(Int_t mint, Int_t maxt, Int_t thr, Int_t maxval)
341 // Set initial viualization parameters for 2D and 3D sector representations.
343 fSetInitSectorParams = kTRUE;
346 fInitThreshold = thr;
347 fInitMaxVal = maxval;