DataRep.cxx
Go to the documentation of this file.
1 
12 // for truncation warning in debug mode
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "DataRep.h"
18 
19 #include "datasrcs/NTuple.h"
20 #include "datasrcs/TupleCut.h"
22 #include "reps/CutRangeRep.h"
23 
24 #include <algorithm>
25 #include <stdexcept>
26 
27 #include <cassert>
28 
29 using std::string;
30 using std::vector;
31 
32 using namespace hippodraw;
33 
35  : m_title ( "%t" ),
36  m_projector ( 0 ),
37  m_rep ( 0 ),
38  m_parent_datarep ( 0 ),
39  m_cut_rep ( 0 )
40 {
41 }
42 
44  : Observable ( ),
45  Observer (),
46  m_name ( rep.m_name ),
47  m_title ( rep.m_title ),
48  m_cut_rep ( 0 )
49 {
50  m_rep = rep.m_rep->clone ();
51  m_projector = rep.m_projector->clone();
53  if ( rep.m_cut_rep != 0 ) {
54  m_cut_rep = rep.m_cut_rep -> clone ();
55  }
56 }
57 
59 {
61 
62  delete m_projector;
63  delete m_rep;
64  if ( m_cut_rep != 0 ) delete m_cut_rep;
65 }
66 
67 void DataRep::update ( const Observable * )
68 {
69  notifyObservers ();
70 }
71 
72 const string & DataRep::name () const
73 {
74  return m_name;
75 }
76 
77 /* virtual */
79 {
80  return m_parent_datarep;
81 }
82 
83 /* virtual */
84 void DataRep::setParentDataRep( DataRep * parent_datarep )
85 {
86  m_parent_datarep = parent_datarep;
87 }
88 
89 
91 {
92  return false;
93 }
94 
96 {
97  return true;
98 }
99 
100 void
101 DataRep::
102 setAxisBinding ( const std::string & axis,
103  const std::string & label )
104 {
105  if ( hasNTupleBindings () ) {
106  m_projector -> setAxisBinding ( axis, label );
107  }
108 }
109 
110 void
111 DataRep::
112 setAxisBindings ( const std::vector < std::string > & bindings )
113 {
114  if ( hasNTupleBindings () ) {
115  m_projector -> setAxisBindings ( bindings );
116  }
117 }
118 
119 void
120 DataRep::
122 {
123  m_projector -> matrixTranspose ( yes );
124 }
125 
126 void DataRep::setRepSize ( double size )
127 {
128  m_rep->setSize ( size );
129 
130  notifyObservers();
131 }
132 
133 void DataRep::setDirty ( bool flag )
134 {
135  m_projector->setDirty ( flag );
136 }
137 
139 {
140  return m_projector;
141 }
142 
143 void
144 DataRep::
146 {
147  m_projector->setAxisModel ( axis, model );
148 }
149 
151 {
152  if ( yes != isSelected () ) {
153  m_rep->setSelected ( yes );
154  setDirty ( true );
155  }
156 }
157 
158 bool
159 DataRep::
160 isSelected () const
161 {
162  return m_rep ->isSelected ();
163 }
164 
165 bool DataRep::isDirty ( ) const
166 {
167  return m_projector->isDirty();
168 }
169 
170 double
171 DataRep::
173 {
174  return m_projector->getPosOn ( axis );
175 }
176 
177 Range
178 DataRep::
180 {
181  return m_projector->preferredRange ( axis );
182 }
183 
184 void
185 DataRep::
187 {
188  assert ( axis == Axes::X || axis == Axes::Y );
189 
190  m_rep -> setErrorOn ( axis, flag );
191 
192  notifyObservers ();
193 }
194 
195 bool
196 DataRep::
198 {
199  assert ( axis == Axes::X || axis == Axes::Y );
200 
201 
202  if ( axis == Axes::X ) {
203  return m_rep->xError ( );
204  }
205  //else
206  return m_rep->yError ( );
207 }
208 
209 
210 void
211 DataRep::
212 setRange ( hippodraw::Axes::Type axis, bool const_width )
213 {
214  m_projector->setRange ( axis, const_width );
215 }
216 
218 {
219  Color color ( Color::black );
220  if ( m_rep != 0 ) {
221  bool yes_x = m_rep -> xError ();
222  bool yes_y = m_rep -> yError ();
223  color = m_rep -> getColor ();
224  delete m_rep;
225 
226  rep -> setErrorOn ( Axes::X, yes_x );
227  rep -> setErrorOn ( Axes::Y, yes_y );
228  }
229  m_rep = rep;
230  m_rep -> setColor ( color );
231  notifyObservers ();
232 }
233 
235 {
236  return m_rep;
237 }
238 
239 void
240 DataRep::
241 set ( Color::Value value )
242 {
243  const Color color ( value );
244  m_rep -> setColor ( color );
245 
246  notifyObservers ();
247 }
248 
249 void DataRep::setRepColor ( const Color & color )
250 {
251  m_rep->setColor ( color );
252 
253  notifyObservers ();
254 }
255 
256 void DataRep::setRepStyle ( int style )
257 {
258  m_rep->setStyle ( style );
259 
260  notifyObservers ();
261 }
262 
263 const Color & DataRep::getRepColor () const
264 {
265  return m_rep->color ();
266 }
267 
268 const DataSource *
269 DataRep::
271 {
273  const DataSource * ntuple = m_projector -> getProjectedValues ();
274 
275  return ntuple;
276 }
277 
278 void
279 DataRep::
281 {
282  drawCuts ( transform, view );
283  const DataSource * ntuple = getProjectedValues ();
284 
285  m_rep -> drawProjectedValues ( ntuple, transform, view );
286 }
287 
288 void
289 DataRep::
290 drawCuts ( TransformBase * transform, ViewBase * view )
291 {
292  if ( m_cut_rep != 0 ) {
293  const Range & x_range = m_projector -> getRange ( Axes::X );
294  const Range & y_range = m_projector -> getRange ( Axes::Y );
295  m_cut_rep -> drawProjectedValues ( x_range, y_range, *transform, *view );
296  }
297 }
298 
300 {
301  return false;
302 }
303 
305 {
306  bool yes = true;
307  if ( m_projector != 0 ) {
308  yes = m_projector->isEmpty ();
309  }
310 
311  return yes;
312 }
313 
314 bool DataRep::hasZoomY ( ) const
315 {
316  return false;
317 }
318 
319 void
320 DataRep::
321 addValues ( const std::vector < double > & v )
322 {
323  if ( hasNTupleBindings () ) return;
324 
325  m_projector -> addValues ( v );
326 }
327 
328 NTuple *
329 DataRep::
331 {
333 }
334 
335 void
336 DataRep::
337 fillColumnAfterCuts(const std::string & column,
338  std::vector<double> & columnData) const {
339  m_projector->fillColumnAfterCuts(column, columnData);
340 }
341 
342 NTuple *
343 DataRep::
345 {
346  const vector < TupleCut > & cut_list = m_cut_rep -> getCuts ();
347 
348  return m_projector -> createNTupleWith ( cut_list );
349 }
350 
351 double
352 DataRep::
353 getMean ( const std::string & axis )
354 {
355  Axes::Type type = Axes::convert ( axis );
356 
357  return m_projector -> getAverage ( type );
358 }
359 
360 double
361 DataRep::
362 getRMS ( const std::string & axis )
363 {
364  Axes::Type type = Axes::convert ( axis );
365 
366  return m_projector -> getRMS ( type );
367 }
368 
369 bool
370 DataRep::
372 {
373  bool yes = false;
374  if ( axis == Axes::X ) yes = m_projector -> isAxisBinned ( "X" );
375  else if ( axis == Axes::Y ) yes = m_projector -> isAxisBinned ( "Y" );
376 
377  return yes;
378 }
379 
380 void
381 DataRep::
383 {
384  m_projector -> setDirty ( true );
385 }
386 
387 void
388 DataRep::
389  normalizeTo ( const DataRep * target )
390 {
391  ProjectorBase * projector = target -> getProjector ();
392 
393  m_projector -> normalizeTo ( projector );
394 }
395 
396 const Range &
397 DataRep::
398 setBinWidth ( hippodraw::Axes::Type axis, double width )
399 {
400  return m_projector -> setBinWidth ( axis, width );
401 }
402 
403 int
404 DataRep::
406 {
407  return m_projector -> getNumberOfEntries ();
408 }
409 
410 bool
411 DataRep::
412 isTargetable () const
413 {
414  return true;
415 }
416 
417 NTuple *
418 DataRep::
419 createNTuple () const
420 {
422  const DataSource * ds = m_projector -> createOldStyleNTuple ();
423  NTuple * ntuple = new NTuple ( ds );
424 
425  return ntuple;
426 }
427 
428 void
429 DataRep::
430 setTitle ( const std::string & title )
431 {
432  m_title = title;
433 }
434 
435 const std::string &
436 DataRep::
437 getTitle ( ) const
438 {
439  if ( m_title == "%t" ) {
440  return m_projector -> getTitle ();
441  }
442  // else
443  return m_title;
444 }
445 
446 bool
447 DataRep::
448 needColorRep () const
449 {
450  return hasAxis ( Axes::Z );
451 }
452 
453 bool
454 DataRep::
456 {
457  assert ( false );
458 
459  return false;
460 }
461 
462 void
463 DataRep::
464 addCut ( const TupleCut & cut )
465 {
466  if ( m_cut_rep == 0 ) {
467  m_cut_rep = new CutRangeRep ();
468  }
469  m_cut_rep -> addCut ( cut );
470 
471  setDirty ( true );
472 }
473 
474 void
475 DataRep::
477 {
478  delete m_cut_rep;
479  m_cut_rep = 0;
480 
481  setDirty ( true );
482 }
483 
484 void
485 DataRep::
487 {
488  TupleCut cut;
489  const ProjectorBase * projector = getProjector ();
490 
491  const string & label = projector -> getXLabel ();
492  cut.setLabel ( label );
493 
494  int index = projector -> indexOf ( label );
495  cut.setColumn ( index );
496 
497  const Range & range = projector -> getRange ( Axes::X );
498  cut.setRange ( range );
499 
500  addCut ( cut );
501 }
502 
503 const vector < TupleCut > &
504 DataRep::
505 getCuts () const
506 {
507  assert ( m_cut_rep != 0 );
508 
509  return m_cut_rep -> getCuts ();
510 }
511 
512 bool
513 DataRep::
514 hasCut () const
515 {
516  return m_cut_rep != 0;
517 }
518 
519 void
520 DataRep::
522 {
523  string what ( "DataRep::setCutRange: index out of range." );
524  throw std::out_of_range ( what );
525 }
526 
527 void
528 DataRep::
529 setCutRangeAt ( const Range & range, unsigned int i )
530 {
531  m_cut_rep -> setCutRangeAt ( range, i );
532 }
533 
534 void
535 DataRep::
536 toggleInverted ( unsigned int i )
537 {
538  assert ( m_cut_rep != 0 );
539 
540  m_cut_rep -> toggleInverted ( i );
541 }
542 
543 void
544 DataRep::
545 setEnabled ( unsigned int i, bool yes )
546 {
547  m_cut_rep -> setEnabled ( i, yes );
548 }
549 
550 RepBase *
551 DataRep::
553 {
554  return m_cut_rep;
555 }
556 
557 bool
558 DataRep::
560 {
561  return false;
562 }
563 
564 bool
565 DataRep::
567 {
568  return m_projector -> isImageConvertable ();
569 }
570 
void setTitle(const std::string &title)
Sets the title.
Definition: DataRep.cxx:430
Part of an implementation of the Observable-Observer pattern based on the example in the GOF Patterns...
Definition: Observable.h:39
virtual NTuple * getNTupleAfterCuts() const
Template for projectors that can return subsets of the NTuple used by the DataRep.
const std::vector< TupleCut > & getCuts() const
Returns a reference to the cut list.
Definition: DataRep.cxx:505
unsigned int i
void setRepSize(double size)
Sets the size of the representation.
Definition: DataRep.cxx:126
std::string m_name
The name of the display as it might be displayed in a GUI.
Definition: DataRep.h:76
const Color & getRepColor() const
Returns the color used for the representation.
Definition: DataRep.cxx:263
DataRep()
The default constructor.
Definition: DataRep.cxx:34
virtual bool isTargetable() const
Returns true if the receiving object is target-able.
Definition: DataRep.cxx:412
virtual void setAxisBinding(const std::string &axis, const std::string &label)
Sets the axis binding.
Definition: DataRep.cxx:102
DataRep * m_parent_datarep
There are times when a given DataRep results from some operations performed on some other DataRep...
Definition: DataRep.h:99
virtual void notifyObservers() const
Notifies Observer objects of a change.
Definition: Observable.cxx:93
virtual bool needsMatrixSet() const
Returns true if this data representation needs an XY matrix parameters to be set in order to display ...
Definition: DataRep.cxx:559
virtual DataRep * getParentDataRep() const
Gets the parent DataRep.
Definition: DataRep.cxx:78
void setEnabled(unsigned int i, bool yes=true)
Sets the TupleCut indexed by i to be enabled or not.
Definition: DataRep.cxx:545
virtual void update()
Updates the data representation.
Definition: DataRep.cxx:382
A transform that transforms coordinates from one coordinate system to another.
Definition: TransformBase.h:35
A derived class of PointRepBase class that draws a representation of a cut range. ...
Definition: CutRangeRep.h:29
virtual RepBase * clone()=0
Returns a copy of the object.
virtual void setAxisBindings(const std::vector< std::string > &bindings)
Sets the axis bindings.
Definition: DataRep.cxx:112
const std::string & name() const
Returns the name of the display.
Definition: DataRep.cxx:72
double getPosRange(Axes::Type axis)
Returns the smallest positive number from in the range of the data.
Definition: DataRep.cxx:172
NTuple * createNTupleUnderRegion() const
Returns a NTuple that is a copy of the projector&#39;s DataSource with rows not passing region cuts remov...
Definition: DataRep.cxx:344
RepBase * getCutRep()
Returns the point representation that draws the cuts.
Definition: DataRep.cxx:552
virtual void prepareValues()
Informs the projector to prepare its projected values for plotting.
virtual void setPointRep(RepBase *pointrep)
Sets the representation of the data points.
Definition: DataRep.cxx:217
int getNumberOfEntries() const
Returns the number of entries used for the DataRep object.
Definition: DataRep.cxx:405
void setErrorDisplay(Axes::Type axis, bool)
Sets the display of error bar, if applicable, on the specified axis.
Definition: DataRep.cxx:186
virtual NTuple * getNTupleAfterCuts() const
Returns the full NTuple but with the current set of cuts applied.
Definition: DataRep.cxx:330
void setRange(const Range &range)
Sets the range of the cut.
Definition: TupleCut.cxx:77
virtual bool isEmpty() const =0
Returns true if the data source used by this projector is empty.
hippodraw::DataRep class interface.
virtual void setSelected(bool yes=true)
Sets the representation to be selected if yes is true, otherwise set it to be deselected.
Definition: RepBase.cxx:72
column
The column indices for 2 dimension data point tuple.
virtual void addValues(const std::vector< double > &v)
Add the data values to the DataRep.
Definition: DataRep.cxx:321
virtual void setSelected(bool yes=true)
Sets the data representation as selected.
Definition: DataRep.cxx:150
virtual void willDelete(const Observable *)
Notifies this Observer object that one of its Observable objects is about to be deleted.
Definition: Observer.cxx:25
virtual ~DataRep()
The destructor.
Definition: DataRep.cxx:58
bool isDirty() const
Returns true if the projector has been marked dirty.
void setAxisModel(Axes::Type axis, AxisModelBase *)
Sets the AxisModel for axis axis.
Definition: DataRep.cxx:145
bool isErrorDisplayed(Axes::Type) const
Returns true if the error bars are being displayed.
Definition: DataRep.cxx:197
The class expresses a cut on a DataSource, i.e.
Definition: TupleCut.h:43
return rep
Definition: Inspector.cxx:3843
Value
A few common colors.
Definition: Color.h:51
virtual void setDirty(bool value=true)
Sets the dirty flag to value.
RepBase * m_rep
The representation used for drawing each data point in the view.
Definition: DataRep.h:94
return yes
Definition: CanvasView.cxx:883
virtual void setRange(Axes::Type axis, bool const_width=true)
Sets the range of the selected axis.
void throwRangeException()
Throws exception with message saying argument is out of range.
Definition: DataRep.cxx:521
virtual bool needColorRep() const
Determines if extra space is needed for a color rep.
Definition: DataRep.cxx:448
NTuple * createNTuple() const
Returns a new NTuple representation of the receiving object.
Definition: DataRep.cxx:419
virtual bool yError() const
Returns true if the point representation displays error on the Y axis.
Definition: RepBase.cxx:122
A Color class for creating the color object following the standard RGB color space.
Definition: Color.h:37
void setRepStyle(int style)
Sets the style type of the point representation.
Definition: DataRep.cxx:256
hippodraw::NTuple class interface.
virtual const DataSource * getProjectedValues() const
Returns an DataSource representation of the projected data.
Definition: DataRep.cxx:270
bool isDirty() const
Return true if the data representation has changed is some way and it needs to be re-drawn...
Definition: DataRep.cxx:165
virtual void setStyle(unsigned int style)
Sets the symbol of the representation.
Definition: RepBase.cxx:103
virtual bool hasErrorDisplay() const
Returns true if the data representation is capable of error display on the data values.
Definition: DataRep.cxx:90
PyArray_TYPES type(numeric::array arr)
Definition: num_util.cpp:249
The base class for data representations.
Definition: DataRep.h:68
virtual Range preferredRange(Axes::Type) const
Returns the preferred Range.
void toggleInverted(unsigned int i)
Changes state of inversion flag to be the opposite of its current state.
Definition: DataRep.cxx:536
std::string m_title
The title of the object.
Definition: DataRep.h:82
virtual bool isSelected() const
Returns true if data representation is in selected state.
Definition: DataRep.cxx:160
ViewBase * v
Definition: PlotTable.cxx:104
virtual bool hasAxis(Axes::Type axis) const
Returns true if the data representation has specified axis type axis.
Definition: DataRep.cxx:455
virtual double getMean(const std::string &axis)
Returns the mean.
Definition: DataRep.cxx:353
intp size(numeric::array arr)
Definition: num_util.cpp:296
virtual void normalizeTo(const DataRep *target)
Normalizes the receiving object to the target one.
Definition: DataRep.cxx:389
CutRangeRep * m_cut_rep
The representation of the cut or highlighted range.
Definition: DataRep.h:103
virtual ProjectorBase * clone()=0
The clone function returns an object of its own kind which is a copy of this object at this moment...
void setCutRangeAt(const Range &range, unsigned int i)
Sets the Range of the TupleCut index by i.
Definition: DataRep.cxx:529
virtual void setSize(float value)
Sets the size of the representation.
Definition: RepBase.cxx:96
const std::string & getTitle() const
Returns the the current title of the object.
Definition: DataRep.cxx:437
virtual const Color & color() const
Returns the representation&#39;s color.
Definition: RepBase.cxx:63
The AxisModelBase class maintains the Range and scaling of an axis.
Definition: AxisModelBase.h:33
bool hasCut() const
Returns true if the receiving object has one or more regional cuts.
Definition: DataRep.cxx:514
void drawCuts(TransformBase *transform, ViewBase *view)
Draws the cuts.
Definition: DataRep.cxx:290
virtual bool hasNTupleBindings() const
Returns true if the DataRep&#39;s projector can bind to DataSource.
Definition: DataRep.cxx:95
virtual DataRep * clone()=0
The clone function returns an object of its own kind which is a copy of this object.
virtual void setColor(const Color &)
Sets the color of the representation.
Definition: RepBase.cxx:53
hippodraw::ProjectorBase class interface.
const Range & setBinWidth(Axes::Type axis, double width)
Sets the bin width, if binned, on specified axis to width.
Definition: DataRep.cxx:398
virtual void fillColumnAfterCuts(const std::string &column, std::vector< double > &columnData) const
Fill the vector with values from named column with the present set of cuts applied.
Part of an implementation of the Observable Observer pattern based on the example implementation in t...
Definition: Observer.h:34
virtual bool acceptFunction(int number)
Returns true if the DataRep accepts functions on number variables.
Definition: DataRep.cxx:299
A DataSource class implemented with std::vector&lt;double&gt; to store the column data. ...
Definition: NTuple.h:33
The base class for the Projector hierarchy.
Definition: ProjectorBase.h:56
The abstract base class for views.
Definition: ViewBase.h:62
ProjectorBase * m_projector
A projector used to transform data to projected values that will be plotted.
Definition: DataRep.h:90
hippodraw::TupleCut class interface
virtual void fillColumnAfterCuts(const std::string &column, std::vector< double > &columnData) const
Fills a vector with named column data with the current set of cuts applied.
Definition: DataRep.cxx:337
Range preferredRange(Axes::Type axis) const
Returns the preferred range to display the data.
Definition: DataRep.cxx:179
virtual void setAxisModel(Axes::Type axis, AxisModelBase *)
Sets the AxisModel for axis axis.
void removeCut()
Remove a region cut on the data representation.
Definition: DataRep.cxx:476
virtual void drawProjectedValues(TransformBase *transform, ViewBase *view)
Draws the projected values.
Definition: DataRep.cxx:280
void setRepColor(const Color &)
Sets the color of the data representation.
Definition: DataRep.cxx:249
virtual bool isSelected() const
Returns true if representation is in selected state, otherwise returns false.
Definition: RepBase.cxx:79
virtual bool hasZeroRows()
Returns true if this DataRep has zero rows in its DataSource.
Definition: DataRep.cxx:304
virtual bool hasZoomY() const
Returns true if this DataRep has zoom feature on the Y axis.
Definition: DataRep.cxx:314
void addCut()
Adds a cut to the data representation.
Definition: DataRep.cxx:486
virtual void setDirty(bool yes=true)
Sets the dirty flag.
Definition: DataRep.cxx:133
Expresses a range of values.
Definition: Range.h:33
virtual bool isImageConvertable() const
Returns true if the receiving object can be converted to an image.
Definition: DataRep.cxx:566
return index
Definition: PickTable.cxx:182
virtual bool xError() const
Returns true if the point representation displays error on the X axis.
Definition: RepBase.cxx:116
Type convert(const std::string &axis)
Converts from string representation ot Axes::Type representation.
Definition: AxesType.cxx:32
virtual double getRMS(const std::string &axis)
Returns the RMS.
Definition: DataRep.cxx:362
bool isAxisBinned(Axes::Type axis) const
Returns true if the specified axis is binned, otherwise returns false.
Definition: DataRep.cxx:371
void setLabel(const std::string &label)
Sets the label for the cut.
Definition: TupleCut.cxx:117
virtual ProjectorBase * getProjector() const
Returns the Projector object controlling the data.
Definition: DataRep.cxx:138
virtual void matrixTranspose(bool yes)
Transposes the X and Y axis.
Definition: DataRep.cxx:121
virtual double getPosOn(Axes::Type) const =0
Returns the minimum positive value.
Type
Axes constants.
Definition: AxesType.h:31
The base class for the point representation hierarchy.
Definition: RepBase.h:45
void set(Color::Value value)
Sets the Color of the PointRepBase object.
Definition: DataRep.cxx:241
RepBase * getRepresentation() const
Returns the representation used to draw the data points.
Definition: DataRep.cxx:234
CutRangeRep class interface.
virtual void setParentDataRep(DataRep *parent_datarep)
Sets the parent DataRep.
Definition: DataRep.cxx:84
void setColumn(unsigned int col)
Sets the column in the DataSource to be used.
Definition: TupleCut.cxx:63
Base class for DataSource.
Definition: DataSource.h:55
void setRange(Axes::Type axis, bool const_width=true)
Sets the range of the axis.
Definition: DataRep.cxx:212

Generated for HippoDraw Class Library by doxygen