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