13 #include <boost/python.hpp>
21 #include "msdevstudio/MSconfig.h"
35 using std::runtime_error;
39 using namespace hippodraw;
72 const vector < double > &
76 static vector < double > temp;
83 catch (
const runtime_error & e ) {
90 const vector < double > &
93 const std::vector < int > & indexes )
const
95 static vector < double > temp;
98 const vector < double > &
column
103 catch (
const runtime_error & e ) {
110 const vector < double > &
114 static vector < double > temp;
121 catch (
const runtime_error & e ) {
129 const vector < double > &
133 static vector < double > temp;
140 catch (
const runtime_error & e ) {
151 const std::vector < double > &
column )
156 const std::vector < std::string > &
174 catch (
const runtime_error & e ) {
184 unsigned int rank = shape.size ();
185 for (
unsigned int i = 0;
i < rank -1;
i++ ) {
186 shape[
i] = shape[
i+1];
191 const std::vector < int >
198 string what (
"RootNTuple: No column with named `" );
201 throw std::runtime_error ( what );
203 vector < int >
shape;
211 catch (
const runtime_error & e ) {
229 const std::vector < int > & indices )
const
234 using namespace boost::python;
238 valueAt (
unsigned int row,
const std::string & variable )
243 vector < int >
shape;
244 fillShape ( shape, column );
245 sliceRowDimension ( shape );
275 throw std::runtime_error (
"HippoDraw was not built with "
276 "numeric Python support" );
285 throwIfInvalidLabel ( name );
286 unsigned int length = rows ();
287 unsigned int column = indexOf ( name );
289 if ( isMultiDimensional ( name ) ==
false ) {
290 vector < int >
shape;
291 shape.push_back ( length );
292 const vector < double > & col_vec = getColumn ( column );
293 double * array = const_cast <
double * > ( &col_vec[0] );
300 vector < int >
shape;
301 fillShape ( shape, column );
302 unsigned int rank = shape.size();
303 for (
unsigned int i = 1;
i <
rank;
i++ ) {
306 int total_size = size * shape [ 0 ];
313 vector < double > array_vec;
314 array_vec.reserve ( total_size );
315 for (
unsigned int row = 0; row < length; row++ ) {
317 array_vec.insert ( array_vec.end(), array, array +
size );
327 vector < float > array_vec;
328 array_vec.reserve ( total_size );
329 for (
unsigned int row = 0; row < length; row++ ) {
331 array_vec.insert ( array_vec.end(), array, array +
size );
341 vector < int > array_vec;
342 array_vec.reserve ( total_size );
343 for (
unsigned int row = 0; row < length; row++ ) {
345 array_vec.insert ( array_vec.end(), array, array +
size );
355 vector < unsigned int > array_vec;
356 array_vec.reserve ( total_size );
357 for (
unsigned int row = 0; row < length; row++ ) {
359 array_vec.insert ( array_vec.end(), array, array +
size );
371 vector < double > array_vec;
376 throw std::runtime_error (
"HippoDraw was not built with "
377 "numeric Python support" );
const std::vector< std::string > & getLabels() const
Returns the labels of the column, i.e.
boost::python::numeric::array valueAt(unsigned int row, const std::string &variable)
Returns a numarray for variable in row of NTuple.
Type
The type of data on the branch.
numeric::array makeNum(object x)
virtual void fillShape(std::vector< int > &v, unsigned int column) const
Fills the vector with the shape of a column.
hippodraw::QtRootNTuple class interface.
const std::vector< int > getColumnShape(const std::string &column)
Returns the shape of multidimensional array excluding row dimension.
std::string createBinding(const std::string &name, const std::vector< int > &indices) const
Creates complete binding string from the array variable name and indexes.
unsigned int rows() const
Returns the number of rows.
A DataSource class implemented with a ROOT TBranch objects from a ROOT TTree to store the column data...
virtual float * floatArrayAt(unsigned int row, unsigned int column) const
Returns pointer to a float array type in given row.
static void lock()
Obtains a lock on the application's mutex.
void expandIfNeeded(const std::vector< std::string > &labels) const
Expand the multidimension column if needed.
column
The column indices for 2 dimension data point tuple.
virtual double * doubleArrayAt(unsigned int row, unsigned int column) const
Returns pointer to a double array type in given row.
std::vector< intptr_t > shape(numeric::array arr)
QtRootNTuple()
The default constructor.
PyArray_TYPES type(numeric::array arr)
std::string createBinding(const std::string &name, const std::vector< int > &indices) const
virtual const std::vector< std::string > & getLabels() const
Returns the list of available labels.
unsigned int columns() const
Returns the number of columns.
hippodraw::PyApp class interface.
virtual int * intArrayAt(unsigned int row, unsigned int column) const
Returns pointer to a int array type in given row.
static void sliceRowDimension(std::vector< int > &shape)
Removes the row dimension, i.e.
int addColumn(const std::string &label, RootBranch *)
Adds a column to the end of the RootNTuple.
intp size(numeric::array arr)
int rank(numeric::array arr)
virtual unsigned int rows() const
Returns the size of first dimension, i.e.
virtual const std::vector< double > & getRow(unsigned int i) const
Returns a const reference to slice along the axis known as a row.
virtual void throwIfInvalidLabel(const std::string &label) const
Throws a DataSourceException object if label is not a valid label for this DataSource.
hippodraw::RootData::Type getType(unsigned int column) const
Returns the type of data in column.
const std::vector< double > & getColumn(const std::string &name) const
Returns copy of TBranch data by name.
virtual const std::vector< double > & getColumn(const std::string &name) const
Returns the data in the column with label name.
static void unlock()
Releases the lock on the application's mutex.
virtual int indexOf(const std::string &label) const
Returns true if the specified column labeled label has been filled.
unsigned int columns() const
Returns the number of columns or data arrays available from this DataSource.
boost::python::numeric::array getColumnAsArray(const std::string &variable)
Returns a numarray for variable.
int addColumn(const std::string &, const std::vector< double > &)
Adds a column to the object.
bool isMultiDimensional(const std::string &column) const
Returns true if the column named column, is an array, rather then simple type.
void expandIfNeeded(const std::vector< std::string > &labels) const
Expand the labels if needed.
virtual bool isMultiDimensional(const std::string &column) const
Answers if rows of column are composed of the multidimensional data.
virtual unsigned int * uintArrayAt(unsigned int row, unsigned int column) const
Returns pointer to a unsigned int array type in given row and column.
const std::vector< double > & getRow(unsigned int index) const
Returns the row indexed by index.