diff --git a/Alignment/AlignTrTools/CMakeLists.txt b/Alignment/AlignTrTools/CMakeLists.txt index b672f6c7bdf85aa95a806fff4dcd74c369460ebd..98c0a49e88b8ea004f128d3ee301bb48f7f2099d 100644 --- a/Alignment/AlignTrTools/CMakeLists.txt +++ b/Alignment/AlignTrTools/CMakeLists.txt @@ -26,6 +26,7 @@ gaudi_add_module(AlignTrTools src/TrackParticleRefitter.cpp src/TrackToParticleRelinker.cpp src/AlignTrackCloneRemover.cpp + src/ResettingSink.cpp LINK Alignment::AlignmentInterfacesLib Boost::headers @@ -49,3 +50,13 @@ gaudi_add_module(AlignTrTools Rec::TrackInterfacesLib Rec::TrackKernel ) + +gaudi_add_module(AlignTrToolsTests + SOURCES + tests/src/HistogramTests.cpp + LINK + Gaudi::GaudiAlgLib + Gaudi::GaudiKernel +) + +gaudi_add_tests(QMTest) diff --git a/Alignment/AlignTrTools/src/ResettingSink.cpp b/Alignment/AlignTrTools/src/ResettingSink.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e442c81c37b4b4d408d6492440fcd1f7019188db --- /dev/null +++ b/Alignment/AlignTrTools/src/ResettingSink.cpp @@ -0,0 +1,32 @@ +/***********************************************************************************\ +* (c) Copyright 2022 CERN for the benefit of the LHCb and ATLAS collaborations * +* * +* This software is distributed under the terms of the Apache version 2 licence, * +* copied verbatim in the file "LICENSE". * +* * +* In applying this licence, CERN does not waive the privileges and immunities * +* granted to it by virtue of its status as an Intergovernmental Organization * +* or submit itself to any jurisdiction. * +\***********************************************************************************/ + +#include <Gaudi/BaseSink.h> + +namespace LHCb::Alignment { + + class ResettingSink : public Gaudi::Monitoring::BaseSink { + + public: + using BaseSink::BaseSink; + + StatusCode start() override { + return BaseSink::start().andThen( [&]() { + applyToAllEntities( []( auto& ent ) { reset( ent ); } ); + return StatusCode::SUCCESS; + } ); + } + void flush( bool ) override {} + }; + + DECLARE_COMPONENT( ResettingSink ) + +} // namespace LHCb::Alignment diff --git a/Alignment/AlignTrTools/tests/options/histo_noreset_on_stop.py b/Alignment/AlignTrTools/tests/options/histo_noreset_on_stop.py new file mode 100644 index 0000000000000000000000000000000000000000..321f4b5381667695564d87651688edec7064222f --- /dev/null +++ b/Alignment/AlignTrTools/tests/options/histo_noreset_on_stop.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +############################################################################### +# (c) Copyright 2000-2021 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### + +from Configurables import ApplicationMgr +from Configurables import Alignment__Tests__Histograms__BasicSink as BasicSink + +basicSink = BasicSink() +app = ApplicationMgr( + EvtSel="NONE", + TopAlg=["Alignment::Tests::Histograms::TestHistoAlg"], + ExtSvc=[basicSink], +) + +from GaudiPython.Bindings import AppMgr + +appMgr = AppMgr() +appMgr.run(1) +appMgr.stop() +appMgr.run(1) +appMgr.exit() diff --git a/Alignment/AlignTrTools/tests/options/histo_reset_on_stop.py b/Alignment/AlignTrTools/tests/options/histo_reset_on_stop.py new file mode 100644 index 0000000000000000000000000000000000000000..c3650eec0757df01079b1d24718ce7dd8d461287 --- /dev/null +++ b/Alignment/AlignTrTools/tests/options/histo_reset_on_stop.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +############################################################################### +# (c) Copyright 2000-2021 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### + +from Configurables import ApplicationMgr +from Configurables import Alignment__Tests__Histograms__BasicSink as BasicSink, LHCb__Alignment__ResettingSink as ResettingSink + +basicSink = BasicSink() +resettingSink = ResettingSink() +app = ApplicationMgr( + EvtSel="NONE", + TopAlg=["Alignment::Tests::Histograms::TestHistoAlg"], + ExtSvc=[basicSink, resettingSink], +) + +from GaudiPython.Bindings import AppMgr + +appMgr = AppMgr() +appMgr.run(1) +appMgr.stop() +appMgr.run(1) +appMgr.exit() diff --git a/Alignment/AlignTrTools/tests/qmtest/histo_noreset_on_stop.qmt b/Alignment/AlignTrTools/tests/qmtest/histo_noreset_on_stop.qmt new file mode 100644 index 0000000000000000000000000000000000000000..acaf5d7602cab6c41e8e90821f9f121adeb490c6 --- /dev/null +++ b/Alignment/AlignTrTools/tests/qmtest/histo_noreset_on_stop.qmt @@ -0,0 +1,19 @@ +<?xml version="1.0" ?><!DOCTYPE extension PUBLIC '-//QM/2.3/Extension//EN' 'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'> +<!-- + (c) Copyright 2021 CERN for the benefit of the LHCb and ATLAS collaborations + + This software is distributed under the terms of the Apache version 2 licence, + copied verbatim in the file "LICENSE". + + In applying this licence, CERN does not waive the privileges and immunities + granted to it by virtue of its status as an Intergovernmental Organization + or submit itself to any jurisdiction. +--> +<extension class="GaudiTest.GaudiExeTest" kind="test"> +<argument name="program"><text>python</text></argument> +<argument name="args"><set><text>../options/histo_noreset_on_stop.py</text></set></argument> +<argument name="reference"><text>../refs/histo_noreset_on_stop.ref</text></argument> +<argument name="validator"><text> +validateWithReference() +</text></argument> +</extension> diff --git a/Alignment/AlignTrTools/tests/qmtest/histo_reset_on_stop.qmt b/Alignment/AlignTrTools/tests/qmtest/histo_reset_on_stop.qmt new file mode 100644 index 0000000000000000000000000000000000000000..06ca6dc0abc2492ced282d708d60e38250b10552 --- /dev/null +++ b/Alignment/AlignTrTools/tests/qmtest/histo_reset_on_stop.qmt @@ -0,0 +1,19 @@ +<?xml version="1.0" ?><!DOCTYPE extension PUBLIC '-//QM/2.3/Extension//EN' 'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'> +<!-- + (c) Copyright 2021 CERN for the benefit of the LHCb and ATLAS collaborations + + This software is distributed under the terms of the Apache version 2 licence, + copied verbatim in the file "LICENSE". + + In applying this licence, CERN does not waive the privileges and immunities + granted to it by virtue of its status as an Intergovernmental Organization + or submit itself to any jurisdiction. +--> +<extension class="GaudiTest.GaudiExeTest" kind="test"> +<argument name="program"><text>python</text></argument> +<argument name="args"><set><text>../options/histo_reset_on_stop.py</text></set></argument> +<argument name="reference"><text>../refs/histo_reset_on_stop.ref</text></argument> +<argument name="validator"><text> +validateWithReference() +</text></argument> +</extension> diff --git a/Alignment/AlignTrTools/tests/refs/histo_noreset_on_stop.ref b/Alignment/AlignTrTools/tests/refs/histo_noreset_on_stop.ref new file mode 100644 index 0000000000000000000000000000000000000000..6bb5a324ac15a286617f7ede775c79238e0780a9 --- /dev/null +++ b/Alignment/AlignTrTools/tests/refs/histo_noreset_on_stop.ref @@ -0,0 +1,23 @@ +# setting LC_ALL to "C" +ApplicationMgr SUCCESS +==================================================================================================================================== + Welcome to ApplicationMgr (GaudiCoreSvc v38r1) + running on lblhcbpr11.cern.ch on Fri Feb 9 11:37:04 2024 +==================================================================================================================================== +ApplicationMgr INFO Application Manager Configured successfully +EventLoopMgr WARNING Unable to locate service "EventSelector" +EventLoopMgr WARNING No events will be processed from external input. +ApplicationMgr INFO Application Manager Initialized successfully +JobOptionsSvc INFO Properties are dumped into "histo_noreset_on_stop.joboptsdump" +ApplicationMgr INFO Application Manager Started successfully +[{"axis":[{"maxValue":1.0,"minValue":0.0,"nBins":1,"title":""}],"bins":[0,1,0],"dimension":1,"empty":false,"nEntries":1,"title":"Histo title","type":"histogram:Histogram:d"}] +[{"empty":false,"nEntries":1,"type":"counter:Counter:m"}] +ApplicationMgr INFO Application Manager Stopped successfully +JobOptionsSvc INFO Properties are dumped into "histo_noreset_on_stop.joboptsdump" +ApplicationMgr INFO Application Manager Started successfully +[{"axis":[{"maxValue":1.0,"minValue":0.0,"nBins":1,"title":""}],"bins":[0,2,0],"dimension":1,"empty":false,"nEntries":2,"title":"Histo title","type":"histogram:Histogram:d"}] +[{"empty":false,"nEntries":2,"type":"counter:Counter:m"}] +ApplicationMgr INFO Application Manager Stopped successfully +EventLoopMgr INFO Histograms converted successfully according to request. +ApplicationMgr INFO Application Manager Finalized successfully +ApplicationMgr INFO Application Manager Terminated successfully diff --git a/Alignment/AlignTrTools/tests/refs/histo_reset_on_stop.ref b/Alignment/AlignTrTools/tests/refs/histo_reset_on_stop.ref new file mode 100644 index 0000000000000000000000000000000000000000..29cab404d39823cc44ec10f30c8ed00409f3eb16 --- /dev/null +++ b/Alignment/AlignTrTools/tests/refs/histo_reset_on_stop.ref @@ -0,0 +1,23 @@ +# setting LC_ALL to "C" +ApplicationMgr SUCCESS +==================================================================================================================================== + Welcome to ApplicationMgr (GaudiCoreSvc v38r1) + running on lblhcbpr11.cern.ch on Mon Feb 12 11:28:01 2024 +==================================================================================================================================== +ApplicationMgr INFO Application Manager Configured successfully +EventLoopMgr WARNING Unable to locate service "EventSelector" +EventLoopMgr WARNING No events will be processed from external input. +ApplicationMgr INFO Application Manager Initialized successfully +JobOptionsSvc INFO Properties are dumped into "histo_reset_on_stop.joboptsdump" +ApplicationMgr INFO Application Manager Started successfully +[{"axis":[{"maxValue":1.0,"minValue":0.0,"nBins":1,"title":""}],"bins":[0,1,0],"dimension":1,"empty":false,"nEntries":1,"title":"Histo title","type":"histogram:Histogram:d"}] +[{"empty":false,"nEntries":1,"type":"counter:Counter:m"}] +ApplicationMgr INFO Application Manager Stopped successfully +JobOptionsSvc INFO Properties are dumped into "histo_reset_on_stop.joboptsdump" +ApplicationMgr INFO Application Manager Started successfully +[{"axis":[{"maxValue":1.0,"minValue":0.0,"nBins":1,"title":""}],"bins":[0,1,0],"dimension":1,"empty":false,"nEntries":1,"title":"Histo title","type":"histogram:Histogram:d"}] +[{"empty":false,"nEntries":1,"type":"counter:Counter:m"}] +ApplicationMgr INFO Application Manager Stopped successfully +EventLoopMgr INFO Histograms converted successfully according to request. +ApplicationMgr INFO Application Manager Finalized successfully +ApplicationMgr INFO Application Manager Terminated successfully diff --git a/Alignment/AlignTrTools/tests/src/HistogramTests.cpp b/Alignment/AlignTrTools/tests/src/HistogramTests.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2cc065f1ab3528b744d51d1d790dfd335c977cf1 --- /dev/null +++ b/Alignment/AlignTrTools/tests/src/HistogramTests.cpp @@ -0,0 +1,39 @@ +/***********************************************************************************\ +* (c) Copyright 2021 CERN for the benefit of the LHCb and ATLAS collaborations * +* * +* This software is distributed under the terms of the Apache version 2 licence, * +* copied verbatim in the file "LICENSE". * +* * +* In applying this licence, CERN does not waive the privileges and immunities * +* granted to it by virtue of its status as an Intergovernmental Organization * +* or submit itself to any jurisdiction. * +\***********************************************************************************/ +#include <Gaudi/Accumulators.h> +#include <Gaudi/Accumulators/Histogram.h> +#include <Gaudi/BaseSink.h> +#include <GaudiAlg/Consumer.h> + +namespace Alignment::Tests::Histograms { + + // simple algo with one histo and one counter + struct TestHistoAlg : Gaudi::Functional::Consumer<void()> { + using Consumer::Consumer; + mutable Gaudi::Accumulators::Histogram<1> m_hist{this, "Histo", "Histo title", {1, 0, 1}}; + mutable Gaudi::Accumulators::Counter<> m_counterhist{this, "Counter"}; + void operator()() const override { + ++m_hist[0.5]; + ++m_counterhist; + } + }; + DECLARE_COMPONENT( TestHistoAlg ) + + // simple Sink printing every entity to stdout + struct BasicSink : Gaudi::Monitoring::BaseSink { + using BaseSink::BaseSink; + void flush( bool ) override { + applyToAllEntities( []( auto& ent ) { std::cout << nlohmann::json{ent} << "\n"; } ); + } + }; + DECLARE_COMPONENT( BasicSink ) + +} // namespace Alignment::Tests::Histograms