DataSourceController Class Reference

#include <DataSourceController.h>

Inheritance diagram for DataSourceController:

Inheritance graph
Observer
[legend]
Collaboration diagram for DataSourceController:

Collaboration graph
Observer
[legend]

List of all members.


Detailed Description

A singleton class that is the interface between GUI and the DataSource objects.

It implements the application logic which should neither be in the GUI nor in the DataSource objects.

Author:
Paul F. Kunz <Paul_Kunz@slac.stanford.edu>

Definition at line 40 of file DataSourceController.h.


Public Member Functions

void changeName (const std::string &old_name, const std::string &new_name)
 Changes the name of the DataSource.
DataSourcefindDataSource (const std::string &name) const throw ( std::runtime_error )
 Returns the DataSource object registered as name.
DataSourcegetCurrent () const
 Returns a pointer to the current DataSource.
DataSourcegetDataSource (const std::string &name) const
 Returns the DataSource object registered as name.
void getDataSources (std::vector< DataSource * > &, bool all=true) const
 Clears and fills the vector with the registered DataSource objects.
const std::vector
< std::string > & 
getNTupleNames () const
 Returns a vector of the current DataSource names.
int indexOfDataSource (const std::string &name) const
 Returns index of DataSource, or -1 if not found.
bool isFromFile (const DataSource *source) const
 Returns true if the DataSource object was created from a file or was saved to a file, otherwise returns false.
void registerDataSourceFile (DataSource *ds)
 Registers that the DataSource came from a file.
void registerNTuple (const std::string &, DataSource *source)
 Register a DataSoruce.
std::string registerNTuple (DataSource *nt)
 Register a DataSource.
void setCurrentIndex (int index)
 Sets the index to the current DataSource.
void unregisterNTuple (const DataSource *nt)
 Un-registers the DataSource.
virtual void update (const Observable *)
 Responds to the Observable having a change.
void willDelete (const Observable *observee)
 Responds to Observable being deleted.

Static Public Member Functions

static
DataSourceController
instance ()
 Returns the pointer to the singleton instance.

Private Types

typedef std::vector
< DataSource * > 
DataSourceList_t
 The type of STL container used to keep list of DataSource objects.

Private Member Functions

 DataSourceController (const DataSourceController &)
 A private copy constructor in order to avoid copying.
 DataSourceController ()
 A default constructor for avoiding creation except by itself.

Private Attributes

std::string m_base_name
 Base of name given to NTuple which is built in memory.
int m_current_index
 The current DataSource index.
DataSourceList_t m_ds_files
 The list of files that were read.
std::vector
< std::string > 
m_names
 A temporary list of DataSource names.
DataSourceList_t m_sources
 The list of registered DataSource objects.
int m_suffix
 Suffix added to base name given to NTuple which is built in memory.

Static Private Attributes

static
DataSourceController
s_instance = 0
 The pointer to the singleton object.

Member Typedef Documentation

typedef std::vector< DataSource * > DataSourceList_t [private]

The type of STL container used to keep list of DataSource objects.

Definition at line 57 of file DataSourceController.h.


Constructor & Destructor Documentation

DataSourceController (  )  [private]

A default constructor for avoiding creation except by itself.

Definition at line 37 of file DataSourceController.cxx.

Referenced by DataSourceController::instance().

DataSourceController ( const DataSourceController  )  [private]

A private copy constructor in order to avoid copying.

The copy constructor.

Only needed for SIP interface and should never be called.

Definition at line 47 of file DataSourceController.cxx.


Member Function Documentation

void changeName ( const std::string &  old_name,
const std::string &  new_name 
)

Changes the name of the DataSource.

Changes the name of the registered DataSource object designated by old_name, to the name new_name.

Definition at line 122 of file DataSourceController.cxx.

References DataSourceController::getDataSource().

DataSource * findDataSource ( const std::string &  name  )  const throw ( std::runtime_error )

Returns the DataSource object registered as name.

If a object of the given name is found, returns a pointer to it, otherwise throws a std::runtime_error.

Warning:
If more than one data source has the same name, the first one is returned.

Definition at line 70 of file DataSourceController.cxx.

References DataSourceController::getDataSource().

DataSource * getCurrent (  )  const

Returns a pointer to the current DataSource.

Definition at line 238 of file DataSourceController.cxx.

References DataSourceController::m_current_index, and DataSourceController::m_sources.

DataSource * getDataSource ( const std::string &  name  )  const

Returns the DataSource object registered as name.

If the object is found, return a pointer to it. If the object is not found, return a null pointer.

Warning:
If more than one data source has the same name, then the first one found is returned.

Definition at line 108 of file DataSourceController.cxx.

References DataSourceController::indexOfDataSource(), and DataSourceController::m_sources.

Referenced by DataSourceController::changeName(), and DataSourceController::findDataSource().

void getDataSources ( std::vector< DataSource * > &  sources,
bool  all = true 
) const

Clears and fills the vector with the registered DataSource objects.

If all is true, the default, returns vector of all DataSource objects registered with the controller. If all is false, then only returns the DataSource objects that were not created from a file.

Definition at line 143 of file DataSourceController.cxx.

References DataSourceController::isFromFile(), DataSourceController::m_sources, and num_util::size().

Referenced by XmlController::fillNTupleMap(), and NTupleController::saveNTuples().

const vector< string > & getNTupleNames (  )  const

Returns a vector of the current DataSource names.

Attention:
The order of the names should agree with the order from getDataSources. This is so that the application can fill a GUI with names, and access the DataSource by index.

Definition at line 162 of file DataSourceController.cxx.

References DataSourceController::m_names, and DataSourceController::m_sources.

Referenced by CanvasView::createNTuple(), and CanvasView::exportTextTuple().

int indexOfDataSource ( const std::string &  name  )  const

Returns index of DataSource, or -1 if not found.

Warning:
If more than one DataSource has the same name, then the index of the first one found is returned.

Definition at line 88 of file DataSourceController.cxx.

References DataSourceController::m_sources, and num_util::size().

Referenced by DataSourceController::getDataSource().

DataSourceController * instance (  )  [static]

Returns the pointer to the singleton instance.

Definition at line 53 of file DataSourceController.cxx.

References DataSourceController::DataSourceController(), and DataSourceController::s_instance.

Referenced by Inspector::addDataRepButton_clicked(), Inspector::allNtupleComboActivated(), DisplayController::areDataSourcesSaved(), Inspector::availPlotTypesActivated(), Inspector::changeNTupleName(), CreateNTuple::createButtonClicked(), NTupleController::createCircularBuffer(), DisplayController::createDifferenceDisplay(), CreateNTuple::createFileButtonClicked(), PyNTupleController::createNTuple(), NTupleController::createNTuple(), FitsController::createNTuple(), DisplayController::createNTuple(), CanvasView::createNTuple(), FunctionController::createResidualsDisplay(), CreateNTuple::currentDataSourceChanged(), Inspector::dataCreateNTuple(), Inspector::dataNTupleSelChanged(), FunctionController::ellipsoidNTuple(), CanvasView::exportTextTuple(), NTupleController::fillFromFile(), XmlController::fillNTupleMap(), PyNTupleController::findDataSource(), NTupleController::findDataSource(), PyDataSource::getCurrentDataSource(), CreateNTuple::getDataCutList(), Inspector::getSelectedDataSourceName(), RootController::initNTuple(), Inspector::newPlotButton_clicked(), Inspector::ntupleChanged(), PickTable::PickTable(), QtDisplay::QtDisplay(), PyNTupleController::registerNTuple(), PyDataSource::registerNTuple(), NTupleController::registerNTuple(), NTupleController::saveNTuples(), Inspector::setNewPlotNTuple(), CreateNTuple::updateColumnList(), Inspector::updateNewPlotControls(), CreateNTuple::updateNTupleIn(), Inspector::updateSelectedPlotDataSource(), NTupleController::writeNTupleToFile(), and FitsController::writeNTupleToFile().

bool isFromFile ( const DataSource source  )  const

Returns true if the DataSource object was created from a file or was saved to a file, otherwise returns false.

Definition at line 133 of file DataSourceController.cxx.

References DataSourceController::m_ds_files.

Referenced by DataSourceController::getDataSources().

void registerDataSourceFile ( DataSource ds  ) 

Registers that the DataSource came from a file.

Definition at line 63 of file DataSourceController.cxx.

References DataSourceController::m_ds_files.

void registerNTuple ( const std::string &  key,
DataSource source 
)

Register a DataSoruce.

Register a DataSource object source using the name key for later lookup. DataSource objects need to be registered in order to be visible application wide using this singleton controller.

Definition at line 196 of file DataSourceController.cxx.

References DataSourceController::m_current_index, and DataSourceController::m_sources.

string registerNTuple ( DataSource nt  ) 

Register a DataSource.

A unique name will be generated for the NTuple.

See also:
registerNTuple( const std::string &, NTuple * ).

Definition at line 178 of file DataSourceController.cxx.

References hippodraw::String::convert(), DataSource::getName(), DataSourceController::m_base_name, DataSourceController::m_suffix, and DataSource::setName().

Referenced by PickTable::PickTable(), and PyDataSource::registerNTuple().

void setCurrentIndex ( int  index  ) 

Sets the index to the current DataSource.

Definition at line 250 of file DataSourceController.cxx.

References DataSourceController::m_current_index.

void unregisterNTuple ( const DataSource nt  ) 

Un-registers the DataSource.

Un-registers the DataSource from the list of available DataSource objects. If the object is not found, does nothing.

Definition at line 206 of file DataSourceController.cxx.

References DataSourceController::m_current_index, DataSourceController::m_sources, and num_util::size().

Referenced by DataSourceController::willDelete().

void update ( const Observable  )  [virtual]

Responds to the Observable having a change.

This implementation does noting. The implementation is required because of the pure virtual function in the base class.

Implements Observer.

Definition at line 221 of file DataSourceController.cxx.

void willDelete ( const Observable observee  )  [virtual]

Responds to Observable being deleted.

If observer is an object derived from DataSource, then unregisters it.

Reimplemented from Observer.

Definition at line 227 of file DataSourceController.cxx.

References DataSourceController::unregisterNTuple().


Member Data Documentation

std::string m_base_name [private]

Base of name given to NTuple which is built in memory.

Definition at line 71 of file DataSourceController.h.

Referenced by DataSourceController::registerNTuple().

int m_current_index [private]

The current DataSource index.

Definition at line 79 of file DataSourceController.h.

Referenced by DataSourceController::getCurrent(), DataSourceController::registerNTuple(), DataSourceController::setCurrentIndex(), and DataSourceController::unregisterNTuple().

DataSourceList_t m_ds_files [private]

The list of files that were read.

Definition at line 65 of file DataSourceController.h.

Referenced by DataSourceController::isFromFile(), and DataSourceController::registerDataSourceFile().

std:: vector< std::string > m_names [mutable, private]

A temporary list of DataSource names.

Definition at line 68 of file DataSourceController.h.

Referenced by DataSourceController::getNTupleNames().

DataSourceList_t m_sources [private]

The list of registered DataSource objects.

Definition at line 61 of file DataSourceController.h.

Referenced by DataSourceController::getCurrent(), DataSourceController::getDataSource(), DataSourceController::getDataSources(), DataSourceController::getNTupleNames(), DataSourceController::indexOfDataSource(), DataSourceController::registerNTuple(), and DataSourceController::unregisterNTuple().

int m_suffix [private]

Suffix added to base name given to NTuple which is built in memory.

Definition at line 75 of file DataSourceController.h.

Referenced by DataSourceController::registerNTuple().

DataSourceController * s_instance = 0 [static, private]

The pointer to the singleton object.

Definition at line 46 of file DataSourceController.h.

Referenced by DataSourceController::instance().


The documentation for this class was generated from the following files:
Generated for HippoDraw Class Library by doxygen