Using AliLog instead of Root error messages
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpGraphContext.cxx
... / ...
CommitLineData
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: AliMpGraphContext.cxx,v 1.11 2006/05/24 13:58:32 ivana Exp $
18// Category: graphics
19//
20// Class AliMpGraphContext
21// -----------------------
22// Class describing a the correspondance between a given area
23// in pad, and a zone of real (cm) position
24// Included in AliRoot: 2003/05/02
25// Author: David GUEZ, IPN Orsay
26
27#include "AliMpGraphContext.h"
28
29/// \cond CLASSIMP
30ClassImp(AliMpGraphContext)
31/// \endcond
32
33AliMpGraphContext *AliMpGraphContext::fgInstance = 0;
34AliMpGraphContext::GraphContextVector AliMpGraphContext::fgStack;
35
36#ifdef WITH_ROOT
37Int_t AliMpGraphContext::fgStackSize = 0;
38#endif
39
40//_____________________________________________________________________________
41AliMpGraphContext::AliMpGraphContext():
42 TObject(),
43 fPadPosition(TVector2(0.5,0.5)),
44 fPadDimensions(TVector2(0.49,0.49)),
45 fRealPosition(TVector2(0.,0.)),
46 fRealDimensions(TVector2(1,1))
47{
48/// Private constructor
49
50 fColor = 20;
51 // default constructor (private)
52}
53
54//_____________________________________________________________________________
55AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right)
56 : TObject(right),
57 fColor(right.fColor),
58 fPadPosition(right.fPadPosition),
59 fPadDimensions(right.fPadDimensions),
60 fRealPosition(right.fRealPosition),
61 fRealDimensions(right.fRealDimensions)
62{
63/// Copy constructor
64}
65
66//_____________________________________________________________________________
67AliMpGraphContext&
68AliMpGraphContext::operator=(const AliMpGraphContext& right)
69{
70/// Protected assignment operator
71
72 // check assignment to self
73 if (this == &right) return *this;
74
75 fColor = right.fColor;
76 fPadPosition = right.fPadPosition;
77 fPadDimensions = right.fPadDimensions;
78 fRealPosition = right.fRealPosition;
79 fRealDimensions = right.fRealDimensions;
80
81 return *this;
82}
83
84//_____________________________________________________________________________
85AliMpGraphContext *AliMpGraphContext::Instance()
86{
87 /// Return or create a unique instance of this class
88
89 if (fgInstance) return fgInstance;
90 fgInstance = new AliMpGraphContext;
91 return fgInstance;
92}
93
94//_____________________________________________________________________________
95TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
96{
97 /// Transform a real position into its equivalent position in the pad
98
99 Double_t x=position.X();
100 Double_t y=position.Y();
101 x-= (fRealPosition.X()-fRealDimensions.X());
102 x/=fRealDimensions.X();
103 x*=fPadDimensions.X();
104 x+= (fPadPosition.X()-fPadDimensions.X() );
105
106 y-= (fRealPosition.Y()-fRealDimensions.Y());
107 y/=fRealDimensions.Y();
108 y*=fPadDimensions.Y();
109 y+= (fPadPosition.Y()-fPadDimensions.Y() );
110
111 return TVector2(x,y);
112}
113
114//_____________________________________________________________________________
115void AliMpGraphContext::RealToPad(const TVector2 &position,
116 const TVector2 &dimensions,
117 TVector2 &padPosition,
118 TVector2 &padDimensions) const
119{
120 // Transform the real area (position,dimensions) to
121 // its equivalent pad area
122
123 padPosition = RealToPad(position);
124 padDimensions =
125 TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
126 dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
127
128}
129
130//_____________________________________________________________________________
131void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
132 const TVector2 &dimensions)
133{
134 /// Set the pad area from the actual one
135 /// corresponding to the given real area.
136
137 RealToPad(position,dimensions,fPadPosition,fPadDimensions);
138}
139
140//_____________________________________________________________________________
141void AliMpGraphContext::Push() const
142{
143 /// Store the current configuration
144
145 AliMpGraphContext *save = new AliMpGraphContext(*this);
146
147#ifdef WITH_STL
148 fgStack.push_back(save);
149#endif
150
151#ifdef WITH_ROOT
152 fgStack.AddAt(save, fgStackSize++);
153#endif
154}
155
156//_____________________________________________________________________________
157void AliMpGraphContext::Pop()
158{
159/// Pop an object from the stack.
160
161#ifdef WITH_STL
162 // restore the last saved configuration
163 if (!fgStack.empty()){
164 AliMpGraphContext *obj = fgStack.back();
165 *this = *obj;
166 fgStack.pop_back();
167 delete obj;
168 }
169#endif
170
171#ifdef WITH_ROOT
172 // restore the last saved configuration
173 if ( fgStackSize ){
174 AliMpGraphContext *obj
175 = (AliMpGraphContext*)fgStack.At(--fgStackSize);
176 *this = *obj;
177 fgStack.RemoveAt(fgStackSize);
178 delete obj;
179 }
180#endif
181}