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