The Gaudi Framework  master (da3d77e1)
ExtendedProperties.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 
107  struct HashFunction {
108  std::size_t operator()( Triplet const& entry ) const {
109  return hasher( std::get<0>( entry ) ) ^ hasher( std::get<1>( entry ) ) ^ hasher( std::get<2>( entry ) );
110  }
111  };
112 
122 };
123 // ============================================================================
125 // ============================================================================
127 // ============================================================================
129  always() << " My Properties : " << endmsg;
130 
131  always() << " \t" << m_1 << endmsg;
132  always() << " \t" << m_2 << endmsg;
133  always() << " \t" << m_3 << endmsg;
134  always() << " \t" << m_4 << endmsg;
135  always() << " \t" << m_5 << endmsg;
136  always() << " \t" << m_6 << endmsg;
137  always() << " \t" << m_7 << endmsg;
138  always() << " \t" << m_8 << endmsg;
139  always() << " \t" << m_9 << endmsg;
140  always() << " \t" << m_10 << endmsg;
141  always() << " \t" << m_11 << endmsg;
142  always() << " \t" << m_12 << endmsg;
143  always() << " \t" << m_13 << endmsg;
144  always() << " \t" << m_14 << endmsg;
145  always() << " \t" << m_14 << endmsg;
146  always() << " \t" << m_15 << endmsg;
147  always() << " \t" << m_16 << endmsg;
148 
149  always() << " \t" << m_20 << endmsg;
150  always() << " \t" << m_21 << endmsg;
151 
152  always() << " \t" << m_22 << endmsg;
153  always() << " \t" << m_25 << endmsg;
154  always() << " \t" << m_23 << endmsg;
155  always() << " \t" << m_26 << endmsg;
156 
157  always() << " \t" << m_24 << endmsg;
158 
159  always() << " \t" << m_30 << endmsg;
160  always() << " \t" << m_31 << endmsg;
161 
162  always() << " \t" << m_tuplevector << endmsg;
163  always() << " \t" << m_intvectortuple << endmsg;
164  always() << " \t" << m_tupleset << endmsg;
165  always() << " \t" << m_intsettuple << endmsg;
166  always() << " \t" << m_tupleunset << endmsg;
167  always() << " \t" << m_intunsettuple << endmsg;
168 
169  // some properties could be created from other (convertible) types:
170  Gaudi::Property<short> m1( "a", 0 );
171  Gaudi::Property<double> m2( "b", m1 );
172 
173  // some properties could be assigned from other (convertible) types
174  Gaudi::Property<int> m3( "c", 0 );
175  m3 = m1;
176 
177  float i = 10;
178  Gaudi::Property<float&> m4( "d", i );
179 
180  m4 = 12;
181 
182  return StatusCode::SUCCESS;
183 }
184 // ============================================================================
185 // The END
186 // ============================================================================
ExtendedProperties::m_tuplevector
Gaudi::Property< std::vector< Triplet > > m_tuplevector
Definition: ExtendedProperties.cpp:113
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
std::unordered_set< std::string >
Gaudi::Units::m3
constexpr double m3
Definition: SystemOfUnits.h:110
std::vector< std::string >
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::HashFunction::operator()
std::size_t operator()(Triplet const &entry) const
Definition: ExtendedProperties.cpp:108
ExtendedProperties::m_25
Gaudi::Property< std::tuple< std::string > > m_25
Definition: ExtendedProperties.cpp:94
std::tuple
ExtendedProperties::m_3
Gaudi::Property< std::vector< std::vector< std::string > > > m_3
Definition: ExtendedProperties.cpp:71
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
ExtendedProperties::m_intunsettuple
Gaudi::Property< std::tuple< int, USS > > m_intunsettuple
Definition: ExtendedProperties.cpp:121
ExtendedProperties::HashFunction
Definition: ExtendedProperties.cpp:107
StatusCode
Definition: StatusCode.h:65
ExtendedProperties::m_12
Gaudi::Property< std::map< std::string, std::vector< int > > > m_12
Definition: ExtendedProperties.cpp:82
GaudiPython.Pythonizations.execute
execute
Definition: Pythonizations.py:578
ExtendedProperties::m_tupleunset
Gaudi::Property< std::unordered_set< Triplet, HashFunction > > m_tupleunset
Definition: ExtendedProperties.cpp:115
ExtendedProperties::m_intvectortuple
Gaudi::Property< std::tuple< int, VS > > m_intvectortuple
Definition: ExtendedProperties.cpp:117
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
ExtendedProperties::m_9
Gaudi::Property< std::map< std::string, std::vector< std::string > > > m_9
Definition: ExtendedProperties.cpp:78
ExtendedProperties::execute
StatusCode execute() override
factory
Definition: ExtendedProperties.cpp:128
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
ExtendedProperties::m_intsettuple
Gaudi::Property< std::tuple< int, SS > > m_intsettuple
Definition: ExtendedProperties.cpp:119
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
std::size_t
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
std::set< std::string >
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:37
ExtendedProperties::m_tupleset
Gaudi::Property< std::set< Triplet > > m_tupleset
Definition: ExtendedProperties.cpp:114
std::hash< std::string >
ExtendedProperties::hasher
static std::hash< std::string > hasher
Definition: ExtendedProperties.cpp:106