Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

NTupleSorter Class Reference

#include <NTupleSorter.h>

Collaboration diagram for NTupleSorter:

Collaboration graph
[legend]
List of all members.

Detailed Description

A helper class to sort and keep sorted an NTuple.

A class to maintain a sorted NTuple. Sorting is done by the value of elements in the selected column.

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

Definition at line 30 of file NTupleSorter.h.

Public Member Functions

void addRow (const std::vector< double > &row)
 Adds a row to the NTuple.
void clear ()
 Clears the NTuple.
unsigned int columns () const
 Returns the number of columns of the NTuple.
virtual void eraseRow (unsigned int index)
 Erases a row from the NTuple.
NTuplegetNTuple () const
 Returns the NTuple being managed by the sorter.
const std::vector< double > & getRow (unsigned int index) const
 Returns a reference to the index row of the sorted NTuple.
 NTupleSorter (NTuple *ntuple)
 A constructor taking the NTuple to be sorted as the parameter.
 NTupleSorter (const NTupleSorter &)
 The copy constructor.
bool operator() (std::vector< double > *x, std::vector< double > *y) const
 A predicate function to be used for comparing two rows.
unsigned int rows () const
 Returns the number of rows of the NTuple.
void setSorting (int column)
 Sets the sorting column.
void sort ()
 Sorts the NTuple.
virtual ~NTupleSorter ()
 The virtual destructor.

Private Member Functions

NTupleSorteroperator= (const NTupleSorter &)
 Private assignment operator to prevent copying.
void rowwiseCopy (std::vector< std::vector< double > * > &row_copy)
 Makes a row-wise copy of the NTuple object.

Private Attributes

int m_column
 The column used for sorting, or -1 if sorting is disabled.
bool m_increasing
 The direction of the sort.
NTuplem_ntuple
 The NTuple object that will be used.


Constructor & Destructor Documentation

NTupleSorter::NTupleSorter const NTupleSorter  ) 
 

The copy constructor.

Initializes the newly constructed object with save value of the data members except for m_ntuple which is set to null pointer. It is intended that the copy only be used as predicate to the STL sort function.

Definition at line 35 of file NTupleSorter.cxx.

NTupleSorter::NTupleSorter NTuple ntuple  ) 
 

A constructor taking the NTuple to be sorted as the parameter.

Constructs the object and initialize it to sort column 0 in increasing order. Does not sort the NTuple object.

Definition at line 27 of file NTupleSorter.cxx.

virtual NTupleSorter::~NTupleSorter  )  [inline, virtual]
 

The virtual destructor.

The virtual distructor which is needed only to avoid warning from some compilers such as Gcc 4.0.0.

Definition at line 75 of file NTupleSorter.h.


Member Function Documentation

void NTupleSorter::addRow const std::vector< double > &  row  ) 
 

Adds a row to the NTuple.

Adds a row to the NTuple object. Maintains the sorted order with the current sorting column and its direction.

Note:
The implementation of this function has some fine examples of the use of STL template functions from algorithm, functional, and iterator. However, workarounds may be needed for compilers weak in the handling of templates.

Definition at line 115 of file NTupleSorter.cxx.

References NTuple::getColumn(), NTuple::insertRow(), std::lower_bound(), m_column, m_increasing, and m_ntuple.

Referenced by sort().

void NTupleSorter::clear  ) 
 

Clears the NTuple.

Definition at line 108 of file NTupleSorter.cxx.

References NTuple::clear(), and m_ntuple.

Referenced by PickTable::clear(), and sort().

unsigned int NTupleSorter::columns  )  const
 

Returns the number of columns of the NTuple.

Definition at line 143 of file NTupleSorter.cxx.

References DataSource::columns(), and m_ntuple.

void NTupleSorter::eraseRow unsigned int  index  )  [virtual]
 

Erases a row from the NTuple.

Removes the row index from the NTuple.

See also:
NTuple::eraseRow.

Definition at line 136 of file NTupleSorter.cxx.

References m_ntuple.

Referenced by PickTable::deleteSelectedItem().

NTuple * NTupleSorter::getNTuple  )  const
 

Returns the NTuple being managed by the sorter.

Definition at line 44 of file NTupleSorter.cxx.

References m_ntuple.

const vector< double > & NTupleSorter::getRow unsigned int  index  )  const
 

Returns a reference to the index row of the sorted NTuple.

Definition at line 157 of file NTupleSorter.cxx.

References NTuple::getRow(), and m_ntuple.

Referenced by PickTable::refreshItems(), and rowwiseCopy().

bool NTupleSorter::operator() std::vector< double > *  x,
std::vector< double > *  y
const
 

A predicate function to be used for comparing two rows.

Returns true if the element of the column used for sorting of row x is less than the element of row y.

Definition at line 77 of file NTupleSorter.cxx.

References m_column, and m_increasing.

NTupleSorter& NTupleSorter::operator= const NTupleSorter  )  [private]
 

Private assignment operator to prevent copying.

unsigned int NTupleSorter::rows  )  const
 

Returns the number of rows of the NTuple.

Definition at line 150 of file NTupleSorter.cxx.

References m_ntuple, and NTuple::rows().

Referenced by PickTable::refreshItems(), and rowwiseCopy().

void NTupleSorter::rowwiseCopy std::vector< std::vector< double > * > &  row_copy  )  [private]
 

Makes a row-wise copy of the NTuple object.

Clears the vector row_copy and fills it with a pointers to vectors containing the elements of each row.

Definition at line 63 of file NTupleSorter.cxx.

References getRow(), m_ntuple, and rows().

Referenced by sort().

void NTupleSorter::setSorting int  column  ) 
 

Sets the sorting column.

Sets the sorting column and resets the direction. If column is different from the current one, sets the sorting direction to be increasing. If column is the same as previously used, toggles the sorting direction to be the opposite of the current state.

Definition at line 51 of file NTupleSorter.cxx.

References m_column, and m_increasing.

void NTupleSorter::sort  ) 
 

Sorts the NTuple.

Definition at line 88 of file NTupleSorter.cxx.

References addRow(), clear(), m_ntuple, NTuple::notifyObservers(), rowwiseCopy(), and std::sort().


Member Data Documentation

int NTupleSorter::m_column [private]
 

The column used for sorting, or -1 if sorting is disabled.

Definition at line 41 of file NTupleSorter.h.

Referenced by addRow(), operator()(), and setSorting().

bool NTupleSorter::m_increasing [private]
 

The direction of the sort.

Definition at line 45 of file NTupleSorter.h.

Referenced by addRow(), operator()(), and setSorting().

NTuple* NTupleSorter::m_ntuple [private]
 

The NTuple object that will be used.

Definition at line 49 of file NTupleSorter.h.

Referenced by addRow(), clear(), columns(), eraseRow(), getNTuple(), getRow(), rows(), rowwiseCopy(), and sort().


The documentation for this class was generated from the following files:
Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3