// TrackFinder.cpp #include "TrackFinder.h" #include "objstream/ObjData.hpp" #include "objstream/ObjTable.hpp" #include "trfutil/trfstream.h" #include "Path.h" using std::string; using trf::Algorithm; using trf::SurfacePtr; using trf::ETrack; using trf::TrackVector; using trf::TrackError; using trf::Path; using trf::PTrack; using trf::TrackFinder; //********************************************************************** // Free functions. //********************************************************************** namespace { // Creator. ObjPtr create(const ObjData& data) { assert( data.get_object_type() == "TrackFinder" ); const Path* ppath; data.get_bare_pointer( "path", ppath ); SurfacePtr psrf; data.get_share_pointer( "surface", psrf ); vector tvec; vector terr; TrackFinder::PathStopList stops; #ifdef ObjData_supports_lists data.get_double_list( "vector", tvec ); data.get_double_list( "error_matrix", terr ); data.get_bare_ptr_list( "stops" , stops ); #endif TrackVector vec; for ( int i=0; i<5; ++i ) vec(i) = tvec[i]; TrackError err; { int ij = 0; for ( int j=0; j<5; ++j ) for ( int i=0; i<=j; ++i ) err(i,j) = terr[ij++]; assert( ij = terr.size() ); } string tuple_name = data.get_string( "tuple_name" ); int debug = data.get_int( "debug" ); ETrack tre(psrf,vec,err); TrackFinder* pfind = new TrackFinder(*ppath,tre); for ( TrackFinder::PathStopList::const_iterator istp=stops.begin(); istp!=stops.end(); ++istp ) pfind->add_stop(**istp); pfind->set_tuple(tuple_name); pfind->set_debug(debug); return ObjPtr(pfind); } } //********************************************************************** // methods //********************************************************************** // output stream void TrackFinder::ostr(ostream& stream) const { stream << begin_object; stream << "Global track finder:" << new_line; stream << "Starting path: " << _path << new_line; stream << "Starting track: " << _tre << new_line; stream << "Extender: " << *_pextend << new_line; stream << end_object; } //********************************************************************** // constructor TrackFinder::TrackFinder(const Path& path, const ETrack& tre, CpuTimerTuple* ptimer) : _pextend(new TrackExtender(ptimer)), _path(path), _tre(tre) { // demand the path is a head path assert( path.is_head() ); } //********************************************************************** // destructor TrackFinder::~TrackFinder() { } //********************************************************************** // Return the creator. ObjCreator TrackFinder::get_creator() { return create; } //********************************************************************** // Write the object data. ObjData TrackFinder::write_data() const { ObjData data( get_type_name() ); data.add_bare_pointer( "path", &get_path() ); data.add_share_pointer( "surface", get_track().get_surface() ); #ifdef ObjData_supports_lists const vector vecvec = get_track().get_vector().get_std_vector(); data.add_double_list( "vector", vecvec ); const vector errvec = get_track().get_error().get_std_vector(); data.add_double_list( "error_matrix", errvec ); data.add_bare_ptr_list( "stops", get_stops() ); #endif data.add_string( "tuple_name", get_tuple_name() ); data.add_int( "debug", get_debug() ); return data; } //********************************************************************** // add a stop void TrackFinder::add_stop(const PathStop& stop) { _pextend->add_stop(stop); } //********************************************************************** // Define ntuple. If this is called with a nonzero length argument // then A PTrack ntuple with the given name will be filled. void TrackFinder::set_tuple(string name) { _pextend->set_tuple(name); } //********************************************************************** // find the tracks PTrack::PTrackList TrackFinder::find() const { // Build the track list. PTrack::PTrackList tracks; // Build the starting track. tracks.push_back( PTrack::PTrackPtr(new PTrack(_path,_tre)) ); // Extend tracks. _pextend->extend(tracks); // return the found tracks. return tracks; } //********************************************************************** // Override set debug to set extender debug. void TrackFinder::set_debug(int debug) { Algorithm::set_debug(debug); _pextend->set_debug(debug); } //**********************************************************************