115 Open json files and load all merged contents
116 in a dictionary, which is later converted to a
117 list of strings, each to be parsed in a
118 (flattened) json format
120 log = logging.getLogger(
"getPlotsDefList" )
123 log.debug(
"plotsDefFileList : %s", flags.PhysVal.IDTPM.plotsDefFileList )
126 log.error(
"plotsDefFileList not found" )
129 plotsDefFileNames = []
130 with open( listPath,
"r" )
as input_flist :
131 plotsDefFileNames = input_flist.read().splitlines()
136 for plotsDefFileName
in plotsDefFileNames :
138 log.debug(
"Reading input plots definitions : %s", dataPath )
140 log.error(
"plotsDefFile %s not found", plotsDefFileName )
143 with open( dataPath,
"r" )
as input_json_file :
144 plotsDefDict.update( json.load( input_json_file ) )
152 def flatten_json( y ) :
154 def flatten(x, name=''):
157 flatten(x[a], name + a +
'_')
163 plotsDefStrList_v1 = []
164 for plotName, plotDict
in plotsDefDict.items():
165 newPlotDict = plotDict.copy()
166 newPlotDict[
"name" ] = plotName
169 plotDictFlat = flatten_json( newPlotDict )
172 plotDefStr =
str( json.dumps( plotDictFlat ) )
175 plotsDefStrList_v1.append( plotDefStr )
179 plotsCommonValuesFileName = flags.PhysVal.IDTPM.plotsCommonValuesFile
180 if not plotsCommonValuesFileName :
181 if flags.Detector.GeometryID :
182 plotsCommonValuesFileName =
"InDetTrackPerfMon/PlotsDefCommonValues.json"
183 elif flags.Detector.GeometryITk :
184 plotsCommonValuesFileName =
"InDetTrackPerfMon/PlotsDefCommonValues_ITk.json"
186 log.error(
"Could not get detector geometry for plotsCommonValuesFile" )
190 if commonValuesPath
is None :
191 log.error(
"plotsCommonValuesFile not found: %s", plotsCommonValuesFileName )
194 commonValuesDict = {}
195 with open( commonValuesPath,
"r" )
as input_commonValues :
196 commonValuesDict.update( json.load( input_commonValues ) )
198 plotsDefStrList_v2 = []
199 for plotDefStr
in plotsDefStrList_v1 :
200 newPlotDefStr = plotDefStr
201 if commonValuesDict :
202 for key, value
in commonValuesDict.items() :
203 plotDefStr_tmp = newPlotDefStr.replace(
"$"+key, value[0] )
204 newPlotDefStr = plotDefStr_tmp
205 plotsDefStrList_v2.append( newPlotDefStr )
208 testLabel =
getLabel( flags, flags.PhysVal.IDTPM.currentTrkAna.TestType )
209 refLabel =
getLabel( flags, flags.PhysVal.IDTPM.currentTrkAna.RefType )
210 trkLabels = [ testLabel, refLabel ]
212 testAllLabel =
getAllTruthLabel( flags, flags.PhysVal.IDTPM.currentTrkAna.TestType )
213 refAllLabel =
getAllTruthLabel( flags, flags.PhysVal.IDTPM.currentTrkAna.RefType )
216 if flags.PhysVal.IDTPM.currentTrkAna.MatchingType ==
"EFTruthMatch":
217 trkLabels.append(
getLabel( flags,
"Truth" ) )
221 for plotsDefStr
in plotsDefStrList_v2 :
222 plotsDefStr = plotsDefStr.replace(
"$TESTALL", testAllLabel ).
replace(
"$REFALL", refAllLabel )
223 plotsDefStr = plotsDefStr.replace(
"$TESTTYPE", testLabel[1] ).
replace(
"$TESTTAG", testLabel[0] )
224 plotsDefStr = plotsDefStr.replace(
"$REFTYPE", refLabel[1] ).
replace(
"$REFTAG", refLabel[0] )
225 if (
"$TRKTAG" not in plotsDefStr )
and (
"$TRKTYPE" not in plotsDefStr ) :
226 plotsDefStrList.append( plotsDefStr )
228 for trkLabel
in trkLabels :
229 newPlotsDefStr = plotsDefStr.replace(
"$TRKTYPE", trkLabel[1] ).
replace(
"$TRKTAG", trkLabel[0] )
230 if (
"$TRK2TAG" not in newPlotsDefStr )
and (
"$TRK2TYPE" not in newPlotsDefStr ) :
231 plotsDefStrList.append( newPlotsDefStr )
233 for trk2Label
in trkLabels :
234 newPlotsDefStr2 = newPlotsDefStr.replace(
"$TRK2TYPE", trk2Label[1] ).
replace(
"$TRK2TAG", trk2Label[0] )
235 plotsDefStrList.append( newPlotsDefStr2 )
238 plotsDefStrList_v2 = []
239 for plotsDefStr
in plotsDefStrList :
240 plotsDefStr = plotsDefStr.replace(
"$TESTVTXTYPE", testLabel[2] ).
replace(
"$TESTVTXTAG", testLabel[0] )
241 plotsDefStr = plotsDefStr.replace(
"$REFVTXTYPE", refLabel[2] ).
replace(
"$REFVTXTAG", refLabel[0] )
242 if (
"$VTXTAG" not in plotsDefStr )
and (
"$VTXTYPE" not in plotsDefStr ) :
243 plotsDefStrList_v2.append( plotsDefStr )
245 for trkLabel
in trkLabels :
246 newPlotsDefStr = plotsDefStr.replace(
"$VTXTYPE", trkLabel[2] ).
replace(
"$VTXTAG", trkLabel[0] )
247 if (
"$VTX2TAG" not in newPlotsDefStr )
and (
"$VTX2TYPE" not in newPlotsDefStr ) :
248 plotsDefStrList_v2.append( newPlotsDefStr )
250 for trk2Label
in trkLabels :
251 newPlotsDefStr2 = newPlotsDefStr.replace(
"$VTX2TYPE", trk2Label[2] ).
replace(
"$VTX2TAG", trk2Label[0] )
252 plotsDefStrList_v2.append( newPlotsDefStr2 )
254 return plotsDefStrList_v2