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