]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpBusPatch.cxx
Add methods to set/get cable length & change patch module interface needed for station 2
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpBusPatch.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: AliMpBusPatch.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
18 //
19 // --------------------
20 // Class AliMpBusPatch
21 // --------------------
22 // The class defines the properties of BusPatch
23 // Author: Ivana Hrivnacova, IPN Orsay
24
25 #include "AliMpBusPatch.h"
26 #include "AliMpConstants.h"
27 #include "AliMpDEManager.h"
28 #include "AliMpSegmentation.h"
29 #include "AliMpSlatSegmentation.h"
30 #include "AliMpSlat.h"
31 #include "AliMpPCB.h"
32 #include "AliMpMotifPosition.h"
33
34 #include "AliLog.h"
35
36 #include <Riostream.h>
37
38 /// \cond CLASSIMP
39 ClassImp(AliMpBusPatch)
40 /// \endcond
41
42 const Int_t  AliMpBusPatch::fgkOffset = 100;
43 //
44 // static methods
45 //
46
47 //____________________________________________________________________
48 Int_t AliMpBusPatch::GetGlobalBusID(Int_t localID, Int_t ddlID)
49 {
50   /// return global bus id from local bus and ddl id
51
52   return ddlID*fgkOffset + localID;
53
54 }
55 //____________________________________________________________________
56 Int_t AliMpBusPatch::GetLocalBusID(Int_t globalID, Int_t ddlID)
57 {
58   /// return local bus id from local bus id
59
60   return globalID - ddlID*fgkOffset;
61
62 }
63
64 //______________________________________________________________________________
65 AliMpBusPatch::AliMpBusPatch(Int_t id, Int_t detElemId, Int_t ddlId)
66   : TObject(),
67     fId(id),
68     fDEId(detElemId),
69     fDdlId(ddlId),
70     fManus(false),
71     fNofManusPerModule(false),
72     fCableLength(-1)
73 {
74 /// Standard constructor
75 }
76
77 //______________________________________________________________________________
78 AliMpBusPatch::AliMpBusPatch(TRootIOCtor* /*ioCtor*/)
79   : TObject(),
80     fId(),
81     fDEId(),
82     fDdlId(),
83     fManus(),
84     fNofManusPerModule(false),
85     fCableLength(-1)
86 {
87 /// Root IO constructor
88 }
89
90 //______________________________________________________________________________
91 AliMpBusPatch::~AliMpBusPatch()
92 {
93 /// Destructor
94 }
95
96 //
97 // public methods
98 //
99
100 //______________________________________________________________________________
101 Bool_t AliMpBusPatch::AddManu(Int_t manuId)
102 {
103 /// Add detection element with given detElemId.
104 /// Return true if the detection element was added
105
106   if ( HasManu(manuId) ) {
107     AliWarningStream() 
108       << "Manu with manuId=" << manuId << " already present."
109       << endl;
110     return false;
111   }    
112
113   fManus.Add(manuId);
114   return true;
115 }   
116
117 //______________________________________________________________________________
118 Bool_t AliMpBusPatch::SetNofManusPerModule(Int_t manuNumber)
119 {
120 /// Set the number of manus per patch module (PCB):
121 /// - for stations 1 all manus are connected to one PCB,
122 /// - for stations 2 there maximum two PCBs per buspatch,
123 /// - for slat stations there are maximum three PCBs per buspatch
124
125   if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation1) {
126
127     // simply fill the number of manus, no bridge for station 1
128        
129     fNofManusPerModule.Add(GetNofManus());
130     return true;
131   }
132
133  if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation2) {
134
135     // there is max two patch modules per buspatch
136        
137     fNofManusPerModule.Add(manuNumber);
138     if (manuNumber != GetNofManus())
139         fNofManusPerModule.Add(GetNofManus() - manuNumber);
140
141     return true;
142   }
143
144   if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation345 ) {
145   
146     const AliMpSlatSegmentation* seg0 
147         = static_cast<const AliMpSlatSegmentation*>(
148             AliMpSegmentation::Instance()->GetMpSegmentation(fDEId, AliMp::kCath0));
149
150     const AliMpSlatSegmentation* seg1 
151         = static_cast<const AliMpSlatSegmentation*>(
152             AliMpSegmentation::Instance()->GetMpSegmentation(fDEId, AliMp::kCath1));
153
154     const AliMpSlat* slat0 = seg0->Slat();
155     const AliMpSlat* slat1 = seg1->Slat();
156
157        
158     Int_t iPcb = 0;
159     Int_t iPcbPrev = -1;
160     Int_t manuPerPcb = 0;
161
162     Double_t x = 0.;
163     Double_t length = 0.;
164
165     // Loop over manu
166     for (Int_t iManu = 0; iManu < GetNofManus(); ++iManu) {
167       Int_t manuId = GetManuId(iManu);
168       AliMpMotifPosition* motifPos0 = slat0->FindMotifPosition(manuId);
169       AliMpMotifPosition* motifPos1 = slat1->FindMotifPosition(manuId);   
170       
171       if ( !motifPos0 && !motifPos1 ) {
172         // should never happen
173         AliErrorStream() 
174           << "Motif position for manuId = " << manuId << "not found" << endl;
175         return false;
176       }
177
178       // find PCB id
179       if ( motifPos0 ) {
180         x = motifPos0->Position().X();
181         length = slat0->GetPCB(0)->DX()*2.;
182       }
183       if ( motifPos1 ) {
184         x = motifPos1->Position().X();
185         length = slat1->GetPCB(0)->DX()*2.;
186       }
187       
188       iPcb = Int_t(x/length + AliMpConstants::LengthTolerance());
189
190       // check when going to next PCB
191       if ( iPcb == iPcbPrev )
192         manuPerPcb++;
193       else if ( iPcbPrev != -1 ) {
194         //vec.Set(vec.GetSize()+1);
195         //vec[vec.GetSize()-1] = manuPerPcb+1;
196         fNofManusPerModule.Add(manuPerPcb+1);
197         manuPerPcb = 0;
198       }
199       iPcbPrev = iPcb;
200     }
201    
202     // store last PCB
203     //vec.Set(vec.GetSize()+1);
204     //vec[vec.GetSize()-1] = manuPerPcb+1;
205     fNofManusPerModule.Add(manuPerPcb+1);
206     return true;  
207   } 
208   
209   return false; 
210 }     
211
212 //______________________________________________________________________________
213 Int_t AliMpBusPatch::GetNofManus() const
214 {  
215 /// Return the number of detection elements connected to this DDL
216
217   return fManus.GetSize(); 
218 }
219
220 //______________________________________________________________________________
221 Int_t  AliMpBusPatch::GetManuId(Int_t index) const
222 {  
223 /// Return the detection element by index (in loop)
224
225   return fManus.GetValue(index); 
226 }
227
228 //______________________________________________________________________________
229 Bool_t  AliMpBusPatch::HasManu(Int_t manuId) const
230 {  
231 /// Return true if bus patch has manu with given manuId
232
233   return fManus.HasValue(manuId); 
234 }
235
236 //______________________________________________________________________________
237 Int_t  AliMpBusPatch::GetNofPatchModules() const
238 {
239 /// Return the number of patch modules (PCB) connected to this bus patch.
240
241   return fNofManusPerModule.GetSize();
242 }  
243   
244 //______________________________________________________________________________
245 Int_t  AliMpBusPatch::GetNofManusPerModule(Int_t patchModule) const
246 {
247 /// Return the number of manus per patch module (PCB)
248
249   if ( patchModule < 0 || patchModule >= GetNofPatchModules() ) {
250     AliErrorStream() << "Invalid patch module number = " << patchModule << endl;
251     return 0;
252   }
253   
254   return fNofManusPerModule.GetValue(patchModule);
255 }