]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpBusPatch.cxx
In SetNofManusPerModule(): return false if no action
[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 {
73 /// Standard constructor
74 }
75
76 //______________________________________________________________________________
77 AliMpBusPatch::AliMpBusPatch(TRootIOCtor* /*ioCtor*/)
78   : TObject(),
79     fId(),
80     fDEId(),
81     fDdlId(),
82     fManus(),
83     fNofManusPerModule(false)
84 {
85 /// Root IO constructor
86 }
87
88 //______________________________________________________________________________
89 AliMpBusPatch::~AliMpBusPatch()
90 {
91 /// Destructor
92 }
93
94 //
95 // public methods
96 //
97
98 //______________________________________________________________________________
99 Bool_t AliMpBusPatch::AddManu(Int_t manuId)
100 {
101 /// Add detection element with given detElemId.
102 /// Return true if the detection element was added
103
104   if ( HasManu(manuId) ) {
105     AliWarningStream() 
106       << "Manu with manuId=" << manuId << " already present."
107       << endl;
108     return false;
109   }    
110
111   fManus.Add(manuId);
112   return true;
113 }   
114
115 //______________________________________________________________________________
116 Bool_t AliMpBusPatch::SetNofManusPerModule()
117 {
118 /// Set the number of manus per patch module (PCB):
119 /// - for stations 12 all manus are connected to one PCB,
120 /// - for slat stations there are maximum three PCBs per buspatch
121 /// Not correct for station 2
122
123   if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation1 ||
124        AliMpDEManager::GetStationType(fDEId) == AliMp::kStation2 ) {
125
126     // simply fill the number of manus, no bridge for station 1
127     // not the case for station 2.
128        
129     fNofManusPerModule.Add(GetNofManus());
130     return true;
131   }
132
133   if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation345 ) {
134   
135     const AliMpSlatSegmentation* seg0 
136         = static_cast<const AliMpSlatSegmentation*>(
137             AliMpSegmentation::Instance()->GetMpSegmentation(fDEId, AliMp::kCath0));
138
139     const AliMpSlatSegmentation* seg1 
140         = static_cast<const AliMpSlatSegmentation*>(
141             AliMpSegmentation::Instance()->GetMpSegmentation(fDEId, AliMp::kCath1));
142
143     const AliMpSlat* slat0 = seg0->Slat();
144     const AliMpSlat* slat1 = seg1->Slat();
145
146        
147     Int_t iPcb = 0;
148     Int_t iPcbPrev = -1;
149     Int_t manuPerPcb = 0;
150
151     Double_t x = 0.;
152     Double_t length = 0.;
153
154     // Loop over manu
155     for (Int_t iManu = 0; iManu < GetNofManus(); ++iManu) {
156       Int_t manuId = GetManuId(iManu);
157       AliMpMotifPosition* motifPos0 = slat0->FindMotifPosition(manuId);
158       AliMpMotifPosition* motifPos1 = slat1->FindMotifPosition(manuId);   
159       
160       if ( !motifPos0 && !motifPos1 ) {
161         // should never happen
162         AliErrorStream() 
163           << "Motif position for manuId = " << manuId << "not found" << endl;
164         return false;
165       }
166
167       // find PCB id
168       if ( motifPos0 ) {
169         x = motifPos0->Position().X();
170         length = slat0->GetPCB(0)->DX()*2.;
171       }
172       if ( motifPos1 ) {
173         x = motifPos1->Position().X();
174         length = slat1->GetPCB(0)->DX()*2.;
175       }
176       
177       iPcb = Int_t(x/length + AliMpConstants::LengthTolerance());
178
179       // check when going to next PCB
180       if ( iPcb == iPcbPrev )
181         manuPerPcb++;
182       else if ( iPcbPrev != -1 ) {
183         //vec.Set(vec.GetSize()+1);
184         //vec[vec.GetSize()-1] = manuPerPcb+1;
185         fNofManusPerModule.Add(manuPerPcb+1);
186         manuPerPcb = 0;
187       }
188       iPcbPrev = iPcb;
189     }
190    
191     // store last PCB
192     //vec.Set(vec.GetSize()+1);
193     //vec[vec.GetSize()-1] = manuPerPcb+1;
194     fNofManusPerModule.Add(manuPerPcb+1);
195     return true;  
196   } 
197   
198   return false; 
199 }     
200
201 //______________________________________________________________________________
202 Int_t AliMpBusPatch::GetNofManus() const
203 {  
204 /// Return the number of detection elements connected to this DDL
205
206   return fManus.GetSize(); 
207 }
208
209 //______________________________________________________________________________
210 Int_t  AliMpBusPatch::GetManuId(Int_t index) const
211 {  
212 /// Return the detection element by index (in loop)
213
214   return fManus.GetValue(index); 
215 }
216
217 //______________________________________________________________________________
218 Bool_t  AliMpBusPatch::HasManu(Int_t manuId) const
219 {  
220 /// Return true if bus patch has manu with given manuId
221
222   return fManus.HasValue(manuId); 
223 }
224
225 //______________________________________________________________________________
226 Int_t  AliMpBusPatch::GetNofPatchModules() const
227 {
228 /// Return the number of patch modules (PCB) connected to this bus patch.
229
230   return fNofManusPerModule.GetSize();
231 }  
232   
233 //______________________________________________________________________________
234 Int_t  AliMpBusPatch::GetNofManusPerModule(Int_t patchModule) const
235 {
236 /// Return the number of manus per patch module (PCB)
237
238   if ( patchModule < 0 || patchModule >= GetNofPatchModules() ) {
239     AliErrorStream() << "Invalid patch module number = " << patchModule << endl;
240     return 0;
241   }
242   
243   return fNofManusPerModule.GetValue(patchModule);
244 }