ATLAS Offline Software
Loading...
Searching...
No Matches
HelloWorldConfig.py
Go to the documentation of this file.
1#!/usr/bin/env athena.py
2# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
4from AthenaConfiguration.ComponentFactory import CompFactory
5from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
6
7
8def HelloWorldToolCfg(flags, name="HelloTool", **kwargs):
9 result = ComponentAccumulator()
10 # one can use kwargs to set properties
11 kwargs.setdefault("MyMessage", "Hello World!")
12 # create and add the tool to the result (and pass arguments)
13 result.setPrivateTools(CompFactory.HelloTool(name, **kwargs))
14 return result
15
16
17def HelloWorldPublicToolCfg(flags, name="PublicHello", **kwargs):
18 result = ComponentAccumulator()
19 # one can also set properties directly with creation
20 tool = CompFactory.HelloTool(name, MyMessage="Hello!", **kwargs)
21 # ...or after creation
22 tool.MyMessage = "A public Message!"
23 # add the tool to the result
24 result.addPublicTool(tool, primary=True)
25 return result
26
27
28def HelloWorldCfg(flags):
29 result = ComponentAccumulator()
30
31 alg = CompFactory.HelloAlg("HelloWorld",
32 # Set an int from a flag
33 MyInt=flags.Input.JobNumber,
34 # Set a boolean property (False, True, 0, 1)
35 MyBool=True,
36 # Set a double property
37 MyDouble=3.14159,
38 # Set a vector of strings property
39 MyStringVec=["Welcome", "to",
40 "Athena", "Framework", "Tutorial"],
41 # Set a map of strings to strings property
42 MyDict={"Bonjour": "Guten Tag",
43 "Good Morning": "Bonjour",
44 "one": "uno"},
45 # Set a table (a vector of pairs of doubles)
46 MyTable=[(1, 1), (2, 4), (3, 9)],
47 # Set a matrix (a vector of vectors) ...
48 MyMatrix=[[1, 2, 3],
49 [4, 5, 6]],
50 # set a private tool
51 MyPrivateHelloTool=result.popToolsAndMerge(
52 HelloWorldToolCfg(flags)),
53 # set a public tool
54 MyPublicHelloTool=result.getPrimaryAndMerge(
56 )
57
58 # add the algorithm to the result
59 result.addEventAlgo(alg)
60 return result
61
62
63if __name__ == "__main__":
64 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
65 from AthenaConfiguration.AllConfigFlags import initConfigFlags
66 flags = initConfigFlags()
67 flags.Exec.MaxEvents = 10
68 flags.fillFromArgs()
69 flags.lock()
70
71 cfg = MainServicesCfg(flags)
72 cfg.merge(HelloWorldCfg(flags))
73
74 import sys
75 sys.exit(cfg.run().isFailure())
HelloWorldPublicToolCfg(flags, name="PublicHello", **kwargs)
HelloWorldToolCfg(flags, name="HelloTool", **kwargs)