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 
43 DataRep::DataRep ( const DataRep & rep )
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::
121 matrixTranspose ( bool yes )
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 
150 void DataRep::setSelected ( bool yes )
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 

Generated for HippoDraw Class Library by doxygen