]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpDEManager.cxx
Fixing part of the Coding violation
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDEManager.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 // $MpId: AliMpDEManager.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpDEManager
22 // --------------------
23 // The manager class for definition of detection element types
24 // Authors: Ivana Hrivnacova, IPN Orsay
25 //          Laurent Aphecetche, SUBATECH Nantes
26 //-----------------------------------------------------------------------------
27
28 #include "AliMpDEManager.h"
29 #include "AliMpDEStore.h"
30 #include "AliMpDetElement.h"
31 #include "AliMpConstants.h"
32 #include "AliMpCathodType.h"
33
34 #include "AliLog.h"
35
36 #include <Riostream.h>
37 #include <TClass.h>
38
39 /// \cond CLASSIMP
40 ClassImp(AliMpDEManager)
41 /// \endcond
42
43 const Int_t AliMpDEManager::fgkCoefficient = 100;
44 TArrayI     AliMpDEManager::fgNofDEPerChamber;
45
46 //______________________________________________________________________________
47
48 AliMpDEManager::~AliMpDEManager()
49 {
50 /// Destructor
51 }
52
53 //
54 // static private methods
55 //
56
57 //______________________________________________________________________________
58 AliMpDetElement* AliMpDEManager::GetDetElement(Int_t detElemId, Bool_t warn)
59 {
60 /// Return det element for given detElemId
61
62   return AliMpDEStore::Instance()->GetDetElement(detElemId, warn);
63 }    
64
65 //______________________________________________________________________________
66 AliMpDetElement* AliMpDEManager::GetDetElement(const TString& deName, Bool_t warn)
67 {
68 /// Return det element for given deName
69
70   return AliMpDEStore::Instance()->GetDetElement(deName, warn);
71 }    
72
73 //
74 // static public methods
75 //
76
77 //______________________________________________________________________________
78 Bool_t AliMpDEManager::IsValidDetElemId(Int_t detElemId, Bool_t warn)
79 {
80 /// Return true if detElemId is valid
81 /// (is present in the DE map)
82
83   if ( GetDetElement(detElemId, warn) ) return true;
84
85   return false;
86 }    
87
88 //______________________________________________________________________________
89 Bool_t AliMpDEManager::IsValidChamberId(Int_t chamberId, Bool_t warn)
90 {
91 /// Return true if chamberId is valid
92
93   if ( chamberId >= 0 && chamberId < AliMpConstants::NofChambers() ) 
94     return true;
95  
96   if (warn) 
97     AliErrorClassStream() << "Wrong chamber Id " << chamberId << endl;
98   
99   return false;
100 }    
101
102 //______________________________________________________________________________
103 Bool_t AliMpDEManager::IsValidGeomModuleId(Int_t moduleId, Bool_t warn)
104 {
105 /// Return true if moduleId is valid
106
107   if ( moduleId >= 0 && moduleId < AliMpConstants::NofGeomModules() ) 
108     return true;
109  
110   if (warn) 
111     AliErrorClassStream() << "Wrong module Id " << moduleId << endl;
112   
113   return false;
114 }    
115
116 //______________________________________________________________________________
117 Int_t  AliMpDEManager::GetChamberId(Int_t detElemId, Bool_t warn)
118 {
119 /// Return chamber Id for given detElemId
120
121   if ( ! IsValidDetElemId(detElemId, warn) ) return -1;
122   
123   return detElemId/fgkCoefficient - 1;
124 }  
125
126 //______________________________________________________________________________
127 Int_t AliMpDEManager::GetGeomModuleId(Int_t detElemId, Bool_t warn)
128 {
129 /// <pre>
130 /// Get module Id from detection element Id                 
131 /// !!! moduleId != chamberId
132 /// Station 1:   Chamber:  1   Module:  0   Det elements:  100-103
133 ///              Chamber:  2   Module:  1   Det elements:  200-203
134 /// Station 2:   Chamber:  3   Module:  2   Det elements:  300-303
135 ///              Chamber:  4   Module:  3   Det elements:  400-403
136 /// Station 3:   Chamber:  5   Module:  4   Det elements:  500-504, 514-517
137 ///                            Module:  5   Det elements:  505-513,
138 ///              Chamber:  6   Module:  6   Det elements:  600-604, 614-617
139 ///                            Module:  7   Det elements:  605-613
140 /// Station 4:   Chamber:  7   Module:  8   Det elements:  700-706, 720-725
141 ///                            Module:  9   Det elements:  707-719
142 ///              Chamber:  8   Module: 10   Det elements:  800-806, 820-825
143 ///                            Module: 11   Det elements:  807-819
144 /// Station 5:   Chamber:  9   Module: 12   Det elements:  900-906, 920-925
145 ///                            Module: 13   Det elements:  907-919        
146 ///              Chamber: 10   Module: 14   Det elements: 1000-1006,1020-1025
147 ///                            Module: 15   Det elements: 1007-1019
148 /// Station 6:   Chamber: 11   Module: 16   Det elements: 1100-1117
149 ///              Chamber: 12   Module: 17   Det elements: 1200-1217
150 /// Station 7:   Chamber: 13   Module: 18   Det elements: 1300-1317
151 ///              Chamber: 14   Module: 19   Det elements: 1400-1417
152 /// </pre>
153
154   if ( ! IsValidDetElemId(detElemId, warn) ) return -1;
155   
156   return detElemId/fgkCoefficient 
157            + (detElemId >=  505 && detElemId <=  513 || detElemId >= 600 )
158            + (detElemId >=  605 && detElemId <=  613 || detElemId >= 700 )
159            + (detElemId >=  707 && detElemId <=  719 || detElemId >= 800 )
160            + (detElemId >=  807 && detElemId <=  819 || detElemId >= 900 )
161            + (detElemId >=  907 && detElemId <=  919 || detElemId >= 1000 )
162            + (detElemId >= 1007 && detElemId <= 1019 || detElemId >= 1100 ) - 1;
163 }  
164
165 //______________________________________________________________________________
166 AliMp::PlaneType  AliMpDEManager::GetPlaneType(Int_t detElemId, AliMp::CathodType cath)
167 {
168 /// Return plane type                                                      \n
169 /// Failure causes Fatal error - as AliMp::PlaneType has no possibility
170 /// to return undefined value
171
172   if ( ! IsValidDetElemId(detElemId, true) ) {
173     AliFatalClass("Cannot return AliMp::PlaneType value.");
174     return AliMp::kBendingPlane;
175   }  
176
177   return GetDetElement(detElemId)->GetPlaneType(cath);
178 }    
179
180 //______________________________________________________________________________
181 AliMp::StationType AliMpDEManager::GetStationType(Int_t detElemId)
182 {
183 /// Return station type                                                      \n
184 /// Failure causes Fatal error - as AliMp::StationType has no possibility
185 /// to return undefined value
186
187   if ( ! IsValidDetElemId(detElemId, true) ) {
188     AliFatalClass("Cannot return AliMp::StationType value.");
189     return AliMp::kStation1;
190   }  
191   
192   return GetDetElement(detElemId)->GetStationType();
193 }
194
195 //______________________________________________________________________________
196 AliMp::CathodType 
197 AliMpDEManager::GetCathod(Int_t detElemId, AliMp::PlaneType planeType)
198 {
199 /// Return cathod number for given detElemId and planeType
200
201   if ( ! IsValidDetElemId(detElemId, true) ) {
202     AliFatalClass("Cannot return AliMp::CathodType value.");
203     return AliMp::kCath0;
204   }  
205   
206   return GetDetElement(detElemId)->GetCathodType(planeType);
207 }
208
209 //______________________________________________________________________________
210 Int_t AliMpDEManager::GetNofDEInChamber(Int_t chamberId, Bool_t warn)
211 {
212 /// Return the number of detection elements in the chamber with the given 
213 /// chamberId
214
215   if ( ! IsValidChamberId(chamberId,warn) ) return 0;
216
217   // Fill array if it is empty
218   if ( ! fgNofDEPerChamber.GetSize() ) {
219     fgNofDEPerChamber.Set(AliMpConstants::NofChambers());
220     AliMpDEIterator it;
221     for ( Int_t i=0; i<AliMpConstants::NofChambers(); i++ ) {
222       Int_t counter = 0;
223       for ( it.First(i); ! it.IsDone(); it.Next() ) ++counter;
224       fgNofDEPerChamber[i] = counter;
225     }  
226   }
227   
228   return fgNofDEPerChamber[chamberId];    
229
230 }
231
232 //______________________________________________________________________________
233 AliMpIntPair AliMpDEManager::GetDetElemIdRange(Int_t chamberId)
234 {
235 /// Return the detection element Id range for given chamberId
236  
237   if ( ! IsValidChamberId(chamberId) ) return AliMpIntPair::Invalid();
238
239   return AliMpIntPair(
240            (chamberId+1)*fgkCoefficient,
241            (chamberId+1)*fgkCoefficient + GetNofDEInChamber(chamberId) - 1);
242   
243 }
244