The Gaudi Framework  master (37c0b60a)
ExtendedProperties.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 files
13 // ============================================================================
14 // STD & STL
15 // ============================================================================
16 #include <array>
17 #include <map>
18 #include <string>
19 #include <tuple>
20 #include <unordered_set>
21 #include <utility>
22 #include <vector>
23 
24 #include <GaudiKernel/Map.h>
25 
26 // ============================================================================
27 // Include parsers for creating parser that handles tuple
28 // ============================================================================
29 #include <Gaudi/Parsers/Factory.h>
31 
32 #include <GaudiKernel/Algorithm.h>
33 // ============================================================================
34 
35 #ifdef __ICC
36 // disable icc remark #177: declared but never referenced
37 # pragma warning( disable : 177 )
38 #endif
39 
56 class ExtendedProperties : public Algorithm {
57 public:
58  StatusCode execute() override;
59 
61  setProperty( "PropertiesPrint", true ).ignore();
62 
63  m_20["key"] = "value";
64  m_21.value().push_back( 123 );
65  }
66 
67 private:
69 
71  Gaudi::Property<std::vector<std::vector<std::string>>> m_3{ this, "VectorOfVectorsString" };
72  Gaudi::Property<std::vector<std::vector<double>>> m_4{ this, "VectorOfVectorsDouble" };
73 
74  Gaudi::Property<std::map<int, double>> m_5{ this, "MapIntDouble" };
79 
81  Gaudi::Property<std::map<std::string, std::vector<double>>> m_11{ this, "MapStringVectorOfDoubles" };
83 
86 
89 
91  Gaudi::Property<std::vector<int>> m_21{ this, "EmptyVector" };
92 
95 
98 
99  // std::array must be explicitly initialized
100  Gaudi::Property<std::array<double, 3>> m_23{ this, "StdArrayDouble3", { 0 } };
101  Gaudi::Property<std::array<int, 1>> m_26{ this, "StdArrayInt1", { 0 } };
102 
104 };
105 // ============================================================================
107 // ============================================================================
109 // ============================================================================
110 namespace {
111  template <class TYPE>
112  inline SimplePropertyRef<TYPE> _prop( TYPE& value ) {
113  // construct a readable name
114  std::string name = System::typeinfoName( typeid( value ) );
115  std::string::size_type ipos = name.find( "std::" );
116  while ( std::string::npos != ipos ) {
117  name.erase( ipos, 5 );
118  ipos = name.find( "std::" );
119  }
120  ipos = name.find( "__cxx11::" );
121  while ( std::string::npos != ipos ) {
122  name.erase( ipos, 9 );
123  ipos = name.find( "__cxx11::" );
124  }
125  ipos = name.find( " " );
126  while ( std::string::npos != ipos ) {
127  name.erase( ipos, 1 );
128  ipos = name.find( " " );
129  }
130  ipos = name.find( "const" );
131  while ( std::string::npos != ipos ) {
132  name.erase( ipos, 5 );
133  ipos = name.find( "const" );
134  }
135  ipos = name.find( ",allocator<" );
136  while ( std::string::npos != ipos ) {
137  std::string::size_type ip2 = ipos + 11;
138  int ip3 = 1;
139  for ( ; ip2 < name.size(); ++ip2 ) {
140  if ( '<' == name[ip2] ) { ip3 += 1; }
141  if ( '>' == name[ip2] ) { ip3 -= 1; }
142  if ( 0 == ip3 ) { break; }
143  }
144  name.erase( ipos, ip2 + 1 - ipos );
145  ipos = name.find( ",allocator<" );
146  }
147  if ( std::string::npos != name.find( "map<" ) ) {
148  ipos = name.find( ",less<" );
149  while ( std::string::npos != ipos ) {
150  std::string::size_type ip2 = ipos + 6;
151  int ip3 = 1;
152  for ( ; ip2 < name.size(); ++ip2 ) {
153  if ( '<' == name[ip2] ) { ip3 += 1; }
154  if ( '>' == name[ip2] ) { ip3 -= 1; }
155  if ( 0 == ip3 ) { break; }
156  }
157  name.erase( ipos, ip2 + 1 - ipos );
158  ipos = name.find( ",less<" );
159  }
160  }
161  ipos = name.find( ">>" );
162  while ( std::string::npos != ipos ) {
163  name.replace( ipos, 2, "> >" );
164  ipos = name.find( ">>" );
165  }
166  return SimplePropertyRef<TYPE>( name, value );
167  }
168 } // namespace
169 // ============================================================================
171  always() << " My Properties : " << endmsg;
172 
173  always() << " \t" << m_1 << endmsg;
174  always() << " \t" << m_2 << endmsg;
175  always() << " \t" << m_3 << endmsg;
176  always() << " \t" << m_4 << endmsg;
177  always() << " \t" << m_5 << endmsg;
178  always() << " \t" << m_6 << endmsg;
179  always() << " \t" << m_7 << endmsg;
180  always() << " \t" << m_8 << endmsg;
181  always() << " \t" << m_9 << endmsg;
182  always() << " \t" << m_10 << endmsg;
183  always() << " \t" << m_11 << endmsg;
184  always() << " \t" << m_12 << endmsg;
185  always() << " \t" << m_13 << endmsg;
186  always() << " \t" << m_14 << endmsg;
187  always() << " \t" << m_14 << endmsg;
188  always() << " \t" << m_15 << endmsg;
189  always() << " \t" << m_16 << endmsg;
190 
191  always() << " \t" << m_20 << endmsg;
192  always() << " \t" << m_21 << endmsg;
193 
194  always() << " \t" << m_22 << endmsg;
195  always() << " \t" << m_25 << endmsg;
196  always() << " \t" << m_23 << endmsg;
197  always() << " \t" << m_26 << endmsg;
198 
199  always() << " \t" << m_24 << endmsg;
200 
201  always() << " \t" << m_30 << endmsg;
202  always() << " \t" << m_31 << endmsg;
203 
204  // some properties could be created from other (convertible) types:
205  Gaudi::Property<short> m1( "a", 0 );
206  Gaudi::Property<double> m2( "b", m1 );
207 
208  // some properties could be assigned from other (convertible) types
209  Gaudi::Property<int> m3( "c", 0 );
210  m3 = m1;
211 
212  float i = 10;
213  Gaudi::Property<float&> m4( "d", i );
214 
215  m4 = 12;
216 
217  return StatusCode::SUCCESS;
218 }
219 // ============================================================================
220 // The END
221 // ============================================================================
ExtendedProperties::m_21
Gaudi::Property< std::vector< int > > m_21
Definition: ExtendedProperties.cpp:91
std::string
STL class.
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:526
ExtendedProperties::m_30
Gaudi::Property< std::unordered_set< int > > m_30
Definition: ExtendedProperties.cpp:96
Gaudi::Units::m3
constexpr double m3
Definition: SystemOfUnits.h:110
PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >::setProperty
StatusCode setProperty(const Gaudi::Details::PropertyBase &p)
Set the property from a property.
Definition: IProperty.h:39
StdArrayAsProperty.h
ISvcLocator
Definition: ISvcLocator.h:46
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:58
Gaudi::Units::m2
constexpr double m2
Definition: SystemOfUnits.h:109
ExtendedProperties::m_10
Gaudi::Property< std::pair< int, int > > m_10
Definition: ExtendedProperties.cpp:80
Algorithm.h
ExtendedProperties::m_25
Gaudi::Property< std::tuple< std::string > > m_25
Definition: ExtendedProperties.cpp:94
ExtendedProperties::m_3
Gaudi::Property< std::vector< std::vector< std::string > > > m_3
Definition: ExtendedProperties.cpp:71
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:315
ExtendedProperties::m_1
Gaudi::Property< std::pair< double, double > > m_1
Definition: ExtendedProperties.cpp:68
ExtendedProperties::m_11
Gaudi::Property< std::map< std::string, std::vector< double > > > m_11
Definition: ExtendedProperties.cpp:81
ExtendedProperties::m_8
Gaudi::Property< std::map< std::string, double > > m_8
Definition: ExtendedProperties.cpp:77
ExtendedProperties::m_24
Gaudi::Property< GaudiUtils::Map< std::string, std::string > > m_24
Definition: ExtendedProperties.cpp:103
ExtendedProperties::m_13
Gaudi::Property< std::map< int, int > > m_13
Definition: ExtendedProperties.cpp:84
ExtendedProperties::m_22
Gaudi::Property< std::tuple< std::string, int, double > > m_22
Definition: ExtendedProperties.cpp:93
ExtendedProperties::m_2
Gaudi::Property< std::vector< std::pair< double, double > > > m_2
Definition: ExtendedProperties.cpp:70
ExtendedProperties::m_5
Gaudi::Property< std::map< int, double > > m_5
Definition: ExtendedProperties.cpp:74
StatusCode
Definition: StatusCode.h:65
ExtendedProperties::m_12
Gaudi::Property< std::map< std::string, std::vector< int > > > m_12
Definition: ExtendedProperties.cpp:82
ExtendedProperties::m_26
Gaudi::Property< std::array< int, 1 > > m_26
Definition: ExtendedProperties.cpp:101
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:237
ExtendedProperties::m_23
Gaudi::Property< std::array< double, 3 > > m_23
Definition: ExtendedProperties.cpp:100
ExtendedProperties::m_7
Gaudi::Property< std::map< std::string, int > > m_7
Definition: ExtendedProperties.cpp:76
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
ExtendedProperties::m_16
Gaudi::Property< std::map< unsigned int, std::string > > m_16
Definition: ExtendedProperties.cpp:88
ExtendedProperties::m_15
Gaudi::Property< std::map< int, std::string > > m_15
Definition: ExtendedProperties.cpp:87
ExtendedProperties::ExtendedProperties
ExtendedProperties(const std::string &name, ISvcLocator *pSvc)
Definition: ExtendedProperties.cpp:60
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
Factory.h
ExtendedProperties
Definition: ExtendedProperties.py:1
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
ExtendedProperties::m_9
Gaudi::Property< std::map< std::string, std::vector< std::string > > > m_9
Definition: ExtendedProperties.cpp:78
ExtendedProperties::execute
StatusCode execute() override
Definition: ExtendedProperties.cpp:170
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
ExtendedProperties::m_6
Gaudi::Property< std::map< std::string, std::string > > m_6
Definition: ExtendedProperties.cpp:75
ExtendedProperties::m_4
Gaudi::Property< std::vector< std::vector< double > > > m_4
Definition: ExtendedProperties.cpp:72
Map.h
ExtendedProperties::m_20
Gaudi::Property< std::map< std::string, std::string > > m_20
Definition: ExtendedProperties.cpp:90
ExtendedProperties::m_31
Gaudi::Property< std::unordered_set< std::string > > m_31
Definition: ExtendedProperties.cpp:97
ExtendedProperties::m_14
Gaudi::Property< std::vector< std::pair< int, int > > > m_14
Definition: ExtendedProperties.cpp:85
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:37