11 from AthenaCommon.Logging
import logging
12 log = logging.getLogger(
'plugin_miniSim')
15 flags.DQ.doMonitoring=
False
16 flags.Trigger.enableL1CaloPhase1=
False
18 flags.addFlag(
"GlobalSim.Algs",[])
19 flags.addFlag(
"GlobalSim.txtInputs",[])
20 flags.addFlag(
"GlobalSim.txtOutputs",[])
22 from AthenaConfiguration.ComponentFactory
import CompFactory
23 availableAlgs = [f[:-3]
for f
in CompFactory.GlobalSim._getEntries()[-1]
if f.endswith(
'Alg')]
25 if flags.hasFlag(
"L1CaloAthMon.UnknownArgs"):
28 parser = argparse.ArgumentParser()
29 parser.add_argument(
'--algs',nargs=
'*',default=[],help=f
"algs to run. Available are: {', '.join(availableAlgs)}")
30 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>)")
31 parser.add_argument(
'--filesOutput',nargs=
'*',default=[],help=
"outputs to save, specify similarly to inputs")
32 args,unknown = parser.parse_known_args(flags.L1CaloAthMon.UnknownArgs)
33 flags.L1CaloAthMon.UnknownArgs = unknown
34 flags.GlobalSim.Algs = args.algs
35 flags.GlobalSim.txtOutputs = args.filesOutput
37 if len(flags.GlobalSim.Algs) == 0:
38 log.fatal(
"You must specify what algorithms to run. Use the --algs option")
39 log.fatal(f
"Available algs: {availableAlgs}")
48 for alg
in flags.GlobalSim.Algs:
50 algType,algName = (alg.split(
"/")
if "/" in alg
else [alg,alg])
51 if not hasattr(CompFactory.GlobalSim,algType+
"Alg"):
52 log.fatal(f
"Unknown Alg: {algType}")
53 log.fatal(f
"Available Algs: {availableAlgs}")
56 from GaudiKernel.DataHandle
import DataHandle
57 from AthenaCommon
import CfgMgr
58 propDocs = getattr(CfgMgr,f
"GlobalSim__{algType}Alg")._propertyDocDct
59 for propName,propVal
in getattr(CompFactory.GlobalSim,algType+
"Alg").getDefaultProperties().items():
60 if not isinstance(propVal,DataHandle):
continue
61 sgKey = propVal.Path.split(
'+')[-1]
63 for item
in propDocs[propName].
split(
";"):
65 if item.startswith(
"type="):
66 knownTypes[sgKey] = item[len(
"type="):]
67 knownTypes[f
"{algName}.{propName}"] = item[len(
"type="):]
69 if propVal.Mode ==
'W':
71 if sgKey
not in outputsMap: outputsMap[sgKey] = []
72 outputsMap[sgKey] += [f
"{algName}.{propName}"]
75 if sgKey
not in inputsMap: inputsMap[sgKey] = []
76 inputsMap[sgKey] += [f
"{algName}.{propName}"]
80 algInputs -= algOutputs
82 log.info(f
"Your algorithms {flags.GlobalSim.Algs} require the following inputs: {[i for a in algInputs for i in inputsMap[a]]}")
83 log.info(f
"and produces the following outputs: {[i for a in algOutputs for i in outputsMap[a]]}")
87 for f
in flags.Input.Files:
88 if f.endswith(
".txt"):
92 if f.split(
":")[0]
in knownTypes:
93 f = knownTypes[f.split(
":")[0]] +
":" + f
95 log.fatal(f
"{f.split(':')[0]} has no known type. Add to algorithm metadata or otherwise specify it explicitly with '<type>:' prefix")
98 log.fatal(
"txt input must be specified in form <type>:<SGkey>:<filepath>")
100 flags.GlobalSim.txtInputs += [f]
103 flags.Input.Files = cleanList
105 if len(flags.GlobalSim.txtInputs):
106 flags.Input.isMC =
True
108 if flags.Exec.MaxEvents==-1:
111 for f
in flags.GlobalSim.txtInputs:
112 typeAndName,path = f.rsplit(
":",1)
113 if typeAndName
not in maxVals: maxVals[typeAndName]=0
114 maxVals[typeAndName] += sum(1
for _
in open(path))
115 flags.Exec.MaxEvents =
max(maxVals.values())
117 log.info(f
"Processing {flags.Exec.MaxEvents} events from txt filesInput")
119 txtOutputs = list(flags.GlobalSim.txtOutputs)
120 flags.GlobalSim.txtOutputs = []
122 if f.endswith(
".txt"):
124 if f.count(
":") != 2:
126 if f.split(
":")[0]
in knownTypes:
127 f = knownTypes[f.split(
":")[0]] +
":" + f
129 log.fatal(f
"{f.split(':')[0]} has no known type. Add to algorithm metadata or otherwise specify it explicitly with '<type>:' prefix")
132 log.fatal(
"txt output must be specified in form <type>:<SGkey>:<filepath>")
134 flags.GlobalSim.txtOutputs += [f]
213 from OutputStreamAthenaPool.OutputStreamConfig
import OutputStreamCfg
214 from GaudiKernel.DataHandle
import DataHandle
215 algo = cfg.getEventAlgo(algName)
217 for propName
in algo.getDefaultProperties().keys():
218 p = algo.__getattribute__(propName)
219 if isinstance(p,DataHandle)
and p.Mode==
'W':
220 items += [f
"{p.Type}#{p.Path.split('+')[-1]}",f
"xAOD::AuxContainerBase#{p.Path.split('+')[-1]}Aux."]
221 cfg.merge(OutputStreamCfg(flags,
'AOD', ItemList=items,takeItemsFromInput=
False,disableEventTag=
True))