4 from __future__
import print_function
12 from CoolRunQuery.utils.AtlRunQueryTimer
import timer
13 from CoolRunQuery.utils.AtlRunQueryUtils
import coolDbConn
14 from CoolRunQuery.AtlRunQueryRun
import Run
15 from CoolRunQuery.selector.AtlRunQuerySelectorBase
import Selector, DataKey
32 negate = pattern[0]==
'!'
33 pattern = pattern.lstrip(
'!')
34 p = re.compile(pattern)
35 nevt = (s.split()+[
None])[1]
38 super(StreamSelector,self).
__init__(name)
44 self.showstreampatterns += streampattern.replace(
'*',
'.*').
replace(
'%',
'.*').
replace(
'?',
'.').
split(
',')
48 return 'SELOUT Checking if the stream name matches "%s"' % self.
streams
58 compiledShowPatterns = [re.compile(
'.*')]
65 if len(compiledShowPatterns)>0:
74 connection = coolDbConn.GetSFODBConnection()
75 cursor = connection.cursor()
76 cursor.arraysize = 1000
78 runnrlist = [r.runNr
for r
in runlist]
80 from CoolRunQuery.AtlRunQuerySFO
import GetSFO_streamsAll,GetSFO_filesAll
81 with timer(
'GetSFO_streamsAll', disabled=
True):
83 with timer(
'GetSFO_filesAll', disabled=
True):
87 from CoolRunQuery.AtlRunQuerySFO
import GetSFO_LBsAll,GetSFO_NeventsAll,GetSFO_overlapAll
88 with timer(
'GetSFO_LBsAll', disabled=
True):
90 with timer(
'GetSFO_overlapAll', disabled=
True):
94 if r
not in streamsall:
96 for s
in streamsall[r]:
97 if r
in lbinfoall
and s
in lbinfoall[r]
and lbinfoall[r][s][1]>0:
100 with timer(
'GetSFO_NeventsAll', disabled=
True):
110 if run.runNr
in streamsall:
111 streams = streamsall[run.runNr]
114 _, size, events = filesall[run.runNr][s]
116 _, size, events = (0,0,0)
118 strevents += [events]
123 from CoolRunQuery.utils.AtlRunQueryUtils
import Matrix
127 for i,s
in enumerate(streams):
128 run.stats[
'STR:'+s] = {}
131 for j,s2
in enumerate(streams):
133 eventsij = overlapall[run.runNr][s][s2]
138 stovmat.setitem(i,j,
float(eventsij))
139 stovmat.setitem(j,i,
float(eventsij))
143 minlb, maxlb, lbs = (0,0,1)
145 minlb, maxlb, lbs = lbinfoall[run.runNr][s]
150 if minlb == 0
and maxlb == 0:
151 run.stats[
'STR:'+s][
'LBRecInfo'] =
None
155 result = neventsall[run.runNr][s]
164 for ice,(lb,nev)
in enumerate(result):
165 if ice == len(result):
168 if lb != lbold
or lastElement:
175 lbevcount +=
'</tr><tr>'
176 lbevcount +=
'<td style="font-size:75%%">%i (%s)</td>' % (lbold,allnev)
179 lbevcount +=
'</tr><tr>'
180 lbevcount +=
'<td style="font-size:75%%" colspan="8">... <i>too many LBs (> 100) to show</i></td>'
187 run.stats[
'STR:'+s][
'LBRecInfo'] = lbevcount
188 run.stats[
'STR:'+s][
'LBRecInfo'] = result
192 statkey =
'STR:'+streams[i]
193 run.stats[statkey][
'StrOverlap'] = []
194 denom = stovmat.getitem(i,i)
198 if i == j
or stovmat.getitem(i,j) == 0:
201 if stovmat.getitem(i,j) != denom:
202 fraction =
float(stovmat.getitem(i,j))/
float(denom)*100.0
203 run.stats[statkey][
'StrOverlap'] += [(streams[j], fraction)]
208 if not self.
passes(zip(streams,strevents),0):
210 newrunlist += [run.runNr]
211 allStreams.update(streams)
212 for k,v,s
in zip(streams,strevents,strsize):
213 run.addResult(
'STR:'+k, (v,s))
215 allStreams = [
'STR:'+s
for s
in allStreams]
218 allStreams.sort(key =
lambda x: (x[5:]) )
219 allStreams.sort(key =
lambda x: (x[4]), reverse=
True )
224 if s
not in run.result:
225 run.addResult(s,
'n.a.')
227 runlist = [r
for r
in runlist
if r.runNr
in newrunlist]
231 if any( [p.match(s[4:])
is not None for p
in compiledShowPatterns] ):
232 Run.AddToShowOrder(DataKey(s, keytype=DataKey.STREAM))
240 from CoolRunQuery.AtlRunQueryTier0
import GetTier0_datasetsAndTypes
241 tier0connection = coolDbConn.GetTier0DBConnection()
242 cursor = tier0connection.cursor()
243 cursor.arraysize = 1000
249 if run.result[s]==
'n.a.':
251 run.stats[s][
'StrTier0TypesRAW'] = {}
252 run.stats[s][
'StrTier0TypesESD'] = {}
253 run.stats[s][
'StrTier0AMI'] = {}
254 if run.runNr
in tier0retdico.keys():
255 for dsname,t,pstates
in tier0retdico[run.runNr]:
256 if s.replace(
'STR:',
'')
in dsname:
258 if '.merge' in dsname:
259 prodstep =
'StrTier0TypesESD'
262 prodstep =
'StrTier0TypesRAW'
265 if '.recon.' in dsname:
266 prodstep =
'StrTier0TypesRAW'
268 prodstep =
'StrTier0TypesESD'
269 if prodstep
not in run.stats[s][
'StrTier0AMI']:
270 dsnamesplit = dsname.split(
'.')
271 if len(dsnamesplit)>5:
272 amitag = dsnamesplit[5]
273 run.stats[s][
'StrTier0AMI'][prodstep] = amitag
278 if pstates
and 'replicate:done' in pstates:
282 if t
not in run.stats[s][prodstep]:
283 run.stats[s][prodstep][t] = oncaf
287 duration = time() - start
289 print (
" ==> %i runs found (%.2f sec)" % (len(runlist),duration))
291 print (
" ==> Done (%g sec)" % duration)
298 foundmatchingStream =
False
299 for se
in streamevents:
300 if streampattern.match(se[0]):
302 foundmatchingStream =
True
304 if neventreq[-1]
in '+-':
305 if neventreq[-1] ==
'-':
306 passreq = nevents <
int( neventreq[:-1] )
308 passreq = nevents >
int( neventreq[:-1] )
310 passreq = nevents>
int(neventreq)
313 passreq =
not foundmatchingStream
315 passreq = foundmatchingStream