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