195 """ Creates the filters and connect them to the menu sequences"""
198 chainWithMaxSteps =
max(chains, key =
lambda chain: len(chain.steps))
199 NSTEPS = len(chainWithMaxSteps.steps)
200 log.info(
"[createDataFlow] creating DF for %d chains and total %d steps", len(chains), NSTEPS)
203 finalDecisions = [ []
for n
in range(NSTEPS) ]
204 CFseqList = [ []
for n
in range(NSTEPS) ]
205 CFSeqByFilterName = [ {}
for n
in range(NSTEPS) ]
209 log.debug(
"\n Configuring chain %s with %d steps: \n - %s ", chain.name,len(chain.steps),
'\n - '.
join(map(str, [{step.name:step.multiplicity}
for step
in chain.steps])))
213 for nstep, chainStep
in enumerate( chain.steps ):
214 if not flags.Trigger.fastMenuGeneration:
216 chainStep.createSequences()
217 log.debug(
"\n************* Start connecting step %d %s for chain %s", nstep+1, chainStep.name, chain.name)
219 filterInput = chain.L1decisions
221 filterInput = lastDecisions
222 if len(filterInput) == 0 :
223 log.error(
"[createDataFlow] Filter for step %s has %d inputs! At least one is expected", chainStep.name, len(filterInput))
224 raise Exception(
"[createDataFlow] Cannot proceed, exiting.")
226 log.debug(
"Set Filter input: %s while setting the chain: %s", filterInput, chain.name)
229 sequenceFilter =
None
230 filterName = CFNaming.filterName(chainStep.name)
231 if chainStep.isEmpty:
232 filterOutput = filterInput
234 filterOutput = [CFNaming.filterOutName(filterName, inputName)
for inputName
in filterInput ]
237 foundCFgroup = CFSeqByFilterName[nstep].
get(filterName,
None)
238 log.debug(
"%s CF sequences with filter name %s",
"Not found" if foundCFgroup
is None else "Found", filterName)
239 if foundCFgroup
is None:
240 sequenceFilter =
buildFilter(filterName, filterInput, chainStep.isEmpty)
241 if flags.Trigger.fastMenuGeneration:
243 chainStep.createSequences()
245 CFgroup = CFGroup( ChainStep = chainStep, FilterAlg = sequenceFilter)
246 CFgroup.connect(filterOutput)
247 CFSeqByFilterName[nstep][sequenceFilter.Alg.getName()] = CFgroup
248 CFseqList[nstep].
append(CFgroup)
249 lastCFgroup = CFgroup
251 lastCFgroup = foundCFgroup
252 sequenceFilter = lastCFgroup.sequenceCA.filterNode
254 [ sequenceFilter.addInput(inputName)
for inputName
in filterInput ]
255 [ sequenceFilter.addOutput(outputName)
for outputName
in filterOutput ]
256 lastCFgroup.connect(filterOutput)
258 lastDecisions = lastCFgroup.sequenceCA.decisions
261 chainLegs = chainStep.getChainLegs()
262 if len(chainLegs) != len(filterInput):
263 log.error(
"[createDataFlow] lengths of chainlegs = %s differ from inputs = %s",
str(chainLegs),
str(filterInput))
264 raise Exception(
"[createDataFlow] Cannot proceed, exiting.")
265 for finput, leg
in zip(filterInput, chainLegs):
266 log.debug(
"Adding chain %s to input %s of %s", leg, finput, sequenceFilter.Alg.name)
267 sequenceFilter.addChain(leg, finput)
269 log.debug(
"Now Filter has chains: %s", sequenceFilter.getChains())
270 log.debug(
"Now Filter has chains/input: %s", sequenceFilter.getChainsPerInput())
272 lastCFgroup.addStepLeg(chainStep, chain.name)
274 if len(chain.steps) == nstep+1:
275 log.debug(
"Adding finalDecisions for chain %s at step %d:", chain.name, nstep+1)
276 for dec
in lastDecisions:
277 finalDecisions[nstep].
append(dec)
281 log.debug(
"\n Built CD for chain %s with %d steps: \n - %s ", chain.name,len(chain.steps),
'\n - '.
join(map(str, [{step.name:step.multiplicity}
for step
in chain.steps])))
284 log.debug(
"End of createDataFlow for %d chains and total %d steps", len(chains), NSTEPS)
285 return (finalDecisions, CFseqList)