// LayerStatChain.cpp #include "LayerStatChain.h" #include "trfutil/trfstream.h" #include "ClusterContainerStandard.h" using std::map; using trf::ClusterList; using trf::MissPtr; using trf::ClusterContainer; using trf::ClusterContainerStandard; using trf::LayerStat; using trf::LayerStatChain; //********************************************************************** // Local data. //********************************************************************** ClusterContainerStandard _empty_box; //********************************************************************** // Class methods. //********************************************************************** // Output stream. void LayerStatChain::ostr(ostream& stream) const { stream << begin_object; int size = _stats.size(); stream << "Layer status chain has " << size << " entr"; if ( size == 0 ) { stream << "ies."; stream << end_object; return; } if ( size == 1 ) stream << "y:"; if ( size > 1 ) stream << "ies:"; for ( StatList::const_iterator istat=_stats.begin(); istat!=_stats.end(); ++istat ) { stream << new_line; stream << *istat; if ( istat == _istat_current ) stream << " (current layer)"; if ( istat == _istat_cluster ) stream << " (cluster layer)"; } stream << end_object; } //********************************************************************** // Default constructor. LayerStatChain::LayerStatChain() : _stats(), _istat_current(_stats.begin()), _istat_cluster(_stats.end()) { } //********************************************************************** // Constructor from the first layer status. LayerStatChain::LayerStatChain(const LayerStat& lstat) : _stats(1,lstat), _istat_current(_stats.begin()), _istat_cluster(_stats.end()) { } //********************************************************************** // Copy constructor LayerStatChain::LayerStatChain(const LayerStatChain& rhs) { // To ensure consistency, we use assignment. *this = rhs; } //********************************************************************** // Assignment operator LayerStatChain& LayerStatChain::operator=(const LayerStatChain& rhs) { // usual check for identity if ( this == &rhs ) return *this; // copy the list _stats = rhs._stats; // copy the iterators _istat_current = _stats.end(); _istat_cluster = _stats.end(); StatList::const_iterator istat_rhs = rhs._stats.begin(); StatList::iterator istat_lhs = _stats.begin(); while ( istat_rhs != rhs._stats.end() ) { if ( istat_rhs == rhs._istat_current ) _istat_current = istat_lhs; if ( istat_rhs == rhs._istat_cluster ) _istat_cluster = istat_lhs; ++istat_rhs; ++istat_lhs; } return *this; } //********************************************************************** // Destructor LayerStatChain::~LayerStatChain() { } //********************************************************************** // Return if the current status is set. bool LayerStatChain::current_status_is_valid() const { return _istat_current != _stats.end(); } //********************************************************************** // Return if the cluster status is set. bool LayerStatChain::cluster_status_is_valid() const { return _istat_cluster != _stats.end(); } //********************************************************************** // Is the cluster status at the first element of the list? bool LayerStatChain::cluster_status_at_first() const { return _istat_cluster == _stats.begin(); } //********************************************************************** // Is the cluster status at the last element of the list? bool LayerStatChain::cluster_status_at_last() const { if ( ! current_status_is_valid() ) return false; StatList::const_iterator istat = _stats.end(); --istat; return _istat_cluster == istat; } //********************************************************************** // Return the current status. LayerStat& LayerStatChain::get_current_status() const { assert( current_status_is_valid() ); return *_istat_current; } //********************************************************************** // Return the cluster status. LayerStat& LayerStatChain::get_cluster_status() const { assert( cluster_status_is_valid() ); return *_istat_cluster; } //********************************************************************** // Are there clusters associated with this chain? bool LayerStatChain::has_clusters() const { if ( ! cluster_status_is_valid() ) return false; return _istat_cluster->has_clusters(); } //********************************************************************** // Fetch the clusters associated with this chain. ClusterList LayerStatChain::get_clusters() const { if ( ! cluster_status_is_valid() ) return ClusterList(); return _istat_cluster->get_clusters(); } //********************************************************************** // Fetch the clusters near a track and generate CutRecords. const ClusterContainer& LayerStatChain:: get_clusters(const ETrack& tre, const CutRecord* pcut_record, map* precs) const { if ( ! cluster_status_is_valid() ) return _empty_box; return _istat_cluster->get_clusters(tre, pcut_record, precs); } //********************************************************************** // Is there a miss associated with this chain? bool LayerStatChain::has_miss() const { return get_miss() != 0; } //********************************************************************** // Return the miss. MissPtr LayerStatChain::get_miss() const { if ( ! cluster_status_is_valid() ) return MissPtr(0); else return _istat_cluster->get_miss(); } //********************************************************************** // Return begin iterator. LayerStatChain::Iterator LayerStatChain::begin() const { return _stats.begin(); } //********************************************************************** // Return end iterator. LayerStatChain::Iterator LayerStatChain::end() const { return _stats.end(); } //********************************************************************** // Output stream. ostream& trf::operator<<(ostream& stream, const LayerStatChain& rhs) { rhs.ostr(stream); return stream; } //**********************************************************************