14 #include "msdevstudio/MSconfig.h"
18 #include <boost/python.hpp>
38 using std::runtime_error;
41 using namespace boost::python;
51 "A base class for representing data in various ways. For example, a\n"
52 "a histogram is a way to represent a column of data." )
54 .def ( init <
const std::string &,
56 const std::vector< std::string > & >
58 "DataRep ( string ) -> DataRep\n"
59 "DataRep ( string, DataSource, sequence ) -> DataRep\n"
60 "DataRep ( DataRep ) -> DataRep\n"
62 "Constructors for DataRep objects. The first form creates a\n"
63 "static version. The second form creates a dynamic version\n"
64 "bound to a DataSource with bindings taken from the strings in\n"
65 "the sequence. The final version makes a copy of existing\n"
67 "For the names of the types of DataRep classes available\n"
70 .def ( init <
const std::string &,
72 const std::vector< std::string > & > () )
74 .def ( init < PyDataRep * > () )
76 .def (
"names", &PyDataRep::names,
77 return_value_policy < copy_const_reference > (),
80 "Returns a tuple containing the names of the types of DataRep\n"
81 "that are available." )
83 .staticmethod (
"names" )
85 .def (
"setPointRep", &PyDataRep::setPointRep,
86 "setPointRep ( RepBase ) -> None\n"
88 "Sets the point representation." )
90 .def (
"setAxisBinding", &PyDataRep::setAxisBinding,
91 "setAxisBinding ( string, string ) -> None\n"
93 "Sets an axis binding. The first argument is the axis and the\n"
94 "second is a label of a column in the DataSource." )
96 .def (
"setAxisBindings", &PyDataRep::setAxisBindings,
97 "setAxisBindings ( string, sequence ) -> None\n"
99 "Sets all the axes bindings. The first argument is the axis and\n"
100 "the sequence contains labels of columns in the DataSource." )
102 .def (
"setWeight", &PyDataRep::setWeight,
103 "setWeight ( string ) -> None\n"
105 "Sets the weight option if DataRep is a type of histogram.\n"
106 "The string is a label of a column in the DataSource." )
108 .def (
"name", &PyDataRep::name,
109 return_value_policy < copy_const_reference > (),
110 "name ( ) -> string\n"
112 "Returns the type of DataRep." )
114 .def (
"getBinWidth", &PyDataRep::getBinWidth,
115 "getBinWidth ( string ) -> value\n"
117 "Returns the bin width on specified axis. Only meaningful if\n"
118 "object is histogram type." )
120 .def (
"getMean", &PyDataRep::getMean,
121 "getMean ( string ) -> value\n"
123 "Returns the mean of the data along specified axis" )
125 .def (
"getRMS", &PyDataRep::getRMS,
126 "getRMS ( string ) -> value\n"
128 "Returns root mean squared of data along specified axis" )
130 .def (
"numberOfEntries", &PyDataRep::numberOfEntries,
131 "numberOfEntries ( ) -> value\n"
133 "Returns the number of entries." )
135 .def (
"applyCut", &PyDataRep::applyCut,
136 "applyCut ( Cut ) -> None\n"
138 "Applies a Cut to limit the rows of the DataSource used by\n"
141 .def (
"applyCuts", &PyDataRep::applyCuts,
142 "applyCuts ( sequence ) -> None\n"
144 "Applies a sequence of Cut object to limit the rows of\n"
145 "the DataSource used by the Display." )
147 .def (
"colorNames", &PyDataRep::colorNames,
148 return_value_policy < copy_const_reference > (),
149 "colorNames () -> tuple\n"
151 "Returns a list of available color names." )
157 "set ( ColorValue ) -> None\n"
158 "set ( Line ) -> None\n"
159 "set ( Symbol ) -> None\n"
161 "Sets the color, line style or Symbol of the RepBase object.\n"
162 "Use ColorValue.values, Line.values, or Symbol.values to see\n"
163 "available values." )
175 .def (
"setColor", &PyDataRep::setColor,
176 "setColor ( string ) -> None\n"
178 "Sets the color of the point representation.\n"
179 "See DataRep.colorNames() for list of available colors." )
181 .def (
"setErrorDisplay", &PyDataRep::setErrorDisplay,
182 "setErrorDisplay ( string, boolean ) -> None\n"
184 "Turns on or off display of error bars, if available, on\n"
187 .def (
"createNTuple", &PyDataRep::createNTuple,
188 return_value_policy < manage_new_object > (),
189 "createNTuple () -> NTuple\n"
191 "Creates and returns an NTuple representation of the object." )
193 .def (
"getNTupleWithCuts", &PyDataRep::getNTupleWithCuts,
194 return_value_policy < manage_new_object > (),
195 "getNTupleWithCuts () -> NTuple\n"
197 "Creates and returns to NTuple being used, with cuts applied." )
199 .def (
"getColumnWithCuts",
200 (
const std::vector<double> & (
PyDataRep:: *)
201 (
const std::string & )
const )
202 &PyDataRep::getColumnWithCuts,
203 return_value_policy < copy_const_reference > (),
204 "getColumnWithCuts ( column ) -> tuple\n"
206 "Creates and returns the named column, with cuts applied." )
208 .def (
"createNTupleUnderRegion", &PyDataRep::createNTupleUnderRegion,
209 return_value_policy < manage_new_object > (),
210 "createNTupleUnderRegion () -> NTuple\n"
212 "Creates and returns a NTuple contain only rows that pass the\n"
215 .def (
"addCut", &PyDataRep::addCut,
216 "addCut ( ) -> None\n"
218 "Adds a cut to limit the region given to a fitter." )
220 .def (
"setCutRange", &PyDataRep::setCutRange,
221 "setCutRange ( low, high ) -> None\n"
223 "Sets the low and high end of the region highlight" )
225 .def (
"setSize", & PyDataRep::setSize,
226 "setSize ( value ) -> None\n"
228 "Sets the size of the point representation." )
230 .def (
"setSymbol", &PyDataRep::setSymbol,
231 "setSymbol ( string, value ) -> None\n"
233 "Sets the point symbol and size. This method is deprecated, use\n"
234 "DataRep.set(Symbol) and DataRep.setSize() instead." )
236 .def (
"setLineStyle", &PyDataRep::setLineStyle,
237 "setLineStyle ( string ) -> None\n"
239 "Sets the line style.\n"
240 "This method is deprecated, use DataRep.set(Line) instead." )
242 .def (
"normalizeTo", &PyDataRep::normalizeTo,
243 "normalizeTo ( DataRep ) -> None\n"
245 "Sets the object to normalize itself to a target one" )
247 .def (
"setBinWidth", &PyDataRep::setBinWidth,
248 "setBinWidth ( string, value ) -> None\n"
250 "Sets the width of the bins, if data representation is binned.\n" )
257 using namespace hippodraw;
259 std::map< std::string, hippodraw::Symbol::Type > PyDataRep::s_symbols;
260 std::map< std::string, hippodraw::Line::Style > PyDataRep::s_lineStyles;
261 bool PyDataRep::s_have_static_members(
false);
269 PyDataRep::PyDataRep (
const std::string &
type,
271 const std::vector< std::string > & bindings )
274 m_datarep = controller->
createDataRep ( type, ntuple, bindings );
278 PyDataRep::PyDataRep (
const std::string &
type,
280 const std::vector< std::string > & bindings )
288 PyDataRep::PyDataRep ()
299 const vector < string > &
305 return controller -> names ();
318 void PyDataRep::setPointRep (
RepBase * pointRep )
321 m_datarep->setPointRep ( pointRep );
325 void PyDataRep::setAxisBinding (
const std::string & axis,
326 const std::string & label )
330 m_datarep->setAxisBinding ( axis, label );
332 catch ( runtime_error & e ) {
339 void PyDataRep::setAxisBindings (
const std::vector< std::string > & bindings)
343 m_datarep->setAxisBindings ( bindings );
345 catch ( runtime_error & e ) {
352 void PyDataRep::setWeight (
const std::string &label )
355 if ( m_datarep->name() ==
"Histogram"
356 || m_datarep->name() ==
"Color Plot"
357 || m_datarep->name() ==
"Contour Plot") {
358 m_datarep->setAxisBinding( std::string(
"Weight (optional)"),
366 const std::string & PyDataRep::name ()
const
368 return m_datarep->name();
371 double PyDataRep::getBinWidth (
const std::string &axis )
383 getMean (
const std::string & axis )
386 double mean = m_datarep -> getMean ( axis );
394 getRMS (
const std::string & axis )
397 double rms = m_datarep -> getRMS ( axis );
403 double PyDataRep::numberOfEntries()
const
406 return projector -> getNumberOfEntries();
409 void PyDataRep::applyCut (
QtCut * cut )
414 controller -> linkCutAndRep( cp, m_datarep );
418 void PyDataRep::applyCuts (
const std::vector < QtCut * > & cuts )
422 unsigned int size = cuts.size();
423 for (
unsigned int i = 0;
i <
size;
i++ ) {
425 controller -> linkCutAndRep( cp, m_datarep );
431 const vector < string > &
435 return Color::colorNames ();
443 const RepBase *
rep = m_datarep -> getRepresentation ();
444 if ( rep -> uses ( value ) ) {
445 m_datarep -> set ( value );
449 const string what (
"This DataRep does not use ColorValue." );
450 throw std::runtime_error ( what );
457 setColor (
const std::string & color )
461 if ( Color::isValid ( color ) ) {
462 Color colorObj ( color );
463 m_datarep -> setRepColor ( colorObj );
466 std::string what (
"DataRep.setColor: color" );
469 what +=
"' not available.";
470 throw runtime_error( what );
477 setErrorDisplay (
const std::string &axis,
bool flag )
482 m_datarep->setErrorDisplay( at, flag );
489 createNTuple ()
const
493 const NTuple * ntuple = m_datarep -> createNTuple ();
500 NTuple * PyDataRep::getNTupleWithCuts ()
const {
502 NTuple * ntuple = m_datarep->getNTupleAfterCuts();
508 const std::vector<double> &
510 getColumnWithCuts(
const std::string &
column ) {
513 m_columnData.clear();
514 m_datarep->fillColumnAfterCuts(column, m_columnData);
523 createNTupleUnderRegion ()
const
527 NTuple * nt = m_datarep -> createNTupleUnderRegion ();
539 m_datarep -> addCut ( );
545 setCutRange (
double low,
double high )
549 const Range range ( low, high );
550 m_datarep -> setCutRangeAt ( range, 0 );
555 void PyDataRep::makeSymbolMap() {
571 const RepBase *
rep = m_datarep -> getRepresentation ();
572 if ( rep -> uses ( type ) ) {
573 m_datarep -> setRepStyle ( type );
577 const string what (
"This DataRep does not use Symbol type." );
578 throw std::runtime_error ( what );
588 m_datarep -> setRepSize ( size );
592 void PyDataRep::setSymbol(
const std::string &symbolName,
float size) {
594 if ( s_symbols.count( symbolName ) ) {
595 m_datarep -> setRepStyle ( s_symbols[symbolName] );
596 m_datarep -> setRepSize ( size );
599 std::ostringstream what;
600 what <<
"PyDataRep::setSymbol: symbol "
601 << symbolName <<
" is not available.\n"
602 <<
"Valid symbol names:\n";
603 std::map< std::string, hippodraw::Symbol::Type >
604 ::const_iterator
it = s_symbols.begin();
605 for ( ; it != s_symbols.end(); it++) {
606 what <<
" " << it->first <<
"\n";
608 throw runtime_error( what.str() );
613 void PyDataRep::makeLineStyleMap() {
627 const RepBase *
rep = m_datarep -> getRepresentation ();
628 if ( rep -> uses ( style ) ) {
629 m_datarep -> setRepStyle ( style );
633 const string what (
"This DataRep does not use Line style." );
634 throw std::runtime_error ( what );
642 setLineStyle(
const std::string &lineStyleName )
645 if ( s_lineStyles.count( lineStyleName ) ) {
646 m_datarep->setRepStyle( s_lineStyles[lineStyleName] );
649 std::ostringstream what;
650 what <<
"PyDataRep::setLineStyle: lineStyle "
651 << lineStyleName <<
" is not available.\n"
652 <<
"Valid lineStyle names:\n";
653 std::map< std::string, hippodraw::Line::Style >
654 ::const_iterator
it = s_lineStyles.begin();
655 for ( ; it != s_lineStyles.end(); it++) {
656 what <<
" " << it->first <<
"\n";
658 throw runtime_error( what.str() );
663 void PyDataRep::init() {
664 if (!s_have_static_members) {
668 s_have_static_members =
true;
678 const DataRep * datarep = rep -> m_datarep;
679 m_datarep -> normalizeTo ( datarep );
686 setBinWidth (
const std::string & axis,
double width )
692 controller -> setBinWidth ( m_datarep, type, width );
A singleton class that is the interface between GUI and the displays.
Qt Displays wraps a derived class of Cut1DPlotter.
hippodraw::QtCut class interface
hippodraw::PyDataRep class interface
Type
Enumeration of the type of symbols supported by this class.
void export_DataRep()
Exports the PyDataRep class to Python.
column
The column indices for 2 dimension data point tuple.
Value
A few common colors.
DataRep * createDataRep(const std::string &name)
Creates a new DataRep object of class name.
virtual double getBinWidth(Axes::Type axis) const
Returns the bin width of the axis.
A Color class for creating the color object following the standard RGB color space.
hippodraw::PyDataSource class interface
hippodraw::NTuple class interface.
PyArray_TYPES type(numeric::array arr)
The base class for data representations.
hippodraw::PyApp class interface.
A PlotterBase derived class that serves a base class for cut plotters.
DataRepController class interface.
intp size(numeric::array arr)
hippodraw::DyHistogram class interface.
A singleton class that is the interface between GUI and the DataRep.
virtual DataRep * clone()=0
The clone function returns an object of its own kind which is a copy of this object.
This class is the public interface to a DataSource object that the user sees as the DataArray object ...
hippodraw::ProjectorBase class interface.
Style
Line style constants.
hippodraw::RepBase class interface
A DataSource class implemented with std::vector<double> to store the column data. ...
The base class for the Projector hierarchy.
hippodraw::CutController class interface
const DataSource & dataSource() const
Return a reference to the underlying DataSource.
Expresses a range of values.
hippodraw::DataRep * getDataRep()
The get method.
Cut1DPlotter class interface.
Type convert(const std::string &axis)
Converts from string representation ot Axes::Type representation.
A singleton class that handles the application logic for cuts.
DisplayController class interface declaration.
list< QAction * >::iterator it
The base class for the point representation hierarchy.
This class is the public interface the what the user sees as the DataRep object from Python...
Base class for DataSource.