11 from CoolRunQuery.utils.AtlRunQueryTimer
import timer
12 from CoolRunQuery.utils.AtlRunQueryUtils
import coolDbConn
13 from CoolRunQuery.AtlRunQueryRun
import Run
14 from CoolRunQuery.selector.AtlRunQuerySelectorBase
import Selector, DataKey
31 negate = pattern[0]==
'!'
32 pattern = pattern.lstrip(
'!')
33 p = re.compile(pattern)
34 nevt = (s.split()+[
None])[1]
37 super(StreamSelector,self).
__init__(name)
43 self.showstreampatterns += streampattern.replace(
'*',
'.*').
replace(
'%',
'.*').
replace(
'?',
'.').
split(
',')
47 return 'SELOUT Checking if the stream name matches "%s"' % self.
streams
57 compiledShowPatterns = [re.compile(
'.*')]
64 if len(compiledShowPatterns)>0:
73 connection = coolDbConn.GetSFODBConnection()
74 cursor = connection.cursor()
75 cursor.arraysize = 1000
77 runnrlist = [r.runNr
for r
in runlist]
79 from CoolRunQuery.AtlRunQuerySFO
import GetSFO_streamsAll,GetSFO_filesAll
80 with timer(
'GetSFO_streamsAll', disabled=
True):
82 with timer(
'GetSFO_filesAll', disabled=
True):
86 from CoolRunQuery.AtlRunQuerySFO
import GetSFO_LBsAll,GetSFO_NeventsAll,GetSFO_overlapAll
87 with timer(
'GetSFO_LBsAll', disabled=
True):
89 with timer(
'GetSFO_overlapAll', disabled=
True):
93 if r
not in streamsall:
95 for s
in streamsall[r]:
96 if r
in lbinfoall
and s
in lbinfoall[r]
and lbinfoall[r][s][1]>0:
99 with timer(
'GetSFO_NeventsAll', disabled=
True):
109 if run.runNr
in streamsall:
110 streams = streamsall[run.runNr]
113 _, size, events = filesall[run.runNr][s]
115 _, size, events = (0,0,0)
117 strevents += [events]
122 from CoolRunQuery.utils.AtlRunQueryUtils
import Matrix
126 for i,s
in enumerate(streams):
127 run.stats[
'STR:'+s] = {}
130 for j,s2
in enumerate(streams):
132 eventsij = overlapall[run.runNr][s][s2]
137 stovmat.setitem(i,j,
float(eventsij))
138 stovmat.setitem(j,i,
float(eventsij))
142 minlb, maxlb, lbs = (0,0,1)
144 minlb, maxlb, lbs = lbinfoall[run.runNr][s]
149 if minlb == 0
and maxlb == 0:
150 run.stats[
'STR:'+s][
'LBRecInfo'] =
None
154 result = neventsall[run.runNr][s]
163 for ice,(lb,nev)
in enumerate(result):
164 if ice == len(result):
167 if lb != lbold
or lastElement:
174 lbevcount +=
'</tr><tr>'
175 lbevcount +=
'<td style="font-size:75%%">%i (%s)</td>' % (lbold,allnev)
178 lbevcount +=
'</tr><tr>'
179 lbevcount +=
'<td style="font-size:75%%" colspan="8">... <i>too many LBs (> 100) to show</i></td>'
186 run.stats[
'STR:'+s][
'LBRecInfo'] = lbevcount
187 run.stats[
'STR:'+s][
'LBRecInfo'] = result
191 statkey =
'STR:'+streams[i]
192 run.stats[statkey][
'StrOverlap'] = []
193 denom = stovmat.getitem(i,i)
197 if i == j
or stovmat.getitem(i,j) == 0:
200 if stovmat.getitem(i,j) != denom:
201 fraction =
float(stovmat.getitem(i,j))/
float(denom)*100.0
202 run.stats[statkey][
'StrOverlap'] += [(streams[j], fraction)]
207 if not self.
passes(zip(streams,strevents),0):
209 newrunlist += [run.runNr]
210 allStreams.update(streams)
211 for k,v,s
in zip(streams,strevents,strsize):
212 run.addResult(
'STR:'+k, (v,s))
214 allStreams = [
'STR:'+s
for s
in allStreams]
217 allStreams.sort(key =
lambda x: (x[5:]) )
218 allStreams.sort(key =
lambda x: (x[4]), reverse=
True )
223 if s
not in run.result:
224 run.addResult(s,
'n.a.')
226 runlist = [r
for r
in runlist
if r.runNr
in newrunlist]
230 if any( [p.match(s[4:])
is not None for p
in compiledShowPatterns] ):
231 Run.AddToShowOrder(DataKey(s, keytype=DataKey.STREAM))
239 from CoolRunQuery.AtlRunQueryTier0
import GetTier0_datasetsAndTypes
240 tier0connection = coolDbConn.GetTier0DBConnection()
241 cursor = tier0connection.cursor()
242 cursor.arraysize = 1000
248 if run.result[s]==
'n.a.':
250 run.stats[s][
'StrTier0TypesRAW'] = {}
251 run.stats[s][
'StrTier0TypesESD'] = {}
252 run.stats[s][
'StrTier0AMI'] = {}
253 if run.runNr
in tier0retdico.keys():
254 for dsname,t,pstates
in tier0retdico[run.runNr]:
255 if s.replace(
'STR:',
'')
in dsname:
257 if '.merge' in dsname:
258 prodstep =
'StrTier0TypesESD'
261 prodstep =
'StrTier0TypesRAW'
264 if '.recon.' in dsname:
265 prodstep =
'StrTier0TypesRAW'
267 prodstep =
'StrTier0TypesESD'
268 if prodstep
not in run.stats[s][
'StrTier0AMI']:
269 dsnamesplit = dsname.split(
'.')
270 if len(dsnamesplit)>5:
271 amitag = dsnamesplit[5]
272 run.stats[s][
'StrTier0AMI'][prodstep] = amitag
277 if pstates
and 'replicate:done' in pstates:
281 if t
not in run.stats[s][prodstep]:
282 run.stats[s][prodstep][t] = oncaf
286 duration = time() - start
288 print (
" ==> %i runs found (%.2f sec)" % (len(runlist),duration))
290 print (
" ==> Done (%g sec)" % duration)
297 foundmatchingStream =
False
298 for se
in streamevents:
299 if streampattern.match(se[0]):
301 foundmatchingStream =
True
303 if neventreq[-1]
in '+-':
304 if neventreq[-1] ==
'-':
305 passreq = nevents <
int( neventreq[:-1] )
307 passreq = nevents >
int( neventreq[:-1] )
309 passreq = nevents>
int(neventreq)
312 passreq =
not foundmatchingStream
314 passreq = foundmatchingStream