]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpBusPatch.cxx
- Added class for Global Crate object
[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 #include "AliMpConstants.h"
28 #include "AliMpDEManager.h"
29 #include "AliMpSegmentation.h"
30 #include "AliMpSlatSegmentation.h"
31 #include "AliMpSlat.h"
32 #include "AliMpPCB.h"
33 #include "AliMpMotifPosition.h"
34
35 #include "AliLog.h"
36
37 #include <Riostream.h>
38
39 /// \cond CLASSIMP
40 ClassImp(AliMpBusPatch)
41 /// \endcond
42
43 const Int_t  AliMpBusPatch::fgkOffset = 100;
44 //
45 // static methods
46 //
47
48 //____________________________________________________________________
49 Int_t AliMpBusPatch::GetGlobalBusID(Int_t localID, Int_t ddlID)
50 {
51   /// return global bus id from local bus and ddl id
52
53   return ddlID*fgkOffset + localID;
54
55 }
56 //____________________________________________________________________
57 Int_t AliMpBusPatch::GetLocalBusID(Int_t globalID, Int_t ddlID)
58 {
59   /// return local bus id from local bus id
60
61   return globalID - ddlID*fgkOffset;
62
63 }
64
65 //______________________________________________________________________________
66 AliMpBusPatch::AliMpBusPatch(Int_t id, Int_t detElemId, Int_t ddlId)
67   : TObject(),
68     fId(id),
69     fDEId(detElemId),
70     fDdlId(ddlId),
71     fManus(false),
72     fNofManusPerModule(false),
73     fCableLength(-1)
74 {
75 /// Standard constructor
76 }
77
78 //______________________________________________________________________________
79 AliMpBusPatch::AliMpBusPatch(TRootIOCtor* /*ioCtor*/)
80   : TObject(),
81     fId(),
82     fDEId(),
83     fDdlId(),
84     fManus(),
85     fNofManusPerModule(false),
86     fCableLength(-1)
87 {
88 /// Root IO constructor
89 }
90
91 //______________________________________________________________________________
92 AliMpBusPatch::~AliMpBusPatch()
93 {
94 /// Destructor
95 }
96
97 //
98 // public methods
99 //
100
101 //______________________________________________________________________________
102 Bool_t AliMpBusPatch::AddManu(Int_t manuId)
103 {
104 /// Add detection element with given detElemId.
105 /// Return true if the detection element was added
106
107   if ( HasManu(manuId) ) {
108     AliWarningStream() 
109       << "Manu with manuId=" << manuId << " already present."
110       << endl;
111     return false;
112   }    
113
114   fManus.Add(manuId);
115   return true;
116 }   
117
118 //______________________________________________________________________________
119 Bool_t AliMpBusPatch::SetNofManusPerModule(Int_t manuNumber)
120 {
121 /// Set the number of manus per patch module (PCB):
122 /// - for stations 1 all manus are connected to one PCB,
123 /// - for stations 2 there maximum two PCBs per buspatch,
124 /// - for slat stations there are maximum three PCBs per buspatch
125
126   if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation1) {
127
128     // simply fill the number of manus, no bridge for station 1
129        
130     fNofManusPerModule.Add(GetNofManus());
131     return true;
132   }
133
134  if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation2) {
135
136     // there is max two patch modules per buspatch
137        
138     fNofManusPerModule.Add(manuNumber);
139     if (manuNumber != GetNofManus())
140         fNofManusPerModule.Add(GetNofManus() - manuNumber);
141
142     return true;
143   }
144
145   if ( AliMpDEManager::GetStationType(fDEId) == AliMp::kStation345 ) {
146   
147     const AliMpSlatSegmentation* seg0 
148         = static_cast<const AliMpSlatSegmentation*>(
149             AliMpSegmentation::Instance()->GetMpSegmentation(fDEId, AliMp::kCath0));
150
151     const AliMpSlatSegmentation* seg1 
152         = static_cast<const AliMpSlatSegmentation*>(
153             AliMpSegmentation::Instance()->GetMpSegmentation(fDEId, AliMp::kCath1));
154
155     const AliMpSlat* slat0 = seg0->Slat();
156     const AliMpSlat* slat1 = seg1->Slat();
157
158        
159     Int_t iPcb = 0;
160     Int_t iPcbPrev = -1;
161     Int_t manuPerPcb = 0;
162
163     Double_t x = 0.;
164     Double_t length = 0.;
165
166     // Loop over manu
167     for (Int_t iManu = 0; iManu < GetNofManus(); ++iManu) {
168       Int_t manuId = GetManuId(iManu);
169       AliMpMotifPosition* motifPos0 = slat0->FindMotifPosition(manuId);
170       AliMpMotifPosition* motifPos1 = slat1->FindMotifPosition(manuId);   
171       
172       if ( !motifPos0 && !motifPos1 ) {
173         // should never happen
174         AliErrorStream() 
175           << "Motif position for manuId = " << manuId << "not found" << endl;
176         return false;
177       }
178
179       // find PCB id
180       if ( motifPos0 ) {
181         x = motifPos0->Position().X();
182         length = slat0->GetPCB(0)->DX()*2.;
183       }
184       if ( motifPos1 ) {
185         x = motifPos1->Position().X();
186         length = slat1->GetPCB(0)->DX()*2.;
187       }
188       
189       iPcb = Int_t(x/length + AliMpConstants::LengthTolerance());
190
191       // check when going to next PCB
192       if ( iPcb == iPcbPrev )
193         manuPerPcb++;
194       else if ( iPcbPrev != -1 ) {
195         //vec.Set(vec.GetSize()+1);
196         //vec[vec.GetSize()-1] = manuPerPcb+1;
197         fNofManusPerModule.Add(manuPerPcb+1);
198         manuPerPcb = 0;
199       }
200       iPcbPrev = iPcb;
201     }
202    
203     // store last PCB
204     //vec.Set(vec.GetSize()+1);
205     //vec[vec.GetSize()-1] = manuPerPcb+1;
206     fNofManusPerModule.Add(manuPerPcb+1);
207     return true;  
208   } 
209   
210   return false; 
211 }     
212
213 //______________________________________________________________________________
214 Int_t AliMpBusPatch::GetNofManus() const
215 {  
216 /// Return the number of detection elements connected to this DDL
217
218   return fManus.GetSize(); 
219 }
220
221 //______________________________________________________________________________
222 Int_t  AliMpBusPatch::GetManuId(Int_t index) const
223 {  
224 /// Return the detection element by index (in loop)
225
226   return fManus.GetValue(index); 
227 }
228
229 //______________________________________________________________________________
230 Bool_t  AliMpBusPatch::HasManu(Int_t manuId) const
231 {  
232 /// Return true if bus patch has manu with given manuId
233
234   return fManus.HasValue(manuId); 
235 }
236
237 //______________________________________________________________________________
238 Int_t  AliMpBusPatch::GetNofPatchModules() const
239 {
240 /// Return the number of patch modules (PCB) connected to this bus patch.
241
242   return fNofManusPerModule.GetSize();
243 }  
244   
245 //______________________________________________________________________________
246 Int_t  AliMpBusPatch::GetNofManusPerModule(Int_t patchModule) const
247 {
248 /// Return the number of manus per patch module (PCB)
249
250   if ( patchModule < 0 || patchModule >= GetNofPatchModules() ) {
251     AliErrorStream() << "Invalid patch module number = " << patchModule << endl;
252     return 0;
253   }
254   
255   return fNofManusPerModule.GetValue(patchModule);
256 }