The Gaudi Framework  master (37c0b60a)
PropertyMgr Class Reference

#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<Gaudi::DataHandle, 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, Gaudi::DataHandle &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 std::string &name, 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 setPropertyRepr (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 (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...
 
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 (std::string_view 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 (std::string_view 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 43 of file PropertyMgr.h.

Member Typedef Documentation

◆ Properties

Definition at line 142 of file PropertyMgr.h.

◆ RemoteProperties

Definition at line 144 of file PropertyMgr.h.

◆ RemProperty

Constructor & Destructor Documentation

◆ PropertyMgr() [1/2]

PropertyMgr::PropertyMgr ( IInterface iface = nullptr)

constructor from the interface

Definition at line 51 of file PropertyMgr.cpp.

51  : m_pOuter( iface ) {
52  addRef(); // initial reference count set to 1
53 }

◆ 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 ( !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 }

◆ declareProperty() [1/6]

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

Declare a property (specialization)

Definition at line 89 of file PropertyMgr.cpp.

89  {
91  auto p = m_todelete.emplace_back( std::make_unique<typename Gaudi::DataHandle::PropertyType>( name, ref ) ).get();
92  //
93  p->setDocumentation( doc );
95  //
96  return p;
97 }

◆ 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.

Definition at line 190 of file PropertyMgr.h.

190  {
192  Gaudi::Details::PropertyBase* p = &prop;
193  //
194  p->setName( name );
195  p->setDocumentation( doc );
196  m_properties.push_back( p );
197  //
198  return p;
199 }

◆ 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 (templated)

Definition at line 174 of file PropertyMgr.h.

175  {
177  Gaudi::Details::PropertyBase* p = &prop;
178  //
179  p->setName( name );
180  p->setDocumentation( doc );
181  m_properties.push_back( p );
182  //
183  return p;
184 }

◆ declareProperty() [4/6]

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

Declare a property (specialization)

Definition at line 77 of file PropertyMgr.cpp.

78  {
80  auto p = m_todelete.emplace_back( std::make_unique<typename GaudiHandleArrayBase::PropertyType>( name, ref ) ).get();
81  //
82  p->setDocumentation( doc );
84  //
85  return p;
86 }

◆ declareProperty() [5/6]

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

Declare a property (specialization)

Definition at line 67 of file PropertyMgr.cpp.

67  {
69  auto p = m_todelete.emplace_back( std::make_unique<typename GaudiHandleBase::PropertyType>( name, ref ) ).get();
70  //
71  p->setDocumentation( doc );
73  //
74  return p;
75 }

◆ declareProperty() [6/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 159 of file PropertyMgr.h.

160  {
164  //
165  p->setDocumentation( doc );
166  m_properties.push_back( p );
167  //
168  return p;
169 }

◆ declareRemoteProperty()

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

Declare a remote property.

Definition at line 57 of file PropertyMgr.cpp.

57  {
58  if ( !rsvc ) return nullptr;
59  const std::string& nam = rname.empty() ? name : rname;
60  PropertyBase* p = property( nam, rsvc->getProperties() );
62  return p;
63 }

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

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

◆ getProperty() [2/3]

StatusCode PropertyMgr::getProperty ( std::string_view  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 }

◆ getProperty() [3/3]

const PropertyBase & PropertyMgr::getProperty ( std::string_view  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 " + std::string{ name } + " not found." ); // Not found
175  return *p; // RETURN
176 }

◆ hasProperty()

bool PropertyMgr::hasProperty ( std::string_view  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 }

◆ operator=()

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

◆ property() [1/2]

PropertyBase * PropertyMgr::property ( std::string_view  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 }

◆ property() [2/2]

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

get the property by name form the proposed list

Definition at line 101 of file PropertyMgr.cpp.

101  {
102  auto it = std::find_if( props.begin(), props.end(),
103  [=]( const PropertyBase* p ) { return p && noCaseCmp( p->name(), name ); } );
104  return ( it != props.end() ) ? *it : nullptr; // RETURN
105 }

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

◆ setProperty() [1/2]

StatusCode PropertyMgr::setProperty ( const std::string name,
const Gaudi::Details::PropertyBase p 
)
override

set the property form another property

See also
IProperty

Definition at line 127 of file PropertyMgr.cpp.

127  {
129  try {
130  if ( pp && pp->assign( p ) ) return StatusCode::SUCCESS;
131  } // RETURN
132  catch ( ... ) {}
133  //
134  return StatusCode::FAILURE;
135 }

◆ setProperty() [2/2]

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 : setPropertyRepr( name, value );
145 }

◆ setPropertyRepr()

StatusCode PropertyMgr::setPropertyRepr ( 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 }

Member Data Documentation

◆ m_pOuter

IInterface* PropertyMgr::m_pOuter
private

Interface hub reference (ApplicationMgr)

Definition at line 153 of file PropertyMgr.h.

◆ m_properties

Properties PropertyMgr::m_properties
private

Collection of all declared properties.

Definition at line 147 of file PropertyMgr.h.

◆ m_remoteProperties

RemoteProperties PropertyMgr::m_remoteProperties
private

Collection of all declared remote properties.

Definition at line 149 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 151 of file PropertyMgr.h.


The documentation for this class was generated from the following files:
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: PropertyBase.h:35
implements::queryInterface
StatusCode queryInterface(const InterfaceID &ti, void **pp) override
Implementation of IInterface::queryInterface.
Definition: implements.h:30
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition: PropertyBase.h:39
std::string
STL class.
IMessageSvc
Definition: IMessageSvc.h:47
Gaudi.Configuration.log
log
Definition: Configuration.py:28
PropertyMgr::property
Gaudi::Details::PropertyBase * property(std::string_view name) const
Definition: PropertyMgr.cpp:109
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
Gaudi::Parsers::parse
StatusCode parse(GaudiUtils::HashMap< K, V > &result, std::string_view input)
Basic parser for the types of HashMap used in DODBasicMapper.
Definition: DODBasicMapper.cpp:21
std::find_if
T find_if(T... args)
check_ParticleID.props
props
Definition: check_ParticleID.py:21
PropertyMgr::m_pOuter
IInterface * m_pOuter
Interface hub reference (ApplicationMgr)
Definition: PropertyMgr.h:153
std::unique_ptr::get
T get(T... args)
MSG::WARNING
@ WARNING
Definition: IMessageSvc.h:25
IInterface::queryInterface
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.
std::vector::back
T back(T... args)
std::any_of
T any_of(T... args)
Gaudi::Details::PropertyBase::fromString
virtual StatusCode fromString(const std::string &value)=0
string -> value
AvalancheSchedulerErrorTest.msgSvc
msgSvc
Definition: AvalancheSchedulerErrorTest.py:80
std::vector::push_back
T push_back(T... args)
IProperty
Definition: IProperty.h:33
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
Gaudi::Details::PropertyBase::setDocumentation
void setDocumentation(std::string value)
set the documentation string
Definition: PropertyBase.h:91
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:136
PropertyMgr::assertUniqueName
void assertUniqueName(const std::string &name) const
Throw an exception if the name is already present in the list of properties (see GAUDI-1023).
Definition: PropertyMgr.cpp:212
StatusCode
Definition: StatusCode.h:65
PropertyMgr::hasProperty
bool hasProperty(std::string_view name) const override
Return true if we have a property with the given name.
Definition: PropertyMgr.cpp:208
PropertyMgr::m_todelete
std::vector< std::unique_ptr< Gaudi::Details::PropertyBase > > m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:151
std::cerr
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:98
PropertyMgr::setPropertyRepr
StatusCode setPropertyRepr(const std::string &n, const std::string &v) override
set the property from name and the value
Definition: PropertyMgr.cpp:151
SmartIF
Definition: IConverter.h:25
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
MsgStream
Definition: MsgStream.h:33
implements< IProperty >::addRef
unsigned long addRef() override
Reference Interface instance
Definition: implements.h:48
cpluginsvc.n
n
Definition: cpluginsvc.py:234
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
std::vector::emplace_back
T emplace_back(T... args)
PropertyMgr::m_remoteProperties
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
Definition: PropertyMgr.h:149
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
std::endl
T endl(T... args)
IProperty::getProperties
virtual const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const =0
Get list of properties.
PropertyMgr::m_properties
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:147
Gaudi::Details::PropertyBase::toString
virtual std::string toString() const =0
value -> string
std::string::empty
T empty(T... args)
Properties.v
v
Definition: Properties.py:122
std::out_of_range
STL class.
Gaudi::Details::PropertyBase::setName
void setName(std::string value)
set the new value for the property name
Definition: PropertyBase.h:89
std::make_pair
T make_pair(T... args)
IOTest.end
end
Definition: IOTest.py:125
compareRootHistos.ref
ref
Definition: compareRootHistos.py:27
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
compareOutputFiles.pp
pp
Definition: compareOutputFiles.py:507
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:37