// Path.cpp #include "Path.h" #include "objstream/ObjData.hpp" #include "objstream/ObjTable.hpp" #include "trfutil/trfstream.h" #include "trfbase/Propagator.h" #include "trflayer/Layer.h" #include "trffit/AddFitter.h" #include "trffit/FullFitter.h" #include "Checker.h" #include "PathStop.h" #include using trf::Propagator; using trf::Layer; using trf::AddFitter; using trf::FullFitter; using trf::ClusterFilterPtr; using trf::CheckerPtr; using trf::PathStopPtr; using trf::Path; using trf::PathPtr; using trf::MutablePathPtr; //********************************************************************** // Free functions. //********************************************************************** namespace { // Creator. ObjPtr create(const ObjData& data) { assert( data.get_object_type() == "Path" ); PathPtr pparent; data.get_share_pointer("parent",pparent); MutablePathPtr pthis; // Fetch the optional name. string name; if ( data.has("name") ) { name = data.get_string("name"); } // If there is no parent, this is a head path. if ( pparent == 0 ) { pthis = MutablePathPtr( new Path(name) ); // Otherwise get this path from parent. } else { const Layer* plyr; data.get_bare_pointer("layer", plyr); const Propagator* pprop; data.get_bare_pointer("propagator", pprop ); const AddFitter* pfit; data.get_bare_pointer("fitter", pfit); MutablePathPtr pparent_mutable; pparent_mutable.assign_with_const_cast(pparent); pthis = pparent_mutable->add_child(*plyr, *pprop, *pfit, name); } #ifdef ObjData_supports_lists // Add the cluster filters. // For now this list is optional. if ( data.has("cfilters") ) { Path::ClusterFilterList filters; data.get_share_ptr_list("cfilters",filters); for ( Path::ClusterFilterList::const_iterator ifil=filters.begin(); ifil!=filters.end(); ++ifil ) { pthis->add_cluster_filter(*ifil); } } // Add the checkers. { Path::CheckerList checkers; data.get_share_ptr_list("checkers",checkers); for ( Path::CheckerList::const_iterator ichk=checkers.begin(); ichk!=checkers.end(); ++ichk ) { pthis->add_checker(*ichk); } } // Add the post checkers. if ( data.has("post_checkers") ) { Path::CheckerList checkers; data.get_share_ptr_list("post_checkers",checkers); for ( Path::CheckerList::const_iterator ichk=checkers.begin(); ichk!=checkers.end(); ++ichk ) { pthis->add_post_checker(*ichk); } } #endif // Add the stop. PathStopPtr pstop; data.get_share_pointer("stop", pstop); if ( pstop != 0 ) { pthis->set_stop(pstop); } bool end = data.get_bool("end"); pthis->set_end(end); // Add the optional refitter. if ( data.has("refitter") ) { const FullFitter* pfit; data.get_bare_pointer("refitter", pfit); pthis->add_refitter(*pfit); } return ObjPtr(pthis); } } //********************************************************************** // Static data. //********************************************************************** // Initialize path count. int Path::_count = 0; //********************************************************************** // Member functions. //********************************************************************** // private constructor Path::Path(MutableNullPathPtr pparent, const Layer& layer, const Propagator& prop, const AddFitter& fit, string name) : _pparent(pparent), _cnl(layer,prop,fit), _prefit(0), _pstop(0), _end(false), _id(_count), _name(name) { // Increment path count ++_count; } //********************************************************************** // output stream void Path::ostr(ostream& stream) const { stream << begin_object; int nchild = get_children().size(); if ( ! _pparent ) stream << "Head path"; else stream << "Path"; stream << " " << _name; stream << " " << get_id(); stream << " with " << nchild << " child"; if ( nchild != 1 ) stream << "ren"; if ( ! _pparent ) { stream << end_object; return; } stream << ":"; PathList::const_iterator ipth; for (ipth=get_children().begin(); ipth!=get_children().end(); ++ipth) stream << " " << (*ipth)->get_id(); stream << new_line; stream << _cnl; stream << new_line; { int nchk = get_checkers().size(); stream << "Path has " << nchk << " checker"; if ( nchk != 1 ) stream << "s"; if ( nchk == 0 ) { stream << "."; } else { stream << ":"; for (CheckerList::const_iterator ichk=get_checkers().begin(); ichk!=get_checkers().end(); ++ichk) stream << new_line << **ichk; } } stream << new_line; if ( _prefit == 0 ) { stream << "No refitter."; } else { stream << *_prefit; } stream << new_line; { int nchk = get_post_checkers().size(); stream << "Path has " << nchk << " checker"; if ( nchk != 1 ) stream << "s"; if ( nchk == 0 ) { stream << "."; } else { stream << ":"; for (CheckerList::const_iterator ichk=get_post_checkers().begin(); ichk!=get_post_checkers().end(); ++ichk) stream << new_line << **ichk; } } if ( _pstop ) stream << "Stop: " << *_pstop; else stream << "No stop."; stream << new_line; if ( _end ) stream << "This is a track endpoint."; else stream << "This is not a track endpoint."; stream << end_object; } //********************************************************************** // head constructor Path::Path(string name) : _pparent(0), _prefit(0), _pstop(0), _end(false), _id(_count), _name(name) { ++_count; } //********************************************************************** // destructor // Destroy all child paths. Path::~Path() { } //********************************************************************** // Return the creator. ObjCreator Path::get_creator() { return create; } //********************************************************************** // Write the object data. // We need to add list of filters. ObjData Path::write_data() const { ObjData data( get_type_name() ); data.add_share_pointer( "parent", get_parent() ); if ( get_parent() != 0 ) { data.add_bare_pointer( "layer", &get_candidate_layer().get_layer() ); data.add_bare_pointer( "propagator", &get_candidate_layer().get_propagator() ); data.add_bare_pointer( "fitter", &get_candidate_layer().get_fitter() ); } data.add_bare_pointer( "refitter", _prefit ); #ifdef ObjData_supports_lists data.add_share_ptr_list( "checkers", get_checkers() ); data.add_share_ptr_list( "post_checkers", get_post_checkers() ); #endif data.add_share_pointer( "stop", get_stop() ); data.add_bool( "end", get_end() ); if ( _name != "" ) { data.add_string("name", _name); } return data; } //********************************************************************** // Add a child to this path. MutablePathPtr Path::add_child(const Layer& layer, const Propagator& prop, const AddFitter& fit, string name) { MutableNullPathPtr pparent(this); MutablePathPtr pchild( new Path(pparent,layer,prop,fit,name) ); _children.push_back(pchild); return pchild; } //********************************************************************** // Add a cluster filter. void Path::add_cluster_filter(const ClusterFilterPtr& pfil) { // The head path may not have cluser filters. assert( ! is_head() ); _cfilters.push_back(pfil); } //********************************************************************** // Add a checker. void Path::add_checker(const CheckerPtr& pchk) { // The head path may not have checkers. assert( ! is_head() ); _checkers.push_back(pchk); } //********************************************************************** // Add a post checker. void Path::add_post_checker(const CheckerPtr& pchk) { // The head path may not have checkers. assert( ! is_head() ); _post_checkers.push_back(pchk); } //********************************************************************** // Add the refitterr. void Path::add_refitter(const FullFitter& fit) { _prefit = &fit; } //********************************************************************** // set the stop void Path::set_stop(const PathStopPtr& pstop) { //assert( ! is_head() ); _pstop = pstop; } //********************************************************************** // fetch the list of mutable child paths // We must cast way const because the child paths are stored // as such for the more common retrieval. const Path::MutablePathList Path::get_mutable_children() { MutablePathList children; PathList::const_iterator ipth = get_children().begin(); while ( ipth != get_children().end() ) { PathPtr pconst = *ipth++; MutablePathPtr pmutable; pmutable.assign_with_const_cast(pconst); children.push_back(pmutable); } return children; } //********************************************************************** // Friends. //********************************************************************** ostream& trf::operator<<(ostream& stream, const Path& path) { path.ostr(stream); return stream; } //**********************************************************************