14 from AthenaCommon.Logging
import logging
15 log = logging.getLogger(
'plugin_miniSim')
18 flags.DQ.doMonitoring=
False
19 flags.Trigger.enableL1CaloPhase1=any([flags.Trigger.L1.doeFex,flags.Trigger.L1.dojFex,flags.Trigger.L1.dogFex])
21 flags.addFlag(
"GlobalSim.Algs",[])
22 flags.addFlag(
"GlobalSim.txtInputs",[])
23 flags.addFlag(
"GlobalSim.txtOutputs",[])
24 flags.addFlag(
"GlobalSim.poolOutputs",[])
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]
31 if flags.hasFlag(
"L1CaloAthMon.UnknownArgs"):
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>)")
38 parser.add_argument(
'--filesOutput',nargs=
'*',default=[],help=
"outputs to save, specify similarly to inputs")
39 if "--help" in flags.L1CaloAthMon.UnknownArgs:
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():
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
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])
71 for alg
in flags.GlobalSim.Algs:
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}")
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
84 sgKey = propVal.Path.split(
'+')[-1]
86 for item
in propDocs[propName].
split(
";"):
88 if item.startswith(
"type="):
89 knownTypes[sgKey] = item[len(
"type="):]
90 knownTypes[f
"{algName}.{propName}"] = item[len(
"type="):]
92 if propVal.Mode ==
'W':
94 if sgKey
not in outputsMap: outputsMap[sgKey] = []
95 outputsMap[sgKey] += [f
"{algName}.{propName}"]
98 if sgKey
not in inputsMap: inputsMap[sgKey] = []
99 inputsMap[sgKey] += [f
"{algName}.{propName}"]
103 algInputs -= algOutputs
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]]}")
110 for f
in flags.Input.Files:
111 if f.endswith(
".txt"):
113 if f.count(
":") != 2:
115 if f.split(
":")[0]
in knownTypes:
116 f = knownTypes[f.split(
":")[0]] +
":" + f
118 log.fatal(f
"{f.split(':')[0]} has no known type. Add to algorithm metadata or otherwise specify it explicitly with '<type>:' prefix")
121 log.fatal(
"txt input must be specified in form <type>:<SGkey>:<filepath>")
123 flags.GlobalSim.txtInputs += [f]
126 flags.Input.Files = cleanList
128 if len(flags.GlobalSim.txtInputs):
129 flags.Input.isMC =
True
131 if flags.Exec.MaxEvents==-1:
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())
140 log.info(f
"Processing {flags.Exec.MaxEvents} events from txt filesInput")
142 txtOutputs = list(flags.GlobalSim.txtOutputs)
143 flags.GlobalSim.txtOutputs = []
146 if f.endswith(
".txt"):
148 if f.count(
":") != 2:
150 if f.split(
":")[0]
in knownTypes:
151 f = knownTypes[f.split(
":")[0]] +
":" + f
153 log.fatal(f
"{f.split(':')[0]} has no known type. Add to algorithm metadata or otherwise specify it explicitly with '<type>:' prefix")
156 log.fatal(
"txt output must be specified in form <type>:<SGkey>:<filepath>")
158 flags.GlobalSim.txtOutputs += [f]
159 elif f.endswith(
".pool.root"):
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)
165 flags.GlobalSim.poolOutputs += [f.replace(filename,filenameMap[filename])]