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