// PathStop.cpp #include "PathStop.h" #include "objstream/ObjData.hpp" #include "objstream/ObjTable.hpp" #include "trfutil/trfstream.h" #include "trffit/MTrack.h" #include "trffit/FullFitter.h" #include "Filter.h" #include "Checker.h" using std::ostream; using trf::MTrack; using trf::FullFitterPtr; using trf::PathStop; //********************************************************************** // Free functions. //********************************************************************** namespace { // Creator. // Need to add list of filters. ObjPtr create(const ObjData& data) { assert( data.get_object_type() == "PathStop" ); FullFitterPtr pfit(0); if ( data.has("fitter") ) { data.get_share_pointer("fitter", pfit); } PathStop* pstop = new PathStop(pfit); #ifdef ObjData_supports_lists // Filters PathStop::FilterList filters; data.get_share_ptr_list("filters",filters); for ( PathStop::FilterList::const_iterator ifil=filters.begin(); ifil!=filters.end(); ++ifil ) { pstop->add_filter(*ifil); } // Checkers. if ( data.has("checkers") ) { PathStop::CheckerList checkers; data.get_share_ptr_list("checkers",checkers); for ( PathStop::CheckerList::const_iterator ichk=checkers.begin(); ichk!=checkers.end(); ++ichk ) { pstop->add_checker(*ichk); } } #endif return ObjPtr(pstop); } } //********************************************************************** // output stream void PathStop::ostr(ostream& stream) const { stream << begin_object; int size = get_filters().size(); if ( ! size ) stream << "Stop has no filters."; else { stream << "Stop has " << size << " filter"; if ( size > 1 ) stream << "s"; stream << ":"; FilterList::const_iterator ifilt; for ( ifilt=get_filters().begin(); ifilt!=get_filters().end(); ++ifilt ) stream << new_line << **ifilt; } stream << end_object; } //********************************************************************** // constructor PathStop::PathStop() : _pfit(0) { } //********************************************************************** // constructor with fitter. PathStop::PathStop(const FullFitterPtr& pfit) : _pfit(pfit) { } //********************************************************************** // destructor PathStop::~PathStop() { } //********************************************************************** // Return the creator. ObjCreator PathStop::get_creator() { return create; } //********************************************************************** // Write the object data. // We need to add list of filters. ObjData PathStop::write_data() const { ObjData data( get_type_name() ); data.add_share_pointer("fitter",_pfit); #ifdef ObjData_supports_lists data.add_share_ptr_list("filters",_filters); data.add_share_ptr_list("checkers",_checkers); #endif return data; } //********************************************************************** // add a checker void PathStop::add_checker(const CheckerPtr& pchk) { _checkers.push_back(pchk); } //********************************************************************** // add a filter void PathStop::add_filter(const FilterPtr& pfilt) { _filters.push_back(pfilt); } //********************************************************************** // Apply the fitter and list of post checkers to the track. // Return 0 if fit succeeds and all checkers pass. // Track may no longer be valid if nonzero is returned. int PathStop::fitcheck(MTrack& trm) const { if ( _pfit != 0 ) { int stat = _pfit->fit(trm); if ( stat != 0 ) { make_report(*this, "refit error", stat); return stat; } } int icount = 0; for ( CheckerList::const_iterator ichk=_checkers.begin(); ichk!=_checkers.end(); ++ichk ) { icount += 10000; const Checker& chk = **ichk; if ( ! chk.status(trm) ) { make_report(*this, "check failure", icount/10000); return icount; } } return 0; } //********************************************************************** // Friends. //********************************************************************** ostream& trf::operator<<(ostream& stream, const PathStop& stop) { stop.ostr(stream); return stream; } //**********************************************************************