]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpDetElement.cxx
In mapping:
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpDetElement.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: AliMpDetElement.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
18 // Category: management
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpDetElement
22 // --------------------
23 // The class defines the electronics properties of detection element
24 // Authors: Ivana Hrivnacova, IPN Orsay
25 //          Laurent Aphecetche, Christian Finck, SUBATECH Nantes
26 //-----------------------------------------------------------------------------
27
28 #include "AliMpDetElement.h"
29
30 #include "AliMpArrayI.h"
31 #include "AliMpConstants.h"
32 #include "AliMpDEManager.h"
33 #include "AliMpHVNamer.h"
34 #include "AliMpHVUID.h"
35 #include "AliMpManuUID.h"
36 #include "AliMpPadUID.h"
37 #include "AliMpSegmentation.h"
38 #include "AliMpVSegmentation.h"
39
40 #include "AliCodeTimer.h"
41 #include "AliLog.h"
42
43 #include <Riostream.h>
44
45 /// \cond CLASSIMP
46 ClassImp(AliMpDetElement)
47 /// \endcond
48
49 const char  AliMpDetElement::fgkNameSeparator = '_'; 
50
51 //______________________________________________________________________________
52 AliMpDetElement::AliMpDetElement(Int_t id, const TString& name,
53                     const TString& segType, AliMp::PlaneType planeType)
54   : TObject(),
55     fId(id),
56     fDdlId(-1),
57     fName(name),
58     fSegType(segType),
59     fPlaneType(planeType),
60     fBusPatchIds(false),
61     fManuToSerialNbs(),
62     fSerialNbToManus(),
63     fManuList(),
64     fTrackerChannels(),
65     fHVmanus(),
66     fNofChannels(0)
67 {
68 /// Standard constructor
69 }
70
71 //______________________________________________________________________________
72 AliMpDetElement::AliMpDetElement(TRootIOCtor* ioCtor)
73   : TObject(),
74     fId(0),
75     fDdlId(-1),
76     fName(),
77     fSegType(),
78     fPlaneType(),
79     fBusPatchIds(),
80     fManuToSerialNbs(),
81     fSerialNbToManus(),
82     fManuList(),
83     fTrackerChannels(),
84     fHVmanus(ioCtor),
85     fNofChannels()
86 {
87 /// Root IO constructor
88 }
89
90 //______________________________________________________________________________
91 AliMpDetElement::~AliMpDetElement()
92 {
93 /// Destructor
94 }
95
96
97 //
98 // public methods
99 //
100
101 //______________________________________________________________________________
102 Bool_t AliMpDetElement::AddBusPatch(Int_t busPatchId)
103 {
104 /// Add bus patch Id if a bus patch with the same Id is not yet present;
105 /// return false if bus patch was not added
106
107   if ( HasBusPatchId(busPatchId) ) {
108     AliWarningStream() 
109       << "Bus patch Id = " << busPatchId << " already present."
110       << endl;
111     return false;
112   } 
113
114   fBusPatchIds.Add(busPatchId); 
115   return true;
116 }  
117  
118 //______________________________________________________________________________
119 void AliMpDetElement::AddManuSerial(Int_t manuId, Int_t serialNb)
120 {
121 /// Map the serial manu number 
122 /// (Eventually add check if the given pair already present)
123
124   AliCodeTimerAuto("");
125   
126   AliDebug(1,Form("DE %4d ManuId %4d SerialNB %d",
127                fId,manuId,serialNb));
128   
129   fManuToSerialNbs.Add(Long_t(manuId), Long_t(serialNb)); 
130   fSerialNbToManus.Add(Long_t(serialNb), Long_t(manuId));
131 }      
132
133 //______________________________________________________________________________
134 TString AliMpDetElement::GetSegName(AliMp::CathodType cathType) const
135 {
136 /// Return the segmentation name for the given catod type
137
138   return fSegType + fgkNameSeparator + PlaneTypeName(GetPlaneType(cathType));
139 }         
140
141 //______________________________________________________________________________
142 AliMp::PlaneType  AliMpDetElement::GetPlaneType(AliMp::CathodType cath) const 
143 {
144 /// Return plane type                                                      \n
145
146   if ( cath == AliMp::kCath0 ) return fPlaneType;
147   else                         return AliMp::OtherPlaneType(fPlaneType); 
148 }    
149
150 //______________________________________________________________________________
151 AliMp::CathodType AliMpDetElement::GetCathodType(AliMp::PlaneType planeType) const
152 {
153 /// Return cathod type for given planeType
154
155   if ( fPlaneType == planeType ) return AliMp::kCath0;
156   else                           return AliMp::kCath1;
157 }
158
159 //______________________________________________________________________________
160 AliMp::CathodType AliMpDetElement::GetCathodTypeFromManuId(Int_t manuId) const
161 {
162 /// Return cathod type for given manuId
163
164   AliMp::PlaneType planeType = AliMp::kBendingPlane;
165   if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) 
166   {
167     planeType = AliMp::kNonBendingPlane;
168   }
169   return GetCathodType(planeType);
170 }
171
172 //______________________________________________________________________________
173 AliMp::StationType AliMpDetElement::GetStationType() const
174 {
175 /// Return station type                                                      \n
176 /// Failure causes Fatal error - as AliMp::StationType has no possibility
177 /// to return undefined value
178
179   Int_t chamberId = AliMpDEManager::GetChamberId(fId, false);
180   if ( ! AliMpDEManager::IsValidChamberId(chamberId, true) ) {
181     AliFatal("Cannot return AliMp::StationType value.");
182     return AliMp::kStation1;
183   }  
184   
185   if ( chamberId ==  0 || chamberId ==  1 )  return AliMp::kStation1;
186   if ( chamberId ==  2 || chamberId ==  3 )  return AliMp::kStation2;
187   if ( chamberId >=  4 && chamberId <=  9 )  return AliMp::kStation345;
188   if ( chamberId >= 10 && chamberId <= 13 )  return AliMp::kStationTrigger;
189
190   // Should never get to this line
191   AliFatal("Cannot return AliMp::StationType value.");
192   return AliMp::kStation1;
193 }
194
195 //______________________________________________________________________________
196 Int_t AliMpDetElement::GetNofBusPatches() const
197 {
198 /// Return the number of bus patches in this detection element
199
200   return fBusPatchIds.GetSize();
201 }  
202
203 //______________________________________________________________________________
204 Int_t AliMpDetElement::GetBusPatchId(Int_t index) const
205 {
206 /// Return the index-th bus patch
207
208   if ( index < 0 || index > GetNofBusPatches() ) {
209     AliErrorStream()
210       << "In DE = " << fId << ": Index " << index << " outside limits." << endl;
211     return 0;
212   }     
213
214   return  fBusPatchIds.GetValue(index);
215 }   
216
217
218 //______________________________________________________________________________
219 Bool_t  AliMpDetElement::HasBusPatchId(Int_t busPatchId) const
220 {  
221 /// Return true if the bus patch Id is present
222
223   return fBusPatchIds.HasValue(busPatchId);; 
224 }
225
226 //______________________________________________________________________________
227 Int_t  AliMpDetElement::GetManuSerialFromId(Int_t manuId) const
228 {
229 /// Return manu serial number from manuId
230
231   return (Int_t)fManuToSerialNbs.GetValue(Long_t(manuId));
232 }
233
234 //______________________________________________________________________________
235 Int_t  AliMpDetElement::GetManuIdFromSerial(Int_t serialNb) const
236 {
237 /// Return manuId from manu serial number
238   
239   return (Int_t)fSerialNbToManus.GetValue(Long_t(serialNb));
240 }
241
242 //______________________________________________________________________________
243 Int_t 
244 AliMpDetElement::NofChannelsInManu(Int_t manuId) const
245 {
246   /// Return the number of channels in a given manu
247   
248   Long_t uid = AliMpManuUID::BuildUniqueID(fId,manuId);
249   
250   return (Int_t)(fManuList.GetValue(uid));
251 }
252
253 //______________________________________________________________________________
254 Bool_t 
255 AliMpDetElement::IsExistingChannel(Int_t manuId, Int_t manuChannel) const
256 {
257   /// Whether or not the channel is a valid one (does not tell if it is
258   /// connected or not
259   
260   if ( NofChannelsInManu(manuId) > 0 && 
261        manuChannel >= 0 && 
262        manuChannel < AliMpConstants::ManuNofChannels() ) 
263   {
264     return kTRUE;
265   }
266   else
267   {
268     return kFALSE;
269   }
270 }
271
272 //______________________________________________________________________________
273 Bool_t 
274 AliMpDetElement::IsConnectedChannel(Int_t manuId, Int_t manuChannel) const
275 {
276   /// Whether or not the channel is a *connected* one (i.e. it is valid plus
277   /// it corresponds to a real pad)
278   
279   return ( fTrackerChannels.GetValue(AliMpPadUID::BuildUniqueID(fId,manuId,manuChannel)) > 0 );
280 }
281
282 //______________________________________________________________________________
283 void
284 AliMpDetElement::AddManu(Int_t manuId)
285 {
286   /// Fills the fManuList and fTrackerChannels
287   AliMp::StationType stationType = AliMpDEManager::GetStationType(fId);
288   
289   if ( stationType == AliMp::kStationTrigger ) return;
290     
291   AliCodeTimerAuto("")
292   
293   AliDebug(1,Form("DE %4d Manu %4d",fId,manuId));
294
295   AliCodeTimerStart(Form("%s",AliMp::StationTypeName(stationType).Data()));
296   
297   if ( fHVmanus.GetSize() == 0 ) 
298   {
299     fHVmanus.SetOwner(kTRUE); // to be 100% explicit
300     
301     // get the size, to avoid resizing when adding later on
302     Int_t nmanus(0);
303     
304     AliMp::CathodType cathodes[] = { AliMp::kCath0, AliMp::kCath1 };
305     
306     for ( Int_t i = 0; i < 2; ++i ) 
307     {
308       const AliMpVSegmentation* seg = 
309       AliMpSegmentation::Instance()->GetMpSegmentation(fId,cathodes[i]);
310       
311       TArrayI manus;
312       
313       seg->GetAllElectronicCardIDs(manus);
314
315       nmanus += manus.GetSize();
316     }
317     
318     fHVmanus.SetSize(nmanus);
319   }
320   
321   const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(fId,manuId);
322   
323   Int_t n(0);
324   
325   for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i ) 
326   {
327     if ( seg->PadByLocation(AliMpIntPair(manuId,i),kFALSE).IsValid() )
328     {
329       ++n;
330       fTrackerChannels.Add((Long_t)AliMpPadUID::BuildUniqueID(fId,manuId,i),
331                            (Long_t)1);
332     }
333   }
334   
335   fManuList.Add(AliMpManuUID::BuildUniqueID(fId,manuId),(Long_t)n);
336
337   fNofChannels += n;
338   
339   AliMpHVNamer hvNamer;
340   
341   Int_t index = hvNamer.ManuId2Index(fId,manuId);
342                             
343   UInt_t hvuid = AliMpHVUID::BuildUniqueID(fId,index);
344   
345   AliMpArrayI* hv = static_cast<AliMpArrayI*>(fHVmanus.GetValue(hvuid));
346   
347   if (!hv)
348   {
349     Bool_t sort(kFALSE);
350     hv = new AliMpArrayI(sort);
351     fHVmanus.Add(hvuid,hv);
352   }
353   
354   hv->Add(manuId,kFALSE);        
355   
356   AliCodeTimerStop(Form("%s",AliMp::StationTypeName(stationType).Data()));
357 }
358   
359 //______________________________________________________________________________
360 const AliMpArrayI* 
361 AliMpDetElement::ManusForHV(Int_t hvIndex) const
362 {
363   /// Return the list of manus sharing a hv channel
364   return static_cast<AliMpArrayI*>(fHVmanus.GetValue(AliMpHVUID::BuildUniqueID(fId,hvIndex)));
365 }
366
367 //______________________________________________________________________________
368 Int_t 
369 AliMpDetElement::NofManusWithSerialNumber() const
370 {
371   /// Return the number of manus which have a serial number in this detection element  
372   return fManuToSerialNbs.GetSize();
373 }
374
375 //______________________________________________________________________________
376 Int_t 
377 AliMpDetElement::NofManus() const
378 {
379   /// Return the number of manus in this detection element
380   return fManuList.GetSize();
381 }
382