// CheckCylDca_t.cpp #include "CheckCylDca.h" #include #include #include #include #include "objstream/StdObjStream.hpp" #include "trfutil/trfstream.h" #include "SurfCylinder.h" #include "trfbase/ETrack.h" #include "trffit/MTrack.h" #include "trffind/CheckerPtr.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 = "CheckCylDca"; 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 checker." << endl; ObjTable::register_type(); CheckCylDca chk(5.0, ObjDoublePtr(new ObjDouble(-2.0))); cout << chk << endl; //******************************************************************** cout << ok_prefix << "Test status." << endl; ETrack tre( SurfacePtr( new SurfCylinder(50.) ) ); TrackVector tv1; tv1(0) = 4.23249; tv1(1) = -18.7014; tv1(2) = -0.14731; tv1(3) = -0.55047; tv1(4) = -0.975139; tre.set_vector(tv1); MTrack trm(tre); cout << ok_prefix << "Checking Track: " << endl << trm << endl; trm.set_fit(tre,2.0); assert( chk.status(trm) ); //******************************************************************** cout << ok_prefix << "Write object data." << endl; { CheckerPtr pchk( new CheckCylDca(12.34,ObjDoublePtr(new ObjDouble(-2.0)))); ostringstream mystream; StdObjStream objstream(mystream); objstream.write_object("chk1",pchk); cout << mystream.str() << endl; assert( ObjTable::has_object_name("chk1") ); assert( mystream.str().find("12.34 ") != string::npos ); } //******************************************************************** cout << ok_prefix << "Read object data." << endl; { string istring = "[ chk2 CheckCylDca max_dca=24.68 bfield=2.0 ]"; istringstream isstrm(istring); { StdObjStream obstr(isstrm); string name = obstr.read_object(); assert( name == "chk2" ); const CheckCylDca* pchk; ObjTable::get_object("chk2",pchk); assert( pchk != 0 ); assert( pchk->get_type() == CheckCylDca::get_static_type() ); assert( pchk->get_max_dca() == 24.68 ); } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }