152def parsePlots(filename,varCaption) :
153 inputfile=open(filename)
154 parsedPlots = []
155 parsedRestricts = []
156 for line in inputfile :
157 line = line.expandtabs(1)
158 line = line.rstrip("\n")
159 line = line.split("#")[0]
160 line = line.split(" ")
161 line[:] = [x for x in line if (len(x) > 0) ]
162 if len(line) == 0 :
163 continue
164 pe = PlotEntry()
165 if line[0] == "hist" :
166 pe.vars_to_draw.append(line[1])
167 pe.givenmin = float(line[2])
168 pe.givenmax = float(line[3])
169 pe.nbins = int(line[4])
170 pe.logy = int(line[5])
171 pe.display_name = " ".join(line[6:])
172 for var in pe.vars_to_draw :
173 varcap = varCaption(var.lstrip("+"))
174 if (varcap == "") :
175 varcap = var.lstrip("+")
176 pe.axis_captions[var.lstrip("+")]=varcap
177 if (pe.vars_to_draw[0].startswith("+")) and ((pe.givenmin < 0) or (pe.givenmax < 0)) :
178 print ("WARNING: Boundaries are less the zero, while the variable is absolute. Ignore.")
179 pe.givenmin = 0.0
180 pe.givenmax = 0.0
181 print ("Found 1D histogram:",pe.vars_to_draw[0],[pe.givenmin,pe.givenmax])
182 parsedPlots.append(pe)
183 elif line[0] == "prof" :
184 pe.vars_to_draw.extend(line[1:3])
185 pe.givenmin = float(line[3])
186 pe.givenmax = float(line[4])
187 pe.nbins = int(line[5])
188 pe.logy = int(line[6])
189 pe.display_name = " ".join(line[7:])
190 pe.profile = True
191 for var in pe.vars_to_draw :
192 varcap = varCaption(var.lstrip("+"))
193 if (varcap == "") :
194 varcap = var.lstrip("+")
195 pe.axis_captions[var.lstrip("+")]=varcap
196 if (pe.vars_to_draw[0].startswith("+")) and ((pe.givenmin < 0) or (pe.givenmax < 0)) :
197 print ("WARNING: Boundaries are less the zero, while the variable is absolute. Ignore.")
198 pe.givenmin = 0.0
199 pe.givenmax = 0.0
200 print ("Found 1D profile:",pe.vars_to_draw[1],"vs",pe.vars_to_draw[0],[pe.givenmin,pe.givenmax])
201 parsedPlots.append(pe)
202 elif line[0] == "hist2d" :
203 pe = PlotEntry()
204 pe.vars_to_draw.extend(line[1:3])
205 pe.givenmin = 0
206 pe.givenmax = 0
207 pe.nbins = [int(line[3]), int(line[4])]
208 pe.logy = 0
209 pe.display_name = " ".join(line[5:])
210 pe.i2d = True
211 for var in pe.vars_to_draw :
212 varcap = varCaption(var.lstrip("+"))
213 if (varcap == "") :
214 varcap = var.lstrip("+")
215 pe.axis_captions[var.lstrip("+")]=varcap
216 print ("Found 2D histogram:",pe.vars_to_draw)
217 parsedPlots.append(pe)
218 elif line[0] == "prof2d" :
219 pe.vars_to_draw.extend(line[1:4])
220 pe.givenmin = 0
221 pe.givenmax = 0
222 pe.nbins = [int(line[4]), int(line[5])]
223 pe.logy = 0
224 pe.display_name = " ".join(line[6:])
225 pe.profile = True
226 pe.i2d = True
227 for var in pe.vars_to_draw :
228 varcap = varCaption(var.lstrip("+"))
229 if (varcap == "") :
230 varcap = var.lstrip("+")
231 pe.axis_captions[var.lstrip("+")]=varcap
232 print ("Found 2D profile:",pe.vars_to_draw[2],"vs",pe.vars_to_draw[0:2])
233 parsedPlots.append(pe)
234 elif line[0] == "restrict" :
235 re = RestrictEntry()
236 abs = False
237 if line[1].startswith("+") :
238 abs = True
239 line[1] = line[1][1:]
240 re.var = line[1]
241 for rang in line[2:] :
242 if abs :
243 re.addRangeAbs(rang)
244 else :
245 re.addRange(rang)
246 if (len(parsedPlots) > 0) :
247 rstrict = parsedPlots[-1].restricts
248 else :
249 rstrict = parsedRestricts
250 for rech in rstrict :
251 if (rech.var == re.var) :
252 rech.rangeList += re.rangeList
253 re.rangeList = []
254 if (len(re.rangeList) > 0) :
255 print ("A restriction found for variable",str(re))
256 rstrict.append(re)
257 elif line[0] == "axisname" :
258 if (len(parsedPlots) == 0) :
259 print ("WARNING: axisname shouldn't be before plots")
260 continue
261 parsedPlots[-1].axis_captions[line[1].lstrip(
"+")] =
" ".join(line[2:]).
replace(
"%",
"#")
262 else :
263 print ("WARNING: unknown key:", line[0])
264 continue
265 for pe in parsedPlots :
266 for re in parsedRestricts :
267 for rech in pe.restricts :
268 if (rech.var == re.var) :
269 rech.rangeList += re.rangeList
270 re.rangeList = []
271 if (len(re.rangeList) > 0) :
272 pe.restricts.append(re)
273 return parsedPlots
274
std::string replace(std::string s, const std::string &s2, const std::string &s3)