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