Bins1DBase.cxx
Go to the documentation of this file.
1 
12 #ifdef _MSC_VER
13 #include "msdevstudio/MSconfig.h"
14 #endif
15 
16 
17 #include "Bins1DBase.h"
18 
20 #include "datasrcs/NTuple.h"
21 
22 #include <cassert>
23 
24 using std::string;
25 using std::vector;
26 
27 using namespace hippodraw;
28 
29 Bins1DBase::Bins1DBase ( const char * name )
30  : BinsBase ( name ),
31  binner_axis ( 0 )
32 {
33 }
34 
36  : BinsBase ( binner ),
37  binner_axis ( 0 )
38 {
39  if ( binner.binner_axis != 0 ) {
40  binner_axis = binner.binner_axis->clone();
41  }
42 
43  m_values_dirty = true;
44 }
45 
47 {
48  if ( binner_axis ) delete binner_axis;
49 }
50 
51 int
54 {
55  return 1;
56 }
57 const BinnerAxis *
60 {
61  assert ( axis == Axes::X );
62 
63  return binner_axis;
64 }
65 
68 {
69  assert ( axis == Axes::X );
70 
71  if ( binner_axis ) delete binner_axis;
72 
73  binner_axis = binner;
74  resize ();
75  m_values_dirty = true;
76 }
77 
79 {
80  assert ( axis == Axes::X );
81 
82  return binner_axis->axisGetLow();
83 }
84 
85 double Bins1DBase::getHigh() const
86 {
87  return binner_axis->axisGetHigh();
88 }
89 
91 {
92  assert ( axis == Axes::X );
93 
94  return binner_axis->axisNumberOfBins();
95 }
96 
98 {
99  assert ( axis == Axes::X && nb > 0 );
100 
102 
103  resize ();
104 }
105 
106 bool
108 {
109  return binner_axis->hasEqualWidths ();
110 }
111 
112 double
113 Bins1DBase::binWidth ( int i ) const
114 {
115  return binner_axis->axisBinWidth(i);
116 }
117 
118 double
120 {
121  return binner_axis->scaleFactorWid ();
122 }
123 
124 double
126 {
127  assert ( axis == Axes::X );
128 
129  return binner_axis->getConstWid();
130 }
131 
132 const Range &
134 {
135  assert ( axis == Axes::X &&
136  width > 0.0 );
137 
138  const Range & range = binner_axis->setBinWidth ( width );
139  resize ();
140 
141  return range;
142 }
143 
144 double
146 calcBinWidth ( Axes::Type axis, int parm, bool dragging ) const
147 {
148  assert ( axis == Axes::X );
149  double new_width = binner_axis->calcBinWidth ( parm, dragging );
150 
151  return new_width;
152 }
153 
154 double
155 Bins1DBase::calcOffset ( const std::string & axis,
156  int parm,
157  bool dragging ) const
158 {
159  assert ( axis == "X" );
160 
161  return binner_axis->calcOffset ( parm, dragging );
162 }
163 
164 double
166 {
167  assert ( axis == Axes::X );
168 
169  return binner_axis->getOffset();
170 }
171 
172 void
174 setOffset ( hippodraw::Axes::Type axis, double offset )
175 {
176  assert ( axis == Axes::X );
177 
178  binner_axis->setOffset ( offset );
179 }
180 
181 const Range &
183 setRange ( hippodraw::Axes::Type axis, const Range & range, bool hold_width )
184 {
185  assert ( axis == Axes::X );
186 
187  const Range & new_range = binner_axis->setRange ( range, hold_width );
188  resize ();
189 
190  return new_range;
191 }
192 
193 const Range &
196 {
197  assert ( axis == Axes::X );
198 
199  return binner_axis->getRange();
200 }
201 
203 {
204  int number = numberOfBins ( Axes::X );
205  resize ( number );
206 }
207 
208 namespace dp = DataPoint2DTuple;
209 
210 NTuple *
212 prepareNTuple ( unsigned int rows ) const
213 {
214  unsigned int columns = 4;
215  NTuple * ntuple = new NTuple ( columns );
216  ntuple -> reserve ( rows );
217 
218  vector < string > labels;
219  labels.push_back ( "X" );
220  labels.push_back ( "Value" );
221  labels.push_back ( dp::WIDTH );
222  labels.push_back ( dp::ERROR );
223 
224  ntuple->setLabels ( labels );
225 
226  return ntuple;
227 }
virtual double calcOffset(const std::string &, int parm, bool dragging) const
Calculates and returns a new range from dragging slider.
Definition: Bins1DBase.cxx:155
unsigned int i
virtual bool hasEqualWidths() const
Returns true if all the bins have the same width.
Definition: BinnerAxis.cxx:59
double getHigh() const
Returns the lower edge of the last + 1 bin through binner_axis.
Definition: Bins1DBase.cxx:85
Bins1DBase(const char *name)
A constructor taking a bins container name.
Definition: Bins1DBase.cxx:29
virtual void setOffset(hippodraw::Axes::Type axis, double value)
Sets the offset parameter on the specified axis.
Definition: Bins1DBase.cxx:174
std::string ERROR
YERR column label.
virtual int numberOfBins(hippodraw::Axes::Type axis) const
Returns the number of bins on specified axis.
Definition: Bins1DBase.cxx:90
The base class for the one-dimensional binner hierarchy.
Definition: Bins1DBase.h:30
virtual double getLow(hippodraw::Axes::Type axis) const
Returns the low value of the bins on the specified axis.
Definition: Bins1DBase.cxx:78
const Range & getRange() const
Returns the range.
Definition: BinnerAxis.cxx:78
virtual const Range & setBinWidth(hippodraw::Axes::Type axis, double value)
Sets the bin width parameter on the specified axis.
Definition: Bins1DBase.cxx:133
virtual const Range & setRange(hippodraw::Axes::Type axis, const Range &, bool hold_width=true)
Sets the Range on the specified axis.
Definition: Bins1DBase.cxx:183
virtual bool hasEqualWidths() const
Returns true if all bins have the same width.
Definition: Bins1DBase.cxx:107
BinnerAxis * binner_axis
The binner axis object.
Definition: Bins1DBase.h:40
virtual double getOffset() const =0
Returns the offset.
virtual double scaleFactor() const
Returns the scale factor.
Definition: Bins1DBase.cxx:119
virtual double axisBinWidth(int i) const =0
Returns the width of each bin.
void setLabels(const std::vector< std::string > &v)
Assigns the label to each column from the vector of strings.
Definition: NTuple.cxx:471
virtual double getOffset(hippodraw::Axes::Type axis) const
Returns the offset parameter on specific axis.
Definition: Bins1DBase.cxx:165
virtual NTuple * prepareNTuple(unsigned int rows) const
Prepares the NTuple.
Definition: Bins1DBase.cxx:212
void resize()
Resizes the internal arrays.
Definition: Bins1DBase.cxx:202
virtual const Range & setBinWidth(double width)=0
Sets the bin width and adjusts the range and number of bins accordingly.
virtual BinnerAxis * clone()=0
The clone function returns an object of its own kind which is a copy of this object at this moment...
virtual int getNumberOfAxes() const
Returns the number of axes handled by the BinsBase derived class.
Definition: Bins1DBase.cxx:53
int axisNumberOfBins() const
Returns the number of bins.
Definition: BinnerAxis.cxx:84
virtual const Range & setRange(const Range &, bool hold_width=true)=0
Sets the range.
double axisGetLow() const
Returns the lower edge of the first bin.
Definition: BinnerAxis.cxx:65
hippodraw::NTuple class interface.
virtual double scaleFactorWid()=0
Returns the bin width associated with the scale factor.
virtual const BinnerAxis * getBinnerOn(hippodraw::Axes::Type axis) const
Returns the BinnerAxis object used by this object.
Definition: Bins1DBase.cxx:59
double binWidth(int i) const
Returns the width of each bin.
Definition: Bins1DBase.cxx:113
hippodraw::Bins1DBase class interface
bool m_values_dirty
A flag to indicate that the objects in m_values are not correct.
Definition: BinsBase.h:53
The base class for the BinnerAxis hierarchy.
Definition: BinnerAxis.h:35
virtual void setBinnerOn(BinnerAxis *, hippodraw::Axes::Type axis)
Sets a new BinnerAxis for the binner to use.
Definition: Bins1DBase.cxx:66
virtual void axisSetNumberOfBins(int nb)=0
Sets m_num_bins.
A DataSource class implemented with std::vector&lt;double&gt; to store the column data. ...
Definition: NTuple.h:33
virtual void setNumberOfBins(hippodraw::Axes::Type axis, int num_bins)
Sets the number of bins on the the specified axis.
Definition: Bins1DBase.cxx:97
virtual ~Bins1DBase()
The destructor.
Definition: Bins1DBase.cxx:46
virtual const void setOffset(double offset)=0
Sets the offset and adjusts the range accordingly.
Expresses a range of values.
Definition: Range.h:33
hippodraw::DataPointTuple namespace interface
double calcBinWidth(hippodraw::Axes::Type axis, int parm, bool dragging) const
Calculates the bin width from dragging slider.
Definition: Bins1DBase.cxx:146
virtual double calcOffset(int parm, bool dragging) const =0
Calculates and returns a double corresponding to a bin offset when dragging a slider control...
double axisGetHigh() const
Returns the lower edge of the last + 1 bin.
Definition: BinnerAxis.cxx:71
virtual double getConstWid() const =0
Returns the constant width parameter.
std::string WIDTH
XERR column label.
virtual const Range & getRange(hippodraw::Axes::Type axis)
Returns range from binner axis.
Definition: Bins1DBase.cxx:195
Type
Axes constants.
Definition: AxesType.h:31
The base class for the binner hierarchy.
Definition: BinsBase.h:33
double calcBinWidth(int parm, bool dragging) const
Calculates the bin width parameter when dragging a slider control.
Definition: BinnerAxis.cxx:130

Generated for HippoDraw Class Library by doxygen