The Gaudi Framework  master (adcf1ca6)
Loading...
Searching...
No Matches
Gaudi.Main Namespace Reference

Classes

class  BootstrapHelper
 
class  gaudimain
 

Functions

 _getAllOpts_old (explicit_defaults=False)
 
 getAllOpts (explicit_defaults=False)
 
 toOpt (value)
 
 parseOpt (s)
 

Variables

 log = logging.getLogger(__name__)
 

Function Documentation

◆ _getAllOpts_old()

Gaudi.Main._getAllOpts_old ( explicit_defaults = False)
protected
Return all options from the old configuration system as a dictionary.

If explicit_defaults is true, include default values of unset properties in the dictionary.

Definition at line 178 of file Main.py.

178def _getAllOpts_old(explicit_defaults=False):
179 """
180 Return all options from the old configuration system as a dictionary.
181
182 If explicit_defaults is true, include default values of unset properties in the dictionary.
183 """
184 from itertools import chain
185
186 from GaudiKernel.Proxy.Configurable import Configurable, getNeededConfigurables
187
188 old_opts = {}
189
190 # Keep track of which algorithms we have already processed to avoid
191 # computing them many times
192 done_conf = set()
193 # More algorithms may be generated when we call "getValuedProperties" so we
194 # may need a few iterations before we get the full list
195 # (see GaudiConfig.ControlFlow)
196 while True:
197 needed_conf = [n for n in getNeededConfigurables() if n not in done_conf]
198 if not needed_conf:
199 break
200
201 for n in needed_conf:
202 done_conf.add(n)
203 c = Configurable.allConfigurables[n]
204 items = getattr(c, "getValuedProperties", dict)().items()
205 if explicit_defaults:
206 items = chain(c.getDefaultProperties().items(), items)
207 for p, v in items:
208 # Note: AthenaCommon.Configurable does not have Configurable.PropertyReference
209 if hasattr(Configurable, "PropertyReference") and isinstance(
210 v, Configurable.PropertyReference
211 ):
212 # this is done in "getFullName", but the exception is ignored,
213 # so we do it again to get it
214 v = v.__resolve__()
215 if hasattr(v, "__opt_value__"):
216 v = v.__opt_value__()
217 elif isinstance(v, str):
218 v = repr(v)
219 else:
220 v = str(v)
221 old_opts[".".join((n, p))] = v
222
223 return old_opts
224
225

◆ getAllOpts()

Gaudi.Main.getAllOpts ( explicit_defaults = False)
Return all options from the old and new configuration system as a dictionary.

If explicit_defaults is true, include default values of unset properties in the dictionary.

Definition at line 226 of file Main.py.

226def getAllOpts(explicit_defaults=False):
227 """
228 Return all options from the old and new configuration system as a dictionary.
229
230 If explicit_defaults is true, include default values of unset properties in the dictionary.
231 """
232 import GaudiConfig2
233
234 # We need to run normal (without defaults) collection first (regardless of explicit_defaults)
235 # as the conflicts detection makes sense only for explicitly set options
236 old_opts = _getAllOpts_old(False)
237 opts = GaudiConfig2.all_options(False)
238
239 conflicts = [n for n in set(opts).intersection(old_opts) if opts[n] != old_opts[n]]
240 if conflicts:
241 conflicts.sort()
242 log.error("Some properties are set in old and new style configuration")
243 log.warning("name: old -> new")
244 for n in conflicts:
245 log.warning("%s: %s -> %s", n, old_opts[n], opts[n])
246 sys.exit(10)
247
248 opts.update(old_opts)
249
250 if explicit_defaults:
251 # If we are asked to print also the defaults, we collect everything
252 # and blindly merge to make sure we have the full set of configurables
253 all_opts = _getAllOpts_old(True)
254 all_opts.update(GaudiConfig2.all_options(True))
255 # the we override the dictionary with the explicitly set options
256 # (that leaves the defaults untouched and the set options with the
257 # correct value)
258 all_opts.update(opts)
259 opts = all_opts
260
261 return opts
262
263

◆ parseOpt()

Gaudi.Main.parseOpt ( s)
Helper to parse option strings to Python values.

Ideally it should just be "eval", but the string parser of Gaudi
is different from the Python one, so we get string options that
cannot be just evaluated.

>>> print(parseOpt('123'))
123
>>> print(parseOpt('"some\\n\\\\"text\\\\""'))
some
"text"
>>> print(parseOpt(''))
<BLANKLINE>

(see gaudi/Gaudi#78)

Definition at line 288 of file Main.py.

288def parseOpt(s):
289 """
290 Helper to parse option strings to Python values.
291
292 Ideally it should just be "eval", but the string parser of Gaudi
293 is different from the Python one, so we get string options that
294 cannot be just evaluated.
295
296 >>> print(parseOpt('123'))
297 123
298 >>> print(parseOpt('"some\\n\\\\"text\\\\""'))
299 some
300 "text"
301 >>> print(parseOpt(''))
302 <BLANKLINE>
303
304 (see gaudi/Gaudi#78)
305 """
306 import re
307
308 quoted_string = re.compile(r'^"(.*)"$', re.DOTALL)
309 # FIXME: this is needed because we cannot use repr for strings
310 # (see gaudi/Gaudi#78)
311 if not s: # pass through empty strings
312 return s
313 m = quoted_string.match(s)
314 if m:
315 return m.group(1).replace('\\"', '"')
316 return eval(s)
317
318

◆ toOpt()

Gaudi.Main.toOpt ( value)
Helper to convert values to old .opts format.

>>> print(toOpt('some "text"'))
"some \\"text\\""
>>> print(toOpt('first\\nsecond'))
"first
second"
>>> print(toOpt({'a': [1, 2, '3']}))
{"a": [1, 2, "3"]}

Definition at line 264 of file Main.py.

264def toOpt(value):
265 """
266 Helper to convert values to old .opts format.
267
268 >>> print(toOpt('some "text"'))
269 "some \\"text\\""
270 >>> print(toOpt('first\\nsecond'))
271 "first
272 second"
273 >>> print(toOpt({'a': [1, 2, '3']}))
274 {"a": [1, 2, "3"]}
275 """
276 if isinstance(value, str):
277 return '"{0}"'.format(value.replace('"', '\\"'))
278 elif isinstance(value, dict):
279 return "{{{0}}}".format(
280 ", ".join("{0}: {1}".format(toOpt(k), toOpt(v)) for k, v in value.items())
281 )
282 elif hasattr(value, "__iter__"):
283 return "[{0}]".format(", ".join(map(toOpt, value)))
284 else:
285 return repr(value)
286
287
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93

Variable Documentation

◆ log

Gaudi.Main.log = logging.getLogger(__name__)

Definition at line 18 of file Main.py.