11 from AthenaCommon.Logging import logging
12 log = logging.getLogger('plugin_miniSim')
13
14
15 flags.DQ.doMonitoring=False
16 flags.Trigger.enableL1CaloPhase1=False
17
18 flags.addFlag("GlobalSim.Algs",[])
19 flags.addFlag("GlobalSim.txtInputs",[])
20 flags.addFlag("GlobalSim.txtOutputs",[])
21
22 from AthenaConfiguration.ComponentFactory import CompFactory
23 availableAlgs = [f[:-3] for f in CompFactory.GlobalSim._getEntries()[-1] if f.endswith('Alg')]
24
25 if flags.hasFlag("L1CaloAthMon.UnknownArgs"):
26
27 import argparse
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
36
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}")
40 exit(-1)
41
42
45 inputsMap = {}
46 outputsMap = {}
47 knownTypes = {}
48 for alg in flags.GlobalSim.Algs:
49
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}")
54 exit(-1)
55
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]
62
63 for item
in propDocs[propName].
split(
";"):
64 item = item.strip()
65 if item.startswith("type="):
66 knownTypes[sgKey] = item[len("type="):]
67 knownTypes[f"{algName}.{propName}"] = item[len("type="):]
68 break
69 if propVal.Mode == 'W':
70 algOutputs.add(sgKey)
71 if sgKey not in outputsMap: outputsMap[sgKey] = []
72 outputsMap[sgKey] += [f"{algName}.{propName}"]
73 else:
74 algInputs.add(sgKey)
75 if sgKey not in inputsMap: inputsMap[sgKey] = []
76 inputsMap[sgKey] += [f"{algName}.{propName}"]
77
78
79
80 algInputs -= algOutputs
81
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]]}")
84
85
86 cleanList = []
87 for f in flags.Input.Files:
88 if f.endswith(".txt"):
89
90 if f.count(":") != 2:
91 if f.count(":")==1:
92 if f.split(":")[0] in knownTypes:
93 f = knownTypes[f.split(":")[0]] + ":" + f
94 else:
95 log.fatal(f"{f.split(':')[0]} has no known type. Add to algorithm metadata or otherwise specify it explicitly with '<type>:' prefix")
96 exit(-1)
97 else:
98 log.fatal("txt input must be specified in form <type>:<SGkey>:<filepath>")
99 exit(-1)
100 flags.GlobalSim.txtInputs += [f]
101 else:
102 cleanList += [f]
103 flags.Input.Files = cleanList
104
105 if len(flags.GlobalSim.txtInputs):
106 flags.Input.isMC = True
107
108 if flags.Exec.MaxEvents==-1:
109
110 maxVals = {}
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())
116
117 log.info(f"Processing {flags.Exec.MaxEvents} events from txt filesInput")
118
119 txtOutputs = list(flags.GlobalSim.txtOutputs)
120 flags.GlobalSim.txtOutputs = []
121 for f in txtOutputs:
122 if f.endswith(".txt"):
123
124 if f.count(":") != 2:
125 if f.count(":")==1:
126 if f.split(":")[0] in knownTypes:
127 f = knownTypes[f.split(":")[0]] + ":" + f
128 else:
129 log.fatal(f"{f.split(':')[0]} has no known type. Add to algorithm metadata or otherwise specify it explicitly with '<type>:' prefix")
130 exit(-1)
131 else:
132 log.fatal("txt output must be specified in form <type>:<SGkey>:<filepath>")
133 exit(-1)
134 flags.GlobalSim.txtOutputs += [f]
135 else:
136 pass
137
138
139
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=":")