]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDsegmentArray.cxx
Bug fix reported by Jiri. Make atoi input zero terminated in StepManager()
[u/mrichter/AliRoot.git] / TRD / AliTRDsegmentArray.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 /*
17 $Log$
18 Revision 1.7  2001/03/13 09:30:35  cblume
19 Update of digitization. Moved digit branch definition to AliTRD
20
21 Revision 1.6  2000/11/01 14:53:21  cblume
22 Merge with TRD-develop
23
24 Revision 1.1.4.3  2000/10/06 16:49:46  cblume
25 Made Getters const
26
27 Revision 1.1.4.2  2000/10/04 16:34:58  cblume
28 Replace include files by forward declarations
29
30 Revision 1.5  2000/10/02 21:28:19  fca
31 Removal of useless dependecies via forward declarations
32
33 Revision 1.4  2000/06/27 13:08:50  cblume
34 Changed to Copy(TObject &A) to appease the HP-compiler
35
36 Revision 1.3  2000/06/08 18:32:58  cblume
37 Make code compliant to coding conventions
38
39 Revision 1.2  2000/05/08 16:17:27  cblume
40 Merge TRD-develop
41
42 Revision 1.1.4.1  2000/05/08 14:55:03  cblume
43 Bug fixes
44
45 Revision 1.1  2000/02/28 19:02:32  cblume
46 Add new TRD classes
47
48 */
49
50 ///////////////////////////////////////////////////////////////////////////////
51 //                                                                           //
52 //  Alice segment manager class                                              //
53 //                                                                           //
54 ///////////////////////////////////////////////////////////////////////////////
55
56 #include <TTree.h>
57
58 #include "AliRun.h"
59
60 #include "AliTRD.h"
61 #include "AliTRDgeometry.h"
62 #include "AliTRDsegmentArray.h"
63 #include "AliTRDdataArray.h"
64
65 ClassImp(AliTRDsegmentArray)
66
67 //_____________________________________________________________________________
68 AliTRDsegmentArray::AliTRDsegmentArray():AliTRDsegmentArrayBase()
69 {
70   //
71   // Default constructor
72   //
73
74 }
75
76 //_____________________________________________________________________________
77 AliTRDsegmentArray::AliTRDsegmentArray(Text_t *classname, Int_t n)
78                    :AliTRDsegmentArrayBase(classname,n)
79 {
80   //
81   // Constructor creating an array of AliTRDdataArray of size <n>
82   //
83
84   AliTRDdataArray *dataArray;  
85
86   for (Int_t i = 0; i < n; i++) {
87     dataArray = (AliTRDdataArray *) AddSegment(i);
88   }
89
90 }
91
92 //_____________________________________________________________________________
93 AliTRDsegmentArray::AliTRDsegmentArray(AliTRDsegmentArray &a)
94 {
95   //
96   // AliTRDsegmentArray copy constructor
97   //
98
99   a.Copy(*this);
100
101 }
102
103 //_____________________________________________________________________________
104 AliTRDsegmentArray::~AliTRDsegmentArray()
105 {
106   //
107   // AliTRDsegmentArray destructor
108   //
109 }
110
111 //_____________________________________________________________________________
112 void AliTRDsegmentArray::Copy(TObject &a)
113 {
114   //
115   // Copy function
116   //
117
118   AliTRDsegmentArrayBase::Copy(a);
119
120 }
121
122 //_____________________________________________________________________________
123 void AliTRDsegmentArray::Delete()
124 {
125   //
126   // Deletes all detector segments from the array
127   //
128
129   for (Int_t iDet = 0; iDet < fNSegment; iDet++) {
130     ClearSegment(iDet);
131   }
132
133 }
134
135 //_____________________________________________________________________________
136 Bool_t AliTRDsegmentArray::LoadArray(const Char_t *branchname, TTree *tree)
137 {
138   //
139   // Loads all segments of the array from the branch <branchname> of
140   // the digits tree <tree>
141   //
142
143   fTree = tree;
144
145   // Connect the digits tree as default
146   if (!fTree) {
147     printf("AliTRDsegmentArray::LoadArray -- ");
148     printf("Use default TreeD\n");
149     fTree = gAlice->TreeD();
150     if (!fTree) return kFALSE;
151   }
152
153   // Get the branch
154   fBranch = fTree->GetBranch(branchname);
155   if (!fBranch) return kFALSE;
156
157   // Loop through all segments and read them from the tree
158   Bool_t status = kTRUE;
159   for (Int_t iSegment = 0; iSegment < fNSegment; iSegment++) {
160     AliTRDdataArray *dataArray = (AliTRDdataArray *) fSegment->At(iSegment);
161     if (!dataArray) {
162       status = kFALSE;
163       break;    
164     }
165     fBranch->SetAddress(&dataArray);
166     fBranch->GetEntry(iSegment);
167   }
168
169   return status;
170
171 }
172
173 //_____________________________________________________________________________
174 Bool_t AliTRDsegmentArray::StoreArray(const Char_t *branchname, TTree *tree)
175 {
176   //
177   // Stores all segments of the array in the branch <branchname> of 
178   // the digits tree <tree>
179   //
180
181   fTree = tree;
182
183   // Connect the digits tree as default
184   if (!fTree) {
185     printf("AliTRDsegmentArray::StoreArray -- ");
186     printf("Use default TreeD\n");
187     fTree = gAlice->TreeD();
188     if (!fTree) return kFALSE;
189   }
190
191   // Get the branch
192   fBranch = fTree->GetBranch(branchname);
193   if (!fBranch) return kFALSE;
194
195   // Loop through all segments and fill them into the tree
196   Bool_t status = kTRUE;
197   for (Int_t iSegment = 0; iSegment < fNSegment; iSegment++) {
198     const AliTRDdataArray *kDataArray = 
199          (AliTRDdataArray *) AliTRDsegmentArrayBase::At(iSegment);
200     if (!kDataArray) {
201       status = kFALSE;
202       break;
203     }
204     fBranch->SetAddress(&kDataArray);
205     fBranch->Fill();
206   }
207
208   return status;
209
210 }
211
212 //_____________________________________________________________________________
213 AliTRDdataArray *AliTRDsegmentArray::GetDataArray(Int_t det) const
214 {
215   //
216   // Returns the data array for a given detector
217   //
218
219   return ((AliTRDdataArray *) AliTRDsegmentArrayBase::At(det));
220
221 }
222
223 //_____________________________________________________________________________
224 AliTRDdataArray *AliTRDsegmentArray::GetDataArray(Int_t pla
225                                                 , Int_t cha, Int_t sec) const
226 {
227   //
228   // Returns the data array for a given detector
229   //
230
231   if (gAlice) {
232
233     AliTRDgeometry *geo = ((AliTRD*) gAlice->GetDetector("TRD"))->GetGeometry();  
234     Int_t det = geo->GetDetector(pla,cha,sec);
235     return GetDataArray(det);
236
237   }
238   else {
239
240     printf("AliTRDsegmentArray::GetDigits -- ");
241     printf("gAlice is not defined\n");
242     return NULL;
243
244   }
245
246 }