DataRep.cxx

Go to the documentation of this file.
00001 
00012 // for truncation warning in debug mode
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #include "DataRep.h"
00018 
00019 #include "datasrcs/NTuple.h"
00020 #include "datasrcs/TupleCut.h"
00021 #include "projectors/ProjectorBase.h"
00022 #include "reps/CutRangeRep.h"
00023 
00024 #include <algorithm>
00025 #include <stdexcept>
00026 
00027 #include <cassert>
00028 
00029 using std::string;
00030 using std::vector;
00031 
00032 using namespace hippodraw;
00033 
00034 DataRep::DataRep ( )
00035   : m_title ( "%t" ),
00036     m_projector ( 0 ),
00037     m_rep ( 0 ),
00038     m_parent_datarep ( 0 ),
00039     m_cut_rep ( 0 )
00040 {
00041 }
00042 
00043 DataRep::DataRep ( const DataRep & rep )
00044   : Observable ( ),
00045     Observer (),
00046     m_name ( rep.m_name ),
00047     m_title ( rep.m_title ),
00048     m_cut_rep ( 0 )
00049 {
00050   m_rep = rep.m_rep->clone ();
00051   m_projector = rep.m_projector->clone();
00052   m_parent_datarep = rep.m_parent_datarep;
00053   if ( rep.m_cut_rep != 0 ) {
00054     m_cut_rep = rep.m_cut_rep -> clone ();
00055   }
00056 }
00057 
00058 DataRep::~DataRep ()
00059 {
00060   notifyObservers ( &Observer::willDelete );
00061 
00062   delete m_projector;
00063   delete m_rep;
00064   if ( m_cut_rep != 0 ) delete m_cut_rep;
00065 }
00066 
00067 void DataRep::update ( const Observable * )
00068 {
00069   notifyObservers ();
00070 }
00071 
00072 const string & DataRep::name () const
00073 {
00074   return m_name;
00075 }
00076 
00077 /* virtual */
00078 DataRep * DataRep::getParentDataRep() const
00079 {
00080   return m_parent_datarep;
00081 }
00082 
00083 /* virtual */
00084 void DataRep::setParentDataRep( DataRep * parent_datarep )
00085 {
00086   m_parent_datarep =  parent_datarep;
00087 }
00088 
00089 
00090 bool DataRep:: hasErrorDisplay () const
00091 {
00092   return false;
00093 }
00094 
00095 bool DataRep::hasNTupleBindings () const
00096 {
00097   return true;
00098 }
00099 
00100 void
00101 DataRep::
00102 setAxisBinding ( const std::string & axis, 
00103                  const std::string & label )
00104 {
00105   if ( hasNTupleBindings () ) {
00106     m_projector -> setAxisBinding ( axis, label );
00107   }
00108 }
00109 
00110 void
00111 DataRep::
00112 setAxisBindings ( const std::vector < std::string > & bindings )
00113 {
00114   if ( hasNTupleBindings () ) {
00115     m_projector -> setAxisBindings ( bindings );
00116   }
00117 }
00118 
00119 void
00120 DataRep::
00121 matrixTranspose ( bool yes )
00122 {
00123   m_projector -> matrixTranspose ( yes );
00124 }
00125 
00126 void DataRep::setRepSize ( double size )
00127 {
00128  m_rep->setSize ( size );
00129 
00130  notifyObservers();
00131 }
00132 
00133 void DataRep::setDirty ( bool flag )
00134 {
00135   m_projector->setDirty ( flag );
00136 }
00137 
00138 ProjectorBase * DataRep::getProjector ( ) const
00139 {
00140   return m_projector;
00141 }
00142 
00143 void
00144 DataRep::
00145 setAxisModel ( hippodraw::Axes::Type axis, AxisModelBase * model )
00146 {
00147   m_projector->setAxisModel ( axis, model );
00148 }
00149 
00150 void DataRep::setSelected ( bool yes )
00151 {
00152   if ( yes != isSelected () ) {
00153     m_rep->setSelected ( yes );
00154     setDirty ( true );
00155   }
00156 }
00157 
00158 bool
00159 DataRep::
00160 isSelected () const
00161 {
00162   return m_rep ->isSelected ();
00163 }
00164 
00165 bool DataRep::isDirty ( ) const
00166 {
00167   return m_projector->isDirty();
00168 }
00169 
00170 double
00171 DataRep::
00172 getPosRange ( hippodraw::Axes::Type axis )
00173 {
00174   return m_projector->getPosOn ( axis );
00175 }
00176 
00177 Range
00178 DataRep::
00179 preferredRange ( hippodraw::Axes::Type axis ) const
00180 {
00181   return m_projector->preferredRange ( axis );
00182 }
00183 
00184 void
00185 DataRep::
00186 setErrorDisplay ( hippodraw::Axes::Type axis, bool flag )
00187 {
00188   assert ( axis == Axes::X || axis == Axes::Y );
00189 
00190   m_rep -> setErrorOn ( axis, flag );
00191 
00192   notifyObservers ();
00193 }
00194 
00195 bool
00196 DataRep::
00197 isErrorDisplayed ( hippodraw::Axes::Type axis ) const
00198 {
00199   assert ( axis == Axes::X || axis == Axes::Y );
00200 
00201 
00202   if ( axis == Axes::X ) {
00203     return m_rep->xError ( );
00204   }
00205   //else
00206   return m_rep->yError ( );
00207 }
00208 
00209 
00210 void
00211 DataRep::
00212 setRange ( hippodraw::Axes::Type axis, bool const_width )
00213 {
00214   m_projector->setRange ( axis, const_width );
00215 }
00216 
00217 void DataRep::setPointRep ( RepBase * rep )
00218 {
00219   Color color ( Color::black );
00220   if ( m_rep != 0 ) {
00221     bool yes_x = m_rep -> xError ();
00222     bool yes_y = m_rep -> yError ();
00223     color = m_rep -> getColor ();
00224     delete m_rep;
00225 
00226     rep -> setErrorOn ( Axes::X, yes_x );
00227     rep -> setErrorOn ( Axes::Y, yes_y );
00228   }
00229   m_rep = rep;
00230   m_rep -> setColor ( color );
00231   notifyObservers ();
00232 }
00233 
00234 RepBase * DataRep::getRepresentation () const
00235 {
00236   return m_rep;
00237 }
00238 
00239 void
00240 DataRep::
00241 set ( Color::Value value )
00242 {
00243   const Color color ( value );
00244   m_rep -> setColor ( color );
00245 
00246   notifyObservers ();
00247 }
00248 
00249 void DataRep::setRepColor ( const Color & color )
00250 {
00251   m_rep->setColor ( color );
00252 
00253   notifyObservers ();
00254 }
00255 
00256 void DataRep::setRepStyle ( int style )
00257 {
00258   m_rep->setStyle ( style );
00259   
00260   notifyObservers ();
00261 }
00262 
00263 const Color & DataRep::getRepColor () const
00264 {
00265   return m_rep->color ();
00266 }
00267 
00268 const DataSource *
00269 DataRep::
00270 getProjectedValues () const
00271 {
00272   m_projector->prepareValues();
00273   const DataSource * ntuple = m_projector -> getProjectedValues ();
00274 
00275   return ntuple;
00276 }
00277 
00278 void
00279 DataRep::
00280 drawProjectedValues ( TransformBase * transform, ViewBase * view )
00281 {
00282   drawCuts ( transform, view );
00283   const DataSource * ntuple = getProjectedValues ();
00284 
00285   m_rep -> drawProjectedValues ( ntuple, transform, view );
00286 }
00287 
00288 void
00289 DataRep::
00290 drawCuts ( TransformBase * transform, ViewBase * view )
00291 {
00292   if ( m_cut_rep != 0 ) {
00293     const Range & x_range = m_projector -> getRange ( Axes::X );
00294     const Range & y_range = m_projector -> getRange ( Axes::Y );
00295     m_cut_rep -> drawProjectedValues ( x_range, y_range, *transform, *view );
00296   }
00297 }
00298 
00299 bool DataRep::acceptFunction ( int )
00300 {
00301   return false;
00302 }
00303 
00304 bool DataRep::hasZeroRows ( )
00305 {
00306   bool yes = true;
00307   if ( m_projector != 0 )  {
00308     yes = m_projector->isEmpty ();
00309   }
00310 
00311   return yes;
00312 }
00313 
00314 bool DataRep::hasZoomY ( ) const
00315 {
00316   return false;
00317 }
00318 
00319 void
00320 DataRep::
00321 addValues  ( const std::vector < double > & v )
00322 {
00323   if ( hasNTupleBindings () ) return;
00324 
00325   m_projector -> addValues ( v );
00326 }
00327 
00328 NTuple *
00329 DataRep::
00330 getNTupleAfterCuts () const
00331 {
00332    return m_projector->getNTupleAfterCuts();
00333 }
00334 
00335 void
00336 DataRep::
00337 fillColumnAfterCuts(const std::string & column,
00338                     std::vector<double> & columnData) const {
00339    m_projector->fillColumnAfterCuts(column, columnData);
00340 }
00341 
00342 NTuple *
00343 DataRep::
00344 createNTupleUnderRegion () const
00345 {
00346   const vector < TupleCut > & cut_list = m_cut_rep -> getCuts ();
00347 
00348   return m_projector -> createNTupleWith ( cut_list );
00349 }
00350 
00351 double
00352 DataRep::
00353 getMean ( const std::string & axis )
00354 {
00355   Axes::Type type = Axes::convert ( axis );
00356 
00357   return m_projector -> getAverage ( type );
00358 }
00359 
00360 double
00361 DataRep::
00362 getRMS ( const std::string & axis )
00363 {
00364   Axes::Type type = Axes::convert ( axis );
00365 
00366   return m_projector -> getRMS ( type );
00367 }
00368 
00369 bool
00370 DataRep::
00371 isAxisBinned ( hippodraw::Axes::Type axis ) const
00372 {
00373   bool yes = false;
00374   if ( axis == Axes::X ) yes = m_projector -> isAxisBinned ( "X" );
00375   else if ( axis == Axes::Y ) yes = m_projector -> isAxisBinned ( "Y" );
00376 
00377   return yes;
00378 }
00379 
00380 void
00381 DataRep::
00382 update ()
00383 {
00384   m_projector -> setDirty ( true );
00385 }
00386 
00387 void
00388 DataRep::
00389  normalizeTo ( const DataRep * target )
00390 {
00391   ProjectorBase * projector = target -> getProjector ();
00392 
00393   m_projector -> normalizeTo ( projector );
00394 }
00395 
00396 const Range &
00397 DataRep::
00398 setBinWidth ( hippodraw::Axes::Type axis, double width )
00399 {
00400   return m_projector -> setBinWidth ( axis, width );
00401 }
00402 
00403 int
00404 DataRep::
00405 getNumberOfEntries () const
00406 {
00407   return m_projector -> getNumberOfEntries ();
00408 }
00409 
00410 bool
00411 DataRep::
00412 isTargetable () const
00413 {
00414   return true;
00415 }
00416 
00417 NTuple *
00418 DataRep::
00419 createNTuple () const
00420 {
00421   m_projector->prepareValues();
00422   const DataSource * ds = m_projector -> createOldStyleNTuple ();
00423   NTuple * ntuple = new NTuple ( ds );
00424 
00425   return ntuple;
00426 }
00427 
00428 void
00429 DataRep::
00430 setTitle ( const std::string & title )
00431 {
00432   m_title = title;
00433 }
00434 
00435 const std::string &
00436 DataRep::
00437 getTitle ( ) const
00438 {
00439   if ( m_title == "%t" ) {
00440     return m_projector -> getTitle ();
00441   }
00442   //  else 
00443   return m_title;
00444 }
00445 
00446 bool
00447 DataRep::
00448 needColorRep () const
00449 {
00450   return hasAxis ( Axes::Z );
00451 }
00452 
00453 bool
00454 DataRep::
00455 hasAxis ( hippodraw::Axes::Type ) const
00456 {
00457   assert ( false );
00458 
00459   return false;
00460 }
00461 
00462 void
00463 DataRep::
00464 addCut ( const TupleCut & cut )
00465 {
00466   if ( m_cut_rep == 0 ) {
00467     m_cut_rep = new CutRangeRep ();
00468   }
00469   m_cut_rep -> addCut ( cut );
00470 
00471   setDirty ( true );
00472 }
00473 
00474 void
00475 DataRep::
00476 removeCut ()
00477 {
00478   delete m_cut_rep;
00479   m_cut_rep = 0;
00480     
00481   setDirty ( true );
00482 }
00483 
00484 void
00485 DataRep::
00486 addCut ( )
00487 {
00488   TupleCut cut;
00489   const ProjectorBase * projector = getProjector ();
00490 
00491   const string & label = projector -> getXLabel ();
00492   cut.setLabel ( label );
00493 
00494   int index = projector -> indexOf ( label );
00495   cut.setColumn ( index );
00496 
00497   const Range & range  = projector -> getRange ( Axes::X );
00498   cut.setRange ( range );
00499 
00500   addCut ( cut );
00501 }
00502 
00503 const vector < TupleCut > &
00504 DataRep::
00505 getCuts () const
00506 {
00507   assert ( m_cut_rep != 0 );
00508 
00509   return m_cut_rep -> getCuts ();
00510 }
00511 
00512 bool
00513 DataRep::
00514 hasCut () const
00515 {
00516   return m_cut_rep != 0;
00517 }
00518 
00519 void
00520 DataRep::
00521 throwRangeException ()
00522 {
00523   string what ( "DataRep::setCutRange: index out of range." );
00524   throw std::out_of_range ( what );
00525 }
00526 
00527 void
00528 DataRep::
00529 setCutRangeAt ( const Range & range, unsigned int i )
00530 {
00531   m_cut_rep -> setCutRangeAt ( range, i );
00532 }
00533 
00534 void
00535 DataRep::
00536 toggleInverted ( unsigned int i )
00537 {
00538   assert ( m_cut_rep != 0 );
00539 
00540   m_cut_rep -> toggleInverted ( i );
00541 }
00542 
00543 void
00544 DataRep::
00545 setEnabled ( unsigned int i, bool yes )
00546 {
00547   m_cut_rep -> setEnabled ( i, yes );
00548 }
00549 
00550 RepBase *
00551 DataRep::
00552 getCutRep ()
00553 {
00554   return m_cut_rep;
00555 }
00556 
00557 bool
00558 DataRep::
00559 needsMatrixSet () const
00560 {
00561   return false;
00562 }
00563 
00564 bool
00565 DataRep::
00566 isImageConvertable () const
00567 {
00568   return m_projector -> isImageConvertable ();
00569 }
00570 

Generated for HippoDraw Class Library by doxygen