Skip to content
Snippets Groups Projects
Commit 7b89d4f2 authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Improvements on Monitoring::Hub::Entity and accumulators

2 main points :
  - the ptr internal data of Entity is now private
  - the string type of some accumulators (counters and histograms
    mostly) has been extended with an extra ':' and a string after it
    describing the precision of the internal data, using the typeid of
    the type that should be used when deserializing it from json
parent f79f7a2c
No related branches found
No related tags found
1 merge request!1185Improvements on Monitoring::Hub::Entity and accumulators
Pipeline #2349525 passed
......@@ -134,9 +134,12 @@ namespace Gaudi::Histograming::Sink {
} );
TFile histoFile( m_fileName.value().c_str(), "RECREATE" );
std::for_each( begin( m_monitoringEntities ), end( m_monitoringEntities ), []( auto& ent ) {
auto j = ent.toJSON();
auto dim = j.at( "dimension" ).template get<unsigned int>();
auto type = j.at( "type" ).template get<std::string>();
auto j = ent.toJSON();
auto dim = j.at( "dimension" ).template get<unsigned int>();
auto type = j.at( "type" ).template get<std::string>();
// cut type after last ':' if there is one. The rest is precision parameter that we do not need here
// as ROOT anyway treats everything as doubles in histograms
type = type.substr( 0, type.find_last_of( ':' ) );
auto saver = registry.find( {type, dim} );
if ( saver == registry.end() )
throw GaudiException( "Unknown type : " + type + " dim : " + std::to_string( dim ), "Histogram::Sink::Root",
......
......@@ -133,19 +133,29 @@ namespace Gaudi::Accumulators {
*
* Here is a list of types defined in this header and their corresponding fields.
* Note that there are 2 kinds of fields : raw ones and derived ones, built on top of raw ones.
* Note also that <prec> when present is a string defining the precision of the data when numerical. It
* is described at the end of the list
* for each dependent field, the computation formula is given
* - counter:Counter : empty(bool), nEntries(integer)
* - counter:AveragingCounter : same as counter:Counter, sum(number), mean(number) = sum/nEntries
* - counter:SigmaCounter : same as counter:AveragingCounter, sum2(number),
* standard_deviation(number) = sqrt((sum2-sum*sum/nEntries)/(nEntries-1))
* - counter:StatCounter : same as counter:SigmaCounter, min(number), max(number)
* - counter:BinomialCounter : nTrueEntries(integer), nFalseEntries(integer),
* nEntries(integer) = nTrueEntries+nFalseEntries
* efficiency(number) = nTrueEntries/nEntries,
* efficiencyErr(number) = (nTrueEntries*nFalseEntries)/(nEntries*nEntries)
* - counter:Counter:<prec> : empty(bool), nEntries(integer)
* - counter:AveragingCounter:<prec> : same as counter:Counter, sum(number), mean(number) = sum/nEntries
* - counter:SigmaCounter:<prec> : same as counter:AveragingCounter, sum2(number),
* standard_deviation(number) = sqrt((sum2-sum*sum/nEntries)/(nEntries-1))
* - counter:StatCounter:<prec> : same as counter:SigmaCounter, min(number), max(number)
* - counter:BinomialCounter:<prec> : nTrueEntries(integer), nFalseEntries(integer),
* nEntries(integer) = nTrueEntries+nFalseEntries
* efficiency(number) = nTrueEntries/nEntries,
* efficiencyErr(number) = (nTrueEntries*nFalseEntries)/(nEntries*nEntries)
* - counter:MsgCounter : same as counter:Counter, level(number), max(number), msg(string)
* - statentity : union of fields of counter:StatCounter and counter:BinomialCounter. DEPRECATED
* - timer : same fields as counter:StatCounter
* - timer:<prec> : same fields as counter:StatCounter
* - <prec> is a string defining the type of data in the counter. It is the typeid representation
* of the type that should be used by a customer to use the data and not lose precision.
* In other terms, it's usually one char of chstijlmxyfde for respectively char, unsigned char,
* short, unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long,
* float, double, long double
* Note that it does not have to match the original type, just to be the same precision.
* E.g. an std::chrono::nanoseconds type can and should be mapped to its internal representation
* that happens to be long so <prec> will be l.
*
* Notes
* -----
......@@ -853,7 +863,7 @@ namespace Gaudi::Accumulators {
*/
template <atomicity Atomicity = atomicity::full>
struct Counter : BufferableCounter<Atomicity, CountAccumulator, int> {
inline static const std::string typeString{"counter:Counter"};
inline static const std::string typeString{std::string{"counter:Counter:"} + typeid( int ).name()};
using BufferableCounter<Atomicity, CountAccumulator, int>::BufferableCounter;
template <typename OWNER>
Counter( OWNER* o, std::string const& name )
......@@ -895,7 +905,7 @@ namespace Gaudi::Accumulators {
*/
template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
struct AveragingCounter : BufferableCounter<Atomicity, AveragingAccumulator, Arithmetic> {
inline static const std::string typeString{"counter:AveragingCounter"};
inline static const std::string typeString{std::string{"counter:AveragingCounter:"} + typeid( Arithmetic ).name()};
using BufferableCounter<Atomicity, AveragingAccumulator, Arithmetic>::BufferableCounter;
template <typename OWNER>
AveragingCounter( OWNER* o, std::string const& name )
......@@ -934,7 +944,7 @@ namespace Gaudi::Accumulators {
*/
template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
struct SigmaCounter : BufferableCounter<Atomicity, SigmaAccumulator, Arithmetic> {
inline static const std::string typeString{"counter:SigmaCounter"};
inline static const std::string typeString{std::string{"counter:SigmaCounter:"} + typeid( Arithmetic ).name()};
using BufferableCounter<Atomicity, SigmaAccumulator, Arithmetic>::BufferableCounter;
template <typename OWNER>
SigmaCounter( OWNER* o, std::string const& name )
......@@ -973,7 +983,7 @@ namespace Gaudi::Accumulators {
*/
template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
struct StatCounter : BufferableCounter<Atomicity, StatAccumulator, Arithmetic> {
inline static const std::string typeString{"counter:StatCounter"};
inline static const std::string typeString{std::string{"counter:StatCounter:"} + typeid( Arithmetic ).name()};
using BufferableCounter<Atomicity, StatAccumulator, Arithmetic>::BufferableCounter;
template <typename OWNER>
StatCounter( OWNER* o, std::string const& name )
......@@ -1016,7 +1026,7 @@ namespace Gaudi::Accumulators {
*/
template <typename Arithmetic = double, atomicity Atomicity = atomicity::full>
struct BinomialCounter : BufferableCounter<Atomicity, BinomialAccumulator, Arithmetic> {
inline static const std::string typeString{"counter:BinomialCounter"};
inline static const std::string typeString{std::string{"counter:BinomialCounter:"} + typeid( Arithmetic ).name()};
using BufferableCounter<Atomicity, BinomialAccumulator, Arithmetic>::BufferableCounter;
template <typename OWNER>
BinomialCounter( OWNER* o, std::string const& name )
......
......@@ -370,8 +370,9 @@ namespace Gaudi::Accumulators {
* wcounter += {{val1, val2}, w}; // original syntax inherited from counters
* \endcode
*
* When serialized to json, this counter uses new types histogram:Histogram, histogram:ProfileHistogram,
* histogram:WeightedHistogram and histrogram:WeightedProfileHistogram
* When serialized to json, this counter uses new types histogram:Histogram:<prec>, histogram:ProfileHistogram:<prec>,
* histogram:WeightedHistogram:<prec> and histrogram:WeightedProfileHistogram:<prec>
* <prec> id described in Accumulators.h and decribes here the precision of the bin data.
* All these types have the same fields, namely :
* dimension(integer), title(string), empty(bool), nEntries(integer), axis(array), bins(array)
* where :
......@@ -392,7 +393,9 @@ namespace Gaudi::Accumulators {
template <typename OWNER>
HistogramingCounterBase( OWNER* owner, std::string const& name, std::string const& title,
std::initializer_list<Axis<Arithmetic>> axis )
: Parent( owner, name, Type, axis, std::make_index_sequence<ND>{} ), m_title( title ) {}
: Parent( owner, name, std::string( Type ) + ":" + typeid( Arithmetic ).name(), axis,
std::make_index_sequence<ND>{} )
, m_title( title ) {}
template <typename OWNER>
HistogramingCounterBase( OWNER* owner, std::string const& name, std::string const& title, Axis<Arithmetic> axis )
: HistogramingCounterBase( owner, name, title, {axis} ) {}
......@@ -420,7 +423,7 @@ namespace Gaudi::Accumulators {
totNEntries += this->nEntries( i );
}
// build json
return {{"type", Type},
return {{"type", std::string( Type ) + ":" + typeid( Arithmetic ).name()},
{"title", m_title},
{"dimension", ND},
{"empty", totNEntries == Arithmetic{}},
......
......@@ -37,7 +37,8 @@ namespace Gaudi::Monitoring {
* to decide if they have to handle a given entity or not.
* It can also be used to know which fields to expect in the json dictionnary
*/
struct Entity {
class Entity {
public:
template <typename T>
Entity( std::string component, std::string name, std::string type, const T& ent )
: component{std::move( component )}
......@@ -51,11 +52,17 @@ namespace Gaudi::Monitoring {
std::string name;
/// type of the entity, see comment above concerning its format and usage
std::string type;
/// function giving access to internal data in json format
json toJSON() const { return ( *getJSON )( ptr ); }
private:
/// pointer to the actual data inside this Entity
const void* ptr{nullptr};
/// function converting the internal data to json. Due to type erasure, it needs to be a member of this struct
/// function converting the internal data to json.
/// Due to type erasure, it needs to be a member of this struct as it's
/// implementation is different for different types (see Constructor
/// above and the usage of T in the reinterpret_cast)
json ( *getJSON )( const void* );
json toJSON() const { return ( *getJSON )( ptr ); }
};
/// Interface reporting services must implement.
......
......@@ -80,7 +80,7 @@ namespace Gaudi {
/// Constructor attaching the statistics counter to an owner
template <class OWNER>
GenericTimer( OWNER* o, const std::string& name ) {
o->declareCounter( name, "timer", m_stats );
o->declareCounter( name, std::string{"timer:"} + typeid( Unit::rep ).name(), m_stats );
}
/// No copy
......
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