]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSLoader.cxx
effc++ warnings corrected
[u/mrichter/AliRoot.git] / ITS / AliITSLoader.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 #include <TClonesArray.h>
19 #include <TClass.h>
20
21 #include "AliITSdigit.h"
22 #include "AliITSLoader.h"
23 #include "AliRunLoader.h"
24 #include "AliITSInitGeometry.h"
25 #include "AliLog.h"
26
27 ///////////////////////////////////////////////////////////////////////////
28 // Loader for ITS
29 // it manages the I/O for:
30 // raw clusters, primary vertices
31 // V0 and cascade
32 // and tracks propagated to the origin
33 //////////////////////////////////////////////////////////////////////////
34 const TString AliITSLoader::fgkDefaultRawClustersContainerName = "TreeC";
35 const TString AliITSLoader::fgkDefaultBackTracksContainerName = "TreeB";
36 const TString AliITSLoader::fgkDefaultVerticesContainerName = "Vertex";
37 const TString AliITSLoader::fgkDefaultV0ContainerName = "V0";
38 const TString AliITSLoader::fgkDefaultCascadeContainerName = "Cascade";
39 ClassImp(AliITSLoader)
40
41 /**********************************************************************/
42   AliITSLoader::AliITSLoader():AliLoader(),
43 fITSpid(0),
44 fGeom(0){
45   // Default constructor
46 }
47 /*********************************************************************/
48 AliITSLoader::AliITSLoader(const Char_t *name,const Char_t *topfoldername):
49 AliLoader(name,topfoldername),
50 fITSpid(0),
51 fGeom(0){
52   //Constructor   
53     AliDataLoader* rawClustersDataLoader = new AliDataLoader(
54         fDetectorName + ".RawCl.root",fgkDefaultRawClustersContainerName,
55         "Raw Clusters");
56     fDataLoaders->Add(rawClustersDataLoader);
57     rawClustersDataLoader->SetEventFolder(fEventFolder);
58     rawClustersDataLoader->SetFolder(GetDetectorDataFolder());
59
60     AliDataLoader* backTracksDataLoader =  new AliDataLoader(
61         fDetectorName + ".BackTracks.root",fgkDefaultBackTracksContainerName,
62         "Back Propagated Tracks");
63     fDataLoaders->Add(backTracksDataLoader);
64     backTracksDataLoader->SetEventFolder(fEventFolder);
65     backTracksDataLoader->SetFolder(GetDetectorDataFolder());
66
67     AliDataLoader* vertexDataLoader = new AliDataLoader(
68         fDetectorName + ".Vertex.root",fgkDefaultVerticesContainerName,
69         "Primary Vertices","O");
70     fDataLoaders->Add(vertexDataLoader);
71     vertexDataLoader->SetEventFolder(fEventFolder);
72     vertexDataLoader->SetFolder(GetDetectorDataFolder());
73
74     AliDataLoader* v0DataLoader = new AliDataLoader(
75         fDetectorName + ".V0s.root",fgkDefaultV0ContainerName,"V0 Vertices");
76     fDataLoaders->Add(v0DataLoader);
77     v0DataLoader->SetEventFolder(fEventFolder);
78     v0DataLoader->SetFolder(GetDetectorDataFolder());
79
80     AliDataLoader* cascadeDataLoader = new AliDataLoader(
81         fDetectorName + ".Cascades.root",fgkDefaultCascadeContainerName,
82         "Cascades");
83     fDataLoaders->Add(cascadeDataLoader);
84     cascadeDataLoader->SetEventFolder(fEventFolder);
85     cascadeDataLoader->SetFolder(GetDetectorDataFolder());
86 }
87 /**********************************************************************/
88 AliITSLoader::AliITSLoader(const Char_t *name,TFolder *topfolder): 
89   AliLoader(name,topfolder),
90 fITSpid(0),
91 fGeom(0){
92   //ctor  
93     AliDataLoader*  rawClustersDataLoader = new AliDataLoader(
94         fDetectorName + ".RawCl.root",fgkDefaultRawClustersContainerName,
95         "Raw Clusters"); 
96     fDataLoaders->Add(rawClustersDataLoader);
97     rawClustersDataLoader->SetEventFolder(fEventFolder);
98     rawClustersDataLoader->SetFolder(GetDetectorDataFolder());
99
100     AliDataLoader*  backTracksDataLoader =  new AliDataLoader(
101         fDetectorName + ".BackTracks.root",fgkDefaultBackTracksContainerName,
102         "Back Propagated Tracks");
103     fDataLoaders->Add(backTracksDataLoader);
104     backTracksDataLoader->SetEventFolder(fEventFolder);
105     backTracksDataLoader->SetFolder(GetDetectorDataFolder());
106
107     AliDataLoader* vertexDataLoader = new AliDataLoader(
108         fDetectorName + ".Vertex.root",fgkDefaultVerticesContainerName,
109         "Primary Vertices","O");
110     fDataLoaders->Add(vertexDataLoader);
111     vertexDataLoader->SetEventFolder(fEventFolder);
112     vertexDataLoader->SetFolder(GetDetectorDataFolder());
113
114     AliDataLoader* v0DataLoader = new AliDataLoader(
115         fDetectorName + ".V0.root",fgkDefaultV0ContainerName,"V0 Vertices");
116     fDataLoaders->Add(v0DataLoader);
117     v0DataLoader->SetEventFolder(fEventFolder);
118     v0DataLoader->SetFolder(GetDetectorDataFolder());
119
120     AliDataLoader* cascadeDataLoader = new AliDataLoader(
121         fDetectorName + ".Cascade.root",fgkDefaultCascadeContainerName,
122         "Cascades");
123     fDataLoaders->Add(cascadeDataLoader);
124     cascadeDataLoader->SetEventFolder(fEventFolder);
125     cascadeDataLoader->SetFolder(GetDetectorDataFolder());
126 }
127
128
129 /**********************************************************************/
130 AliITSLoader::~AliITSLoader(){
131     //destructor
132     AliDataLoader* dl = 0;
133     UnloadRawClusters();
134     dl = GetRawClLoader();
135     fDataLoaders->Remove(dl);
136
137     UnloadBackTracks();
138     dl = GetBackTracksDataLoader();
139     fDataLoaders->Remove(dl);
140
141     UnloadVertices();
142     dl = GetVertexDataLoader();
143     fDataLoaders->Remove(dl);
144
145     UnloadV0s();
146     dl = GetV0DataLoader();
147     fDataLoaders->Remove(dl);
148
149     UnloadCascades();
150     dl = GetCascadeDataLoader();
151     fDataLoaders->Remove(dl);
152   
153     if(fGeom)delete fGeom;
154     fGeom = 0;
155 }
156 /*
157 //----------------------------------------------------------------------
158 AliITS* AliITSLoader::GetITS(){
159     // Returns the pointer to the ITS, kept on the file. A short cut metthod
160     // Inputs:
161     //    none.
162     // Outputs:
163     //    none.
164     // Returns:
165     //    Returns a pointer to the ITS, if not found returns 0.
166     AliITS *its;
167
168     if(gAlice){
169         its = dynamic_cast<AliITS*> (gAlice->GetDetector(
170             GetDetectorName().Data()));
171         if(its) return its;
172     } // end if gAlice
173     AliRunLoader *rl=0;
174     rl = GetRunLoader();
175     if(!rl) return 0;
176     AliRun *ar=0;
177     ar = rl->GetAliRun();
178     if(!ar) return 0;
179     its = dynamic_cast<AliITS*> (ar->GetDetector(GetDetectorName().Data()));
180     return its;
181 }
182 //----------------------------------------------------------------------
183 void AliITSLoader::SetupDigits(AliITS *its){
184     // Sets up to store ITS Digits in side AliITS::fDtype TObjArray
185     // Inputs:
186     //    AliITS *its  Pointer to the ITS
187     // Outputs:
188     //    none.
189     // Return:
190     //    none.
191
192     its->SetTreeAddressD(TreeD());
193 }
194 */
195 //----------------------------------------------------------------------
196 void AliITSLoader::SetupDigits(TObjArray *digPerDet,Int_t n,
197                                const Char_t **digclass){
198     // Sets up digPerDet to store ITS Digits.
199     // Inputs:
200     //    TObjArray *digPerDet   A pointer to a TObject Array size>=3.
201     //    Int_t      n           The size of the TObjArray and digclass array
202     //    Char_t     **digclass  Array of digit class names
203     // Outputs:
204     //    TObjArray *digPerDet   Setup and linked to the tree of digits
205     // Return:
206     //    none.
207     Int_t i,m;
208     TClonesArray *cl = 0;
209     TTree *td = 0;
210     TBranch *br = 0;
211     Char_t branch[13];
212     const Char_t *det[3] = {"SPD","SDD","SSD"};
213
214     if(!digPerDet){
215         Error("SetUpDigits","TObject Array digPerDet does not exist");
216         return;
217     } // end if
218     m = digPerDet->GetSize();
219     if(m<n){
220         Error("SetUpDigits","TObject Array digPerDet=%p must have a size"
221               " at least that of n=%d",digPerDet,n);
222     } // end if
223     if(m<3){
224         Error("SetUpDigits","TObject Array digPerDet=%p must have a size >2",
225               digPerDet);
226         return;
227     } // end if
228     td = TreeD();
229     for(i=0;i<n;i++){
230         if(digPerDet->At(i)==0){ // set up TClones Array
231             digPerDet->AddAt(new TClonesArray(digclass[i],1000),i);
232             if(n==3) sprintf(branch,"ITSDigits%s",det[i]);
233             else     sprintf(branch,"ITSDigits%d",i+1);
234             br = td->GetBranch(branch);
235             br->SetAddress(&((*digPerDet)[i]));
236             continue; // do next one.
237         } // end if
238         cl =  dynamic_cast<TClonesArray*> (digPerDet->At(i));
239         if(!cl && digPerDet->At(i)!=0){  // not a TClonesArray
240             Error("SetUpDigits","TObject Array digPerDet-At(%d)=%p must be "
241                   "zeroed or filled with TClonesArrays",i,digPerDet);
242             return;
243         } // end if
244         if(!(cl->GetClass()->GetBaseClass(AliITSdigit::Class()))){
245             Error("SetUPDigits","TClones array at digPerDet[%d}=%p must be"
246                   "derived from AliITSdigit",i,digPerDet->At(i));
247         } // end if
248         cl->Clear();
249         if(n==3) sprintf(branch,"ITSDigits%s",det[i]);
250         else     sprintf(branch,"ITSDigits%d",i+1);
251         br = td->GetBranch(branch);
252         br->SetAddress(&((*digPerDet)[i]));
253         continue;
254     } // end for i
255 }
256 //---------------------------------------------------------------------
257 AliITSdigit * AliITSLoader::GetDigit(TObjArray *digPerDet,Int_t module,
258                                      Int_t digit){
259     // Gets the digit for for a specific detector type and module.
260     // To be used in conjustion with Setupdigits(AliITS *its).
261     // Inputs:
262     //   TObjArray *digPereDet    Pointer to the Array of digits
263     //   Int_t      module        Module number
264     //   Int_t      digit         Digit number
265     // Outputs:
266     //   none.
267     // Return:
268     //   returns the pointer to the digit. if zero then last digit for that
269     //   module.
270
271     if(digPerDet==0){
272         Error("GetDigit","digPerDet=%p, module=%d, digit=%d",
273               digPerDet,module,digit);
274         return 0;
275     } // end if
276     return 0;
277 }
278 /*
279 //---------------------------------------------------------------------
280 AliITSdigit * AliITSLoader::GetDigit(AliITS *its,Int_t module,Int_t digit){
281     // Gets the digit for for a specific detector type and module.
282     // To be used in conjustion with Setupdigits(AliITS *its).
283     // Inputs:
284     //   AliITS *its    Pointer to the ITS
285     //   Int_t  module  Module number
286     //   Int_t digit    Digit number
287     // Outputs:
288     //   none.
289     // Return:
290     //   returns the pointer to the digit. if zero then last digit for that
291     //   module.
292     //AliITSDetType *idtype;
293     AliITSgeom *geom = its->GetITSgeom();
294     Int_t idet = geom->GetModuleType(module);
295     TClonesArray *digits;
296  
297     its->ResetDigits();
298     TreeD()->GetEvent(module);
299     digits = its->DigitsAddress(idet);
300     if(digit>-1 && digit<digits->GetEntriesFast()){ // if in range.
301         return (AliITSdigit*) digits->At(digit);
302     } // end if
303     return 0;
304 }
305 */
306 //----------------------------------------------------------------------
307 void AliITSLoader::MakeTree(Option_t *opt){
308     // invokes AliLoader::MakeTree + specific ITS tree(s)
309     // Valid options: H,S,D,R,T and C (C=raw clusters)
310     AliLoader::MakeTree(opt);
311     const char *oC = strstr(opt,"C");
312     if (oC) MakeRawClustersContainer();
313
314     const char *oB = strstr(opt,"B");
315     if (oB) MakeBackTracksContainer();
316
317     const char *oV0 = strstr(opt,"V0");
318     if (oV0) MakeV0Container();
319
320     const char *oX = strstr(opt,"X");
321     if (oX) MakeCascadeContainer();
322 }
323
324 //----------------------------------------------------------------------
325 AliITSgeom* AliITSLoader::GetITSgeom(Bool_t force) {
326   // retrieves the ITS geometry from file
327   if(fGeom && !force)return fGeom;
328   if(fGeom && force){
329     delete fGeom;
330     fGeom = 0;
331   }
332   AliITSInitGeometry initgeom;
333   fGeom = initgeom.CreateAliITSgeom();
334   AliDebug(1,"AliITSgeom object has been initialized from TGeo\n");
335   AliInfo(Form("Geometry name: %s",(initgeom.GetGeometryName()).Data()));
336   return fGeom;
337 }
338 //______________________________________________________________________
339 void AliITSLoader::SetITSgeom(AliITSgeom *geom){
340     // Replaces the AliITSgeom object read from file with the one
341     // given.
342     // Inputs:
343     //   AliITSgeom *geom   The AliITSgeom object to replace the one
344     //                      read from the file
345     // Outputs:
346     //   none.
347     // Return:
348     //   none.
349
350     if(fGeom==geom) return; // Same do nothing
351     if(fGeom) {
352         delete fGeom;
353         fGeom=0;
354     }// end if
355     fGeom=geom;
356 }
357