]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPainterMatrix.cxx
Fixing (again) the HV display for St1 and 2. Should be OK now
[u/mrichter/AliRoot.git] / MUON / AliMUONPainterMatrix.cxx
CommitLineData
0145e89a 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 "AliMUONPainterMatrix.h"
19
20#include "AliMUONPainterGroup.h"
21#include "AliMUONVPainter.h"
22#include "AliLog.h"
23#include <Riostream.h>
24#include <TObjArray.h>
25#include <float.h>
26#include <TObjString.h>
27
28///\class AliMUONPainterMatrix
29///
30/// Matrix of AliMUONVPainter
31///
32///\author Laurent Aphecetche, Subatech
33
34///\cond CLASSIMP
35ClassImp(AliMUONPainterMatrix)
36///\endcond
37
38//_____________________________________________________________________________
39AliMUONPainterMatrix::AliMUONPainterMatrix(const char* name, Int_t nx, Int_t ny)
40: TObject(),
41 fBasename(name),
42 fName(""),
43 fNx(nx),
44 fNy(ny),
45 fPainters(new TObjArray(fNx*fNy)),
46 fAttributes()
47{
48 /// ctor
49
50 fPainters->SetOwner(kTRUE);
51 if ( fNx*fNy > 1 )
52 {
53 fAttributes.SetSingle(kFALSE);
54 }
55
56 fName = NameIt(name,fAttributes);
57}
58
59//_____________________________________________________________________________
60AliMUONPainterMatrix::~AliMUONPainterMatrix()
61{
62 /// dtor
63 delete fPainters;
64}
65
66//_____________________________________________________________________________
67void
68AliMUONPainterMatrix::Adopt(AliMUONVPainter* painter)
69{
70 /// Adopt a given painter
71 fPainters->AddLast(painter);
72 UpdateAttributes();
73}
74
75//_____________________________________________________________________________
76void
77AliMUONPainterMatrix::UpdateAttributes()
78{
79 /// Update our attributes (using our painters' attributes)
80
81 Bool_t cathode0(kFALSE);
82 Bool_t cathode1(kFALSE);
83 Bool_t bending(kFALSE);
84 Bool_t nonbending(kFALSE);
85 Bool_t front(kFALSE);
86 Bool_t back(kFALSE);
87 Bool_t cathplaneexclusive(kFALSE);
88 Bool_t cathplanedisabled(kFALSE);
89
90 for ( Int_t i = 0; i < Size(); ++i )
91 {
92 AliMUONAttPainter att = Painter(i)->Attributes();
93
94 if ( att.IsCathodeDefined() )
95 {
96 if ( att.IsCathode0() ) cathode0 = kTRUE;
97 if ( att.IsCathode1() ) cathode1 = kTRUE;
98 }
99
100 if ( att.IsPlaneDefined() )
101 {
102 if ( att.IsBendingPlane() ) bending = kTRUE;
103 if ( att.IsNonBendingPlane() ) nonbending = kTRUE;
104 }
105
106 if ( att.IsFrontView() ) front = kTRUE;
107 if ( att.IsBackView() ) back = kTRUE;
108
109 if ( att.IsCathodeAndPlaneMutuallyExclusive() ) cathplaneexclusive = kTRUE;
110
111 if ( att.IsCathodeAndPlaneDisabled() ) cathplanedisabled = kTRUE;
112 }
113
114 fAttributes.SetCathode(cathode0,cathode1);
115 fAttributes.SetPlane(bending,nonbending);
116 fAttributes.SetViewPoint(front,back);
117 fAttributes.SetCathodeAndPlaneMutuallyExclusive(cathplaneexclusive);
118 fAttributes.SetCathodeAndPlaneDisabled(cathplanedisabled);
119
120 fName = NameIt(fBasename,fAttributes);
121}
122
123//_____________________________________________________________________________
124TString
125AliMUONPainterMatrix::NameIt(const TString& basename, const AliMUONAttPainter& att)
126{
127 /// Build a name
128 TString name(basename);
129
130 name += "-";
131 name += att.Name();
132
133 return name;
134}
135
136//_____________________________________________________________________________
137void
138AliMUONPainterMatrix::ComputeDataRange()
139{
140 /// Compute the data range spanned by the painters in this matrix
141
142 Double_t dataMin(FLT_MAX);
143 Double_t dataMax(-FLT_MAX);
144 Bool_t atLeastOnePlotter(kFALSE);
145
146 for ( Int_t i = 0; i < Size(); ++i )
147 {
148 AliMUONVPainter* p = Painter(i);
149 AliMUONPainterGroup* g = p->PlotterGroup();
150
151 Double_t min(FLT_MAX);
152 Double_t max(-FLT_MAX);
153
154 if ( g )
155 {
156 atLeastOnePlotter = kTRUE;
157 g->ComputeDataRange(min,max);
158 if ( min <= max )
159 {
160 dataMin = TMath::Min(min,dataMin);
161 dataMax = TMath::Max(max,dataMax);
162 }
163 }
164
165 AliDebug(1,Form("painter %s group %s min %e max %e dataMin,Max=%7.3f,%7.3f",
166 p->GetName(),
167 g ? g->Type() : "none",
168 min,max,
169 dataMin,dataMax));
170 }
171
172 if ( dataMin > dataMax && atLeastOnePlotter )
173 {
174 AliError(Form("data min %e > max %e : setting both to 0.0",
175 dataMin,dataMax));
176 dataMin = dataMax = 0.0;
177 }
178
179 AliDebug(1,Form("Final dataMin,Max=%7.3f,%7.3f",dataMin,dataMax));
180
181 SetDataRange(dataMin,dataMax);
182}
183
184//_____________________________________________________________________________
185void
186AliMUONPainterMatrix::Connect(const char* sourceMethod, const char* destClassName,
187 void* destObject, const char* destMethod)
188{
189 /// Connect our painters
190
191 for ( Int_t i = 0; i < Size(); ++i )
192 {
193 Painter(i)->Connect(sourceMethod,destClassName,destObject,destMethod);
194 }
195}
196
197//_____________________________________________________________________________
198void
199AliMUONPainterMatrix::GetDataRange(Double_t& dataMin, Double_t& dataMax) const
200{
201 /// Get the data range spanned by the painters in this matrix
202
203 dataMin=FLT_MAX;
204 dataMax=-FLT_MAX;
205
206 for ( Int_t i = 0; i < Size(); ++i )
207 {
208 AliMUONVPainter* p = Painter(i);
209 if ( p )
210 {
211 AliMUONPainterGroup* g = p->PlotterGroup();
212 if ( g )
213 {
214 dataMin = TMath::Min(dataMin,g->DataMin());
215 dataMax = TMath::Max(dataMax,g->DataMax());
216 }
217 }
218 }
219}
220
221//_____________________________________________________________________________
222void
223AliMUONPainterMatrix::GetTypes(TObjArray& types) const
224{
225 /// Get the types of the painters in this matrix
226
227 types.SetOwner(kTRUE);
228 types.Clear();
229
230 for ( Int_t i = 0; i < Size(); ++i )
231 {
232 AliMUONVPainter* p = Painter(i);
233 TObjArray ptypes;
234 p->GetTypes(ptypes);
235 TIter next(&ptypes);
236 TObject* o;
237 while ( ( o = next() ) )
238 {
239 if ( ! types.FindObject(o) )
240 {
241 types.AddLast(o->Clone());
242 }
243 }
244 }
245}
246
247//_____________________________________________________________________________
248AliMUONVPainter*
249AliMUONPainterMatrix::Painter(Int_t index) const
250{
251 /// Get a given painter
252
253 if ( index <= fPainters->GetLast() )
254 {
255 return static_cast<AliMUONVPainter*>(fPainters->At(index));
256 }
257 return 0x0;
258}
259
260//_____________________________________________________________________________
261AliMUONVTrackerData*
262AliMUONPainterMatrix::Data() const
263{
9016a84e 264 /// Return our data
0145e89a 265 AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
266 return ( group ? group->Data() : 0x0 );
267}
268
269//_____________________________________________________________________________
270TString
271AliMUONPainterMatrix::DataPattern() const
272{
9016a84e 273 /// Return our data pattern
0145e89a 274 AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
275 return ( group ? group->Type() : "" );
276}
277
278//_____________________________________________________________________________
279Int_t
280AliMUONPainterMatrix::DataIndex() const
281{
9016a84e 282 /// Return our data index
0145e89a 283 AliMUONPainterGroup* group = Painter(0)->PlotterGroup();
284 return ( group ? group->DataIndex() : -1 );
285}
286
287//_____________________________________________________________________________
288void
289AliMUONPainterMatrix::SetData(const char* pattern, AliMUONVTrackerData* d,
290 Int_t indexInData)
291{
292 /// Set the data to be plotted
293
294 for ( Int_t i = 0; i < Size(); ++i )
295 {
296 AliMUONVPainter* painter = Painter(i);
297 painter->SetData(pattern,d,indexInData);
298 }
299}
300
301//_____________________________________________________________________________
302void
303AliMUONPainterMatrix::SetDataRange(Double_t dataMin, Double_t dataMax)
304{
305 /// Set the data range
306
307 for ( Int_t i = 0; i < Size(); ++i )
308 {
309 AliMUONVPainter* p = Painter(i);
310 AliMUONPainterGroup* g = p->PlotterGroup();
311 if ( g )
312 {
313 g->SetDataRange(dataMin,dataMax);
314 }
315 }
316}
317
318//_____________________________________________________________________________
319Int_t
320AliMUONPainterMatrix::Size() const
321{
322 /// Return the number of painters we actually handle
323 return fPainters->GetLast()+1;
324}
325
326//_____________________________________________________________________________
327void
328AliMUONPainterMatrix::Print(Option_t*) const
329{
330 /// Printout
331 cout << "Basename=" << fBasename.Data() << " Name=" << fName.Data()
332 << " Nx=" << fNx << " Ny=" << fNy << " Att=" << fAttributes.GetName() << endl;
333}
334
335//_____________________________________________________________________________
336//void
337//AliMUONPainterMatrix::ChangeAttributes(const AliMUONAttPainter& attributes)
338//{
339// /// Change painters' attributes
340//
341// AliWarning("Implement me !");
342//
343// // for ( Int_t i = 0; i < Size(); ++i )
344// // {
345// // Painter(i)->SetAttributes(attributes);
346// // }
347//}
348
349//_____________________________________________________________________________
350AliMUONPainterMatrix*
351AliMUONPainterMatrix::Clone(const AliMUONAttPainter& attributes) const
352{
353 /// Clone with given attributes
354
355 AliMUONPainterMatrix* clone = new AliMUONPainterMatrix(Basename().Data(),Nx(),Ny());
356
357 for ( Int_t i = 0; i < Size(); ++i )
358 {
359 AliMUONVPainter* oldPainter = Painter(i);
360
361 AliMUONVPainter* newPainter(0x0);
362
363 newPainter = AliMUONVPainter::CreatePainter(oldPainter->ClassName(),
364 attributes,
365 oldPainter->ID0(),
366 oldPainter->ID1());
367
368 if (newPainter)
369 {
370 newPainter->UpdateGroupsFrom(*(oldPainter->Master()));
371 clone->Adopt(newPainter);
372 }
373 else
374 {
375 AliError(Form("Failed to create painter of class %s ID0 %d ID1 %d",
376 oldPainter->ClassName(),
377 oldPainter->ID0(),
378 oldPainter->ID1()));
379 }
380 }
381
382 return clone;
383}
384
385//_____________________________________________________________________________
386void
387AliMUONPainterMatrix::SetOutlined(const char* pattern, Bool_t value)
388{
389 /// Calls SetOutlined for all our painters
390
391 for ( Int_t i = 0; i < Size(); ++i )
392 {
393 Painter(i)->SetOutlined(pattern,value);
394 }
395}
396
397//_____________________________________________________________________________
398void
399AliMUONPainterMatrix::SetResponder(const char* pattern)
400{
401 /// Calls SetResponder for all our painters
402 for ( Int_t i = 0; i < Size(); ++i )
403 {
404 Painter(i)->SetResponder(pattern);
405 }
406}
407
408//_____________________________________________________________________________
409AliMUONAttPainter
410AliMUONPainterMatrix::Validate(const AliMUONAttPainter& att) const
411{
412 /// Normalize attributes
413
414 AliMUONAttPainter a;
415
416 for ( Int_t i = 0; i < Size() && a.IsValid(); ++i )
417 {
418 a = Painter(i)->Validate(att);
419 }
420 return a;
421}
422
423