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