diff --git a/Tracking/TrkTools/TrkTrackSummaryTool/CMakeLists.txt b/Tracking/TrkTools/TrkTrackSummaryTool/CMakeLists.txt index f7c99f2a718722c8abd55c11d14a218c6a4b3acf..3535e938d9dd82822ad5c61d1361863ea5fb5ffc 100644 --- a/Tracking/TrkTools/TrkTrackSummaryTool/CMakeLists.txt +++ b/Tracking/TrkTools/TrkTrackSummaryTool/CMakeLists.txt @@ -7,7 +7,17 @@ atlas_subdir( TrkTrackSummaryTool ) atlas_add_component( TrkTrackSummaryTool src/*.cxx src/components/*.cxx - LINK_LIBRARIES AthenaBaseComps GaudiKernel TrkParameters TrkTrackSummary TrkToolInterfaces AtlasDetDescr Identifier TrkDetElementBase TrkGeometry TrkCompetingRIOsOnTrack TrkEventPrimitives TrkMeasurementBase TrkRIO_OnTrack TrkTrack TRT_ElectronPidToolsLib ) + LINK_LIBRARIES AthenaBaseComps GaudiKernel TrkTrackSummary TrkToolInterfaces AtlasDetDescr Identifier TrkDetElementBase TrkGeometry TrkCompetingRIOsOnTrack TrkEventPrimitives TrkMeasurementBase TrkRIO_OnTrack TrkTrack TRT_ElectronPidToolsLib ) + + +atlas_add_test(TrackSummaryTool_test + SOURCES test/TrackSummaryTool_test.cxx + INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} + LINK_LIBRARIES ${Boost_LIBRARIES} ${ROOT_LIBRARIES} AthenaBaseComps GaudiKernel IdDictParser StoreGateLib TrkToolInterfaces AtlasDetDescr Identifier TrkDetElementBase TrkGeometry TrkCompetingRIOsOnTrack TrkEventPrimitives TrkMeasurementBase TrkRIO_OnTrack TrkTrack TRT_ElectronPidToolsLib + POST_EXEC_SCRIPT "nopost.sh" ) + +# Install files from the package: +atlas_install_joboptions( share/*.txt ) # Install files from the package: atlas_install_python_modules( python/*.py POST_BUILD_CMD ${ATLAS_FLAKE8} ) diff --git a/Tracking/TrkTools/TrkTrackSummaryTool/share/TrackSummaryTool_test.txt b/Tracking/TrkTools/TrkTrackSummaryTool/share/TrackSummaryTool_test.txt new file mode 100644 index 0000000000000000000000000000000000000000..50845d9e77c3389d21def868c360960c90ae061d --- /dev/null +++ b/Tracking/TrkTools/TrkTrackSummaryTool/share/TrackSummaryTool_test.txt @@ -0,0 +1,8 @@ +EventDataSvc.ForceLeaves = true; +EventDataSvc.RootCLID = 1; +ApplicationMgr.Dlls += { "AthenaServices" }; +ApplicationMgr.ExtSvc = {"StoreGateSvc"}; +ApplicationMgr.EvtMax = 1; +ApplicationMgr.EvtSel = "TestEvtSelector"; +ApplicationMgr.HistogramPersistency = "NONE"; +MessageSvc.OutputLevel = 5; diff --git a/Tracking/TrkTools/TrkTrackSummaryTool/share/TrackSummaryUpdater_test.txt b/Tracking/TrkTools/TrkTrackSummaryTool/share/TrackSummaryUpdater_test.txt new file mode 100644 index 0000000000000000000000000000000000000000..77d6b87f291234c46480cabefe4d83f06d6a15d6 --- /dev/null +++ b/Tracking/TrkTools/TrkTrackSummaryTool/share/TrackSummaryUpdater_test.txt @@ -0,0 +1,8 @@ +EventDataSvc.ForceLeaves = true; +EventDataSvc.RootCLID = 1; +ApplicationMgr.Dlls += { "AthenaServices", "StoreGate" }; +ApplicationMgr.ExtSvc = {"StoreGateSvc", "StoreGateSvc/DetectorStore"}; +ApplicationMgr.EvtMax = 1; +ApplicationMgr.EvtSel = "TestEvtSelector"; +ApplicationMgr.HistogramPersistency = "NONE"; +MessageSvc.OutputLevel = 3; diff --git a/Tracking/TrkTools/TrkTrackSummaryTool/src/TrackSummaryTool.cxx b/Tracking/TrkTools/TrkTrackSummaryTool/src/TrackSummaryTool.cxx index e86b1766abd7e7dc9c98b97af0c4be7375ec302a..99a7a8c445f952d10e1973cf022a4c95ac1a156b 100755 --- a/Tracking/TrkTools/TrkTrackSummaryTool/src/TrackSummaryTool.cxx +++ b/Tracking/TrkTools/TrkTrackSummaryTool/src/TrackSummaryTool.cxx @@ -66,8 +66,7 @@ StatusCode Trk::TrackSummaryTool::initialize(){ ATH_CHECK( detStore()->retrieve(m_detID, "AtlasID" )); if (m_idTool.empty() && m_muonTool.empty()) { - ATH_MSG_ERROR ("Could get neither InDetHelperTool nor MuonHelperTool. Must abort."); - return StatusCode::FAILURE; + ATH_MSG_WARNING ("Could get neither InDetHelperTool nor MuonHelperTool."); } if (not m_idTool.empty()) ATH_CHECK(m_idTool.retrieve()); if (not m_eProbabilityTool.empty()) ATH_CHECK(m_eProbabilityTool.retrieve()); @@ -305,7 +304,9 @@ Trk::TrackSummaryTool::updateSharedHitCount( TrackSummary& summary) const { // first check if track has no summary - then it is recreated - m_idTool->updateSharedHitCount(track, prdToTrackMap, summary); + if (m_idTool){ + m_idTool->updateSharedHitCount(track, prdToTrackMap, summary); + } } void @@ -330,10 +331,12 @@ Trk::TrackSummaryTool::updateAdditionalInfo(const Track& track, if (track.info().trackFitter() != TrackInfo::Unknown && !m_dedxtool.empty()) { dedx = m_dedxtool->dEdx(track, nHitsUsed_dEdx, nOverflowHits_dEdx); } - m_idTool->updateAdditionalInfo(summary, eProbability,dedx, nHitsUsed_dEdx,nOverflowHits_dEdx); - m_idTool->updateExpectedHitInfo(track, summary); - if (m_addInDetDetailedSummary) { - m_idTool->addDetailedTrackSummary(track,summary); + if (m_idTool){ + m_idTool->updateAdditionalInfo(summary, eProbability,dedx, nHitsUsed_dEdx,nOverflowHits_dEdx); + m_idTool->updateExpectedHitInfo(track, summary); + if (m_addInDetDetailedSummary) m_idTool->addDetailedTrackSummary(track,summary); + } else { + ATH_MSG_INFO("No updates attempted, as the SummaryHelperTool is not defined."); } } diff --git a/Tracking/TrkTools/TrkTrackSummaryTool/test/TrackSummaryTool_test.cxx b/Tracking/TrkTools/TrkTrackSummaryTool/test/TrackSummaryTool_test.cxx new file mode 100644 index 0000000000000000000000000000000000000000..437c700d56fb93c636940533e382bb81712b1afc --- /dev/null +++ b/Tracking/TrkTools/TrkTrackSummaryTool/test/TrackSummaryTool_test.cxx @@ -0,0 +1,150 @@ +/* + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration +*/ +/* + */ +/** + * @file TrkTrackSummaryUpdater/test/TrackSummaryUpdater_test.cxx + * @author Shaun Roe + * @date Dec, 2020 + * @brief Some tests for TrackSummaryTool algorithm in the Boost framework + */ + + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MAIN +#define BOOST_TEST_MODULE TEST_TRKTRACKSUMMARYTOOL +// +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Woverloaded-virtual" +#include <boost/test/unit_test.hpp> + +#pragma GCC diagnostic pop + +// +#include "GaudiKernel/ISvcLocator.h" +#include "StoreGate/StoreGateSvc.h" +#include "CxxUtils/checker_macros.h" +#include "TInterpreter.h" +// +#include "GaudiKernel/IAppMgrUI.h" +#include "GaudiKernel/SmartIF.h" +#include "GaudiKernel/EventContext.h" +#include "AthenaBaseComps/AthAlgTool.h" +#include "CxxUtils/ubsan_suppress.h" +#include "IdDictParser/IdDictParser.h" +#include "AtlasDetDescr/AtlasDetectorID.h" + +#include "TrkTrackSummaryTool/TrackSummaryTool.h" +ATLAS_NO_CHECK_FILE_THREAD_SAFETY; // This test uses global svcLoc. + +// Gaudi fixture +class GaudiFixture { + public: + ISvcLocator * + svcLoc(){ + return m_svcLoc; + } + + IToolSvc * + toolSvc(){ + return m_toolSvc; + } + + StoreGateSvc* + storeGateSvc(){ + return m_sg; + } + StoreGateSvc* + detStore(){ + return m_detStore; + } + + GaudiFixture(const std::string & joPath = "TrkTrackSummaryUpdater/TrackSummaryUpdater_test.txt") { + setUpGaudi(joPath); + } + + ~GaudiFixture() { + tearDownGaudi(); + } + + private: + void + setUpGaudi(const std::string & joPath) { + CxxUtils::ubsan_suppress ([]() { TInterpreter::Instance(); } ); + m_appMgr = Gaudi::createApplicationMgr(); + m_svcLoc = m_appMgr; + m_svcMgr = m_appMgr; + m_propMgr = m_appMgr; + m_propMgr->setProperty( "EvtSel", "NONE" ).ignore() ; + m_propMgr->setProperty( "JobOptionsType", "FILE" ).ignore(); + m_propMgr->setProperty( "JobOptionsPath", joPath ).ignore(); + m_toolSvc = m_svcLoc->service("ToolSvc"); + m_appMgr->configure().ignore(); + m_appMgr->initialize().ignore(); + m_sg = nullptr; + m_svcLoc->service ("StoreGateSvc", m_sg).ignore(); + m_svcLoc->service ("StoreGateSvc/DetectorStore", m_detStore).ignore(); + } + + void + tearDownGaudi() { + m_svcMgr->finalize().ignore(); + m_appMgr->finalize().ignore(); + m_appMgr->terminate().ignore(); + m_svcLoc->release(); + m_svcMgr->release(); + Gaudi::setInstance( static_cast<IAppMgrUI*>(nullptr) ); + } + + StoreGateSvc* + evtStore(){ + return m_sg; + } + + //member variables for Core Gaudi components + IAppMgrUI* m_appMgr{nullptr}; + SmartIF<ISvcLocator> m_svcLoc; + SmartIF<ISvcManager> m_svcMgr; + SmartIF<IToolSvc> m_toolSvc; + SmartIF<IProperty> m_propMgr; + StoreGateSvc* m_sg{ nullptr }; + StoreGateSvc * m_detStore{nullptr}; + }; + +BOOST_AUTO_TEST_SUITE(TrackSummaryUpdaterTest) + + GaudiFixture g("TrkTrackSummaryTool/TrackSummaryTool_test.txt"); + auto pSvcLoc=g.svcLoc(); + auto pToolSvc=g.toolSvc(); + auto pDetStore=g.detStore(); + IAlgTool* pToolInterface{}; + + BOOST_AUTO_TEST_CASE( sanityCheck ){ + const bool svcLocatorIsOk=(pSvcLoc != nullptr); + BOOST_TEST(svcLocatorIsOk); + const bool toolSvcIsOk = ( pToolSvc != nullptr); + BOOST_TEST(toolSvcIsOk); + const bool detStoreIsOk = (pDetStore != nullptr); + BOOST_TEST(detStoreIsOk); + } + + BOOST_AUTO_TEST_CASE(retrieveTool){ + static IdDictParser parser; + parser.register_external_entity ("InnerDetector","IdDictInnerDetector.xml"); + parser.register_external_entity ("MuonSpectrometer","IdDictMuonSpectrometer_S.02.xml"); + parser.register_external_entity ("Calorimeter","IdDictCalorimeter_L1Onl.xml"); + IdDictMgr& idDict = parser.parse ("IdDictParser/ATLAS_IDS.xml"); + auto atlasId = std::make_unique<AtlasDetectorID>(); + atlasId->initialize_from_dictionary (idDict); + if (pDetStore and (not pDetStore->contains<AtlasDetectorID>("AtlasID"))) { + BOOST_TEST ( pDetStore->record (std::move (atlasId), "AtlasID").isSuccess() ); + } + BOOST_TEST ( pToolSvc->retrieveTool("Trk::TrackSummaryTool", pToolInterface).isSuccess()); + BOOST_TEST(pToolInterface -> initialize()); + } + + +BOOST_AUTO_TEST_SUITE_END() + +