diff --git a/Generators/GeneratorObjects/share/HepMcParticleLink_test.ref b/Generators/GeneratorObjects/share/HepMcParticleLink_test.ref index 3b5c108c78eaab7a82dfa60c6a4bc5cfb5502009..b7430df5df9969fb9ce9e54b348f54acc0787a7e 100644 --- a/Generators/GeneratorObjects/share/HepMcParticleLink_test.ref +++ b/Generators/GeneratorObjects/share/HepMcParticleLink_test.ref @@ -1,31 +1,32 @@ -[==========] Running 3 tests from 1 test case. +[==========] Running 4 tests from 1 test case. [----------] Global test environment set-up. ApplicationMgr SUCCESS ==================================================================================================================================== - Welcome to ApplicationMgr (GaudiCoreSvc v27r1p99) - running on karma on Tue Feb 19 16:13:51 2019 + Welcome to ApplicationMgr (GaudiCoreSvc v33r1) + running on pc-camb05 on Wed Apr 29 13:48:28 2020 ==================================================================================================================================== ApplicationMgr INFO Application Manager Configured successfully EventLoopMgr WARNING Unable to locate service "EventSelector" EventLoopMgr WARNING No events will be processed from external input. -HistogramPersis...WARNING Histograms saving not required. ApplicationMgr INFO Application Manager Initialized successfully ApplicationMgr Ready -[----------] 3 tests from HepMcParticleLink_test +[----------] 4 tests from HepMcParticleLink_test [ RUN ] HepMcParticleLink_test.old_test *** HepMcParticleLink_test starts *** -ClassIDSvc INFO getRegistryEntries: read 896 CLIDRegistry entries for module ALL +ClassIDSvc INFO getRegistryEntries: read 817 CLIDRegistry entries for module ALL Testing HepMcParticleLink streamer Event index 0, Barcode 10005, McEventCollection CollectionNotSet(a) --- Event index 1, Barcode 10005, McEventCollection CollectionNotSet(a) HepMcParticleLink INFO find_proxy: Using TruthEvent as McEventCollection key for this job *** HepMcParticleLink_test OK *** -[ OK ] HepMcParticleLink_test.old_test (63 ms) +[ OK ] HepMcParticleLink_test.old_test (53 ms) [ RUN ] HepMcParticleLink_test.broken_event_link -ClassIDSvc INFO getRegistryEntries: read 1024 CLIDRegistry entries for module ALL -[ OK ] HepMcParticleLink_test.broken_event_link (5 ms) +ClassIDSvc INFO getRegistryEntries: read 1070 CLIDRegistry entries for module ALL +[ OK ] HepMcParticleLink_test.broken_event_link (1 ms) [ RUN ] HepMcParticleLink_test.truth_event_link [ OK ] HepMcParticleLink_test.truth_event_link (0 ms) -[----------] 3 tests from HepMcParticleLink_test (68 ms total) +[ RUN ] HepMcParticleLink_test.max_event_number +[ OK ] HepMcParticleLink_test.max_event_number (0 ms) +[----------] 4 tests from HepMcParticleLink_test (54 ms total) [----------] Global test environment tear-down -[==========] 3 tests from 1 test case ran. (113 ms total) -[ PASSED ] 3 tests. +[==========] 4 tests from 1 test case ran. (176 ms total) +[ PASSED ] 4 tests. diff --git a/Generators/GeneratorObjects/test/HepMcParticleLink_test.cxx b/Generators/GeneratorObjects/test/HepMcParticleLink_test.cxx index 9faf8cf0d3d017603b758c266391e59bd5cd76b3..022754721ff5abdab1c3f1114e2d6de16361d3dc 100644 --- a/Generators/GeneratorObjects/test/HepMcParticleLink_test.cxx +++ b/Generators/GeneratorObjects/test/HepMcParticleLink_test.cxx @@ -260,18 +260,24 @@ namespace MCTesting { const int process_id1(20); const int event_number1(17); inputTestDataHandle->push_back(new HepMC::GenEvent(process_id1, event_number1)); + const HepMcParticleLink::index_type dummyIndex1(0); + const HepMcParticleLink::index_type refEvtNum1 = static_cast<HepMcParticleLink::index_type>(event_number1); HepMC::GenEvent& ge1 = *(inputTestDataHandle->at(0)); const HepMC::GenParticle* particle1 = populateGenEvent(ge1); // Add a second dummy GenEvent const int process_id2(20); const int event_number2(25); inputTestDataHandle->push_back(new HepMC::GenEvent(process_id2, event_number2)); + const HepMcParticleLink::index_type dummyIndex2(1); + const HepMcParticleLink::index_type refEvtNum2 = static_cast<HepMcParticleLink::index_type>(event_number2); HepMC::GenEvent& ge2 = *(inputTestDataHandle->at(1)); const HepMC::GenParticle* particle2 = populateGenEvent2(ge2); // Add a third dummy GenEvent (identical to the first) const int process_id3(20); const int event_number3(17); inputTestDataHandle->push_back(new HepMC::GenEvent(process_id3, event_number3)); + const HepMcParticleLink::index_type dummyIndex3(2); + const HepMcParticleLink::index_type refEvtNum3 = static_cast<HepMcParticleLink::index_type>(event_number3); HepMC::GenEvent& ge3 = *(inputTestDataHandle->at(2)); const HepMC::GenParticle* particle3 = populateGenEvent(ge3); @@ -284,8 +290,8 @@ namespace MCTesting { HepMcParticleLink::IS_POSITION); ASSERT_TRUE( testLink1a.isValid() ); ASSERT_EQ( particle1->barcode(), testLink1a.barcode()); - ASSERT_EQ( event_number1, testLink1a.eventIndex()); - ASSERT_EQ( 0, testLink1a.getEventPositionInCollection(sg)); + ASSERT_EQ( refEvtNum1, testLink1a.eventIndex()); + ASSERT_EQ( dummyIndex1, testLink1a.getEventPositionInCollection(sg)); ASSERT_EQ(particle1,testLink1a.cptr()); // A HepMcParticleLink built using the barcode and the position of // the GenEvent. @@ -293,26 +299,26 @@ namespace MCTesting { HepMcParticleLink::IS_POSITION); ASSERT_TRUE( testLink1b.isValid() ); ASSERT_EQ( particle1->barcode(), testLink1b.barcode()); - ASSERT_EQ( event_number1, testLink1b.eventIndex()); - ASSERT_EQ( 0, testLink1b.getEventPositionInCollection(sg)); + ASSERT_EQ( refEvtNum1, testLink1b.eventIndex()); + ASSERT_EQ( dummyIndex1, testLink1b.getEventPositionInCollection(sg)); ASSERT_EQ(*(testLink1a.cptr()),*(testLink1b.cptr())); // HepMcParticleLink built using a GenParticle pointer and the // event_number of the GenEvent. HepMcParticleLink testLink1c(particle1,event_number1); ASSERT_TRUE( testLink1c.isValid() ); ASSERT_EQ( particle1->barcode(), testLink1c.barcode()); - ASSERT_NE( 0, testLink1c.eventIndex()); - ASSERT_EQ( event_number1, testLink1c.eventIndex()); - ASSERT_EQ( 0, testLink1c.getEventPositionInCollection(sg)); + ASSERT_NE( dummyIndex1, testLink1c.eventIndex()); + ASSERT_EQ( refEvtNum1, testLink1c.eventIndex()); + ASSERT_EQ( dummyIndex1, testLink1c.getEventPositionInCollection(sg)); ASSERT_EQ(particle1,testLink1c.cptr()); // A HepMcParticleLink built using the barcode and the event_number of // the GenEvent. HepMcParticleLink testLink1d(particle1->barcode(),event_number1); ASSERT_TRUE( testLink1d.isValid() ); ASSERT_EQ( particle1->barcode(), testLink1d.barcode()); - ASSERT_NE( 0, testLink1d.eventIndex()); - ASSERT_EQ( event_number1, testLink1d.eventIndex()); - ASSERT_EQ( 0, testLink1d.getEventPositionInCollection(sg)); + ASSERT_NE( dummyIndex1, testLink1d.eventIndex()); + ASSERT_EQ( refEvtNum1, testLink1d.eventIndex()); + ASSERT_EQ( dummyIndex1, testLink1d.getEventPositionInCollection(sg)); ASSERT_EQ(particle1,testLink1d.cptr()); //Testing links to the second dummy GenEvent @@ -323,8 +329,8 @@ namespace MCTesting { HepMcParticleLink::IS_POSITION); ASSERT_TRUE( testLink2a.isValid() ); ASSERT_EQ( particle2->barcode(), testLink2a.barcode()); - ASSERT_EQ( event_number2, testLink2a.eventIndex()); - ASSERT_EQ( 1, testLink2a.getEventPositionInCollection(sg)); + ASSERT_EQ( refEvtNum2, testLink2a.eventIndex()); + ASSERT_EQ( dummyIndex2, testLink2a.getEventPositionInCollection(sg)); ASSERT_EQ(particle2,testLink2a.cptr()); // A HepMcParticleLink built using the barcode and the position of // the GenEvent. @@ -332,26 +338,26 @@ namespace MCTesting { HepMcParticleLink::IS_POSITION); ASSERT_TRUE( testLink2b.isValid() ); ASSERT_EQ( particle2->barcode(), testLink2b.barcode()); - ASSERT_EQ( event_number2, testLink2b.eventIndex()); - ASSERT_EQ( 1, testLink2b.getEventPositionInCollection(sg)); + ASSERT_EQ( refEvtNum2, testLink2b.eventIndex()); + ASSERT_EQ( dummyIndex2, testLink2b.getEventPositionInCollection(sg)); ASSERT_EQ(particle2,testLink2b.cptr()); // HepMcParticleLink built using a GenParticle pointer and the // event_number of the GenEvent. HepMcParticleLink testLink2c(particle2,event_number2); ASSERT_TRUE( testLink2c.isValid() ); ASSERT_EQ( particle2->barcode(), testLink2c.barcode()); - ASSERT_NE( 1, testLink2c.eventIndex()); - ASSERT_EQ( event_number2, testLink2c.eventIndex()); - ASSERT_EQ( 1, testLink2c.getEventPositionInCollection(sg)); + ASSERT_NE( dummyIndex2, testLink2c.eventIndex()); + ASSERT_EQ( refEvtNum2, testLink2c.eventIndex()); + ASSERT_EQ( dummyIndex2, testLink2c.getEventPositionInCollection(sg)); ASSERT_EQ(particle2,testLink2c.cptr()); // A HepMcParticleLink built using the barcode and the event_number of // the GenEvent. HepMcParticleLink testLink2d(particle2->barcode(),event_number2); ASSERT_TRUE( testLink2d.isValid() ); ASSERT_EQ( particle2->barcode(), testLink2d.barcode()); - ASSERT_NE( 1, testLink2d.eventIndex()); - ASSERT_EQ( event_number2, testLink2d.eventIndex()); - ASSERT_EQ( 1, testLink2d.getEventPositionInCollection(sg)); + ASSERT_NE( dummyIndex2, testLink2d.eventIndex()); + ASSERT_EQ( refEvtNum2, testLink2d.eventIndex()); + ASSERT_EQ( dummyIndex2, testLink2d.getEventPositionInCollection(sg)); ASSERT_EQ(particle2,testLink2d.cptr()); //Testing links to the third dummy GenEvent @@ -362,7 +368,7 @@ namespace MCTesting { HepMcParticleLink::IS_POSITION); ASSERT_TRUE( testLink3a.isValid() ); ASSERT_EQ( particle3->barcode(), testLink3a.barcode()); - ASSERT_EQ( event_number3, testLink3a.eventIndex()); + ASSERT_EQ( refEvtNum3, testLink3a.eventIndex()); ASSERT_EQ(particle3,testLink3a.cptr()); // A HepMcParticleLink built using the barcode and the position of // the GenEvent. @@ -370,23 +376,23 @@ namespace MCTesting { HepMcParticleLink::IS_POSITION); ASSERT_TRUE( testLink3b.isValid() ); ASSERT_EQ( particle3->barcode(), testLink3b.barcode()); - ASSERT_EQ( event_number3, testLink3b.eventIndex()); + ASSERT_EQ( refEvtNum3, testLink3b.eventIndex()); ASSERT_EQ(particle3,testLink3b.cptr()); // HepMcParticleLink built using a GenParticle pointer and the // event_number of the GenEvent. HepMcParticleLink testLink3c(particle3,event_number3); ASSERT_TRUE( testLink3c.isValid() ); ASSERT_EQ( particle3->barcode(), testLink3c.barcode()); - ASSERT_NE( 2, testLink3c.eventIndex()); - ASSERT_EQ( event_number3, testLink3c.eventIndex()); + ASSERT_NE( dummyIndex3, testLink3c.eventIndex()); + ASSERT_EQ( refEvtNum3, testLink3c.eventIndex()); ASSERT_EQ(particle3,testLink3c.cptr()); // A HepMcParticleLink built using the barcode and the event_number of // the GenEvent. BROKEN HepMcParticleLink testLink3d(particle3->barcode(),event_number3); ASSERT_TRUE( testLink3d.isValid() ); ASSERT_EQ( particle3->barcode(), testLink3d.barcode()); - ASSERT_NE( 2, testLink3d.eventIndex()); - ASSERT_EQ( event_number3, testLink3d.eventIndex()); + ASSERT_NE( dummyIndex3, testLink3d.eventIndex()); + ASSERT_EQ( refEvtNum3, testLink3d.eventIndex()); ASSERT_NE(particle3,testLink3d.cptr()); ASSERT_EQ(particle1,testLink3d.cptr()); //POINTS AT THE IDENTICAL PARTICLE IN FIRST GenEvent!! @@ -395,6 +401,79 @@ namespace MCTesting { pStore->clearStore(true).ignore(); // forceRemove=true to remove all proxies } + TEST_F(HepMcParticleLink_test, max_event_number) { + // create dummy input McEventCollection with a name that + // HepMcParticleLink knows about + SG::WriteHandle<McEventCollection> inputTestDataHandle{"TruthEvent"}; + inputTestDataHandle = std::make_unique<McEventCollection>(); + + // Add a dummy GenEvent + const int process_id1(20); + const int event_number1(32767); + // 32767 = 2^15 -1 is the largest supported event number by + // HepMcParticleLink as the 16th bit of the unsigned short used to + // hold the eventIndex is used to flag whether the it represents the + // position of the GenEvent in the McEventCollection or the + // GenEvent::event_number. + inputTestDataHandle->push_back(new HepMC::GenEvent(process_id1, event_number1)); + const HepMcParticleLink::index_type dummyIndex1(0); + const HepMcParticleLink::index_type refEvtNum1 = static_cast<HepMcParticleLink::index_type>(event_number1); + HepMC::GenEvent& ge1 = *(inputTestDataHandle->at(0)); + const HepMC::GenParticle* particle1 = populateGenEvent(ge1); + // Add a second dummy GenEvent + const int process_id2(20); + const int event_number2(25); + inputTestDataHandle->push_back(new HepMC::GenEvent(process_id2, event_number2)); + // Add a third dummy GenEvent + const int process_id3(20); + const int event_number3(17); + inputTestDataHandle->push_back(new HepMC::GenEvent(process_id3, event_number3)); + + //Testing links to the first dummy GenEvent + const IProxyDict* sg = SG::CurrentEventStore::store(); + + // HepMcParticleLink built using a GenParticle pointer and the + // position of the GenEvent. + HepMcParticleLink testLink1a(particle1,0, EBC_MAINEVCOLL, + HepMcParticleLink::IS_POSITION); + ASSERT_TRUE( testLink1a.isValid() ); + ASSERT_EQ( particle1->barcode(), testLink1a.barcode()); + ASSERT_EQ( refEvtNum1, testLink1a.eventIndex()); + ASSERT_EQ( dummyIndex1, testLink1a.getEventPositionInCollection(sg)); + ASSERT_EQ(particle1,testLink1a.cptr()); + // A HepMcParticleLink built using the barcode and the position of + // the GenEvent. + HepMcParticleLink testLink1b(particle1->barcode(),0, EBC_MAINEVCOLL, + HepMcParticleLink::IS_POSITION); + ASSERT_TRUE( testLink1b.isValid() ); + ASSERT_EQ( particle1->barcode(), testLink1b.barcode()); + ASSERT_EQ( refEvtNum1, testLink1b.eventIndex()); + ASSERT_EQ( dummyIndex1, testLink1b.getEventPositionInCollection(sg)); + ASSERT_EQ(*(testLink1a.cptr()),*(testLink1b.cptr())); + // HepMcParticleLink built using a GenParticle pointer and the + // event_number of the GenEvent. + HepMcParticleLink testLink1c(particle1,event_number1); + ASSERT_TRUE( testLink1c.isValid() ); + ASSERT_EQ( particle1->barcode(), testLink1c.barcode()); + ASSERT_NE( dummyIndex1, testLink1c.eventIndex()); + ASSERT_EQ( refEvtNum1, testLink1c.eventIndex()); + ASSERT_EQ( dummyIndex1, testLink1c.getEventPositionInCollection(sg)); + ASSERT_EQ(particle1,testLink1c.cptr()); + // A HepMcParticleLink built using the barcode and the event_number of + // the GenEvent. + HepMcParticleLink testLink1d(particle1->barcode(),event_number1); + ASSERT_TRUE( testLink1d.isValid() ); + ASSERT_EQ( particle1->barcode(), testLink1d.barcode()); + ASSERT_NE( dummyIndex1, testLink1d.eventIndex()); + ASSERT_EQ( refEvtNum1, testLink1d.eventIndex()); + ASSERT_EQ( dummyIndex1, testLink1d.getEventPositionInCollection(sg)); + ASSERT_EQ(particle1,testLink1d.cptr()); + + StoreGateSvc* pStore(nullptr); + ASSERT_TRUE(MCTesting::g_svcLoc->service("StoreGateSvc", pStore).isSuccess()); + pStore->clearStore(true).ignore(); // forceRemove=true to remove all proxies + } + } // <-- namespace MCTesting