1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 //_________________________________________________________________________
19 // A singleton that retrieves objets from an array stored in a Tree on a disk file
20 // 1. AliPHOSDigit from TreeD
22 //*-- Author: Yves Schutz (SUBATECH)
23 //////////////////////////////////////////////////////////////////////////////
27 // --- ROOT system ---
31 // --- Standard library ---
33 // --- AliRoot header files ---
35 #include "AliPHOSIndexToObject.h"
37 ClassImp(AliPHOSIndexToObject)
39 AliPHOSIndexToObject * AliPHOSIndexToObject::fgObjGetter = 0 ;
41 //____________________________________________________________________________
42 AliPHOSIndexToObject::AliPHOSIndexToObject(AliPHOS * det)
44 // ctor called once to initialize the detector in use
49 //____________________________________________________________________________
50 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance()
52 // Returns the pointer of the unique instance already defined
54 AliPHOSIndexToObject * rv = 0 ;
58 cout << "AliPHOSIndexToObject::GetInstance ERROR: not yet initialized" << endl ;
63 //____________________________________________________________________________
64 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance(AliPHOS * det)
66 // Creates and returns the pointer of the unique instance
67 // Must be called only when the environment has changed (a new event for exemple)
69 if ( fgObjGetter ) // delete it if already exists
72 fgObjGetter = new AliPHOSIndexToObject(det) ;
78 //____________________________________________________________________________
79 AliPHOSDigit * AliPHOSIndexToObject::GimeDigit(Int_t index)
81 // returns the object AliPHOSDigit stored at array position index in TreeD
83 AliPHOSDigit * rv = 0 ;
85 if ( index >= fDetector->Digits()->GetEntries() )
86 cout << "AliPHOSIndexToObject::GimeDigit: index " << index << " larger than available entries "
87 << fDetector->Digits()->GetEntries() << endl ;
88 else if ( index != -1)
89 rv = (AliPHOSDigit *) (fDetector->Digits()->At(index) ) ;
94 //____________________________________________________________________________
95 TParticle * AliPHOSIndexToObject::GimePrimaryParticle(Int_t index)
97 // returns the object TParticle stored at array position index in TreeK
101 if ( index >= gAlice->Particles()->GetEntries() )
102 cout << "AliPHOSIndexToObject::GimePrimaryParticles: index " << index << " larger than available entries "
103 << gAlice->Particles()->GetEntries() << endl ;
105 rv = (TParticle *) (gAlice->Particles()->At(index) ) ;
111 //____________________________________________________________________________
112 AliPHOSRecParticle * AliPHOSIndexToObject::GimeRecParticle(Int_t index)
114 // returns the object AliPHOSRecParticle stored at array position index in TreeR/PHOSRP
115 // this one takes more work because the detetor object and the objects in TreeR are not saved at the same time
116 // therefore the links are lost
118 AliPHOSRecParticle * rv = 0 ;
120 AliPHOSRecParticle::RecParticlesList * rplist = *(fDetector->RecParticles()) ;
122 Int_t rpentries = 0 ;
125 rpentries = rplist->GetEntries() ;
127 fReconstruct = gAlice->TreeR() ;
130 fReconstruct->SetBranchAddress( "PHOSRP", &rplist ) ;
131 fReconstruct->GetEvent(0) ;
132 rpentries = rplist->GetEntries() ;
135 if ( index >= rpentries ) // ERROR
136 cout << "AliPHOSIndexToObject::GimeRecParticle: index " << index << " larger than available entries "
137 << rpentries << endl ;
139 rv = (AliPHOSRecParticle *) (*(fDetector->RecParticles()) )->At(index) ;
145 //____________________________________________________________________________
146 AliRecPoint * AliPHOSIndexToObject::GimeRecPoint(Int_t index, TString type)
148 // returns the object AliPHOSRecPoint stored at array position index in TreeR/PHOSEmcRP or TreeR/PHOSPpsdRP
149 // this one takes more work because the detetor object and the objects in TreeR are not saved at the same time
150 // therefore the links are lost
152 AliPHOSRecPoint * rv = 0 ;
154 AliPHOSRecPoint::RecPointsList * emclist = *(fDetector->EmcRecPoints() );
155 AliPHOSRecPoint::RecPointsList * ppsdlist = *(fDetector->PpsdRecPoints() );
157 Int_t emcentries = 0 ;
158 Int_t ppsdentries = 0 ;
161 emcentries = emclist->GetEntries() ;
164 ppsdentries= ppsdlist->GetEntries() ;
166 fReconstruct = gAlice->TreeR() ;
168 if (!emcentries && !ppsdentries) {
169 fReconstruct->SetBranchAddress("PHOSEmcRP",&emclist);
170 fReconstruct->SetBranchAddress("PHOSPpsdRP",&ppsdlist);
171 fReconstruct->GetEvent(0) ;
172 emcentries = emclist->GetEntries() ;
173 ppsdentries= ppsdlist->GetEntries() ;
176 if ( type == "emc" ) {
177 if ( index >= emcentries )
178 cout << "AliPHOSIndexToObject::GimeRecPoint emc: index " << index << " larger than available entries "
179 << emcentries << endl ;
181 rv = (AliPHOSEmcRecPoint *) ( emclist->At(index) ) ;
183 else if ( type == "ppsd" ) {
184 if ( index >= ppsdentries )
185 cout << "AliPHOSIndexToObject::GimeRecPoint ppsd: index " << index << " larger than available entries "
186 << ppsdentries << endl ;
187 else if (index != -1)
188 rv = (AliPHOSPpsdRecPoint *) (ppsdlist->At(index) ) ;
190 cout << "AliPHOSIndexToObject::GimeRecPoint: " << type << " is an unknown type " << endl
191 << " valid types are : emc " << endl
192 << " ppsd " << endl ;
198 //____________________________________________________________________________
199 AliPHOSTrackSegment * AliPHOSIndexToObject::GimeTrackSegment(Int_t index)
201 // returns the object AliPHOSTrackSegment stored at array position index in TreeR/PHOSTS
202 // this one takes more work because the detetor object and the objects in TreeR are not saved at the same time
203 // therefore the links are lost
205 AliPHOSTrackSegment * rv = 0 ;
207 AliPHOSTrackSegment::TrackSegmentsList * tslist = *( fDetector->TrackSegments()) ;
209 Int_t tsentries = 0 ;
212 tsentries = tslist->GetEntries() ;
214 fReconstruct = gAlice->TreeR() ;
217 fReconstruct->SetBranchAddress( "PHOSTS", &tslist ) ;
218 fReconstruct->GetEvent(0) ;
219 tsentries = tslist->GetEntries() ;
222 if ( index >= tsentries ) // ERROR
223 cout << "AliPHOSIndexToObject::GimeTrackSegment: index " << index << " larger than available entries "
224 << tsentries << endl ;
226 rv = (AliPHOSTrackSegment *) (tslist->At(index) ) ;