4 Functions to solve dependencies of Jet reco components.
6 Jet reco components are objects described by classes in JetDefinition.py (including JetDefinition, JetModifier,...)
7 and the dependencies of each instance are set as (list of) string aliases refering to other components.
9 The functions here are scanning recursively all the aliases, building the corresponding component objects and
10 collecting them in a JetDefinition.
13 from .JetDefinition
import JetInputExternal, JetInputConstit, JetModifier, JetInputConstitSeq
21 """ Retrieve recursively all dependencies described by str aliases (from modifiers, ghosts, etc..) within jetdef0.
22 The aliases are converted in to proper config objects (like JetModifier, JetInputConstit,...) and are collected into
23 a cloned version of jetdef0.
25 The cloned version is returned and contains all the necessary information to build the actual C++ tools and algs.
26 (in particular, the _prereqDic and _prereqOrder internal members of the clone are filled).
27 The cloned version also has its member '._cflags' set to the given config flags (might be used to instantiate the dependencies).
28 If jetdef0.context=='default' than the cloned version has its context set according to flags
32 jetdef = jetdef0.clone()
33 jetdef._cflags = flags
34 jetdef._contextDic = flags.Jet.Context[jetdef0.context]
38 jetdef._prereqDic[
'input:'+jetdef.inputdef.name] = jetdef.inputdef
39 jetdef._prereqOrder.append(
'input:'+jetdef.inputdef.name)
41 for g
in jetdef.extrainputs:
43 jetdef._prereqDic[
'input:'+g] = gInstance
44 jetdef._prereqOrder.append(
'input:'+g)
46 for g
in jetdef.ghostdefs:
48 jetdef._prereqDic[
'input:'+g] = gInstance
49 jetdef._prereqOrder.append(
'input:'+g)
50 jetdef._prereqDic[
'ghost:'+g] = gInstance
51 jetdef._prereqOrder.append(
'ghost:'+g)
53 for mod
in jetdef.modifiers:
55 jetdef._prereqDic[
'mod:'+mod] = modInstance
56 jetdef._prereqOrder.append(
'mod:'+mod)
59 jetdef._prereqOrder[:] =
list(dict.fromkeys(jetdef._prereqOrder) )
65 """Retrieve all dependencies described by str aliases in groomdef0.modifiers.
67 The aliases are converted in to proper config objects (like JetModifier, JetInputConstit,...) and are collected into
68 a cloned version of groomdef0.
69 The cloned version is returned and contains all the necessary information to build the actual C++ tools and algs.
70 (in particular, the _prereqDic and _prereqOrder internal members of the clone are filled).
74 groomdef = groomdef0.clone()
75 groomdef._cflags = flags
76 groomdef._contextDic = flags.Jet.Context[groomdef0.context]
78 for mod
in groomdef.modifiers:
80 groomdef._prereqDic[
'mod:'+mod] = modInstance
81 groomdef._prereqOrder.append(
'mod:'+mod)
86 """convert a string alias to a full config object, either a JetInputConstitSeq or a JetInputExternal according to the alias.
88 This also recursively translate all aliases which are dependencies of this alias. All these dependencies are
89 collected into the 'parentjetdef' (JetDefinition ).
91 if canBeConstit==false, the alias is not searched amongst known JetInputConstitSeq (in stdConstitDic),
96 if isinstance(alias, JetInputConstit):
99 if isinstance(alias, JetInputExternal):
106 from .StandardJetConstits
import stdConstitDic, stdInputExtDic
108 if canBeConstit
and alias
in stdConstitDic:
111 elif alias
in stdInputExtDic :
115 raise Exception(f
"Could not match a known jet input definition for '{alias}' ")
118 """Recursively translate all aliases appearing in the prereqs of constitseq into proper config objects.
119 All are collected into the parentjetdef for which this JetInputConstitSeq is being configured.
120 Then instantiates all aliases for JetConstitModifier
124 constitseq = constitseq.clone()
126 from .StandardJetConstits
import stdInputExtDic, stdContitModifDic
128 stdInputExtDic.setdefault( constitseq.inputname,
JetInputExternal( constitseq.inputname, constitseq.basetype) )
133 if callable(constitseq.inputname):
134 constitseq.prereqs += [
'ext'+constitseq.inputname(parentjetdef)]
136 constitseq.prereqs += [
'extinput:'+constitseq.inputname]
138 if isinstance( constitseq, JetInputConstitSeq):
140 for mod
in constitseq.modifiers:
141 modInstance = stdContitModifDic[ mod ].
clone()
142 parentjetdef._prereqDic[f
'cmod:{mod}'] = modInstance
150 """Recursively translate all aliases appearing in the prereqs of jetinputext into proper config objects.
151 All are collected into the parentjetdef for which this JetInputConstitSeq is being configured.
154 jetinputext = jetinputext.clone()
158 if callable(jetinputext.prereqs):
160 jetinputext.prereqs = jetinputext.prereqs(parentjetdef)
162 jetinputext.prereqs = [ prereq(parentjetdef)
if callable(prereq)
164 for prereq
in jetinputext.prereqs ]
167 for prereq
in jetinputext.prereqs :
168 reqInstance = parentjetdef._prereqDic.get( prereq,
None)
169 if reqInstance
is None:
170 reqType , inputkey = prereq.split(
':')
172 canBeConstit = (reqType !=
"extinput") )
173 parentjetdef._prereqDic[prereq] = reqInstance
174 parentjetdef._prereqOrder.append(prereq)
182 """translate a prereq string in the form 'type:alias' into a known config object.
184 str_prereq = prereq(parentjetdef)
if callable(prereq)
else prereq
185 reqtype, reqkey = str_prereq.split(
':',1)
193 """return a JetModifier config object corresponding to alias, also recursively translating all aliases in the dependencies of this JetModifier."""
194 if isinstance(alias, JetModifier):
199 modL = alias.split(
":")
201 modspec =
':'.
join(modL[1:])
204 from .StandardJetMods
import stdJetModifiers
205 moddef = stdJetModifiers[modkey].
clone( modspec = modspec)
208 if callable(moddef.prereqs):
209 moddef.prereqs = moddef.prereqs( modspec, parentjetdef )
211 for prereq
in moddef.prereqs:
212 str_prereq = prereq(parentjetdef)
if callable(prereq)
else prereq
213 reqInstance = parentjetdef._prereqDic.get( str_prereq,
None)
214 if reqInstance
is None:
215 reqInstance =
prereqToDef(str_prereq, parentjetdef)
217 if str_prereq.startswith(
'ghost:'):
219 prereqN = str_prereq.split(
':')[1]
220 parentjetdef._prereqOrder.append(
'input:'+prereqN)
221 parentjetdef._prereqDic[
'input:'+prereqN] = reqInstance
223 parentjetdef._prereqOrder.append(str_prereq)
224 parentjetdef._prereqDic[str_prereq] = reqInstance