The Gaudi Framework  v37r0 (b608885e)
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 More...
 
bool operator== (void *ent)
 operator== for comparison with raw pointer More...
 
bool operator== (Entity const &ent)
 operator== for comparison with an entity More...
 
void * id () const
 unique identifier, actually mapped to internal pointer More...
 

Public Attributes

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

Private Attributes

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

Friends

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

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 100 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 103 of file MonitoringHub.h.

105  , name{ std::move( name ) }
106  , type{ std::move( type ) }
107  , m_ptr{ &ent }
108  , m_typeIndex{ []( const void* ptr ) {
109  return std::type_index( typeid( *reinterpret_cast<const T*>( ptr ) ) );
110  } }
111  , m_getJSON{ []( Entity const& e ) -> nlohmann::json { return *reinterpret_cast<const T*>( e.m_ptr ); } }
112  , m_reset{ []( Entity& e ) { reset( *reinterpret_cast<T*>( e.m_ptr ) ); } }
113  , m_mergeAndReset{ []( Entity& e, Entity& o ) {
114  mergeAndReset( *reinterpret_cast<T*>( e.m_ptr ), *reinterpret_cast<T*>( o.m_ptr ) );
115  } } {}

Member Function Documentation

◆ id()

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

unique identifier, actually mapped to internal pointer

Definition at line 146 of file MonitoringHub.h.

146 { return m_ptr; }

◆ operator==() [1/2]

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

operator== for comparison with an entity

Definition at line 144 of file MonitoringHub.h.

144 { return m_ptr == ent.m_ptr; }

◆ operator==() [2/2]

bool Gaudi::Monitoring::Hub::Entity::operator== ( void *  ent)
inline

operator== for comparison with raw pointer

Definition at line 142 of file MonitoringHub.h.

142 { return m_ptr == ent; }

◆ typeIndex()

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

function to get internal type

Definition at line 123 of file MonitoringHub.h.

123 { return ( *m_typeIndex )( m_ptr ); }

Friends And Related Function Documentation

◆ mergeAndReset

void mergeAndReset ( Entity ent,
Entity 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 134 of file MonitoringHub.h.

134  {
135  if ( ent.typeIndex() != other.typeIndex() ) {
136  throw std::runtime_error( std::string( "Entity: mergeAndReset called on different types: " ) +
137  ent.typeIndex().name() + " and " + other.typeIndex().name() );
138  }
139  ( *ent.m_mergeAndReset )( ent, other );
140  }

◆ reset

void reset ( Entity e)
friend

function resetting internal data

Definition at line 127 of file MonitoringHub.h.

127 { ( *e.m_reset )( e ); }

◆ to_json

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

conversion to json via nlohmann library

Definition at line 125 of file MonitoringHub.h.

125 { j = ( *e.m_getJSON )( e ); }

Member Data Documentation

◆ component

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

name of the component owning the Entity

Definition at line 117 of file MonitoringHub.h.

◆ m_getJSON

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

function converting the internal data to json.

Definition at line 157 of file MonitoringHub.h.

◆ m_mergeAndReset

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

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

Definition at line 161 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 150 of file MonitoringHub.h.

◆ m_reset

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

function reseting internal data.

Definition at line 159 of file MonitoringHub.h.

◆ m_typeIndex

std::type_index( * Gaudi::Monitoring::Hub::Entity::m_typeIndex) (const void *)
private

function to get internal type.

Definition at line 155 of file MonitoringHub.h.

◆ name

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

name of the entity

Definition at line 119 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 121 of file MonitoringHub.h.


The documentation for this class was generated from the following file:
Gaudi::Monitoring::Hub::Entity::name
std::string name
name of the entity
Definition: MonitoringHub.h:119
std::string
STL class.
std::move
T move(T... args)
jsonFromLHCbLog.json
json
Definition: jsonFromLHCbLog.py:87
std::type_index
Gaudi::Monitoring::Hub::Entity::m_typeIndex
std::type_index(* m_typeIndex)(const void *)
function to get internal type.
Definition: MonitoringHub.h:155
ProduceConsume.j
j
Definition: ProduceConsume.py:101
std::runtime_error
STL class.
Gaudi::Monitoring::Hub::Entity::m_reset
void(* m_reset)(Entity &)
function reseting internal data.
Definition: MonitoringHub.h:159
Gaudi::Monitoring::Hub::Entity::mergeAndReset
friend void mergeAndReset(Entity &ent, Entity &other)
function calling merge and reset on internal data with the internal data of another entity
Definition: MonitoringHub.h:134
Gaudi::Monitoring::Hub::Entity::m_ptr
void * m_ptr
pointer to the actual data inside this Entity
Definition: MonitoringHub.h:150
Gaudi::Monitoring::Hub::Entity::m_getJSON
nlohmann::json(* m_getJSON)(Entity const &)
function converting the internal data to json.
Definition: MonitoringHub.h:157
Gaudi::Monitoring::Hub::Entity::Entity
Entity(std::string component, std::string name, std::string type, T &ent)
Definition: MonitoringHub.h:103
Gaudi::Monitoring::Hub::Entity::reset
friend void reset(Entity &e)
function resetting internal data
Definition: MonitoringHub.h:127
Gaudi::Monitoring::Hub::Entity::m_mergeAndReset
void(* m_mergeAndReset)(Entity &, Entity &)
function calling merge and reset on internal data with the internal data of another entity
Definition: MonitoringHub.h:161
Gaudi::Monitoring::Hub::Entity::type
std::string type
type of the entity, see comment above concerning its format and usage
Definition: MonitoringHub.h:121
Gaudi::Monitoring::Hub::Entity::component
std::string component
name of the component owning the Entity
Definition: MonitoringHub.h:117