| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

PropertyMgr.cpp
Go to the documentation of this file.
1 // hide deprecation warnings here... the whole file is deprecated
2 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD& STL
7 // ============================================================================
8 #include <algorithm>
9 #include <functional>
10 #include <iostream>
11 #include <sstream>
12 #include <stdexcept>
13 #include <string>
14 // ============================================================================
15 // GaudiKernel
16 // ============================================================================
17 #include "GaudiKernel/Bootstrap.h"
18 #include "GaudiKernel/GaudiException.h"
19 #include "GaudiKernel/IMessageSvc.h"
20 #include "GaudiKernel/INamedInterface.h"
21 #include "GaudiKernel/ISvcLocator.h"
22 #include "GaudiKernel/PropertyMgr.h"
23 // ============================================================================
24
25 using Gaudi::Details::PropertyBase;
26
27 namespace
28 {
29 // ==========================================================================
31 constexpr struct NoCaseCmp_t {
32 inline bool operator()( const std::string& v1, const std::string& v2 ) const
33 {
34 return v1.size() == v2.size() && std::equal( std::begin( v1 ), std::end( v1 ), std::begin( v2 ),
35 []( char c1, char c2 ) { return toupper( c1 ) == toupper( c2 ); } );
36 }
37 } noCaseCmp{};
38 // ==========================================================================
40 struct PropByName {
41 std::string m_name;
42
43 inline bool operator()( const PropertyBase* p ) const { return p && noCaseCmp( p->name(), m_name ); }
44 };
45 // ==========================================================================
46 }
47 // ====================================================================
48 // constructor from the interface
49 // ====================================================================
50 PropertyMgr::PropertyMgr( IInterface* iface ) : m_pOuter( iface )
51 {
52 addRef(); // initial reference count set to 1
53 }
54 // ====================================================================
55 // Declare a remote property
56 // ====================================================================
57 PropertyBase* PropertyMgr::declareRemoteProperty( const std::string& name, IProperty* rsvc, const std::string& rname )
58 {
59 if ( !rsvc ) {
60 return nullptr;
61 }
62 const std::string& nam = rname.empty() ? name : rname;
63 PropertyBase* p = property( nam, rsvc->getProperties() );
64 m_remoteProperties.emplace_back( name, std::make_pair( rsvc, nam ) );
65 return p;
66 }
67 // ============================================================================
68 // Declare a property
69 // ============================================================================
70 PropertyBase*
71 PropertyMgr::declareProperty ( const std::string& name,
72 GaudiHandleBase& ref,
73 const std::string& doc )
74 {
75 assertUniqueName(name);
76 m_todelete . emplace_back (new GaudiHandleProperty( name, ref ));
77 Property* p = m_todelete.back().get();
78 //
79 p -> setDocumentation ( doc ) ;
80 m_properties . push_back ( p ) ;
81 //
82 return p ;
83 }
84 // ============================================================================
85 PropertyBase*
86 PropertyMgr::declareProperty ( const std::string& name,
87 GaudiHandleArrayBase& ref,
88 const std::string& doc )
89 {
90 assertUniqueName(name);
91 m_todelete . emplace_back ( new GaudiHandleArrayProperty( name, ref ) );
92 Property* p = m_todelete.back().get();
93 //
94 p -> setDocumentation ( doc ) ;
95 m_properties . push_back ( p ) ;
96 //
97 return p ;
98 }
99
100 // ============================================================================
101 PropertyBase*
102 PropertyMgr::declareProperty ( const std::string& name,
103 DataObjectHandleBase& ref,
104 const std::string& doc )
105 {
106 assertUniqueName(name);
107 m_todelete . emplace_back( new DataObjectHandleProperty( name, ref ) );
108 Property* p = m_todelete.back().get();
109 //
110 p -> setDocumentation ( doc ) ;
111 m_properties . push_back ( p ) ;
112 //
113 return p ;
114 }
115 // ====================================================================
116 // get the property by name form the proposed list
117 // ====================================================================
118 PropertyBase* PropertyMgr::property( const std::string& name, const std::vector<PropertyBase*>& props ) const
119 {
120 auto it = std::find_if( props.begin(), props.end(), PropByName{name} );
121 return ( it != props.end() ) ? *it : nullptr; // RETURN
122 }
123 // ====================================================================
124 // retrieve the property by name
125 // ====================================================================
126 PropertyBase* PropertyMgr::property( const std::string& name ) const
127 {
128 // local property ?
129 PropertyBase* lp = property( name, m_properties );
130 if ( lp ) {
131 return lp;
132 } // RETURN
133 // look for remote property
134 for ( const auto& it : m_remoteProperties ) {
135 if ( !noCaseCmp( it.first, name ) ) {
136 continue;
137 } // CONTINUE
138 const IProperty* p = it.second.first;
139 if ( !p ) {
140 continue;
141 } // CONTINUE
142 return property( it.second.second, p->getProperties() ); // RETURN
143 }
144 return nullptr; // RETURN
145 }
146 // ====================================================================
147 /* set a property from another property
148 * Implementation of IProperty::setProperty
149 */
150 // =====================================================================
151 StatusCode PropertyMgr::setProperty( const PropertyBase& p )
152 {
153 PropertyBase* pp = property( p.name() );
154 try {
155 if ( pp && pp->assign( p ) ) {
156 return StatusCode::SUCCESS;
157 }
158 } // RETURN
159 catch ( ... ) {
160 }
161 //
162 return StatusCode::FAILURE;
163 }
164 // ====================================================================
165 /* set a property from the stream
166 * Implementation of IProperty::setProperty
167 */
168 // =====================================================================
169 StatusCode PropertyMgr::setProperty( const std::string& i )
170 {
171 std::string name;
172 std::string value;
173 StatusCode sc = Gaudi::Parsers::parse( name, value, i );
174 if ( sc.isFailure() ) {
175 return sc;
176 }
177 return setProperty( name, value );
178 }
179 // =====================================================================
180 /* set a property from the string
181 * Implementation of IProperty::setProperty
182 */
183 // =====================================================================
184 StatusCode PropertyMgr::setProperty( const std::string& n, const std::string& v )
185 {
186 PropertyBase* p = property( n );
187 return ( p && p->fromString( v ) ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
188 }
189 // =====================================================================
190 /* Retrieve the value of a property
191 * Implementation of IProperty::getProperty
192 */
193 // =====================================================================
194 StatusCode PropertyMgr::getProperty( PropertyBase* p ) const
195 {
196 try {
197 const PropertyBase* pp = property( p->name() );
198 if ( pp && pp->load( *p ) ) return StatusCode::SUCCESS; // RETURN
199 } catch ( ... ) {
200 }
201 return StatusCode::FAILURE; // RETURN
202 }
203 // =====================================================================
204 /* Get the property by name
205 * Implementation of IProperty::getProperty
206 */
207 // =====================================================================
208 const PropertyBase& PropertyMgr::getProperty( const std::string& name ) const
209 {
210 const PropertyBase* p = property( name );
211 if ( !p ) throw std::out_of_range( "Property " + name + " not found." ); // Not found
212 return *p; // RETURN
213 }
214 // =====================================================================
215 /* Get the property by name
216 * Implementation of IProperty::getProperty
217 */
218 // =====================================================================
219 StatusCode PropertyMgr::getProperty( const std::string& n, std::string& v ) const
220 {
221 // get the property
222 const PropertyBase* p = property( n );
223 if ( !p ) {
224 return StatusCode::FAILURE;
225 }
226 // convert the value into the string
227 v = p->toString();
228 //
229 return StatusCode::SUCCESS;
230 }
231 // =====================================================================
232 // Implementation of IProperty::getProperties
233 // =====================================================================
234 const std::vector<PropertyBase*>& PropertyMgr::getProperties() const { return m_properties; }
235 // =====================================================================
236 // Implementation of IInterface::queryInterface
237 // =====================================================================
238 StatusCode PropertyMgr::queryInterface( const InterfaceID& iid, void** pinterface )
239 {
240 // try local interfaces
241 StatusCode sc = base_class::queryInterface( iid, pinterface );
242 if ( sc.isSuccess() ) return sc;
243 // fall back on the owner
244 return m_pOuter ? m_pOuter->queryInterface( iid, pinterface ) : sc; // FAILURE
245 }
246 // =====================================================================
247 // Implementation of IProperty::hasProperty
248 // =====================================================================
249 bool PropertyMgr::hasProperty( const std::string& name ) const
250 {
251 return any_of( begin( m_properties ), end( m_properties ),
252 [&name]( const PropertyBase* prop ) { return noCaseCmp( prop->name(), name ); } );
253 }
254 void PropertyMgr::assertUniqueName( const std::string& name ) const
255 {
256 if ( UNLIKELY( hasProperty( name ) ) ) {
257 auto owner = SmartIF<INamedInterface>( m_pOuter );
258 auto msgSvc = Gaudi::svcLocator()->service<IMessageSvc>( "MessageSvc" );
259 if ( !msgSvc ) {
260 std::cerr << "error: cannot get MessageSvc!" << std::endl;
261 }
262 MsgStream log( msgSvc, owner ? owner->name() : "PropertyMgr" );
263 log << MSG::WARNING << "duplicated property name '" << name << "', see https://its.cern.ch/jira/browse/GAUDI-1023"
264 << endmsg;
265 }
266 }
267 // =====================================================================
268 // The END
269 // =====================================================================
Gaudi::Utils::setProperty
StatusCode setProperty(IProperty *component, const std::string &name, const TYPE &value, const std::string &doc)
simple function to set the property of the given object from the value
Definition: Property.h:1138
std::out_of_range
STL class.
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode::SUCCESS
Definition: StatusCode.h:30
SmartIF< INamedInterface >
HiveAlgSequencer.c2
c2
Definition: HiveAlgSequencer.py:26
std::string::empty
T empty(T...args)
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
StatusCode::FAILURE
Definition: StatusCode.h:29
Gaudi::Details::PropertyBase::load
virtual bool load(PropertyBase &dest) const =0
export the property value to the destination
Gaudi::Details::PropertyBase::assign
virtual bool assign(const PropertyBase &source)=0
import the property value form the source
Gaudi::Details::PropertyBase::name
const std::string name() const
property name
Definition: Property.h:40
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
std::endl
T endl(T...args)
property
Gaudi::Details::PropertyBase * property(const std::string &name) const
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:126
Bootstrap.h
declareRemoteProperty
Gaudi::Details::PropertyBase * declareRemoteProperty(const std::string &name, IProperty *rsvc, const std::string &rname="")
Declare a remote property.
Gaudi::Parsers::parse
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
Definition: DODBasicMapper.cpp:11
std::end
T end(T...args)
Gaudi::Functional::details::details2::push_back
void push_back(Container &c, const Value &v, std::true_type)
Definition: FunctionalDetails.h:154
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).
Gaudi::Details::PropertyBase::toString
virtual std::string toString() const =0
value -> string
Property
Gaudi::Details::PropertyBase Property
backward compatibility hack for old Property base class
Definition: PropertyFwd.h:28
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
Gaudi::Details::PropertyBase::fromString
virtual StatusCode fromString(const std::string &value)=0
string -> value
begin
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:48
DataObjectHandleProperty
DataObjectHandleProperty.h GaudiKernel/DataObjectHandleProperty.h.
Definition: DataObjectHandleProperty.h:23
std::string
STL class.
compareRootHistos.ref
string ref
Definition: compareRootHistos.py:14
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:217
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:78
InterfaceID
Interface ID class.
Definition: IInterface.h:30
INamedInterface.h
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
PropertyMgr
class GAUDI_API[[deprecated("will be removed in v29r0, consider using PropertyHolder instead")]] PropertyMgr
Definition: PropertyMgr.h:32
hasProperty
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
declareProperty
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, TYPE &value, const std::string &doc="none")
Declare a property (templated)
ForwardSchedulerSimpleTest.msgSvc
msgSvc
Definition: ForwardSchedulerSimpleTest.py:112
GaudiException.h
IInterface
Definition of the basic interface.
Definition: IInterface.h:234
IMessageSvc
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
std::make_pair
T make_pair(T...args)
GaudiPython.Bindings.GaudiHandleArrayProperty
GaudiHandleArrayProperty
Definition: Bindings.py:50
end
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:50
IMessageSvc.h
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
IProperty::getProperties
virtual const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const =0
Get list of properties.
std::unique_ptr::get
T get(T...args)
std::find_if
T find_if(T...args)
std::string::size
T size(T...args)
GaudiHandleArrayBase
Base class of array&#39;s of various gaudihandles.
Definition: GaudiHandle.h:364
std::vector
STL class.
Gaudi::Functional::operator()
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
DataObjectHandleBase
DataObjectHandleBase GaudiKernel/DataObjectHandleBase.h.
Definition: DataObjectHandleBase.h:24
std::begin
T begin(T...args)
std::any_of
T any_of(T...args)
PropertyMgr.h
m_properties
Properties m_properties
Collection of all declared properties.
Definition: PropertyMgr.h:144
std::vector::back
T back(T...args)
GaudiPython.Bindings.GaudiHandleProperty
GaudiHandleProperty
Definition: Bindings.py:49
compareOutputFiles.pp
pp
Definition: compareOutputFiles.py:417
m_todelete
std::vector< std::unique_ptr< Gaudi::Details::PropertyBase > > m_todelete
Properties to be deleted.
Definition: PropertyMgr.h:148
MSG::WARNING
Definition: IMessageSvc.h:20
GaudiHandleBase
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
Definition: GaudiHandle.h:94
queryInterface
StatusCode queryInterface(const InterfaceID &iid, void **pinterface) override
IProperty
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:20
getProperties
const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const override
get all properties
std::cerr
ISvcLocator.h
std::equal
T equal(T...args)
toupper
void toupper(std::string &s)
Definition: StatusCodeSvc.cpp:10
m_pOuter
IInterface * m_pOuter
Interface hub reference (ApplicationMgr)
Definition: PropertyMgr.h:150
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
m_remoteProperties
RemoteProperties m_remoteProperties
Collection of all declared remote properties.
Definition: PropertyMgr.h:146
HiveAlgSequencer.c1
c1
Definition: HiveAlgSequencer.py:25
Gaudi.Configuration.log
log
Definition: Configuration.py:13
Gaudi::Utils::getProperty
GAUDI_API Gaudi::Details::PropertyBase * getProperty(const IProperty *p, const std::string &name)
simple function which gets the property with given name from the component
Definition: Property.cpp:223
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::emplace_back
T emplace_back(T...args)