Adding comment lines to class description needed for Root documentation,
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpGraphContext.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 // $MpId: AliMpGraphContext.cxx,v 1.11 2006/05/24 13:58:32 ivana Exp $
18 // Category: graphics
19
20 //-----------------------------------------------------------------------------
21 // Class AliMpGraphContext
22 // -----------------------
23 // Class describing a the correspondance between a given area
24 // in pad, and a zone of real (cm) position
25 // Included in AliRoot: 2003/05/02
26 // Author: David GUEZ, IPN Orsay
27 //-----------------------------------------------------------------------------
28
29 #include "AliMpGraphContext.h"
30
31 /// \cond CLASSIMP
32 ClassImp(AliMpGraphContext)
33 /// \endcond
34
35 AliMpGraphContext *AliMpGraphContext::fgInstance = 0;
36 AliMpGraphContext::GraphContextVector AliMpGraphContext::fgStack;
37
38 #ifdef WITH_ROOT
39 Int_t              AliMpGraphContext::fgStackSize = 0;
40 #endif
41
42 //_____________________________________________________________________________
43 AliMpGraphContext::AliMpGraphContext():
44   TObject(),
45   fColor(20),
46   fPadPosition(TVector2(0.5,0.5)),
47   fPadDimensions(TVector2(0.49,0.49)),
48   fRealPosition(TVector2(0.,0.)),
49   fRealDimensions(TVector2(1,1))
50 {
51 /// Default constructor (private)
52 }
53
54 //_____________________________________________________________________________
55 AliMpGraphContext::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 //_____________________________________________________________________________
67 AliMpGraphContext& 
68 AliMpGraphContext::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 //_____________________________________________________________________________
85 AliMpGraphContext *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 //_____________________________________________________________________________
95 TVector2 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 //_____________________________________________________________________________
115 void 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 //_____________________________________________________________________________
131 void 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 //_____________________________________________________________________________
141 void 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 //_____________________________________________________________________________
157 void 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 }