diff --git a/Control/AthenaMonitoringKernel/AthenaMonitoringKernel/MonitoredScalar.h b/Control/AthenaMonitoringKernel/AthenaMonitoringKernel/MonitoredScalar.h index 42b97fddd449ed8beac5f2f431b83a448d3ffa3a..4a080d552ff971075f720a49b34e6a5997282442 100644 --- a/Control/AthenaMonitoringKernel/AthenaMonitoringKernel/MonitoredScalar.h +++ b/Control/AthenaMonitoringKernel/AthenaMonitoringKernel/MonitoredScalar.h @@ -49,8 +49,7 @@ namespace Monitored { */ Scalar(std::string name, const T& defaultValue = {}) : IMonitoredVariable(std::move(name)), - m_value(defaultValue), - m_valueTransform() + m_value(defaultValue) {} /** @@ -80,8 +79,6 @@ namespace Monitored { */ Scalar(std::string name, std::function<T()> generator) : IMonitoredVariable(std::move(name)), - m_value(0), - m_valueTransform(), m_valueGenerator( generator ) {} @@ -111,7 +108,7 @@ namespace Monitored { } std::vector<std::string> getStringVectorRepresentation() const override{ - return { convertToString( m_value ) }; + return { convertToString( m_value, m_valueGenerator ) }; } virtual bool hasStringRepresentation() const override { @@ -123,17 +120,19 @@ namespace Monitored { } private: - T m_value; + T m_value{}; std::function<double(const T&)> m_valueTransform; std::function<T()> m_valueGenerator; - template< typename U, typename = typename std::enable_if< std::is_constructible<std::string, U>::value >::type > - std::string convertToString( const U& value ) const { - return std::string{value}; + template< typename U, typename Generator, + typename = typename std::enable_if< std::is_constructible<std::string, U>::value >::type > + std::string convertToString( const U& value, Generator g ) const { + return ( g ? g() : value ); } - template< typename U, typename = typename std::enable_if< ! std::is_constructible<std::string, U>::value >::type, typename = void > - std::string convertToString( const U& ) const { + template< typename U, typename Generator, + typename = typename std::enable_if< ! std::is_constructible<std::string, U>::value >::type, typename = void > + std::string convertToString( const U&, Generator ) const { return ""; } diff --git a/Control/AthenaMonitoringKernel/test/GenericMonFilling_test.cxx b/Control/AthenaMonitoringKernel/test/GenericMonFilling_test.cxx index ac2a5e86fd3003490b290168b4daeeba17d3da2c..eef3b25efaf9001fd4ce7ec47d28a0828a07e0a7 100644 --- a/Control/AthenaMonitoringKernel/test/GenericMonFilling_test.cxx +++ b/Control/AthenaMonitoringKernel/test/GenericMonFilling_test.cxx @@ -52,6 +52,10 @@ TTree* getTree( ITHistSvc* histSvc, const std::string& treeName ) { void resetHist( ITHistSvc* histSvc, const std::string& histName ) { TH1* h ATLAS_THREAD_SAFE = const_cast<TH1*>(getHist( histSvc, histName )); h->Reset(); + THashList* labels = h->GetXaxis()->GetLabels(); + if (labels) labels->Clear(); + labels = h->GetYaxis()->GetLabels(); + if (labels) labels->Clear(); } void resetHists( ITHistSvc* histSvc ) { @@ -572,6 +576,26 @@ bool stringFilling(ToolHandle<GenericMonitoringTool>& monTool, ITHistSvc* histSv return true; } +bool stringFillingGen(ToolHandle<GenericMonitoringTool>& monTool, ITHistSvc* histSvc) { + + auto fill = [&]() { + auto det = Monitored::Scalar<std::string>( "DetID", [&](){return "SCT";} ); + Monitored::Group(monTool, det); + return 1; + }; + auto check = [&](size_t N) { + const TH1* h = getHist( histSvc, "/EXPERT/TestGroup/DetID" ); + VALUE( h->GetEntries() ) EXPECTED( N ); + VALUE( h->GetXaxis()->FindFixBin("SCT") ) EXPECTED( 1 ); + }; + + resetHists( histSvc ); check(fill()); + resetHists( histSvc ); check(fill_mt(fill)); + + return true; +} + + bool stringFromCollection(ToolHandle<GenericMonitoringTool>& monTool, ITHistSvc* histSvc) { auto fill = [&]() { @@ -716,6 +740,8 @@ int main() { assert( timerFilling( validMon, histSvc ) ); log << MSG::DEBUG << "stringFilling" << endmsg; assert( stringFilling( validMon, histSvc ) ); + log << MSG::DEBUG << "stringFillingGen" << endmsg; + assert( stringFillingGen( validMon, histSvc ) ); log << MSG::DEBUG << "string2DFilling" << endmsg; assert( string2DFilling( validMon, histSvc ) ); log << MSG::DEBUG << "stringFromCollection" << endmsg;