1 import os,coral,fnmatch,time
2 from RecoLuminosity.LumiDB
import nameDealer,dbUtil,revisionDML,lumiTime,CommonUtil,lumiCorrections
3 from datetime
import datetime
18 select data_id from lumicorrectionss [where entry_name=:tagname]
19 result lumicorrectionsdataid
24 qHandle=schema.newQuery()
26 qHandle.addToTableList( nameDealer.lumicorrectionsTableName() )
27 qHandle.addToOutputList(
'DATA_ID')
29 qConditionStr=
'ENTRY_NAME=:tagname '
30 qCondition=coral.AttributeList()
31 qCondition.extend(
'tagname',
'string')
32 qCondition[
'tagname'].setData(tagname)
33 qResult=coral.AttributeList()
34 qResult.extend(
'DATA_ID',
'unsigned long long')
35 qHandle.defineOutput(qResult)
37 qHandle.setCondition(qConditionStr,qCondition)
38 cursor=qHandle.execute()
40 dataid=cursor.currentRow()[
'DATA_ID'].
data()
41 lumicorrectionids.append(dataid)
46 if len(lumicorrectionids) !=0:
return max(lumicorrectionids)
51 select entry_name,a1,a2,drift from lumicorrections where DATA_ID=:dataid
52 output: {tagname:(data_id(0),a1(1),a2(2),driftcoeff(3))}
55 qHandle=schema.newQuery()
57 qHandle.addToTableList(nameDealer.lumicorrectionsTableName())
58 qHandle.addToOutputList(
'ENTRY_NAME')
59 qHandle.addToOutputList(
'A1')
60 qHandle.addToOutputList(
'A2')
61 qHandle.addToOutputList(
'DRIFT')
62 qCondition=coral.AttributeList()
63 qCondition.extend(
'dataid',
'unsigned long long')
64 qCondition[
'dataid'].setData(correctiondataid)
65 qResult=coral.AttributeList()
66 qResult.extend(
'ENTRY_NAME',
'string')
67 qResult.extend(
'A1',
'float')
68 qResult.extend(
'A2',
'float')
69 qResult.extend(
'DRIFT',
'float')
70 qHandle.defineOutput(qResult)
71 qHandle.setCondition(
'DATA_ID=:dataid',qCondition)
72 cursor=qHandle.execute()
74 tagname=cursor.currentRow()[
'ENTRY_NAME'].
data()
75 a1=cursor.currentRow()[
'A1'].
data()
77 if cursor.currentRow()[
'A2'].
data():
78 a2=cursor.currentRow()[
'A2'].
data()
80 if cursor.currentRow()[
'DRIFT'].
data():
81 drift=cursor.currentRow()[
'DRIFT'].
data()
82 result={tagname:(correctiondataid,a1,a2,drift)}
89 def fillInRange(schema,fillmin,fillmax,amodetag,startT,stopT):
91 select fillnum,runnum,starttime from cmsrunsummary where [where fillnum>=:fillmin and fillnum<=:fillmax and amodetag=:amodetag]
96 qHandle=schema.newQuery()
100 qHandle.addToTableList(r)
103 qCondition=coral.AttributeList()
105 qConditionPieces.append(
'FILLNUM>=:fillmin')
106 qCondition.extend(
'fillmin',
'unsigned int')
107 qCondition[
'fillmin'].setData(int(fillmin))
109 qConditionPieces.append(
'FILLNUM<=:fillmax')
110 qCondition.extend(
'fillmax',
'unsigned int')
111 qCondition[
'fillmax'].setData(int(fillmax))
113 qConditionPieces.append(
'AMODETAG=:amodetag')
114 qCondition.extend(
'amodetag',
'string')
115 qCondition[
'amodetag'].setData(amodetag)
116 if len(qConditionPieces)!=0:
117 qConditionStr=(
' AND ').
join(qConditionPieces)
118 qResult=coral.AttributeList()
119 qResult.extend(
'fillnum',
'unsigned int')
120 qResult.extend(
'runnum',
'unsigned int')
121 qResult.extend(
'starttime',
'string')
122 qHandle.defineOutput(qResult)
123 if len(qConditionStr)!=0:
124 qHandle.setCondition(qConditionStr,qCondition)
125 qHandle.addToOutputList(
'FILLNUM',
'fillnum')
126 qHandle.addToOutputList(
'RUNNUM',
'runnum')
127 qHandle.addToOutputList(
'TO_CHAR('+r+
'.STARTTIME,\'MM/DD/YY HH24:MI:SS\')',
'starttime')
128 cursor=qHandle.execute()
130 currentfill=cursor.currentRow()[
'fillnum'].
data()
131 runnum=cursor.currentRow()[
'runnum'].
data()
132 starttimeStr=cursor.currentRow()[
'starttime'].
data()
133 runTime=lute.StrToDatetime(starttimeStr,customfm=
'%m/%d/%y %H:%M:%S')
137 minTime=lute.StrToDatetime(startT,customfm=
'%m/%d/%y %H:%M:%S')
138 maxTime=lute.StrToDatetime(stopT,customfm=
'%m/%d/%y %H:%M:%S')
139 if runTime>=minTime
and runTime<=maxTime:
140 tmpresult.setdefault(currentfill,[]).
append(runnum)
141 elif startT
is not None:
142 minTime=lute.StrToDatetime(startT,customfm=
'%m/%d/%y %H:%M:%S')
144 tmpresult.setdefault(currentfill,[]).
append(runnum)
145 elif stopT
is not None:
146 maxTime=lute.StrToDatetime(stopT,customfm=
'%m/%d/%y %H:%M:%S')
148 tmpresult.setdefault(currentfill,[]).
append(runnum)
150 tmpresult.setdefault(currentfill,[]).
append(runnum)
152 for f
in sorted(tmpresult):
160 def fillrunMap(schema,fillnum=None,runmin=None,runmax=None,startT=None,stopT=None,l1keyPattern=None,hltkeyPattern=None,amodetag=None):
162 select fillnum,runnum,starttime from cmsrunsummary [where fillnum=:fillnum and runnum>=runmin and runnum<=runmax and amodetag=:amodetag ]
163 output: {fill:[runnum,...]}
167 qHandle=schema.newQuery()
171 qHandle.addToTableList(r)
174 qCondition=coral.AttributeList()
176 qConditionPieces.append(
'FILLNUM=:fillnum')
177 qCondition.extend(
'fillnum',
'unsigned int')
178 qCondition[
'fillnum'].setData(int(fillnum))
180 qConditionPieces.append(
'RUNNUM>=:runmin')
181 qCondition.extend(
'runmin',
'unsigned int')
182 qCondition[
'runmin'].setData(runmin)
184 qConditionPieces.append(
'RUNNUM<=:runmax')
185 qCondition.extend(
'runmax',
'unsigned int')
186 qCondition[
'runmax'].setData(runmax)
188 qConditionPieces.append(
'AMODETAG=:amodetag')
189 qCondition.extend(
'amodetag',
'string')
190 qCondition[
'amodetag'].setData(amodetag)
192 qConditionPieces.append(
'regexp_like(L1KEY,:l1keypattern)')
193 qCondition.extend(
'l1keypattern',
'string')
194 qCondition[
'l1keypattern'].setData(l1keyPattern)
196 qConditionPieces.append(
'regexp_like(HLTKEY,:hltkeypattern)')
197 qCondition.extend(
'hltkeypattern',
'string')
198 qCondition[
'hltkeypattern'].setData(hltkeyPattern)
199 if len(qConditionPieces)!=0:
200 qConditionStr=(
' AND ').
join(qConditionPieces)
201 qResult=coral.AttributeList()
202 qResult.extend(
'fillnum',
'unsigned int')
203 qResult.extend(
'runnum',
'unsigned int')
204 qResult.extend(
'starttime',
'string')
205 qHandle.defineOutput(qResult)
206 if len(qConditionStr) !=0:
207 qHandle.setCondition(qConditionStr,qCondition)
208 qHandle.addToOutputList(
'FILLNUM',
'fillnum')
209 qHandle.addToOutputList(
'RUNNUM',
'runnum')
210 qHandle.addToOutputList(
'TO_CHAR('+r+
'.STARTTIME,\'MM/DD/YY HH24:MI:SS\')',
'starttime')
211 cursor=qHandle.execute()
213 currentfill=cursor.currentRow()[
'fillnum'].
data()
214 starttimeStr=cursor.currentRow()[
'starttime'].
data()
215 runnum=cursor.currentRow()[
'runnum'].
data()
216 runTime=lute.StrToDatetime(starttimeStr,customfm=
'%m/%d/%y %H:%M:%S')
220 minTime=lute.StrToDatetime(startT,customfm=
'%m/%d/%y %H:%M:%S')
221 maxTime=lute.StrToDatetime(stopT,customfm=
'%m/%d/%y %H:%M:%S')
222 if runTime>=minTime
and runTime<=maxTime:
223 result.setdefault(currentfill,[]).
append(runnum)
224 elif startT
is not None:
225 minTime=lute.StrToDatetime(startT,customfm=
'%m/%d/%y %H:%M:%S')
227 result.setdefault(currentfill,[]).
append(runnum)
228 elif stopT
is not None:
229 maxTime=lute.StrToDatetime(stopT,customfm=
'%m/%d/%y %H:%M:%S')
231 result.setdefault(currentfill,[]).
append(runnum)
233 result.setdefault(currentfill,[]).
append(runnum)
240 def runList(schema,datatagid,runmin=None,runmax=None,fillmin=None,fillmax=None,startT=None,stopT=None,l1keyPattern=None,hltkeyPattern=None,amodetag=None,nominalEnergy=None,energyFlut=0.2,requiretrg=True,requirehlt=True,preselectedruns=None,lumitype=None):
242 select r.runnum,l.starttime,l.stoptime,l.data_id,tag.trgdataid,tag.hltdataid from cmsrunsummary r,tagruns tag,lumidata l,trgdata t,hltdata h where l.runnum=tag.runnum and r.runnum=l.runnum (and l.runnum=t.runnum and t.runnum=h.runnum) and r.fillnum>=:fillmin and r.fillnum<=fillmax and r.runnum>:runmin and r.runnum<:runmax and r.amodetag=:amodetag (and regexp_like(r.l1key,:l1keypattern) and regexp_like(hltkey,:hltkeypattern) ) and l.nominalEnergy>=:nominalEnergy*(1-energyFlut) and l.nominalEnergy<=:nominalEnergy*(1+energyFlut) and tag.tagid<=:tagid and l.starttime is not null and l.stoptime is not null
243 output: {runnum:[lumiid,trgid,hltid]}
246 if lumitype
not in [
'HF',
'PIXEL']:
247 raise ValueError(
'unknown lumitype '+lumitype)
253 elif lumitype ==
'PIXEL':
257 assert False,
"ERROR Unknown lumitype '%s'" % lumitype
260 qHandle=schema.newQuery()
268 qHandle.addToTableList(r)
269 qHandle.addToTableList(l)
270 qHandle.addToTableList(tag)
271 qConditionStr=r+
'.RUNNUM='+l+
'.RUNNUM AND '+tag+
'.RUNNUM='+l+
'.RUNNUM AND '+tag+
'.TAGID<=:tagid'
272 qCondition=coral.AttributeList()
273 qCondition.extend(
'tagid',
'unsigned long long')
274 qCondition[
'tagid'].setData(datatagid)
281 if runmin
and runmax :
283 qConditionStr+=
' AND '+r+
'.RUNNUM=:runmin'
284 qCondition.extend(
'runmin',
'unsigned int')
285 qCondition[
'runmin'].setData(int(runmin))
287 qConditionStr+=
' AND '+r+
'.RUNNUM>=:runmin AND '+r+
'.RUNNUM<=:runmax'
288 qCondition.extend(
'runmin',
'unsigned int')
289 qCondition.extend(
'runmax',
'unsigned int')
290 qCondition[
'runmin'].setData(int(runmin))
291 qCondition[
'runmax'].setData(int(runmax))
293 raise 'runmin > runmax'
295 qConditionStr+=
' AND '+r+
'.RUNNUM>=:runmin'
296 qCondition.extend(
'runmin',
'unsigned int')
297 qCondition[
'runmin'].setData(int(runmin))
299 qConditionStr+=
' AND '+r+
'.RUNNUM<=:runmax'
300 qCondition.extend(
'runmax',
'unsigned int')
301 qCondition[
'runmax'].setData(int(runmax))
304 if fillmin
and fillmax:
306 qConditionStr+=
' AND '+r+
'.FILLNUM=:fillnum'
307 qCondition.extend(
'fillnum',
'unsigned int')
308 qCondition[
'fillnum'].setData(int(fillmin))
309 elif fillmax>fillmin:
310 qConditionStr+=
' AND '+r+
'.FILLNUM>=:fillmin AND '+r+
'.FILLNUM<=:fillmax'
311 qCondition.extend(
'fillmin',
'unsigned int')
312 qCondition.extend(
'fillmax',
'unsigned int')
313 qCondition[
'fillmin'].setData(int(fillmin))
314 qCondition[
'fillmax'].setData(int(fillmax))
316 raise 'fillmin > fillmax'
318 qConditionStr+=
' AND '+r+
'.AMODETAG=:amodetag'
319 qCondition.extend(
'amodetag',
'string')
320 qCondition[
'amodetag'].setData(amodetag)
322 qHandle.addToTableList(t)
323 qConditionStr+=
' AND regexp_like('+r+
'.L1KEY,:l1keypattern )'+
' AND '+l+
'.RUNNUM='+t+
'.RUNNUM'
324 qCondition.extend(
'l1keypattern',
'string')
325 qCondition[
'l1keypattern'].setData(l1keyPattern)
327 qHandle.addToTableList(h)
328 qConditionStr+=
' AND regexp_like('+r+
'.HLTKEY,:hltkeypattern)'+
' AND '+l+
'.RUNNUM='+h+
'.RUNNUM'
329 qCondition.extend(
'hltkeypattern',
'string')
330 qCondition[
'hltkeypattern'].setData(hltkeyPattern)
332 emin=nominalEnergy*(1.0-energyFlut)
333 emax=nominalEnergy*(1.0+energyFlut)
334 qConditionStr+=
' AND '+l+
'.NOMINALEGEV>=:emin and '+l+
'.NOMINALEGEV<=:emax'
335 qCondition.extend(
'emin',
'float')
336 qCondition.extend(
'emax',
'float')
337 qCondition[
'emin'].setData(emin)
338 qCondition[
'emax'].setData(emax)
339 qResult=coral.AttributeList()
340 qResult.extend(
'runnum',
'unsigned int')
341 qResult.extend(
'starttime',
'string')
342 qResult.extend(
'stoptime',
'string')
343 qResult.extend(
'lumiid',
'unsigned long long')
345 qResult.extend(
'trgid',
'unsigned long long')
347 qResult.extend(
'hltid',
'unsigned long long')
348 qHandle.setCondition(qConditionStr,qCondition)
349 qHandle.addToOutputList(r+
'.RUNNUM',
'runnum')
350 qHandle.addToOutputList(
'TO_CHAR('+l+
'.STARTTIME,\'MM/DD/YY HH24:MI:SS\')',
'starttime')
351 qHandle.addToOutputList(
'TO_CHAR('+l+
'.STOPTIME,\'MM/DD/YY HH24:MI:SS\')',
'stoptime')
352 qHandle.addToOutputList(l+
'.DATA_ID',
'lumiid')
358 qHandle.addToOutputList(tag+
'.TRGDATAID',
'trgid')
360 qHandle.addToOutputList(tag+
'.HLTDATAID',
'hltid')
361 qHandle.defineOutput(qResult)
362 cursor=qHandle.execute()
367 runnum=cursor.currentRow()[
'runnum'].
data()
368 if preselectedruns
and runnum
not in preselectedruns:
370 if cursor.currentRow()[
'starttime'].isNull():
372 if cursor.currentRow()[
'stoptime'].isNull():
374 starttimeStr=cursor.currentRow()[
'starttime'].
data()
375 stoptimeStr=cursor.currentRow()[
'stoptime'].
data()
376 runstartTime=lute.StrToDatetime(starttimeStr,customfm=
'%m/%d/%y %H:%M:%S')
377 runstopTime=lute.StrToDatetime(stoptimeStr,customfm=
'%m/%d/%y %H:%M:%S')
378 minTime=datetime(2010,1,1,0,0,0,0)
379 maxTime=datetime.now()
381 minTime=lute.StrToDatetime(startT,customfm=
'%m/%d/%y %H:%M:%S')
382 maxTime=lute.StrToDatetime(stopT,customfm=
'%m/%d/%y %H:%M:%S')
383 if not (runstopTime>=minTime
and runstartTime<=maxTime):
385 elif startT
is not None:
386 minTime=lute.StrToDatetime(startT,customfm=
'%m/%d/%y %H:%M:%S')
387 if not (runstopTime>=minTime):
389 elif stopT
is not None:
390 maxTime=lute.StrToDatetime(stopT,customfm=
'%m/%d/%y %H:%M:%S')
391 runTime=lute.StrToDatetime(starttimeStr,customfm=
'%m/%d/%y %H:%M:%S')
392 if not (runTime<=maxTime):
396 if not cursor.currentRow()[
'lumiid'].isNull():
397 lumiid=cursor.currentRow()[
'lumiid'].
data()
398 if result.has_key(runnum):
399 if lumiid>result[runnum][0]:
400 result[runnum][0]=lumiid
402 result[runnum]=[lumiid,0,0]
404 if cursor.currentRow()[
'trgid'].isNull():
407 trgid=cursor.currentRow()[
'trgid'].
data()
408 if result.has_key(runnum):
409 if trgid>result[runnum][1]:
410 result[runnum][1]=trgid
411 if requirehlt
and not cursor.currentRow()[
'hltid'].isNull():
412 hltid=cursor.currentRow()[
'hltid'].
data()
413 if result.has_key(runnum):
414 if hltid>result[runnum][2]:
415 result[runnum][2]=hltid
424 select l1key,amodetag,hltkey,fillnum,fillscheme from cmsrunsummary where runnum=:runnum
425 output: [l1key(0),amodetag(1),hltkey(3),fillnum(4),fillscheme(5)]
428 qHandle=schema.newQuery()
432 qCondition=coral.AttributeList()
433 qCondition.extend(
'runnum',
'unsigned int')
434 qCondition[
'runnum'].setData(int(runnum))
435 qHandle.addToOutputList(
'L1KEY',
'l1key')
436 qHandle.addToOutputList(
'AMODETAG',
'amodetag')
438 qHandle.addToOutputList(
'HLTKEY',
'hltkey')
439 qHandle.addToOutputList(
'FILLNUM',
'fillnum')
440 qHandle.addToOutputList(
'FILLSCHEME',
'fillscheme')
447 qHandle.setCondition(
'RUNNUM=:runnum',qCondition)
448 qResult=coral.AttributeList()
449 qResult.extend(
'l1key',
'string')
450 qResult.extend(
'amodetag',
'string')
452 qResult.extend(
'hltkey',
'string')
453 qResult.extend(
'fillnum',
'unsigned int')
454 qResult.extend(
'fillscheme',
'string')
457 qHandle.defineOutput(qResult)
458 cursor=qHandle.execute()
460 result.append(cursor.currentRow()[
'l1key'].
data())
461 result.append(cursor.currentRow()[
'amodetag'].
data())
463 result.append(cursor.currentRow()[
'hltkey'].
data())
464 result.append(cursor.currentRow()[
'fillnum'].
data())
466 if not cursor.currentRow()[
'fillscheme'].isNull():
467 fillscheme=cursor.currentRow()[
'fillscheme'].
data()
468 result.append(fillscheme)
557 select entry_name,amodetag,norm_1,egev_1,norm_2,egev_2 from luminorms where DATA_ID=:dataid
558 output: {norm_name:(amodetag(0),norm_1(1),egev_1(2),norm_occ2(3),norm_et(4),norm_pu(5),constfactor(6))}
561 qHandle=schema.newQuery()
564 qHandle.addToOutputList(
'ENTRY_NAME',
'normname')
565 qHandle.addToOutputList(
'AMODETAG',
'amodetag')
566 qHandle.addToOutputList(
'NORM_1',
'norm_1')
567 qHandle.addToOutputList(
'EGEV_1',
'energy_1')
568 qHandle.addToOutputList(
'NORM_OCC2',
'norm_occ2')
569 qHandle.addToOutputList(
'NORM_ET',
'norm_et')
570 qHandle.addToOutputList(
'NORM_PU',
'norm_pu')
571 qHandle.addToOutputList(
'CONSTFACTOR',
'constfactor')
572 qCondition=coral.AttributeList()
573 qCondition.extend(
'dataid',
'unsigned long long')
574 qCondition[
'dataid'].setData(dataid)
575 qResult=coral.AttributeList()
576 qResult.extend(
'normname',
'string')
577 qResult.extend(
'amodetag',
'string')
578 qResult.extend(
'norm_1',
'float')
579 qResult.extend(
'energy_1',
'unsigned int')
580 qResult.extend(
'norm_occ2',
'float')
581 qResult.extend(
'norm_et',
'float')
582 qResult.extend(
'norm_pu',
'float')
583 qResult.extend(
'constfactor',
'float')
584 qHandle.defineOutput(qResult)
585 qHandle.setCondition(
'DATA_ID=:dataid',qCondition)
586 cursor=qHandle.execute()
588 normname=cursor.currentRow()[
'normname'].
data()
589 amodetag=cursor.currentRow()[
'amodetag'].
data()
590 norm_1=cursor.currentRow()[
'norm_1'].
data()
591 energy_1=cursor.currentRow()[
'energy_1'].
data()
593 if cursor.currentRow()[
'norm_occ2'].
data():
594 norm_occ2=cursor.currentRow()[
'norm_occ2'].
data()
596 if cursor.currentRow()[
'norm_et'].
data():
597 norm_et=cursor.currentRow()[
'norm_et'].
data()
599 if cursor.currentRow()[
'norm_pu'].
data():
600 norm_pu=cursor.currentRow()[
'norm_pu'].
data()
602 if cursor.currentRow()[
'constfactor'].
data():
603 constfactor=cursor.currentRow()[
'constfactor'].
data()
604 result={normname:(amodetag,norm_1,energy_1,norm_occ2,norm_et,norm_pu,constfactor)}
675 select entry_name,amodetag,norm_1,egev_1,norm_2,egev_2 from luminorms where DATA_ID=:dataid
676 result (normname(0),amodetag(1),egev(2),norm(3),norm_occ2(4),norm_et(5),norm_pu(6),constfactor(7))
679 qHandle=schema.newQuery()
682 qHandle.addToOutputList(
'ENTRY_NAME',
'normname')
683 qHandle.addToOutputList(
'AMODETAG',
'amodetag')
684 qHandle.addToOutputList(
'NORM_1',
'norm_1')
685 qHandle.addToOutputList(
'EGEV_1',
'energy_1')
686 qHandle.addToOutputList(
'NORM_OCC2',
'norm_occ2')
687 qHandle.addToOutputList(
'NORM_ET',
'norm_et')
688 qHandle.addToOutputList(
'NORM_PU',
'norm_pu')
689 qHandle.addToOutputList(
'CONSTFACTOR',
'constfactor')
690 qCondition=coral.AttributeList()
691 qCondition.extend(
'dataid',
'unsigned long long')
692 qCondition[
'dataid'].setData(dataid)
693 qResult=coral.AttributeList()
694 qResult.extend(
'normname',
'string')
695 qResult.extend(
'amodetag',
'string')
696 qResult.extend(
'norm_1',
'float')
697 qResult.extend(
'energy_1',
'unsigned int')
698 qResult.extend(
'norm_occ2',
'float')
699 qResult.extend(
'norm_et',
'float')
700 qResult.extend(
'norm_pu',
'float')
701 qResult.extend(
'constfactor',
'float')
702 qHandle.defineOutput(qResult)
703 qHandle.setCondition(
'DATA_ID=:dataid',qCondition)
704 cursor=qHandle.execute()
706 normname=cursor.currentRow()[
'normname'].
data()
707 amodetag=cursor.currentRow()[
'amodetag'].
data()
708 norm_1=cursor.currentRow()[
'norm_1'].
data()
709 energy_1=cursor.currentRow()[
'energy_1'].
data()
711 if cursor.currentRow()[
'norm_occ2'].
data():
712 norm_occ2=cursor.currentRow()[
'norm_occ2'].
data()
714 if cursor.currentRow()[
'norm_et'].
data():
715 norm_et=cursor.currentRow()[
'norm_et'].
data()
717 if cursor.currentRow()[
'norm_pu'].
data():
718 norm_pu=cursor.currentRow()[
'norm_pu'].
data()
720 if cursor.currentRow()[
'constfactor'].
data():
721 constfactor=cursor.currentRow()[
'constfactor'].
data()
722 result={normname:(amodetag,norm_1,energy_1,norm_occ2,norm_et,norm_pu,constfactor)}
729 def trgRunById(schema,dataid,trgbitname=None,trgbitnamepattern=None):
731 query: select RUNNUM,SOURCE,BITZERONAME,BITNAMECLOB,ALGOMASK_H,ALGOMASK_L,TECHMASK from trgdata where DATA_ID=:dataid
733 output: [runnum(0),datasource(1),bitzeroname(2),bitnamedict(3),algomask_h(4),algomask_l(5),techmask(6)]
735 -- original source database name
736 -- deadtime norm bitname
737 -- bitnamedict [(bitidx,bitname),...]
740 qHandle=schema.newQuery()
747 qHandle.addToOutputList(
'RUNNUM',
'runnum')
748 qHandle.addToOutputList(
'SOURCE',
'source')
749 qHandle.addToOutputList(
'BITZERONAME',
'bitzeroname')
750 qHandle.addToOutputList(
'BITNAMECLOB',
'bitnameclob')
751 qHandle.addToOutputList(
'ALGOMASK_H',
'algomask_h')
752 qHandle.addToOutputList(
'ALGOMASK_L',
'algomask_l')
753 qHandle.addToOutputList(
'TECHMASK',
'techmask')
754 qCondition=coral.AttributeList()
755 qCondition.extend(
'dataid',
'unsigned long long')
756 qCondition[
'dataid'].setData(dataid)
757 qResult=coral.AttributeList()
758 qResult.extend(
'runnum',
'unsigned int')
759 qResult.extend(
'source',
'string')
760 qResult.extend(
'bitzeroname',
'string')
761 qResult.extend(
'bitnameclob',
'string')
762 qResult.extend(
'algomask_h',
'unsigned long long')
763 qResult.extend(
'algomask_l',
'unsigned long long')
764 qResult.extend(
'techmask',
'unsigned long long')
765 qHandle.defineOutput(qResult)
766 qHandle.setCondition(
'DATA_ID=:dataid',qCondition)
767 cursor=qHandle.execute()
771 runnum=cursor.currentRow()[
'runnum'].
data()
772 source=cursor.currentRow()[
'source'].
data()
773 bitzeroname=cursor.currentRow()[
'bitzeroname'].
data()
774 bitnameclob=cursor.currentRow()[
'bitnameclob'].
data()
775 algomask_h=cursor.currentRow()[
'algomask_h'].
data()
776 algomask_l=cursor.currentRow()[
'algomask_l'].
data()
777 techmask=cursor.currentRow()[
'techmask'].
data()
779 bitnames=bitnameclob.split(
',')
780 for trgnameidx,trgname
in enumerate(bitnames):
782 if trgname==trgbitname:
783 bitnamedict.append((trgnameidx,trgname))
785 elif trgbitnamepattern:
786 if fnmatch.fnmatch(trgname,trgbitnamepattern):
787 bitnamedict.append((trgnameidx,trgname))
789 bitnamedict.append((trgnameidx,trgname))
790 result=[runnum,source,bitzeroname,bitnamedict,algomask_h,algomask_l,techmask]
797 def trgLSById(schema,dataid,trgbitname=None,trgbitnamepattern=None,withL1Count=False,withPrescale=False):
799 output: (runnum,{cmslsnum:[deadtimecount(0),bitzerocount(1),bitzeroprescale(2),deadfrac(3),[(bitname,trgcount,prescale,mask)](4)]})
804 if trgbitname
or trgbitnamepattern
or withPrescale
or withL1Count:
805 trgrundata=
trgRunById(schema,dataid,trgbitname=trgbitname,trgbitnamepattern=trgbitnamepattern)
806 trgnamedict=trgrundata[3]
807 algomask_h=trgrundata[4]
808 algomask_l=trgrundata[5]
809 techmask=trgrundata[6]
810 qHandle=schema.newQuery()
813 qHandle.addToOutputList(
'RUNNUM',
'runnum')
814 qHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
815 qHandle.addToOutputList(
'DEADTIMECOUNT',
'deadtimecount')
818 qHandle.addToOutputList(
'DEADFRAC',
'deadfrac')
820 qHandle.addToOutputList(
'PRESCALEBLOB',
'prescalesblob')
822 qHandle.addToOutputList(
'TRGCOUNTBLOB',
'trgcountblob')
823 qConditionStr=
'DATA_ID=:dataid'
824 qCondition=coral.AttributeList()
825 qCondition.extend(
'dataid',
'unsigned long long')
826 qCondition[
'dataid'].setData(dataid)
827 qResult=coral.AttributeList()
828 qResult.extend(
'runnum',
'unsigned int')
829 qResult.extend(
'cmslsnum',
'unsigned int')
830 qResult.extend(
'deadtimecount',
'unsigned long long')
833 qResult.extend(
'deadfrac',
'float')
835 qResult.extend(
'prescalesblob',
'blob')
837 qResult.extend(
'trgcountblob',
'blob')
838 qHandle.defineOutput(qResult)
839 qHandle.setCondition(qConditionStr,qCondition)
840 cursor=qHandle.execute()
842 runnum=cursor.currentRow()[
'runnum'].
data()
843 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
844 deadtimecount=cursor.currentRow()[
'deadtimecount'].
data()
849 deadfrac=cursor.currentRow()[
'deadfrac'].
data()
850 if not result.has_key(cmslsnum):
852 result[cmslsnum].
append(deadtimecount)
853 result[cmslsnum].
append(bitzerocount)
854 result[cmslsnum].
append(bitzeroprescale)
855 result[cmslsnum].
append(deadfrac)
859 prescalesblob=cursor.currentRow()[
'prescalesblob'].
data()
861 trgcountblob=cursor.currentRow()[
'trgcountblob'].
data()
876 for (bitidx,thisbitname)
in trgnamedict:
880 thispresc=prescales[bitidx]
882 thistrgcount=trgcounts[bitidx]
885 if bitidx
in range(0,128):
887 maskval=algomask_l>>bitidx&1
889 maskval=algomask_h>>(bitidx-64)&1
892 maskval=techmask>>(bitidx-128)&1
893 thisbitinfo=(thisbitname,thistrgcount,thispresc,maskval)
894 bitinfo.append(thisbitinfo)
895 result[cmslsnum].
append(bitinfo)
902 return (runnum,result)
906 input dataidMap : {run:lumidataid}
907 result {runnum: (datasource(0),nominalegev(1),ncollidingbunches(2),starttime(3),stoptime(4),nls(5)}
912 inputRange=dataidMap.keys()
914 lumidataid=dataidMap[r][0]
916 perrundata=
lumiRunById(schema,lumidataid,lumitype=lumitype)
917 result[r]=(perrundata[1],perrundata[2],perrundata[3],perrundata[4],perrundata[5])
922 input dataidMap : {run:lumidataid}
923 result {runnum:{cmslsnum:beamstatus}}
928 inputRange=dataidMap.keys()
930 if not result.has_key(r):
932 lumidataid=dataidMap[r][0]
934 qHandle=schema.newQuery()
937 qHandle.addToOutputList(
'CMSLSNUM')
938 qHandle.addToOutputList(
'BEAMSTATUS')
939 qConditionStr=
'DATA_ID=:dataid'
940 qCondition=coral.AttributeList()
941 qCondition.extend(
'dataid',
'unsigned long long')
942 qCondition[
'dataid'].setData(int(lumidataid))
943 qResult=coral.AttributeList()
944 qResult.extend(
'CMSLSNUM',
'unsigned int')
945 qResult.extend(
'BEAMSTATUS',
'string')
946 qHandle.defineOutput(qResult)
947 qHandle.setCondition(qConditionStr,qCondition)
948 cursor=qHandle.execute()
950 cmslsnum=cursor.currentRow()[
'CMSLSNUM'].
data()
951 bs=cursor.currentRow()[
'BEAMSTATUS'].
data()
952 if bs!=
'STABLE BEAMS':
953 result[r][cmslsnum]=bs
963 output: (runnum(0),datasource(1),nominalegev(2),ncollidingbunches(3),starttimestr(4),stoptimestr(5),nls(6))
966 if lumitype
not in [
'HF',
'PIXEL']:
967 raise ValueError(
'unknown lumitype '+lumitype)
973 qHandle=schema.newQuery()
975 qHandle.addToTableList(lumitableName)
976 qHandle.addToOutputList(
'RUNNUM')
977 qHandle.addToOutputList(
'SOURCE')
978 qHandle.addToOutputList(
'NOMINALEGEV')
979 qHandle.addToOutputList(
'NCOLLIDINGBUNCHES')
980 qHandle.addToOutputList(
'TO_CHAR('+lumitableName+
'.STARTTIME,\'MM/DD/YY HH24:MI:SS\')',
'startT')
981 qHandle.addToOutputList(
'TO_CHAR('+lumitableName+
'.STOPTIME,\'MM/DD/YY HH24:MI:SS\')',
'stopT')
982 qHandle.addToOutputList(
'NLS')
983 qConditionStr=
'DATA_ID=:dataid'
984 qCondition=coral.AttributeList()
985 qCondition.extend(
'dataid',
'unsigned long long')
986 qCondition[
'dataid'].setData(lumidataid)
987 qResult=coral.AttributeList()
988 qResult.extend(
'RUNNUM',
'unsigned int')
989 qResult.extend(
'SOURCE',
'string')
990 qResult.extend(
'NOMINALEGEV',
'float')
991 qResult.extend(
'NCOLLIDINGBUNCHES',
'unsigned int')
992 qResult.extend(
'startT',
'string')
993 qResult.extend(
'stopT',
'string')
994 qResult.extend(
'NLS',
'unsigned int')
995 qHandle.defineOutput(qResult)
996 qHandle.setCondition(qConditionStr,qCondition)
997 cursor=qHandle.execute()
1000 while cursor.next():
1001 runnum=cursor.currentRow()[
'RUNNUM'].
data()
1002 datasource=cursor.currentRow()[
'SOURCE'].
data()
1004 if not cursor.currentRow()[
'NOMINALEGEV'].isNull():
1005 nominalegev=cursor.currentRow()[
'NOMINALEGEV'].
data()
1007 if not cursor.currentRow()[
'NCOLLIDINGBUNCHES'].isNull():
1008 ncollidingbunches=cursor.currentRow()[
'NCOLLIDINGBUNCHES'].
data()
1009 startTstr=cursor.currentRow()[
'startT'].
data()
1010 stopTstr=cursor.currentRow()[
'stopT'].
data()
1013 if not cursor.currentRow()[
'NLS'].isNull():
1014 nls=cursor.currentRow()[
'NLS'].
data()
1015 result=(runnum,datasource,nominalegev,ncollidingbunches,startTstr,stopTstr,nls)
1067 qHandle.addToTableList(s)
1068 qResult=coral.AttributeList()
1069 qResult.extend(
'FILLSCHEMEPATTERN',
'string')
1070 qResult.extend(
'CORRECTIONFACTOR',
'float')
1071 qHandle.defineOutput(qResult)
1072 qHandle.addToOutputList(
'FILLSCHEMEPATTERN')
1073 qHandle.addToOutputList(
'CORRECTIONFACTOR')
1074 cursor=qHandle.execute()
1075 while cursor.next():
1076 fillschemePattern=cursor.currentRow()[
'FILLSCHEMEPATTERN'].
data()
1077 afterglowfac=cursor.currentRow()[
'CORRECTIONFACTOR'].
data()
1078 afterglows.append((fillschemePattern,afterglowfac))
1085 def lumiLSById(schema,dataid,beamstatus=None,withBXInfo=False,bxAlgo='OCC1',withBeamIntensity=False,tableName=None):
1088 beamstatus: filter on beam status flag
1090 result (runnum,{lumilsnum,[cmslsnum(0),instlumi(1),instlumierr(2),instlumiqlty(3),beamstatus(4),beamenergy(5),numorbit(6),startorbit(7),(bxvalueArray,bxerrArray)(8),(bxindexArray,beam1intensityArray,beam2intensityArray)(9)]})
1094 qHandle=schema.newQuery()
1095 if withBXInfo
and bxAlgo
not in [
'OCC1',
'OCC2',
'ET']:
1096 raise ValueError(
'unknown lumi algo '+bxAlgo)
1097 if beamstatus
and beamstatus
not in [
'STABLE BEAMS',]:
1098 raise ValueError(
'unknown beam status '+beamstatus)
1100 if tableName
is None:
1104 qHandle.addToTableList(lls)
1105 qHandle.addToOutputList(
'RUNNUM',
'runnum')
1106 qHandle.addToOutputList(
'LUMILSNUM',
'lumilsnum')
1107 qHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1108 qHandle.addToOutputList(
'INSTLUMI',
'instlumi')
1109 qHandle.addToOutputList(
'INSTLUMIERROR',
'instlumierr')
1110 qHandle.addToOutputList(
'INSTLUMIQUALITY',
'instlumiqlty')
1111 qHandle.addToOutputList(
'BEAMSTATUS',
'beamstatus')
1112 qHandle.addToOutputList(
'BEAMENERGY',
'beamenergy')
1113 qHandle.addToOutputList(
'NUMORBIT',
'numorbit')
1114 qHandle.addToOutputList(
'STARTORBIT',
'startorbit')
1116 qHandle.addToOutputList(
'BXLUMIVALUE_'+bxAlgo,
'bxvalue')
1117 qHandle.addToOutputList(
'BXLUMIERROR_'+bxAlgo,
'bxerror')
1118 if withBeamIntensity:
1119 qHandle.addToOutputList(
'CMSBXINDEXBLOB',
'bxindexblob')
1120 qHandle.addToOutputList(
'BEAMINTENSITYBLOB_1',
'beam1intensity')
1121 qHandle.addToOutputList(
'BEAMINTENSITYBLOB_2',
'beam2intensity')
1123 qConditionStr=
'DATA_ID=:dataid'
1124 qCondition=coral.AttributeList()
1125 qCondition.extend(
'dataid',
'unsigned long long')
1126 qCondition[
'dataid'].setData(int(dataid))
1128 qConditionStr+=
' and BEAMSTATUS=:beamstatus'
1129 qCondition.extend(
'beamstatus',
'string')
1130 qCondition[
'beamstatus'].setData(beamstatus)
1131 qResult=coral.AttributeList()
1132 qResult.extend(
'runnum',
'unsigned int')
1133 qResult.extend(
'lumilsnum',
'unsigned int')
1134 qResult.extend(
'cmslsnum',
'unsigned int')
1135 qResult.extend(
'instlumi',
'float')
1136 qResult.extend(
'instlumierr',
'float')
1137 qResult.extend(
'instlumiqlty',
'short')
1138 qResult.extend(
'beamstatus',
'string')
1139 qResult.extend(
'beamenergy',
'float')
1140 qResult.extend(
'numorbit',
'unsigned int')
1141 qResult.extend(
'startorbit',
'unsigned int')
1143 qResult.extend(
'bxvalue',
'blob')
1144 qResult.extend(
'bxerror',
'blob')
1145 if withBeamIntensity:
1146 qResult.extend(
'bxindexblob',
'blob')
1147 qResult.extend(
'beam1intensity',
'blob')
1148 qResult.extend(
'beam2intensity',
'blob')
1149 qHandle.defineOutput(qResult)
1150 qHandle.setCondition(qConditionStr,qCondition)
1151 cursor=qHandle.execute()
1152 while cursor.next():
1153 runnum=cursor.currentRow()[
'runnum'].
data()
1154 lumilsnum=cursor.currentRow()[
'lumilsnum'].
data()
1155 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1156 instlumi=cursor.currentRow()[
'instlumi'].
data()
1157 instlumierr=cursor.currentRow()[
'instlumierr'].
data()
1158 instlumiqlty=cursor.currentRow()[
'instlumiqlty'].
data()
1159 bs=cursor.currentRow()[
'beamstatus'].
data()
1160 begev=cursor.currentRow()[
'beamenergy'].
data()
1161 numorbit=cursor.currentRow()[
'numorbit'].
data()
1162 startorbit=cursor.currentRow()[
'startorbit'].
data()
1167 bxvalueblob=cursor.currentRow()[
'bxvalue'].
data()
1168 bxerrblob=cursor.currentRow()[
'bxerror'].
data()
1169 if bxvalueblob
and bxerrblob:
1172 bxinfo=(bxvaluesArray,bxerrArray)
1177 if withBeamIntensity:
1178 bxindexblob=cursor.currentRow()[
'bxindexblob'].
data()
1179 beam1intensity=cursor.currentRow()[
'beam1intensity'].
data()
1180 beam2intensity=cursor.currentRow()[
'beam2intensity'].
data()
1185 beaminfo=(bxindexArray,beam1intensityArray,beam2intensityArray)
1186 result[lumilsnum]=[cmslsnum,instlumi,instlumierr,instlumiqlty,bs,begev,numorbit,startorbit,bxinfo,beaminfo]
1191 return (runnum,result)
1194 result (runnum,[(lumilsnum(0),cmslsnum(1),beamstatus(2),beamenergy(3),ncollidingbunches(4),beaminfolist(5),..])
1195 beaminfolist=[(bxidx,beam1intensity,beam2intensity)]
1200 qHandle=schema.newQuery()
1203 qHandle.addToOutputList(
'NCOLLIDINGBUNCHES')
1204 qConditionStr=
'DATA_ID=:dataid'
1205 qCondition=coral.AttributeList()
1206 qCondition.extend(
'dataid',
'unsigned long long')
1207 qCondition[
'dataid'].setData(dataid)
1208 qResult=coral.AttributeList()
1209 qResult.extend(
'NCOLLIDINGBUNCHES',
'unsigned int')
1210 qHandle.defineOutput(qResult)
1211 qHandle.setCondition(qConditionStr,qCondition)
1212 cursor=qHandle.execute()
1213 while cursor.next():
1214 ncollidingbunches=cursor.currentRow()[
'NCOLLIDINGBUNCHES'].
data()
1219 qHandle=schema.newQuery()
1222 qHandle.addToOutputList(
'RUNNUM')
1223 qHandle.addToOutputList(
'CMSLSNUM')
1224 qHandle.addToOutputList(
'LUMILSNUM')
1225 qHandle.addToOutputList(
'BEAMSTATUS')
1226 qHandle.addToOutputList(
'BEAMENERGY')
1227 if withBeamIntensity:
1228 qHandle.addToOutputList(
'CMSBXINDEXBLOB')
1229 qHandle.addToOutputList(
'BEAMINTENSITYBLOB_1')
1230 qHandle.addToOutputList(
'BEAMINTENSITYBLOB_2')
1231 qConditionStr=
'DATA_ID=:dataid'
1232 qCondition=coral.AttributeList()
1233 qCondition.extend(
'dataid',
'unsigned long long')
1234 qCondition[
'dataid'].setData(dataid)
1235 qResult=coral.AttributeList()
1236 qResult.extend(
'RUNNUM',
'unsigned int')
1237 qResult.extend(
'CMSLSNUM',
'unsigned int')
1238 qResult.extend(
'LUMILSNUM',
'unsigned int')
1239 qResult.extend(
'BEAMSTATUS',
'string')
1240 qResult.extend(
'BEAMENERGY',
'float')
1241 if withBeamIntensity:
1242 qResult.extend(
'BXINDEXBLOB',
'blob')
1243 qResult.extend(
'BEAM1INTENSITY',
'blob')
1244 qResult.extend(
'BEAM2INTENSITY',
'blob')
1245 qHandle.defineOutput(qResult)
1246 qHandle.setCondition(qConditionStr,qCondition)
1247 cursor=qHandle.execute()
1248 while cursor.next():
1249 runnum=cursor.currentRow()[
'RUNNUM'].
data()
1250 cmslsnum=cursor.currentRow()[
'CMSLSNUM'].
data()
1251 lumilsnum=cursor.currentRow()[
'LUMILSNUM'].
data()
1252 beamstatus=cursor.currentRow()[
'BEAMSTATUS'].
data()
1253 beamenergy=cursor.currentRow()[
'BEAMENERGY'].
data()
1255 beaminfotupleList=[]
1256 if withBeamIntensity:
1257 bxindexblob=cursor.currentRow()[
'BXINDEXBLOB'].
data()
1258 beam1intensityblob=cursor.currentRow()[
'BEAM1INTENSITY'].
data()
1259 beam2intensityblob=cursor.currentRow()[
'BEAM2INTENSITY'].
data()
1261 beam1intensityArray=
None
1262 beam2intensityArray=
None
1265 if beam1intensityblob:
1267 if beam2intensityblob:
1269 if bxindexArray
and beam1intensityArray
and beam2intensityArray:
1270 for idx,bxindex
in enumerate(bxindexArray):
1271 if (beam1intensityArray[idx]
and beam1intensityArray[idx]>minIntensity)
or (beam2intensityArray[idx]
and beam2intensityArray[idx]>minIntensity):
1272 beaminfotuple=(bxindex,beam1intensityArray[idx],beam2intensityArray[idx])
1273 beaminfotupleList.append(beaminfotuple)
1275 del beam1intensityArray[:]
1276 del beam2intensityArray[:]
1277 result.append((lumilsnum,cmslsnum,beamstatus,beamenergy,ncollidingbunches,beaminfotupleList))
1282 return (runnum,result)
1285 result {lumilsnum:[cmslsnum,numorbit,startorbit,bxlumivalue,bxlumierr,bxlumiqlty]}
1288 qHandle=schema.newQuery()
1291 qHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1292 qHandle.addToOutputList(
'LUMILSNUM',
'lumilsnum')
1294 qHandle.addToOutputList(
'NUMORBIT',
'numorbit')
1295 qHandle.addToOutputList(
'STARTORBIT',
'startorbit')
1296 qHandle.addToOutputList(
'BXLUMIVALUE_'+algoname,
'bxlumivalue')
1297 qHandle.addToOutputList(
'BXLUMIERROR_'+algoname,
'bxlumierr')
1298 qHandle.addToOutputList(
'BXLUMIQUALITY_'+algoname,
'bxlumiqlty')
1299 qConditionStr=
'DATA_ID=:dataid'
1300 qCondition=coral.AttributeList()
1301 qCondition.extend(
'dataid',
'unsigned long long')
1302 qCondition[
'dataid'].setData(dataid)
1303 qResult=coral.AttributeList()
1304 qResult.extend(
'cmslsnum',
'unsigned int')
1305 qResult.extend(
'lumilsnum',
'unsigned int')
1306 qResult.extend(
'numorbit',
'unsigned int')
1307 qResult.extend(
'startorbit',
'unsigned int')
1308 qResult.extend(
'bxlumivalue',
'blob')
1309 qResult.extend(
'bxlumierr',
'blob')
1310 qResult.extend(
'bxlumiqlty',
'blob')
1311 qHandle.defineOutput(qResult)
1312 qHandle.setCondition(qConditionStr,qCondition)
1313 cursor=qHandle.execute()
1314 while cursor.next():
1315 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1316 lumilsnum=cursor.currentRow()[
'lumilsnum'].
data()
1317 numorbit=cursor.currentRow()[
'numorbit'].
data()
1318 startorbit=cursor.currentRow()[
'startorbit'].
data()
1319 bxlumivalue=cursor.currentRow()[
'bxlumivalue'].
data()
1320 bxlumierr=cursor.currentRow()[
'bxlumierr'].
data()
1321 bxlumiqlty=cursor.currentRow()[
'bxlumiqlty'].
data()
1322 if not result.has_key(algoname):
1324 if not result[algoname].has_key(lumilsnum):
1325 result[algoname][lumilsnum]=[]
1326 result[algoname][lumilsnum].extend([cmslsnum,numorbit,startorbit,bxlumivalue,bxlumierr,bxlumiqlty])
1329 raise RuntimeError(
' dataDML.lumiBXById: '+str(e))
1333 def hltRunById(schema,dataid,hltpathname=None,hltpathpattern=None):
1335 result [runnum(0),datasource(1),npath(2),hltnamedict(3)]
1337 npath : total number of hltpath in DB
1338 hltnamedict : list of all selected paths [(hltpathidx,hltname),(hltpathidx,hltname)]
1341 qHandle=schema.newQuery()
1348 qHandle.addToOutputList(
'RUNNUM',
'runnum')
1349 qHandle.addToOutputList(
'SOURCE',
'datasource')
1350 qHandle.addToOutputList(
'NPATH',
'npath')
1351 qHandle.addToOutputList(
'PATHNAMECLOB',
'pathnameclob')
1352 qConditionStr=
'DATA_ID=:dataid'
1353 qCondition=coral.AttributeList()
1354 qCondition.extend(
'dataid',
'unsigned long long')
1355 qCondition[
'dataid'].setData(dataid)
1356 qResult=coral.AttributeList()
1357 qResult.extend(
'runnum',
'unsigned int')
1358 qResult.extend(
'datasource',
'string')
1359 qResult.extend(
'npath',
'unsigned int')
1360 qResult.extend(
'pathnameclob',
'string')
1361 qHandle.defineOutput(qResult)
1362 qHandle.setCondition(qConditionStr,qCondition)
1363 cursor=qHandle.execute()
1366 while cursor.next():
1367 runnum=cursor.currentRow()[
'runnum'].
data()
1368 datasource=cursor.currentRow()[
'datasource'].
data()
1369 npath=cursor.currentRow()[
'npath'].
data()
1370 pathnameclob=cursor.currentRow()[
'pathnameclob'].
data()
1372 pathnames=pathnameclob.split(
',')
1373 for pathnameidx,hltname
in enumerate(pathnames):
1375 if hltpathname==hltname:
1376 hltnamedict.append((pathnameidx,hltname))
1378 elif hltpathpattern:
1379 if fnmatch.fnmatch(hltname,hltpathpattern):
1380 hltnamedict.append((pathnameidx,hltname))
1383 result=[runnum,datasource,npath,hltnamedict]
1392 select m.hltpathname,m.l1seed from cmsrunsummary r,trghltmap m where r.runnum=:runnum and m.hltkey=r.hltkey and [m.hltpathname=:hltpathname]
1393 output: {hltpath:l1seed}
1396 queryHandle=schema.newQuery()
1399 if hltpathpattern
and hltpathpattern
in [
'*',
'all',
'All',
'ALL']:
1402 queryHandle.addToTableList(r)
1403 queryHandle.addToTableList(m)
1404 queryCondition=coral.AttributeList()
1405 queryCondition.extend(
'runnum',
'unsigned int')
1406 queryCondition[
'runnum'].setData(int(runnum))
1408 queryHandle.addToOutputList(m+
'.HLTPATHNAME',
'hltpathname')
1409 queryHandle.addToOutputList(m+
'.L1SEED',
'l1seed')
1410 conditionStr=r+
'.RUNNUM=:runnum and '+m+
'.HLTKEY='+r+
'.HLTKEY'
1413 conditionStr+=
' AND '+m+
'.HLTPATHNAME=:hltpathname'
1414 queryCondition.extend(
'hltpathname',
'string')
1415 queryCondition[
'hltpathname'].setData(hltpathname)
1416 queryHandle.setCondition(conditionStr,queryCondition)
1417 queryResult=coral.AttributeList()
1418 queryResult.extend(
'pname',
'string')
1419 queryResult.extend(
'l1seed',
'string')
1420 queryHandle.defineOutput(queryResult)
1421 cursor=queryHandle.execute()
1422 while cursor.next():
1423 pname=cursor.currentRow()[
'pname'].
data()
1424 l1seed=cursor.currentRow()[
'l1seed'].
data()
1425 if not result.has_key(hltpathname):
1427 if fnmatch.fnmatch(pname,hltpathpattern):
1428 result[pname]=l1seed
1430 result[pname]=l1seed
1437 def hltLSById(schema,dataid,hltpathname=None,hltpathpattern=None,withL1Pass=False,withHLTAccept=False):
1439 result (runnum, {cmslsnum:[(pathname,prescale,1lpass,hltaccept)](0)]}
1444 hltrundata=
hltRunById(schema,dataid,hltpathname=hltpathname,hltpathpattern=hltpathpattern)
1447 hltnamedict=hltrundata[3]
1449 return (hltrundata[0],{})
1453 qHandle=schema.newQuery()
1456 qHandle.addToOutputList(
'RUNNUM',
'runnum')
1457 qHandle.addToOutputList(
'CMSLSNUM',
'cmslsnum')
1458 if len(hltnamedict)!=0:
1459 qHandle.addToOutputList(
'PRESCALEBLOB',
'prescaleblob')
1461 qHandle.addToOutputList(
'HLTCOUNTBLOB',
'hltcountblob')
1463 qHandle.addToOutputList(
'HLTACCEPTBLOB',
'hltacceptblob')
1464 qConditionStr=
'DATA_ID=:dataid'
1465 qCondition=coral.AttributeList()
1466 qCondition.extend(
'dataid',
'unsigned long long')
1467 qCondition[
'dataid'].setData(dataid)
1468 qResult=coral.AttributeList()
1469 qResult.extend(
'runnum',
'unsigned int')
1470 qResult.extend(
'cmslsnum',
'unsigned int')
1471 if len(hltnamedict)!=0:
1472 qResult.extend(
'prescaleblob',
'blob')
1474 qResult.extend(
'hltcountblob',
'blob')
1476 qResult.extend(
'hltacceptblob',
'blob')
1477 qHandle.defineOutput(qResult)
1478 qHandle.setCondition(qConditionStr,qCondition)
1479 cursor=qHandle.execute()
1480 while cursor.next():
1481 runnum=cursor.currentRow()[
'runnum'].
data()
1482 cmslsnum=cursor.currentRow()[
'cmslsnum'].
data()
1486 if len(hltnamedict)!=0:
1487 prescaleblob=cursor.currentRow()[
'prescaleblob'].
data()
1489 hltcountblob=cursor.currentRow()[
'hltcountblob'].
data()
1491 hltacceptblob=cursor.currentRow()[
'hltacceptblob'].
data()
1492 if not result.has_key(cmslsnum):
1513 for (hltpathidx,thispathname)
in hltnamedict:
1518 thispresc=prescales[hltpathidx]
1520 thishltcount=hltcounts[hltpathidx]
1522 thisaccept=hltaccepts[hltpathidx]
1523 thispathinfo=(thispathname,thispresc,thishltcount,thisaccept)
1524 pathinfo.append(thispathinfo)
1525 result[cmslsnum]=pathinfo
1534 return (runnum,result)
1538 output: {run:intglumi_in_fb}
1545 qHandle=schema.newQuery()
1548 qResult=coral.AttributeList()
1549 qResult.extend(
'RUNNUM',
'unsigned int')
1550 qResult.extend(
'INTGLUMI',
'float')
1551 qConditionStr=
'RUNNUM>=:minrun AND RUNNUM<=:maxrun'
1552 qCondition=coral.AttributeList()
1553 qCondition.extend(
'minrun',
'unsigned int')
1554 qCondition.extend(
'maxrun',
'unsigned int')
1555 qCondition[
'minrun'].setData(minrun)
1556 qCondition[
'maxrun'].setData(maxrun)
1557 qHandle.addToOutputList(
'RUNNUM')
1558 qHandle.addToOutputList(
'INTGLUMI')
1559 qHandle.setCondition(qConditionStr,qCondition)
1560 qHandle.defineOutput(qResult)
1561 cursor=qHandle.execute()
1562 while cursor.next():
1563 runnum=cursor.currentRow()[
'RUNNUM'].
data()
1564 intglumi=cursor.currentRow()[
'INTGLUMI'].
data()
1565 result[runnum]=intglumi
1574 output:(patternStr:correctionFac)
1576 if lumitype
not in [
'PIXEL',
'HF']:
1577 raise ValueError(
'[ERROR] unsupported lumitype '+lumitype)
1578 correctorField=
'CORRECTIONFACTOR'
1579 if lumitype==
'PIXEL':
1580 correctorField=
'PIXELCORRECTIONFACTOR'
1582 qHandle=schema.newQuery()
1585 qResult=coral.AttributeList()
1586 qResult.extend(
'FILLSCHEMEPATTERN',
'string')
1587 qResult.extend(
'CORRECTIONFACTOR',
'float')
1588 qHandle.defineOutput(qResult)
1589 qHandle.addToOutputList(
'FILLSCHEMEPATTERN')
1590 qHandle.addToOutputList(correctorField)
1591 cursor=qHandle.execute()
1592 while cursor.next():
1593 fillschemePattern=cursor.currentRow()[
'FILLSCHEMEPATTERN'].
data()
1594 afterglowfac=cursor.currentRow()[
'CORRECTIONFACTOR'].
data()
1595 result[fillschemePattern]=afterglowfac
1606 return latestrevision
1612 return latestrevision
1618 return latestrevision
1622 select max data_id of the given run. In current design, it's the most recent data of the run
1626 qHandle=schema.newQuery()
1628 qHandle.addToTableList(tablename)
1629 qHandle.addToOutputList(
'DATA_ID')
1630 qConditionStr=
'RUNNUM=:runnum '
1631 qCondition=coral.AttributeList()
1632 qCondition.extend(
'runnum',
'unsigned int')
1633 qCondition[
'runnum'].setData(runnum)
1634 qResult=coral.AttributeList()
1635 qResult.extend(
'DATA_ID',
'unsigned long long')
1636 qHandle.defineOutput(qResult)
1637 qHandle.setCondition(qConditionStr,qCondition)
1638 cursor=qHandle.execute()
1639 while cursor.next():
1640 dataid=cursor.currentRow()[
'DATA_ID'].
data()
1653 input: inputRange [run]
1654 output: {run:lumiid}
1655 select data_id,runnum from hltdata where runnum<=runmax and runnum>=:runmin
1658 if not inputRange :
return result
1659 if len(inputRange)==1:
1661 result[inputRange[0]]=trgid
1663 rmin=
min(inputRange)
1664 rmax=
max(inputRange)
1665 result=dict.fromkeys(inputRange,
None)
1666 qHandle=schema.newQuery()
1668 qHandle.addToTableList(tablename)
1669 qHandle.addToOutputList(
'DATA_ID')
1670 qHandle.addToOutputList(
'RUNNUM')
1671 qConditionStr=
'RUNNUM>=:rmin'
1672 qCondition=coral.AttributeList()
1673 qCondition.extend(
'rmin',
'unsigned int')
1674 qCondition[
'rmin'].setData(rmin)
1676 qConditionStr+=
' AND RUNNUM<=:rmax'
1677 qCondition.extend(
'rmax',
'unsigned int')
1678 qCondition[
'rmax'].setData(rmax)
1679 qResult=coral.AttributeList()
1680 qResult.extend(
'DATA_ID',
'unsigned long long')
1681 qResult.extend(
'RUNNUM',
'unsigned int')
1682 qHandle.defineOutput(qResult)
1683 qHandle.setCondition(qConditionStr,qCondition)
1684 cursor=qHandle.execute()
1685 while cursor.next():
1686 dataid=cursor.currentRow()[
'DATA_ID'].
data()
1687 runnum=cursor.currentRow()[
'RUNNUM'].
data()
1688 if result.has_key(runnum):
1689 if dataid>result[runnum]:
1690 result[runnum]=dataid
1741 get norm dataids by amodetag, egev if there are duplicates, pick max(dataid).Bypass full version lookups
1742 select data_id from luminorm where amodetag=:amodetag and egev_1=:egev1
1745 qHandle=schema.newQuery()
1750 qHandle.addToOutputList(
'DATA_ID',
'normdataid')
1751 qConditionStr=
'AMODETAG=:amodetag AND EGEV_1>=:egevmin AND EGEV_1<=:egevmax'
1752 qCondition=coral.AttributeList()
1753 qCondition.extend(
'amodetag',
'string')
1754 qCondition.extend(
'egevmin',
'unsigned int')
1755 qCondition.extend(
'egevmax',
'unsigned int')
1756 qCondition[
'amodetag'].setData(amodetag)
1757 qCondition[
'egevmin'].setData(int(egevmin))
1758 qCondition[
'egevmax'].setData(int(egevmax))
1759 qResult=coral.AttributeList()
1760 qResult.extend(
'normdataid',
'unsigned long long')
1761 qHandle.defineOutput(qResult)
1762 qHandle.setCondition(qConditionStr,qCondition)
1763 cursor=qHandle.execute()
1764 while cursor.next():
1765 normdataid=cursor.currentRow()[
'normdataid'].
data()
1766 luminormids.append(normdataid)
1771 if len(luminormids) !=0:
return max(luminormids)
1776 get norm dataids by name, if there are duplicates, pick max(dataid).Bypass full version lookups
1777 select data_id from luminorms where entry_name=:normname
1778 result luminormdataid
1781 qHandle=schema.newQuery()
1784 qHandle.addToOutputList(
'DATA_ID',
'normdataid')
1785 qConditionStr=
'ENTRY_NAME=:normname '
1786 qCondition=coral.AttributeList()
1787 qCondition.extend(
'normname',
'string')
1788 qCondition[
'normname'].setData(normname)
1789 qResult=coral.AttributeList()
1790 qResult.extend(
'normdataid',
'unsigned long long')
1791 qHandle.defineOutput(qResult)
1792 qHandle.setCondition(qConditionStr,qCondition)
1793 cursor=qHandle.execute()
1794 while cursor.next():
1795 normdataid=cursor.currentRow()[
'normdataid'].
data()
1796 luminormids.append(normdataid)
1801 if len(luminormids) !=0:
return max(luminormids)
1808 select el.entry_id,et.entry_id,eh.entry_id,el.revision_id,et.revision_id,eh.revision_id from lumidataentiries el,trgdataentries et,hltdataentries eh where el.name=et.name and et.name=eh.name and el.name=:entryname;
1811 return [lumientryid,trgentryid,hltentryid]
1814 qHandle=schema.newQuery()
1823 qCondition=coral.AttributeList()
1824 qCondition.extend(
'runnumstr',
'string')
1825 qCondition[
'runnumstr'].setData(str(runnum))
1826 qResult=coral.AttributeList()
1827 qResult.extend(
'lumientryid',
'unsigned long long')
1828 qResult.extend(
'trgentryid',
'unsigned long long')
1829 qResult.extend(
'hltentryid',
'unsigned long long')
1830 qHandle.defineOutput(qResult)
1831 qHandle.setCondition(qConditionStr,qCondition)
1832 cursor=qHandle.execute()
1833 while cursor.next():
1834 lumientryid=cursor.currentRow()[
'lumientryid'].
data()
1835 trgentryid=cursor.currentRow()[
'trgentryid'].
data()
1836 hltentryid=cursor.currentRow()[
'hltentryid'].
data()
1837 if lumientryid
in branchfilter
and trgentryid
in branchfilter
and hltentryid
in branchfilter:
1838 result.extend([lumientryid,trgentryid,hltentryid])
1847 select l.data_id,rl.revision_id from lumidatatable l,lumirevisions rl where l.data_id=rl.data_id and l.entry_id=:entryid
1848 check revision_id is in branch
1853 if datatype==
'lumi':
1855 elif datatype==
'trg':
1857 elif dataytpe==
'hlt':
1860 raise RunTimeError(
'datatype '+datatype+
' is not supported')
1862 qHandle=schema.newQuery()
1864 qHandle.addToTableList(revmaptablename)
1865 qHandle.addToTableList(datatablename)
1866 qHandle.addToOutputList(
'l.DATA_ID',
'dataid')
1867 qHandle.addToOutputList(revmaptablename+
'.REVISION_ID',
'revisionid')
1868 qConditionStr=datatablename+
'.DATA_ID='+revmaptablename+
'.DATA_ID AND '+datatablename+
'.ENTRY_ID=:entryid'
1869 qCondition=coral.AttributeList()
1870 qCondition.extend(
'entryid',
'unsigned long long')
1871 qResult=coral.AttributeList()
1872 qResult.extend(
'dataid',
'unsigned long long')
1873 qResult.extend(
'revisionid',
'unsigned long long')
1874 qHandle.defineOutput(qResult)
1875 qHandle.setCondition(qConditionStr,qCondition)
1876 cursor=qHandle.execute()
1877 while cursor.next():
1878 dataid=cursor.currentRow()[
'dataid'].
data()
1879 revisionid=cursor.currentRow()[
'revisionid'].
data()
1880 if revisionid
in branchfilter:
1881 dataids.append(dataid)
1886 if len(dataids)!=0:
return max(dataids)
1896 branchinfo(normrevisionid,branchname)
1897 optionalnormdata {'norm_occ2':norm_occ2,'norm_et':norm_et,'norm_pu':norm_pu,'constfactor':constfactor}
1899 (revision_id,entry_id,data_id)
1903 if optionalnormdata.has_key(
'normOcc2'):
1904 norm_occ2=optionalnormdata[
'norm_occ2']
1906 if optionalnormdata.has_key(
'norm_et'):
1907 norm_et=optionalnormdata[
'norm_et']
1909 if optionalnormdata.has_key(
'norm_pu'):
1910 norm_pu=optionalnormdata[
'norm_pu']
1912 if optionalnormdata.has_key(
'constfactor'):
1913 constfactor=optionalnormdata[
'constfactor']
1916 if entry_id
is None:
1918 entryinfo=(revision_id,entry_id,normname,data_id)
1923 tabrowDefDict={
'DATA_ID':
'unsigned long long',
'ENTRY_ID':
'unsigned long long',
'ENTRY_NAME':
'string',
'AMODETAG':
'string',
'NORM_1':
'float',
'EGEV_1':
'unsigned int',
'NORM_OCC2':
'float',
'NORM_ET':
'float',
'NORM_PU':
'float',
'CONSTFACTOR':
'float'}
1924 tabrowValueDict={
'DATA_ID':data_id,
'ENTRY_ID':entry_id,
'ENTRY_NAME':normname,
'AMODETAG':amodetag,
'NORM_1':norm1,
'EGEV_1':egev1,
'NORM_OCC2':norm_occ2,
'NORM_ET':norm_et,
'NORM_PU':norm_pu,
'CONSTFACTOR':constfactor}
1927 return (revision_id,entry_id,data_id)
1934 branchinfo(corrrevisionid,branchname)
1935 optionalcorrdata {'a2':a2,'drift':drif}
1937 (revision_id,entry_id,data_id)
1940 if optionalcorrdata.has_key(
'a2'):
1941 a2=optionalcorrdata[
'a2']
1943 if optionalcorrdata.has_key(
'drift'):
1944 drift=optionalcorrdata[
'drift']
1947 if entry_id
is None:
1949 entryinfo=(revision_id,entry_id,corrname,data_id)
1954 tabrowDefDict={
'DATA_ID':
'unsigned long long',
'ENTRY_ID':
'unsigned long long',
'ENTRY_NAME':
'string',
'A1':
'float',
'A2':
'float',
'DRIFT':
'float'}
1955 tabrowValueDict={
'DATA_ID':data_id,
'ENTRY_ID':entry_id,
'ENTRY_NAME':corrname,
'A1':a1,
'A2':a2,
'DRIFT':drift}
1957 db.insertOneRow(nameDealer.lumicorrectionsTableName(),tabrowDefDict,tabrowValueDict)
1958 return (revision_id,entry_id,data_id)
1965 lumirundata [datasource,nominalenergy,ncollidingbunches,starttime,stoptime,nls]
1966 branchinfo (branch_id,branch_name)
1967 tableName lumiruntablename
1969 (revision_id,entry_id,data_id)
1972 datasource=lumirundata[0]
1975 starttime=coral.TimeStamp()
1976 stoptime=coral.TimeStamp()
1978 if len(lumirundata)>1:
1979 nominalenergy=lumirundata[1]
1980 ncollidingbunches=lumirundata[2]
1981 starttime=lumirundata[3]
1982 stoptime=lumirundata[4]
1985 if entry_id
is None:
1987 entryinfo=(revision_id,entry_id,str(runnumber),data_id)
1993 tabrowDefDict={
'DATA_ID':
'unsigned long long',
'ENTRY_ID':
'unsigned long long',
'ENTRY_NAME':
'string',
'RUNNUM':
'unsigned int',
'SOURCE':
'string',
'NOMINALEGEV':
'float',
'NCOLLIDINGBUNCHES':
'unsigned int',
'STARTTIME':
'time stamp',
'STOPTIME':
'time stamp',
'NLS':
'unsigned int'}
1994 tabrowValueDict={
'DATA_ID':data_id,
'ENTRY_ID':entry_id,
'ENTRY_NAME':str(runnumber),
'RUNNUM':int(runnumber),
'SOURCE':datasource,
'NOMINALEGEV':nominalegev,
'NCOLLIDINGBUNCHES':ncollidingbunches,
'STARTTIME':starttime,
'STOPTIME':stoptime,
'NLS':nls}
1996 db.insertOneRow(tableName,tabrowDefDict,tabrowValueDict)
1997 return (revision_id,entry_id,data_id)
2004 trgrundata [datasource(0),bitzeroname(1),bitnameclob(2)]
2005 bitnames clob, bitnames separated by ','
2007 (revision_id,entry_id,data_id)
2010 datasource=trgrundata[0]
2011 bitzeroname=trgrundata[1]
2012 bitnames=trgrundata[2]
2014 if entry_id
is None:
2016 entryinfo=(revision_id,entry_id,str(runnumber),data_id)
2021 tabrowDefDict={
'DATA_ID':
'unsigned long long',
'ENTRY_ID':
'unsigned long long',
'ENTRY_NAME':
'string',
'SOURCE':
'string',
'RUNNUM':
'unsigned int',
'BITZERONAME':
'string',
'BITNAMECLOB':
'string'}
2022 tabrowValueDict={
'DATA_ID':data_id,
'ENTRY_ID':entry_id,
'ENTRY_NAME':str(runnumber),
'SOURCE':datasource,
'RUNNUM':int(runnumber),
'BITZERONAME':bitzeroname,
'BITNAMECLOB':bitnames}
2025 return (revision_id,entry_id,data_id)
2031 hltrundata [pathnameclob(0),datasource(1)]
2033 (revision_id,entry_id,data_id)
2036 pathnames=hltrundata[0]
2037 datasource=hltrundata[1]
2038 npath=len(pathnames.split(
','))
2040 if entry_id
is None:
2042 entryinfo=(revision_id,entry_id,str(runnumber),data_id)
2047 tabrowDefDict={
'DATA_ID':
'unsigned long long',
'ENTRY_ID':
'unsigned long long',
'ENTRY_NAME':
'string',
'RUNNUM':
'unsigned int',
'SOURCE':
'string',
'NPATH':
'unsigned int',
'PATHNAMECLOB':
'string'}
2048 tabrowValueDict={
'DATA_ID':data_id,
'ENTRY_ID':entry_id,
'ENTRY_NAME':str(runnumber),
'RUNNUM':int(runnumber),
'SOURCE':datasource,
'NPATH':npath,
'PATHNAMECLOB':pathnames}
2051 return (revision_id,entry_id,data_id)
2058 runsummarydata [l1key,amodetag,egev,sequence,hltkey,fillnum,starttime,stoptime]
2061 l1key=runsummarydata[0]
2062 amodetag=runsummarydata[1]
2063 egev=runsummarydata[2]
2069 if not complementalOnly:
2070 sequence=runsummarydata[3]
2071 hltkey=runsummarydata[4]
2072 fillnum=runsummarydata[5]
2073 starttime=runsummarydata[6]
2074 stoptime=runsummarydata[7]
2076 if not complementalOnly:
2077 tabrowDefDict={
'RUNNUM':
'unsigned int',
'L1KEY':
'string',
'AMODETAG':
'string',
'EGEV':
'unsigned int',
'SEQUENCE':
'string',
'HLTKEY':
'string',
'FILLNUM':
'unsigned int',
'STARTTIME':
'time stamp',
'STOPTIME':
'time stamp'}
2078 tabrowValueDict={
'RUNNUM':int(runnumber),
'L1KEY':l1key,
'AMODETAG':amodetag,
'EGEV':int(egev),
'SEQUENCE':sequence,
'HLTKEY':hltkey,
'FILLNUM':int(fillnum),
'STARTTIME':starttime,
'STOPTIME':stoptime}
2082 setClause=
'L1KEY=:l1key,AMODETAG=:amodetag,EGEV=:egev'
2083 updateCondition=
'RUNNUM=:runnum'
2084 inputData=coral.AttributeList()
2085 inputData.extend(
'l1key',
'string')
2086 inputData.extend(
'amodetag',
'string')
2087 inputData.extend(
'egev',
'unsigned int')
2088 inputData.extend(
'runnum',
'unsigned int')
2089 inputData[
'l1key'].setData(l1key)
2090 inputData[
'amodetag'].setData(amodetag)
2091 inputData[
'egev'].setData(int(egev))
2092 inputData[
'runnum'].setData(int(runnumber))
2100 trghltmap {hltpath:l1seed}
2106 kQueryBindList=coral.AttributeList()
2107 kQueryBindList.extend(
'hltkey',
'string')
2108 kQuery=schema.newQuery()
2110 kQuery.setCondition(
'HLTKEY=:hltkey',kQueryBindList)
2111 kQueryBindList[
'hltkey'].setData(hltkey)
2112 kResult=kQuery.execute()
2113 while kResult.next():
2115 if not hltkeyExists:
2117 trghltDefDict=[(
'HLTKEY',
'string'),(
'HLTPATHNAME',
'string'),(
'L1SEED',
'string')]
2118 for hltpath,l1seed
in trghltmap.items():
2119 bulkvalues.append([(
'HLTKEY',hltkey),(
'HLTPATHNAME',hltpath),(
'L1SEED',l1seed)])
2122 nrows=len(bulkvalues)
2125 print 'error in insertTrgHltMap '
2129 insert trg per-LS data for given run and data_id, this operation can be split in transaction chuncks
2131 trglsdata {cmslsnum:[deadtime,bitzerocount,bitzeroprescale,trgcountBlob,trgprescaleBlob]}
2132 result nrows inserted
2133 if nrows==0, then this insertion failed
2135 print 'total number of trg rows ',len(trglsdata)
2136 lstrgDefDict=[(
'DATA_ID',
'unsigned long long'),(
'RUNNUM',
'unsigned int'),(
'CMSLSNUM',
'unsigned int'),(
'DEADTIMECOUNT',
'unsigned long long'),(
'BITZEROCOUNT',
'unsigned int'),(
'BITZEROPRESCALE',
'unsigned int'),(
'PRESCALEBLOB',
'blob'),(
'TRGCOUNTBLOB',
'blob')]
2141 for cmslsnum,perlstrg
in trglsdata.items():
2142 deadtimecount=perlstrg[0]
2143 bitzerocount=perlstrg[1]
2144 bitzeroprescale=perlstrg[2]
2145 trgcountblob=perlstrg[3]
2146 trgprescaleblob=perlstrg[4]
2147 bulkvalues.append([(
'DATA_ID',data_id),(
'RUNNUM',runnumber),(
'CMSLSNUM',cmslsnum),(
'DEADTIMECOUNT',deadtimecount),(
'BITZEROCOUNT',bitzerocount),(
'BITZEROPRESCALE',bitzeroprescale),(
'PRESCALEBLOB',trgprescaleblob),(
'TRGCOUNTBLOB',trgcountblob)])
2151 print 'committing trg in LS chunck ',nrows
2153 session.transaction().
start(
False)
2155 session.transaction().commit()
2158 elif committedrows==len(trglsdata):
2159 print 'committing trg at the end '
2161 session.transaction().
start(
False)
2163 session.transaction().commit()
2165 print 'error in bulkInsertTrgLSData'
2170 hltlsdata {cmslsnum:[inputcountBlob,acceptcountBlob,prescaleBlob]}
2172 print 'total number of hlt rows ',len(hltlsdata)
2173 lshltDefDict=[(
'DATA_ID',
'unsigned long long'),(
'RUNNUM',
'unsigned int'),(
'CMSLSNUM',
'unsigned int'),(
'PRESCALEBLOB',
'blob'),(
'HLTCOUNTBLOB',
'blob'),(
'HLTACCEPTBLOB',
'blob')]
2178 for cmslsnum,perlshlt
in hltlsdata.items():
2179 inputcountblob=perlshlt[0]
2180 acceptcountblob=perlshlt[1]
2181 prescaleblob=perlshlt[2]
2182 bulkvalues.append([(
'DATA_ID',data_id),(
'RUNNUM',runnumber),(
'CMSLSNUM',cmslsnum),(
'PRESCALEBLOB',prescaleblob),(
'HLTCOUNTBLOB',inputcountblob),(
'HLTACCEPTBLOB',acceptcountblob)])
2187 print 'committing hlt in LS chunck ',nrows
2189 session.transaction().
start(
False)
2191 session.transaction().commit()
2194 elif committedrows==len(hltlsdata):
2195 print 'committing hlt at the end '
2197 session.transaction().
start(
False)
2199 session.transaction().commit()
2201 print 'error in bulkInsertHltLSData'
2207 lumilsdata {lumilsnum:[cmslsnum,instlumi,instlumierror,instlumiquality,beamstatus,beamenergy,numorbit,startorbit,cmsbxindexblob,beam1intensity,beam2intensity,bxlumivalue_occ1,bxlumierror_occ1,bxlumiquality_occ1,bxlumivalue_occ2,bxlumierror_occ2,bxlumiquality_occ2,bxlumivalue_et,bxlumierror_et,bxlumiquality_et]}
2211 lslumiDefDict=[(
'DATA_ID',
'unsigned long long'),(
'RUNNUM',
'unsigned int'),(
'LUMILSNUM',
'unsigned int'),(
'CMSLSNUM',
'unsigned int'),(
'INSTLUMI',
'float'),(
'INSTLUMIERROR',
'float'),(
'INSTLUMIQUALITY',
'short'),(
'BEAMSTATUS',
'string'),(
'BEAMENERGY',
'float'),(
'NUMORBIT',
'unsigned int'),(
'STARTORBIT',
'unsigned int'),(
'CMSBXINDEXBLOB',
'blob'),(
'BEAMINTENSITYBLOB_1',
'blob'),(
'BEAMINTENSITYBLOB_2',
'blob'),(
'BXLUMIVALUE_OCC1',
'blob'),(
'BXLUMIERROR_OCC1',
'blob'),(
'BXLUMIQUALITY_OCC1',
'blob'),(
'BXLUMIVALUE_OCC2',
'blob'),(
'BXLUMIERROR_OCC2',
'blob'),(
'BXLUMIQUALITY_OCC2',
'blob'),(
'BXLUMIVALUE_ET',
'blob'),(
'BXLUMIERROR_ET',
'blob'),(
'BXLUMIQUALITY_ET',
'blob')]
2213 lslumiDefDict=[(
'DATA_ID',
'unsigned long long'),(
'RUNNUM',
'unsigned int'),(
'LUMILSNUM',
'unsigned int'),(
'CMSLSNUM',
'unsigned int'),(
'INSTLUMI',
'float'),(
'INSTLUMIERROR',
'float'),(
'INSTLUMIQUALITY',
'short'),(
'BEAMSTATUS',
'string'),(
'BEAMENERGY',
'float'),(
'NUMORBIT',
'unsigned int'),(
'STARTORBIT',
'unsigned int')]
2214 print 'total number of lumi rows ',len(lumilsdata)
2219 for lumilsnum,perlslumi
in lumilsdata.items():
2220 cmslsnum=perlslumi[0]
2221 instlumi=perlslumi[1]
2222 instlumierror=perlslumi[2]
2223 instlumiquality=perlslumi[3]
2224 beamstatus=perlslumi[4]
2225 beamenergy=perlslumi[5]
2226 numorbit=perlslumi[6]
2227 startorbit=perlslumi[7]
2229 cmsbxindexindexblob=perlslumi[8]
2230 beam1intensity=perlslumi[9]
2231 beam2intensity=perlslumi[10]
2232 bxlumivalue_occ1=perlslumi[11]
2233 bxlumierror_occ1=perlslumi[12]
2234 bxlumiquality_occ1=perlslumi[13]
2235 bxlumivalue_occ2=perlslumi[14]
2236 bxlumierror_occ2=perlslumi[15]
2237 bxlumiquality_occ2=perlslumi[16]
2238 bxlumivalue_et=perlslumi[17]
2239 bxlumierror_et=perlslumi[18]
2240 bxlumiquality_et=perlslumi[19]
2241 bulkvalues.append([(
'DATA_ID',data_id),(
'RUNNUM',runnumber),(
'LUMILSNUM',lumilsnum),(
'CMSLSNUM',cmslsnum),(
'INSTLUMI',instlumi),(
'INSTLUMIERROR',instlumierror),(
'INSTLUMIQUALITY',instlumiquality),(
'BEAMSTATUS',beamstatus),(
'BEAMENERGY',beamenergy),(
'NUMORBIT',numorbit),(
'STARTORBIT',startorbit),(
'CMSBXINDEXBLOB',cmsbxindexindexblob),(
'BEAMINTENSITYBLOB_1',beam1intensity),(
'BEAMINTENSITYBLOB_2',beam2intensity),(
'BXLUMIVALUE_OCC1',bxlumivalue_occ1),(
'BXLUMIERROR_OCC1',bxlumierror_occ1),(
'BXLUMIQUALITY_OCC1',bxlumiquality_occ1),(
'BXLUMIVALUE_OCC2',bxlumivalue_occ2),(
'BXLUMIERROR_OCC2',bxlumierror_occ2),(
'BXLUMIQUALITY_OCC2',bxlumiquality_occ2),(
'BXLUMIVALUE_ET',bxlumivalue_et),(
'BXLUMIERROR_ET',bxlumierror_et),(
'BXLUMIQUALITY_ET',bxlumiquality_et)])
2243 bulkvalues.append([(
'DATA_ID',data_id),(
'RUNNUM',runnumber),(
'LUMILSNUM',lumilsnum),(
'CMSLSNUM',cmslsnum),(
'INSTLUMI',instlumi),(
'INSTLUMIERROR',instlumierror),(
'INSTLUMIQUALITY',instlumiquality),(
'BEAMSTATUS',beamstatus),(
'BEAMENERGY',beamenergy),(
'NUMORBIT',numorbit),(
'STARTORBIT',startorbit)])
2247 print 'committing lumi in LS chunck ',nrows
2249 session.transaction().
start(
False)
2250 db.bulkInsert(tableName,lslumiDefDict,bulkvalues)
2251 session.transaction().commit()
2254 elif committedrows==len(lumilsdata):
2255 print 'committing lumi at the end '
2257 session.transaction().
start(
False)
2258 db.bulkInsert(tableName,lslumiDefDict,bulkvalues)
2259 session.transaction().commit()
2327 if __name__ ==
"__main__":
2328 import sessionManager
2329 import lumidbDDL,revisionDML,generateDummyData
2331 myconstr=
'oracle://devdb10/cms_xiezhen_dev'
2333 session=svc.openSession(isReadOnly=
False,cpp2sqltype=[(
'unsigned int',
'NUMBER(10)'),(
'unsigned long long',
'NUMBER(20)')])
2334 schema=session.nominalSchema()
2335 session.transaction().
start(
False)
2351 normbranchinfo=(normbranchid,
'NORM')
2352 addNormToBranch(schema,
'pp7TeV',
'PROTPHYS',6370.0,3500,{},normbranchinfo)
2355 branchinfo=(branchid,
'DATA')
2356 for runnum
in [1200,1211,1222,1233,1345]:
2362 lumirundata=[lumidummydata[0]]
2363 lumilsdata=lumidummydata[1]
2365 insertLumiLSSummary(schema,runnum,lumidataid,lumilsdata)
2367 trgrundata=[trgdata[0],trgdata[1],trgdata[2]]
2368 trglsdata=trgdata[3]
2370 insertTrgLSData(schema,runnum,trgdataid,trglsdata)
2372 hltrundata=[hltdata[0],hltdata[1]]
2373 hltlsdata=hltdata[2]
2375 insertHltLSData(schema,runnum,hltdataid,hltlsdata)
2376 session.transaction().commit()
2377 print 'test reading'
2378 session.transaction().
start(
True)
2379 print '===inspecting NORM by name==='
2383 print 'latest norm data_id for pp7TeV ',latestNorms
2385 print '===inspecting DATA branch==='
2391 print 'latest lumi data_id for run 1211 ',latestrevision
2394 print 'latest lumi data_id for run 1222 ',latestrevision
2397 print 'latest trg data_id for run 1222 ',latestrevision
2398 session.transaction().commit()
2399 print 'tagging data so far as data_orig'
2400 session.transaction().
start(
False)
2402 session.transaction().commit()
2403 session.transaction().
start(
True)
2407 session.transaction().commit()
2408 session.transaction().
start(
False)
2409 for runnum
in [1200,1222]:
2410 print 'revising lumidata for run ',runnum
2412 lumirundata=[lumidummydata[0]]
2413 lumilsdata=lumidummydata[1]
2415 insertLumiLSSummary(schema,runnum,lumidataid,lumilsdata)
2418 session.transaction().commit()
2421 print '===test reading==='
2422 session.transaction().
start(
True)
2444 print 'trg run, trgdataid ',trgdataid
2445 print trgRunById(schema,trgdataid,withblobdata=
True)
2452 session.transaction().commit()
def guessLumiDataIdByRunInBranch
def revisionsInBranchName
def pixeltagRunsTableName
def guessTrgDataIdByRunInBranch
def bulkInsertLumiLSSummary
def addTrgRunDataToBranch
const T & max(const T &a, const T &b)
def addLumiRunDataToBranch
def pixellumidataTableName
static std::string join(char **cmd)
def lumisummaryv2TableName
char data[epos_bytes_allocation]
def guesscorrIdByName
LumiDB DML API # # Author: Zhen Xie #.
def guessHltDataIdByRunInBranch
def addHLTRunDataToBranch
def latestDataRevisionOfEntry
def cmsrunsummaryTableName