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