// LTrack.cpp #include "LTrack.h" #include "trfutil/trfstream.h" #include "trfbase/Miss.h" using trf::ETrack; using trf::LayerStatChain; using trf::PropStat; using trf::LayerStat; using trf::LTrack; //********************************************************************** // output stream void LTrack::ostr(ostream& stream) const { stream << begin_object; stream << "LTrack track:" << new_line; stream << _tre << new_line; stream << "LTrack chain: " << new_line; stream << _chain; stream << end_object; } //********************************************************************** // default constructor LTrack::LTrack() : _tre(), _chain() { } //********************************************************************** // constructor from track and layer // Track is copied. // Layer is used to start a new chain. LTrack::LTrack(const ETrack& tre, const LayerStat& lstat) : _tre(tre), _chain(lstat) { } //********************************************************************** // copy constructor // track and complete status chain are copied LTrack::LTrack(const LTrack& trl) : _tre(trl._tre), _chain(trl._chain), _pstat(trl._pstat) { } //********************************************************************** // assignment operator LTrack& LTrack::operator=(const LTrack& trl) { if ( this == &trl ) return *this; _tre = trl._tre; _chain = trl._chain; _pstat = trl._pstat; return *this; } //********************************************************************** // destructor LTrack::~LTrack() { } //********************************************************************** // return if the current status is defined bool LTrack::at_valid_status() const { return _chain.current_status_is_valid(); } //********************************************************************** // Return if the current status is the top-level status. // Returns true for an empty status list. bool LTrack::at_top_status() const { return _chain._istat_current == _chain._stats.begin(); } //********************************************************************** // return the current status const const LayerStat& LTrack::get_status() const { assert( at_valid_status() ); return _chain.get_current_status(); } //********************************************************************** // return the current status LayerStat& LTrack::get_status() { assert( at_valid_status() ); return _chain.get_current_status(); } //********************************************************************** // step down the status chain // return false and stop stepping at the last status bool LTrack::set_next_status() { if ( _chain._istat_current == _chain._stats.end() ) return false; ++_chain._istat_current; if ( _chain._istat_current == _chain._stats.end() ) { --_chain._istat_current; return false; } return true; } //********************************************************************** // step up the status chain bool LTrack::set_previous_status() { if ( at_top_status() ) return false; --_chain._istat_current; return true; } //********************************************************************** // Add a status to the end of the list. // Returns a reference to the added status. // Sets pointer to reference the new status. LayerStat& LTrack::push_status(const LayerStat& lstat) { bool cluster_status_valid = _chain.cluster_status_is_valid(); _chain._stats.insert(_chain._stats.end(),lstat); _chain._istat_current = _chain._stats.end(); --_chain._istat_current; // If the cluster status was invalid, it was pointing at the end // of the list. We must reset it invalid because the end of the // list has moved. if ( ! cluster_status_valid ) { clear_cluster_status(); } return get_status(); } //********************************************************************** // drop the last status from the list // Set current status back only if it pointed at deleted element. // Return false if there was no status to drop. bool LTrack::pop_status() { if ( ! _chain._stats.size() ) return false; bool cluster_status_valid = _chain.cluster_status_is_valid(); LayerStatChain::StatList::iterator istat = _chain._stats.end(); --istat; bool cluster_status_dropped = _chain.cluster_status_at_last(); // Reset the current pointer if we are at the last element in // the list. if ( _chain._istat_current == istat ) { --_chain._istat_current; } _chain._stats.pop_back(); // If the cluster status is invalid or if it was pointing to // the element we dropped, then we must clear it. if ( !cluster_status_valid || cluster_status_dropped ) { clear_cluster_status(); } return true; } //********************************************************************** // Set the current status to be the cluster status. void LTrack::set_cluster_status() { _chain._istat_cluster = _chain._istat_current; } //********************************************************************** // Clear the current status. void LTrack::clear_cluster_status() { _chain._istat_cluster = _chain._stats.end(); } //********************************************************************** // output stream fundtion ostream& trf::operator<<(ostream& stream, const LTrack& trl) { trl.ostr(stream); return stream; } //**********************************************************************