86def generateJSON(flags, chainDicts, HLTAllSteps):
87 """ Generates JSON given the ChainProps and sequences
88 """
89
90 menuDict = {"filetype": "hltmenu",
91 "name": __getMenuBaseName(flags.Trigger.triggerMenuSetup),
92 "chains": {},
93 "streams": {},
94 "sequencers": {}}
95
96
97 stepsData = __getStepsDataFromAlgSequence(HLTAllSteps)
98 chainSequencers = __getChainSequencers(stepsData)
99 from TriggerMenuMT.HLT.Menu import StreamInfo
100 for chain in chainDicts:
101
102 chainStreamTags = []
103 for streamName in chain["stream"]:
104 streamTag = StreamInfo.getStreamTag(streamName)
105
106 if streamTag is None:
107 __log.error('Stream %s does not have StreamTags defined excluding from JSON', streamName)
108 continue
109
110 chainStreamTags.append(streamName)
111
112 if streamName not in menuDict["streams"]:
113 menuDict["streams"][streamName] = {
114 "name": streamName,
115 "type": streamTag.type(),
116 "obeyLB": streamTag.obeysLumiBlock(),
117 "forceFullEventBuilding": streamTag.forceFullEventBuilding()
118 }
119
120
121 l1Thresholds = []
122
123 [ l1Thresholds.append(p['L1threshold']) for p in chain['chainParts'] ]
124
125
126 chainName = chain["chainName"]
127 menuDict["chains"][chainName] = {
128 "counter": chain["chainCounter"],
129 "nameHash": chain["chainNameHash"],
130 "legMultiplicities": chain["chainMultiplicities"],
131 "l1item": chain["L1item"],
132 "l1thresholds": l1Thresholds,
133 "groups": chain["groups"],
134 "streams": chainStreamTags,
135 "sequencers": chainSequencers.get(chainName, [])
136 }
137
138
139 menuDict["sequencers"].update( __getSequencerAlgs(stepsData) )
140
141 __validateJSON(menuDict)
142
143
144 fileName = getHLTMenuFileName( flags)
145 __log.info( "Writing HLT Menu JSON to %s", fileName )
146 with open( fileName, 'w' ) as fp:
147 json.dump( menuDict, fp, indent=4, sort_keys=False )
148
149