106 Open json files and load all merged contents
107 in a dictionary, which is later converted to a
108 list of strings, each to be parsed in a
109 (flattened) json format
111 log = logging.getLogger(
"getPlotsDefList" )
114 log.debug(
"plotsDefFileList : %s", flags.PhysVal.IDTPM.plotsDefFileList )
115 listPath =
find_datafile( flags.PhysVal.IDTPM.plotsDefFileList )
117 log.error(
"plotsDefFileList not found" )
120 plotsDefFileNames = []
121 with open( listPath,
"r" )
as input_flist :
122 plotsDefFileNames = input_flist.read().splitlines()
127 for plotsDefFileName
in plotsDefFileNames :
129 log.debug(
"Reading input plots definitions : %s", dataPath )
131 log.error(
"plotsDefFile %s not found", plotsDefFileName )
134 with open( dataPath,
"r" )
as input_json_file :
135 plotsDefDict.update( json.load( input_json_file ) )
143 def flatten_json( y ) :
145 def flatten(x, name=''):
148 flatten(x[a], name + a +
'_')
154 plotsDefStrList_v1 = []
155 for plotName, plotDict
in plotsDefDict.items():
156 newPlotDict = plotDict.copy()
157 newPlotDict[
"name" ] = plotName
160 plotDictFlat = flatten_json( newPlotDict )
163 plotDefStr =
str( json.dumps( plotDictFlat ) )
166 plotsDefStrList_v1.append( plotDefStr )
170 plotsCommonValuesFileName = flags.PhysVal.IDTPM.plotsCommonValuesFile
171 if not plotsCommonValuesFileName :
172 if flags.Detector.GeometryID :
173 plotsCommonValuesFileName =
"InDetTrackPerfMon/PlotsDefCommonValues.json"
174 elif flags.Detector.GeometryITk :
175 plotsCommonValuesFileName =
"InDetTrackPerfMon/PlotsDefCommonValues_ITk.json"
177 log.error(
"Could not get detector geometry for plotsCommonValuesFile" )
180 commonValuesPath =
find_datafile( plotsCommonValuesFileName )
181 if commonValuesPath
is None :
182 log.error(
"plotsCommonValuesFile not found: %s", plotsCommonValuesFileName )
185 commonValuesDict = {}
186 with open( commonValuesPath,
"r" )
as input_commonValues :
187 commonValuesDict.update( json.load( input_commonValues ) )
189 plotsDefStrList_v2 = []
190 for plotDefStr
in plotsDefStrList_v1 :
191 newPlotDefStr = plotDefStr
192 if commonValuesDict :
193 for key, value
in commonValuesDict.items() :
194 plotDefStr_tmp = newPlotDefStr.replace(
"$"+key, value[0] )
195 newPlotDefStr = plotDefStr_tmp
196 plotsDefStrList_v2.append( newPlotDefStr )
199 testLabel =
getLabel( flags, flags.PhysVal.IDTPM.currentTrkAna.TestType )
200 refLabel =
getLabel( flags, flags.PhysVal.IDTPM.currentTrkAna.RefType )
201 trkLabels = [ testLabel, refLabel ]
203 if flags.PhysVal.IDTPM.currentTrkAna.MatchingType ==
"EFTruthMatch":
204 trkLabels.append(
getLabel( flags,
"Truth" ) )
207 for plotsDefStr
in plotsDefStrList_v2 :
208 plotsDefStr = plotsDefStr.replace(
"$TESTTYPE", testLabel[0] ).
replace(
"$TESTTAG", testLabel[1] )
209 plotsDefStr = plotsDefStr.replace(
"$REFTYPE", refLabel[0] ).
replace(
"$REFTAG", refLabel[1] )
210 if (
"$TRKTAG" not in plotsDefStr )
and (
"$TRKTYPE" not in plotsDefStr ) :
211 plotsDefStrList.append( plotsDefStr )
213 for trkLabel
in trkLabels :
214 newPlotsDefStr = plotsDefStr.replace(
"$TRKTYPE", trkLabel[0] ).
replace(
"$TRKTAG", trkLabel[1] )
215 if (
"$TRK2TAG" not in newPlotsDefStr )
and (
"$TRK2TYPE" not in newPlotsDefStr ) :
216 plotsDefStrList.append( newPlotsDefStr )
218 for trk2Label
in trkLabels :
219 newPlotsDefStr2 = newPlotsDefStr.replace(
"$TRK2TYPE", trk2Label[0] ).
replace(
"$TRK2TAG", trk2Label[1] )
220 plotsDefStrList.append( newPlotsDefStr2 )
222 return plotsDefStrList