// TrackFinder_t.cpp #include "TrackFinder.h" #include #include #include #include "objstream/StdObjStream.hpp" #include "trfutil/trfstream.h" #include "Path.h" #include "trflayer/LayerTest.h" #include "trfbase/PropDirectedTest.h" #include "trffit/AddFitter.h" #include "trffit/AddFitterTest.h" #include "trfbase/SurfTest.h" #include "trfbase/ETrack.h" using std::cout; using std::cerr; using std::endl; using std::string; using std::ostringstream; using std::istringstream; using namespace trf; //********************************************************************** int main( ) { string component = "TrackFinder"; string ok_prefix = component + " (I): "; string error_prefix = component + " test (E): "; cout << ok_prefix << "-------- Testing component " + component + ". --------" << endl; // Make sure assert is enabled. bool assert_flag = false; assert ( ( assert_flag = true, assert_flag ) ); if ( ! assert_flag ) { cerr << "Assert is disabled" << endl; return 1; } //******************************************************************** cout << trf_format; cout << ok_prefix << "Create the paths." << endl; ObjTable::register_type(); Path path0; cout << path0 << endl; assert( path0.is_head() ); assert( path0.get_children().size() == 0 ); // add 1st generation LayerTest lay(1.0); PropTest prop; AddFitterTest fit(1); Path& path1 = *path0.add_child(lay,prop,fit); Path& path2 = *path0.add_child(lay,prop,fit); Path& path3 = *path0.add_child(lay,prop,fit); //******************************************************************** cout << ok_prefix << "Create starting track." << endl; SurfacePtr psrf( new SurfTest(1) ); TrackVector tvec; tvec(0) = 1.0; tvec(1) = 1.1; tvec(2) = 1.2; tvec(3) = 1.3; tvec(4) = 1.4; TrackError terr; terr(0,0) = .0100; terr(0,1) = .0101; terr(1,1) = .0111; terr(0,2) = .0102; terr(1,2) = .0112; terr(2,2) = .0122; terr(0,3) = .0103; terr(1,3) = .0113; terr(2,3) = .0123; terr(3,3) = .0133; terr(0,4) = .0104; terr(1,4) = .0114; terr(2,4) = .0124; terr(3,4) = .0134; terr(4,4) = .0144; ETrack tre(psrf,tvec,terr); //******************************************************************** cout << ok_prefix << "Create track finder." << endl; TrackFinder tfind(path0,tre); cout << tfind << endl; //******************************************************************** cout << ok_prefix << "Find tracks." << endl; PTrack::PTrackList tracks = tfind.find(); assert( tracks.size() == 3 ); //******************************************************************** cout << ok_prefix << "Fill PTrack ntuples." << endl; cout << "test1 should have 1 entry." << endl; cout << "test2 should have 2 entries." << endl; // fill test1 tfind.set_tuple("test1"); tfind.set_debug(1); cout << tfind << endl; tracks = tfind.find(); assert( tracks.size() == 3 ); // fill test1 tfind.set_tuple("test2"); tracks = tfind.find(); assert( tracks.size() == 3 ); tracks = tfind.find(); assert( tracks.size() == 3 ); // fill nothing tfind.set_tuple(""); tracks = tfind.find(); assert( tracks.size() == 3 ); //******************************************************************** cout << ok_prefix << "Write object data." << endl; PathPtr phead(new Path); PathStopPtr pstp1(new PathStop); PathStopPtr pstp2(new PathStop); { TrackFinder* pfind = new TrackFinder(*phead,tre); pfind->add_stop(*pstp1); pfind->add_stop(*pstp2); pfind->set_tuple("mytup"); pfind->set_debug(5); ObjPtr pobj(pfind); ostringstream mystream; StdObjStream objstream(mystream); objstream.write_object("head_path",phead); objstream.write_object("mysurf",psrf); objstream.write_object("stop1",pstp1); objstream.write_object("stop2",pstp2); objstream.write_object("obj1",pobj); cout << mystream.str() << endl; assert( ObjTable::has_object_name("obj1") ); string::size_type pos = 0; assert( (pos=mystream.str().find("obj1 ",pos)) != string::npos ); assert( (pos=mystream.str().find("TrackFinder ",pos)) != string::npos ); assert( (pos=mystream.str().find("path",pos)) != string::npos ); assert( (pos=mystream.str().find("head_path ",pos)) != string::npos ); assert( (pos=mystream.str().find("surface",pos)) != string::npos ); assert( (pos=mystream.str().find("mysurf ",pos)) != string::npos ); #ifdef ObjData_supports_lists assert( (pos=mystream.str().find("vector",pos)) != string::npos ); assert( (pos=mystream.str().find("1 ",pos)) != string::npos ); ++pos; assert( (pos=mystream.str().find("1.1 ",pos)) != string::npos ); assert( (pos=mystream.str().find("1.2 ",pos)) != string::npos ); assert( (pos=mystream.str().find("1.3 ",pos)) != string::npos ); assert( (pos=mystream.str().find("1.4 ",pos)) != string::npos ); assert( (pos=mystream.str().find("error_matrix",pos)) != string::npos ); assert( (pos=mystream.str().find("0.01",pos)) != string::npos ); assert( (pos=mystream.str().find("0.011",pos)) != string::npos ); assert( (pos=mystream.str().find("0.0111 ",pos)) != string::npos ); assert( (pos=mystream.str().find("0.0102 ",pos)) != string::npos ); assert( (pos=mystream.str().find("0.0112 ",pos)) != string::npos ); assert( (pos=mystream.str().find("0.0122 ",pos)) != string::npos ); assert( (pos=mystream.str().find("0.0103 ",pos)) != string::npos ); assert( (pos=mystream.str().find("0.0113 ",pos)) != string::npos ); assert( (pos=mystream.str().find("0.0123 ",pos)) != string::npos ); assert( (pos=mystream.str().find("0.0133 ",pos)) != string::npos ); assert( (pos=mystream.str().find("0.0104 ",pos)) != string::npos ); assert( (pos=mystream.str().find("0.0114 ",pos)) != string::npos ); assert( (pos=mystream.str().find("0.0124 ",pos)) != string::npos ); assert( (pos=mystream.str().find("0.0134 ",pos)) != string::npos ); assert( (pos=mystream.str().find("0.0144 ",pos)) != string::npos ); assert( (pos=mystream.str().find("stops",pos)) != string::npos ); assert( (pos=mystream.str().find("stop1 ",pos)) != string::npos ); assert( (pos=mystream.str().find("stop2 ",pos)) != string::npos ); #endif assert( (pos=mystream.str().find("tuple_name",pos)) != string::npos ); assert( (pos=mystream.str().find("\"mytup\" ",pos)) != string::npos ); assert( (pos=mystream.str().find("debug",pos)) != string::npos ); assert( (pos=mystream.str().find("5 ",pos)) != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ obj2 TrackFinder"; istring += "\n path=*head_path"; istring += "\n surface=@mysurf"; #ifdef ObjData_supports_lists istring += "\n vector=double( 1.0 1.1 1.2 1.3 1.4 )"; istring += "\n error_matrix=double("; istring += "\n 0.0100"; istring += "\n 0.0101 0.0111"; istring += "\n 0.0102 0.0112 0.0122"; istring += "\n 0.0103 0.0113 0.0123 0.0133"; istring += "\n 0.0104 0.0114 0.0124 0.0134 0.0144"; istring += "\n )"; istring += "\n stops=*( stop1 stop2 )"; #endif istring += "\n tuple_name=\"mytup2\""; istring += "\n debug = 3"; istring += "\n]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "obj2" ); const TrackFinder* pobj; ObjTable::get_object("obj2",pobj); assert( pobj != 0 ); assert( pobj->get_type() == TrackFinder::get_static_type() ); assert( &pobj->get_path() == phead ); #ifdef ObjData_supports_lists assert( pobj->get_track() == tre ); assert( pobj->get_stops().size() == 2 ); assert( pobj->get_stops().front() == pstp1 ); assert( pobj->get_stops().back() == pstp2 ); #endif assert( pobj->get_tuple_name() == "mytup2" ); assert( pobj->get_debug() == 3 ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }