The Gaudi Framework  v32r2 (46d42edc)
PropertyMgr Class Reference

Property manager helper class. More...

#include <GaudiKernel/PropertyMgr.h>

Inheritance diagram for PropertyMgr:
Collaboration diagram for PropertyMgr:

Public Member Functions

 PropertyMgr (IInterface *iface=nullptr)
 constructor from the interface More...
 
 PropertyMgr (const PropertyMgr &)=delete
 
PropertyMgroperator= (const PropertyMgr &)=delete
 
template<class TYPE , typename = std::enable_if_t<!std::is_base_of_v<GaudiHandleBase, TYPE> && !std::is_base_of_v<GaudiHandleArrayBase, TYPE> && !std::is_base_of_v<DataObjectHandleBase, TYPE>>>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Declare a property (templated) More...
 
template<class TYPE >
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE > &prop, const std::string &doc="none")
 Declare a property (specialization) More...
 
template<class TYPE >
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE & > &prop, const std::string &doc="none")
 Declare a property (specialization) More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, GaudiHandleBase &ref, const std::string &doc="none")
 Declare a property (specialization) More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, GaudiHandleArrayBase &ref, const std::string &doc="none")
 Declare a property (specialization) More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, DataObjectHandleBase &ref, const std::string &doc="none")
 Declare a property (specialization) More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p) override
 set the property form another property More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the property formatted string More...
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 set the property from name and the value More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (const std::string &name) const override
 get the property by name More...
 
StatusCode getProperty (const std::string &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 (const std::string &name) const override
 Return true if we have a property with the given name. More...
 
StatusCode queryInterface (const InterfaceID &iid, void **pinterface) override
 
- Public Member Functions inherited from implements< IProperty >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 implements ()=default
 Default constructor. More...
 
 implements (const implements &)
 Copy constructor (zero the reference count) More...
 
implementsoperator= (const implements &)
 Assignment operator (do not touch the reference count). More...
 
unsigned long addRef () override
 Reference Interface instance. More...
 
unsigned long release () override
 Release Interface instance. More...
 
unsigned long refCount () const override
 Current reference count. More...
 

Protected Member Functions

Gaudi::Details::PropertyBaseproperty (const std::string &name) const
 

Private Types

typedef std::vector< Gaudi::Details::PropertyBase * > Properties
 
typedef std::pair< std::string, std::pair< IProperty *, std::string > > RemProperty
 
typedef std::vector< RemPropertyRemoteProperties
 

Private Member Functions

Gaudi::Details::PropertyBaseproperty (const std::string &name, const std::vector< Gaudi::Details::PropertyBase * > &props) const
 get the property by name form the proposed list More...
 
void assertUniqueName (const std::string &name) const
 Throw an exception if the name is already present in the list of properties (see GAUDI-1023). More...
 

Private Attributes

Properties m_properties
 Collection of all declared properties. More...
 
RemoteProperties m_remoteProperties
 Collection of all declared remote properties. More...
 
std::vector< std::unique_ptr< Gaudi::Details::PropertyBase > > m_todelete
 Properties to be deleted. More...
 
IInterfacem_pOuter
 Interface hub reference (ApplicationMgr) More...
 

Additional Inherited Members

- Public Types inherited from implements< IProperty >
using base_class = implements< Interfaces... >
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces... >
 Typedef to the base of this class. More...
 
using iids = typename extend_interfaces_base::ext_iids
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Attributes inherited from implements< IProperty >
std::atomic_ulong m_refCount
 Reference counter. More...
 

Detailed Description

Property manager helper class.

This class is used by algorithms and services for helping to manage its own set of properties. It implements the IProperty interface.

Author
Paul Maley
David Quarrie
Deprecated:
will be removed in v29r0, consider using PropertyHolder instead

Definition at line 33 of file PropertyMgr.h.

Member Typedef Documentation

◆ Properties

Definition at line 132 of file PropertyMgr.h.

◆ RemoteProperties

Definition at line 134 of file PropertyMgr.h.

◆ RemProperty

Constructor & Destructor Documentation

◆ PropertyMgr() [1/2]

PropertyMgr::PropertyMgr ( IInterface iface = nullptr)

constructor from the interface

Definition at line 48 of file PropertyMgr.cpp.

48  : m_pOuter( iface ) {
49  addRef(); // initial reference count set to 1
50 }
IInterface * m_pOuter
Interface hub reference (ApplicationMgr)
Definition: PropertyMgr.h:143
unsigned long addRef() override
Reference Interface instance.
Definition: implements.h:38

◆ PropertyMgr() [2/2]

PropertyMgr::PropertyMgr ( const PropertyMgr )
delete

Member Function Documentation

◆ assertUniqueName()

void PropertyMgr::assertUniqueName ( const std::string name) const
private

Throw an exception if the name is already present in the list of properties (see GAUDI-1023).

Definition at line 212 of file PropertyMgr.cpp.

212  {
213  if ( LIKELY( !hasProperty( name ) ) ) return;
214  auto msgSvc = Gaudi::svcLocator()->service<IMessageSvc>( "MessageSvc" );
215  if ( !msgSvc ) std::cerr << "error: cannot get MessageSvc!" << std::endl;
216  auto owner = SmartIF<INamedInterface>( m_pOuter );
217  MsgStream log( msgSvc, owner ? owner->name() : "PropertyMgr" );
218  log << MSG::WARNING << "duplicated property name '" << name << "', see https://its.cern.ch/jira/browse/GAUDI-1023"
219  << endmsg;
220 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
IInterface * m_pOuter
Interface hub reference (ApplicationMgr)
Definition: PropertyMgr.h:143
T endl(T... args)
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:76
GAUDI_API ISvcLocator * svcLocator()
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:37
#define LIKELY(x)
Definition: Kernel.h:95
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ declareProperty() [1/6]

template<class TYPE , typename >
Gaudi::Details::PropertyBase * PropertyMgr::declareProperty ( const std::string name,
TYPE &  value,
const std::string doc = "none" 
)
inline

Declare a property (templated)

Definition at line 149 of file PropertyMgr.h.

150  {
154  //
155  p->setDocumentation( doc );
156  m_properties.push_back( p );
157  //
158  return p;
159 }
std::vector< std::unique_ptr< Gaudi::Details::PropertyBase > > m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:141
void setDocumentation(std::string value)
set the documentation string
Definition: Property.h:86
Implementation of property with value of concrete type.
Definition: Property.h:352
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
T push_back(T... args)
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:137
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
T get(T... args)
T back(T... args)
T emplace_back(T... args)

◆ declareProperty() [2/6]

template<class TYPE >
Gaudi::Details::PropertyBase * PropertyMgr::declareProperty ( const std::string name,
Gaudi::Property< TYPE > &  prop,
const std::string doc = "none" 
)
inline

Declare a property (specialization)

Declare a property (templated)

Definition at line 164 of file PropertyMgr.h.

165  {
167  Gaudi::Details::PropertyBase* p = &prop;
168  //
169  p->setName( name );
170  p->setDocumentation( doc );
171  m_properties.push_back( p );
172  //
173  return p;
174 }
void setDocumentation(std::string value)
set the documentation string
Definition: Property.h:86
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
T push_back(T... args)
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:137
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
void setName(std::string value)
set the new value for the property name
Definition: Property.h:84

◆ declareProperty() [3/6]

template<class TYPE >
Gaudi::Details::PropertyBase * PropertyMgr::declareProperty ( const std::string name,
Gaudi::Property< TYPE & > &  prop,
const std::string doc = "none" 
)
inline

Declare a property (specialization)

Declare a property.

Definition at line 180 of file PropertyMgr.h.

180  {
182  Gaudi::Details::PropertyBase* p = &prop;
183  //
184  p->setName( name );
185  p->setDocumentation( doc );
186  m_properties.push_back( p );
187  //
188  return p;
189 }
void setDocumentation(std::string value)
set the documentation string
Definition: Property.h:86
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
T push_back(T... args)
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:137
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
void setName(std::string value)
set the new value for the property name
Definition: Property.h:84

◆ declareProperty() [4/6]

PropertyBase * PropertyMgr::declareProperty ( const std::string name,
GaudiHandleBase ref,
const std::string doc = "none" 
)

Declare a property (specialization)

Definition at line 64 of file PropertyMgr.cpp.

64  {
67  Property* p = m_todelete.back().get();
68  //
69  p->setDocumentation( doc );
71  //
72  return p;
73 }
std::vector< std::unique_ptr< Gaudi::Details::PropertyBase > > m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:141
void setDocumentation(std::string value)
set the documentation string
Definition: Property.h:86
Gaudi::Details::PropertyBase Property
\fixme backward compatibility hack for old Property base class
Definition: PropertyFwd.h:25
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
T push_back(T... args)
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:137
T get(T... args)
T back(T... args)
T emplace_back(T... args)

◆ declareProperty() [5/6]

PropertyBase * PropertyMgr::declareProperty ( const std::string name,
GaudiHandleArrayBase ref,
const std::string doc = "none" 
)

Declare a property (specialization)

Definition at line 75 of file PropertyMgr.cpp.

76  {
79  Property* p = m_todelete.back().get();
80  //
81  p->setDocumentation( doc );
83  //
84  return p;
85 }
std::vector< std::unique_ptr< Gaudi::Details::PropertyBase > > m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:141
void setDocumentation(std::string value)
set the documentation string
Definition: Property.h:86
Gaudi::Details::PropertyBase Property
\fixme backward compatibility hack for old Property base class
Definition: PropertyFwd.h:25
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
T push_back(T... args)
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:137
T get(T... args)
T back(T... args)
T emplace_back(T... args)

◆ declareProperty() [6/6]

PropertyBase * PropertyMgr::declareProperty ( const std::string name,
DataObjectHandleBase ref,
const std::string doc = "none" 
)

Declare a property (specialization)

Definition at line 88 of file PropertyMgr.cpp.

89  {
92  Property* p = m_todelete.back().get();
93  //
94  p->setDocumentation( doc );
96  //
97  return p;
98 }
std::vector< std::unique_ptr< Gaudi::Details::PropertyBase > > m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:141
void setDocumentation(std::string value)
set the documentation string
Definition: Property.h:86
Gaudi::Details::PropertyBase Property
\fixme backward compatibility hack for old Property base class
Definition: PropertyFwd.h:25
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
DataObjectHandleProperty.h GaudiKernel/DataObjectHandleProperty.h.
T push_back(T... args)
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:137
T get(T... args)
T back(T... args)
T emplace_back(T... args)

◆ declareRemoteProperty()

PropertyBase * PropertyMgr::declareRemoteProperty ( const std::string name,
IProperty rsvc,
const std::string rname = "" 
)

Declare a remote property.

Definition at line 54 of file PropertyMgr.cpp.

54  {
55  if ( !rsvc ) return nullptr;
56  const std::string& nam = rname.empty() ? name : rname;
57  PropertyBase* p = property( nam, rsvc->getProperties() );
59  return p;
60 }
T empty(T... args)
STL class.
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
Definition: PropertyMgr.h:139
T make_pair(T... args)
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Gaudi::Details::PropertyBase * property(const std::string &name) const
virtual const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const =0
Get list of properties.
T emplace_back(T... args)

◆ getProperties()

const std::vector< PropertyBase * > & PropertyMgr::getProperties ( ) const
override

get all properties

See also
IProperty

Definition at line 194 of file PropertyMgr.cpp.

194 { return m_properties; }
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:137

◆ getProperty() [1/3]

StatusCode PropertyMgr::getProperty ( Gaudi::Details::PropertyBase p) const
override

get the property

See also
IProperty

Definition at line 160 of file PropertyMgr.cpp.

160  {
161  try {
162  const PropertyBase* pp = property( p->name() );
163  if ( pp && pp->load( *p ) ) return StatusCode::SUCCESS; // RETURN
164  } catch ( ... ) {}
165  return StatusCode::FAILURE; // RETURN
166 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
const std::string name() const
property name
Definition: Property.h:36
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Gaudi::Details::PropertyBase * property(const std::string &name) const
constexpr static const auto FAILURE
Definition: StatusCode.h:86

◆ getProperty() [2/3]

const PropertyBase & PropertyMgr::getProperty ( const std::string name) const
override

get the property by name

See also
IProperty

Definition at line 172 of file PropertyMgr.cpp.

172  {
173  const PropertyBase* p = property( name );
174  if ( !p ) throw std::out_of_range( "Property " + name + " not found." ); // Not found
175  return *p; // RETURN
176 }
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Gaudi::Details::PropertyBase * property(const std::string &name) const

◆ getProperty() [3/3]

StatusCode PropertyMgr::getProperty ( const std::string n,
std::string v 
) const
override

convert the property to the string

See also
IProperty

Definition at line 182 of file PropertyMgr.cpp.

182  {
183  // get the property
184  const PropertyBase* p = property( n );
185  if ( !p ) return StatusCode::FAILURE;
186  // convert the value into the string
187  v = p->toString();
188  //
189  return StatusCode::SUCCESS;
190 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Gaudi::Details::PropertyBase * property(const std::string &name) const
constexpr static const auto FAILURE
Definition: StatusCode.h:86
virtual std::string toString() const =0
value -> string

◆ hasProperty()

bool PropertyMgr::hasProperty ( const std::string name) const
override

Return true if we have a property with the given name.

See also
IProperty

Definition at line 208 of file PropertyMgr.cpp.

208  {
209  return any_of( begin( m_properties ), end( m_properties ),
210  [&name]( const PropertyBase* prop ) { return noCaseCmp( prop->name(), name ); } );
211 }
const std::string name() const
property name
Definition: Property.h:36
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:137
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
def end
Definition: IOTest.py:113
T any_of(T... args)
AttribStringParser::Iterator begin(const AttribStringParser &parser)

◆ operator=()

PropertyMgr& PropertyMgr::operator= ( const PropertyMgr )
delete

◆ property() [1/2]

PropertyBase * PropertyMgr::property ( const std::string name) const
protected

Definition at line 109 of file PropertyMgr.cpp.

109  {
110  // local property ?
112  if ( lp ) return lp; // RETURN
113  // look for remote property
114  for ( const auto& it : m_remoteProperties ) {
115  if ( !noCaseCmp( it.first, name ) ) continue; // CONTINUE
116  const IProperty* p = it.second.first;
117  if ( !p ) continue;
118  return property( it.second.second, p->getProperties() ); // RETURN
119  }
120  return nullptr; // RETURN
121 }
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:137
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
Definition: PropertyMgr.h:139
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Gaudi::Details::PropertyBase * property(const std::string &name) const
virtual const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const =0
Get list of properties.
The IProperty is the basic interface for all components which have properties that can be set or get.
Definition: IProperty.h:20

◆ property() [2/2]

PropertyBase * PropertyMgr::property ( const std::string name,
const std::vector< Gaudi::Details::PropertyBase * > &  props 
) const
private

get the property by name form the proposed list

Definition at line 102 of file PropertyMgr.cpp.

102  {
103  auto it = std::find_if( props.begin(), props.end(), PropByName{name} );
104  return ( it != props.end() ) ? *it : nullptr; // RETURN
105 }
T end(T... args)
T find_if(T... args)
T begin(T... args)

◆ queryInterface()

StatusCode PropertyMgr::queryInterface ( const InterfaceID iid,
void **  pinterface 
)
override

Definition at line 198 of file PropertyMgr.cpp.

198  {
199  // try local interfaces
200  StatusCode sc = base_class::queryInterface( iid, pinterface );
201  if ( sc.isSuccess() ) return sc;
202  // fall back on the owner
203  return m_pOuter ? m_pOuter->queryInterface( iid, pinterface ) : sc; // FAILURE
204 }
IInterface * m_pOuter
Interface hub reference (ApplicationMgr)
Definition: PropertyMgr.h:143
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
bool isSuccess() const
Definition: StatusCode.h:267
StatusCode queryInterface(const InterfaceID &ti, void **pp) override
Implementation of IInterface::queryInterface.
Definition: implements.h:20
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.

◆ setProperty() [1/3]

StatusCode PropertyMgr::setProperty ( const Gaudi::Details::PropertyBase p)
override

set the property form another property

See also
IProperty

Definition at line 127 of file PropertyMgr.cpp.

127  {
128  PropertyBase* pp = property( p.name() );
129  try {
130  if ( pp && pp->assign( p ) ) return StatusCode::SUCCESS;
131  } // RETURN
132  catch ( ... ) {}
133  //
134  return StatusCode::FAILURE;
135 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
const std::string name() const
property name
Definition: Property.h:36
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Gaudi::Details::PropertyBase * property(const std::string &name) const
constexpr static const auto FAILURE
Definition: StatusCode.h:86

◆ setProperty() [2/3]

StatusCode PropertyMgr::setProperty ( const std::string s)
override

set the property from the property formatted string

See also
IProperty

Definition at line 141 of file PropertyMgr.cpp.

141  {
142  std::string name, value;
143  StatusCode sc = Gaudi::Parsers::parse( name, value, i );
144  return sc.isFailure() ? sc : setProperty( name, value );
145 }
StatusCode setProperty(const Gaudi::Details::PropertyBase &p) override
set the property form another property
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
STL class.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
bool isFailure() const
Definition: StatusCode.h:130

◆ setProperty() [3/3]

StatusCode PropertyMgr::setProperty ( const std::string n,
const std::string v 
)
override

set the property from name and the value

See also
IProperty

Definition at line 151 of file PropertyMgr.cpp.

151  {
152  PropertyBase* p = property( n );
153  return ( p && p->fromString( v ) ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
154 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
virtual StatusCode fromString(const std::string &value)=0
string -> value
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Gaudi::Details::PropertyBase * property(const std::string &name) const
constexpr static const auto FAILURE
Definition: StatusCode.h:86

Member Data Documentation

◆ m_pOuter

IInterface* PropertyMgr::m_pOuter
private

Interface hub reference (ApplicationMgr)

Definition at line 143 of file PropertyMgr.h.

◆ m_properties

Properties PropertyMgr::m_properties
private

Collection of all declared properties.

Definition at line 137 of file PropertyMgr.h.

◆ m_remoteProperties

RemoteProperties PropertyMgr::m_remoteProperties
private

Collection of all declared remote properties.

Definition at line 139 of file PropertyMgr.h.

◆ m_todelete

std::vector<std::unique_ptr<Gaudi::Details::PropertyBase> > PropertyMgr::m_todelete
private

Properties to be deleted.

Definition at line 141 of file PropertyMgr.h.


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