]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpBusPatch.cxx
Implementing the Print
[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
26 #include "AliMpBusPatch.h"
27
28 #include "AliDAQ.h"
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"
36
37 #include "AliLog.h"
38
39 #include <Riostream.h>
40
41 /// \cond CLASSIMP
42 ClassImp(AliMpBusPatch)
43 /// \endcond
44
45 const Int_t  AliMpBusPatch::fgkOffset = 100;
46 //
47 // static methods
48 //
49
50 //____________________________________________________________________
51 Int_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 //____________________________________________________________________
59 Int_t AliMpBusPatch::GetLocalBusID(Int_t globalID, Int_t ddlID)
60 {
61   /// return local bus id from local bus id
62
63   return globalID - ddlID*fgkOffset;
64
65 }
66
67 //______________________________________________________________________________
68 AliMpBusPatch::AliMpBusPatch(Int_t id, Int_t detElemId, Int_t ddlId)
69   : TObject(),
70     fId(id),
71     fDEId(detElemId),
72     fDdlId(ddlId),
73     fManus(false),
74     fNofManusPerModule(false),
75     fCableLength(-1),
76     fCableLabel(),
77     fTranslatorLabel(),
78     fFrtId(0)
79 {
80 /// Standard constructor
81 }
82
83 //______________________________________________________________________________
84 AliMpBusPatch::AliMpBusPatch(TRootIOCtor* /*ioCtor*/)
85   : TObject(),
86     fId(),
87     fDEId(),
88     fDdlId(),
89     fManus(false),
90     fNofManusPerModule(false),
91     fCableLength(-1),
92     fCableLabel(),
93     fTranslatorLabel(),
94     fFrtId(0)
95 {
96 /// Root IO constructor
97 }
98
99 //______________________________________________________________________________
100 AliMpBusPatch::~AliMpBusPatch()
101 {
102 /// Destructor
103 }
104
105 //
106 // public methods
107 //
108
109 //______________________________________________________________________________
110 Bool_t AliMpBusPatch::AddManu(Int_t manuId)
111 {
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
126 //______________________________________________________________________________
127 Bool_t AliMpBusPatch::SetNofManusPerModule(Int_t manuNumber)
128 {
129 /// Set the number of manus per patch module (PCB):
130 /// - for stations 1 all manus are connected to one PCB,
131 /// - for stations 2 there maximum two PCBs per buspatch,
132 /// - for slat stations there are maximum three PCBs per buspatch
133
134   if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation1) {
135
136     // simply fill the number of manus, no bridge for station 1
137        
138     fNofManusPerModule.Add(GetNofManus());
139     return true;
140   }
141
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
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;  
216   } 
217   
218   return false; 
219 }     
220
221 //______________________________________________________________________________
222 void  AliMpBusPatch::RevertReadout()
223 {
224 /// Revert order of manus
225
226   fManus.Revert();
227 }
228
229 //______________________________________________________________________________
230 void  AliMpBusPatch::ResetReadout()
231 {
232 /// Revert order of manus
233
234   fManus.Reset();
235 }
236
237 //______________________________________________________________________________
238 Int_t AliMpBusPatch::GetNofManus() const
239 {  
240 /// Return the number of detection elements connected to this DDL
241
242   return fManus.GetSize(); 
243 }
244
245 //______________________________________________________________________________
246 Int_t  AliMpBusPatch::GetManuId(Int_t index) const
247 {  
248 /// Return the detection element by index (in loop)
249
250   return fManus.GetValue(index); 
251 }
252
253 //______________________________________________________________________________
254 Bool_t  AliMpBusPatch::HasManu(Int_t manuId) const
255 {  
256 /// Return true if bus patch has manu with given manuId
257
258   return fManus.HasValue(manuId); 
259 }
260
261 //______________________________________________________________________________
262 Int_t  AliMpBusPatch::GetNofPatchModules() const
263 {
264 /// Return the number of patch modules (PCB) connected to this bus patch.
265
266   return fNofManusPerModule.GetSize();
267 }  
268   
269 //______________________________________________________________________________
270 TString
271 AliMpBusPatch::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
278 //______________________________________________________________________________
279 Int_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 }     
290
291 //______________________________________________________________________________
292 void 
293 AliMpBusPatch::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 }