74 def CreateXMLFile( runlist, options, origQuery, datapath, xmlfname, xmllabel, svnversion='Unknown' ):
79 with timer(
'create RunStreamAndNeventsList'):
82 ShowNumberOfEventsPerStreamPerRun =
False
83 ShowNumberOfEventsPerStreamSummary =
True
89 with timer(
'prepare document'):
98 docType = DocumentType(
'LumiRangeCollection')
99 docType.systemId =
'http://atlas-runquery.cern.ch/LumiRangeCollection.dtd'
100 doc.appendChild(docType)
103 txt =
' Good-runs-list created by %s on %s ' % (sys.argv[0].
split(
'/')[-1],
str(datetime.datetime.now()))
104 doc.appendChild( doc.createComment( txt ) )
107 lrc = doc.createElement(
'LumiRangeCollection')
111 namedLR = doc.createElement(
'NamedLumiRange')
112 lrc.appendChild(namedLR)
115 namedLR.appendChild(TextElement(
'Name',xmllabel,doc))
118 namedLR.appendChild(TextElement(
'Version',
'2.1',doc))
122 'Query' : origQuery.split(
'/')[0],
123 'RQTSVNVersion' : svnversion,
124 'RunList' : runnrliststr
128 mdelm = TextElement(
'Metadata', metadata[md], doc)
129 mdelm.setAttribute(
'Name', md)
130 namedLR.appendChild(mdelm)
132 with timer(
'ShowNumberOfEventsPerStreamSummary'):
133 if ShowNumberOfEventsPerStreamSummary:
134 strsummdelm = doc.createElement(
'Metadata')
135 strsummdelm.setAttribute(
'Name',
'StreamListInfo')
136 namedLR.appendChild(strsummdelm)
142 with timer(
'Loop over all runs'):
144 lbc = doc.createElement(
'LumiBlockCollection')
146 runnrelm = TextElement(
'Run',
str(run.runNr),doc)
149 if len(run.stats[
'SMK'][
'random'])==2:
150 (rd0,rd1) = run.stats[
'SMK'][
'random'][0:2]
156 runnrelm.setAttribute(
'PrescaleRD0',0x1<<(3+rd0))
157 runnrelm.setAttribute(
'PrescaleRD1',0x1<<(3+rd1))
159 (rd0,rd1,rd2,rd3) = run.stats[
'SMK'][
'random'][0:4]
169 runnrelm.setAttribute(
'Cut0', rd0)
170 runnrelm.setAttribute(
'Cut1', rd1)
171 runnrelm.setAttribute(
'Cut2', rd2)
172 runnrelm.setAttribute(
'Cut3', rd3)
174 lbc.appendChild(runnrelm)
178 streams_byrun[run.runNr] = streams
179 if run.runNr
in runstreamevents:
180 for stream
in runstreamevents[run.runNr].
keys():
181 if 'physics_' == stream[:8]:
182 streams[stream] = [0,0]
183 if stream
not in streams_sum:
184 streams_sum[stream] = [0,0]
186 for (nlb,nev)
in runstreamevents[run.runNr][stream]:
187 streams[stream][0] += nev
191 for lbrange
in run.data.getLBRanges(activeOnly=
True):
192 lbrelm = TextElement(
'LBRange',
'',doc)
193 lbrelm.setAttribute(
'Start',lbrange[1])
194 lbrelm.setAttribute(
'End',lbrange[2]-1)
195 lbc.appendChild(lbrelm)
197 if run.runNr
in runstreamevents:
198 for stream, lbnevts
in runstreamevents[run.runNr].
items():
199 if 'physics_' == stream[:8]:
200 for (nlb,nev)
in lbnevts:
201 if nlb>=lbrange[1]
and nlb<lbrange[2]:
202 streams[stream][1] += nev
205 strselm = doc.createElement(
'StreamsInRun')
207 for stream
in sorted (streams.keys()):
208 nevts = streams[stream]
209 if ShowNumberOfEventsPerStreamPerRun:
210 strelm = TextElement(
'Stream',
'',doc)
211 strelm.setAttribute(
'Name', stream)
212 strelm.setAttribute(
'TotalNumOfEvents', nevts[0])
213 strelm.setAttribute(
'NumOfSelectedEvents', nevts[1])
214 strselm.appendChild(strelm)
217 eff = nevts[1]/
float(nevts[0])*100.0
220 streams_sum[stream][0] += nevts[0]
221 streams_sum[stream][1] += nevts[1]
224 if ShowNumberOfEventsPerStreamPerRun:
225 lbc.appendChild(strselm)
228 namedLR.appendChild(lbc)
230 with timer(
'Streams'):
231 for stream
in sorted(streams_sum.keys()):
232 nevts = streams_sum[stream]
233 if ShowNumberOfEventsPerStreamSummary:
234 strelm = TextElement(
'Stream',
'',doc)
235 strelm.setAttribute(
'Name', stream)
236 strelm.setAttribute(
'TotalNumOfEvents', nevts[0])
237 strelm.setAttribute(
'NumOfSelectedEvents', nevts[1])
238 strsummdelm.appendChild(strelm)
241 with timer(
'Save GRL'):
243 filename =
'%s/%s' % (datapath, xmlfname)
245 xmlfile =
open( filename, mode=
"w" )
246 xmlfile.write( doc.toprettyxml(
' ') )
249 with timer(
'Create HTML'):
259 htmltext +=
'<table style="width: auto; border: 0px solid; border-width: margin: 0 0 0 0; 0px; border-spacing: 0px; border-collapse: separate; padding: 0px;" font-family: sans-serif; font-size: 85%%">\n'
260 htmltext +=
'<tr><td colspan="2"><b><font color="#999999">' + txt.strip() +
'</font></b></td></tr>\n'
261 htmltext +=
'<tr><td style="vertical-align:top">SVN Version: </td><td> ' + svnversion +
'</td></tr>\n'
262 htmltext +=
'<tr><td style="vertical-align:top">Query string:</td><td><b>' + origQuery.split(
'/')[0] +
'</b></td></tr>\n'
263 htmltext +=
'<tr><td style="vertical-align:top">Run list:</td><td>' + runnrliststr +
'</td></tr>\n'
264 htmltext +=
'</table>'
265 htmltext +=
'<hr color="#000000" size=1><font color="#777777">\n'
266 htmltext +=
'<table style="width: auto; border: 0px solid; border-width: margin: 0 0 0 0; 0px; border-spacing: 0px; border-collapse: separate; padding: 0px;" font-family: sans-serif; font-size: 90%%">\n'
272 htmltext +=
'<tr><td style="text-align:left;height:25px;vertical-align:bottom">Run <b>%i</b>:</td><td></td></tr>\n' % run.runNr
276 for lbrange
in run.data.getLBRanges(activeOnly=
True):
277 htmltext +=
'<tr><td></td><td style="text-align:left">LB range: [%5i-%5i]</td></tr>\n' % (lbrange[1],lbrange[2]-1)
280 htmltext +=
'<tr><td></td><td style="text-align:left"></td></tr>'
281 htmltext +=
'<tr><td></td><td style="text-align:left"><table style="width: auto; border: 0px solid; border-width: margin: 0 0 0 0; 0px; border-spacing: 0px; border-collapse: separate; padding: 0px;font-family: sans-serif; font-size: 90%"><tr><td>Stream name</td><td>#Events total</td><td> #Events selected</td><td> Sel. fraction (%)</td></tr>\n'
283 streams = streams_byrun[run.runNr]
284 for stream
in sorted(streams.keys()):
285 nevts = streams[stream]
286 eff = (nevts[1]/
float(nevts[0])*100.0)
if (nevts[0] > 0)
else 0
287 htmltext +=
'<tr><td style="text-align:left"><i>%s</i></td><td style="text-align:right">%s</td><td style="text-align:right">%s</td><td style="text-align:right">%.4g</td></tr>\n' % (stream,
prettyNumber(nevts[0]),
prettyNumber(nevts[1]),eff)
289 htmltext +=
'</table></td></tr>\n'
293 htmltext +=
'</table>'
294 htmltext +=
'<hr color="#000000" size=1><font color="#777777">\n'
295 htmltext +=
'<b>Stream summary for all selected runs:</b><br>\n'
296 htmltext +=
'<table style="width: auto; border: 0px solid; border-width: margin: 0 0 0 0; 0px; border-spacing: 0px; border-collapse: separate; padding: 0px;font-family: sans-serif; font-size: 95%"><tr><td>Stream name</td><td>#Events total</td><td> #Events selected</td><td> Sel. fraction (%)</td></tr>\n'
297 for stream
in sorted(streams_sum.keys()):
298 nevts = streams_sum[stream]
301 eff = nevts[1]/
float(nevts[0])*100.0
302 htmltext +=
'<tr><td style="text-align:left"><i>%s</i></td><td style="text-align:right">%s</td><td style="text-align:right">%s</td><td style="text-align:right">%.4g</td></tr>\n' % (stream,
prettyNumber(nevts[0]),
prettyNumber(nevts[1]),eff)
303 htmltext +=
'</table>\n'