]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONBusPatchPainter.cxx
Coding violation fixes
[u/mrichter/AliRoot.git] / MUON / AliMUONBusPatchPainter.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
18 #include "AliMUONBusPatchPainter.h"
19
20 #include "AliMUONManuPainter.h"
21 #include "AliMUONContour.h"
22 #include "AliMUONPainterHelper.h"
23 #include "AliMUONVCalibParam.h"
24 #include "AliMUONVTrackerData.h"
25 #include "AliMpBusPatch.h"
26 #include "AliMpConstants.h"
27 #include "AliMpDDLStore.h"
28 #include "AliMpDEManager.h"
29 #include "AliMpPlaneType.h"
30 #include "AliLog.h"
31 #include <TObjArray.h>
32 #include <TString.h>
33 #include <float.h>
34
35 /// \class AliMUONBusPatchPainter
36 ///
37 /// Painter for one bus patch. Actually possibly for only part of one
38 /// buspatch (the part that is on the plane/cathode requested when
39 /// creating the painter)
40 ///
41 /// \author Laurent Aphecetche, Subatech
42
43 ///\cond CLASSIMP
44 ClassImp(AliMUONBusPatchPainter)
45 ///\endcond
46
47 //_____________________________________________________________________________
48 AliMUONBusPatchPainter::AliMUONBusPatchPainter()
49 : AliMUONVPainter(),
50 fBusPatchId(-1)
51 {
52   /// default ctor
53 }
54
55 //_____________________________________________________________________________
56 AliMUONBusPatchPainter::AliMUONBusPatchPainter(TRootIOCtor* ioCtor)
57 : AliMUONVPainter(ioCtor),
58 fBusPatchId(-1)
59 {
60   /// default streaming ctor
61 }
62
63 //_____________________________________________________________________________
64 AliMUONBusPatchPainter::AliMUONBusPatchPainter(const AliMUONAttPainter& att, 
65                                                Int_t busPatchId)
66 : AliMUONVPainter("BUSPATCH"),
67 fBusPatchId(busPatchId)
68 {
69   /// normal ctor
70   /// WARNING : the construction of this object can fail.
71   /// You MUST check the IsValid() method afterwards (real world would
72   /// be to use exception, but well, whether we should use exceptions
73   /// in aliroot is still unclear to me.
74   
75   SetAttributes(Validate(att));
76   
77   AliMp::PlaneType planeType = ( Attributes().IsBendingPlane() ? AliMp::kBendingPlane : AliMp::kNonBendingPlane );
78
79   Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchId);
80
81   AliMUONPainterHelper* h = AliMUONPainterHelper::Instance();
82   
83   SetID(busPatchId,-1);
84   SetName(h->BusPatchName(busPatchId));
85   SetPathName(h->BusPatchPathName(busPatchId));
86   
87   AliMpBusPatch* busPatch = AliMpDDLStore::Instance()->GetBusPatch(fBusPatchId);
88   
89   Int_t mask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane);
90   
91   AliMUONContour* bpContour = h->GetContour(ContourName());
92   
93   AliDebug(1,Form("BusPatchId %04d bending %d DE %4d bpContour(%s)=%p nofManus=%d",
94                   fBusPatchId,att.IsBendingPlane(),detElemId,ContourName().Data(),bpContour,busPatch->GetNofManus()));
95   
96   Double_t xmin(FLT_MAX), ymin(FLT_MAX), xmax(-FLT_MAX), ymax(-FLT_MAX);
97   
98   TObjArray contours;
99   
100   Int_t nmanus(0);
101   
102   for ( Int_t i = 0; i < busPatch->GetNofManus(); ++i ) 
103   {
104     Int_t manuId = busPatch->GetManuId(i);
105     
106     Bool_t correctPlane(kTRUE);
107     
108     if ( planeType == AliMp::kNonBendingPlane ) 
109     {
110       if ( ( manuId & mask ) == 0 ) correctPlane = kFALSE;
111     }
112     else
113     {
114       if ( ( manuId & mask ) == mask ) correctPlane = kFALSE;
115     }
116
117     AliDebug(1,Form("Adding Manu %04d to BusPatch %04d (DE %04d) "
118                     "manu & mask = %d correctPlane %d planeType %s",
119                     manuId,fBusPatchId,busPatch->GetDEId(),
120                     (manuId & mask),correctPlane,AliMp::PlaneTypeName(planeType).Data()));
121         
122     if (!correctPlane) continue;
123     
124     ++nmanus;
125     
126     AliMUONVPainter* painter = new AliMUONManuPainter(Attributes(),
127                                                       busPatch->GetDEId(),
128                                                       manuId);
129     
130     Add(painter);
131     
132     const AliMpArea& area = painter->Area();
133     
134     xmin = TMath::Min(xmin,\varea.LeftBorder());
135     ymin = TMath::Min(ymin,area.DownBorder());
136     xmax = TMath::Max(xmax,area.RightBorder());
137     ymax = TMath::Max(ymax,area.UpBorder());
138     
139     if (!bpContour)
140     {
141       contours.Add(painter->Contour());
142     }
143   }
144   
145   if ( !nmanus )
146   {
147     Invalidate();
148     return;
149   }
150     
151   if (!bpContour)
152   {
153     AliDebug(1,Form("Creating contour %s",ContourName().Data()));
154     bpContour = h->MergeContours(contours,ContourName());
155     if (!bpContour)
156     {
157       AliError("Could not merge those contours");
158       StdoutToAliError(contours.Print(););
159     }
160   }
161   
162   SetContour(bpContour);
163 }
164
165 //_____________________________________________________________________________
166 void 
167 AliMUONBusPatchPainter::ComputeDataRange(const AliMUONVTrackerData& data, Int_t dataIndex, 
168                                          Double_t& dataMin, Double_t& dataMax) const
169 {
170   /// Compute the data range spanned by this bus patch (on this cathode or plane)
171   dataMin = dataMax = data.BusPatch(fBusPatchId, dataIndex);
172 }
173
174 //_____________________________________________________________________________
175 AliMUONBusPatchPainter::AliMUONBusPatchPainter(const AliMUONBusPatchPainter& rhs)
176 : AliMUONVPainter(rhs), fBusPatchId(-1)
177 {
178   /// Copy ctor
179   rhs.Copy(*this);
180 }
181
182 //_____________________________________________________________________________
183 AliMUONBusPatchPainter&
184 AliMUONBusPatchPainter::operator=(const AliMUONBusPatchPainter& rhs)
185 {
186   /// Assignment operator
187   if ( this != &rhs ) 
188   {
189     rhs.Copy(*this);
190   }
191   return *this;
192 }
193
194 //_____________________________________________________________________________
195 AliMUONBusPatchPainter::~AliMUONBusPatchPainter()
196 {
197   /// dtor
198 }
199
200 //_____________________________________________________________________________
201 void
202 AliMUONBusPatchPainter::Copy(TObject& object) const
203 {
204   /// Copy this to object
205   AliMUONVPainter::Copy((AliMUONVPainter&)(object));
206   ((AliMUONBusPatchPainter&)(object)).fBusPatchId = fBusPatchId;
207 }
208
209 //_____________________________________________________________________________
210 Bool_t
211 AliMUONBusPatchPainter::IsIncluded() const
212 {
213   /// whether this bus patch is included in the readout or not
214   return ( InteractiveReadOutConfig()->BusPatch(fBusPatchId) > 0 );
215 }
216
217 //_____________________________________________________________________________
218 TString
219 AliMUONBusPatchPainter::Describe(const AliMUONVTrackerData& data, Int_t dataIndex, 
220                                  Double_t, Double_t)
221 {
222   /// Text about data
223   
224   if (!data.HasBusPatch(fBusPatchId)) return "";
225   
226   Double_t value = data.BusPatch(fBusPatchId,dataIndex);
227   
228   return AliMUONPainterHelper::Instance()->FormatValue(data.DimensionName(dataIndex).Data(),value);
229 }
230
231 //_____________________________________________________________________________
232 void
233 AliMUONBusPatchPainter::PaintArea(const AliMUONVTrackerData& data, Int_t dataIndex,
234                                   Double_t min, Double_t max)
235 {
236   /// Paint area of this buspatch according to the data
237   
238   if (!data.HasBusPatch(fBusPatchId)) return;
239   
240   Double_t value = data.BusPatch(fBusPatchId,dataIndex);
241   
242   if ( value >= AliMUONVCalibParam::InvalidFloatValue() ) return;
243   
244   Int_t color = AliMUONPainterHelper::Instance()->ColorFromValue(value,min,max);
245   
246   PaintArea(color);
247 }
248
249 //_____________________________________________________________________________
250 AliMUONAttPainter 
251 AliMUONBusPatchPainter::Validate(const AliMUONAttPainter& attributes) const
252 {
253   /// Normalize attributes
254   
255   // we invalidate the attributes, if we have no manu in the requested plane
256   // and we cross-check that both cathode and plane are up-to-date
257   
258   AliMUONAttPainter norm(attributes);
259   
260   Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(fBusPatchId);
261
262   if (!norm.IsValid()) return norm;
263   
264   if ( !norm.IsCathodeDefined() )
265   {
266     AliMp::PlaneType planeType = ( norm.IsBendingPlane() ? AliMp::kBendingPlane : AliMp::kNonBendingPlane );
267   
268     AliMp::CathodType cathodeType = AliMpDEManager::GetCathod(detElemId,planeType);
269     
270     Bool_t cath0 = ( cathodeType == AliMp::kCath0 );
271     
272     norm.SetCathode(cath0,!cath0);
273   }
274   else if ( !norm.IsPlaneDefined() )
275   {
276     AliMp::CathodType cathodeType = ( norm.IsCathode0() ? AliMp::kCath0 : AliMp::kCath1 );
277     
278     AliMp::PlaneType planeType = AliMpDEManager::GetPlaneType(detElemId,cathodeType);
279     
280     Bool_t bending = ( planeType == AliMp::kBendingPlane );
281
282     norm.SetPlane(bending,!bending);    
283   }
284   
285   AliMpBusPatch* busPatch = AliMpDDLStore::Instance()->GetBusPatch(fBusPatchId);
286   
287   Int_t mask = AliMpConstants::ManuMask(AliMp::kNonBendingPlane);
288   
289   Int_t nb(0);
290   Int_t b(0);
291   
292   for ( Int_t i = 0; i < busPatch->GetNofManus(); ++i ) 
293   {
294     Int_t manuId = busPatch->GetManuId(i);
295     
296     if ( manuId & mask  ) ++nb;
297     else ++b;
298   }
299   
300   if ( norm.IsBendingPlane() && !b ) norm.SetValid(kFALSE);
301   if ( norm.IsNonBendingPlane() && !nb ) norm.SetValid(kFALSE);
302   
303   return norm;
304 }
305