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