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.
int addColumn (const std::string &label, boost::python::numeric::array array)
 Add a column to a NumArrayTuple.
void addRow (const std::vector< double > &array)
 Adds a row to the DataSource.
void append (const DataSource *source)
 Adds all the rows of source to the DataArray.
void append (const PyDataSource *source)
 Adds all the rows of source to the DataArray.
void clear ()
 Clear the data elements of the 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.
boost::python::numeric::array columnAsNumArray (unsigned int index) const
 Return a column from the DataSource as a numarray object, indexing by column number.
unsigned int columns () const
const DataSourcedataSource () const
 Return a reference to the underlying DataSource.
const std::vector< double > & getColumn (const std::string &name) const
 Get a column as a tuple of floats by column name.
const std::vector< double > & getColumn (unsigned int index) const
 Get a column as a tuple of floats by column index.
const std::vector< std::string > & getLabels () const
 Get the column names.
const std::string & getTitle () const
 The title of the DataSource.
bool hasColumn (const std::string &name) const
 Return true if column with label name exists in DataSource.
 PyDataSource ()
 Default constructor wraps an ordinary NTuple.
 PyDataSource (const std::string &dataSource)
 Constructor taking the kind of DataSource as an argument.
 PyDataSource (const std::string &name, DataSource *source)
 Constructor taking an existing DataSource and its name as an argument.
std::string registerNTuple ()
 Register this DataSource, returning a unique name.
void registerNTuple (const std::string &name)
 Register this DataSource by a chosen name.
void replaceColumn (const std::string &, const std::vector< double > &col)
 Replace a column by its label.
void replaceColumn (unsigned int index, const std::vector< double > &col)
 Replace a column by its index.
void replaceColumn (const std::string &, boost::python::numeric::array array)
 Replace a column by its label.
void replaceColumn (unsigned int index, boost::python::numeric::array array)
 Replace a column by its index.
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.
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.
void saveColumnFromNumArray (unsigned int index, boost::python::numeric::array array)
 Replace or add a column from a numarray object, indexing by column label.
void setName (const std::string &name)
 Set the name of the DataSource.
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.
static void extractVector (boost::python::numeric::array array, std::vector< double > &col)
 Extracts a vector from the numarray object.
static PyDataSourcegetCurrentDataSource ()
 Returns a new PyDataSource that wraps the current DataSource in the DataSourceController.

Private Member Functions

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

Private Attributes

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

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 404 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 420 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 410 of file PyDataSource.cxx.

~PyDataSource ( )
virtual

Definition at line 440 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 691 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 963 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 978 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 986 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 785 of file PyDataSource.cxx.

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

Referenced by PyDataSource::saveColumnFromNumArray().

void clear ( )

Clear the data elements of the DataSource.

Definition at line 706 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 728 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 760 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 448 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 458 of file PyDataSource.cxx.

References 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 596 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 601 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 527 of file PyDataSource.cxx.

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

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

Get the column names.

Definition at line 591 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 579 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 710 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 721 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 626 of file PyDataSource.cxx.

References hippodraw::Axes::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 641 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 659 of file PyDataSource.cxx.

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

unsigned int rows ( ) const

Definition at line 575 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 950 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 895 of file PyDataSource.cxx.

References PyDataSource::checkRank(), PyDataSource::columns(), hippodraw::Axes::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 587 of file PyDataSource.cxx.

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

void setTitle ( const std::string &  title)

Definition at line 583 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