17 #include "w32pragma.h"
46 using std::runtime_error;
48 using namespace hippodraw;
54 m_cur_entry ( UINT_MAX )
63 m_cur_entry ( UINT_MAX )
71 BranchList_t::iterator first =
m_data.begin();
72 while ( first !=
m_data.end() ) {
78 vector< double > * p = *cache++;
94 TObjArray * branches =
m_tree -> GetListOfBranches ();
95 Int_t number = branches -> GetEntries ();
97 for ( Int_t i = 0; i < number; i++ )
99 TObject *
object = branches -> At ( i );
103 branch -> SetBasketSize ( 320000 );
106 const string name =
object -> GetName ();
113 m_dups.push_back ( name );
115 m_data [ index ] = h_branch;
125 const std::vector < int > & sz,
130 if( d < sz.size() - 1 )
136 full = ( wheels[d] ==
static_cast< int >( sz[d] ) ) ?
148 full = ( wheels[d] ==
static_cast< int >( sz[d] ) ) ?
true :
false;
169 Double_t number =
m_tree -> GetEntries ();
170 return static_cast <
unsigned int > ( number );
178 vector < double > * cache =
new vector < double > (
size );
180 for (
unsigned int row = 0; row <
size; row++ ) {
181 double value = data ->
valueAt ( row );
212 if ( column <
m_data.size () ) {
214 value = data ->
valueAt ( row );
217 value =
valueAt ( row, column );
272 for (
unsigned int i = 0; i <
m_data_cache.size (); i++ ) {
299 const vector < double > &
303 const vector < string > & labels =
getLabels ();
304 unsigned int size = labels.size();
306 const string & label = labels [
column ];
311 std::string what (
"RootNTuple: can not export data source\n"
312 "because some column(s) cantain\n"
313 " variable length data" );
314 throw runtime_error ( what );
337 string what (
"RootNTuple Attempt to add a column whose label"
338 " is same as other column." );
339 throw runtime_error ( what );
342 m_data.push_back ( branch );
353 const std::vector < double > & col )
358 string what (
"RootNTuple Attempt to add a column whose label"
359 " is same as other column." );
360 throw runtime_error ( what );
363 unsigned int new_size = col.size ();
365 if (
m_data.empty () == false ) {
366 unsigned int old_size =
rows ();
368 if ( old_size != 0 && old_size != new_size ) {
369 string what (
"RootNTuple Attempt to add a column whose size"
370 " is not equal to other columns." );
371 throw runtime_error ( what );
374 vector < double > *
vec =
new vector < double > ( col );
386 const std::vector < double > &
data )
391 (
"RootNTuple: Attempt to replace non-existant column." );
392 throw runtime_error ( what );
396 unsigned int new_size = data.size ();
397 if ( size != 0 && size != new_size ) {
399 (
"RootNTuple: Attempt to replace column with one whose "
400 "size is not equal to other columns." );
401 throw runtime_error ( what );
404 std::copy ( data.begin(), data.end(),
m_data_cache [ col ] -> begin() );
417 const vector < unsigned int > &
429 unsigned int colIndex =
indexOf( column );
438 unsigned int colIndex =
indexOf( column );
453 BranchList_t::size_type
size =
m_data.size ();
454 if ( column < size ) {
456 const vector < int > & sub_shape = col ->
getShape ();
457 unsigned int rank = sub_shape.size ();
459 for (
unsigned int i = 0; i <
rank; i++ ) {
460 shape.push_back ( sub_shape [ i ] );
468 const std::vector< unsigned int >& index )
473 unsigned int colIndex =
indexOf ( column );
487 unsigned int colIndex =
indexOf ( column );
505 const vector< string > & labels =
getLabels();
507 for(
unsigned int i = 0; i < labels.size(); i++ ) {
508 const string & label = labels[i];
509 if( label.find( column +
"[" ) != string::npos ) {
518 unsigned int colIndex =
indexOf ( column );
522 unsigned int dims = colRootBranch ->
getRank ();
523 const vector < int > & sz =colRootBranch ->
getShape ();
524 int nelems = colRootBranch -> numberOfElements();
526 vector< unsigned int > indx( dims, 0);
528 vector< int > wheels( dims, 0);
529 wheels[ dims - 1 ] = -1;
532 for(
int i = 0; i < nelems; i++ )
534 #ifdef SSTREAM_DEFECT
535 std::ostrstream namestream;
537 std::ostringstream namestream;
542 for (
unsigned int j = 0; j < dims; j++ ) {
543 namestream <<
"[" << wheels[ j ] <<
"]";
546 colTBranch -> SetBasketSize ( 320000 );
549 for(
unsigned int k = 0; k < wheels.size(); k++ )
550 indx[ k ] = static_cast< unsigned int > ( wheels[ k ] );
553 rtuple ->
addColumn ( namestream.str(), h_branch );
564 string::size_type pos = column.find_first_of (
'[' );
566 if ( pos != string::npos ) {
567 const string label = column.substr ( 0, pos );
579 unsigned int size = labels.size ();
581 for (
unsigned int i = 0; i <
size; i++ ) {
582 const string &
column = labels [ i ];
587 const vector < double > &
599 const vector < double > &
602 const std::vector < int > & indices )
const
609 const vector < double > &
626 const std::vector < int > & indices )
const
628 string text ( label );
630 unsigned int size = indices.size();
631 for (
unsigned int i = 0; i <
size; i++ ) {
Type
The type of data on the branch.
virtual void notifyObservers() const
Notifies observers.
unsigned int getRank() const
Returns the rank of the data source.
void smartExpandRootNTuple(const std::string &column) const
Suppose we encounter a RootNTuple which has multi-dimensional data sitting in the rows of the concern...
virtual int * intArrayAt(unsigned int row, unsigned int column) const
Returns pointer to a int array type in given row.
virtual ~RootNTuple()
The destructor.
hippodraw::Range class interface
virtual double valueAtNoCache(unsigned int row, unsigned int column) const
Returns the value in the table in position given by the row and column indexes without storing it int...
virtual unsigned int rows() const
Returns the size of first dimension, i.e.
void * data(numeric::array arr)
std::vector< unsigned int > m_shape
The shape of the data.
Base class for DataSource.
virtual void notifyObservers() const
Notifies Observer objects of a change.
TBranch * getTBranch(const std::string &column)
Get the TBranch associated with this column.
virtual const std::vector< std::string > & getLabels() const
Returns the list of available labels.
virtual void setShape(std::vector< unsigned int > &shape)
Sets the shape of the data elements.
virtual double valueAt(unsigned int row, unsigned int column) const
Returns the value in the table in position given by the row and column indexes.
void expandIfNeeded(const std::vector< std::string > &labels) const
Expand the labels if needed.
virtual void reserve(unsigned int)
Does nothing as the contained ROOT file controls the size.
virtual float * floatArrayAt(unsigned int row, unsigned int column) const
Returns pointer to a float array type in given row.
std::vector< intptr_t > shape(numeric::array arr)
virtual bool setReleventIndex(const std::string &column, const std::vector< unsigned int > &index)
In case we are dealing with multidimensional data in rows of this column we would like to deal with o...
bool isValidColumn(unsigned int index) const
Returns true if index is valid, otherwise throws a DataSourceException.
Observer class interface.
virtual void clear()
Removes all the cached data vectors, does not change the contained ROOT file.
virtual void fillShape(std::vector< int > &v, unsigned int column) const
Fills the vector with the shape of a column.
unsigned int columns() const
Returns the number of columns or data arrays available from this DataSource.
int addColumn(const std::string &label, RootBranch *)
Adds a column to the end of the RootNTuple.
std::vector< double > m_array
A temporary array that can be returned by const reference.
std::vector< std::string > m_dups
A list of labels that duplicated others in a DataSource file.
A DataSource class implemented with a ROOT TBranch objects from a ROOT TTree to store the column data...
void initBranches()
Initializes the columns of the NTuple.
BranchList_t m_data
The RootBranch objects that contains the data.
virtual void throwIfInvalidLabel(const std::string &label) const
Throws a DataSourceException object if label is not a valid label for this DataSource.
const std::vector< unsigned int > & getShape() const
Returns the shape of the data elements.
bool rotateWheels(std::vector< int > &wheels, const std::vector< int > &sz, unsigned int d)
A hack to generate labels.
virtual const std::vector< double > & getRow(unsigned int i) const
Returns a const reference to slice along the axis known as a row.
std::string createBinding(const std::string &name, const std::vector< int > &indices) const
Creates complete binding string from the array variable name and indexes.
int rank(numeric::array arr)
hippodraw::RootNTuple class interface.
virtual bool isUseable(const std::string &label) const
Returns true if the column is usable in the context of a DataSource.
virtual unsigned int * uintArrayAt(unsigned int row, unsigned int column) const
Returns pointer to a unsigned int array type in given row and column.
virtual int indexOf(const std::string &label) const
Returns true if the specified column labeled label has been filled.
virtual double * doubleArrayAt(unsigned int row, unsigned int column) const
Returns pointer to a double array type in given row.
virtual void willDelete(const Observable *)
Notifies this Observer object that one of its Observable objects is about to be deleted.
A class to read data from a ROOT TBranch.
intp size(numeric::array arr)
string convert(int i)
Converts an integer to a string.
column
The column indices for 2 dimension data point tuple.
virtual bool empty() const
Returns true, if RootNTuple is empty, i.e.
std::vector< bool > m_multiDimensional
Answers if rows of column are composed of the multidimensional data.
virtual const std::vector< double > & getColumn(const std::string &name) const
Returns the data in the column with label name.
void fillDataCache(unsigned int column)
Fills the data cache for column column.
CacheList_t m_data_cache
A cache of data already read.
The namespace for conversion to string.
void replaceColumn(unsigned int index, const std::vector< double > &data)
Replaces the data in column index.
virtual double operator[](std::vector< unsigned int > &indices) const
Raises an assertion, as a RootNTuple does not really have shape.
virtual bool isMultiDimensional(const std::string &column) const
Answers if rows of column are composed of the multidimensional data.
RootNTuple()
The default constructor.
virtual void addLabel(const std::string &label)
Adds a new label for a column.
TTree * m_tree
The ROOT TTree object which is the source of the data.
hippodraw::RootBranch class interface.
hippodraw::RootData::Type getType(unsigned int column) const
Returns the type of data in column.