PyDataSource.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
2 
14 #ifndef _PyDataSource_H
15 #define _PyDataSource_H
16 
17 #include <exception>
18 #include <string>
19 #include <vector>
20 
21 #ifndef _MSC_VER
22 #include <inttypes.h>
23 #endif
24 
25 namespace boost {
26  namespace python {
27  namespace numeric {
28  class array;
29  }
30  }
31 }
32 
33 namespace hippodraw {
34 
35  class DataSource;
36 
44 {
45 
46 private:
47 
51  void checkRank ( boost::python::numeric::array array );
52 
53 public:
54 
56  PyDataSource();
57 
59  PyDataSource(const std::string & dataSource);
60 
64  PyDataSource ( const std::string & name, DataSource * source );
65 
66  virtual ~PyDataSource();
67 
73  void static extractVector ( boost::python::numeric::array array,
74  std::vector<double> & col );
75 
79  template < typename T >
80  void static copy_direct ( boost::python::numeric::array array,
81  std::vector<double > & col );
82 
87 
89  const DataSource & dataSource() const { return *m_dataSource; }
90 
91  unsigned int columns() const;
92 
93  unsigned int rows() const;
94 
96  const std::string & getTitle () const;
97 
98  void setTitle(const std::string & title);
99 
102  void setName(const std::string & name);
103 
105  const std::vector<std::string> & getLabels() const;
106 
108  const std::vector<double> & getColumn(const std::string & name) const;
110  const std::vector<double> & getColumn(unsigned int index) const;
111 
113  void replaceColumn(const std::string &,
114  const std::vector<double> & col);
115 
117  void replaceColumn(unsigned int index,
118  const std::vector<double> & col);
119 
122  void replaceColumn ( const std::string &,
123  boost::python::numeric::array array );
124 
127  void replaceColumn ( unsigned int index,
128  boost::python::numeric::array array);
129 
131  int addColumn( const std::string & label,
132  const std::vector<double> & col );
133 
140  int addColumn( const std::string & label,
141  boost::python::numeric::array array );
142 
144  void clear();
145 
148  bool hasColumn(const std::string & name) const;
149 
152  std::string registerNTuple();
153 
156  void registerNTuple( const std::string & name );
157 
161  boost::python::numeric::array
162  columnAsNumArray( const std::string & label ) const;
163 
167  boost::python::numeric::array
168  columnAsNumArray( unsigned int index ) const;
169 
172  void saveColumn ( const std::string & label,
173  const std::vector < double > & v,
174  const std::vector < intptr_t > & shape );
175 
179  void saveColumnFromNumArray( const std::string & label,
180  boost::python::numeric::array array );
181 
185  void saveColumnFromNumArray( unsigned int index,
186  boost::python::numeric::array array );
187 
188 
191  void saveColumnFrom ( const std::string & label,
192  const std::vector < double > & array );
193 
196  void addRow ( const std::vector < double > & array );
197 
200  void append ( const DataSource * source );
201 
204  void append ( const PyDataSource * source );
205 
206  class StopIteration : public std::exception {
207  public:
208  StopIteration(const std::string & what) : m_what(what) {}
209  ~StopIteration() throw() {}
210  const char * what() const throw() {
211  return m_what.c_str();
212  }
213  private:
214  const std::string m_what;
215  };
216 
217 
218 private:
219 
221  std::string m_type;
222 
225 
226 };
227 
228 } // namespace hippodraw
229 
230 #endif // _PyDataSource_H
unsigned int columns() const
void replaceColumn(const std::string &, const std::vector< double > &col)
Replace a column by its label.
void setTitle(const std::string &title)
const std::vector< std::string > & getLabels() const
Get the column names.
std::string registerNTuple()
Register this DataSource, returning a unique name.
void clear()
Clear the data elements of the DataSource.
PyDataSource()
Default constructor wraps an ordinary NTuple.
void addRow(const std::vector< double > &array)
Adds a row to the DataSource.
static PyDataSource * getCurrentDataSource()
Returns a new PyDataSource that wraps the current DataSource in the DataSourceController.
unsigned int rows() const
std::vector< intptr_t > shape(numeric::array arr)
Definition: num_util.cpp:317
const std::string & getTitle() const
The title of the DataSource.
static void extractVector(boost::python::numeric::array array, std::vector< double > &col)
Extracts a vector from the numarray object.
boost::python::numeric::array columnAsNumArray(const std::string &label) const
Return a column from the DataSource as a numarray object, indexing by column label.
void append(const DataSource *source)
Adds all the rows of source to the DataArray.
DataSource * m_dataSource
The actual DataSource object.
Definition: PyDataSource.h:224
void saveColumnFrom(const std::string &label, const std::vector< double > &array)
Replace or add a column from vector.
void saveColumnFromNumArray(const std::string &label, boost::python::numeric::array array)
Replace or add a column from a numarray object, indexing by column label.
ViewBase * v
Definition: PlotTable.cxx:104
const std::vector< double > & getColumn(const std::string &name) const
Get a column as a tuple of floats by column name.
void checkRank(boost::python::numeric::array array)
Checks the rank of the array.
This class is the public interface to a DataSource object that the user sees as the DataArray object ...
Definition: PyDataSource.h:43
void setName(const std::string &name)
Set the name of the DataSource.
void saveColumn(const std::string &label, const std::vector< double > &v, const std::vector< intptr_t > &shape)
Replaces or add column vector.
const DataSource & dataSource() const
Return a reference to the underlying DataSource.
Definition: PyDataSource.h:89
StopIteration(const std::string &what)
Definition: PyDataSource.h:208
bool hasColumn(const std::string &name) const
Return true if column with label name exists in DataSource.
return index
Definition: PickTable.cxx:182
std::string m_type
The type of data source.
Definition: PyDataSource.h:221
static void copy_direct(boost::python::numeric::array array, std::vector< double > &col)
Copies and converts to double, if needed, data of type T from array to fill the std::vector col...
int addColumn(const std::string &label, const std::vector< double > &col)
Add a column to an NTuple or ListTuple.
Base class for DataSource.
Definition: DataSource.h:55

Generated for HippoDraw Class Library by doxygen