]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpTrigger.cxx
Removing a comma that gcc 3.4 does not like ;-)
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpTrigger.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 purpeateose. It is      *
13 * provided "as is" without express or implied warranty.                  *
14 **************************************************************************/
15
16 // $Id$
17 // $MpId: AliMpTrigger.cxx,v 1.4 2006/05/24 13:58:52 ivana Exp $
18
19 #include "AliMpTrigger.h"
20 #include "AliMpSlatSegmentation.h"
21 #include "AliMpConstants.h"
22 #include "AliLog.h"
23 #include "AliMpSlat.h"
24
25 #include "Riostream.h"
26 #include "TArrayI.h"
27 #include "TObjArray.h"
28
29 //-----------------------------------------------------------------------------
30 /// \class AliMpTrigger
31 /// 
32 /// A trigger 'slat' object. 
33 /// It is to be viewed as a superposition of  
34 /// virtual layers of AliMpSlat objects. The need for more than one layer  
35 /// arise from the fact that a given local board deals with strips  
36 /// located in different detelem. So a given strip (pad) can have several  
37 /// "locations".
38 ///
39 /// \author Laurent Aphecetche
40 //-----------------------------------------------------------------------------
41
42 /// \cond CLASSIMP
43 ClassImp(AliMpTrigger)
44 /// \endcond
45
46 namespace
47 {
48   Bool_t IsEqual(Double_t a, Double_t b, Double_t precision)
49 {
50     if (b)
51     {
52       Double_t diff = TMath::Abs(b-a)/TMath::Abs(b);
53       if ( diff < precision ) 
54       {
55         return kTRUE;
56       }
57     }
58     else
59     {
60       if ( !a ) return kTRUE;
61     }
62     return kFALSE;
63 }
64 }
65
66 //_____________________________________________________________________________
67 AliMpTrigger::AliMpTrigger()
68 : TObject(), 
69   fId(""), 
70   fPlaneType(AliMp::kNonBendingPlane), 
71   fSlats(0),
72   fSlatSegmentations(0),
73   fMaxNofPadsY(0),
74   fDX(0), 
75   fDY(0)
76 {
77   /// default ctor
78
79   AliDebugStream(1) << "this = " << this << endl;
80
81   fSlats.SetOwner(kFALSE);
82   fSlatSegmentations.SetOwner(kTRUE);
83 }
84
85 //_____________________________________________________________________________
86 AliMpTrigger::AliMpTrigger(const char* slatType, AliMp::PlaneType bendingOrNot)
87     :  TObject(), 
88        fId(slatType), 
89        fPlaneType(bendingOrNot), 
90        fSlats(0),
91        fSlatSegmentations(0),
92        fMaxNofPadsY(0), 
93        fDX(0), 
94        fDY(0)
95 {
96   /// normal ctor
97
98   AliDebugStream(1) << "this = " << this << endl;
99
100   fSlats.SetOwner(kFALSE);
101   fSlatSegmentations.SetOwner(kTRUE);
102 }
103
104 //_____________________________________________________________________________
105 AliMpTrigger::~AliMpTrigger()
106 {
107   /// dtor
108   AliDebugStream(1) << "this = " << this << endl;
109
110   fSlatSegmentations.Delete();
111 }
112
113 //_____________________________________________________________________________
114 Bool_t
115 AliMpTrigger::AdoptLayer(AliMpSlat* slat)
116 {
117   /// Adopt (i.e. we become owner of that pointer) a slat, as 
118   /// a layer of this trigger slat.
119
120   AliDebug(2,Form("%s is adopting %s ",
121                   GetID(),slat->GetID()));
122
123   // Check that we keep our size constant.
124     
125   if ( GetSize() > 0 && 
126        ( !::IsEqual(slat->DX(),fDX,AliMpConstants::LengthTolerance()) || 
127          !::IsEqual(slat->DY(),fDY,AliMpConstants::LengthTolerance()) )
128      )
129   {
130     AliError(Form("In %s trying to add a layer (%e,%e) (layer #%d) "
131                   "of a different size than mine (%e,%e)",
132                   GetID(),slat->DX(),slat->DY(),fSlats.GetEntries(),
133                   fDX,fDY));
134     return kFALSE;
135   }
136   fSlats.Add(slat);
137   Bool_t owner(kTRUE);
138   // the slat segmentation will be the owner of the slat, and will delete
139   // it when it'll be deleted itself
140   fSlatSegmentations.Add(new AliMpSlatSegmentation(slat,owner));
141   fMaxNofPadsY = TMath::Max(slat->GetMaxNofPadsY(),fMaxNofPadsY);
142   fDX = TMath::Max(fDX,slat->DX());
143   fDY = TMath::Max(fDY,slat->DY());
144   return kTRUE;
145 }
146
147 //_____________________________________________________________________________
148 Double_t
149 AliMpTrigger::DX() const
150 {
151   /// Returns the half-size in X (cm)
152   return fDX;
153 }
154
155 //_____________________________________________________________________________
156 Double_t
157 AliMpTrigger::DY() const
158 {
159   /// Returns the half-size in Y (cm)
160   return fDY;
161 }
162
163 //_____________________________________________________________________________
164 void 
165 AliMpTrigger::GetAllLocalBoardNumbers(TArrayI& lbn) const
166 {
167   /// Fills lbn with the local board numbers we're dealing with
168   Int_t n(0);
169   for ( Int_t i = 0; i < GetSize(); ++i )
170   {
171     n += GetLayer(i)->GetNofElectronicCards();
172   }
173   
174   lbn.Set(n);
175
176   Int_t index(0);
177   
178   for ( Int_t i = 0; i < GetSize(); ++i )
179   {
180     TArrayI slbn;
181     GetLayer(i)->GetAllMotifPositionsIDs(slbn);
182     for ( Int_t j = 0; j < slbn.GetSize(); ++j )
183     {
184       lbn[index] = slbn[j];
185       ++index;
186     }
187   }
188 }
189
190 //_____________________________________________________________________________
191 const char*
192 AliMpTrigger::GetID() const
193 {
194   /// returns the id of this slat
195   return fId.Data();
196 }
197
198 //_____________________________________________________________________________
199 const char*
200 AliMpTrigger::GetName() const
201 {
202   /// returns the name (=id+bending/non-bending) of this slat
203   TString name(GetID());
204   if ( fPlaneType == AliMp::kBendingPlane )
205   {
206     name += ".Bending";
207   }
208   else if ( fPlaneType == AliMp::kNonBendingPlane )
209   {
210     name += ".NonBending";
211   }
212   else
213   {
214     name += ".Invalid";
215   }
216   return name.Data();
217 }
218
219 //_____________________________________________________________________________
220 AliMpSlat*
221 AliMpTrigger::GetLayer(int layer) const
222 {
223   /// Returns a given layer
224   if ( IsLayerValid(layer) )
225   {
226     return (AliMpSlat*)fSlats.At(layer);
227   }
228   return 0;
229 }
230
231 //_____________________________________________________________________________
232 AliMpVSegmentation*
233 AliMpTrigger::GetLayerSegmentation(int layer) const
234 {
235   /// Returns a given layer
236   if ( IsLayerValid(layer) )
237   {
238     return (AliMpSlatSegmentation*)fSlatSegmentations.At(layer);
239   }
240   return 0;
241 }
242
243 //_____________________________________________________________________________
244 Int_t
245 AliMpTrigger::GetNofPadsX() const
246 {
247   /// Returns the number of pad in x direction
248   if ( !GetSize() ) return -1;
249   if ( GetLayer(0) )
250   {
251     return GetLayer(0)->GetNofPadsX();
252   }
253   return -1;
254 }
255
256 //_____________________________________________________________________________
257 Int_t
258 AliMpTrigger::GetMaxNofPadsY() const
259 {
260   /// Maximum number of pads in y direction
261   return fMaxNofPadsY;
262 }
263
264 //_____________________________________________________________________________
265 Int_t
266 AliMpTrigger::GetSize() const
267 {
268   /// Number of layers
269   return fSlats.GetEntriesFast();
270 }
271
272 //_____________________________________________________________________________
273 Bool_t
274 AliMpTrigger::IsLayerValid(int layer) const
275 {
276   /// Whether a given layer index is valid or not
277   if ( layer >= 0 && layer < GetSize() )
278   {
279     return kTRUE;
280   }
281   return kFALSE;
282 }
283
284 //_____________________________________________________________________________
285 AliMp::PlaneType
286 AliMpTrigger::PlaneType() const
287 {
288   /// Bending or not
289   return fPlaneType;
290 }
291
292 //_____________________________________________________________________________
293 void
294 AliMpTrigger::Print(Option_t* opt) const
295 {
296   /// Dump on screen
297   cout << "AliMpTrigger::" << GetID();
298   if ( GetSize() == 0 )
299   {
300     cout << " Empty";
301   }
302   else if ( GetSize() > 1 )
303   {
304     cout << " Number of layers : " << GetSize();
305   }
306   else 
307   {
308     cout << " One layer";
309   }
310   cout << endl;
311   for ( Int_t i = 0; i < GetSize(); ++i ) 
312   {
313     cout << "   ";
314     GetLayer(i)->Print(opt);
315   }
316 }
317
318 //_____________________________________________________________________________
319 //_____________________________________________________________________________
320 //_____________________________________________________________________________
321 //_____________________________________________________________________________