Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
PyDataSource Class Reference

This class is the public interface to a DataSource object that the user sees as the DataArray object from Python. More...

#include <PyDataSource.h>

Collaboration diagram for PyDataSource:
Collaboration graph
[legend]

Classes

class  StopIteration
 

Public Member Functions

int addColumn (const std::string &label, const std::vector< double > &col)
 Add a column to an NTuple or ListTuple. More...
 
int addColumn (const std::string &label, boost::python::numeric::array array)
 Add a column to a NumArrayTuple. More...
 
void addRow (const std::vector< double > &array)
 Adds a row to the DataSource. More...
 
void append (const DataSource *source)
 Adds all the rows of source to the DataArray. More...
 
void append (const PyDataSource *source)
 Adds all the rows of source to the DataArray. More...
 
void clear ()
 Clear the data elements of the DataSource. More...
 
boost::python::numeric::array columnAsNumArray (const std::string &label) const
 Return a column from the DataSource as a numarray object, indexing by column label. More...
 
boost::python::numeric::array columnAsNumArray (unsigned int index) const
 Return a column from the DataSource as a numarray object, indexing by column number. More...
 
unsigned int columns () const
 
const DataSourcedataSource () const
 Return a reference to the underlying DataSource. More...
 
const std::vector< double > & getColumn (const std::string &name) const
 Get a column as a tuple of floats by column name. More...
 
const std::vector< double > & getColumn (unsigned int index) const
 Get a column as a tuple of floats by column index. More...
 
const std::vector< std::string > & getLabels () const
 Get the column names. More...
 
const std::string & getTitle () const
 The title of the DataSource. More...
 
bool hasColumn (const std::string &name) const
 Return true if column with label name exists in DataSource. More...
 
 PyDataSource ()
 Default constructor wraps an ordinary NTuple. More...
 
 PyDataSource (const std::string &dataSource)
 Constructor taking the kind of DataSource as an argument. More...
 
 PyDataSource (const std::string &name, DataSource *source)
 Constructor taking an existing DataSource and its name as an argument. More...
 
std::string registerNTuple ()
 Register this DataSource, returning a unique name. More...
 
void registerNTuple (const std::string &name)
 Register this DataSource by a chosen name. More...
 
void replaceColumn (const std::string &, const std::vector< double > &col)
 Replace a column by its label. More...
 
void replaceColumn (unsigned int index, const std::vector< double > &col)
 Replace a column by its index. More...
 
void replaceColumn (const std::string &, boost::python::numeric::array array)
 Replace a column by its label. More...
 
void replaceColumn (unsigned int index, boost::python::numeric::array array)
 Replace a column by its index. More...
 
unsigned int rows () const
 
void saveColumn (const std::string &label, const std::vector< double > &v, const std::vector< intptr_t > &shape)
 Replaces or add column vector. More...
 
void saveColumnFrom (const std::string &label, const std::vector< double > &array)
 Replace or add a column from vector. More...
 
void saveColumnFromNumArray (const std::string &label, boost::python::numeric::array array)
 Replace or add a column from a numarray object, indexing by column label. More...
 
void saveColumnFromNumArray (unsigned int index, boost::python::numeric::array array)
 Replace or add a column from a numarray object, indexing by column label. More...
 
void setName (const std::string &name)
 Set the name of the DataSource. More...
 
void setTitle (const std::string &title)
 
virtual ~PyDataSource ()
 

Static Public Member Functions

template<typename T >
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. More...
 
static void extractVector (boost::python::numeric::array array, std::vector< double > &col)
 Extracts a vector from the numarray object. More...
 
static PyDataSourcegetCurrentDataSource ()
 Returns a new PyDataSource that wraps the current DataSource in the DataSourceController. More...
 

Private Member Functions

void checkRank (boost::python::numeric::array array)
 Checks the rank of the array. More...
 

Private Attributes

DataSourcem_dataSource
 The actual DataSource object. More...
 
std::string m_type
 The type of data source. More...
 

Detailed Description

This class is the public interface to a DataSource object that the user sees as the DataArray object from Python.

Author
J. Chiang jchia.nosp@m.ng@s.nosp@m.lac.s.nosp@m.tanf.nosp@m.ord.e.nosp@m.du

Definition at line 43 of file PyDataSource.h.

Constructor & Destructor Documentation

Default constructor wraps an ordinary NTuple.

Definition at line 397 of file PyDataSource.cxx.

Referenced by PyDataSource::getCurrentDataSource().

PyDataSource ( const std::string &  dataSource)

Constructor taking the kind of DataSource as an argument.

Requests:
@@ Have a constructor that takes DataSource and figures out what type it is.

Definition at line 413 of file PyDataSource.cxx.

References PyDataSource::m_dataSource.

PyDataSource ( const std::string &  name,
DataSource source 
)

Constructor taking an existing DataSource and its name as an argument.

Definition at line 403 of file PyDataSource.cxx.

~PyDataSource ( )
virtual

Definition at line 433 of file PyDataSource.cxx.

References PyDataSource::m_dataSource.

Member Function Documentation

int addColumn ( const std::string &  label,
const std::vector< double > &  col 
)
int addColumn ( const std::string &  label,
boost::python::numeric::array  array 
)

Add a column to a NumArrayTuple.

Requests:
@@ This method only works if contained DataSource is NumArrayTuple. It could accept more like saveColumnFromNumArray does.

Definition at line 694 of file PyDataSource.cxx.

References NumArrayTuple::addColumn(), PyDataSource::m_dataSource, and PyDataSource::m_type.

void addRow ( const std::vector< double > &  array)

Adds a row to the DataSource.

Definition at line 966 of file PyDataSource.cxx.

References PyApp::lock(), PyDataSource::m_dataSource, and PyApp::unlock().

void append ( const DataSource source)

Adds all the rows of source to the DataArray.

Definition at line 981 of file PyDataSource.cxx.

References PyApp::lock(), PyDataSource::m_dataSource, and PyApp::unlock().

Referenced by PyDataSource::append().

void append ( const PyDataSource source)

Adds all the rows of source to the DataArray.

Definition at line 989 of file PyDataSource.cxx.

References PyDataSource::append(), PyDataSource::dataSource(), and PyDataSource::m_dataSource.

void checkRank ( boost::python::numeric::array  array)
private

Checks the rank of the array.

Check of the array and if the rank is greater than 1, throws a std::runtime_error.

Definition at line 788 of file PyDataSource.cxx.

References hippodraw::String::convert(), PyDataSource::m_type, and num_util::rank().

Referenced by PyDataSource::saveColumnFromNumArray().

void clear ( )

Clear the data elements of the DataSource.

Definition at line 709 of file PyDataSource.cxx.

References DataSource::clear(), and PyDataSource::m_dataSource.

boost::python::numeric::array columnAsNumArray ( const std::string &  label) const

Return a column from the DataSource as a numarray object, indexing by column label.

Definition at line 731 of file PyDataSource.cxx.

References DataSource::getColumn(), NumArrayTuple::getNumArray(), PyDataSource::m_dataSource, PyDataSource::m_type, num_util::makeNum(), and num_util::shape().

boost::python::numeric::array columnAsNumArray ( unsigned int  index) const

Return a column from the DataSource as a numarray object, indexing by column number.

Definition at line 763 of file PyDataSource.cxx.

References PyDataSource::columns(), DataSource::getColumn(), NumArrayTuple::getNumArray(), PyDataSource::m_dataSource, PyDataSource::m_type, num_util::makeNum(), and num_util::shape().

unsigned int columns ( ) const
void copy_direct ( boost::python::numeric::array  array,
std::vector< double > &  col 
)
static

Copies and converts to double, if needed, data of type T from array to fill the std::vector col.

Definition at line 441 of file PyDataSource.cxx.

References num_util::data(), num_util::size(), and hippodraw::Axes::T.

const DataSource& dataSource ( ) const
inline

Return a reference to the underlying DataSource.

Definition at line 89 of file PyDataSource.h.

References PyDataSource::m_dataSource.

Referenced by PyDataSource::append(), PyDataRep::PyDataRep(), QtCut::QtCut(), and QtDisplay::QtDisplay().

void extractVector ( boost::python::numeric::array  array,
std::vector< double > &  col 
)
static

Extracts a vector from the numarray object.

Extracts a vector from the numarray object array and fills the vector col. If array is contiguous, copies the data directly, otherwise copies the data element by element.

Definition at line 456 of file PyDataSource.cxx.

References i, num_util::iscontiguous(), num_util::rank(), num_util::size(), num_util::type(), and num_util::type2string().

Referenced by PyDataSource::saveColumnFromNumArray().

const std::vector< double > & getColumn ( const std::string &  name) const

Get a column as a tuple of floats by column name.

Definition at line 599 of file PyDataSource.cxx.

References DataSource::getColumn(), and PyDataSource::m_dataSource.

const std::vector< double > & getColumn ( unsigned int  index) const

Get a column as a tuple of floats by column index.

Definition at line 604 of file PyDataSource.cxx.

References DataSource::getColumn(), and PyDataSource::m_dataSource.

PyDataSource * getCurrentDataSource ( )
static

Returns a new PyDataSource that wraps the current DataSource in the DataSourceController.

Definition at line 530 of file PyDataSource.cxx.

References DataSourceController::instance(), and PyDataSource::PyDataSource().

const std::vector< std::string > & getLabels ( ) const

Get the column names.

Definition at line 594 of file PyDataSource.cxx.

References DataSource::getLabels(), and PyDataSource::m_dataSource.

Referenced by PyDataSource::hasColumn().

const std::string & getTitle ( ) const

The title of the DataSource.

Definition at line 582 of file PyDataSource.cxx.

References PyDataSource::m_dataSource, and DataSource::title().

bool hasColumn ( const std::string &  name) const

Return true if column with label name exists in DataSource.

Definition at line 713 of file PyDataSource.cxx.

References PyDataSource::getLabels().

Referenced by PyDataSource::saveColumn(), PyDataSource::saveColumnFrom(), and PyDataSource::saveColumnFromNumArray().

std::string registerNTuple ( )

Register this DataSource, returning a unique name.

Definition at line 724 of file PyDataSource.cxx.

References DataSourceController::instance(), PyDataSource::m_dataSource, and DataSourceController::registerNTuple().

void registerNTuple ( const std::string &  name)
void replaceColumn ( const std::string &  label,
const std::vector< double > &  col 
)
void replaceColumn ( unsigned int  index,
const std::vector< double > &  col 
)

Replace a column by its index.

Definition at line 629 of file PyDataSource.cxx.

References hippodraw::String::convert(), DataSource::getLabels(), PyDataSource::m_dataSource, and PyDataSource::replaceColumn().

void replaceColumn ( const std::string &  label,
boost::python::numeric::array  array 
)

Replace a column by its label.

Definition at line 644 of file PyDataSource.cxx.

References PyDataSource::m_dataSource, PyDataSource::m_type, and NumArrayTuple::replaceColumn().

void replaceColumn ( unsigned int  index,
boost::python::numeric::array  array 
)

Replace a column by its index.

Definition at line 662 of file PyDataSource.cxx.

References PyDataSource::m_dataSource, PyDataSource::m_type, and NumArrayTuple::replaceColumn().

unsigned int rows ( ) const

Definition at line 578 of file PyDataSource.cxx.

References PyDataSource::m_dataSource, and DataSource::rows().

void saveColumn ( const std::string &  label,
const std::vector< double > &  v,
const std::vector< intptr_t > &  shape 
)
void saveColumnFrom ( const std::string &  label,
const std::vector< double > &  array 
)

Replace or add a column from vector.

Definition at line 953 of file PyDataSource.cxx.

References PyDataSource::addColumn(), PyDataSource::hasColumn(), PyDataSource::m_dataSource, and PyDataSource::replaceColumn().

void saveColumnFromNumArray ( const std::string &  label,
boost::python::numeric::array  array 
)
void saveColumnFromNumArray ( unsigned int  index,
boost::python::numeric::array  array 
)

Replace or add a column from a numarray object, indexing by column label.

Bug:
@@@ Should allow any type of DataSource if rank is acceptable.

Definition at line 898 of file PyDataSource.cxx.

References PyDataSource::checkRank(), PyDataSource::columns(), hippodraw::String::convert(), PyDataSource::extractVector(), PyDataSource::m_dataSource, PyDataSource::m_type, ListTuple::replaceColumn(), PyDataSource::replaceColumn(), NTuple::replaceColumn(), and num_util::shape().

void setName ( const std::string &  name)

Set the name of the DataSource.

Definition at line 590 of file PyDataSource.cxx.

References PyDataSource::m_dataSource, and DataSource::setName().

void setTitle ( const std::string &  title)

Definition at line 586 of file PyDataSource.cxx.

References PyDataSource::m_dataSource, and DataSource::setTitle().

Member Data Documentation

DataSource* m_dataSource
private
std::string m_type
private

The documentation for this class was generated from the following files:

Generated for HippoDraw Class Library by doxygen