]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSGetter.h
IMproved the clean up in the dtor: folders are now deleted (necessary if one wants to
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGetter.h
1 #ifndef ALIPHOSGETTER_H
2 #define ALIPHOSGETTER_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 /* $Id$ */
7
8 //_________________________________________________________________________
9 //  A singleton that returns various objects 
10 //  Should be used on the analysis stage to avoid confusing between different
11 //  branches of reconstruction tree: e.g. reading RecPoints and TS made from 
12 //  another set of RecPoints.
13 // 
14 //  The objects are retrived from folders.  
15 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
16 //    
17
18
19 // --- ROOT system ---
20 #include "TClonesArray.h"
21 #include "TFolder.h"  
22 #include "TTree.h"
23 #include "TFile.h"
24 class TString ;
25 class TParticle ;
26 class TTask ;
27
28 // --- Standard library ---
29 #include <stdlib.h>
30 #include <iostream.h>
31
32 // --- AliRoot header files ---
33
34 #include "AliRun.h"
35 #include "AliPHOS.h" 
36 #include "AliPHOSHit.h" 
37 #include "AliPHOSDigit.h"
38 #include "AliPHOSEmcRecPoint.h"
39 #include "AliPHOSCpvRecPoint.h"
40 #include "AliPHOSTrackSegment.h"
41 #include "AliPHOSRecParticle.h"
42 class AliPHOSGeometry ;
43 class AliPHOSDigitizer ;
44 class AliPHOSSDigitizer ;
45 class AliPHOSClusterizer ;
46 class AliPHOSTrackSegmentMaker ;
47 class AliPHOSPID ;
48
49 class AliPHOSGetter : public TObject {
50   
51  public:
52   
53   AliPHOSGetter(){    // ctor: this is a singleton, the ctor should never be called but cint needs it as public
54     cerr << "ERROR: AliPHOGetter is a singleton default ctor not callable" << endl ;
55     abort() ; 
56   } 
57   AliPHOSGetter(const AliPHOSGetter & obj) {
58     // cpy ctor requested by Coding Convention 
59     // but not yet needed
60     abort() ; 
61   } 
62   
63   virtual ~AliPHOSGetter() ; 
64   
65   void CloseFile() { fFile->Close() ; } 
66   void ListBranches(Int_t event=0) const ;
67   void NewBranch(TString name, Int_t event = 0) ; 
68   Bool_t AliPHOSGetter::NewFile(TString name) ;
69   const Bool_t HasFailed() const { return fFailed ; }
70   Bool_t PostPrimaries(void ) const ;  
71   Bool_t PostHits(void ) const ;  
72   Bool_t PostSDigits(      const char * name,  const char * file = 0) const ;  
73   Bool_t PostDigits(       const char * name ) const ;  
74   Bool_t PostRecPoints(    const char * name ) const ;  
75   Bool_t PostTrackSegments(const char * name) const ;  
76   Bool_t PostRecParticles( const char * name) const ;  
77
78   Bool_t PostClusterizer( const char * name) const ;  
79   Bool_t PostClusterizer(AliPHOSClusterizer * clu) const ;  
80   Bool_t PostSDigitizer (AliPHOSSDigitizer * sdigitizer) const ;  
81   Bool_t PostSDigitizer ( const char * name, const char * file ) const ;  
82   Bool_t PostDigitizer (AliPHOSDigitizer * digitizer) const ;  
83   Bool_t PostDigitizer  ( const char * name) const ;  
84   Bool_t PostTrackSegmentMaker(AliPHOSTrackSegmentMaker * tsm) const ;  
85   Bool_t PostTrackSegmentMaker(const char * name ) const ;  
86   Bool_t PostPID  (AliPHOSPID * pid) const ;  
87   Bool_t PostPID  (const char * name ) const ;  
88   Bool_t PostQA   (void) const ;
89   
90
91   void   Event(const Int_t event, const char * opt = "HSDRP") ;    
92   void   Track(Int_t itrack) ;
93
94   //Method to be used when digitizing under AliRunDigitizer, who opens all files etc.
95   void   ReadTreeS(TTree * treeS,Int_t input) ;
96   
97   Int_t  EventNumber()       { return (Int_t) gAlice->GetEvNumber() ; }
98   Int_t  MaxEvent()          { return (Int_t) gAlice->TreeE()->GetEntries() ; }
99   static AliPHOSGetter * GetInstance(const char* headerFile,
100                                      const char* branchTitle = "Default" ) ; 
101   static AliPHOSGetter *   GetInstance() ; 
102
103   const AliPHOS *         PHOS()  ;  
104   const  AliPHOSGeometry * PHOSGeometry() ; 
105    // Alarms
106   TFolder * Alarms() const { return (TFolder*)(ReturnO("Alarms", 0)) ; }
107   TObjArray *  Alarms(const char * name ) const { return (TObjArray*)(ReturnO("Alarms", name)) ; }
108
109   // QA Tasks
110   TTask * QATasks(const char * name = 0) const { return (TTask*)(ReturnT("QATasks", name)) ; }
111
112   // Primaries
113   TClonesArray *  Primaries(void) const { return (TClonesArray*)(ReturnO("Primaries")) ; }
114   // Hits
115   const TClonesArray *  Hits(void) { return static_cast<const TClonesArray*>(ReturnO("Hits")) ; }
116   const AliPHOSHit * Hit(Int_t index)  { return static_cast<const AliPHOSHit*>(Hits()->At(index) );}
117   
118   // SDigits
119   TClonesArray *  SDigits(const char * name = 0, const char * file=0) { 
120     return static_cast<TClonesArray*>(ReturnO("SDigits", name, file)) ; 
121   }
122   const AliPHOSDigit *  SDigit(Int_t index) { return static_cast<const AliPHOSDigit*>(SDigits()->At(index)) ;}
123   
124   AliPHOSSDigitizer *  SDigitizer(const char * name =0) const { 
125     return ((AliPHOSSDigitizer*)(ReturnT("SDigitizer", name))) ; 
126   }
127   
128   // Digits
129   TClonesArray *  Digits(const char * name = 0)const  { 
130     return static_cast<TClonesArray*>(ReturnO("Digits", name)) ; 
131   }
132   const AliPHOSDigit *  Digit(Int_t index) { return static_cast<const AliPHOSDigit *>(Digits()->At(index)) ;}
133   AliPHOSDigitizer *  Digitizer(const char * name =0) const { 
134     return (AliPHOSDigitizer*)(ReturnT("Digitizer", name)) ; 
135   }
136   
137   // RecPoints
138   TObjArray * EmcRecPoints(const char * name = 0) {
139     return static_cast<TObjArray*>(ReturnO("EmcRecPoints", name)) ; 
140   }
141   TObjArray * CpvRecPoints(const char * name = 0) { 
142     return static_cast<TObjArray*>(ReturnO("CpvRecPoints", name)) ; 
143   }
144   const AliPHOSEmcRecPoint * EmcRecPoint(Int_t index) { 
145     return static_cast<const AliPHOSEmcRecPoint *>(EmcRecPoints()->At(index)) ;
146   }
147   const AliPHOSCpvRecPoint * CpvRecPoint(Int_t index) { 
148     return static_cast<const AliPHOSCpvRecPoint *>(CpvRecPoints()->At(index)) ;  
149   }
150     
151   AliPHOSClusterizer * Clusterizer (const char * name =0) const { 
152     return (AliPHOSClusterizer*)(ReturnT("Clusterizer", name)) ; 
153   }
154   
155   // TrackSegments
156   TClonesArray * TrackSegments(const char * name = 0) { 
157     return static_cast<TClonesArray*>(ReturnO("TrackSegments", name)) ; 
158   }
159   const AliPHOSTrackSegment * TrackSegment(Int_t index) { 
160     return static_cast<const AliPHOSTrackSegment*>(TrackSegments()->At(index)) ; 
161   }
162   AliPHOSTrackSegmentMaker * TrackSegmentMaker (const char * name =0) const { 
163     return (AliPHOSTrackSegmentMaker*)(ReturnT("TrackSegmentMaker", name)) ; 
164   }
165   
166   // RecParticles
167   TClonesArray * RecParticles(const char * name = 0) { 
168     return static_cast<TClonesArray*>(ReturnO("RecParticles", name)) ; 
169   }
170   const AliPHOSRecParticle * RecParticle(Int_t index) { 
171     return static_cast<const AliPHOSRecParticle*>(RecParticles()->At(index)) ; 
172   }
173   AliPHOSPID * PID(const char * name =0) const { 
174     return (AliPHOSPID*)(ReturnT("PID", name)) ; 
175   }
176   
177   // Primaries
178   const TParticle *           Primary(Int_t index) const ;
179   const Int_t                 NPrimaries()const { return fNPrimaries; }
180   const TParticle *           Secondary(TParticle * p, Int_t index=1) const ;
181   
182   void  SetDebug(Int_t level) {fDebug = level;} // Set debug level
183   
184   AliPHOSGetter & operator = (const AliPHOSGetter & ) {
185     // assignement operator requested by coding convention, but not needed
186     abort() ;
187     return *this ; 
188   }
189   
190   TFolder * SDigitsFolder() { return dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("PHOS")) ; }
191
192   void SetRecParticlesTitle(const TString title) { fRecParticlesTitle = title ; }
193   
194 private:
195   
196   AliPHOSGetter(const char* headerFile, const char* branchTitle ="Default") ; 
197   TObject * ReturnO(TString what, TString name=0, TString file=0) const ; 
198   const TTask * ReturnT(TString what,TString name=0) const ; 
199   void DefineBranchTitles(char* branch, char* branchTitle) ;
200   Int_t ReadTreeD() ;
201   Int_t ReadTreeH() ;
202   Int_t ReadTreeR(Bool_t any=kFALSE) ;
203   Int_t ReadTreeS(Int_t event) ;
204   void ReadTreeQA() ;
205   void ReadPrimaries() ;
206
207   TObject** PrimariesRef(void) const ;
208   TObject** HitsRef(void) const ;
209   TObject** SDigitsRef(const char * name, const char * file = 0 ) const;
210   TObject** DigitsRef (const char * name)   const ;
211   TObject** EmcRecPointsRef (const char * name) const ;
212   TObject** CpvRecPointsRef (const char * name) const ;
213   TObject** TrackSegmentsRef(const char * name)   const ;
214   TObject** RecParticlesRef (const char * name)   const ;
215   TObject** AlarmsRef (void)   const ;
216
217   TObject** SDigitizerRef (const char * name) const ; 
218   TObject** DigitizerRef  (const char * name) const ; 
219   TObject** ClusterizerRef(const char * name) const ; 
220   TObject** TSMakerRef    (const char * name) const ; 
221   TObject** PIDRef        (const char * name) const ; 
222
223  private:
224
225   static TFile *        fFile;               //! 
226   TString        fHeaderFile ;        //! File in which gAlice lives
227   TString        fBranchTitle ;       //!
228   TString        fTrackSegmentsTitle ;//! 
229   TString        fRecPointsTitle ;    //!
230   TString        fRecParticlesTitle ; //!
231   TString        fDigitsTitle ;       //! TDirectory tempo(gDirectory) ; 
232
233   TString        fSDigitsTitle ;      //!
234
235   Bool_t         fFailed ;            //! set if file not opend or galice not found
236   Int_t          fDebug ;             // Debug level
237
238   Int_t          fNPrimaries ;        //! # of primaries
239   
240   TObjArray *    fPrimaries ;         //! list of lists of primaries-for the case of mixing
241
242   TFolder *      fModuleFolder ;      //!Folder that contains the modules 
243   TFolder *      fPrimariesFolder ;   //!Folder that contains the Primary Particles 
244   TFolder *      fHitsFolder ;        //!Folder that contains the Hits 
245   TFolder *      fSDigitsFolder ;     //!Folder that contains the SDigits 
246   TFolder *      fDigitsFolder ;      //!Folder that contains the Digits 
247   TFolder *      fRecoFolder ;        //!Folder that contains the reconstructed objects (RecPoints, TrackSegments, RecParticles) 
248   TFolder *      fQAFolder ;          //!Folder that contains the QA objects  
249   TFolder *      fTasksFolder ;       //!Folder that contains the Tasks (sdigitizer, digitizer, reconstructioner)
250  
251   static AliPHOSGetter * fgObjGetter; // pointer to the unique instance of the singleton 
252
253   ClassDef(AliPHOSGetter,1)  // Algorithm class that provides methods to retrieve objects from a list knowing the index 
254
255 };
256
257 #endif // AliPHOSGETTER_H