The Gaudi Framework  master (da3d77e1)
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 # =============================================================================
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.0, 2.0, 3.0],
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  print(__doc__, __author__)
117 
118  gaudi = gaudimodule.AppMgr()
119  configure(gaudi)
120  gaudi.run(1)
121 
122  alg = gaudi.algorithm("xProps")
123 
124  # get all properties throught python
125  #
126  # IT DOES NOT WORK ANYMORE after the
127  # reimplementation of
128  # gaudimodule.iProperty.properties using
129  # new class PropertyEntry
130  #
131  props = alg.properties()
132 
133  print("All Properties of %s " % alg.name())
134  for p in props:
135  v = props[p].value()
136  t = type(v).__name__
137  print("Python: Name/Value: '%s' / '%s' " % (p, v))
138 
139  # get the properties in the form of python dictionary:
140  print("All Properties of %s " % alg.name())
141  properties = {}
142  for p in props:
143  properties[p] = props[p].value()
144 
145  for p in properties:
146  print("Python: Name/Value: '%s' / '%s' " % (p, properties[p]))
147 
148 # =============================================================================
149 # The END
150 # =============================================================================
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