| The Gaudi Framework v32r1 (f65d50dc)

SvcCatalog.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ===========================================================================
4 // STD & STL:
5 // ===========================================================================
6 #include <iostream>
7 #include <sstream>
8 // ===========================================================================
9 // Boost:
10 // ===========================================================================
11 #include "boost/algorithm/string.hpp"
12 // ===========================================================================
13 // Local
14 // ===========================================================================
15 #include "SvcCatalog.h"
16 // ===========================================================================
17 namespace {
18 constexpr struct select1st_t {
19 template <typename S, typename T>
20 const S& operator()( const std::pair<S, T>& p ) const {
21 return p.first;
22 }
23 template <typename S, typename T>
24 S& operator()( std::pair<S, T>& p ) const {
25 return p.first;
26 }
27 } select1st{};
28 } // namespace
29 // ===========================================================================
30 SvcCatalog::~SvcCatalog() {
31 for ( const auto& cur : m_catalog ) {
32 for ( auto& prop : cur.second ) delete prop;
33 }
34 }
35 // ============================================================================
36 StatusCode SvcCatalog::addProperty( const std::string& client, const Gaudi::Details::PropertyBase* property ) {
37 auto props = findProperties( client );
38 if ( props ) {
39 removeProperty( client, property->name() ).ignore();
40 props->push_back( property );
41 } else {
42 m_catalog.emplace( client, PropertiesT{property} );
43 }
44 return StatusCode::SUCCESS;
45 }
46 // ============================================================================
47 StatusCode SvcCatalog::removeProperty( const std::string& client, const std::string& name ) {
48 auto props = findProperties( client );
49 if ( props ) {
50 auto res = findProperty( *props, name );
51 if ( res.first ) {
52 delete *res.second;
53 props->erase( res.second );
54 }
55 }
56 return StatusCode::SUCCESS;
57 }
58 // ============================================================================
59 const SvcCatalog::PropertiesT* SvcCatalog::getProperties( const std::string& client ) const {
60 return findProperties( client );
61 }
62 // ============================================================================
63 std::vector<std::string> SvcCatalog::getClients() const {
64 std::vector<std::string> result;
65 result.reserve( m_catalog.size() );
66 std::transform( std::begin( m_catalog ), std::end( m_catalog ), std::back_inserter( result ), select1st );
67 return result;
68 }
69 // ============================================================================
70 const SvcCatalog::PropertiesT* SvcCatalog::findProperties( const std::string& client ) const {
71 auto result = m_catalog.find( client );
72 return ( result != m_catalog.end() ) ? &result->second : nullptr;
73 }
74 // ============================================================================
75 SvcCatalog::PropertiesT* SvcCatalog::findProperties( const std::string& client ) {
76 auto result = m_catalog.find( client );
77 return ( result != m_catalog.end() ) ? &result->second : nullptr;
78 }
79 // ============================================================================
80 std::pair<bool, SvcCatalog::PropertiesT::const_iterator> SvcCatalog::findProperty( const SvcCatalog::PropertiesT& props,
81 const std::string& name ) const {
82 auto p = std::find_if( std::begin( props ), std::end( props ), [&]( const Gaudi::Details::PropertyBase* prop ) {
83 return boost::iequals( name, prop->name() );
84 } );
85 return {p != std::end( props ), p};
86 }
87 // ============================================================================
88 std::pair<bool, SvcCatalog::PropertiesT::iterator> SvcCatalog::findProperty( SvcCatalog::PropertiesT& props,
89 const std::string& name ) {
90 auto p = std::find_if( std::begin( props ), std::end( props ), [&]( const Gaudi::Details::PropertyBase* prop ) {
91 return boost::iequals( name, prop->name() );
92 } );
93 return {p != std::end( props ), p};
94 }
95 // ============================================================================
96 std::ostream& SvcCatalog::fillStream( std::ostream& o ) const {
97 // loop over the clients:
98 for ( const auto& iclient : m_catalog ) {
99 o << "Client '" << iclient.first << "'" << std::endl;
100 for ( const auto& p : iclient.second ) {
101 if ( p ) o << "\t" << ( *p ) << std::endl;
102 }
103 }
104 //
105 return o; // RETURN
106 }
107 const Gaudi::Details::PropertyBase* SvcCatalog::getProperty( const std::string& client,
108 const std::string& name ) const {
109 auto props = findProperties( client );
110 if ( props ) {
111 const auto res = findProperty( *props, name );
112 if ( res.first ) { return *res.second; }
113 }
114 return nullptr;
115 }
116 // ============================================================================
117 // printoput operator
118 // ============================================================================
119 std::ostream& operator<<( std::ostream& o, const SvcCatalog& c ) { return c.fillStream( o ); }
120 // ============================================================================
121 // The END
122 // ============================================================================
SvcCatalog::findProperties
const PropertiesT * findProperties(const std::string &client) const
Definition: SvcCatalog.cpp:70
gaudirun.c
c
Definition: gaudirun.py:487
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
SvcCatalog::getProperties
const PropertiesT * getProperties(const std::string &client) const
Definition: SvcCatalog.cpp:59
SvcCatalog::getProperty
const Gaudi::Details::PropertyBase * getProperty(const std::string &client, const std::string &name) const
Definition: SvcCatalog.cpp:107
SvcCatalog::~SvcCatalog
~SvcCatalog()
Definition: SvcCatalog.cpp:30
std::endl
T endl(T... args)
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::end
T end(T... args)
SvcCatalog::addProperty
StatusCode addProperty(const std::string &client, const Gaudi::Details::PropertyBase *property)
Definition: SvcCatalog.cpp:36
SvcCatalog::findProperty
std::pair< bool, PropertiesT::const_iterator > findProperty(const PropertiesT &props, const std::string &name) const
Definition: SvcCatalog.cpp:80
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition: Property.h:36
operator<<
std::ostream & operator<<(std::ostream &o, const SvcCatalog &c)
printoput operator
Definition: SvcCatalog.cpp:119
SvcCatalog::removeProperty
StatusCode removeProperty(const std::string &client, const std::string &name)
Definition: SvcCatalog.cpp:47
std::string
STL class.
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
SvcCatalog::m_catalog
std::map< std::string, PropertiesT > m_catalog
Definition: SvcCatalog.h:47
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
SvcCatalog::getClients
std::vector< std::string > getClients() const
Definition: SvcCatalog.cpp:63
std::pair
std::find_if
T find_if(T... args)
std::vector
STL class.
std::begin
T begin(T... args)
SvcCatalog.h
std::back_inserter
T back_inserter(T... args)
SvcCatalog::fillStream
std::ostream & fillStream(std::ostream &o) const
dump the content of catalog to std::ostream
Definition: SvcCatalog.cpp:96
std::transform
T transform(T... args)
SvcCatalog
Definition: SvcCatalog.h:25
std::ostream
STL class.
std::vector::reserve
T reserve(T... args)