The Gaudi Framework  v36r1 (3e2fb5a8)
ExtendedProperties.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
13 """
14 *******************************************************************************
15 * *
16 * Simple example (identical to C++ ExtendedProperties.opts) which illustrates *
17 * the extended job-properties and their C++/Python intercommunication *
18 * *
19 *******************************************************************************
20 """
21 from __future__ import print_function
22 # =============================================================================
23 __author__ = 'Vanya BELYAEV ibelyaev@physics.syr.edu'
24 # =============================================================================
25 # @file
26 # Simple example (identical to C++ ExtendedProperties.opts) which illustrates
27 # the extended job-properties and their C++/Python intercommunication
28 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
29 # @date 2007-02-13
30 # =============================================================================
31 
32 import gaudimodule
33 
34 SUCCESS = gaudimodule.SUCCESS
35 
36 # =============================================================================
37 # the configurtaion of the job
38 
39 
40 def configure(gaudi=None):
41  """ the configurtaion of the job """
42 
43  # create application manager if not done yet
44  if not gaudi:
45  gaudi = gaudimodule.AppMgr()
46 
47  # read main configuration files
48  gaudi.config(files=['../options/Common.opts'])
49 
50  # private algorithm configuration options
51 
52  gaudi.TopAlg = ["ExtendedProperties/xProps"]
53  gaudi.EvtSel = 'NONE'
54  gaudi.HistogramPersistency = 'NONE'
55 
56  xProps = gaudi.algorithm('xProps')
57 
58  # std::pair<double,double>
59  # xProps.PairDD = ( 3.141592 , 2.18281828 )
60  # std::pair<int,int>
61  # xProps.PairII = ( 3 , 2 )
62 
63  # std::vector<std::pair<double,double> >
64  xProps.VectorOfPairsDD = [(0, 1), (1, 2), (2, 3), (3, 4)]
65 
66  # std::vector<std::vector<std::string> >
67  xProps.VectorOfVectorsString = [["a", "b", "c"], ["A", "B", "C"]]
68 
69  # std::vector<std::vector<double> >
70  xProps.VectorOfVectorsDouble = [[0, 1, 2], [0, -0.5, -0.25]]
71 
72  # std::map<int,double>
73  xProps.MapIntDouble = {1: 0.1, 2: 0.2, 3: 0.3}
74 
75  # std::map<std::string,std::string>
76  xProps.MapStringString = {
77  'a': 'sddsgsgsdgdggf',
78  'b': 'sddsgsgsdgdggf',
79  'c': 'sddsgsgsdgdggf'
80  }
81 
82  # std::map<std::string,int>
83  xProps.MapStringInt = {'a': 1, 'b': 2, "c": 3}
84 
85  # std::map<std::string,double>
86  xProps.MapStringDouble = {'aa': 0.1, 'bb': 0.2, "cc": 3}
87 
88  # std::map<std::string,std::vector<std::string> >
89  xProps.MapStringVectorOfStrings = {
90  'aaa': ['a', 'b', 'c'],
91  'bbb': ['a', 'b', 'c'],
92  'ccc': ['a', 'b', 'c']
93  }
94 
95  # std::map<std::string,std::vector<double> >
96  xProps.MapStringVectorOfDoubles = {
97  'aaa': [1, 2, 3],
98  'bbb': [1., 2., 3.],
99  'ccc': [0.1, 0.2, 0.3]
100  }
101 
102  # std::map<std::string,std::vector<int> >
103  xProps.MapStringVectorOfInts = {
104  'aaa': [1, 2, 3],
105  'bbb': [4, 5, 6],
106  'ccc': [7, 8, 9]
107  }
108 
109  return SUCCESS
110 
111 
112 # =============================================================================
113 # The actual job excution
114 # =============================================================================
115 if '__main__' == __name__:
116 
117  print(__doc__, __author__)
118 
120  configure(gaudi)
121  gaudi.run(1)
122 
123  alg = gaudi.algorithm('xProps')
124 
125  # get all properties throught python
126  #
127  # IT DOES NOT WORK ANYMORE after the
128  # reimplementation of
129  # gaudimodule.iProperty.properties using
130  # new class PropertyEntry
131  #
132  props = alg.properties()
133 
134  print('All Properties of %s ' % alg.name())
135  for p in props:
136  v = props[p].value()
137  t = type(v).__name__
138  print("Python: Name/Value: '%s' / '%s' " % (p, v))
139 
140  # get the properties in the form of python dictionary:
141  print('All Properties of %s ' % alg.name())
142  properties = {}
143  for p in props:
144  properties[p] = props[p].value()
145 
146  for p in properties:
147  print("Python: Name/Value: '%s' / '%s' " % (p, properties[p]))
148 
149 # =============================================================================
150 # The END
151 # =============================================================================
Gaudi::Algorithm::type
const std::string & type() const override
The type of the algorithm object.
Definition: Algorithm.h:165
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:842
Gaudi::Algorithm::configure
StatusCode configure() override
Dummy implementation of IStateful::configure() method.
Definition: Algorithm.h:173