]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSIndexToObject.cxx
Removal of useless dependecies via forward declarations
[u/mrichter/AliRoot.git] / PHOS / AliPHOSIndexToObject.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id:  */
17
18 //_________________________________________________________________________
19 //  A singleton that retrieves objets from an array stored in a Tree on a disk file
20 //    1. AliPHOSDigit from TreeD     
21 //                  
22 //*-- Author: Yves Schutz (SUBATECH)
23 //////////////////////////////////////////////////////////////////////////////
24
25 // --- ROOT system ---
26
27 #include "TTree.h"
28
29 // --- Standard library ---
30
31 // --- AliRoot header files ---
32
33 #include "AliPHOSIndexToObject.h"
34
35 ClassImp(AliPHOSIndexToObject)
36   
37   AliPHOSIndexToObject * AliPHOSIndexToObject::fgObjGetter = 0 ; 
38
39 //____________________________________________________________________________ 
40 AliPHOSIndexToObject::AliPHOSIndexToObject(AliPHOS * det)
41 {
42   // ctor called once to initialize the detector in use
43
44   fDetector = det ; 
45 }
46
47 //____________________________________________________________________________ 
48 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance()
49 {
50   // Returns the pointer of the unique instance already defined
51   
52   AliPHOSIndexToObject * rv = 0 ;
53   if ( fgObjGetter )
54     rv = fgObjGetter ;
55   else
56     cout << "AliPHOSIndexToObject::GetInstance ERROR: not yet initialized" << endl ;
57   
58   return rv ;
59 }
60
61 //____________________________________________________________________________ 
62 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance(AliPHOS * det)
63 {
64   // Creates and returns the pointer of the unique instance
65   // Must be called only when the environment has changed (a new event for exemple)
66
67   if ( fgObjGetter )      // delete it if already exists
68     delete fgObjGetter ; 
69
70   fgObjGetter = new AliPHOSIndexToObject(det) ; 
71   
72   return fgObjGetter ; 
73   
74 }
75
76 //____________________________________________________________________________ 
77 AliPHOSDigit * AliPHOSIndexToObject::GimeDigit(Int_t index)
78 {
79   // returns the object AliPHOSDigit stored at array position index in TreeD
80
81   AliPHOSDigit * rv = 0 ; 
82
83   if ( index >= fDetector->Digits()->GetEntries() ) 
84     cout << "AliPHOSIndexToObject::GimeDigit: index " << index << " larger than available entries " 
85          <<  fDetector->Digits()->GetEntries() << endl ; 
86   else if ( index != -1) 
87     rv =  (AliPHOSDigit *) (fDetector->Digits()->At(index) ) ; 
88
89   return rv ;
90   
91 }
92 //____________________________________________________________________________ 
93 TParticle * AliPHOSIndexToObject::GimePrimaryParticle(Int_t index)
94 {
95   // returns the object TParticle stored at array position index in TreeK
96
97   TParticle * rv = 0 ; 
98      
99   if ( index >= gAlice->Particles()->GetEntries() ) 
100     cout << "AliPHOSIndexToObject::GimePrimaryParticles: index " << index << " larger than available entries " 
101          <<  gAlice->Particles()->GetEntries() << endl ; 
102   else 
103     rv =  (TParticle *) (gAlice->Particles()->At(index) ) ; 
104
105   return rv ;
106   
107 }
108
109 //____________________________________________________________________________ 
110 AliPHOSRecParticle * AliPHOSIndexToObject::GimeRecParticle(Int_t index)
111 {
112   // returns the object AliPHOSRecParticle stored at array position index in TreeR/PHOSRP
113   // this one takes more work because the detetor object and the objects in TreeR are not saved at the same time
114   // therefore the links are lost
115
116   AliPHOSRecParticle * rv = 0 ; 
117
118   AliPHOSRecParticle::RecParticlesList * rplist = *(fDetector->RecParticles()) ; 
119
120   Int_t rpentries  = 0 ; 
121
122   if (rplist) 
123     rpentries = rplist->GetEntries() ;
124   
125   fReconstruct = gAlice->TreeR() ; 
126   
127   if (!rpentries) {
128     fReconstruct->SetBranchAddress( "PHOSRP", &rplist ) ;
129     fReconstruct->GetEvent(0) ;
130     rpentries = rplist->GetEntries() ;  
131   }     
132   
133   if ( index >= rpentries )  // ERROR 
134     cout << "AliPHOSIndexToObject::GimeRecParticle: index " << index << " larger than available entries " 
135            <<  rpentries << endl ; 
136   else 
137     rv =  (AliPHOSRecParticle *) (*(fDetector->RecParticles()) )->At(index)  ; 
138   
139   return rv ;
140   
141 }
142
143 //____________________________________________________________________________ 
144 AliRecPoint * AliPHOSIndexToObject::GimeRecPoint(Int_t index, TString type)
145 {
146   // returns the object AliPHOSRecPoint stored at array position index in TreeR/PHOSEmcRP or TreeR/PHOSPpsdRP
147   // this one takes more work because the detetor object and the objects in TreeR are not saved at the same time
148   // therefore the links are lost
149
150   AliPHOSRecPoint * rv = 0 ; 
151   
152   AliPHOSRecPoint::RecPointsList * emclist = *(fDetector->EmcRecPoints() ); 
153   AliPHOSRecPoint::RecPointsList * ppsdlist = *(fDetector->PpsdRecPoints() ); 
154
155   Int_t emcentries  = 0 ; 
156   Int_t ppsdentries = 0 ; 
157
158   if (emclist) 
159     emcentries = emclist->GetEntries() ;
160
161   if (ppsdlist)
162     ppsdentries= ppsdlist->GetEntries() ;
163
164   fReconstruct = gAlice->TreeR() ; 
165   
166   if (!emcentries && !ppsdentries) {
167     fReconstruct->SetBranchAddress("PHOSEmcRP",&emclist);
168     fReconstruct->SetBranchAddress("PHOSPpsdRP",&ppsdlist);
169     fReconstruct->GetEvent(0) ;
170     emcentries = emclist->GetEntries() ;
171     ppsdentries= ppsdlist->GetEntries() ;
172   }     
173
174   if ( type == "emc" ) {
175     if ( index >= emcentries ) 
176       cout << "AliPHOSIndexToObject::GimeRecPoint emc: index " << index << " larger than available entries " 
177            <<  emcentries << endl ; 
178     else 
179       rv =  (AliPHOSEmcRecPoint *) ( emclist->At(index) ) ;
180   } 
181   else if ( type == "ppsd" ) {  
182     if ( index >= ppsdentries ) 
183       cout << "AliPHOSIndexToObject::GimeRecPoint ppsd: index " << index << " larger than available entries " 
184            <<  ppsdentries << endl ; 
185     else if (index != -1) 
186       rv =  (AliPHOSPpsdRecPoint *) (ppsdlist->At(index) ) ;
187   } else
188     cout << "AliPHOSIndexToObject::GimeRecPoint: " << type << " is an unknown type " << endl
189          << " valid types are : emc " << endl 
190          << "                   ppsd " << endl ;
191   
192   return rv ;
193   
194 }
195
196 //____________________________________________________________________________ 
197 AliPHOSTrackSegment * AliPHOSIndexToObject::GimeTrackSegment(Int_t index)
198 {
199   // returns the object AliPHOSTrackSegment stored at array position index in TreeR/PHOSTS
200   // this one takes more work because the detetor object and the objects in TreeR are not saved at the same time
201   // therefore the links are lost
202
203   AliPHOSTrackSegment * rv = 0 ; 
204
205   AliPHOSTrackSegment::TrackSegmentsList * tslist = *( fDetector->TrackSegments()) ; 
206
207   Int_t tsentries  = 0 ; 
208
209   if (tslist) 
210     tsentries = tslist->GetEntries() ;
211   
212   fReconstruct = gAlice->TreeR() ; 
213   
214   if (!tsentries) {
215     fReconstruct->SetBranchAddress( "PHOSTS", &tslist ) ;
216     fReconstruct->GetEvent(0) ;
217     tsentries = tslist->GetEntries() ;  
218   }     
219   
220   if ( index >= tsentries )  // ERROR 
221       cout << "AliPHOSIndexToObject::GimeTrackSegment: index " << index << " larger than available entries " 
222            <<  tsentries << endl ; 
223   else 
224     rv =  (AliPHOSTrackSegment *) (tslist->At(index) ) ; 
225   
226   return rv ;
227   
228 }