1 from __future__
import print_function
2 from HTMLParser
import HTMLParser
3 from urllib2
import urlopen
4 import cPickle
as pickle
7 locatestarttagend = re.compile(
r""" 8 <[a-zA-Z][-.a-zA-Z0-9:_]* # tag name 9 (?:\s+ # whitespace before attribute name 10 (?:[a-zA-Z_][-.:a-zA-Z0-9_]* # attribute name 11 (?:\s*=\s* # value indicator 12 (?:'[^']*' # LITA-enclosed value 13 |\"[^\"]*\" # LIT-enclosed value 14 |this.src='[^']*' # hack 15 |[^'\">\s]+ # bare value 20 \s* # trailing whitespace 23 tagfind = re.compile(
'[a-zA-Z][-.a-zA-Z0-9:_]*')
24 attrfind = re.compile(
25 r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*' 26 r'(\'[^\']*\'|"[^"]*"|[-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~@]*))?')
32 HTMLParser.__init__(self)
63 rawdata = self.rawdata
68 match = tagfind.match(rawdata, i+1)
69 assert match,
'unexpected call to parse_starttag()' 71 self.
lasttag = tag = rawdata[i+1:k].lower()
77 m = attrfind.match(rawdata, k)
80 attrname, rest, attrvalue = m.group(1, 2, 3)
83 elif attrvalue[:1] ==
'\'' == attrvalue[-1:]
or \
84 attrvalue[:1] ==
'"' == attrvalue[-1:]:
85 attrvalue = attrvalue[1:-1]
86 attrvalue = self.unescape(attrvalue)
87 attrs.append((attrname.lower(), attrvalue))
90 end = rawdata[k:endpos].
strip()
91 if end
not in (
">",
"/>"):
92 lineno, offset = self.getpos()
94 lineno = lineno + self.__starttag_text.count(
"\n")
96 - self.__starttag_text.rfind(
"\n")
99 self.error(
"junk characters in start tag: %r" 100 % (rawdata[k:endpos][:20],))
101 if end.endswith(
'/>'):
106 if tag
in self.CDATA_CONTENT_ELEMENTS:
107 self.set_cdata_mode()
111 rawdata = self.rawdata
112 m = locatestarttagend.match(rawdata, i)
115 next = rawdata[j:j+1]
124 if rawdata.startswith(
"/>", j):
126 if rawdata.startswith(
"/", j):
130 self.updatepos(i, j + 1)
131 self.error(
"malformed empty start tag")
135 if next
in (
"abcdefghijklmnopqrstuvwxyz=/" 136 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
141 self.error(
"malformed start tag")
142 raise AssertionError(
"we should not get here!")
149 self.feed(req.read())
150 except Exception
as inst:
154 ValidTags = [
'a',
'tr',
'td']
156 if not tag
in ValidTags:
160 if tag ==
'a' and attrs:
161 self.hyperlinks.append(attrs[0][1])
174 self.table.append(self.
tmpRow)
184 self.tmpRow.append(data)
189 MostRecent = self.
table[0]
190 for line
in self.
table:
195 TriggerMode = MostRecent[3]
196 isCollisions =
not (TriggerMode.find(
'l1_hlt_collisions') == -1)
201 if not link.find(
'RUN='+self.
RunNumber)==-1:
208 entry = entry.replace(
'../../',
'http://cmswbm/')
209 if not entry.find(
'HLTSummary') == -1:
211 if not entry.find(
'L1Summary') == -1:
213 if not entry.find(
'LumiSections') == -1:
214 self.
LumiPage =
"http://cmswbm/cmsdb/servlet/"+entry
215 if not entry.find(
'TriggerMode') == -1:
216 if not entry.startswith(
"http://cmswbm/cmsdb/servlet/"):
217 entry =
"http://cmswbm/cmsdb/servlet/"+entry
222 for line
in self.
table:
225 if line[1].startswith(
'HLT_'):
226 TriggerName = line[1][:line[1].
find(
' ')]
228 self.Nevts.append([TriggerName,
int(line[3]),
int(line[4]),
int(line[5]),line[9]])
232 self.TriggerRates.append([TriggerName,TriggerRate,PS,line[9]])
235 for line
in self.
table[1:]:
236 if len(line)<4
or len(line)>12:
238 self.PrescaleColumn.append(
int(line[2]))
239 self.LumiByLS.append(
float(line[4]))
242 self.
RatePage = self.RatePage.replace(
'HLTSummary?',
'HLTSummary?fromLS='+line[0]+
'&toLS=&')
245 except ZeroDivisionError:
246 print(
"Cannot calculate average lumi -- something is wrong!")
251 for line
in self.
table:
255 if line[1].startswith(
'L1_'):
260 for line
in self.
table:
264 if line[0].isdigit()
and len(line)>=3:
265 if int(line[0])==ColIndex:
267 StrLumiSplit = line[2].
split(
'E')
268 if len(StrLumiSplit)!=2:
271 lumi =
float(StrLumiSplit[0])
272 lumi*=
pow(10,
int(StrLumiSplit[1])-30)
273 self.ColumnLumi.append(round(lumi,1))
277 if line[1].startswith(
'L1_')
or line[1].startswith(
'HLT_'):
281 seedtmp.append(line[1])
282 for entry
in line[2:]:
285 if entry.startswith(
'L1_'):
286 seedtmp.append(entry)
290 if line[1].startswith(
'L1_'):
291 self.L1PrescaleTable.append(tmp)
293 self.HLTPrescaleTable.append(tmp)
295 self.SeedMap.append(seedtmp)
302 thisAvPS+=
float(L1Row[prescaleThisLS+1])
305 self.L1Prescales.append([L1Row[0],thisAvPS])
322 totalLine = [hltName]+[l1Name]+[-3]*(len(hltLine)-1)
326 if not l1Name.find(
' OR ')==-1:
327 l1Line = [l1Name]+[1]*(len(hltLine)-1)
330 if thisl1Line[0] == l1Name:
334 totalLine = [hltName]+[l1Name]+[-4]*(len(hltLine)-1)
336 totalLine = [hltName,l1Name]
337 for hltPS,l1PS
in zip(hltLine[1:],l1Line[1:]):
339 totalLine.append(
int(hltPS)*
int(l1PS) )
344 self.TotalPrescaleTable.append(totalLine)
348 pickle.dump( self, open( fileName,
'w' ) )
351 self = pickle.load( open( fileName ) )
354 ScaleFactor = 71e-27/11.2e3/nBunches
357 out.append(l*ScaleFactor)
def ParseRunSummaryPage(self)
def replace(string, replacements)
S & print(S &os, JobReport::InputFile const &f)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
def handle_data(self, data)
def handle_endtag(self, tag)
def ParseTrigModePage(self)
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def parse_starttag(self, i)
def handle_startendtag(self, tag, attrs)
def handle_starttag(self, tag, attrs)
def ComputeTotalPrescales(self)
def check_for_whole_start_tag(self, i)
Power< A, B >::type pow(const A &a, const B &b)