Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
BaseSink.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 2022 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 
12 #include "GaudiKernel/Service.h"
13 
14 #include <Gaudi/MonitoringHub.h>
15 
16 #include <deque>
17 #include <string>
18 
19 namespace Gaudi::Monitoring {
20 
27  class BaseSink : public Service, public Hub::Sink {
28 
29  public:
30  using Service::Service;
31 
32  StatusCode initialize() override {
33  // registers itself to the Monitoring Hub
34  return Service::initialize().andThen( [&] { serviceLocator()->monitoringHub().addSink( this ); } );
35  }
36 
38  void registerEntity( Hub::Entity ent ) override {
39  if ( wanted( ent.type, m_typesToSave ) && wanted( ent.name, m_namesToSave ) &&
41  m_monitoringEntities.insert( { ent.id(), std::move( ent ) } );
42  }
43  }
44 
46  void removeEntity( Hub::Entity const& ent ) override {
47  auto it = m_monitoringEntities.find( ent.id() );
48  if ( it != m_monitoringEntities.end() ) { m_monitoringEntities.erase( it ); }
49  }
50 
51  protected:
57  template <typename Callable>
58  void applytoAllEntities( Callable func ) {
60  [func]( auto& p ) { func( p.second ); } );
61  }
62 
68  applytoAllEntities( [&sortedEntities]( auto& ent ) { sortedEntities[ent.component][ent.name] = ent.toJSON(); } );
69  return sortedEntities;
70  }
71 
72  private:
76  if ( searchNames.empty() ) { return true; }
77  for ( const auto& searchName : searchNames ) {
78  const std::regex regex( searchName );
79  if ( std::regex_match( name, regex ) ) { return true; }
80  }
81  return false;
82  }
83 
87  this, "NamesToSave", {}, "List of regexps used to match names of entities to save" };
89  this, "ComponentsToSave", {}, "List of regexps used to match component names of entities to save" };
91  this, "TypesToSave", {}, "List of regexps used to match type names of entities to save" };
92  };
93 
94 } // namespace Gaudi::Monitoring
Gaudi::Monitoring::Hub::Sink
Interface reporting services must implement.
Definition: MonitoringHub.h:158
Gaudi::Monitoring::BaseSink
Base class for all Sinks registering to the Monitoring Hub.
Definition: BaseSink.h:27
std::for_each
T for_each(T... args)
Gaudi::Monitoring::Hub::Entity::name
std::string name
name of the entity
Definition: MonitoringHub.h:107
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:118
std::string
STL class.
Gaudi::Monitoring::BaseSink::m_namesToSave
Gaudi::Property< std::vector< std::string > > m_namesToSave
Definition: BaseSink.h:86
Gaudi::Monitoring::BaseSink::removeEntity
void removeEntity(Hub::Entity const &ent) override
handles removal of an entity
Definition: BaseSink.h:46
Gaudi::Monitoring::BaseSink::m_componentsToSave
Gaudi::Property< std::vector< std::string > > m_componentsToSave
Definition: BaseSink.h:88
StatusCode::andThen
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition: StatusCode.h:163
std::move
T move(T... args)
MonitoringHub.h
std::vector< std::string >
std::map::find
T find(T... args)
Gaudi::Monitoring::BaseSink::registerEntity
void registerEntity(Hub::Entity ent) override
handles registration of a new entity
Definition: BaseSink.h:38
Gaudi::Monitoring::BaseSink::sortedEntitiesAsJSON
std::map< std::string, std::map< std::string, nlohmann::json > > const sortedEntitiesAsJSON()
returns all entities in JSON format, grouped by component first and then name
Definition: BaseSink.h:66
std::regex_match
T regex_match(T... args)
Gaudi::Monitoring
Definition: JSONSink.cpp:19
Gaudi::Monitoring::BaseSink::initialize
StatusCode initialize() override
Definition: BaseSink.h:32
Service
Definition: Service.h:46
Gaudi::Monitoring::BaseSink::m_typesToSave
Gaudi::Property< std::vector< std::string > > m_typesToSave
Definition: BaseSink.h:90
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:332
StatusCode
Definition: StatusCode.h:65
GaudiPluginService.cpluginsvc.func
func
Definition: cpluginsvc.py:236
CLHEP::begin
double * begin(CLHEP::HepVector &v)
Definition: TupleAlg.cpp:45
std::map::erase
T erase(T... args)
std::map
STL class.
Gaudi::Monitoring::BaseSink::wanted
bool wanted(std::string name, std::vector< std::string > searchNames)
deciding whether a given name matches the list of regexps given empty list means everything matches
Definition: BaseSink.h:75
std::regex
Gaudi::Monitoring::Hub::Entity::id
void * id() const
unique identifier, actually mapped to internal pointer
Definition: MonitoringHub.h:137
Service.h
std::map::insert
T insert(T... args)
Service::Service
Service(std::string name, ISvcLocator *svcloc)
Standard Constructor
Definition: Service.cpp:339
std::vector::empty
T empty(T... args)
std::map::end
T end(T... args)
Gaudi::Monitoring::BaseSink::m_monitoringEntities
std::map< void *, Gaudi::Monitoring::Hub::Entity > m_monitoringEntities
list of entities we are dealing with
Definition: BaseSink.h:85
IOTest.end
end
Definition: IOTest.py:123
Gaudi::Monitoring::Hub::Entity
Wrapper class for arbitrary monitoring objects.
Definition: MonitoringHub.h:89
Gaudi::Monitoring::BaseSink::applytoAllEntities
void applytoAllEntities(Callable func)
applies a callable to all monitoring entities
Definition: BaseSink.h:58
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:39
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator
Definition: Service.cpp:335
Gaudi::Monitoring::Hub::Entity::type
std::string type
type of the entity, see comment above concerning its format and usage
Definition: MonitoringHub.h:109
Gaudi::Monitoring::Hub::Entity::component
std::string component
name of the component owning the Entity
Definition: MonitoringHub.h:105