CMS 3D CMS Logo

queryDataSource.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from builtins import range
3 import array,coral
4 from RecoLuminosity.LumiDB import CommonUtil,nameDealer
5 
6 def uncalibrateLumi(runnumber,instlumi,instlumierror):
7  '''
8  input: runnumber,calibrated instlumi,calibrated instlumierror
9  output: (uncalibrated instlumi, uncalbrated instlumierror)
10  '''
11  normpp7tev=float(6370.0)
12  normpp900gev=float(16500.0)
13  normhi7tev=float(2.383)
14  oldnormpp7tev=float(6330)
15  if runnumber in [136290,136294,136297,134721,134725]:#900Gev pp runs
16  return (float(instlumi)/normpp900gev,float(instlumierror)/normpp900gev)
17  if runnumber >=150431 and runnumber<=153368 :#7TeV HI runs
18  return (float(instlumi)/normhi7tev,float(instlumierror)/normhi7tev)
19  return (float(instlumi)/normpp7tev,float(instlumierror)/normpp7tev)
20 
21 def uncalibratedlumiFromOldLumi(session,runnumber):
22  '''
23  retrieve old lumi value, divide by norm and restore to raw value
24  select lumilsnum,cmslsnum,instlumi,instlumierror,instlumiquality,startorbit,numorbit,beamenergy,beamstatus,cmsbxindexblob,beamintensityblob_1,beamintensityblob_2 from lumisummary where runnum=:runnumber order by lumilsnum
25 
26  select s.lumilsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality from lumidetail d,lumisummary s where d.lumisummary_id=s.lumisummary_id and s.runnum=:runnumber and d.algoname=:algoname order by s.lumilsnum
27 
28  output: {lumilsnum:[cmslsnum,uncalibratedinstlumi,uncalibratedinstlumierror,instlumiquality,beamstatus,beamenergy,numorbit,startorbit,cmsbxindexblob,beamintensityblob_1,beamintensityblob_2,bxlumivalue_occ1,bxlumierror_occ1,,bxlumiquality_occ1,bxlumivalue_occ2,bxlumierror_occ2,bxlumiquality_occ2,bxlumivalue_et,bxlumierror_et,bxlumiquality_et]}]}
29  dict size ~ 200mb for 1000LS
30  '''
31  nTotAlgo=3
32  try:
33  datadict={}
34  session.transaction().start(True)
35  lumischema=session.nominalSchema()
36  summaryQuery=lumischema.newQuery()
37  summaryQuery.addToTableList( nameDealer.lumisummaryTableName() )
38  summaryQuery.addToOutputList( 'LUMILSNUM','lumilsnum')
39  summaryQuery.addToOutputList( 'CMSLSNUM','cmslsnum')
40  summaryQuery.addToOutputList( 'INSTLUMI','instlumi')
41  summaryQuery.addToOutputList( 'INSTLUMIERROR','instlumierror')
42  summaryQuery.addToOutputList( 'INSTLUMIQUALITY','instlumiquality')
43  summaryQuery.addToOutputList( 'BEAMSTATUS','beamstatus')
44  summaryQuery.addToOutputList( 'BEAMENERGY','beamenergy')
45  summaryQuery.addToOutputList( 'NUMORBIT','numorbit')
46  summaryQuery.addToOutputList( 'STARTORBIT','startorbit')
47  summaryQuery.addToOutputList( 'CMSBXINDEXBLOB','cmsbxindexblob')
48  summaryQuery.addToOutputList( 'BEAMINTENSITYBLOB_1','beamintensityblob_1')
49  summaryQuery.addToOutputList( 'BEAMINTENSITYBLOB_2','beamintensityblob_2')
50  summaryCondition=coral.AttributeList()
51  summaryCondition.extend('runnumber','unsigned int')
52  summaryCondition['runnumber'].setData(int(runnumber))
53  summaryResult=coral.AttributeList()
54  summaryResult.extend('lumilsnum','unsigned int')
55  summaryResult.extend('cmslsnum','unsigned int')
56  summaryResult.extend('instlumi','float')
57  summaryResult.extend('instlumierror','float')
58  summaryResult.extend('instlumiquality','short')
59  summaryResult.extend('beamstatus','string')
60  summaryResult.extend('beamenergy','float')
61  summaryResult.extend('numorbit','unsigned int')
62  summaryResult.extend('startorbit','unsigned int')
63  summaryResult.extend('cmsbxindexblob','blob')
64  summaryResult.extend('beamintensityblob_1','blob')
65  summaryResult.extend('beamintensityblob_2','blob')
66  summaryQuery.defineOutput(summaryResult)
67  summaryQuery.addToOrderList('lumilsnum')
68  summaryQuery.setCondition('RUNNUM=:runnumber',summaryCondition)
69  summarycursor=summaryQuery.execute()
70  while next(summarycursor):
71  lumilsnum=summarycursor.currentRow()['lumilsnum'].data()
72  cmslsnum=summarycursor.currentRow()['cmslsnum'].data()
73  instlumi=summarycursor.currentRow()['instlumi'].data()
74  instlumierror=summarycursor.currentRow()['instlumierror'].data()
75  instlumiquality=summarycursor.currentRow()['instlumiquality'].data()
76  (uncalibratedinstlumi,uncalibratedinstlumierror)=uncalibrateLumi(runnumber,instlumi,instlumierror)
77  numorbit=summarycursor.currentRow()['numorbit'].data()
78  startorbit=summarycursor.currentRow()['startorbit'].data()
79  beamenergy=summarycursor.currentRow()['beamenergy'].data()
80  beamstatus=summarycursor.currentRow()['beamstatus'].data()
81  cmsbxindexblob=None
82  if not summarycursor.currentRow()['cmsbxindexblob'].isNull():
83  cmsbxindexblob=summarycursor.currentRow()['cmsbxindexblob'].data()
84  beamintensityblob_1=None
85  if not summarycursor.currentRow()['beamintensityblob_1'].isNull():
86  beamintensityblob_1=summarycursor.currentRow()['beamintensityblob_1'].data()
87  beamintensityblob_2=None
88  if not summarycursor.currentRow()['beamintensityblob_2'].isNull():
89  beamintensityblob_2=summarycursor.currentRow()['beamintensityblob_2'].data()
90  datadict[lumilsnum]=[cmslsnum,uncalibratedinstlumi,uncalibratedinstlumierror,instlumiquality,beamstatus,beamenergy,numorbit,startorbit,cmsbxindexblob,beamintensityblob_1,beamintensityblob_2]
91  del summaryQuery
92  #print datadict
93  for algoname in ['OCC1','OCC2','ET']:
94  detailQuery=lumischema.newQuery()
95  detailQuery.addToTableList( nameDealer.lumisummaryTableName(),'s' )
96  detailQuery.addToTableList( nameDealer.lumidetailTableName(),'d' )
97  detailQuery.addToOutputList('s.LUMILSNUM','lumilsnum' )
98  detailQuery.addToOutputList('d.BXLUMIVALUE','bxlumivalue' )
99  detailQuery.addToOutputList('d.BXLUMIERROR','bxlumierror' )
100  detailQuery.addToOutputList('d.BXLUMIQUALITY','bxlumiquality' )
101  detailCondition=coral.AttributeList()
102  detailCondition.extend('runnumber','unsigned int')
103  detailCondition.extend('algoname','string')
104  detailCondition['runnumber'].setData(int(runnumber))
105  detailCondition['algoname'].setData(algoname)
106  detailResult=coral.AttributeList()
107  detailResult.extend('lumilsnum','unsigned int')
108  detailResult.extend('bxlumivalue','blob')
109  detailResult.extend('bxlumierror','blob')
110  detailResult.extend('bxlumiquality','blob')
111  detailQuery.defineOutput(detailResult)
112  detailQuery.addToOrderList('lumilsnum')
113  detailQuery.setCondition('s.RUNNUM=:runnumber AND s.LUMISUMMARY_ID=d.LUMISUMMARY_ID AND d.ALGONAME=:algoname',detailCondition)
114  detailcursor=detailQuery.execute()
115  while next(detailcursor):
116  lumilsnum=detailcursor.currentRow()['lumilsnum'].data()
117  bxlumivalue=detailcursor.currentRow()['bxlumivalue'].data()
118  bxlumierror=detailcursor.currentRow()['bxlumierror'].data()
119  bxlumiquality=detailcursor.currentRow()['bxlumiquality'].data()
120  datadict[lumilsnum].extend([bxlumivalue,bxlumierror,bxlumiquality])
121  del detailQuery
122  session.transaction().commit()
123  return datadict
124  except :
125  raise
126 def hltFromOldLumi(session,runnumber):
127  '''
128  select count(distinct pathname) from hlt where runnum=:runnum
129  select cmslsnum,pathname,inputcount,acceptcount,prescale from hlt where runnum=:runnum order by cmslsnum,pathname
130  [pathnames,databuffer]
131  databuffer: {cmslsnum:[inputcountBlob,acceptcountBlob,prescaleBlob]}
132  '''
133  try:
134  databuffer={}
135  session.transaction().start(True)
136  lumischema=session.nominalSchema()
137  npath=0
138  qHandle=lumischema.newQuery()
139  qHandle.addToTableList( nameDealer.hltTableName() )
140  qHandle.addToOutputList('COUNT(DISTINCT PATHNAME)','npath')
141  qCondition=coral.AttributeList()
142  qCondition.extend('runnum','unsigned int')
143  qCondition['runnum'].setData(int(runnumber))
144  qResult=coral.AttributeList()
145  qResult.extend('npath','unsigned int')
146  qHandle.defineOutput(qResult)
147  qHandle.setCondition('RUNNUM=:runnum',qCondition)
148  cursor=qHandle.execute()
149  while next(cursor):
150  npath=cursor.currentRow()['npath'].data()
151  del qHandle
152  #print 'npath ',npath
153 
154  qHandle=lumischema.newQuery()
155  qHandle.addToTableList( nameDealer.hltTableName() )
156  qHandle.addToOutputList('CMSLSNUM','cmslsnum')
157  qHandle.addToOutputList('PATHNAME','pathname')
158  qHandle.addToOutputList('INPUTCOUNT','inputcount')
159  qHandle.addToOutputList('ACCEPTCOUNT','acceptcount')
160  qHandle.addToOutputList('PRESCALE','prescale')
161  qCondition=coral.AttributeList()
162  qCondition.extend('runnum','unsigned int')
163  qCondition['runnum'].setData(int(runnumber))
164  qResult=coral.AttributeList()
165  qResult.extend('cmslsnum','unsigned int')
166  qResult.extend('pathname','string')
167  qResult.extend('inputcount','unsigned int')
168  qResult.extend('acceptcount','unsigned int')
169  qResult.extend('prescale','unsigned int')
170  qHandle.defineOutput(qResult)
171  qHandle.setCondition('RUNNUM=:runnum',qCondition)
172  qHandle.addToOrderList('cmslsnum')
173  qHandle.addToOrderList('pathname')
174  cursor=qHandle.execute()
175  pathnameList=[]
176  inputcountArray=array.array('I')
177  acceptcountArray=array.array('I')
178  prescaleArray=array.array('I')
179  ipath=0
180  pathnHLT_PixelTracksVdMames=''
181  while next(cursor):
182  cmslsnum=cursor.currentRow()['cmslsnum'].data()
183  pathname=cursor.currentRow()['pathname'].data()
184  ipath+=1
185  inputcount=cursor.currentRow()['inputcount'].data()
186  acceptcount=cursor.currentRow()['acceptcount'].data()
187  prescale=cursor.currentRow()['prescale'].data()
188  pathnameList.append(pathname)
189  inputcountArray.append(inputcount)
190  acceptcountArray.append(acceptcount)
191  prescaleArray.append(prescale)
192  if ipath==npath:
193  if cmslsnum==1:
194  pathnames=','.join(pathnameList)
195  inputcountBlob=CommonUtil.packArraytoBlob(inputcountArray)
196  acceptcountBlob=CommonUtil.packArraytoBlob(acceptcountArray)
197  prescaleBlob=CommonUtil.packArraytoBlob(prescaleArray)
198  databuffer[cmslsnum]=[inputcountBlob,acceptcountBlob,prescaleBlob]
199  pathnameList=[]
200  inputcountArray=array.array('I')
201  acceptcountArray=array.array('I')
202  prescaleArray=array.array('I')
203  ipath=0
204  del qHandle
205  session.transaction().commit()
206  #print 'pathnames ',pathnames
207  return [pathnames,databuffer]
208  except :
209  raise
210 
211 def trgFromOldLumi(session,runnumber):
212  '''
213  select bitnum,bitname from trg where runnum=:runnumber and cmslsnum=1 order by bitnum
214  select cmslsnum,deadtime,trgcount,prescale from trg where bitnum=:bitnum and runnum=:runnumber
215  input: runnumber
216  output: [bitnames,{cmslsnum,[deadtime,bitzerocount,bitzerpoprescale,trgcountBlob,trgprescaleBlob]}]
217  '''
218  session.transaction().start(True)
219  lumischema=session.nominalSchema()
220  qHandle=lumischema.newQuery()
221  try:
222  qHandle=lumischema.newQuery()
223  qHandle.addToTableList(nameDealer.trgTableName())
224  qHandle.addToOutputList('BITNUM','bitnum')
225  qHandle.addToOutputList('BITNAME','bitname')
226  qCondition=coral.AttributeList()
227  qCondition.extend('runnum','unsigned int')
228  qCondition['runnum'].setData(int(runnumber))
229  qCondition.extend('cmslsnum','unsigned int')
230  qCondition['cmslsnum'].setData(int(1))
231  qResult=coral.AttributeList()
232  qResult.extend('bitnum','unsigned int')
233  qResult.extend('bitname','string')
234  qHandle.defineOutput(qResult)
235  qHandle.setCondition('RUNNUM=:runnum AND CMSLSNUM=:cmslsnum',qCondition)
236  qHandle.addToOrderList('BITNUM')
237  cursor=qHandle.execute()
238  bitnums=[]
239  bitnameList=[]
240  while next(cursor):
241  bitnum=cursor.currentRow()['bitnum'].data()
242  bitname=cursor.currentRow()['bitname'].data()
243  bitnums.append(bitnum)
244  bitnameList.append(bitname)
245  del qHandle
246  bitnames=','.join(bitnameList)
247  databuffer={}
248  nbits=len(bitnums)
249  qHandle=lumischema.newQuery()
250  qHandle.addToTableList(nameDealer.trgTableName())
251  qHandle.addToOutputList('CMSLSNUM','cmslsnum')
252  qHandle.addToOutputList('BITNUM','bitnum')
253  qHandle.addToOutputList('DEADTIME','deadtime')
254  qHandle.addToOutputList('TRGCOUNT','trgcount')
255  qHandle.addToOutputList('PRESCALE','prescale')
256  qCondition=coral.AttributeList()
257  qCondition.extend('runnum','unsigned int')
258  qCondition['runnum'].setData(int(runnumber))
259  qResult=coral.AttributeList()
260  qResult.extend('cmslsnum','unsigned int')
261  qResult.extend('bitnum','unsigned int')
262  qResult.extend('deadtime','unsigned long long')
263  qResult.extend('trgcount','unsigned int')
264  qResult.extend('prescale','unsigned int')
265  qHandle.defineOutput(qResult)
266  qHandle.setCondition('RUNNUM=:runnum',qCondition)
267  qHandle.addToOrderList('CMSLSNUM')
268  qHandle.addToOrderList('BITNUM')
269  cursor=qHandle.execute()
270  trgcountArray=array.array('I')
271  prescaleArray=array.array('I')
272  while next(cursor):
273  cmslsnum=cursor.currentRow()['cmslsnum'].data()
274  bitnum=cursor.currentRow()['bitnum'].data()
275  deadtime=cursor.currentRow()['deadtime'].data()
276  trgcount=cursor.currentRow()['trgcount'].data()
277  prescale=cursor.currentRow()['prescale'].data()
278  if cmslsnum not in databuffer:
279  databuffer[cmslsnum]=[]
280  databuffer[cmslsnum].append(deadtime)
281  if bitnum==0:
282  databuffer[cmslsnum].append(trgcount)
283  databuffer[cmslsnum].append(prescale)
284  trgcountArray.append(trgcount)
285  prescaleArray.append(prescale)
286  if bitnum==nbits-1:
287  trgcountBlob=CommonUtil.packArraytoBlob(trgcountArray)
288  prescaleBlob=CommonUtil.packArraytoBlob(prescaleArray)
289  databuffer[cmslsnum].append(trgcountBlob)
290  databuffer[cmslsnum].append(prescaleBlob)
291  trgcountArray=array.array('I')
292  prescaleArray=array.array('I')
293  del qHandle
294  session.transaction().commit()
295  return [bitnames,databuffer]
296  except:
297  del qHandle
298  raise
299 
300 def trgFromWBM(session,runnumber):
301  '''
302  '''
303  pass
304 
305 def trgFromNewGT(session,runnumber):
306  '''
307  select counts,lsnr,algobit from cms_gt_mon.gt_mon_trig_algo_view where runnr=:runnumber order by lsnr,algobit
308  select counts,lsnr,techbit from cms_gt_mon.gt_mon_trig_tech_view where runnr=:runnumber order by lsnr,techbit
309  select counts,lsnr from cms_gt_mon.gt_mon_trig_dead_view where runnr=:runnumber and deadcounter=:countername order by lsnr
310  select algo_index,alias from cms_gt.gt_run_algo_view where runnumber=:runnumber order by algo_index
311  select techtrig_index,name from cms_gt.gt_run_tech_view where runnumber=:runnumber order by techtrig_index
312  select prescale_factor_algo_000,prescale_factor_algo_001..._127 from cms_gt.gt_run_presc_algo_view where runnr=:runnumber and prescale_index=0;
313  select prescale_factor_tt_000,prescale_factor_tt_001..._63 from cms_gt.gt_run_presc_tech_view where runnr=:runnumber and prescale_index=0;
314  '''
315  pass
316 
317 def trgFromOldGT(session,runnumber):
318  '''
319  input: runnumber
320  output: [bitnameclob,{cmslsnum:[deadtime,bitzerocount,bitzeroprescale,trgcountBlob,trgprescaleBlob]}]
321  1. select counts,lsnr from cms_gt_mon.gt_mon_trig_dead_view where runnr=:runnumber and deadcounter=:countername order by lsnr
322  2. select counts,lsnr,algobit from cms_gt_mon.gt_mon_trig_algo_view where runnr=:runnumber order by lsnr,algobit
323  3. select counts,lsnr,techbit from cms_gt_mon.gt_mon_trig_tech_view where runnr=:runnumber order by lsnr,techbit
324  4. select algo_index,alias from cms_gt.gt_run_algo_view where runnumber=:runnumber order by algo_index
325  ## not needed5. select techtrig_index,name from cms_gt.gt_run_tech_view where runnumber=:runnumber order by techtrig_index
326  5 select distinct(prescale_index) from cms_gt_mon.lumi_sections where run_number=:runnumber;
327  6. select prescale_factor_algo_000,algo.prescale_factor_algo_001..._127 from cms_gt.gt_run_presc_algo_view where prescale_index=:prescale_index and runnr=:runnumber;
328  7. select prescale_factor_tt_000,tech.prescale_factor_tt_001..._63 from cms_gt.gt_run_presc_tech_view where prescale_index=:prescale_index and runnr=:runnumber;
329  8. select lumi_section,prescale_index from cms_gt_mon.lumi_sections where run_number=:runnumber order by lumi_section
330 
331  '''
332  result=[]
333  deadtimeresult={}#{cmslsnum:deadtime}
334  NAlgoBit=128 #0-127
335  NTechBit=64 #0-63
336  algocount={}#{cmslsnum:[algocounts]}
337  techcount={}#{cmslsnum:[techcounts]}
338  bitnames=[]
339  bitzerocountDict={}
340  bitzeroprescaleDict={}
341  perlsdict={}#{cmslsnum:[deadtime,bitzerocount,bitzeroprescale,trgcountBlob,trgprescaleBlob]}
342  prescaleDict={} #{prescale_index:[[algo_prescale_factors][tech_prescale_factors]]}
343  prescaleResult={}#{lsnumber:[algo_prescale_factors,tech_prescale_factors]}
344  try:
345  session.transaction().start(True)
346  gtmonschema=session.schema('CMS_GT_MON')
347  #
348  # select counts,lsnr from cms_gt_mon.gt_mon_trig_dead_view where runnr=:runnumber and deadcounter=:countername order by lsnr
349  #
350  deadviewQuery=gtmonschema.newQuery()
351  deadviewQuery.addToTableList('GT_MON_TRIG_DEAD_VIEW')
352  deadOutput=coral.AttributeList()
353  deadOutput.extend('counts','unsigned int')
354  deadOutput.extend('lsnr','unsigned int')
355  deadviewQuery.addToOutputList('counts')
356  deadviewQuery.addToOutputList('lsnr')
357  bindVariablesDead=coral.AttributeList()
358  bindVariablesDead.extend('runnumber','int')
359  bindVariablesDead.extend('countername','string')
360  bindVariablesDead['runnumber'].setData(int(runnumber))
361  bindVariablesDead['countername'].setData('DeadtimeBeamActive')
362  deadviewQuery.setCondition('RUNNR=:runnumber AND DEADCOUNTER=:countername',bindVariablesDead)
363  deadviewQuery.addToOrderList('lsnr')
364  deadviewQuery.defineOutput(deadOutput)
365  deadcursor=deadviewQuery.execute()
366  s=0
367  while next(deadcursor):
368  row=deadcursor.currentRow()
369  s+=1
370  lsnr=row['lsnr'].data()
371  while s!=lsnr:
372  print('DEADTIME alert: found hole in LS range')
373  print(' fill deadtimebeamactive 0 for LS '+str(s))
374  deadtimeresult[s]=0
375  s+=1
376  count=row['counts'].data()
377  deadtimeresult[s]=count
378  if s==0:
379  deadcursor.close()
380  del deadviewQuery
381  session.transaction().commit()
382  raise 'requested run '+str(runnumber )+' does not exist for deadcounts'
383  del deadviewQuery
384  #print 'deadtimeresult ',deadtimeresult
385  mybitcount_algo=[]
386  algoviewQuery=gtmonschema.newQuery()
387  #
388  # select counts,lsnr,algobit from cms_gt_mon.gt_mon_trig_algo_view where runnr=:runnumber order by lsnr,algobit
389  #
390  algoviewQuery.addToTableList('GT_MON_TRIG_ALGO_VIEW')
391  algoOutput=coral.AttributeList()
392  algoOutput.extend('counts','unsigned int')
393  algoOutput.extend('lsnr','unsigned int')
394  algoOutput.extend('algobit','unsigned int')
395  algoviewQuery.addToOutputList('counts')
396  algoviewQuery.addToOutputList('lsnr')
397  algoviewQuery.addToOutputList('algobit')
398  algoCondition=coral.AttributeList()
399  algoCondition.extend('runnumber','unsigned int')
400  algoCondition['runnumber'].setData(int(runnumber))
401  algoviewQuery.setCondition('RUNNR=:runnumber',algoCondition)
402  algoviewQuery.addToOrderList('lsnr')
403  algoviewQuery.addToOrderList('algobit')
404  algoviewQuery.defineOutput(algoOutput)
405 
406  algocursor=algoviewQuery.execute()
407  s=0
408  while next(algocursor):
409  row=algocursor.currentRow()
410  lsnr=row['lsnr'].data()
411  counts=row['counts'].data()
412  algobit=row['algobit'].data()
413  mybitcount_algo.append(counts)
414  if algobit==0:
415  bitzerocountDict[lsnr]=counts
416  if algobit==NAlgoBit-1:
417  s+=1
418  while s!=lsnr:
419  print('ALGO COUNT alert: found hole in LS range')
420  print(' fill all algocount 0 for LS '+str(s))
421  tmpzero=[0]*NAlgoBit
422  algocount[s]=tmpzero
423  s+=1
424  algocount[s]=mybitcount_algo
425  mybitcount_algo=[]
426  if s==0:
427  algocursor.close()
428  del algoviewQuery
429  session.transaction().commit()
430  raise 'requested run '+str(runnumber+' does not exist for algocounts ')
431  del algoviewQuery
432 
433  mybitcount_tech=[]
434  techviewQuery=gtmonschema.newQuery()
435  techviewQuery.addToTableList('GT_MON_TRIG_TECH_VIEW')
436  #
437  # select counts,lsnr,techbit from cms_gt_mon.gt_mon_trig_tech_view where runnr=:runnumber order by lsnr,techbit
438  #
439  techOutput=coral.AttributeList()
440  techOutput.extend('counts','unsigned int')
441  techOutput.extend('lsnr','unsigned int')
442  techOutput.extend('techbit','unsigned int')
443  techviewQuery.addToOutputList('COUNTS','counts')
444  techviewQuery.addToOutputList('LSNR','lsnr')
445  techviewQuery.addToOutputList('TECHBIT','techbit')
446  techCondition=coral.AttributeList()
447  techCondition.extend('runnumber','unsigned int')
448  techCondition['runnumber'].setData(int(runnumber))
449  techviewQuery.setCondition('RUNNR=:runnumber',techCondition)
450  techviewQuery.addToOrderList('lsnr')
451  techviewQuery.addToOrderList('techbit')
452  techviewQuery.defineOutput(techOutput)
453 
454  techcursor=techviewQuery.execute()
455  s=0
456  while next(techcursor):
457  row=techcursor.currentRow()
458  lsnr=row['lsnr'].data()
459  counts=row['counts'].data()
460  techbit=row['techbit'].data()
461  mybitcount_tech.append(counts)
462  if techbit==NTechBit-1:
463  s+=1
464  while s!=lsnr:
465  print('TECH COUNT alert: found hole in LS range')
466  print(' fill all techcount 0 for LS '+str(s))
467  tmpzero=[0]*NTechBit
468  techcount[s]=tmpzero
469  s+=1
470  techcount[s]=mybitcount_tech
471  mybitcount_tech=[]
472  if s==0:
473  techcursor.close()
474  del techviewQuery
475  session.transaction().commit()
476  raise 'requested run '+str(runnumber+' does not exist for techcounts ')
477  del techviewQuery
478 
479  gtschema=session.schema('CMS_GT')
480  triggernamemap={}
481  namealiasQuery=gtschema.newQuery()
482  #
483  # select algo_index,alias from cms_gt.gt_run_algo_view where runnumber=:runnumber
484  #
485  triggernamemap={}
486  namealiasQuery.addToTableList('GT_RUN_ALGO_VIEW')
487  algonameOutput=coral.AttributeList()
488  algonameOutput.extend('algo_index','unsigned int')
489  algonameOutput.extend('alias','string')
490  namealiasQuery.addToOutputList('algo_index')
491  namealiasQuery.addToOutputList('alias')
492  algonameCondition=coral.AttributeList()
493  algonameCondition.extend('runnumber','unsigned int')
494  algonameCondition['runnumber'].setData(int(runnumber))
495  namealiasQuery.setCondition('RUNNUMBER=:runnumber',algonameCondition)
496  namealiasQuery.defineOutput(algonameOutput)
497  algonamecursor=namealiasQuery.execute()
498  while next(algonamecursor):
499  row=algonamecursor.currentRow()
500  algo_index=row['algo_index'].data()
501  algo_name=row['alias'].data()
502  triggernamemap[algo_index]=algo_name
503  del namealiasQuery
504 
505  #techtriggernamemap={}
506  #technamealiasQuery=gtschema.newQuery()
507  #
508  # select techtrig_index,name from cms_gt.gt_run_tech_view where runnumber=:runnumber
509  #
510  # this queryis unnecessary
511  #technamealiasQuery.addToTableList('GT_RUN_TECH_VIEW')
512  #technameOutput=coral.AttributeList()
513  #technameOutput.extend('techtrig_index','unsigned int')
514  #technameOutput.extend('name','string')
515  #technamealiasQuery.addToOutputList('techtrig_index')
516  #technamealiasQuery.addToOutputList('name')
517  #technameCondition=coral.AttributeList()
518  #technameCondition.extend('runnumber','unsigned int')
519  #technameCondition['runnumber'].setData(int(runnumber))
520  #technamealiasQuery.setCondition('RUNNUMBER=:runnumber',technameCondition)
521  #technamealiasQuery.defineOutput(technameOutput)
522  #technamecursor=technamealiasQuery.execute()
523  #while technamecursor.next():
524  #row=technamecursor.currentRow()
525  #techtrig_index=row['techtrig_index'].data()
526  #tech_name=row['name'].data()
527  #techtriggernamemap[techtrig_index]=tech_name
528  #del technamealiasQuery
529  #
530  # reprocess Algo name result filling unallocated trigger bit with string "False"
531  #
532  for algoidx in range(NAlgoBit):
533  if algoidx in triggernamemap.keys():
534  bitnames.append(triggernamemap[algoidx])
535  else:
536  bitnames.append('False')
537  #
538  # reprocess Tech name
539  #
540  for techidx in range(NTechBit):
541  bitnames.append(str(techidx))
542  bitnameclob=','.join(bitnames)
543  #
544  # select distinct(prescale_index) from cms_gt_mon.lumi_sections where run_number=:runnumber;
545  #
546  prescaleidx=[]
547  presidxQuery=gtmonschema.newQuery()
548  presidxQuery.addToTableList('LUMI_SECTIONS')
549 
550  presidxBindVariable=coral.AttributeList()
551  presidxBindVariable.extend('runnumber','int')
552  presidxBindVariable['runnumber'].setData(int(runnumber))
553 
554  presidxOutput=coral.AttributeList()
555  presidxOutput.extend('prescale_index','int')
556  presidxQuery.addToOutputList('distinct(PRESCALE_INDEX)','prescale_index')
557  presidxQuery.defineOutput(presidxOutput)
558  presidxQuery.setCondition('RUN_NUMBER=:runnumber',presidxBindVariable)
559  presidxCursor=presidxQuery.execute()
560  while next(presidxCursor):
561  presc=presidxCursor.currentRow()['prescale_index'].data()
562  prescaleidx.append(presc)
563  #print prescaleidx
564  del presidxQuery
565  #
566  # select algo.prescale_factor_algo_000,,algo.prescale_factor_algo_001..._127 from gt_run_presc_algo_view where run_number=:runnumber and prescale_index=:prescale_index;
567  #
568  for prescaleindex in prescaleidx:
569  algoprescQuery=gtschema.newQuery()
570  algoprescQuery.addToTableList('GT_RUN_PRESC_ALGO_VIEW')
571  algoPrescOutput=coral.AttributeList()
572  algoprescBase='PRESCALE_FACTOR_ALGO_'
573  for bitidx in range(NAlgoBit):
574  algopresc=algoprescBase+str(bitidx).zfill(3)
575  algoPrescOutput.extend(algopresc,'unsigned int')
576  algoprescQuery.addToOutputList(algopresc)
577  PrescbindVariable=coral.AttributeList()
578  PrescbindVariable.extend('runnumber','int')
579  PrescbindVariable.extend('prescaleindex','int')
580  PrescbindVariable['runnumber'].setData(int(runnumber))
581  PrescbindVariable['prescaleindex'].setData(prescaleindex)
582  algoprescQuery.setCondition('RUNNR=:runnumber AND PRESCALE_INDEX=:prescaleindex',PrescbindVariable)
583  algoprescQuery.defineOutput(algoPrescOutput)
584  algopresccursor=algoprescQuery.execute()
585  while next(algopresccursor):
586  row=algopresccursor.currentRow()
587  algoprescale=[]
588  for bitidx in range(NAlgoBit):
589  algopresc=algoprescBase+str(bitidx).zfill(3)
590  algoprescale.append(row[algopresc].data())
591  prescaleDict[prescaleindex]=algoprescale
592  del algoprescQuery
593 
594  #
595  # select prescale_factor_tt_000,prescale_factor_tt_001..._127 from gt_run_presc_tech_view where run_number=:runnumber and prescale_index=:prescale_index;
596  #
597  for prescaleindex in prescaleidx:
598  techprescQuery=gtschema.newQuery()
599  techprescQuery.addToTableList('GT_RUN_PRESC_TECH_VIEW')
600  techPrescOutput=coral.AttributeList()
601  techprescBase='PRESCALE_FACTOR_TT_'
602  for bitidx in range(NTechBit):
603  techpresc=techprescBase+str(bitidx).zfill(3)
604  techPrescOutput.extend(techpresc,'unsigned int')
605  techprescQuery.addToOutputList(techpresc)
606  PrescbindVariable=coral.AttributeList()
607  PrescbindVariable.extend('runnumber','int')
608  PrescbindVariable.extend('prescaleindex','int')
609  PrescbindVariable['runnumber'].setData(int(runnumber))
610  PrescbindVariable['prescaleindex'].setData(prescaleindex)
611  techprescQuery.setCondition('RUNNR=:runnumber AND PRESCALE_INDEX=:prescaleindex',PrescbindVariable)
612  techprescQuery.defineOutput(techPrescOutput)
613  techpresccursor=techprescQuery.execute()
614  while next(techpresccursor):
615  row=techpresccursor.currentRow()
616  techprescale=[]
617  for bitidx in range(NTechBit):
618  techpresc=techprescBase+str(bitidx).zfill(3)
619  techprescale.append(row[techpresc].data())
620  prescaleDict[prescaleindex]+=techprescale
621  del techprescQuery
622  #print prescaleDict
623  #
624  #select lumi_section,prescale_index from cms_gt_mon.lumi_sections where run_number=:runnumber
625  #
626  lumiprescQuery=gtmonschema.newQuery()
627  lumiprescQuery.addToTableList('LUMI_SECTIONS')
628 
629  lumiprescBindVariable=coral.AttributeList()
630  lumiprescBindVariable.extend('runnumber','int')
631  lumiprescBindVariable['runnumber'].setData(int(runnumber))
632 
633  lumiprescOutput=coral.AttributeList()
634  lumiprescOutput.extend('lumisection','int')
635  lumiprescOutput.extend('prescale_index','int')
636  lumiprescQuery.addToOutputList('LUMI_SECTION')
637  lumiprescQuery.addToOutputList('PRESCALE_INDEX')
638  lumiprescQuery.defineOutput(lumiprescOutput)
639  lumiprescQuery.setCondition('RUN_NUMBER=:runnumber',lumiprescBindVariable)
640  lumiprescCursor=lumiprescQuery.execute()
641  while next(lumiprescCursor):
642  row=lumiprescCursor.currentRow()
643  lumisection=row['lumisection'].data()
644  psindex=row['prescale_index'].data()
645  bitzeroprescale=prescaleDict[psindex][0]
646  bitzeroprescaleDict[lumisection]=prescaleDict[psindex][0]
647  prescaleResult[lumisection]=prescaleDict[psindex]
648  #print prescaleResult
649  del lumiprescQuery
650  #return result
651  session.transaction().commit()
652  #
653  #assemble result
654  #
655  for cmslsnum,deadcount in deadtimeresult.items():
656  bitzerocount=bitzerocountDict[cmslsnum]
657  bitzeroprescale=bitzeroprescaleDict[cmslsnum]
658  trgcounts=array.array('I')
659  for acounts in algocount[cmslsnum]:
660  trgcounts.append(acounts)
661  for tcounts in techcount[cmslsnum]:
662  trgcounts.append(tcounts)
663  trgcountBlob=CommonUtil.packArraytoBlob(trgcounts)
664  trgprescale=array.array('I')
665  for aprescale in prescaleResult[cmslsnum]:
666  trgprescale.append(aprescale)
667  trgprescaleBlob=CommonUtil.packArraytoBlob(trgprescale)
668  perlsdict[cmslsnum]=[deadcount,bitzerocount,bitzeroprescale,trgcountBlob,trgprescaleBlob]
669  result=[bitnameclob,perlsdict]
670  return result
671  except:
672  session.transaction().rollback()
673  del session
674  raise
675 
676 def hltFromRuninfoV2(session,runnumber):
677  '''
678  input:
679  output: [pathnameclob,{cmslsnum:[inputcountBlob,acceptcountBlob,prescaleBlob]}]
680  select count(distinct PATHNAME) as npath from HLT_SUPERVISOR_LUMISECTIONS_V2 where runnr=:runnumber and lsnumber=1;
681  select l.pathname,l.lsnumber,l.l1pass,l.paccept,m.psvalue from hlt_supervisor_lumisections_v2 l,hlt_supervisor_scalar_map m where l.runnr=m.runnr and l.psindex=m.psindex and l.pathname=m.pathname and l.runnr=:runnumber order by l.lsnumber
682  '''
683  npaths=0
684  pathnames=[]
685  hltdict={}
686  try:
687  session.transaction().start(True)
688  hltschema=session.schema('CMS_RUNINFO')
689  bvar=coral.AttributeList()
690  bvar.extend('runnumber','unsigned int')
691  bvar.extend('lsnumber','unsigned int')
692  bvar['runnumber'].setData(int(runnumber))
693  bvar['lsnumber'].setData(1)
694  q1=hltschema.newQuery()
695  q1.addToTableList('HLT_SUPERVISOR_LUMISECTIONS_V2')
696  nls=coral.AttributeList()
697  nls.extend('npath','unsigned int')
698  q1.addToOutputList('count(distinct PATHNAME)','npath')
699  q1.setCondition('RUNNR=:runnumber AND LSNUMBER=:lsnumber',bvar)
700  q1.defineOutput(nls)
701  c=q1.execute()
702  while next(c):
703  npath=c.currentRow()['npath'].data()
704  del q1
705  if npath==0:
706  print('request run is empty, do nothing')
707 
708  q=hltschema.newQuery()
709  bindVar=coral.AttributeList()
710  bindVar.extend('runnumber','unsigned int')
711  bindVar['runnumber'].setData(int(runnumber))
712  q.addToTableList('HLT_SUPERVISOR_LUMISECTIONS_V2','l')
713  q.addToTableList('HLT_SUPERVISOR_SCALAR_MAP','m')
714  q.addToOutputList('l.LSNUMBER','lsnumber')
715  q.addToOutputList('l.PATHNAME','pathname')
716  q.addToOutputList('l.L1PASS','hltinput')
717  q.addToOutputList('l.PACCEPT','hltaccept')
718  q.addToOutputList('m.PSVALUE','prescale')
719  q.setCondition('l.RUNNR=m.RUNNR and l.PSINDEX=m.PSINDEX and l.PATHNAME=m.PATHNAME and l.RUNNR=:runnumber',bindVar)
720  q.addToOrderList('l.LSNUMBER')
721  q.addToOrderList('l.PATHNAME')
722  q.setRowCacheSize(10692)
723  cursor=q.execute()
724  lastLumiSection=1
725  currentLumiSection=0
726  allpaths=[]
727  ipath=0
728  hltinputs=array.array('I')
729  hltaccepts=array.array('I')
730  prescales=array.array('I')
731  while next(cursor):
732  row=cursor.currentRow()
733  cmsluminr=row['lsnumber'].data()
734  hltinput=row['hltinput'].data()
735  hltaccept=row['hltaccept'].data()
736  prescale=row['prescale'].data()
737  pathname=row['pathname'].data()
738  ipath+=1
739  if cmsluminr==1:
740  pathnames.append(pathname)
741  if cmsluminr not in hltdict:
742  hltdict[cmsluminr]=[]
743  hltinputs.append(hltinput)
744  hltaccepts.append(hltaccept)
745  prescales.append(prescale)
746  if ipath==npath:
747  #pack
748  #print 'packing hltinputs ',hltinputs
749  hltinputsBlob=CommonUtil.packArraytoBlob(hltinputs)
750  #print 'packing hltaccepts ',hltaccepts
751  hltacceptsBlob=CommonUtil.packArraytoBlob(hltaccepts)
752  #print 'packing prescales ',prescales
753  prescalesBlob=CommonUtil.packArraytoBlob(prescales)
754  hltdict[cmsluminr].extend([hltinputsBlob,hltacceptsBlob,hltacceptsBlob])
755  ipath=0
756  hltinputs=array.array('I')
757  hltaccepts=array.array('I')
758  prescales=array.array('I')
759  pathnameclob=','.join(pathnames)
760  del q
761  session.transaction().commit()
762  return [pathnameclob,hltdict]
763  except:
764  raise
765 
766 def hltFromRuninfoV3(session,runnumber):
767  '''
768  input:
769  output: [datasource,pathnameclob,{cmslsnum:[inputcountBlob,acceptcountBlob,prescaleBlob]}]
770  select distinct(pathid) from HLT_SUPERVISOR_TRIGGERPATHS where runnnumber=:runnumber;
771  select count(*) from HLT_SUPERVISOR_LUMISECTIONS_V3 where runnumber=:runnumber;//total ls
772  select tr.runnumber,tr.lsnumber,tr.pathid,tr.l1pass,tr.paccept,ls.psindex,sm.psvalue from hlt_supervisor_triggerpaths tr,hlt_supervisor_lumisections_v3 ls,hlt_supervisor_scalar_map_v2 sm where tr.runnumber=ls.runnumber and tr.lsnumber=ls.lsnumber and sm.runnumber=tr.runnumber and sm.pathid=tr.pathid and sm.psindex=ls.psindex and tr.runnumber=:runnumber order by tr.lsnumber;
773  loop :
774  select pathname from cms_hlt.paths where pathid=:pathid
775  '''
776  pass
777 
778 def hltconf(session,hltkey):
779  '''
780  select paths.pathid,paths.name,stringparamvalues.value from stringparamvalues,paths,parameters,superidparameterassoc,modules,moduletemplates,pathmoduleassoc,configurationpathassoc,configurations where parameters.paramid=stringparamvalues.paramid and superidparameterassoc.paramid=parameters.paramid and modules.superid=superidparameterassoc.superid and moduletemplates.superid=modules.templateid and pathmoduleassoc.moduleid=modules.superid and paths.pathid=pathmoduleassoc.pathid and configurationpathassoc.pathid=paths.pathid and configurations.configid=configurationpathassoc.configid and moduletemplates.name='HLTLevel1GTSeed' and parameters.name='L1SeedsLogicalExpression' and configurations.configdescriptor=:hlt_description;
781  select paths.pathid,paths.name,stringparamvalues.value from stringparamvalues,paths,parameters,superidparameterassoc,modules,moduletemplates,pathmoduleassoc,configurationpathassoc,configurations where parameters.paramid=stringparamvalues.paramid and superidparameterassoc.paramid=parameters.paramid and modules.superid=superidparameterassoc.superid and moduletemplates.superid=modules.templateid and pathmoduleassoc.moduleid=modules.superid and paths.pathid=pathmoduleassoc.pathid and configurationpathassoc.pathid=paths.pathid and configurations.configid=configurationpathassoc.configid and moduletemplates.name='HLTLevel1GTSeed' and parameters.name='L1SeedsLogicalExpression' and configurations.configid=:hlt_numkey;
782  ##select paths.pathid from cms_hlt.paths paths,cms_hlt.configurations config where config.configdescriptor=' ' and name=:pathname
783  '''
784  try:
785  session.transaction().start(True)
786  hltconfschema=session.nominalSchema()
787  hltconfQuery=hltconfschema.newQuery()
788 
789  hltconfQuery.addToOutputList('PATHS.NAME','hltpath')
790  hltconfQuery.addToOutputList('STRINGPARAMVALUES.VALUE','l1expression')
791 
792  hltconfQuery.addToTableList('PATHS')
793  hltconfQuery.addToTableList('STRINGPARAMVALUES')
794  hltconfQuery.addToTableList('PARAMETERS')
795  hltconfQuery.addToTableList('SUPERIDPARAMETERASSOC')
796  hltconfQuery.addToTableList('MODULES')
797  hltconfQuery.addToTableList('MODULETEMPLATES')
798  hltconfQuery.addToTableList('PATHMODULEASSOC')
799  hltconfQuery.addToTableList('CONFIGURATIONPATHASSOC')
800  hltconfQuery.addToTableList('CONFIGURATIONS')
801 
802  hltconfBindVar=coral.AttributeList()
803  hltconfBindVar.extend('hltseed','string')
804  hltconfBindVar.extend('l1seedexpr','string')
805  hltconfBindVar.extend('hltkey','string')
806  hltconfBindVar['hltseed'].setData('HLTLevel1GTSeed')
807  hltconfBindVar['l1seedexpr'].setData('L1SeedsLogicalExpression')
808  hltconfBindVar['hltkey'].setData(hltkey)
809  hltconfQuery.setCondition('PARAMETERS.PARAMID=STRINGPARAMVALUES.PARAMID AND SUPERIDPARAMETERASSOC.PARAMID=PARAMETERS.PARAMID AND MODULES.SUPERID=SUPERIDPARAMETERASSOC.SUPERID AND MODULETEMPLATES.SUPERID=MODULES.TEMPLATEID AND PATHMODULEASSOC.MODULEID=MODULES.SUPERID AND PATHS.PATHID=PATHMODULEASSOC.PATHID AND CONFIGURATIONPATHASSOC.PATHID=PATHS.PATHID AND CONFIGURATIONS.CONFIGID=CONFIGURATIONPATHASSOC.CONFIGID AND MODULETEMPLATES.NAME=:hltseed AND PARAMETERS.NAME=:l1seedexpr AND CONFIGURATIONS.CONFIGDESCRIPTOR=:hltkey',hltconfBindVar)
810  hlt2l1map={}
811  cursor=hltconfQuery.execute()
812  while next(cursor):
813  hltpath=cursor.currentRow()['hltpath'].data()
814  print(hltpath)
815  l1expression=cursor.currentRow()['l1expression'].data()
816  hlt2l1map[hltpath]=l1expression
817  del hltconfQuery
818  session.transaction().commit()
819  return hlt2l1map
820  except:
821  raise
822 
823 def runsummary(session,schemaname,runnumber,complementalOnly=False):
824  '''
825  x select string_value from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.TRG:TSC_KEY';
826  x select distinct(string_value) from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.SCAL:AMODEtag'
827  x select distinct(string_value),session_id from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.SCAL:EGEV' order by SESSION_ID
828 
829  select string_value from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.LVL0:SEQ_NAME'
830  select string_value from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.LVL0:HLT_KEY_DESCRIPTION';
831  select string_value from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.SCAL:FILLN' and rownum<=1;
832  select time from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.LVL0:START_TIME_T';
833  select time from cms_runinfo.runsession_parameter where runnumber=:runnumber and name='CMS.LVL0:STOP_TIME_T';
834  input:
835  output:[l1key,amodetag,egev,sequence,hltkey,fillnum,starttime,stoptime]
836  if complementalOnly:
837  [l1key,amodetag,egev]
838  '''
839  runsessionparameterTable=''
840  result=[]
841  l1key=''
842  amodetag=''
843  egev=''
844  hltkey=''
845  fillnum=''
846  sequence=''
847  starttime=''
848  stoptime=''
849  try:
850  session.transaction().start(True)
851  runinfoschema=session.schema(schemaname)
852  l1keyQuery=runinfoschema.newQuery()
853  l1keyQuery.addToTableList('RUNSESSION_PARAMETER')
854  l1keyOutput=coral.AttributeList()
855  l1keyOutput.extend('l1key','string')
856  l1keyCondition=coral.AttributeList()
857  l1keyCondition.extend('name','string')
858  l1keyCondition.extend('runnumber','unsigned int')
859  l1keyCondition['name'].setData('CMS.TRG:TSC_KEY')
860  l1keyCondition['runnumber'].setData(int(runnumber))
861  l1keyQuery.addToOutputList('STRING_VALUE')
862  l1keyQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',l1keyCondition)
863  l1keyQuery.defineOutput(l1keyOutput)
864  cursor=l1keyQuery.execute()
865  while next(cursor):
866  l1key=cursor.currentRow()['l1key'].data()
867  del l1keyQuery
868  result.append(l1key)
869 
870  amodetagQuery=runinfoschema.newQuery()
871  amodetagQuery.addToTableList('RUNSESSION_PARAMETER')
872  amodetagOutput=coral.AttributeList()
873  amodetagOutput.extend('amodetag','string')
874  amodetagCondition=coral.AttributeList()
875  amodetagCondition.extend('name','string')
876  amodetagCondition.extend('runnumber','unsigned int')
877  amodetagCondition['name'].setData('CMS.SCAL:AMODEtag')
878  amodetagCondition['runnumber'].setData(int(runnumber))
879  amodetagQuery.addToOutputList('distinct(STRING_VALUE)')
880  amodetagQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',amodetagCondition)
881  amodetagQuery.limitReturnedRows(1)
882  amodetagQuery.defineOutput(amodetagOutput)
883  cursor=amodetagQuery.execute()
884  while next(cursor):
885  amodetag=cursor.currentRow()['amodetag'].data()
886  del amodetagQuery
887  result.append(amodetag)
888 
889  egevQuery=runinfoschema.newQuery()
890  egevQuery.addToTableList('RUNSESSION_PARAMETER')
891  egevOutput=coral.AttributeList()
892  egevOutput.extend('egev','string')
893  egevCondition=coral.AttributeList()
894  egevCondition.extend('name','string')
895  egevCondition.extend('runnumber','unsigned int')
896  egevCondition['name'].setData('CMS.SCAL:EGEV')
897  egevCondition['runnumber'].setData(int(runnumber))
898  egevQuery.addToOutputList('distinct(STRING_VALUE)')
899  egevQuery.addToOutputList('SESSION_ID')
900  egevQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',egevCondition)
901  egevQuery.defineOutput(egevOutput)
902  egevQuery.addToOrderList('SESSION_ID')
903  cursor=egevQuery.execute()
904  while next(cursor):
905  egev=cursor.currentRow()['egev'].data()
906  del egevQuery
907  result.append(egev)
908 
909  if not complementalOnly:
910  seqQuery=runinfoschema.newQuery()
911  seqQuery.addToTableList('RUNSESSION_PARAMETER')
912  seqOutput=coral.AttributeList()
913  seqOutput.extend('seq','string')
914  seqCondition=coral.AttributeList()
915  seqCondition.extend('name','string')
916  seqCondition.extend('runnumber','unsigned int')
917  seqCondition['name'].setData('CMS.LVL0:SEQ_NAME')
918  seqCondition['runnumber'].setData(int(runnumber))
919  seqQuery.addToOutputList('STRING_VALUE')
920  seqQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',seqCondition)
921  seqQuery.defineOutput(seqOutput)
922  cursor=seqQuery.execute()
923  while next(cursor):
924  sequence=cursor.currentRow()['seq'].data()
925  del seqQuery
926  result.append(sequence)
927 
928  hltkeyQuery=runinfoschema.newQuery()
929  hltkeyQuery.addToTableList('RUNSESSION_PARAMETER')
930  hltkeyOutput=coral.AttributeList()
931  hltkeyOutput.extend('hltkey','string')
932  hltkeyCondition=coral.AttributeList()
933  hltkeyCondition.extend('name','string')
934  hltkeyCondition.extend('runnumber','unsigned int')
935  hltkeyCondition['name'].setData('CMS.LVL0:HLT_KEY_DESCRIPTION')
936  hltkeyCondition['runnumber'].setData(int(runnumber))
937  hltkeyQuery.addToOutputList('STRING_VALUE')
938  hltkeyQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',hltkeyCondition)
939  #hltkeyQuery.limitReturnedRows(1)
940  hltkeyQuery.defineOutput(hltkeyOutput)
941  cursor=hltkeyQuery.execute()
942  while next(cursor):
943  hltkey=cursor.currentRow()['hltkey'].data()
944  del hltkeyQuery
945  result.append(hltkey)
946 
947  fillnumQuery=runinfoschema.newQuery()
948  fillnumQuery.addToTableList('RUNSESSION_PARAMETER')
949  fillnumOutput=coral.AttributeList()
950  fillnumOutput.extend('fillnum','string')
951  fillnumCondition=coral.AttributeList()
952  fillnumCondition.extend('name','string')
953  fillnumCondition.extend('runnumber','unsigned int')
954  fillnumCondition['name'].setData('CMS.SCAL:FILLN')
955  fillnumCondition['runnumber'].setData(int(runnumber))
956  fillnumQuery.addToOutputList('STRING_VALUE')
957  fillnumQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',fillnumCondition)
958  fillnumQuery.limitReturnedRows(1)
959  fillnumQuery.defineOutput(fillnumOutput)
960  cursor=fillnumQuery.execute()
961  while next(cursor):
962  fillnum=cursor.currentRow()['fillnum'].data()
963  del fillnumQuery
964  result.append(fillnum)
965 
966  starttimeQuery=runinfoschema.newQuery()
967  starttimeQuery.addToTableList('RUNSESSION_PARAMETER')
968  starttimeOutput=coral.AttributeList()
969  starttimeOutput.extend('starttime','time stamp')
970  starttimeCondition=coral.AttributeList()
971  starttimeCondition.extend('name','string')
972  starttimeCondition.extend('runnumber','unsigned int')
973  starttimeCondition['name'].setData('CMS.LVL0:START_TIME_T')
974  starttimeCondition['runnumber'].setData(int(runnumber))
975  starttimeQuery.addToOutputList('TIME')
976  starttimeQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',starttimeCondition)
977  starttimeQuery.defineOutput(starttimeOutput)
978  cursor=starttimeQuery.execute()
979  while next(cursor):
980  starttime=cursor.currentRow()['starttime'].data()
981  del starttimeQuery
982  result.append(starttime)
983 
984  stoptimeQuery=runinfoschema.newQuery()
985  stoptimeQuery.addToTableList('RUNSESSION_PARAMETER')
986  stoptimeOutput=coral.AttributeList()
987  stoptimeOutput.extend('stoptime','time stamp')
988  stoptimeCondition=coral.AttributeList()
989  stoptimeCondition.extend('name','string')
990  stoptimeCondition.extend('runnumber','unsigned int')
991  stoptimeCondition['name'].setData('CMS.LVL0:STOP_TIME_T')
992  stoptimeCondition['runnumber'].setData(int(runnumber))
993  stoptimeQuery.addToOutputList('TIME')
994  stoptimeQuery.setCondition('NAME=:name AND RUNNUMBER=:runnumber',stoptimeCondition)
995  stoptimeQuery.defineOutput(stoptimeOutput)
996  cursor=stoptimeQuery.execute()
997  while next(cursor):
998  stoptime=cursor.currentRow()['stoptime'].data()
999  del stoptimeQuery
1000  result.append(stoptime)
1001  session.transaction().commit()
1002  else:
1003  session.transaction().commit()
1004  return result
1005  except:
1006  raise
1007 
1008 if __name__ == "__main__":
1009  from RecoLuminosity.LumiDB import sessionManager
1010  #svc=sessionManager.sessionManager('oracle://cms_orcoff_prep/cms_lumi_dev_offline',authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
1011  #session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
1012  #lsresult=trgFromOldLumi(session,135735)
1013  #print lsresult
1014  #lshltresult=hltFromOldLumi(session,135735)
1015  #print lshltresult
1016  #svc=sessionManager.sessionManager('oracle://cms_orcoff_prod/cms_runinfo',authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
1017  #session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
1018  #runsummary(session,'CMS_RUNINFO',135735,complementalOnly=True)
1019  #svc=sessionManager.sessionManager('oracle://cms_orcoff_prod/cms_gt',authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
1020  #session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
1021  #print trgFromOldGT(session,135735)
1022  #svc=sessionManager.sessionManager('oracle://cms_orcoff_prod/cms_runinfo',authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
1023  #session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
1024  #print hltFromRuninfoV2(session,135735)
1025  svc=sessionManager.sessionManager('oracle://cms_orcoff_prod/cms_lumi_prod',authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
1026  session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
1027  print(uncalibratedlumiFromOldLumi(session,135735))
1028  del session
Definition: start.py:1
def runsummary(session, schemaname, runnumber, complementalOnly=False)
def uncalibrateLumi(runnumber, instlumi, instlumierror)
def trgFromOldLumi(session, runnumber)
def hltFromRuninfoV3(session, runnumber)
def lumidetailTableName()
Definition: nameDealer.py:34
def trgTableName()
Definition: nameDealer.py:52
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def lumisummaryTableName()
Definition: nameDealer.py:25
def hltFromOldLumi(session, runnumber)
def hltconf(session, hltkey)
def trgFromNewGT(session, runnumber)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def hltTableName()
Definition: nameDealer.py:55
def hltFromRuninfoV2(session, runnumber)
def packArraytoBlob(iarray)
Definition: CommonUtil.py:222
def uncalibratedlumiFromOldLumi(session, runnumber)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def trgFromOldGT(session, runnumber)
#define str(s)
def trgFromWBM(session, runnumber)