Fixes for Coverity warnings (M. van Leeuwen)
[u/mrichter/AliRoot.git] / ITS / AliITSLoader.cxx
CommitLineData
9edefa04 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
7ca4655f 18#include <TClonesArray.h>
9edefa04 19#include <TClass.h>
6f5308d9 20#include <TGeoManager.h>
c93255fe 21#include <TTree.h>
9edefa04 22
aacedc3e 23#include "AliITSdigit.h"
88cb7938 24#include "AliITSLoader.h"
7d62fb64 25#include "AliRunLoader.h"
ad7f2bfa 26#include "AliObjectLoader.h"
6def2bd2 27#include "AliITSInitGeometry.h"
13033bec 28#include "AliLog.h"
88cb7938 29
aacedc3e 30///////////////////////////////////////////////////////////////////////////
eeac5f9f 31// Loader for ITS
32// it manages the I/O for:
33// raw clusters, primary vertices
34// V0 and cascade
35// and tracks propagated to the origin
aacedc3e 36//////////////////////////////////////////////////////////////////////////
88cb7938 37const TString AliITSLoader::fgkDefaultRawClustersContainerName = "TreeC";
38const TString AliITSLoader::fgkDefaultBackTracksContainerName = "TreeB";
39const TString AliITSLoader::fgkDefaultVerticesContainerName = "Vertex";
566abf75 40const TString AliITSLoader::fgkDefaultV0ContainerName = "V0";
41const TString AliITSLoader::fgkDefaultCascadeContainerName = "Cascade";
88cb7938 42ClassImp(AliITSLoader)
43
aacedc3e 44/**********************************************************************/
e56160b8 45 AliITSLoader::AliITSLoader():AliLoader(),
e56160b8 46fGeom(0){
eeac5f9f 47 // Default constructor
aacedc3e 48}
49/*********************************************************************/
50AliITSLoader::AliITSLoader(const Char_t *name,const Char_t *topfoldername):
e56160b8 51AliLoader(name,topfoldername),
e56160b8 52fGeom(0){
53 //Constructor
aacedc3e 54 AliDataLoader* rawClustersDataLoader = new AliDataLoader(
55 fDetectorName + ".RawCl.root",fgkDefaultRawClustersContainerName,
56 "Raw Clusters");
57 fDataLoaders->Add(rawClustersDataLoader);
58 rawClustersDataLoader->SetEventFolder(fEventFolder);
59 rawClustersDataLoader->SetFolder(GetDetectorDataFolder());
60
61 AliDataLoader* backTracksDataLoader = new AliDataLoader(
62 fDetectorName + ".BackTracks.root",fgkDefaultBackTracksContainerName,
63 "Back Propagated Tracks");
64 fDataLoaders->Add(backTracksDataLoader);
65 backTracksDataLoader->SetEventFolder(fEventFolder);
66 backTracksDataLoader->SetFolder(GetDetectorDataFolder());
eeac5f9f 67
aacedc3e 68 AliDataLoader* vertexDataLoader = new AliDataLoader(
69 fDetectorName + ".Vertex.root",fgkDefaultVerticesContainerName,
70 "Primary Vertices","O");
71 fDataLoaders->Add(vertexDataLoader);
72 vertexDataLoader->SetEventFolder(fEventFolder);
73 vertexDataLoader->SetFolder(GetDetectorDataFolder());
74
75 AliDataLoader* v0DataLoader = new AliDataLoader(
76 fDetectorName + ".V0s.root",fgkDefaultV0ContainerName,"V0 Vertices");
77 fDataLoaders->Add(v0DataLoader);
78 v0DataLoader->SetEventFolder(fEventFolder);
79 v0DataLoader->SetFolder(GetDetectorDataFolder());
80
81 AliDataLoader* cascadeDataLoader = new AliDataLoader(
82 fDetectorName + ".Cascades.root",fgkDefaultCascadeContainerName,
83 "Cascades");
84 fDataLoaders->Add(cascadeDataLoader);
85 cascadeDataLoader->SetEventFolder(fEventFolder);
86 cascadeDataLoader->SetFolder(GetDetectorDataFolder());
eeac5f9f 87}
aacedc3e 88/**********************************************************************/
89AliITSLoader::AliITSLoader(const Char_t *name,TFolder *topfolder):
e56160b8 90 AliLoader(name,topfolder),
e56160b8 91fGeom(0){
aacedc3e 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());
eeac5f9f 99
aacedc3e 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());
88cb7938 126}
e62c1aea 127
e62c1aea 128
aacedc3e 129/**********************************************************************/
130AliITSLoader::~AliITSLoader(){
131 //destructor
132 AliDataLoader* dl = 0;
133 UnloadRawClusters();
134 dl = GetRawClLoader();
135 fDataLoaders->Remove(dl);
88cb7938 136
aacedc3e 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);
e56160b8 152
8e50d897 153 if(fGeom)delete fGeom;
023ae34b 154 fGeom = 0;
88cb7938 155}
7d62fb64 156/*
aacedc3e 157//----------------------------------------------------------------------
158AliITS* 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;
566abf75 167
aacedc3e 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;
88cb7938 181}
aacedc3e 182//----------------------------------------------------------------------
183void 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.
88cb7938 191
aacedc3e 192 its->SetTreeAddressD(TreeD());
193}
7d62fb64 194*/
aacedc3e 195//----------------------------------------------------------------------
196void 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;
ce189d7c 211 Char_t branch[14];
aacedc3e 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);
ce189d7c 232 if(n==3) snprintf(branch,13,"ITSDigits%s",det[i]);
233 else snprintf(branch,13,"ITSDigits%d",i+1);
aacedc3e 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();
c0fc8108 249 if(n==3) snprintf(branch,13,"ITSDigits%s",det[i]);
250 else snprintf(branch,13,"ITSDigits%d",i+1);
aacedc3e 251 br = td->GetBranch(branch);
252 br->SetAddress(&((*digPerDet)[i]));
253 continue;
254 } // end for i
255}
256//---------------------------------------------------------------------
257AliITSdigit * 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}
7d62fb64 278/*
aacedc3e 279//---------------------------------------------------------------------
280AliITSdigit * 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}
7d62fb64 305*/
aacedc3e 306//----------------------------------------------------------------------
88cb7938 307void AliITSLoader::MakeTree(Option_t *opt){
aacedc3e 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();
88cb7938 322}
7d62fb64 323
324//----------------------------------------------------------------------
8e50d897 325AliITSgeom* AliITSLoader::GetITSgeom(Bool_t force) {
7d62fb64 326 // retrieves the ITS geometry from file
8e50d897 327 if(fGeom && !force)return fGeom;
328 if(fGeom && force){
329 delete fGeom;
330 fGeom = 0;
331 }
6f5308d9 332 if(!gGeoManager){
333 AliError("gGeoManager is a null pointer - ITS geometry not built");
334 return fGeom;
335 }
108bd0fe 336 AliITSInitGeometry initgeom;
6def2bd2 337 fGeom = initgeom.CreateAliITSgeom();
338 AliDebug(1,"AliITSgeom object has been initialized from TGeo\n");
15e6a32c 339 AliDebug(1,Form("Geometry name: %s",(initgeom.GetGeometryName()).Data()));
8e50d897 340 return fGeom;
7d62fb64 341}
023ae34b 342//______________________________________________________________________
343void AliITSLoader::SetITSgeom(AliITSgeom *geom){
344 // Replaces the AliITSgeom object read from file with the one
345 // given.
346 // Inputs:
347 // AliITSgeom *geom The AliITSgeom object to replace the one
348 // read from the file
349 // Outputs:
350 // none.
351 // Return:
352 // none.
353
354 if(fGeom==geom) return; // Same do nothing
355 if(fGeom) {
356 delete fGeom;
357 fGeom=0;
358 }// end if
359 fGeom=geom;
360}