In SetNofManusPerModule(): return false if no action
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpBusPatch.cxx
CommitLineData
1e738c3c 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$
b4daf0b2 17// $MpId: AliMpBusPatch.cxx,v 1.4 2006/05/24 13:58:34 ivana Exp $
1e738c3c 18//
b4daf0b2 19// --------------------
20// Class AliMpBusPatch
21// --------------------
22// The class defines the properties of BusPatch
23// Author: Ivana Hrivnacova, IPN Orsay
1e738c3c 24
25#include "AliMpBusPatch.h"
f00f5bb0 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"
b4daf0b2 33
1e738c3c 34#include "AliLog.h"
b4daf0b2 35
36#include <Riostream.h>
1e738c3c 37
13985652 38/// \cond CLASSIMP
1e738c3c 39ClassImp(AliMpBusPatch)
13985652 40/// \endcond
1e738c3c 41
d2892ef5 42const Int_t AliMpBusPatch::fgkOffset = 100;
b4daf0b2 43//
44// static methods
45//
d2892ef5 46
d2892ef5 47//____________________________________________________________________
48Int_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//____________________________________________________________________
56Int_t AliMpBusPatch::GetLocalBusID(Int_t globalID, Int_t ddlID)
57{
58 /// return local bus id from local bus id
1e738c3c 59
d2892ef5 60 return globalID - ddlID*fgkOffset;
61
62}
1e738c3c 63
b4daf0b2 64//______________________________________________________________________________
65AliMpBusPatch::AliMpBusPatch(Int_t id, Int_t detElemId, Int_t ddlId)
66 : TObject(),
67 fId(id),
68 fDEId(detElemId),
69 fDdlId(ddlId),
f00f5bb0 70 fManus(false),
71 fNofManusPerModule(false)
1e738c3c 72{
b4daf0b2 73/// Standard constructor
1e738c3c 74}
75
b4daf0b2 76//______________________________________________________________________________
77AliMpBusPatch::AliMpBusPatch(TRootIOCtor* /*ioCtor*/)
78 : TObject(),
79 fId(),
80 fDEId(),
81 fDdlId(),
f00f5bb0 82 fManus(),
83 fNofManusPerModule(false)
1e738c3c 84{
b4daf0b2 85/// Root IO constructor
1e738c3c 86}
1e738c3c 87
b4daf0b2 88//______________________________________________________________________________
89AliMpBusPatch::~AliMpBusPatch()
5826f1df 90{
b4daf0b2 91/// Destructor
5826f1df 92}
93
b4daf0b2 94//
95// public methods
96//
5826f1df 97
b4daf0b2 98//______________________________________________________________________________
99Bool_t AliMpBusPatch::AddManu(Int_t manuId)
5826f1df 100{
b4daf0b2 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
f00f5bb0 115//______________________________________________________________________________
116Bool_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;
9ece548f 196 }
197
198 return false;
f00f5bb0 199}
200
b4daf0b2 201//______________________________________________________________________________
202Int_t AliMpBusPatch::GetNofManus() const
203{
204/// Return the number of detection elements connected to this DDL
205
206 return fManus.GetSize();
5826f1df 207}
208
b4daf0b2 209//______________________________________________________________________________
210Int_t AliMpBusPatch::GetManuId(Int_t index) const
211{
212/// Return the detection element by index (in loop)
528df1a6 213
b4daf0b2 214 return fManus.GetValue(index);
5826f1df 215}
216
b4daf0b2 217//______________________________________________________________________________
218Bool_t AliMpBusPatch::HasManu(Int_t manuId) const
219{
220/// Return true if bus patch has manu with given manuId
5826f1df 221
b4daf0b2 222 return fManus.HasValue(manuId);
5826f1df 223}
224
f00f5bb0 225//______________________________________________________________________________
226Int_t AliMpBusPatch::GetNofPatchModules() const
227{
228/// Return the number of patch modules (PCB) connected to this bus patch.
5826f1df 229
f00f5bb0 230 return fNofManusPerModule.GetSize();
231}
232
233//______________________________________________________________________________
234Int_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}