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

Functions

 setup (flags)
 getOutputs (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
 create
dict allOutputs = {}
 outputs = getOutputs(alg,alg.name)
dict itemLists = {}
 what
 stream
dict p = allOutputs[what]
 theType = ROOT.TClass.GetClass(p.Type).GetName()
 SubLevelBranchName

Function Documentation

◆ getOutputs()

getOutputs ( c,
prefix = "" )

Definition at line 244 of file plugin_miniSim.py.

244 def getOutputs(c,prefix=""):
245 out = {}
246 for prop in c.getDefaultProperties().keys():
247 propVal = getattr(c,prop)
248 if isinstance(propVal,DataHandle) and propVal.Mode=='W':
249 out[prefix+"."+prop] = propVal
250 elif isinstance(propVal,Configurable):
251 out.update(getOutputs(propVal,prefix+"."+prop)) # recurse into subtools etc
252 return out
std::vector< out_t > getOutputs(size_t length, mt_t &rand)

◆ 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 = ["LArCellPreparationAlg", "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"],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="inputs. 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")
39 if "--help" in flags.L1CaloAthMon.UnknownArgs:
40 # before parsing, set the epilog to list of alg parameters
41 epilog = "Availble Algorithm Parameters:\n"
42 from GaudiKernel.DataHandle import DataHandle
43 from AthenaCommon import CfgMgr
44 for algType in availableAlgs:
45 epilog += f" {algType}:\n"
46 propDocs = getattr(CfgMgr,f"GlobalSim__{algType}Alg")._propertyDocDct
47 for propName,propVal in getattr(CompFactory.GlobalSim,algType+"Alg").getDefaultProperties().items():
48 # skip properties that aren't part of the algorithm itself
49 description = propDocs[propName]
50 if f"[GlobalSim::{algType}Alg]" not in description: continue
51 description = description.replace(f"[GlobalSim::{algType}Alg]","")
52 epilog += f" .{propName}: {description}\n"
53 parser.epilog = epilog + "\n"
54 args,unknown = parser.parse_known_args(flags.L1CaloAthMon.UnknownArgs)
55 flags.L1CaloAthMon.UnknownArgs = unknown
56 flags.GlobalSim.Algs = args.algs
57 flags.GlobalSim.txtOutputs = args.filesOutput
58
59 if "efex" in args.presim: flags.Trigger.L1.doeFex=True
60 if "jfex" in args.presim: flags.Trigger.L1.dojFex=True
61 if "gfex" in args.presim: flags.Trigger.L1.dogFex=True
62 if "muon" in args.presim: flags.Trigger.L1.doMuon=True
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 from AthenaCommon import CfgMgr
81 propDocs = getattr(CfgMgr,f"GlobalSim__{algType}Alg")._propertyDocDct
82 for propName,propVal in getattr(CompFactory.GlobalSim,algType+"Alg").getDefaultProperties().items():
83 if not isinstance(propVal,DataHandle): continue # skip non-handle properties
84 sgKey = propVal.Path.split('+')[-1]
85 # try to get the "type" from the property description
86 for item in propDocs[propName].split(";"):
87 item = item.strip()
88 if item.startswith("type="):
89 knownTypes[sgKey] = item[len("type="):]
90 knownTypes[f"{algName}.{propName}"] = item[len("type="):]
91 break
92 if propVal.Mode == 'W':
93 algOutputs.add(sgKey)
94 if sgKey not in outputsMap: outputsMap[sgKey] = []
95 outputsMap[sgKey] += [f"{algName}.{propName}"]
96 else:
97 algInputs.add(sgKey)
98 if sgKey not in inputsMap: inputsMap[sgKey] = []
99 inputsMap[sgKey] += [f"{algName}.{propName}"]
100
101 # remove from inputs the outputs of the other algs
102 # what is left will be what we need provided externally
103 algInputs -= algOutputs
104
105 log.info(f"Your algorithms {flags.GlobalSim.Algs} require the following inputs: {[i for a in algInputs for i in inputsMap[a]]}")
106 log.info(f"and produces the following outputs: {[i for a in algOutputs for i in outputsMap[a]]}")
107
108 # move any txt inputs into the txtInputs flag
109 cleanList = []
110 for f in flags.Input.Files:
111 if f.endswith(".txt"):
112 # must have two ":" in it ... check
113 if f.count(":") != 2:
114 if f.count(":")==1:
115 if f.split(":")[0] in knownTypes:
116 f = knownTypes[f.split(":")[0]] + ":" + f
117 else:
118 log.fatal(f"{f.split(':')[0]} has no known type. Add to algorithm metadata or otherwise specify it explicitly with '<type>:' prefix")
119 exit(-1)
120 else:
121 log.fatal("txt input must be specified in form <type>:<SGkey>:<filepath>")
122 exit(-1)
123 flags.GlobalSim.txtInputs += [f]
124 else:
125 cleanList += [f]
126 flags.Input.Files = cleanList
127
128 if len(flags.GlobalSim.txtInputs):
129 flags.Input.isMC = True # tell parts of job to behave as this was a simulation
130
131 if flags.Exec.MaxEvents==-1:
132 # determine max number of events of given input file types
133 maxVals = {}
134 for f in flags.GlobalSim.txtInputs:
135 typeAndName,path = f.rsplit(":",1)
136 if typeAndName not in maxVals: maxVals[typeAndName]=0
137 maxVals[typeAndName] += sum(1 for _ in open(path))
138 flags.Exec.MaxEvents = max(maxVals.values())
139 # use the total number of lines in all the input files as the max events
140 log.info(f"Processing {flags.Exec.MaxEvents} events from txt filesInput")
141
142 txtOutputs = list(flags.GlobalSim.txtOutputs)
143 flags.GlobalSim.txtOutputs = []
144 filenameMap = {}
145 for f in txtOutputs:
146 if f.endswith(".txt"):
147 # must have two ":" in it ... check
148 if f.count(":") != 2:
149 if f.count(":")==1:
150 if f.split(":")[0] in knownTypes:
151 f = knownTypes[f.split(":")[0]] + ":" + f
152 else:
153 log.fatal(f"{f.split(':')[0]} has no known type. Add to algorithm metadata or otherwise specify it explicitly with '<type>:' prefix")
154 exit(-1)
155 else:
156 log.fatal("txt output must be specified in form <type>:<SGkey>:<filepath>")
157 exit(-1)
158 flags.GlobalSim.txtOutputs += [f]
159 elif f.endswith(".pool.root"):
160 # need to add filenames to available outputs
161 filename = f.split(":")[-1]
162 if filename not in filenameMap:
163 filenameMap[filename] = f"GSIM{len(filenameMap)}"
164 flags.addFlag("Output."+filenameMap[filename]+"FileName",filename) # used by OutputStreamConfig
165 flags.GlobalSim.poolOutputs += [f.replace(filename,filenameMap[filename])]
166
167
168# 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
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

Variable Documentation

◆ algName

plugin_miniSim.algName

Definition at line 179 of file plugin_miniSim.py.

◆ algos

list plugin_miniSim.algos = []

Definition at line 177 of file plugin_miniSim.py.

◆ algType

plugin_miniSim.algType

Definition at line 179 of file plugin_miniSim.py.

◆ allOutputs

dict plugin_miniSim.allOutputs = {}

Definition at line 239 of file plugin_miniSim.py.

◆ create

plugin_miniSim.create

Definition at line 234 of file plugin_miniSim.py.

◆ filepath

plugin_miniSim.filepath

Definition at line 187 of file plugin_miniSim.py.

◆ foundProp

bool foundProp = False

Definition at line 190 of file plugin_miniSim.py.

◆ itemLists

dict plugin_miniSim.itemLists = {}

Definition at line 259 of file plugin_miniSim.py.

◆ outputs

plugin_miniSim.outputs = getOutputs(alg,alg.name)

Definition at line 255 of file plugin_miniSim.py.

◆ p

dict plugin_miniSim.p = allOutputs[what]

Definition at line 265 of file plugin_miniSim.py.

◆ parentName

plugin_miniSim.parentName

Definition at line 170 of file plugin_miniSim.py.

◆ readerNames

list plugin_miniSim.readerNames = []

Definition at line 185 of file plugin_miniSim.py.

◆ sequenceName

plugin_miniSim.sequenceName = "GlobalSim"

Definition at line 169 of file plugin_miniSim.py.

◆ sgKey

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

Definition at line 187 of file plugin_miniSim.py.

◆ stream

plugin_miniSim.stream

Definition at line 262 of file plugin_miniSim.py.

◆ SubLevelBranchName

plugin_miniSim.SubLevelBranchName

Definition at line 278 of file plugin_miniSim.py.

◆ theAlg

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

Definition at line 180 of file plugin_miniSim.py.

◆ theType

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

Definition at line 266 of file plugin_miniSim.py.

◆ tobType

plugin_miniSim.tobType

Definition at line 187 of file plugin_miniSim.py.

◆ what

plugin_miniSim.what

Definition at line 262 of file plugin_miniSim.py.