- Revised comments and adapted them for Doxygen
[u/mrichter/AliRoot.git] / MUON / AliMUONSegmentation.cxx
CommitLineData
fb921a27 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * SigmaEffect_thetadegrees *
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 purpeateose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// $Id$
17//
490da820 18// ----------------------------
fb921a27 19// Class AliMUONSegmentation
20// ----------------------------
21// Manager class for geometry construction via geometry builders.
fb921a27 22// Author: Ivana Hrivnacova, IPN Orsay
23
24#include <iostream>
25
26#include <TObjArray.h>
27
28#include "AliMUONSegmentation.h"
29#include "AliMUONVGeometryDESegmentation.h"
30#include "AliMUONGeometrySegmentation.h"
e81a0d4f 31#include "AliMUONGeometryStore.h"
32
33#include "AliMpVSegmentation.h"
34
fb921a27 35#include "AliLog.h"
36
a9aad96e 37/// \cond CLASSIMP
fb921a27 38ClassImp(AliMUONSegmentation)
a9aad96e 39/// \endcond
fb921a27 40
41//______________________________________________________________________________
42AliMUONSegmentation::AliMUONSegmentation(Int_t nofModules)
43 : TObject(),
e81a0d4f 44 fMpSegmentations(0),
fb921a27 45 fDESegmentations(0)
46{
47/// Standard constructor
48
e81a0d4f 49 // Create array for mapping segmentations
50 fMpSegmentations = new TObjArray();
51 fMpSegmentations->SetOwner(kTRUE);
52
fb921a27 53 // Create array for DE segmentations
54 fDESegmentations = new TObjArray();
55 fDESegmentations->SetOwner(kTRUE);
56
57 // Create array for modules segmentations
58 for (Int_t cathod = 0; cathod < 2; cathod++) {
59 fModuleSegmentations[cathod] = new TObjArray(nofModules);
60 fModuleSegmentations[cathod]->SetOwner(true);
61
62 for (Int_t i=0; i<nofModules; i++)
63 fModuleSegmentations[cathod]->AddAt(0, i);
64 }
65
66 AliDebug(1, Form("ctor this = %p", this) );
67}
68
69//______________________________________________________________________________
70AliMUONSegmentation::AliMUONSegmentation()
71 : TObject(),
e81a0d4f 72 fMpSegmentations(0),
fb921a27 73 fDESegmentations(0)
74{
75/// Default constructor
76
77 fModuleSegmentations[0] = 0;
78 fModuleSegmentations[1] = 0;
79
80 AliDebug(1, Form("default (empty) ctor this = %p", this));
81}
82
83//______________________________________________________________________________
fb921a27 84AliMUONSegmentation::~AliMUONSegmentation()
85{
86/// Destructor
87
88 AliDebug(1, Form("dtor this = %p", this));
89
e81a0d4f 90 delete fMpSegmentations;
fb921a27 91 delete fDESegmentations;
92 delete fModuleSegmentations[0];
93 delete fModuleSegmentations[1];
94}
95
fb921a27 96//
97// public functions
98//
99
100//_____________________________________________________________________________
e81a0d4f 101void AliMUONSegmentation::AddMpSegmentation(AliMpVSegmentation* segmentation)
102{
103/// Add the mapping segmentation to the array if not present
104
105 Bool_t isPresent = false;
106 for (Int_t i=0; i<fMpSegmentations->GetEntries(); i++)
107 if ( (AliMpVSegmentation*)fMpSegmentations->At(i) == segmentation ) {
108 isPresent = true;
109 break;
110 }
111
112 if (!isPresent) fMpSegmentations->Add(segmentation);
113}
114
115//_____________________________________________________________________________
fb921a27 116void AliMUONSegmentation::AddDESegmentation(
e81a0d4f 117 AliMUONVGeometryDESegmentation* segmentation)
fb921a27 118{
119/// Add the DE segmentation to the array
120
121 fDESegmentations->Add(segmentation);
e81a0d4f 122
123 // Deregister the mapping segmentation contained in DE segmentation
124 // from fMpSegmentations, if present
125 const AliMpVSegmentation* kmpSeg = segmentation->GetMpSegmentation();
126
127 for (Int_t i=0; i<fMpSegmentations->GetEntries(); i++)
128 if ( (const AliMpVSegmentation*)fMpSegmentations->At(i) == kmpSeg ) {
129 fMpSegmentations->RemoveAt(i);
130 break;
131 }
fb921a27 132}
133
134//_____________________________________________________________________________
135void AliMUONSegmentation::AddModuleSegmentation(Int_t moduleId, Int_t cathod,
136 AliMUONGeometrySegmentation* segmentation)
137{
138/// Add the module segmentation to the array
139
140 if (cathod < 0 || cathod >= 2) {
141 AliErrorStream()
142 << "Cathod: " << cathod << " outside limits" << std::endl;
143 return;
144 }
145
146 if (moduleId < 0 || moduleId >= fModuleSegmentations[cathod]->GetEntriesFast()) {
147 AliErrorStream()
148 << "Module Id: " << moduleId << " outside limits" << std::endl;
149 return;
150 }
151
152 fModuleSegmentations[cathod]->AddAt(segmentation, moduleId);
153}
154
155//_____________________________________________________________________________
156void AliMUONSegmentation::Init()
157{
158/// Initialize all segmentations
159
160 for (Int_t cathod = 0; cathod < 2; cathod++) {
161 for (Int_t i = 0; i < fModuleSegmentations[cathod]->GetEntriesFast(); i++) {
162
163 AliMUONGeometrySegmentation* moduleSegmentation
164 = (AliMUONGeometrySegmentation*)fModuleSegmentations[cathod]->At(i);
165
166 if (moduleSegmentation) moduleSegmentation->Init(i);
167 }
168 }
169}
170
171//_____________________________________________________________________________
172AliMUONGeometrySegmentation*
173AliMUONSegmentation::GetModuleSegmentation(
174 Int_t moduleId, Int_t cathod, Bool_t warn) const
175{
a9aad96e 176/// Return the geometry module segmentation specified by moduleId
fb921a27 177
178 if (cathod < 0 || cathod >= 2) {
179 if (warn) {
180 AliWarningStream()
181 << "Cathod: " << cathod << " outside limits" << std::endl;
182 }
183 return 0;
184 }
185
186 if (moduleId < 0 || moduleId >= fModuleSegmentations[cathod]->GetEntriesFast()) {
187 if (warn) {
188 AliWarningStream()
189 << "Index: " << moduleId << " outside limits" << std::endl;
190 }
191 return 0;
192 }
193
194 return (AliMUONGeometrySegmentation*)
195 fModuleSegmentations[cathod]->At(moduleId);
196}
197
198//_____________________________________________________________________________
199AliMUONGeometrySegmentation*
200AliMUONSegmentation::GetModuleSegmentationByDEId(
201 Int_t detElemId, Int_t cathod, Bool_t warn) const
202{
203/// Return the geometry module specified by detElemId/cathod
204
205 // Get moduleId
e81a0d4f 206 Int_t moduleId = AliMUONGeometryStore::GetModuleId(detElemId);
fb921a27 207
208 return GetModuleSegmentation(moduleId, cathod, warn);
209}
210
211//_____________________________________________________________________________
212const AliMUONVGeometryDESegmentation*
213AliMUONSegmentation::GetDESegmentation(
214 Int_t detElemId, Int_t cathod, Bool_t warn) const
215{
216/// Return the DE segmentation specified by detElemId/cathod
217
218 // Get geometry segmentation
219 AliMUONGeometrySegmentation* moduleSegmentation
220 = GetModuleSegmentationByDEId(detElemId, cathod, warn);
221
222 if ( !moduleSegmentation ) return 0;
223
f1b4bfb7 224 return moduleSegmentation->GetDESegmentation(detElemId, warn);
fb921a27 225}
226
227//_____________________________________________________________________________
228const AliMpVSegmentation*
229AliMUONSegmentation::GetMpSegmentation(
230 Int_t detElemId, Int_t cathod, Bool_t warn) const
231{
232/// Return the mapping segmentation specified by detElemId/cathod
233
234
235 // Get DE segmentation
236 const AliMUONVGeometryDESegmentation* kdeSegmentation
237 = GetDESegmentation(detElemId, cathod, warn);
238
239 if ( !kdeSegmentation ) return 0;
240
241 return kdeSegmentation->GetMpSegmentation();
242}
243
244//_____________________________________________________________________________
245Bool_t
246AliMUONSegmentation::HasDE(Int_t detElemId, Int_t cathod) const
247{
a9aad96e 248/// Return true if segmentation for detElemId and cathod is defined.
249
f1b4bfb7 250 const AliMUONVGeometryDESegmentation* kdeSegmentation
251 = GetDESegmentation(detElemId, cathod, false);
fb921a27 252
f1b4bfb7 253 return ( kdeSegmentation != 0 );
fb921a27 254
255}
256
257//_____________________________________________________________________________
258TString
259AliMUONSegmentation::GetDEName(Int_t detElemId, Int_t cathod) const
260{
a9aad96e 261/// Get detection element name
fb921a27 262
fb921a27 263 AliMUONGeometrySegmentation* moduleSegmentation
264 = GetModuleSegmentationByDEId(detElemId, cathod, true);
265
266 return moduleSegmentation->GetDEName(detElemId);
267}
268
269