The Gaudi Framework  v36r10 (fc05264c)
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 ) &&
42  }
43  }
44 
46  void removeEntity( Hub::Entity const& ent ) override {
48  if ( it != m_monitoringEntities.end() ) { m_monitoringEntities.erase( it ); }
49  }
50 
51  protected:
57  template <typename Callable>
58  void applytoAllEntities( Callable func, bool sortFirst = false ) {
59  // sort if required
60  if ( sortFirst ) {
61  std::sort( begin( m_monitoringEntities ), end( m_monitoringEntities ), []( const auto& a, const auto& b ) {
62  return std::tie( a.name, a.component ) > std::tie( b.name, b.component );
63  } );
64  }
65  // loop over entities
67  }
68 
69  private:
73  if ( searchNames.empty() ) { return true; }
74  for ( const auto& searchName : searchNames ) {
75  const std::regex regex( searchName );
76  if ( std::regex_match( name, regex ) ) { return true; }
77  }
78  return false;
79  }
80 
84  this, "NamesToSave", {}, "List of regexps used to match names of entities to save" };
86  this, "ComponentsToSave", {}, "List of regexps used to match component names of entities to save" };
88  this, "TypesToSave", {}, "List of regexps used to match type names of entities to save" };
89  };
90 
91 } // namespace Gaudi::Monitoring
Gaudi::Monitoring::Hub::Sink
Interface reporting services must implement.
Definition: MonitoringHub.h:156
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:83
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:85
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::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
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
Gaudi::Monitoring::BaseSink::m_monitoringEntities
std::deque< Gaudi::Monitoring::Hub::Entity > m_monitoringEntities
list of entities we are dealing with
Definition: BaseSink.h:82
std::sort
T sort(T... args)
Service
Definition: Service.h:46
std::tie
T tie(T... args)
Gaudi::Monitoring::BaseSink::m_typesToSave
Gaudi::Property< std::vector< std::string > > m_typesToSave
Definition: BaseSink.h:87
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::deque::erase
T erase(T... args)
std::deque< Gaudi::Monitoring::Hub::Entity >
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:72
std::regex
IOTest.end
def end
Definition: IOTest.py:128
Service.h
std::deque::emplace_back
T emplace_back(T... args)
Service::Service
Service(std::string name, ISvcLocator *svcloc)
Standard Constructor
Definition: Service.cpp:339
std::vector::empty
T empty(T... args)
std::deque::end
T end(T... args)
Gaudi::Monitoring::BaseSink::applytoAllEntities
void applytoAllEntities(Callable func, bool sortFirst=false)
applies a callable to all monitoring entities
Definition: BaseSink.h:58
Gaudi::Monitoring::Hub::Entity
Wrapper class for arbitrary monitoring objects.
Definition: MonitoringHub.h:89
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