ATLAS Offline Software
Loading...
Searching...
No Matches
plugin_miniSim Namespace Reference

Functions

 setup (flags)
 getInOutputs (c, prefix="")
 fillProps (c, prefix="")

Variables

str sequenceName = "GlobalSim"
 parentName
list algos = []
 algType
 algName
 theAlg = getattr(CompFactory.GlobalSim,algType+"Alg")(algName)
list readerNames = []
 tobType
 sgKey = getattr(a,sgKey.split(".")[1]).Path.split('+')[-1]
 filepath
bool foundProp = False
 skipUnapplied
 create
dict allInputs = {}
dict allOutputs = {}
 inputs
 outputs
 log = logging.getLogger('plugin_miniSim')
dict itemLists = {}
 whats
 stream
dict p = allOutputs[what][0]
 theType = ROOT.TClass.GetClass(p.Type).GetName()
 SubLevelBranchName
dict allProps = {}
 createdObjs = set()
 label = alg.getType() + (('/'+alg.name) if alg.name != alg.getType else '')
 color = None
dict presimOutputs = {}
 myItems = set()

Function Documentation

◆ fillProps()

fillProps ( c,
prefix = "" )

Definition at line 308 of file plugin_miniSim.py.

308 def fillProps(c,prefix=""):
309 if prefix=="": prefix=c.name
310 for prop in c.getDefaultProperties().keys():
311 if prop in ["Cardinality","Enable","Asynchronous","FilterCircularDependencies","ExtraInputs","ExtraOutputs","MonitorService","NeededResources","ErrorMax","OutputLevel","RegisterForContextService","Timeline","EvtStore","DetStore","AuditFinalize","AuditExecute","AuditInitialize","AuditReinitialize","AuditRestart","AuditStart","AuditStop"]: continue
312 propVal = getattr(c,prop)
313 if isinstance(propVal,Configurable):
314 fillProps(propVal,prefix+"."+prop) # recurse into subtools etc
315 else:
316 allProps["l1global-minisim/"+prefix+"."+prop] = str(propVal).split("+",1)[-1] if isinstance(propVal,DataHandle) else str(propVal)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ getInOutputs()

getInOutputs ( c,
prefix = "" )

Definition at line 252 of file plugin_miniSim.py.

252def getInOutputs(c,prefix=""):
253 ins,outs = {},{}
254 if prefix=="": prefix=c.name
255 for prop,defaultVal in c.getDefaultProperties().items():
256 propVal = getattr(c,prop)
257 if isinstance(propVal,DataHandle) and propVal.Mode=='W':
258 outs[prefix+"."+prop] = (propVal,c._descriptors[prop].__doc__,"+" in defaultVal.Path) # returns tuple of property and doc string
259 elif isinstance(propVal,DataHandle) and propVal.Mode=='R':
260 ins[prefix+"."+prop] = (propVal,c._descriptors[prop].__doc__,"+" in defaultVal.Path)
261 elif isinstance(propVal,Configurable):
262 sins,souts = getInOutputs(propVal,prefix+"."+prop) # recurse into subtools etc
263 ins.update(sins)
264 outs.update(souts)
265 return ins,outs

◆ setup()

setup ( flags)

Definition at line 13 of file plugin_miniSim.py.

13def setup(flags):
14 from AthenaCommon.Logging import logging
15 log = logging.getLogger('plugin_miniSim')
16
17 # turn off everything else from the steering script by default, unless user requested through flags
18 flags.DQ.doMonitoring=False
19 flags.Trigger.enableL1CaloPhase1=any([flags.Trigger.L1.doeFex,flags.Trigger.L1.dojFex,flags.Trigger.L1.dogFex])
20
21 flags.addFlag("GlobalSim.Algs",[])
22 flags.addFlag("GlobalSim.txtInputs",[])
23 flags.addFlag("GlobalSim.txtOutputs",[])
24 flags.addFlag("GlobalSim.poolOutputs",[])
25
26 from AthenaConfiguration.ComponentFactory import CompFactory
27 excludeAlgs = ["GlobalSimulationAlg", "PU1SuppTestBenchAlg", "LArCellMuxAlg", "Egamma1_OnlineMapNbhoodAlg"]
28 availableAlgs = [f[:-3] for f in CompFactory.GlobalSim._getEntries()[-1] if f.endswith('Alg') and f not in excludeAlgs]
29
30
31 if flags.hasFlag("L1CaloAthMon.UnknownArgs"):
32 # declare additional parser arguments, and parse!
33 import argparse
34 parser = argparse.ArgumentParser(prog='l1global-minisim',formatter_class=argparse.RawTextHelpFormatter)
35 parser.add_argument('--presim',nargs='+',default=[],choices=["efex","jfex","gfex","muon","lasp"],help="What to pre-simulate")
36 parser.add_argument('--algs',nargs='*',default=[],help=f"algs to run. Available are: {', '.join(availableAlgs)}")
37 parser.add_argument('--filesInput',nargs='*',default=[],help="If nibbler, specify as <key>:<path>. <key> can be storegate key or algorithm input property (<alg>.<input>)") # just here for help dialog
38 parser.add_argument('--filesOutput',nargs='*',default=[],help="outputs to save, specify similarly to inputs, but <key> can also be comma separated list when piping to a pool file")
39 if "--help" in flags.L1CaloAthMon.UnknownArgs:
40 # before parsing, set the epilog to list of alg parameters
41 epilog = "Available Algorithm Parameters (specify in '--postConfig' using \"<algName>.<propName>=<val>\" syntax) :\n"
42 from GaudiKernel.DataHandle import DataHandle
43 for algType in availableAlgs:
44 epilog += f" {algType}:\n"
45 configurable = getattr(CompFactory.GlobalSim,algType+"Alg")
46 for propName,propVal in configurable.getDefaultProperties().items():
47 # skip properties that aren't part of the algorithm itself
48 description = configurable._descriptors[propName].__doc__
49 if f"[GlobalSim::{algType}Alg]" not in description: continue
50 description = description.replace(f"[GlobalSim::{algType}Alg]","")
51 epilog += f" .{propName}: {description}\n"
52 parser.epilog = epilog + "\n"
53 args,unknown = parser.parse_known_args(flags.L1CaloAthMon.UnknownArgs)
54 flags.L1CaloAthMon.UnknownArgs = unknown
55 flags.GlobalSim.Algs = args.algs
56 flags.GlobalSim.txtOutputs = args.filesOutput
57
58 if "efex" in args.presim: flags.Trigger.L1.doeFex=True
59 if "jfex" in args.presim: flags.Trigger.L1.dojFex=True
60 if "gfex" in args.presim: flags.Trigger.L1.dogFex=True
61 if "muon" in args.presim: flags.Trigger.L1.doMuon=True
62 if "lasp" in args.presim: flags.GlobalSim.Algs += ["LArCellPreparation"]
63 flags.Trigger.enableL1CaloPhase1=any([flags.Trigger.L1.doeFex,flags.Trigger.L1.dojFex,flags.Trigger.L1.dogFex])
64
65 # determine inputs required (while checking algs exist)
66 algInputs = set()
67 algOutputs = set()
68 inputsMap = {}
69 outputsMap = {}
70 knownTypes = {} # if can identify the type from the alg metadata, will collect the types here
71 for alg in flags.GlobalSim.Algs:
72 # check alg exists
73 algType,algName = (alg.split("/") if "/" in alg else [alg,alg])
74 if not hasattr(CompFactory.GlobalSim,algType+"Alg"):
75 log.fatal(f"Unknown Alg: {algType}")
76 log.fatal(f"Available Algs: {availableAlgs}")
77 exit(-1)
78 # now iterate through read and write handles
79 from GaudiKernel.DataHandle import DataHandle
80 configurable = getattr(CompFactory.GlobalSim,algType+"Alg")
81 for propName,propVal in configurable.getDefaultProperties().items():
82 if not isinstance(propVal,DataHandle): continue # skip non-handle properties
83 sgKey = propVal.Path.split('+')[-1]
84 # try to get the "type" from the property description
85 for item in configurable._descriptors[propName].__doc__.split(";"):
86 item = item.strip()
87 if item.startswith("type="):
88 knownTypes[sgKey] = item[len("type="):]
89 knownTypes[f"{algName}.{propName}"] = item[len("type="):]
90 break
91 if propVal.Mode == 'W':
92 algOutputs.add(sgKey)
93 if sgKey not in outputsMap: outputsMap[sgKey] = []
94 outputsMap[sgKey] += [f"{algName}.{propName}"]
95 else:
96 algInputs.add(sgKey)
97 if sgKey not in inputsMap: inputsMap[sgKey] = []
98 inputsMap[sgKey] += [f"{algName}.{propName}"]
99
100 # remove from inputs the outputs of the other algs
101 # what is left will be what we need provided externally
102 algInputs -= algOutputs
103
104 log.info(f"Your algorithms {flags.GlobalSim.Algs} require the following inputs: {[i for a in algInputs for i in inputsMap[a]]}")
105 log.info(f"and produces the following outputs: {[i for a in algOutputs for i in outputsMap[a]]}")
106
107 # move any txt inputs into the txtInputs flag
108 cleanList = []
109 for f in flags.Input.Files:
110 if f.endswith(".txt"):
111 # must have two ":" in it ... check
112 if f.count(":") != 2:
113 if f.count(":")==1:
114 if f.split(":")[0] in knownTypes:
115 f = knownTypes[f.split(":")[0]] + ":" + f
116 else:
117 log.fatal(f"{f.split(':')[0]} has no known type. Add to algorithm metadata or otherwise specify it explicitly with '<type>:' prefix")
118 exit(-1)
119 else:
120 log.fatal("txt input must be specified in form <type>:<SGkey>:<filepath>")
121 exit(-1)
122 flags.GlobalSim.txtInputs += [f]
123 else:
124 cleanList += [f]
125 flags.Input.Files = cleanList
126
127 if len(flags.GlobalSim.txtInputs):
128 flags.Input.isMC = True # tell parts of job to behave as this was a simulation
129
130 if flags.Exec.MaxEvents==-1:
131 # determine max number of events of given input file types
132 maxVals = {}
133 for f in flags.GlobalSim.txtInputs:
134 typeAndName,path = f.rsplit(":",1)
135 if typeAndName not in maxVals: maxVals[typeAndName]=0
136 maxVals[typeAndName] += sum(1 for _ in open(path))
137 flags.Exec.MaxEvents = max(maxVals.values())
138 # use the total number of lines in all the input files as the max events
139 log.info(f"Processing {flags.Exec.MaxEvents} events from txt filesInput")
140
141 txtOutputs = list(flags.GlobalSim.txtOutputs)
142 flags.GlobalSim.txtOutputs = []
143 filenameMap = {}
144 for f in txtOutputs:
145 if f.endswith(".txt"):
146 # must have two ":" in it ... check
147 if f.count(":") != 2:
148 if f.count(":")==1:
149 if f.split(":")[0] in knownTypes:
150 f = knownTypes[f.split(":")[0]] + ":" + f
151 else:
152 log.fatal(f"{f.split(':')[0]} has no known type. Add to algorithm metadata or otherwise specify it explicitly with '<type>:' prefix")
153 exit(-1)
154 else:
155 log.fatal("txt output must be specified in form <type>:<SGkey>:<filepath>")
156 exit(-1)
157 flags.GlobalSim.txtOutputs += [f]
158 elif f.endswith(".pool.root"):
159 # need to add filenames to available outputs
160 filename = f.split(":")[-1]
161 if filename not in filenameMap:
162 filenameMap[filename] = f"GSIM{len(filenameMap)}"
163 flags.addFlag("Output."+filenameMap[filename]+"FileName",filename) # used by OutputStreamConfig
164 flags.GlobalSim.poolOutputs += [f.replace(filename,filenameMap[filename])]
165
166
167# I may move this subsequence creation up into the steering script if I can figure out way to control `addEventAlgo` calls
#define max(a, b)
Definition cfImp.cxx:41
STL class.
bool setup(asg::AnaToolHandle< Interface > &tool, const std::string &type, const std::vector< std::string > &config, const std::string &progressFile="")
mostly useful for athena, which will otherwise re-use the previous tool

Variable Documentation

◆ algName

plugin_miniSim.algName

Definition at line 178 of file plugin_miniSim.py.

◆ algos

list plugin_miniSim.algos = []

Definition at line 176 of file plugin_miniSim.py.

◆ algType

plugin_miniSim.algType

Definition at line 178 of file plugin_miniSim.py.

◆ allInputs

dict plugin_miniSim.allInputs = {}

Definition at line 245 of file plugin_miniSim.py.

◆ allOutputs

dict plugin_miniSim.allOutputs = {}

Definition at line 246 of file plugin_miniSim.py.

◆ allProps

dict plugin_miniSim.allProps = {}

Definition at line 307 of file plugin_miniSim.py.

◆ color

str color = None

Definition at line 334 of file plugin_miniSim.py.

◆ create

plugin_miniSim.create

Definition at line 241 of file plugin_miniSim.py.

◆ createdObjs

plugin_miniSim.createdObjs = set()

Definition at line 328 of file plugin_miniSim.py.

◆ filepath

plugin_miniSim.filepath

Definition at line 191 of file plugin_miniSim.py.

◆ foundProp

bool foundProp = False

Definition at line 194 of file plugin_miniSim.py.

◆ inputs

plugin_miniSim.inputs

Definition at line 268 of file plugin_miniSim.py.

◆ itemLists

dict plugin_miniSim.itemLists = {}

Definition at line 279 of file plugin_miniSim.py.

◆ label

plugin_miniSim.label = alg.getType() + (('/'+alg.name) if alg.name != alg.getType else '')

Definition at line 333 of file plugin_miniSim.py.

◆ log

plugin_miniSim.log = logging.getLogger('plugin_miniSim')

Definition at line 276 of file plugin_miniSim.py.

◆ myItems

plugin_miniSim.myItems = set()

Definition at line 393 of file plugin_miniSim.py.

◆ outputs

plugin_miniSim.outputs

Definition at line 268 of file plugin_miniSim.py.

◆ p

plugin_miniSim.p = allOutputs[what][0]

Definition at line 286 of file plugin_miniSim.py.

◆ parentName

plugin_miniSim.parentName

Definition at line 169 of file plugin_miniSim.py.

◆ presimOutputs

dict plugin_miniSim.presimOutputs = {}

Definition at line 368 of file plugin_miniSim.py.

◆ readerNames

list plugin_miniSim.readerNames = []

Definition at line 189 of file plugin_miniSim.py.

◆ sequenceName

plugin_miniSim.sequenceName = "GlobalSim"

Definition at line 168 of file plugin_miniSim.py.

◆ sgKey

plugin_miniSim.sgKey = getattr(a,sgKey.split(".")[1]).Path.split('+')[-1]

Definition at line 191 of file plugin_miniSim.py.

◆ skipUnapplied

plugin_miniSim.skipUnapplied

Definition at line 238 of file plugin_miniSim.py.

◆ stream

plugin_miniSim.stream

Definition at line 282 of file plugin_miniSim.py.

◆ SubLevelBranchName

plugin_miniSim.SubLevelBranchName

Definition at line 304 of file plugin_miniSim.py.

◆ theAlg

plugin_miniSim.theAlg = getattr(CompFactory.GlobalSim,algType+"Alg")(algName)

Definition at line 184 of file plugin_miniSim.py.

◆ theType

plugin_miniSim.theType = ROOT.TClass.GetClass(p.Type).GetName()

Definition at line 287 of file plugin_miniSim.py.

◆ tobType

plugin_miniSim.tobType

Definition at line 191 of file plugin_miniSim.py.

◆ whats

plugin_miniSim.whats

Definition at line 282 of file plugin_miniSim.py.