]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDsegmentArray.cxx
New offline PID code by Prashant
[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 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  Alice segment manager class                                              //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include <TTree.h>
25
26 #include "AliRun.h"
27
28 #include "AliTRDgeometry.h"
29 #include "AliTRDsegmentArray.h"
30 #include "AliTRDdataArray.h"
31
32 ClassImp(AliTRDsegmentArray)
33
34 //_____________________________________________________________________________
35 AliTRDsegmentArray::AliTRDsegmentArray():AliTRDsegmentArrayBase()
36 {
37   //
38   // Default constructor
39   //
40
41 }
42
43 //_____________________________________________________________________________
44 AliTRDsegmentArray::AliTRDsegmentArray(const char *classname, Int_t n)
45                    :AliTRDsegmentArrayBase(classname,n)
46 {
47   //
48   // Constructor creating an array of AliTRDdataArray of size <n>
49   //
50
51   AliTRDdataArray *dataArray;  
52
53   for (Int_t i = 0; i < n; i++) {
54     dataArray = (AliTRDdataArray *) AddSegment(i);
55   }
56
57 }
58
59 //_____________________________________________________________________________
60 AliTRDsegmentArray::AliTRDsegmentArray(AliTRDsegmentArray &a)
61 :AliTRDsegmentArrayBase(a)
62 {
63   //
64   // AliTRDsegmentArray copy constructor
65   //
66
67   a.Copy(*this);
68
69 }
70
71 //_____________________________________________________________________________
72 AliTRDsegmentArray::~AliTRDsegmentArray()
73 {
74   //
75   // AliTRDsegmentArray destructor
76   //
77
78   Delete();
79
80 }
81
82 //_____________________________________________________________________________
83 void AliTRDsegmentArray::Copy(TObject &a) const
84 {
85   //
86   // Copy function
87   //
88
89   AliTRDsegmentArrayBase::Copy(a);
90
91 }
92
93 //_____________________________________________________________________________
94 void AliTRDsegmentArray::Delete()
95 {
96   //
97   // Deletes all detector segments from the array
98   //
99
100   for (Int_t iDet = 0; iDet < fNSegment; iDet++) {
101     ClearSegment(iDet);
102   }
103
104 }
105
106 //_____________________________________________________________________________
107 Bool_t AliTRDsegmentArray::LoadArray(const Char_t *branchname, TTree *tree)
108 {
109   //
110   // Loads all segments of the array from the branch <branchname> of
111   // the digits tree <tree>
112   //
113
114   fTree = tree;
115
116   // Connect the digits tree as default
117   if (!fTree) {
118     printf("AliTRDsegmentArray::LoadArray -- ");
119     printf("Use default TreeD\n");
120     fTree = gAlice->TreeD();
121     if (!fTree) return kFALSE;
122   }
123
124   // Get the branch
125   fBranch = fTree->GetBranch(branchname);
126   if (!fBranch) return kFALSE;
127
128   // Loop through all segments and read them from the tree
129   Bool_t status = kTRUE;
130   for (Int_t iSegment = 0; iSegment < fNSegment; iSegment++) {
131     AliTRDdataArray *dataArray = (AliTRDdataArray *) fSegment->At(iSegment);
132     if (!dataArray) {
133       status = kFALSE;
134       break;    
135     }
136     fBranch->SetAddress(&dataArray);
137     fBranch->GetEntry(iSegment);
138   }
139
140   return status;
141
142 }
143
144 //_____________________________________________________________________________
145 Bool_t AliTRDsegmentArray::StoreArray(const Char_t *branchname, TTree *tree)
146 {
147   //
148   // Stores all segments of the array in the branch <branchname> of 
149   // the digits tree <tree>
150   //
151
152   fTree = tree;
153
154   // Connect the digits tree as default
155   if (!fTree) {
156     printf("AliTRDsegmentArray::StoreArray -- ");
157     printf("Use default TreeD\n");
158     fTree = gAlice->TreeD();
159     if (!fTree) return kFALSE;
160   }
161
162   // Get the branch
163   fBranch = fTree->GetBranch(branchname);
164   if (!fBranch) return kFALSE;
165
166   // Loop through all segments and fill them into the tree
167   Bool_t status = kTRUE;
168   for (Int_t iSegment = 0; iSegment < fNSegment; iSegment++) {
169     const AliTRDdataArray *kDataArray = 
170          (AliTRDdataArray *) AliTRDsegmentArrayBase::At(iSegment);
171     if (!kDataArray) {
172       status = kFALSE;
173       break;
174     }
175     fBranch->SetAddress(&kDataArray);
176     fBranch->Fill();
177   }
178
179   return status;
180
181 }
182
183 //_____________________________________________________________________________
184 AliTRDdataArray *AliTRDsegmentArray::GetDataArray(Int_t det) const
185 {
186   //
187   // Returns the data array for a given detector
188   //
189
190   return ((AliTRDdataArray *) AliTRDsegmentArrayBase::At(det));
191
192 }
193
194 //_____________________________________________________________________________
195 AliTRDdataArray *AliTRDsegmentArray::GetDataArray(Int_t pla
196                                                 , Int_t cha, Int_t sec) const
197 {
198   //
199   // Returns the data array for a given detector
200   //
201
202   if (gAlice) {
203
204     AliTRDgeometry *geo = AliTRDgeometry::GetGeometry(gAlice->GetRunLoader());  
205     Int_t det = geo->GetDetector(pla,cha,sec);
206     return GetDataArray(det);
207
208   }
209   else {
210
211     printf("AliTRDsegmentArray::GetDigits -- ");
212     printf("gAlice is not defined\n");
213     return NULL;
214
215   }
216
217 }