1 from HTMLParser
import HTMLParser
2 from urllib2
import urlopen
3 import cPickle
as pickle
6 locatestarttagend = re.compile(
r""" 7 <[a-zA-Z][-.a-zA-Z0-9:_]* # tag name 8 (?:\s+ # whitespace before attribute name 9 (?:[a-zA-Z_][-.:a-zA-Z0-9_]* # attribute name 10 (?:\s*=\s* # value indicator 11 (?:'[^']*' # LITA-enclosed value 12 |\"[^\"]*\" # LIT-enclosed value 13 |this.src='[^']*' # hack 14 |[^'\">\s]+ # bare value 19 \s* # trailing whitespace 22 tagfind = re.compile(
'[a-zA-Z][-.a-zA-Z0-9:_]*')
23 attrfind = re.compile(
24 r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*' 25 r'(\'[^\']*\'|"[^"]*"|[-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~@]*))?')
31 HTMLParser.__init__(self)
62 rawdata = self.rawdata
67 match = tagfind.match(rawdata, i+1)
68 assert match,
'unexpected call to parse_starttag()' 70 self.
lasttag = tag = rawdata[i+1:k].lower()
76 m = attrfind.match(rawdata, k)
79 attrname, rest, attrvalue = m.group(1, 2, 3)
82 elif attrvalue[:1] ==
'\'' == attrvalue[-1:]
or \
83 attrvalue[:1] ==
'"' == attrvalue[-1:]:
84 attrvalue = attrvalue[1:-1]
85 attrvalue = self.unescape(attrvalue)
86 attrs.append((attrname.lower(), attrvalue))
89 end = rawdata[k:endpos].
strip()
90 if end
not in (
">",
"/>"):
91 lineno, offset = self.getpos()
93 lineno = lineno + self.__starttag_text.count(
"\n")
95 - self.__starttag_text.rfind(
"\n")
98 self.error(
"junk characters in start tag: %r" 99 % (rawdata[k:endpos][:20],))
100 if end.endswith(
'/>'):
105 if tag
in self.CDATA_CONTENT_ELEMENTS:
106 self.set_cdata_mode()
110 rawdata = self.rawdata
111 m = locatestarttagend.match(rawdata, i)
114 next = rawdata[j:j+1]
123 if rawdata.startswith(
"/>", j):
125 if rawdata.startswith(
"/", j):
129 self.updatepos(i, j + 1)
130 self.error(
"malformed empty start tag")
134 if next
in (
"abcdefghijklmnopqrstuvwxyz=/" 135 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
140 self.error(
"malformed start tag")
141 raise AssertionError(
"we should not get here!")
148 self.feed(req.read())
149 except Exception
as inst:
153 ValidTags = [
'a',
'tr',
'td']
155 if not tag
in ValidTags:
159 if tag ==
'a' and attrs:
160 self.hyperlinks.append(attrs[0][1])
173 self.table.append(self.
tmpRow)
183 self.tmpRow.append(data)
188 MostRecent = self.
table[0]
189 for line
in self.
table:
194 TriggerMode = MostRecent[3]
195 isCollisions =
not (TriggerMode.find(
'l1_hlt_collisions') == -1)
200 if not link.find(
'RUN='+self.
RunNumber)==-1:
207 entry = entry.replace(
'../../',
'http://cmswbm/')
208 if not entry.find(
'HLTSummary') == -1:
210 if not entry.find(
'L1Summary') == -1:
212 if not entry.find(
'LumiSections') == -1:
213 self.
LumiPage =
"http://cmswbm/cmsdb/servlet/"+entry
214 if not entry.find(
'TriggerMode') == -1:
215 if not entry.startswith(
"http://cmswbm/cmsdb/servlet/"):
216 entry =
"http://cmswbm/cmsdb/servlet/"+entry
221 for line
in self.
table:
224 if line[1].startswith(
'HLT_'):
225 TriggerName = line[1][:line[1].
find(
' ')]
227 self.Nevts.append([TriggerName,
int(line[3]),
int(line[4]),
int(line[5]),line[9]])
231 self.TriggerRates.append([TriggerName,TriggerRate,PS,line[9]])
234 for line
in self.
table[1:]:
235 if len(line)<4
or len(line)>12:
237 self.PrescaleColumn.append(
int(line[2]))
238 self.LumiByLS.append(
float(line[4]))
241 self.
RatePage = self.RatePage.replace(
'HLTSummary?',
'HLTSummary?fromLS='+line[0]+
'&toLS=&')
244 except ZeroDivisionError:
245 print "Cannot calculate average lumi -- something is wrong!" 246 print self.
table[:10]
250 for line
in self.
table:
254 if line[1].startswith(
'L1_'):
259 for line
in self.
table:
263 if line[0].isdigit()
and len(line)>=3:
264 if int(line[0])==ColIndex:
266 StrLumiSplit = line[2].
split(
'E')
267 if len(StrLumiSplit)!=2:
270 lumi =
float(StrLumiSplit[0])
271 lumi*=
pow(10,
int(StrLumiSplit[1])-30)
272 self.ColumnLumi.append(round(lumi,1))
276 if line[1].startswith(
'L1_')
or line[1].startswith(
'HLT_'):
280 seedtmp.append(line[1])
281 for entry
in line[2:]:
284 if entry.startswith(
'L1_'):
285 seedtmp.append(entry)
289 if line[1].startswith(
'L1_'):
290 self.L1PrescaleTable.append(tmp)
292 self.HLTPrescaleTable.append(tmp)
294 self.SeedMap.append(seedtmp)
301 thisAvPS+=
float(L1Row[prescaleThisLS+1])
304 self.L1Prescales.append([L1Row[0],thisAvPS])
321 totalLine = [hltName]+[l1Name]+[-3]*(len(hltLine)-1)
325 if not l1Name.find(
' OR ')==-1:
326 l1Line = [l1Name]+[1]*(len(hltLine)-1)
329 if thisl1Line[0] == l1Name:
333 totalLine = [hltName]+[l1Name]+[-4]*(len(hltLine)-1)
335 totalLine = [hltName,l1Name]
336 for hltPS,l1PS
in zip(hltLine[1:],l1Line[1:]):
338 totalLine.append(
int(hltPS)*
int(l1PS) )
343 self.TotalPrescaleTable.append(totalLine)
347 pickle.dump( self, open( fileName,
'w' ) )
350 self = pickle.load( open( fileName ) )
353 ScaleFactor = 71e-27/11.2e3/nBunches
356 out.append(l*ScaleFactor)
def ParseRunSummaryPage(self)
def replace(string, replacements)
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)