The Gaudi Framework  master (d98a2936)
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 More...
 
void removeEntity (Hub::Entity const &ent) override
 handles removal of an entity More...
 
virtual void flush (bool isStop)=0
 pure virtual method to be defined by children and responsible for flushing current data of the Sink. More...
 
StatusCode start () override
 
StatusCode stop () override
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor
More...
 
- Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service
More...
 
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
More...
 
StatusCode sysStart () override
 Initialize Service
More...
 
StatusCode sysStop () override
 Initialize Service
More...
 
StatusCode sysFinalize () override
 Finalize Service
More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor
More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator
More...
 
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. More...
 
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. More...
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property. More...
 
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. More...
 
 requires (!Gaudi::Details::is_gaudi_property_v< TYPE >) Gaudi
 Helper to wrap a regular data member and use it as a regular property. More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property. More...
 
virtual StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p)=0
 Set the property from a property with a different name. More...
 
virtual StatusCode setProperty (const std::string &s)=0
 Set the property by string. More...
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals. More...
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string. More...
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name More...
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string More...
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties More...
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name. More...
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected More...
 
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) More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- 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 More...
 
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& ) More...
 
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 More...
 
- Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 
 ~Service () override
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches. More...
 
MSG::Level resetMessaging ()
 Reinitialize internal states. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 

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. More...
 
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
More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state
More...
 
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools More...
 
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
More...
 

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 = PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 Typedef used to refer to this class from derived classes, as in. More...
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 

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 40 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 100 of file BaseSink.h.

100  {
101  std::for_each( begin( m_monitoringEntities ), end( m_monitoringEntities ), [func]( auto& p ) { func( p ); } );
102  }

◆ 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 110 of file BaseSink.h.

110  {
111  std::vector<Hub::Entity const*> sortedEntities;
112  applyToAllEntities( [&sortedEntities]( auto& ent ) { sortedEntities.emplace_back( &ent ); } );
113  std::sort( sortedEntities.begin(), sortedEntities.end(), []( const auto* lhs, const auto* rhs ) {
114  return std::tie( lhs->component, lhs->name ) < std::tie( rhs->component, rhs->name );
115  } );
116  for ( auto const* ent : sortedEntities ) { func( ent->component, ent->name, *ent ); }
117  }

◆ 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::Monitoring::MessageSvcSink, Gaudi::Histograming::Sink::Base, and Gaudi::Monitoring::JSONSink.

◆ initialize()

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

Definition at line 45 of file BaseSink.h.

45  {
46  // registers itself to the Monitoring Hub
47  return Service::initialize().andThen( [&] { serviceLocator()->monitoringHub().addSink( this ); } );
48  }

◆ registerEntity()

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

handles registration of a new entity

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

Definition at line 51 of file BaseSink.h.

51  {
52  if ( wanted( ent.type, m_typesToSave ) && wanted( ent.name, m_namesToSave ) &&
53  wanted( ent.component, m_componentsToSave ) ) {
54  m_monitoringEntities.emplace( std::move( ent ) );
55  }
56  }

◆ removeEntity()

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

handles removal of an entity

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

Definition at line 59 of file BaseSink.h.

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

◆ Service()

Service::Service

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
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 }

◆ start()

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

Definition at line 72 of file BaseSink.h.

72  {
73  return Service::start().andThen( [&] {
74  // promise needs to be recreated in case of a restart
75  m_flushThreadStop = std::promise<void>{};
76  // enable periodic output file flush if requested
77  if ( m_autoFlushPeriod.value() > std::numeric_limits<float>::epsilon() ) {
78  m_flushThread = std::thread{ [this, flushStop = m_flushThreadStop.get_future()]() {
79  using namespace std::chrono_literals;
80  while ( flushStop.wait_for( m_autoFlushPeriod.value() * 1s ) == std::future_status::timeout ) {
81  flush( false );
82  }
83  } };
84  }
85  } );
86  }

◆ stop()

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

Definition at line 88 of file BaseSink.h.

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

◆ 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 121 of file BaseSink.h.

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

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 145 of file BaseSink.h.

◆ 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 137 of file BaseSink.h.

◆ m_flushThread

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

Handling of regular flushes, if requested.

Definition at line 143 of file BaseSink.h.

◆ m_flushThreadStop

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

Definition at line 144 of file BaseSink.h.

◆ m_monitoringEntities

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

Definition at line 134 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 135 of file BaseSink.h.

◆ 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 139 of file BaseSink.h.


The documentation for this class was generated from the following file:
Service::m_auditorStart
Gaudi::Property< bool > m_auditorStart
Definition: Service.h:186
Gaudi::Monitoring::BaseSink::m_monitoringEntities
std::set< Gaudi::Monitoring::Hub::Entity, EntityOrder > m_monitoringEntities
Definition: BaseSink.h:134
Service::m_auditorStop
Gaudi::Property< bool > m_auditorStop
Definition: Service.h:187
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: PropertyBase.h:34
Gaudi::Monitoring::BaseSink::m_flushThread
std::thread m_flushThread
Handling of regular flushes, if requested.
Definition: BaseSink.h:143
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:118
Gaudi::Monitoring::BaseSink::m_namesToSave
Gaudi::Property< std::vector< std::string > > m_namesToSave
Definition: BaseSink.h:135
Gaudi::Monitoring::BaseSink::m_componentsToSave
Gaudi::Property< std::vector< std::string > > m_componentsToSave
Definition: BaseSink.h:137
StatusCode::andThen
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition: StatusCode.h:163
Service::start
StatusCode start() override
Definition: Service.cpp:187
Gaudi::Monitoring::BaseSink::m_autoFlushPeriod
Gaudi::Property< float > m_autoFlushPeriod
Definition: BaseSink.h:145
Service::m_auditorInitialize
Gaudi::Property< bool > m_auditorInitialize
Definition: Service.h:185
Service::m_svcLocator
SmartIF< ISvcLocator > m_svcLocator
Service Locator reference
Definition: Service.h:170
Service::m_auditorReinitialize
Gaudi::Property< bool > m_auditorReinitialize
Definition: Service.h:189
Service::m_name
std::string m_name
Service Name
Definition: Service.h:168
Gaudi::Monitoring::BaseSink::m_typesToSave
Gaudi::Property< std::vector< std::string > > m_typesToSave
Definition: BaseSink.h:139
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:135
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:333
Gaudi::cxx::for_each
void for_each(ContainerOfSynced &c, Fun &&f)
Definition: SynchronizedValue.h:98
cpluginsvc.func
func
Definition: cpluginsvc.py:235
Service::m_auditorFinalize
Gaudi::Property< bool > m_auditorFinalize
Definition: Service.h:188
Service::m_auditorRestart
Gaudi::Property< bool > m_auditorRestart
Definition: Service.h:190
Gaudi::Property::declareUpdateHandler
Details::PropertyBase & declareUpdateHandler(std::function< void(Details::PropertyBase &)> fun) override
set new callback for update
Definition: Property.h:135
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:229
CommonMessaging< implements< IService, IProperty, IStateful > >::updateMsgStreamOutputLevel
void updateMsgStreamOutputLevel(int level)
Update the output level of the cached MsgStream.
Definition: CommonMessaging.h:184
Service::stop
StatusCode stop() override
Definition: Service.cpp:181
Gaudi::Monitoring::BaseSink::flush
virtual void flush(bool isStop)=0
pure virtual method to be defined by children and responsible for flushing current data of the Sink.
Gaudi::Monitoring::BaseSink::applyToAllEntities
void applyToAllEntities(Callable func) const
applies a callable to all monitoring entities
Definition: BaseSink.h:100
IOTest.end
end
Definition: IOTest.py:125
Gaudi::Monitoring::BaseSink::wanted
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:121
IOTest.appMgr
appMgr
Definition: IOTest.py:105
Service::m_outputLevel
Gaudi::Property< int > m_outputLevel
flag indicating whether ToolHandle tools have been added to m_tools
Definition: Service.h:184
Gaudi::Property< bool >
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator
Definition: Service.cpp:336
Gaudi::Monitoring::BaseSink::m_flushThreadStop
std::promise< void > m_flushThreadStop
Definition: BaseSink.h:144