The Gaudi Framework  master (27adc009)
Loading...
Searching...
No Matches
Gaudi::Monitoring::BaseSink Class Referenceabstract

Base class for all Sinks registering to the Monitoring Hub Should be extended by actual Sinks. More...

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

Inheritance diagram for Gaudi::Monitoring::BaseSink:
Collaboration diagram for Gaudi::Monitoring::BaseSink:

Classes

struct  EntityOrder
 list of entities we are dealing with More...
 

Public Member Functions

StatusCode initialize () override
 
void registerEntity (Hub::Entity ent) override
 handles registration of a new entity
 
void removeEntity (Hub::Entity const &ent) override
 handles removal of an entity
 
virtual void flush (bool isStop)=0
 pure virtual method to be defined by children and responsible for flushing current data of the Sink.
 
StatusCode start () override
 
StatusCode stop () override
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
 
- Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service.
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service.
 
StatusCode sysStart () override
 Initialize Service.
 
StatusCode sysStop () override
 Initialize Service.
 
StatusCode sysFinalize () override
 Finalize Service.
 
StatusCode sysReinitialize () override
 Re-initialize the Service.
 
StatusCode sysRestart () override
 Re-initialize the Service.
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool.
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
 
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
 
const std::vector< IAlgTool * > & tools () const
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation.
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 
- Public Member Functions inherited from Gaudi::Monitoring::Hub::Sink
virtual ~Sink ()=default
 

Protected Member Functions

template<typename Callable>
void applyToAllEntities (Callable func) const
 applies a callable to all monitoring entities
 
template<typename Callable>
void applyToAllSortedEntities (Callable func) const
 applies a callable to all monitoring entities ordered by component the callable will be called once per entity and should have a signature ( std::string const&, std::string const&, nlohmann::json const& )
 
bool wanted (std::string const &name, std::vector< std::string > const &searchNames)
 deciding whether a given name matches the list of regexps given empty list means everything matches
 
- Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 
 ~Service () override
 
int outputLevel () const
 get the Service's output level
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches.
 
MSG::Level resetMessaging ()
 Reinitialize internal states.
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
 

Protected Attributes

std::set< Gaudi::Monitoring::Hub::Entity, EntityOrderm_monitoringEntities
 
Gaudi::Property< std::vector< std::string > > m_namesToSave
 
Gaudi::Property< std::vector< std::string > > m_componentsToSave
 
Gaudi::Property< std::vector< std::string > > m_typesToSave
 
std::thread m_flushThread
 Handling of regular flushes, if requested.
 
std::promise< void > m_flushThreadStop
 
Gaudi::Property< float > m_autoFlushPeriod
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
 
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
 
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
 
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
 
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
 
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
 
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
 
Gaudi::Property< bool > m_autoRetrieveTools
 
Gaudi::Property< bool > m_checkToolDeps
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service.
 

Additional Inherited Members

- Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory<IService*( const std::string&, ISvcLocator* )>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
 

Detailed Description

Base class for all Sinks registering to the Monitoring Hub Should be extended by actual Sinks.

Deals with registration and manages selection of Entities Provides support for regular flushing of the Sink content. The AutoFlushPeriod property defines the interval. A value of 0 means no auto flush.

Actual Sinks extending this base class have to implement the flush method. This one has a boolean argument allowing to know whether it was called at a regular interval or a the end

Definition at line 41 of file BaseSink.h.

Member Function Documentation

◆ applyToAllEntities()

template<typename Callable>
void Gaudi::Monitoring::BaseSink::applyToAllEntities ( Callable func) const
inlineprotected

applies a callable to all monitoring entities

Definition at line 101 of file BaseSink.h.

101 {
102 std::for_each( begin( m_monitoringEntities ), end( m_monitoringEntities ), [func]( auto& p ) { func( p ); } );
103 }
std::set< Gaudi::Monitoring::Hub::Entity, EntityOrder > m_monitoringEntities
Definition BaseSink.h:135
AttribStringParser::Iterator begin(const AttribStringParser &parser)

◆ applyToAllSortedEntities()

template<typename Callable>
void Gaudi::Monitoring::BaseSink::applyToAllSortedEntities ( Callable func) const
inlineprotected

applies a callable to all monitoring entities ordered by component the callable will be called once per entity and should have a signature ( std::string const&, std::string const&, nlohmann::json const& )

Definition at line 111 of file BaseSink.h.

111 {
112 std::vector<Hub::Entity const*> sortedEntities;
113 applyToAllEntities( [&sortedEntities]( auto& ent ) { sortedEntities.emplace_back( &ent ); } );
114 std::sort( sortedEntities.begin(), sortedEntities.end(), []( const auto* lhs, const auto* rhs ) {
115 return std::tie( lhs->component, lhs->name ) < std::tie( rhs->component, rhs->name );
116 } );
117 for ( auto const* ent : sortedEntities ) { func( ent->component, ent->name, *ent ); }
118 }
void applyToAllEntities(Callable func) const
applies a callable to all monitoring entities
Definition BaseSink.h:101

◆ flush()

virtual void Gaudi::Monitoring::BaseSink::flush ( bool isStop)
pure virtual

pure virtual method to be defined by children and responsible for flushing current data of the Sink.

This method is called every m_autoFlushPeriod (if not set to 0) and in the stop method by default

Parameters
isStopallows to know which case we are in

Implemented in Gaudi::Histograming::Sink::Base, Gaudi::Monitoring::JSONSink, and Gaudi::Monitoring::MessageSvcSink.

◆ initialize()

StatusCode Gaudi::Monitoring::BaseSink::initialize ( )
inlineoverride

Definition at line 46 of file BaseSink.h.

46 {
47 // registers itself to the Monitoring Hub
48 return Service::initialize().andThen( [&] { serviceLocator()->monitoringHub().addSink( this ); } );
49 }
Gaudi::Monitoring::Hub & monitoringHub()
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition Service.cpp:336
StatusCode initialize() override
Definition Service.cpp:118
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition StatusCode.h:163
void addSink(Sink *sink)

◆ registerEntity()

void Gaudi::Monitoring::BaseSink::registerEntity ( Hub::Entity ent)
inlineoverridevirtual

handles registration of a new entity

Implements Gaudi::Monitoring::Hub::Sink.

Definition at line 52 of file BaseSink.h.

52 {
53 if ( wanted( ent.type, m_typesToSave ) && wanted( ent.name, m_namesToSave ) &&
54 wanted( ent.component, m_componentsToSave ) ) {
55 m_monitoringEntities.emplace( std::move( ent ) );
56 }
57 }
Gaudi::Property< std::vector< std::string > > m_componentsToSave
Definition BaseSink.h:138
Gaudi::Property< std::vector< std::string > > m_namesToSave
Definition BaseSink.h:136
Gaudi::Property< std::vector< std::string > > m_typesToSave
Definition BaseSink.h:140
bool wanted(std::string const &name, std::vector< std::string > const &searchNames)
deciding whether a given name matches the list of regexps given empty list means everything matches
Definition BaseSink.h:122

◆ removeEntity()

void Gaudi::Monitoring::BaseSink::removeEntity ( Hub::Entity const & ent)
inlineoverridevirtual

handles removal of an entity

Implements Gaudi::Monitoring::Hub::Sink.

Definition at line 60 of file BaseSink.h.

60 {
61 auto it = m_monitoringEntities.find( ent );
62 if ( it != m_monitoringEntities.end() ) { m_monitoringEntities.erase( it ); }
63 }

◆ Service()

Service::Service ( std::string name,
ISvcLocator * svcloc )

Standard Constructor.

Definition at line 74 of file Service.cpp.

340 : m_name( std::move( name ) ), m_svcLocator( svcloc ) {
341 if ( m_name != "MessageSvc" ) { // the MessageSvc should not notify itself
342 m_outputLevel.declareUpdateHandler(
343 [this]( Gaudi::Details::PropertyBase& ) { this->updateMsgStreamOutputLevel( this->m_outputLevel ); } );
344 }
345
346 // Initialize the default value from ApplicationMgr AuditAlgorithms
347 Gaudi::Property<bool> audit( "AuditServices", false );
348 if ( auto appMgr = serviceLocator()->service<IProperty>( "ApplicationMgr" ) ) {
349 appMgr->getProperty( &audit ).ignore();
350 }
351
352 m_auditorInitialize = audit;
353 m_auditorStart = audit;
354 m_auditorStop = audit;
355 m_auditorFinalize = audit;
356 m_auditorReinitialize = audit;
357 m_auditorRestart = audit;
358}
Gaudi::Property< bool > m_auditorStart
Definition Service.h:186
Gaudi::Property< bool > m_auditorFinalize
Definition Service.h:188
Gaudi::Property< int > m_outputLevel
flag indicating whether ToolHandle tools have been added to m_tools
Definition Service.h:184
Gaudi::Property< bool > m_auditorStop
Definition Service.h:187
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
Gaudi::Property< bool > m_auditorRestart
Definition Service.h:190
SmartIF< ISvcLocator > m_svcLocator
Service Locator reference.
Definition Service.h:170
SmartIF< IFace > service(const std::string &name, bool createIf=true) const
Definition Service.h:79
Gaudi::Property< bool > m_auditorInitialize
Definition Service.h:185
Gaudi::Property< bool > m_auditorReinitialize
Definition Service.h:189
std::string m_name
Service Name.
Definition Service.h:168

◆ start()

StatusCode Gaudi::Monitoring::BaseSink::start ( )
inlineoverride

Definition at line 73 of file BaseSink.h.

73 {
74 return Service::start().andThen( [&] {
75 // promise needs to be recreated in case of a restart
76 m_flushThreadStop = std::promise<void>{};
77 // enable periodic output file flush if requested
78 if ( m_autoFlushPeriod.value() > std::numeric_limits<float>::epsilon() ) {
79 m_flushThread = std::thread{ [this, flushStop = m_flushThreadStop.get_future()]() {
80 using namespace std::chrono_literals;
81 while ( flushStop.wait_for( m_autoFlushPeriod.value() * 1s ) == std::future_status::timeout ) {
82 flush( false );
83 }
84 } };
85 }
86 } );
87 }
virtual void flush(bool isStop)=0
pure virtual method to be defined by children and responsible for flushing current data of the Sink.
std::thread m_flushThread
Handling of regular flushes, if requested.
Definition BaseSink.h:144
Gaudi::Property< float > m_autoFlushPeriod
Definition BaseSink.h:146
std::promise< void > m_flushThreadStop
Definition BaseSink.h:145
StatusCode start() override
Definition Service.cpp:187

◆ stop()

StatusCode Gaudi::Monitoring::BaseSink::stop ( )
inlineoverride

Definition at line 89 of file BaseSink.h.

89 {
90 m_flushThreadStop.set_value(); // tell the flush thread we are stopping
91 if ( m_flushThread.joinable() ) m_flushThread.join(); // and wait that it exits
92 flush( true );
93 return Service::stop();
94 }
StatusCode stop() override
Definition Service.cpp:181

◆ wanted()

bool Gaudi::Monitoring::BaseSink::wanted ( std::string const & name,
std::vector< std::string > const & searchNames )
inlineprotected

deciding whether a given name matches the list of regexps given empty list means everything matches

Definition at line 122 of file BaseSink.h.

122 {
123 return searchNames.empty() || std::any_of( searchNames.begin(), searchNames.end(), [&]( const auto& searchName ) {
124 const std::regex regex( searchName );
125 return std::regex_match( name, regex );
126 } );
127 }

Member Data Documentation

◆ m_autoFlushPeriod

Gaudi::Property<float> Gaudi::Monitoring::BaseSink::m_autoFlushPeriod
protected
Initial value:
{
this, "AutoFlushPeriod", 0.,
"if different from 0, indicates every how many seconds to force a write of the FSR data to OutputFile (this "
"parameter makes sense only if used in conjunction with OutputFile)" }

Definition at line 146 of file BaseSink.h.

146 {
147 this, "AutoFlushPeriod", 0.,
148 "if different from 0, indicates every how many seconds to force a write of the FSR data to OutputFile (this "
149 "parameter makes sense only if used in conjunction with OutputFile)" };

◆ m_componentsToSave

Gaudi::Property<std::vector<std::string> > Gaudi::Monitoring::BaseSink::m_componentsToSave
protected
Initial value:
{
this, "ComponentsToSave", {}, "List of regexps used to match component names of entities to save" }

Definition at line 138 of file BaseSink.h.

138 {
139 this, "ComponentsToSave", {}, "List of regexps used to match component names of entities to save" };

◆ m_flushThread

std::thread Gaudi::Monitoring::BaseSink::m_flushThread
protected

Handling of regular flushes, if requested.

Definition at line 144 of file BaseSink.h.

◆ m_flushThreadStop

std::promise<void> Gaudi::Monitoring::BaseSink::m_flushThreadStop
protected

Definition at line 145 of file BaseSink.h.

◆ m_monitoringEntities

std::set<Gaudi::Monitoring::Hub::Entity, EntityOrder> Gaudi::Monitoring::BaseSink::m_monitoringEntities
protected

Definition at line 135 of file BaseSink.h.

◆ m_namesToSave

Gaudi::Property<std::vector<std::string> > Gaudi::Monitoring::BaseSink::m_namesToSave
protected
Initial value:
{
this, "NamesToSave", {}, "List of regexps used to match names of entities to save" }

Definition at line 136 of file BaseSink.h.

136 {
137 this, "NamesToSave", {}, "List of regexps used to match names of entities to save" };

◆ m_typesToSave

Gaudi::Property<std::vector<std::string> > Gaudi::Monitoring::BaseSink::m_typesToSave
protected
Initial value:
{
this, "TypesToSave", {}, "List of regexps used to match type names of entities to save" }

Definition at line 140 of file BaseSink.h.

140 {
141 this, "TypesToSave", {}, "List of regexps used to match type names of entities to save" };

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