Skip to content
Snippets Groups Projects
Commit b44955b7 authored by Hass AbouZeid's avatar Hass AbouZeid
Browse files

Merge branch 'ATLASSIM-3365-ISF-improve-CollectionMerger-robustness' into '21.0'

Make ISF CollectionMerger correctly copy pointer-type hits for `AthenaHitsVector` collections

See merge request !3181

Former-commit-id: e77320f7
parents 54a2606f 7fbc3e58
No related branches found
No related tags found
112 merge requests!76035Updated rel21 number,!66713update MadGraph version,!63304adding missing electron iso WPs (Tight_VarRad, Loose_VarRad, TightTrackOnly_VarRad),!62053Merge branch 'sh_xrd_warning' into 'master',!61521fix maxPVrefit,!59663fixed a typo in HIGG8D1 format (followup of https://gitlab.cern.ch/atlas/athena/-/merge_requests/59575),!51680Add functionality to MultiBjetFilter,!50754Return TruthTaus from truth matching tool in SUSY tools,!48850Added new HDBS derivation (HDBS3),!46643Draft:Adding MET Significance in AT,!46457Draft: Adding the tools to run over data,!46454Draft: Adding the tools to be able to run over data,!46320Draft: Adding support for Leading3SignalJets strategy,!45689Bug fix: Use wrong vector to calculate largest bin number in findBin(),!45211Update in the FFJetSmearingTool,!45045WIP: Include another condition for hit merging in FCS_StepInfoSD.cxx,!45043Merge branch 'Update-DAOD_IDNCB' into '21.2',!44869Draft: Update to candidate store,!44864Draft: WIP- MuonUncorrelateSystematics,!44215added ART tests,!43718Modification of EXOT17.py for fractionally charged particle search,!42752Fix for TopRecon UserHook,!4217921.9-first_steps-InDetTrackingGeometryXML,!42171Add LAr cell DQ plots to UPC stream,!41097TruthJetFilter phi filter,!40581Fix crash in egamma topocluster decorator,!40342WIP: ATR-22546 - add missing trigger to MC16a,!39592Cherry picking !27086 in 21.0 mc16d (ATLPHYSVAL-705),!39162Draft: Insert BCM' support,!38765Bis78 cabling,!38102Add SameParticleHardScatteringFilter,!37848Add TrigRingerRings to EGAM3, EGAM4 and EGAM9,!37483Fix in monitoring of Pixel FE errors,!36893Fix size of RPC active region in BIS78 and strip material,!36766Truth class fallback max dr,!36648Rivet doc update,!3645821.9: Improving material map description (ATLITKSW-127),!36293WIP pixel updates,!35816Add HardScatterParticles into the EXOT8 Derivation,!35273Fix JETM1: add back TruthEvents,!34993KF-input adding jXERHO to the AOD outputs,!34864LH rings in front ot HR rigs,!34763Fix L1_4jJ15.0ETA25 item definition (ATR-21261),!3473421.0 fix dq servers,!34244WIP: 21.2 topq1 add rc jets 2020 06 27,!34182Merge new MCTruthClassifier developments into master,!34164Use allMuons instead oc combinedOnly for BPHY15,!33996WIP: Correct MM zpositions,!33707WIP: Fixes for the updated Powheg Wt_DR process, and removal of Wt_DR_onshellW and Wt_DS_onshellW processes,!33109Add delta-R to nearest VR track jet decoration,!33012Adding Prompt Lepton Improved Veto to TOPQ,!3297121.6 parameter dict pythia fixes,!3291021.3 salva s0,!3288421.0 salva s8,!32637WIP: Add tracks in R=0.4 jets to STDM11,!32353WIP: Fix rare bug in jet smearing RNG seed,!3217421.9 - Bug fix for test stream creation in RD53BEncodingTool,!32173H7 lhe interface,!32051Fix of compilation warnings in CPAnalysisExamples,!31371Add missing copyright headings,!31361WIP: AnalysisTop Update - New Muon Isolation WPs included,!3135321.3,!3134821.9 README Update,!31345Add HEC sampling fractions macros,!31136added also PUsub for LargeR jets,!31123WIP: Master ttmdev,!30796Reducing number of warnings in MuonEfficiencyCorrections when missing dRJet decoration,!3043421.6 mg,!3036121.9 fixing bug with layer indices in PixelRDOAnalysis,!30295Move from boost::filesystem to std::filesystem,!29617IDPerfmonZmumu updates,!29454Idpvm 21.0 fix typo in trackselection config,!29180WIP: Add multiplicity calculations to JetEtMiss code,!29085TRT modification for fractional charged particles,!28623Overlay as part of FastChain transform in 21.3,!28497ART tests - fixing the bugs,!27685update MG version to 2.6.7p3.atlas4,!27668Massimos 21.3 bis78,!27299WIP: Turning b-jet thinning off in SUSY1 (permanent?),!27254WIP: Exclusive jets request -- Fix ExclusiveJets algo / ATR-17320,!27094JETM8 UFO fix,!26790Fixes for Simulation ART jobs (ATLASSIM-4309),!26747Update frozen shower generation scripts and code to be compatible with recent developments,!26641Rename member functions to start with lower case,!26592Master upload 2018 global monitoring scripts p2,!2618221.0 z counting,!25405Add new ART test: test_physics_pp_v8_chainorder_build.sh,!2498621.6 transf,!24487Time-stamped PFlow containers in output DAOD,!24347Electron-in-jet and overlap removal interplay fixed,!24210WIP: Add syst for r21 vs r20.7 differences to defaults,!2420321.3 l1 muon 00 - new MuCTPI_RDO.h,!24037Make DCS Calculator dependent on sqlalchemy; fix python code quality issues,!23744New trigger derivation for jet substructure,!23377WIP pixel ID scheme for ITk,!23330Inner Detector create misalignments: radial distortions,!2325521.0 z counting,!22695Master salva id perf mon,!2230421.0-ART_test-InDetPhysValMonitoring,!22214add an utility function to TrigT1TGCRecRoiSvc for storing ROI position and the eta/phi size,!22172changes related to 1-3 points in ATR-19579,!22124Changes related to ticket 19579,!22118Remove cabling information for new thresholds,!21684WIP: test push into tdaq-htt,!21621Updating fJVT WP with new recommendations in TopCPTools,!2153821.0-ART_test-InDetPhysValMonitoring,!21325Tilecal new laser unpack 2019 02 19,!21304WIP: Fix ATR-19377 L1Topo vbs alg,!2117721.3 po bugfixes,!21039Merging in features for HTT Bank Generation,!2089821.2 rpv1l,!20518Mydev
......@@ -153,24 +153,24 @@ StatusCode ISF::CollectionMerger::initialize()
/** Athena Algorithm execute */
StatusCode ISF::CollectionMerger::execute()
{
mergeCollections( m_inputBCMHits, m_outputBCMHits );
mergeCollections( m_inputBLMHits, m_outputBLMHits );
mergeCollections( m_inputPixelHits, m_outputPixelHits );
mergeCollections( m_inputSCTHits, m_outputSCTHits );
mergeCollections( m_inputTRTUncompressedHits, m_outputTRTUncompressedHits );
ATH_CHECK(mergeCollections( m_inputBCMHits, m_outputBCMHits ));
ATH_CHECK(mergeCollections( m_inputBLMHits, m_outputBLMHits ));
ATH_CHECK(mergeCollections( m_inputPixelHits, m_outputPixelHits ));
ATH_CHECK(mergeCollections( m_inputSCTHits, m_outputSCTHits ));
ATH_CHECK(mergeCollections( m_inputTRTUncompressedHits, m_outputTRTUncompressedHits ));
mergeCollections( m_inputLArEMBHits, m_outputLArEMBHits );
mergeCollections( m_inputLArEMECHits, m_outputLArEMECHits );
mergeCollections( m_inputLArFCALHits, m_outputLArFCALHits );
mergeCollections( m_inputLArHECHits, m_outputLArHECHits );
ATH_CHECK(mergeCollections( m_inputLArEMBHits, m_outputLArEMBHits ));
ATH_CHECK(mergeCollections( m_inputLArEMECHits, m_outputLArEMECHits ));
ATH_CHECK(mergeCollections( m_inputLArFCALHits, m_outputLArFCALHits ));
ATH_CHECK(mergeCollections( m_inputLArHECHits, m_outputLArHECHits ));
mergeCollections( m_inputTileHits, m_outputTileHits );
mergeCollections( m_inputMBTSHits, m_outputMBTSHits );
ATH_CHECK(mergeCollections( m_inputTileHits, m_outputTileHits ));
ATH_CHECK(mergeCollections( m_inputMBTSHits, m_outputMBTSHits ));
mergeCollections( m_inputCSCHits, m_outputCSCHits );
mergeCollections( m_inputMDTHits, m_outputMDTHits );
mergeCollections( m_inputRPCHits, m_outputRPCHits );
mergeCollections( m_inputTGCHits, m_outputTGCHits );
ATH_CHECK(mergeCollections( m_inputCSCHits, m_outputCSCHits ));
ATH_CHECK(mergeCollections( m_inputMDTHits, m_outputMDTHits ));
ATH_CHECK(mergeCollections( m_inputRPCHits, m_outputRPCHits ));
ATH_CHECK(mergeCollections( m_inputTGCHits, m_outputTGCHits ));
return StatusCode::SUCCESS;
}
......@@ -186,6 +186,6 @@ StatusCode ISF::CollectionMerger::finalize()
StatusCode ISF::CollectionMerger::initializeVarHandleKey( SG::VarHandleKey& varHandleKey ) const {
if ( varHandleKey.key().empty() )
return StatusCode::SUCCESS;
return varHandleKey.initialize();
}
......@@ -81,8 +81,17 @@ namespace ISF {
/** Merge all hits of inputReadHandleKeys's collections into outputWriteHandleKey */
template <typename T>
void mergeCollections( const ReadHandleKeyVector_t<T>& inputReadHandleKeys,
SG::WriteHandleKey<T>& outputWriteHandleKey ) const;
StatusCode mergeCollections( const ReadHandleKeyVector_t<T>& inputReadHandleKeys,
SG::WriteHandleKey<T>& outputWriteHandleKey ) const;
/** Copy the given hit into the given output collection, container or DataHandle */
template <typename HitType_t, typename OutputType_t>
void insertCopy(const HitType_t& hit, OutputType_t& outputHandle) const;
/** Copy the given const pointer to a hit into the given output collection,
container or DataHandle */
template <typename HitType_t, typename OutputType_t>
void insertCopy(HitType_t * const hit, OutputType_t& outputHandle) const;
/** Input collection StoreGate keys */
SGKeyVector_t m_inputBCMHitsSGKeys;
......@@ -145,7 +154,6 @@ namespace ISF {
SG::WriteHandleKey<TGCSimHitCollection> m_outputTGCHits;
};
}
//
// templated methods below
......@@ -175,28 +183,48 @@ StatusCode ISF::CollectionMerger::setupReadHandleKeyVector( const SGKeyVector_t&
/** Merge all hits of inputReadHandleKeys's collections into outputWriteHandleKey */
template <typename T>
void ISF::CollectionMerger::mergeCollections( const ReadHandleKeyVector_t<T>& inputReadHandleKeys,
SG::WriteHandleKey<T>& outputWriteHandleKey ) const {
inline StatusCode ISF::CollectionMerger::mergeCollections( const ReadHandleKeyVector_t<T>& inputReadHandleKeys,
SG::WriteHandleKey<T>& outputWriteHandleKey ) const {
// skip if not input collection
if ( inputReadHandleKeys.empty() ) {
return;
return StatusCode::SUCCESS;
}
// TODO: is there a way to conveniently get the total number of hits in all inputReadHandleKeys
// and reserve the corresponding size in the outputHandle
SG::WriteHandle<T> outputHandle{outputWriteHandleKey};
if (outputHandle.record( CxxUtils::make_unique<T>() ).isFailure()) {
return;
}
SG::WriteHandle<T> outputHandle{outputWriteHandleKey};
ATH_CHECK( outputHandle.record(std::make_unique<T>()) );
for ( const auto& collKey: inputReadHandleKeys ) {
SG::ReadHandle<T> inputHandle{collKey};
SG::ReadHandle<T> inputHandle{collKey};
for ( const auto& hit: *inputHandle ) {
// TODO: replace with ->Emplace(hit) once LArHitContainer supports this
outputHandle->push_back( hit );
this->insertCopy(hit, outputHandle);
}
}
return StatusCode::SUCCESS;
}
/** Copy the given hit into the given output collection, container or DataHandle */
template <typename HitType_t, typename OutputType_t>
inline void ISF::CollectionMerger::insertCopy(const HitType_t& hit,
OutputType_t& outputHandle) const {
static_assert(!std::is_pointer<HitType_t>::value,
"The hit provided to ISF::CollectionMerger::insertCopy(..) must not be a pointer!");
outputHandle->Emplace( hit );
}
/** Copy the given const pointer to a hit into the given output collection, container or DataHandle */
template <typename HitType_t, typename OutputType_t>
inline void ISF::CollectionMerger::insertCopy(HitType_t * const hit,
OutputType_t& outputHandle) const {
auto&& hitCopy = std::make_unique<HitType_t>(*hit);
outputHandle->push_back( hitCopy.release() );
}
}
#endif //> !ISF_ALGS_COLLECTIONMERGER_H
......@@ -31,14 +31,17 @@ namespace ISFTesting {
// needed every time an AthAlgorithm, AthAlgTool or AthService is instantiated
ISvcLocator* g_svcLoc = nullptr;
// mock object for sensitive detector hits
class TestHits {
// fake sensitive detector hits
class TestHit {
public:
TestHits(int value):m_value(value) { };
TestHit(int value):m_value(value) { };
int m_value;
};
// typedef for convenience
typedef AtlasHitsVector<ISFTesting::TestHits> TestHitCollection_t;
typedef AtlasHitsVector<ISFTesting::TestHit> TestHitCollection_t;
typedef AthenaHitsVector<ISFTesting::TestHit> TestPointerHitCollection_t;
// global test environment takes care of setting up Gaudi
......@@ -196,7 +199,7 @@ TEST_F(CollectionMerger_test, mergeCollections) {
ASSERT_TRUE( mergedCollectionHandle.isValid() );
ASSERT_EQ( mergedCollectionHandle->size(), 3+2+3 );
auto& mergedCollectionVector = mergedCollectionHandle->getVector();
const auto& mergedCollectionVector = mergedCollectionHandle->getVector();
ASSERT_EQ( mergedCollectionVector.at(0).m_value, 1 ); // inputCollectionA
ASSERT_EQ( mergedCollectionVector.at(1).m_value, 20 ); // inputCollectionA
ASSERT_EQ( mergedCollectionVector.at(2).m_value, 5 ); // inputCollectionA
......@@ -250,7 +253,7 @@ TEST_F(CollectionMerger_test, integration_with_data) {
ASSERT_TRUE( mergedCollectionHandle.isValid() );
ASSERT_EQ( mergedCollectionHandle->size(), 3+2+3 );
auto& mergedCollectionVector = mergedCollectionHandle->getVector();
const auto& mergedCollectionVector = mergedCollectionHandle->getVector();
ASSERT_EQ( mergedCollectionVector.at(0).trackNumber(), 1 ); // inputPixelCollectionIntegrationTestA
ASSERT_EQ( mergedCollectionVector.at(1).trackNumber(), 20 ); // inputPixelCollectionIntegrationTestA
ASSERT_EQ( mergedCollectionVector.at(2).trackNumber(), 5 ); // inputPixelCollectionIntegrationTestA
......@@ -262,10 +265,141 @@ TEST_F(CollectionMerger_test, integration_with_data) {
}
TEST_F(CollectionMerger_test, one_empty_one_filled_input_collection___expect_filled_output_collection) {
std::string inputPropertyValue = "['inputPixelCollectionIntegrationTestFilled',"
"'inputPixelCollectionIntegrationTestEmpty']";
std::string outputPropertyValue = "'outputPixelCollectionTestFilled'";
ASSERT_TRUE( m_alg->setProperty( "InputPixelHits", inputPropertyValue).isSuccess() );
ASSERT_TRUE( m_alg->setProperty( "OutputPixelHits", outputPropertyValue).isSuccess() );
// create dummy input collections containing dummy data
HepGeom::Point3D<double> pos(0.,0.,0.);
SG::WriteHandle<SiHitCollection> inputTestDataHandleFilled{"inputPixelCollectionIntegrationTestFilled"};
ASSERT_TRUE(inputTestDataHandleFilled.record(CxxUtils::make_unique<SiHitCollection>()).isSuccess());
inputTestDataHandleFilled->Emplace( pos, pos, 1., 1., 1, 0 );
inputTestDataHandleFilled->Emplace( pos, pos, 1., 1., 20, 0 );
inputTestDataHandleFilled->Emplace( pos, pos, 1., 1., 5, 0 );
SG::WriteHandle<SiHitCollection> inputTestDataHandleEmpty{"inputPixelCollectionIntegrationTestEmpty"};
ASSERT_TRUE(inputTestDataHandleEmpty.record(CxxUtils::make_unique<SiHitCollection>()).isSuccess());
ASSERT_TRUE( m_alg->initialize().isSuccess() );
ASSERT_TRUE( m_alg->execute().isSuccess() );
// test "outputPixelCollectionIntegrationTest" contents
SG::ReadHandleKey<SiHitCollection> mergedCollectionKey{"outputPixelCollectionTestFilled"};
ASSERT_TRUE( mergedCollectionKey.initialize().isSuccess() );
SG::ReadHandle<SiHitCollection> mergedCollectionHandle{mergedCollectionKey};
ASSERT_TRUE( mergedCollectionHandle.isValid() );
ASSERT_EQ( 3, mergedCollectionHandle->size() );
const auto& mergedCollectionVector = mergedCollectionHandle->getVector();
ASSERT_EQ( mergedCollectionVector.at(0).trackNumber(), 1 ); // inputPixelCollectionIntegrationTestA
ASSERT_EQ( mergedCollectionVector.at(1).trackNumber(), 20 ); // inputPixelCollectionIntegrationTestA
ASSERT_EQ( mergedCollectionVector.at(2).trackNumber(), 5 ); // inputPixelCollectionIntegrationTestA
}
TEST_F(CollectionMerger_test, preexisting_output_collection___expect_execute_isFailure) {
std::string inputPropertyValue = "['inputPixelCollectionTestX']";
std::string outputPropertyValue = "'outputPixelCollectionTestPreexisting'";
ASSERT_TRUE( m_alg->setProperty( "InputPixelHits", inputPropertyValue).isSuccess() );
ASSERT_TRUE( m_alg->setProperty( "OutputPixelHits", outputPropertyValue).isSuccess() );
// create dummy input collections containing dummy data
SG::WriteHandle<SiHitCollection> inputTestDataHandleA{"inputPixelCollectionTestX"};
ASSERT_TRUE( inputTestDataHandleA.record(CxxUtils::make_unique<SiHitCollection>()).isSuccess() );
// create pre-existing output collection
SG::WriteHandle<SiHitCollection> outputDataHandle{"outputPixelCollectionTestPreexisting"};
ASSERT_TRUE( outputDataHandle.record(CxxUtils::make_unique<SiHitCollection>()).isSuccess() );
ASSERT_TRUE( m_alg->initialize().isSuccess() );
ASSERT_TRUE( m_alg->execute().isFailure() );
}
TEST_F(CollectionMerger_test, nonexisting_input_collection___expect_SG_exception) {
std::string inputPropertyValue = "['inputPixelCollectionDoesntExist']";
std::string outputPropertyValue = "'outputPixelCollectionTest123'";
ASSERT_TRUE( m_alg->setProperty( "InputPixelHits", inputPropertyValue).isSuccess() );
ASSERT_TRUE( m_alg->setProperty( "OutputPixelHits", outputPropertyValue).isSuccess() );
ASSERT_TRUE( m_alg->initialize().isSuccess() );
ASSERT_THROW( m_alg->execute(), SG::ExcNullReadHandle );
}
TEST_F(CollectionMerger_test, mergeCollections_with_pointer_types___expect_merged_pointers_not_equal_to_input) {
std::vector<SG::ReadHandleKey<TestPointerHitCollection_t>> inputKeys{};
SG::WriteHandleKey<TestPointerHitCollection_t> outputKey{"outputPointerCollectionMergeTest"};
ASSERT_TRUE( outputKey.initialize().isSuccess() );
// create dummy input collections containing dummy data
auto inputTestDataA = CxxUtils::make_unique<TestPointerHitCollection_t>();
SG::WriteHandle<TestPointerHitCollection_t> inputTestDataHandleA{"inputPointerCollectionA"};
inputTestDataHandleA.record( std::move(inputTestDataA) );
auto* inputHitA1 = new ISFTesting::TestHit(1);
inputTestDataHandleA->push_back(inputHitA1);
auto* inputHitA2 = new ISFTesting::TestHit(20);
inputTestDataHandleA->push_back(inputHitA2);
auto* inputHitA3 = new ISFTesting::TestHit(5);
inputTestDataHandleA->push_back(inputHitA3);
auto inputTestDataB = CxxUtils::make_unique<TestPointerHitCollection_t>();
SG::WriteHandle<TestPointerHitCollection_t> inputTestDataHandleB{"inputPointerCollectionB"};
inputTestDataHandleB.record( std::move(inputTestDataB) );
auto* inputHitB1 = new ISFTesting::TestHit(50);
inputTestDataHandleB->push_back(inputHitB1);
auto* inputHitB2 = new ISFTesting::TestHit(1);
inputTestDataHandleB->push_back(inputHitB2);
// add inputCollections with test data to inputKeys for later merging
// ordering A, C, B is on purpose to test for unintended alphabetic ordering
inputKeys.emplace_back( "inputPointerCollectionA" );
inputKeys.emplace_back( "inputPointerCollectionB" );
ASSERT_TRUE( inputKeys.at(0).initialize().isSuccess() );
ASSERT_TRUE( inputKeys.at(1).initialize().isSuccess() );
// merge pointer collections
mergeCollections(inputKeys, outputKey);
// test "outputCollectionMergeTest" contents
SG::ReadHandleKey<TestPointerHitCollection_t> mergedCollectionKey{"outputPointerCollectionMergeTest"};
ASSERT_TRUE( mergedCollectionKey.initialize().isSuccess() );
SG::ReadHandle<TestPointerHitCollection_t> mergedCollectionHandle{mergedCollectionKey};
ASSERT_TRUE( mergedCollectionHandle.isValid() );
ASSERT_EQ( 3+2, mergedCollectionHandle->size() );
const auto* outputHit1 = (*mergedCollectionHandle)[0]; // inputPointerCollectionA
const auto* outputHit2 = (*mergedCollectionHandle)[1]; // inputPointerCollectionA
const auto* outputHit3 = (*mergedCollectionHandle)[2]; // inputPointerCollectionA
const auto* outputHit4 = (*mergedCollectionHandle)[3]; // inputPointerCollectionB
const auto* outputHit5 = (*mergedCollectionHandle)[4]; // inputPointerCollectionB
// check merged hit pointers are different from input (i.e. expect copies, not identities of input in output)
ASSERT_NE( inputHitA1, outputHit1 ); // inputPointerCollectionA
ASSERT_NE( inputHitA2, outputHit2 ); // inputPointerCollectionA
ASSERT_NE( inputHitA3, outputHit3 ); // inputPointerCollectionA
ASSERT_NE( inputHitB1, outputHit4 ); // inputPointerCollectionB
ASSERT_NE( inputHitB2, outputHit5 ); // inputPointerCollectionB
// check values of hits are copied
ASSERT_EQ( outputHit1->m_value, 1 ); // inputPointerCollectionA
ASSERT_EQ( outputHit2->m_value, 20 ); // inputPointerCollectionA
ASSERT_EQ( outputHit3->m_value, 5 ); // inputPointerCollectionA
ASSERT_EQ( outputHit4->m_value, 50 ); // inputPointerCollectionB
ASSERT_EQ( outputHit5->m_value, 1 ); // inputPointerCollectionB
}
} // <-- namespace ISFTesting
CLASS_DEF (ISFTesting::TestHitCollection_t, 1234567890, 1)
CLASS_DEF (ISFTesting::TestPointerHitCollection_t, 1234567891, 1)
int main(int argc, char *argv[])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment