#include #include #include "IHit.hxx" #include "IMCHit.hxx" #include "IMultiHit.hxx" #include "IHandle.hxx" #include "IHandleHack.hxx" #include "COMETGeomId.hxx" #include "ICTHGeomId.hxx" namespace tut { COMET::IHandle MakeHit(int index) { COMET::IWritableMCHit hit; // hit.SetGeomId(COMET::GeomId::FGD::Bar(0,0,0,0)); hit.SetGeomID(COMET::GeomId::CTH::Counter(0,0,0,0)); hit.SetTime(1.0*index); hit.SetCharge(1); COMET::IMCHit *p = new COMET::IMCHit(hit); p->SetBit(kCanDelete,true); return COMET::IHandle(p); } struct baseTMultiHit { baseTMultiHit() { // Run before each test. } ~baseTMultiHit() { // Run after each test. } }; // Declare the test typedef test_group::object testTMultiHit; test_group groupTMultiHit("IMultiHit"); // Test the default constructor and destructor. Make sure the default // values are all null. template<> template<> void testTMultiHit::test<1> () { COMET::IMultiHit hit; ensure("Multi hit is empty", hit.size() == 0); ensure("Iterators are 'void'", hit.begin() == hit.end()); } // Make sure that the right exception is thrown when an empty hit is // accessed through GetGeomID() template<> template<> void testTMultiHit::test<2> () { COMET::IMultiHit hit; try { hit.GetGeomID(); ensure("Empty hit throws exception for GetGeomID()",false); } catch (COMET::EMultiHitIllegal) { /// This should happen! } } // Make sure that the right exception is thrown when an empty hit is // accessed through GetCharge() template<> template<> void testTMultiHit::test<4> () { COMET::IMultiHit hit; try { hit.GetCharge(); ensure("Empty multi-hit throws exception for GetCharge()",false); } catch (COMET::EMultiHitIllegal) { /// This should happen! } } // Make sure that the right exception is thrown when an empty hit is // accessed through GetTime() template<> template<> void testTMultiHit::test<5> () { COMET::IMultiHit hit; try { hit.GetTime(); ensure("Empty multi-hit throws exception for GetTime()",false); } catch (COMET::EMultiHitIllegal) { /// This should happen! } } // Make sure that the right exception is thrown when an empty hit is // accessed through GetPosition() template<> template<> void testTMultiHit::test<6> () { COMET::IMultiHit hit; try { hit.GetPosition(); ensure("Empty multi-hit throws exception for GetPosition()",false); } catch (COMET::EMultiHitIllegal) { /// This should happen! } } // Make sure that the right exception is thrown when an empty hit is // accessed through IsXHit() template<> template<> void testTMultiHit::test<7> () { COMET::IMultiHit hit; try { hit.IsXHit(); ensure("Empty multi-hit throws exception for IsXHit()",false); } catch (COMET::EMultiHitIllegal) { /// This should happen! } } // Make sure that the right exception is thrown when an empty hit is // accessed through IsYHit() template<> template<> void testTMultiHit::test<8> () { COMET::IMultiHit hit; try { hit.IsYHit(); ensure("Empty multi-hit throws exception for IsYHit()",false); } catch (COMET::EMultiHitIllegal) { /// This should happen! } } // Make sure that the right exception is thrown when an empty hit is // accessed through IsZHit() template<> template<> void testTMultiHit::test<9> () { COMET::IMultiHit hit; try { hit.IsZHit(); ensure("Empty multi-hit throws exception for IsZHit()",false); } catch (COMET::EMultiHitIllegal) { /// This should happen! } } // Make sure that the right exception is thrown when an empty hit is // accessed through GetSpread() template<> template<> void testTMultiHit::test<10> () { COMET::IMultiHit hit; try { hit.GetSpread(); ensure("Empty multi-hit throws exception for GetSpread()",false); } catch (COMET::EMultiHitIllegal) { /// This should happen! } } // Make sure that the right exception is thrown when an empty hit is // accessed through GetUncertainty() template<> template<> void testTMultiHit::test<11> () { COMET::IMultiHit hit; try { hit.GetUncertainty(); ensure("Empty multi-hit throws for GetUncertainty()",false); } catch (COMET::EMultiHitIllegal) { /// This should happen! } } /* // Construct a COMET::IMultiHit with actual entries and make sure the accessors // work. This can only check some template<> template<> void testTMultiHit::test<12> () { { // Build a vector of single hits. std::vector< COMET::IHandle > hits; for (int i=0; i<10; ++i) hits.push_back(MakeHit(20-i)); COMET::IMultiHit hit(hits.begin(),hits.end()); ensure_equals("MultiHit size is correct", hit.size(), (unsigned) 10); // Make sure that none of the accessors throw an exception. hit.GetGeomID(); ensure_distance("hit charge same as size",hit.GetCharge(),10.0,0.1); ensure_lessthan("overall hit time not zero", 10, hit.GetTime()); hit.GetPosition(); hit.IsXHit(); hit.IsYHit(); hit.IsZHit(); hit.GetSpread(); hit.GetUncertainty(); unsigned int hitCount = 0; double time = 0; for (COMET::IMultiHit::iterator h = hit.begin(); h != hit.end(); ++h) { ++hitCount; ensure_lessthan("hit time is increasing",time,(*h)->GetTime()); time = (*h)->GetTime(); } ensure_equals("Same number of hits visited as hit.size()", hitCount, hit.size()); } ensure("Handle Registry is clean", COMET::CleanHandleRegistry()); } */ };