Implementing the Print
[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 $
3d1463c8 18
19//-----------------------------------------------------------------------------
b4daf0b2 20// Class AliMpBusPatch
21// --------------------
22// The class defines the properties of BusPatch
23// Author: Ivana Hrivnacova, IPN Orsay
3d1463c8 24//-----------------------------------------------------------------------------
1e738c3c 25
26#include "AliMpBusPatch.h"
6a7424c4 27
28#include "AliDAQ.h"
f00f5bb0 29#include "AliMpConstants.h"
30#include "AliMpDEManager.h"
31#include "AliMpSegmentation.h"
32#include "AliMpSlatSegmentation.h"
33#include "AliMpSlat.h"
34#include "AliMpPCB.h"
35#include "AliMpMotifPosition.h"
b4daf0b2 36
1e738c3c 37#include "AliLog.h"
b4daf0b2 38
39#include <Riostream.h>
1e738c3c 40
13985652 41/// \cond CLASSIMP
1e738c3c 42ClassImp(AliMpBusPatch)
13985652 43/// \endcond
1e738c3c 44
d2892ef5 45const Int_t AliMpBusPatch::fgkOffset = 100;
b4daf0b2 46//
47// static methods
48//
d2892ef5 49
d2892ef5 50//____________________________________________________________________
51Int_t AliMpBusPatch::GetGlobalBusID(Int_t localID, Int_t ddlID)
52{
53 /// return global bus id from local bus and ddl id
54
55 return ddlID*fgkOffset + localID;
56
57}
58//____________________________________________________________________
59Int_t AliMpBusPatch::GetLocalBusID(Int_t globalID, Int_t ddlID)
60{
61 /// return local bus id from local bus id
1e738c3c 62
d2892ef5 63 return globalID - ddlID*fgkOffset;
64
65}
1e738c3c 66
b4daf0b2 67//______________________________________________________________________________
68AliMpBusPatch::AliMpBusPatch(Int_t id, Int_t detElemId, Int_t ddlId)
69 : TObject(),
70 fId(id),
71 fDEId(detElemId),
72 fDdlId(ddlId),
f00f5bb0 73 fManus(false),
bf4bf8d2 74 fNofManusPerModule(false),
59754717 75 fCableLength(-1),
76 fCableLabel(),
77 fTranslatorLabel(),
78 fFrtId(0)
1e738c3c 79{
b4daf0b2 80/// Standard constructor
1e738c3c 81}
82
b4daf0b2 83//______________________________________________________________________________
84AliMpBusPatch::AliMpBusPatch(TRootIOCtor* /*ioCtor*/)
85 : TObject(),
86 fId(),
87 fDEId(),
88 fDdlId(),
ae649dcb 89 fManus(false),
bf4bf8d2 90 fNofManusPerModule(false),
59754717 91 fCableLength(-1),
92 fCableLabel(),
93 fTranslatorLabel(),
94 fFrtId(0)
1e738c3c 95{
b4daf0b2 96/// Root IO constructor
1e738c3c 97}
1e738c3c 98
b4daf0b2 99//______________________________________________________________________________
100AliMpBusPatch::~AliMpBusPatch()
5826f1df 101{
b4daf0b2 102/// Destructor
5826f1df 103}
104
b4daf0b2 105//
106// public methods
107//
5826f1df 108
b4daf0b2 109//______________________________________________________________________________
110Bool_t AliMpBusPatch::AddManu(Int_t manuId)
5826f1df 111{
b4daf0b2 112/// Add detection element with given detElemId.
113/// Return true if the detection element was added
114
115 if ( HasManu(manuId) ) {
116 AliWarningStream()
117 << "Manu with manuId=" << manuId << " already present."
118 << endl;
119 return false;
120 }
121
122 fManus.Add(manuId);
123 return true;
124}
125
f00f5bb0 126//______________________________________________________________________________
bf4bf8d2 127Bool_t AliMpBusPatch::SetNofManusPerModule(Int_t manuNumber)
f00f5bb0 128{
129/// Set the number of manus per patch module (PCB):
bf4bf8d2 130/// - for stations 1 all manus are connected to one PCB,
131/// - for stations 2 there maximum two PCBs per buspatch,
f00f5bb0 132/// - for slat stations there are maximum three PCBs per buspatch
f00f5bb0 133
bf4bf8d2 134 if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation1) {
f00f5bb0 135
136 // simply fill the number of manus, no bridge for station 1
f00f5bb0 137
138 fNofManusPerModule.Add(GetNofManus());
139 return true;
140 }
141
bf4bf8d2 142 if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation2) {
143
144 // there is max two patch modules per buspatch
145
146 fNofManusPerModule.Add(manuNumber);
147 if (manuNumber != GetNofManus())
148 fNofManusPerModule.Add(GetNofManus() - manuNumber);
149
150 return true;
151 }
152
f00f5bb0 153 if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation345 ) {
154
155 const AliMpSlatSegmentation* seg0
156 = static_cast<const AliMpSlatSegmentation*>(
157 AliMpSegmentation::Instance()->GetMpSegmentation(fDEId, AliMp::kCath0));
158
159 const AliMpSlatSegmentation* seg1
160 = static_cast<const AliMpSlatSegmentation*>(
161 AliMpSegmentation::Instance()->GetMpSegmentation(fDEId, AliMp::kCath1));
162
163 const AliMpSlat* slat0 = seg0->Slat();
164 const AliMpSlat* slat1 = seg1->Slat();
165
166
167 Int_t iPcb = 0;
168 Int_t iPcbPrev = -1;
169 Int_t manuPerPcb = 0;
170
171 Double_t x = 0.;
172 Double_t length = 0.;
173
174 // Loop over manu
175 for (Int_t iManu = 0; iManu < GetNofManus(); ++iManu) {
176 Int_t manuId = GetManuId(iManu);
177 AliMpMotifPosition* motifPos0 = slat0->FindMotifPosition(manuId);
178 AliMpMotifPosition* motifPos1 = slat1->FindMotifPosition(manuId);
179
180 if ( !motifPos0 && !motifPos1 ) {
181 // should never happen
182 AliErrorStream()
183 << "Motif position for manuId = " << manuId << "not found" << endl;
184 return false;
185 }
186
187 // find PCB id
188 if ( motifPos0 ) {
189 x = motifPos0->Position().X();
190 length = slat0->GetPCB(0)->DX()*2.;
191 }
192 if ( motifPos1 ) {
193 x = motifPos1->Position().X();
194 length = slat1->GetPCB(0)->DX()*2.;
195 }
196
197 iPcb = Int_t(x/length + AliMpConstants::LengthTolerance());
198
199 // check when going to next PCB
200 if ( iPcb == iPcbPrev )
201 manuPerPcb++;
202 else if ( iPcbPrev != -1 ) {
203 //vec.Set(vec.GetSize()+1);
204 //vec[vec.GetSize()-1] = manuPerPcb+1;
205 fNofManusPerModule.Add(manuPerPcb+1);
206 manuPerPcb = 0;
207 }
208 iPcbPrev = iPcb;
209 }
210
211 // store last PCB
212 //vec.Set(vec.GetSize()+1);
213 //vec[vec.GetSize()-1] = manuPerPcb+1;
214 fNofManusPerModule.Add(manuPerPcb+1);
215 return true;
9ece548f 216 }
217
218 return false;
f00f5bb0 219}
220
ae649dcb 221//______________________________________________________________________________
222void AliMpBusPatch::RevertReadout()
223{
224/// Revert order of manus
225
226 fManus.Revert();
227}
228
229//______________________________________________________________________________
230void AliMpBusPatch::ResetReadout()
231{
232/// Revert order of manus
233
234 fManus.Reset();
235}
236
b4daf0b2 237//______________________________________________________________________________
238Int_t AliMpBusPatch::GetNofManus() const
239{
240/// Return the number of detection elements connected to this DDL
241
242 return fManus.GetSize();
5826f1df 243}
244
b4daf0b2 245//______________________________________________________________________________
246Int_t AliMpBusPatch::GetManuId(Int_t index) const
247{
248/// Return the detection element by index (in loop)
528df1a6 249
b4daf0b2 250 return fManus.GetValue(index);
5826f1df 251}
252
b4daf0b2 253//______________________________________________________________________________
254Bool_t AliMpBusPatch::HasManu(Int_t manuId) const
255{
256/// Return true if bus patch has manu with given manuId
5826f1df 257
b4daf0b2 258 return fManus.HasValue(manuId);
5826f1df 259}
260
f00f5bb0 261//______________________________________________________________________________
262Int_t AliMpBusPatch::GetNofPatchModules() const
263{
264/// Return the number of patch modules (PCB) connected to this bus patch.
5826f1df 265
f00f5bb0 266 return fNofManusPerModule.GetSize();
267}
268
6a7424c4 269//______________________________________________________________________________
270TString
271AliMpBusPatch::GetFRTPosition() const
272{
273 /// Return CRXX-Y-Z where XX is the Crocus number, Y the FRT number
274 /// and Z the local bus patch number.
275 return Form("CR%2d-%d-%d",fDdlId,fFrtId+1,GetLocalBusID(fId,fDdlId));
276}
277
f00f5bb0 278//______________________________________________________________________________
279Int_t AliMpBusPatch::GetNofManusPerModule(Int_t patchModule) const
280{
281/// Return the number of manus per patch module (PCB)
282
283 if ( patchModule < 0 || patchModule >= GetNofPatchModules() ) {
284 AliErrorStream() << "Invalid patch module number = " << patchModule << endl;
285 return 0;
286 }
287
288 return fNofManusPerModule.GetValue(patchModule);
289}
6a7424c4 290
291//______________________________________________________________________________
292void
293AliMpBusPatch::Print(Option_t* opt) const
294{
295 /// Printout
296
297 cout << Form("BusPatch %04d DDL %d : %s <> %s / %s",
298 fId,
299 AliDAQ::DdlID("MUONTRK",fDdlId),
300 GetFRTPosition().Data(),
301 fCableLabel.Data(),
302 fTranslatorLabel.Data()) << endl;
303
304 TString sopt(opt);
305 sopt.ToUpper();
306
307 if ( sopt.Contains("FULL") )
308 {
309 cout << Form("Nof of PCBs (i.e. patch modules) = %d",fNofManusPerModule.GetSize()) << endl;
310
311 for ( Int_t i = 0; i < fNofManusPerModule.GetSize(); ++i )
312 {
313 cout << Form("\t\t %d manus in patch module %d",fNofManusPerModule.GetValue(i),i) << endl;
314 }
315
316 if ( sopt.Contains("MANU") )
317 {
318 cout << "Manus of that buspatch=" << endl;
319
320 for ( Int_t i = 0; i < fManus.GetSize(); ++i )
321 {
322 cout << Form("%4d,",fManus.GetValue(i));
323 }
324 cout << endl;
325 }
326 }
327
328// Int_t fId; ///< Identifier (unique)
329// Int_t fDEId; ///< Detection element to which this bus patch is connected
330// Int_t fDdlId; ///< DDL to which this bus patch is connected
331// AliMpArrayI fManus; ///< Manu Ids connected to this bus patch
332// AliMpArrayI fNofManusPerModule; ///< Nof Manus per patch modules (PCBs)
333// Float_t fCableLength; ///< length of the buspatch cable
334// TString fCableLabel; ///< label of the buspatch cable
335// TString fTranslatorLabel; ///< label of the translator board
336// Int_t fFrtId; ///< FRT Ids connected to this bus patch
337
338}