The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
Gaudi::Monitoring::Hub::Entity Class Reference

Wrapper class for arbitrary monitoring objects. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/Gaudi/MonitoringHub.h>

Collaboration diagram for Gaudi::Monitoring::Hub::Entity:

Public Member Functions

template<typename T>
 Entity (std::string component, std::string name, std::string type, T &ent)
std::type_index typeIndex () const
 function to get internal type
bool operator== (Entity const &ent) const
 operator== for comparison with an entity
void * id () const
 unique identifier, actually mapped to internal pointer

Public Attributes

std::string component
 name of the component owning the Entity
std::string name
 name of the entity
std::string type
 type of the entity, see comment above concerning its format and usage

Private Attributes

void * m_ptr { nullptr }
 pointer to the actual data inside this Entity
std::type_index m_typeIndex
nlohmann::json(* m_getJSON )(void const *)
 function converting the internal data to json.
void(* m_reset )(void *)
 function reseting internal data.
void(* m_mergeAndReset )(void *, void *)
 function calling merge and reset on internal data with the internal data of another entity

Friends

void to_json (nlohmann::json &j, Gaudi::Monitoring::Hub::Entity const &e)
 conversion to json via nlohmann library
void reset (Entity const &e)
 function resetting internal data
void mergeAndReset (Entity const &ent, Entity const &other)
 function calling merge and reset on internal data with the internal data of another entity

Detailed Description

Wrapper class for arbitrary monitoring objects.

Mainly contains a pointer to the actual data with component, name and type metadata Any object can be used as internal data and wrapped into an Entity as long as they can be translated to json format. It is enough to make them aware to the nlohmann library through a dedicated to_json method.

another 2 free functions can be overloaded to adapt the behavior of an Entity for a given type T :

  • void reset( T& t ) called to reset the entity. The default provided implementation is empty
  • void mergeAndReset( T& ent, T&& other ) called to merge other into entity and reset other. The default provided implementation is empty

Definition at line 62 of file MonitoringHub.h.

Constructor & Destructor Documentation

◆ Entity()

template<typename T>
Gaudi::Monitoring::Hub::Entity::Entity ( std::string component,
std::string name,
std::string type,
T & ent )
inline

Definition at line 65 of file MonitoringHub.h.

66 : component{ std::move( component ) }
67 , name{ std::move( name ) }
68 , type{ std::move( type ) }
69 , m_ptr{ &ent }
70 , m_typeIndex{ typeid( T ) }
71 , m_getJSON{ []( void const* ptr ) -> nlohmann::json { return *reinterpret_cast<const T*>( ptr ); } }
72 , m_reset{ []( void* ptr ) {
73 if constexpr ( details::has_reset_method_v<T> ) { reset( *reinterpret_cast<T*>( ptr ) ); }
74 } }
75 , m_mergeAndReset{ []( void* e, void* o ) {
77 mergeAndReset( *reinterpret_cast<T*>( e ), *reinterpret_cast<T*>( o ) );
78 }
79 } } {}
std::string component
name of the component owning the Entity
friend void mergeAndReset(Entity const &ent, Entity const &other)
function calling merge and reset on internal data with the internal data of another entity
nlohmann::json(* m_getJSON)(void const *)
function converting the internal data to json.
void(* m_mergeAndReset)(void *, void *)
function calling merge and reset on internal data with the internal data of another entity
void(* m_reset)(void *)
function reseting internal data.
std::string type
type of the entity, see comment above concerning its format and usage
void * m_ptr
pointer to the actual data inside this Entity
std::string name
name of the entity
friend void reset(Entity const &e)
function resetting internal data
constexpr bool has_mergeAndReset_method_v
constexpr bool has_reset_method_v

Member Function Documentation

◆ id()

void * Gaudi::Monitoring::Hub::Entity::id ( ) const
inline

unique identifier, actually mapped to internal pointer

Definition at line 110 of file MonitoringHub.h.

110{ return m_ptr; }

◆ operator==()

bool Gaudi::Monitoring::Hub::Entity::operator== ( Entity const & ent) const
inline

operator== for comparison with an entity

Definition at line 108 of file MonitoringHub.h.

108{ return id() == ent.id(); }
void * id() const
unique identifier, actually mapped to internal pointer

◆ typeIndex()

std::type_index Gaudi::Monitoring::Hub::Entity::typeIndex ( ) const
inline

function to get internal type

Definition at line 87 of file MonitoringHub.h.

87{ return m_typeIndex; }

◆ mergeAndReset

void mergeAndReset ( Entity const & ent,
Entity const & other )
friend

function calling merge and reset on internal data with the internal data of another entity

This function does not protect against usage with entities with different internal types The user should ensure that entities are compatible before calling this function

Definition at line 100 of file MonitoringHub.h.

100 {
101 if ( ent.typeIndex() != other.typeIndex() ) {
102 throw std::runtime_error( std::string( "Entity: mergeAndReset called on different types: " ) +
103 ent.typeIndex().name() + " and " + other.typeIndex().name() );
104 }
105 std::invoke( ent.m_mergeAndReset, ent.m_ptr, other.m_ptr );
106 }

◆ reset

void reset ( Entity const & e)
friend

function resetting internal data

Definition at line 93 of file MonitoringHub.h.

93{ std::invoke( e.m_reset, e.m_ptr ); }

◆ to_json

void to_json ( nlohmann::json & j,
Gaudi::Monitoring::Hub::Entity const & e )
friend

conversion to json via nlohmann library

Definition at line 89 of file MonitoringHub.h.

89 {
90 j = std::invoke( e.m_getJSON, e.m_ptr );
91 }

Member Data Documentation

◆ component

std::string Gaudi::Monitoring::Hub::Entity::component

name of the component owning the Entity

Definition at line 81 of file MonitoringHub.h.

◆ m_getJSON

nlohmann::json(* Gaudi::Monitoring::Hub::Entity::m_getJSON) (void const *)
private

function converting the internal data to json.

Definition at line 120 of file MonitoringHub.h.

◆ m_mergeAndReset

void(* Gaudi::Monitoring::Hub::Entity::m_mergeAndReset) (void *, void *)
private

function calling merge and reset on internal data with the internal data of another entity

Definition at line 124 of file MonitoringHub.h.

◆ m_ptr

void* Gaudi::Monitoring::Hub::Entity::m_ptr { nullptr }
private

pointer to the actual data inside this Entity

Definition at line 114 of file MonitoringHub.h.

114{ nullptr };

◆ m_reset

void(* Gaudi::Monitoring::Hub::Entity::m_reset) (void *)
private

function reseting internal data.

Definition at line 122 of file MonitoringHub.h.

◆ m_typeIndex

std::type_index Gaudi::Monitoring::Hub::Entity::m_typeIndex
private

Definition at line 118 of file MonitoringHub.h.

◆ name

std::string Gaudi::Monitoring::Hub::Entity::name

name of the entity

Definition at line 83 of file MonitoringHub.h.

◆ type

std::string Gaudi::Monitoring::Hub::Entity::type

type of the entity, see comment above concerning its format and usage

Definition at line 85 of file MonitoringHub.h.


The documentation for this class was generated from the following file: