Using AliLog instead of Root error messages
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpGraphContext.cxx
CommitLineData
dee1d5f1 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
5f91c9e8 16// $Id$
13985652 17// $MpId: AliMpGraphContext.cxx,v 1.11 2006/05/24 13:58:32 ivana Exp $
5f91c9e8 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
dbe945cc 24// Included in AliRoot: 2003/05/02
5f91c9e8 25// Author: David GUEZ, IPN Orsay
26
27#include "AliMpGraphContext.h"
28
13985652 29/// \cond CLASSIMP
30ClassImp(AliMpGraphContext)
31/// \endcond
32
5f91c9e8 33AliMpGraphContext *AliMpGraphContext::fgInstance = 0;
5006ec94 34AliMpGraphContext::GraphContextVector AliMpGraphContext::fgStack;
2c605e66 35
f79c58a5 36#ifdef WITH_ROOT
37Int_t AliMpGraphContext::fgStackSize = 0;
38#endif
5f91c9e8 39
fb1bf5c0 40//_____________________________________________________________________________
5f91c9e8 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{
dee1d5f1 48/// Private constructor
fb1bf5c0 49
5f91c9e8 50 fColor = 20;
51 // default constructor (private)
52}
fb1bf5c0 53
54//_____________________________________________________________________________
55AliMpGraphContext::AliMpGraphContext(const AliMpGraphContext& right)
bcf37928 56 : TObject(right),
57 fColor(right.fColor),
58 fPadPosition(right.fPadPosition),
59 fPadDimensions(right.fPadDimensions),
60 fRealPosition(right.fRealPosition),
61 fRealDimensions(right.fRealDimensions)
fb1bf5c0 62{
dee1d5f1 63/// Copy constructor
fb1bf5c0 64}
65
66//_____________________________________________________________________________
67AliMpGraphContext&
68AliMpGraphContext::operator=(const AliMpGraphContext& right)
69{
dee1d5f1 70/// Protected assignment operator
fb1bf5c0 71
dee1d5f1 72 // check assignment to self
fb1bf5c0 73 if (this == &right) return *this;
74
bcf37928 75 fColor = right.fColor;
76 fPadPosition = right.fPadPosition;
77 fPadDimensions = right.fPadDimensions;
78 fRealPosition = right.fRealPosition;
79 fRealDimensions = right.fRealDimensions;
fb1bf5c0 80
81 return *this;
82}
83
84//_____________________________________________________________________________
5f91c9e8 85AliMpGraphContext *AliMpGraphContext::Instance()
86{
dee1d5f1 87 /// Return or create a unique instance of this class
88
5f91c9e8 89 if (fgInstance) return fgInstance;
90 fgInstance = new AliMpGraphContext;
91 return fgInstance;
92}
93
fb1bf5c0 94//_____________________________________________________________________________
5f91c9e8 95TVector2 AliMpGraphContext::RealToPad(const TVector2 &position) const
96{
dee1d5f1 97 /// Transform a real position into its equivalent position in the pad
98
5f91c9e8 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
fb1bf5c0 114//_____________________________________________________________________________
5f91c9e8 115void AliMpGraphContext::RealToPad(const TVector2 &position,
116 const TVector2 &dimensions,
117 TVector2 &padPosition,
118 TVector2 &padDimensions) const
119{
dee1d5f1 120 // Transform the real area (position,dimensions) to
5f91c9e8 121 // its equivalent pad area
dee1d5f1 122
5f91c9e8 123 padPosition = RealToPad(position);
124 padDimensions =
125 TVector2(dimensions.X()*fPadDimensions.X()/fRealDimensions.X(),
126 dimensions.Y()*fPadDimensions.Y()/fRealDimensions.Y());
127
128}
fb1bf5c0 129
130//_____________________________________________________________________________
5f91c9e8 131void AliMpGraphContext::SetPadPosForReal(const TVector2 &position,
132 const TVector2 &dimensions)
133{
dee1d5f1 134 /// Set the pad area from the actual one
135 /// corresponding to the given real area.
136
5f91c9e8 137 RealToPad(position,dimensions,fPadPosition,fPadDimensions);
138}
fb1bf5c0 139
140//_____________________________________________________________________________
5f91c9e8 141void AliMpGraphContext::Push() const
142{
dee1d5f1 143 /// Store the current configuration
144
5f91c9e8 145 AliMpGraphContext *save = new AliMpGraphContext(*this);
f79c58a5 146
147#ifdef WITH_STL
5f91c9e8 148 fgStack.push_back(save);
f79c58a5 149#endif
150
151#ifdef WITH_ROOT
152 fgStack.AddAt(save, fgStackSize++);
153#endif
5f91c9e8 154}
fb1bf5c0 155
156//_____________________________________________________________________________
5f91c9e8 157void AliMpGraphContext::Pop()
158{
dee1d5f1 159/// Pop an object from the stack.
160
f79c58a5 161#ifdef WITH_STL
5f91c9e8 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 }
f79c58a5 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
5f91c9e8 181}