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