Skip to content
Snippets Groups Projects
Commit daf3de22 authored by Gitlab CI's avatar Gitlab CI Committed by Sebastien Ponce
Browse files

pre-commit fixes

patch generated by https://gitlab.cern.ch/gaudi/Gaudi/-/jobs/17780880
parent a4262260
No related branches found
No related tags found
1 merge request!1278Better (and working) implementation of non mergeable objects in Sinks
Pipeline #3270830 passed
...@@ -28,23 +28,23 @@ namespace Gaudi::Monitoring { ...@@ -28,23 +28,23 @@ namespace Gaudi::Monitoring {
inline constexpr bool has_merge_and_reset_v = Gaudi::cpp17::is_detected_v<has_merge_and_reset_, T>; inline constexpr bool has_merge_and_reset_v = Gaudi::cpp17::is_detected_v<has_merge_and_reset_, T>;
struct MergeAndResetBase { struct MergeAndResetBase {
virtual ~MergeAndResetBase() = default; virtual ~MergeAndResetBase() = default;
virtual void operator()( void*, void* ) const = 0; virtual void operator()( void*, void* ) const = 0;
}; };
using MergeAndReset_t = void (*)(void*, void*); using MergeAndReset_t = void ( * )( void*, void* );
template <typename T> template <typename T>
MergeAndReset_t makeMergeAndResetFor() { MergeAndReset_t makeMergeAndResetFor() {
if constexpr ( has_merge_and_reset_v<T> ) { if constexpr ( has_merge_and_reset_v<T> ) {
return [](void *ptr, void* other) { return []( void* ptr, void* other ) {
reinterpret_cast<T*>( ptr )->mergeAndReset( std::move( *reinterpret_cast<T*>( other ) ) ); reinterpret_cast<T*>( ptr )->mergeAndReset( std::move( *reinterpret_cast<T*>( other ) ) );
}; };
} else { } else {
return [](void*,void*) { }; return []( void*, void* ) {};
} }
} }
} // namespace details } // namespace details
/// Central entity in a Gaudi application that manages monitoring objects (i.e. counters, histograms, etc.). /// Central entity in a Gaudi application that manages monitoring objects (i.e. counters, histograms, etc.).
...@@ -106,7 +106,7 @@ namespace Gaudi::Monitoring { ...@@ -106,7 +106,7 @@ namespace Gaudi::Monitoring {
/// function reseting internal data. /// function reseting internal data.
void ( *m_reset )( void* ); void ( *m_reset )( void* );
/// function calling merge and reset on internal data with the internal data of another entity /// function calling merge and reset on internal data with the internal data of another entity
details::MergeAndReset_t m_mergeAndReset{nullptr}; details::MergeAndReset_t m_mergeAndReset{ nullptr };
/// function converting the internal data to json. /// function converting the internal data to json.
json ( *m_getJSON )( const void* ); json ( *m_getJSON )( const void* );
}; };
......
...@@ -26,13 +26,13 @@ struct ServiceLocator { ...@@ -26,13 +26,13 @@ struct ServiceLocator {
struct Algo { struct Algo {
ServiceLocator* serviceLocator() { return &m_serviceLocator; } ServiceLocator* serviceLocator() { return &m_serviceLocator; }
std::string name() { return ""; } std::string name() { return ""; }
ServiceLocator m_serviceLocator{}; ServiceLocator m_serviceLocator{};
}; };
struct HistSink : public Gaudi::Monitoring::Hub::Sink { struct HistSink : public Gaudi::Monitoring::Hub::Sink {
virtual void registerEntity(Gaudi::Monitoring::Hub::Entity ent) override { m_entities.push_back(ent); } virtual void registerEntity( Gaudi::Monitoring::Hub::Entity ent ) override { m_entities.push_back( ent ); }
virtual void removeEntity(Gaudi::Monitoring::Hub::Entity const& ent) override { virtual void removeEntity( Gaudi::Monitoring::Hub::Entity const& ent ) override {
auto it = std::find(begin(m_entities), end(m_entities), ent); auto it = std::find( begin( m_entities ), end( m_entities ), ent );
if (it != m_entities.end()) m_entities.erase(it); if ( it != m_entities.end() ) m_entities.erase( it );
} }
std::deque<Gaudi::Monitoring::Hub::Entity> m_entities; std::deque<Gaudi::Monitoring::Hub::Entity> m_entities;
}; };
...@@ -120,37 +120,39 @@ BOOST_AUTO_TEST_CASE( test_custom_axis ) { ...@@ -120,37 +120,39 @@ BOOST_AUTO_TEST_CASE( test_custom_axis ) {
BOOST_AUTO_TEST_CASE( test_histos_merge_reset, *boost::unit_test::tolerance( 1e-14 ) ) { BOOST_AUTO_TEST_CASE( test_histos_merge_reset, *boost::unit_test::tolerance( 1e-14 ) ) {
using namespace Gaudi::Accumulators; using namespace Gaudi::Accumulators;
Algo algo; Algo algo;
HistSink histSink; HistSink histSink;
algo.serviceLocator()->monitoringHub().addSink(&histSink); algo.serviceLocator()->monitoringHub().addSink( &histSink );
Histogram<1, atomicity::full, float> hist1(&algo, "TestHist1", "Test histogram 1", Axis<float>{10, 0., 10.}); Histogram<1, atomicity::full, float> hist1( &algo, "TestHist1", "Test histogram 1", Axis<float>{ 10, 0., 10. } );
Histogram<1, atomicity::full, float> hist2(&algo, "TestHist2", "Test histogram 2", Axis<float>{10, 0., 10.}); Histogram<1, atomicity::full, float> hist2( &algo, "TestHist2", "Test histogram 2", Axis<float>{ 10, 0., 10. } );
// test all combinations of entities made (a) as part of the Histogram's constructor and (b) separately // test all combinations of entities made (a) as part of the Histogram's constructor and (b) separately
auto ent1a = histSink.m_entities[0]; auto ent1a = histSink.m_entities[0];
auto ent2a = histSink.m_entities[1]; auto ent2a = histSink.m_entities[1];
Gaudi::Monitoring::Hub::Entity ent1b("","TestHist1",std::string("histogram:Histogram:")+typeid(float).name(),hist1); Gaudi::Monitoring::Hub::Entity ent1b( "", "TestHist1", std::string( "histogram:Histogram:" ) + typeid( float ).name(),
Gaudi::Monitoring::Hub::Entity ent2b("","TestHist2",std::string("histogram:Histogram:")+typeid(float).name(),hist2); hist1 );
Gaudi::Monitoring::Hub::Entity ent2b( "", "TestHist2", std::string( "histogram:Histogram:" ) + typeid( float ).name(),
hist2 );
for ( int i=0; i<10; ++i) { for ( int i = 0; i < 10; ++i ) {
hist1[i] += i; hist1[i] += i;
hist2[i] += 2*i; hist2[i] += 2 * i;
} }
ent1a.mergeAndReset(ent2a); ent1a.mergeAndReset( ent2a );
BOOST_TEST(hist1.toJSON().at( "nEntries" ).get<unsigned long>() == 135); BOOST_TEST( hist1.toJSON().at( "nEntries" ).get<unsigned long>() == 135 );
BOOST_TEST(hist2.toJSON().at( "nEntries" ).get<unsigned long>() == 0); BOOST_TEST( hist2.toJSON().at( "nEntries" ).get<unsigned long>() == 0 );
ent2b.mergeAndReset(ent1b); ent2b.mergeAndReset( ent1b );
BOOST_TEST(hist1.toJSON().at( "nEntries" ).get<unsigned long>() == 0); BOOST_TEST( hist1.toJSON().at( "nEntries" ).get<unsigned long>() == 0 );
BOOST_TEST(hist2.toJSON().at( "nEntries" ).get<unsigned long>() == 135); BOOST_TEST( hist2.toJSON().at( "nEntries" ).get<unsigned long>() == 135 );
ent1a.mergeAndReset(ent2b); ent1a.mergeAndReset( ent2b );
BOOST_TEST(hist1.toJSON().at( "nEntries" ).get<unsigned long>() == 135); BOOST_TEST( hist1.toJSON().at( "nEntries" ).get<unsigned long>() == 135 );
BOOST_TEST(hist2.toJSON().at( "nEntries" ).get<unsigned long>() == 0); BOOST_TEST( hist2.toJSON().at( "nEntries" ).get<unsigned long>() == 0 );
ent2b.mergeAndReset(ent1a); ent2b.mergeAndReset( ent1a );
BOOST_TEST(hist1.toJSON().at( "nEntries" ).get<unsigned long>() == 0); BOOST_TEST( hist1.toJSON().at( "nEntries" ).get<unsigned long>() == 0 );
BOOST_TEST(hist2.toJSON().at( "nEntries" ).get<unsigned long>() == 135); BOOST_TEST( hist2.toJSON().at( "nEntries" ).get<unsigned long>() == 135 );
} }
BOOST_AUTO_TEST_CASE( test_2d_histos, *boost::unit_test::tolerance( 1e-14 ) ) { BOOST_AUTO_TEST_CASE( test_2d_histos, *boost::unit_test::tolerance( 1e-14 ) ) {
......
...@@ -25,57 +25,52 @@ struct ServiceLocator { ...@@ -25,57 +25,52 @@ struct ServiceLocator {
struct Algo { struct Algo {
ServiceLocator* serviceLocator() { return &m_serviceLocator; } ServiceLocator* serviceLocator() { return &m_serviceLocator; }
std::string name() { return ""; } std::string name() { return ""; }
ServiceLocator m_serviceLocator{}; ServiceLocator m_serviceLocator{};
}; };
// A class to be used in Entities and through the Sink/Hub machinery but // A class to be used in Entities and through the Sink/Hub machinery but
// not deriving from counters and with no mergeAndReset method // not deriving from counters and with no mergeAndReset method
// Basically accumulate data into a string // Basically accumulate data into a string
struct Store { struct Store {
std::string m_data; std::string m_data;
Gaudi::Monitoring::Hub* m_monitoringHub{nullptr}; Gaudi::Monitoring::Hub* m_monitoringHub{ nullptr };
template <typename OWNER> Store( OWNER* o, std::string const& name, const std::string storeType ) template <typename OWNER>
: m_monitoringHub( &o->serviceLocator()->monitoringHub() ) { Store( OWNER* o, std::string const& name, const std::string storeType )
: m_monitoringHub( &o->serviceLocator()->monitoringHub() ) {
m_monitoringHub->registerEntity( o->name(), name, storeType, *this ); m_monitoringHub->registerEntity( o->name(), name, storeType, *this );
} }
~Store() { m_monitoringHub->removeEntity( *this ); } ~Store() { m_monitoringHub->removeEntity( *this ); }
void reset() { m_data = ""; } void reset() { m_data = ""; }
void storeData( std::string const& data ) { m_data += data; } void storeData( std::string const& data ) { m_data += data; }
nlohmann::json toJSON() const { nlohmann::json toJSON() const { return m_data; }
return m_data;
}
}; };
// dummy Sink for the purpose of testing Hub and Sink with non mergeable items // dummy Sink for the purpose of testing Hub and Sink with non mergeable items
struct NonMergeableSink : public Gaudi::Monitoring::Hub::Sink { struct NonMergeableSink : public Gaudi::Monitoring::Hub::Sink {
virtual void registerEntity(Gaudi::Monitoring::Hub::Entity ent) override { virtual void registerEntity( Gaudi::Monitoring::Hub::Entity ent ) override { m_entities.push_back( ent ); }
m_entities.push_back(ent); virtual void removeEntity( Gaudi::Monitoring::Hub::Entity const& ent ) override {
} auto it = std::find( begin( m_entities ), end( m_entities ), ent );
virtual void removeEntity(Gaudi::Monitoring::Hub::Entity const& ent) override { if ( it != m_entities.end() ) m_entities.erase( it );
auto it = std::find(begin(m_entities), end(m_entities), ent);
if (it != m_entities.end()) m_entities.erase(it);
} }
std::deque<Gaudi::Monitoring::Hub::Entity> m_entities; std::deque<Gaudi::Monitoring::Hub::Entity> m_entities;
}; };
BOOST_AUTO_TEST_CASE( test_entity_no_merge_reset, *boost::unit_test::tolerance( 1e-14 ) ) { BOOST_AUTO_TEST_CASE( test_entity_no_merge_reset, *boost::unit_test::tolerance( 1e-14 ) ) {
Algo algo; Algo algo;
NonMergeableSink sink; NonMergeableSink sink;
algo.serviceLocator()->monitoringHub().addSink(&sink); algo.serviceLocator()->monitoringHub().addSink( &sink );
Store store1(&algo, "TestStore1", "store:test"); Store store1( &algo, "TestStore1", "store:test" );
Store store2(&algo, "TestStore2", "store:test"); Store store2( &algo, "TestStore2", "store:test" );
store1.storeData("Hel"); store1.storeData( "Hel" );
store1.storeData("lo "); store1.storeData( "lo " );
store2.storeData("World !"); store2.storeData( "World !" );
auto& entities = sink.m_entities; auto& entities = sink.m_entities;
std::sort( begin( entities ), end( entities ), []( const auto& a, const auto& b ) { return a.name < b.name; } ); std::sort( begin( entities ), end( entities ), []( const auto& a, const auto& b ) { return a.name < b.name; } );
std::string output; std::string output;
for (auto& ent : entities) { for ( auto& ent : entities ) { output += ent.toJSON().get<std::string>(); }
output += ent.toJSON().get<std::string>();
}
BOOST_TEST( output == "Hello World !" ); BOOST_TEST( output == "Hello World !" );
} }
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