CMS 3D CMS Logo

lumiQueryAPI.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import os
3 import coral,datetime
4 from RecoLuminosity.LumiDB import nameDealer,lumiTime,CommonUtil,lumiCorrections
5 import array
6 import argparse
7 
8 import six
9 from RecoLuminosity.LumiDB import nameDealer, selectionParser, hltTrgSeedMapper, \
10  connectstrParser, cacheconfigParser, tablePrinter, csvReporter, csvSelectionParser
11 from RecoLuminosity.LumiDB.wordWrappers import wrap_always, wrap_onspace, wrap_onspace_strict
12 from pprint import pprint, pformat
13 
14 '''
15 This module defines lowlevel SQL query API for lumiDB
16 We do not like range queries so far because of performance of range scan.Use only necessary.
17 The principle is to query by runnumber and per each coral queryhandle
18 Try reuse db session/transaction and just renew query handle each time to reduce metadata queries.
19 Avoid unnecessary explicit order by
20 Do not handle transaction in here.
21 Do not do explicit del queryhandle in here.
22 Note: all the returned dict format are not sorted by itself.Sort it outside if needed.
23 '''
24 ###==============temporarilly here======###
25 
27 
28  def __init__ (self):
29  self.norm = 1.0
30  self.lumiversion = '0001'
31  self.NBX = 3564 # number beam crossings
32  self.rotationRate = 11245.613 # for 3.5 TeV Beam energy
33  self.normFactor = 6.37
34  self.beammode = '' #possible choices stable, quiet, either
35  self.verbose = False
36  self.noWarnings = False
37  self.lumischema = 'CMS_LUMI_PROD'
38  #self.lumidb = 'oracle://cms_orcoff_prod/cms_lumi_prod'
39  self.lumisummaryname = 'LUMISUMMARY'
40  self.lumidetailname = 'LUMIDETAIL'
41  self.lumiXing = False
42  self.xingMinLum = 1.0e-4
43  self.xingIndex = 5
44  self.minBiasXsec = 71300 # unit: microbarn
45  self.pileupHistName = 'pileup'
46  self.maxPileupBin = 10
48 
50  '''Given the rotation rate, calculate lumi section length and
51  rotation time. This should be called if rotationRate is
52  updated.'''
53  self.rotationTime = 1 / self.rotationRate
54  self.lumiSectionLen = 2**18 * self.rotationTime
55 
57  return '''<frontier-connect><proxy url = "http://cmst0frontier.cern.ch:3128"/><proxy url = "http://cmst0frontier.cern.ch:3128"/><proxy url = "http://cmst0frontier1.cern.ch:3128"/><proxy url = "http://cmst0frontier2.cern.ch:3128"/><server url = "http://cmsfrontier.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier1.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier2.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier3.cern.ch:8000/FrontierInt"/><server url = "http://cmsfrontier4.cern.ch:8000/FrontierInt"/></frontier-connect>'''
58 
59 def lslengthsec (numorbit, numbx):
60  #print numorbit, numbx
61  l = numorbit * numbx * 25.0e-09
62  return l
63 
64 def lsBylsLumi (deadtable):
65  """
66  input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale...]}
67  output: {lsnum:[instlumi, recordedlumi...]}
68  """
69  result = {}
70  for myls, deadArray in deadtable.items():
71  lstime = lslengthsec (deadArray[3], 3564)
72  instlumi = deadArray[1] * lstime
73  if float( deadArray[2] ) == 0.0:
74  deadfrac = 1.0
75  else:
76  deadfrac = float (deadArray[0]) / (float (deadArray[2])*float(deadArray[4]))
77  recordedLumi = instlumi * (1.0 - deadfrac)
78  myLsList = [instlumi, recordedLumi]
79  #print myls,instlumi,recordedLumi,lstime,deadfrac
80  if len (deadArray) > 5:
81  myLsList.extend (deadArray[5:])
82  result[myls] = myLsList
83  return result
84 
85 
86 def deliveredLumiForRange (dbsession, parameters,inputRange,finecorrections=None):
87  '''Takes either single run as a string or dictionary of run ranges'''
88  lumidata = []
89  runs=[]
90  if isinstance(inputRange, str):
91  runs.append(int(inputRange))
92  else:
93  runs=inputRange.runs()
94  for r in sorted(runs):
95  if parameters.verbose:
96  print("run", run)
97  c=None
98  if finecorrections:
99  c=finecorrections[r]
100  lumidata.append( deliveredLumiForRun (dbsession, parameters,r,finecorrections=c) )
101  return lumidata
102 
103 def recordedLumiForRange (dbsession, parameters, inputRange,finecorrections=None):
104  '''Takes either single run as a string or dictionary of run ranges'''
105  lumidata = []
106  if isinstance(inputRange,str):
107  run=int(inputRange)
108  if finecorrections and finecorrections[run]:
109  lumiDataPiece = recordedLumiForRun (dbsession, parameters,inputRange,lslist=None,finecorrections=finecorrections[run])
110  else:
111  lumiDataPiece = recordedLumiForRun(dbsession, parameters,run)
112  if parameters.lumiXing:
113  # get the xing information for the run
114  if finecorrections and finecorrections[run]:
115  xingLumiDict = xingLuminosityForRun (dbsession, inputRange,
116  parameters,finecorrections=finecorrections[run])
117  else:
118  xingLumiDict = xingLuminosityForRun (dbsession, inputRange,
119  parameters)
120  mergeXingLumi (lumiDataPiece, xingLumiDict)
121  lumidata.append (lumiDataPiece)
122  else:
123  # we want to collapse the lists so that every run is considered once.
124  runLsDict = {}
125  maxLumiSectionDict = {}
126  for (run, lslist) in sorted (inputRange.runsandls().items() ):
127  if(len(lslist)!=0):
128  maxLumiSectionDict[run] = max ( max (lslist),
129  maxLumiSectionDict.get(run,0) )
130  runLsDict.setdefault (run, []).append (lslist)
131  for run, metaLsList in sorted (six.iteritems(runLsDict)):
132  if parameters.verbose:
133  print("run", run)
134  runLumiData = []
135  for lslist in metaLsList:
136  if finecorrections and finecorrections[run]:
137  runLumiData.append( recordedLumiForRun (dbsession, parameters,run,lslist=lslist,finecorrections=finecorrections[run]) )
138 
139  else:
140  runLumiData.append( recordedLumiForRun (dbsession, parameters,run,lslist=lslist) )
141  if parameters.lumiXing:
142  # get the xing information once for the whole run
143  if finecorrections and finecorrections[run]:
144  xingLumiDict = xingLuminosityForRun (dbsession, run,
145  parameters,
146  maxLumiSection = \
147  maxLumiSectionDict[run],
148  finecorrections=finecorrections[run])
149  else:
150  xingLumiDict = xingLuminosityForRun (dbsession, run,
151  parameters,
152  maxLumiSection = \
153  maxLumiSectionDict[run])
154  # merge it with every piece of lumi data for this run
155  for lumiDataPiece in runLumiData:
156  mergeXingLumi (lumiDataPiece, xingLumiDict)
157  lumidata.append (lumiDataPiece)
158  else:
159  lumidata.extend( runLumiData )
160  return lumidata
161 
162 def deliveredLumiForRun (dbsession, parameters, runnum, finecorrections=None ):
163  """
164  select sum (INSTLUMI), count (INSTLUMI) from lumisummary where runnum = 124025 and lumiversion = '0001';
165  select INSTLUMI,NUMORBIT from lumisummary where runnum = 124025 and lumiversion = '0001'
166  query result unit E27cm^-2 (= 1 / mb)
167 
168  optional corrections=None/(constfactor,afterglowfactor,nonlinearfactor)
169  """
170  #if parameters.verbose:
171  # print 'deliveredLumiForRun : norm : ', parameters.norm, ' : run : ', runnum
172  #output ['run', 'totalls', 'delivered', 'beammode']
173  delivered = 0.0
174  totalls = 0
175  try:
176  conditionstring="RUNNUM = :runnum AND LUMIVERSION = :lumiversion"
177  dbsession.transaction().start (True)
178  schema = dbsession.nominalSchema()
179  query = schema.tableHandle (nameDealer.lumisummaryTableName()).newQuery()
180  query.addToOutputList("INSTLUMI",'instlumi')
181  query.addToOutputList ("NUMORBIT", "norbits")
182  queryBind = coral.AttributeList()
183  queryBind.extend ("runnum", "unsigned int")
184  queryBind.extend ("lumiversion", "string")
185  queryBind["runnum"].setData (int (runnum))
186  queryBind["lumiversion"].setData (parameters.lumiversion)
187  #print parameters.beammode
188  if len(parameters.beammode)!=0:
189  conditionstring=conditionstring+' and BEAMSTATUS=:beamstatus'
190  queryBind.extend('beamstatus','string')
191  queryBind['beamstatus'].setData(parameters.beammode)
192  result = coral.AttributeList()
193  result.extend ("instlumi", "float")
194  result.extend ("norbits", "unsigned int")
195  query.defineOutput (result)
196  query.setCondition (conditionstring,queryBind)
197  cursor = query.execute()
198  while next(cursor):
199  instlumi = cursor.currentRow()['instlumi'].data()
200  norbits = cursor.currentRow()['norbits'].data()
201  if finecorrections is not None:
202  instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
203  if instlumi is not None and norbits is not None:
204  lstime = lslengthsec(norbits, parameters.NBX)
205  delivered=delivered+instlumi*parameters.norm*lstime
206  totalls+=1
207  del query
208  dbsession.transaction().commit()
209  lumidata = []
210  if delivered == 0.0:
211  lumidata = [str (runnum), 'N/A', 'N/A', 'N/A']
212  else:
213  lumidata = [str (runnum), str (totalls), '%.3f'%delivered, parameters.beammode]
214  return lumidata
215  except Exception as e:
216  print(str (e))
217  dbsession.transaction().rollback()
218  del dbsession
219 
220 def recordedLumiForRun (dbsession, parameters, runnum, lslist=None,finecorrections=None):
221  """
222  lslist = [] means take none in the db
223  lslist = None means to take all in the db
224  output: ['runnumber', 'trgtable{}', 'deadtable{}']
225  """
226  recorded = 0.0
227  lumidata = [] #[runnumber, trgtable, deadtable]
228  trgtable = {} #{hltpath:[l1seed, hltprescale, l1prescale]}
229  deadtable = {} #{lsnum:[deadtime, instlumi, bit_0, norbits,bitzero_prescale]}
230  lumidata.append (runnum)
231  lumidata.append (trgtable)
232  lumidata.append (deadtable)
233  collectedseeds = [] #[ (hltpath, l1seed)]
234  conditionstring='trghltmap.HLTKEY = cmsrunsummary.HLTKEY AND cmsrunsummary.RUNNUM = :runnumber'
235  try:
236  dbsession.transaction().start (True)
237  schema = dbsession.nominalSchema()
238  query = schema.newQuery()
239  query.addToTableList (nameDealer.cmsrunsummaryTableName(), 'cmsrunsummary')
240  query.addToTableList (nameDealer.trghltMapTableName(), 'trghltmap')#small table first
241  queryCondition = coral.AttributeList()
242  queryCondition.extend ("runnumber", "unsigned int")
243  queryCondition["runnumber"].setData (int (runnum))
244  query.setCondition (conditionstring,queryCondition)
245  query.addToOutputList ("trghltmap.HLTPATHNAME", "hltpathname")
246  query.addToOutputList ("trghltmap.L1SEED", "l1seed")
247  result = coral.AttributeList()
248  result.extend ("hltpathname", "string")
249  result.extend ("l1seed", "string")
250  query.defineOutput (result)
251  cursor = query.execute()
252  while next(cursor):
253  hltpathname = cursor.currentRow()["hltpathname"].data()
254  l1seed = cursor.currentRow()["l1seed"].data()
255  collectedseeds.append ( (hltpathname, l1seed))
256  #print 'collectedseeds ', collectedseeds
257  del query
258  dbsession.transaction().commit()
259  #loop over hltpath
260  for (hname, sname) in collectedseeds:
261  l1bitname = hltTrgSeedMapper.findUniqueSeed (hname, sname)
262  #print 'found unque seed ', hname, l1bitname
263  if l1bitname:
264  lumidata[1][hname] = []
265  lumidata[1][hname].append (l1bitname.replace ('\"', ''))
266  dbsession.transaction().start (True)
267  schema = dbsession.nominalSchema()
268  hltprescQuery = schema.tableHandle (nameDealer.hltTableName()).newQuery()
269  hltprescQuery.addToOutputList ("PATHNAME", "hltpath")
270  hltprescQuery.addToOutputList ("PRESCALE", "hltprescale")
271  hltprescCondition = coral.AttributeList()
272  hltprescCondition.extend ('runnumber', 'unsigned int')
273  hltprescCondition.extend ('cmslsnum', 'unsigned int')
274  hltprescCondition.extend ('inf', 'unsigned int')
275  hltprescResult = coral.AttributeList()
276  hltprescResult.extend ('hltpath', 'string')
277  hltprescResult.extend ('hltprescale', 'unsigned int')
278  hltprescQuery.defineOutput (hltprescResult)
279  hltprescCondition['runnumber'].setData (int (runnum))
280  hltprescCondition['cmslsnum'].setData (1)
281  hltprescCondition['inf'].setData (0)
282  hltprescQuery.setCondition ("RUNNUM = :runnumber and CMSLSNUM = :cmslsnum and PRESCALE != :inf",hltprescCondition)
283  cursor = hltprescQuery.execute()
284  while next(cursor):
285  hltpath = cursor.currentRow()['hltpath'].data()
286  hltprescale = cursor.currentRow()['hltprescale'].data()
287  if hltpath in lumidata[1]:
288  lumidata[1][hltpath].append (hltprescale)
289 
290  cursor.close()
291  del hltprescQuery
292  dbsession.transaction().commit()
293  dbsession.transaction().start (True)
294  schema = dbsession.nominalSchema()
295  query = schema.newQuery()
296  query.addToTableList (nameDealer.trgTableName(), 'trg')
297  query.addToTableList (nameDealer.lumisummaryTableName(), 'lumisummary')#small table first--right-most
298  queryCondition = coral.AttributeList()
299  queryCondition.extend ("runnumber", "unsigned int")
300  queryCondition.extend ("lumiversion", "string")
301  queryCondition["runnumber"].setData (int (runnum))
302  queryCondition["lumiversion"].setData (parameters.lumiversion)
303  conditionstring='lumisummary.RUNNUM =:runnumber and lumisummary.LUMIVERSION =:lumiversion AND lumisummary.CMSLSNUM=trg.CMSLSNUM and lumisummary.RUNNUM=trg.RUNNUM'
304  if len(parameters.beammode)!=0:
305  conditionstring=conditionstring+' and lumisummary.BEAMSTATUS=:beamstatus'
306  queryCondition.extend('beamstatus','string')
307  queryCondition['beamstatus'].setData(parameters.beammode)
308  query.setCondition(conditionstring,queryCondition)
309  query.addToOutputList ("lumisummary.CMSLSNUM", "cmsls")
310  query.addToOutputList ("lumisummary.INSTLUMI", "instlumi")
311  query.addToOutputList ("lumisummary.NUMORBIT", "norbits")
312  query.addToOutputList ("trg.TRGCOUNT", "trgcount")
313  query.addToOutputList ("trg.BITNAME", "bitname")
314  query.addToOutputList ("trg.DEADTIME", "trgdeadtime")
315  query.addToOutputList ("trg.PRESCALE", "trgprescale")
316  query.addToOutputList ("trg.BITNUM", "trgbitnum")
317 
318  result = coral.AttributeList()
319  result.extend ("cmsls", "unsigned int")
320  result.extend ("instlumi", "float")
321  result.extend ("norbits", "unsigned int")
322  result.extend ("trgcount", "unsigned int")
323  result.extend ("bitname", "string")
324  result.extend ("trgdeadtime", "unsigned long long")
325  result.extend ("trgprescale", "unsigned int")
326  result.extend ("trgbitnum", "unsigned int")
327  trgprescalemap = {}
328  query.defineOutput (result)
329  cursor = query.execute()
330  while next(cursor):
331  cmsls = cursor.currentRow()["cmsls"].data()
332  instlumi = cursor.currentRow()["instlumi"].data()*parameters.norm
333  if finecorrections:
334  instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
335  norbits = cursor.currentRow()["norbits"].data()
336  trgcount = cursor.currentRow()["trgcount"].data()
337  trgbitname = cursor.currentRow()["bitname"].data()
338  trgdeadtime = cursor.currentRow()["trgdeadtime"].data()
339  trgprescale = cursor.currentRow()["trgprescale"].data()
340  trgbitnum = cursor.currentRow()["trgbitnum"].data()
341  if cmsls == 1:
342  if trgbitname not in trgprescalemap:
343  trgprescalemap[trgbitname] = trgprescale
344  if trgbitnum == 0:
345  if cmsls not in deadtable:
346  deadtable[cmsls] = []
347  deadtable[cmsls].append (trgdeadtime)
348  deadtable[cmsls].append (instlumi)
349  deadtable[cmsls].append (trgcount)
350  deadtable[cmsls].append (norbits)
351  deadtable[cmsls].append (trgprescale)
352  cursor.close()
353  del query
354  dbsession.transaction().commit()
355 
356  #
357  #consolidate results
358  #
359  #trgtable
360  #print 'trgprescalemap', trgprescalemap
361  #print lumidata[1]
362  for hpath, trgdataseq in lumidata[1].items():
363  bitn = trgdataseq[0]
364  if bitn in trgprescalemap and len (trgdataseq) == 2:
365  lumidata[1][hpath].append (trgprescalemap[bitn])
366  #filter selected cmsls
367  lumidata[2] = filterDeadtable (deadtable, lslist)
368  if not parameters.noWarnings:
369  if len(lumidata[2])!=0:
370  for lumi, deaddata in lumidata[2].items():
371  if deaddata[1] == 0.0 and deaddata[2]!=0 and deaddata[0]!=0:
372  print('[Warning] : run %s :ls %d has 0 instlumi but trigger has data' % (runnum, lumi))
373  if (deaddata[2] == 0 or deaddata[0] == 0) and deaddata[1]!=0.0:
374  print('[Warning] : run %s :ls %d has 0 dead counts or 0 zerobias bit counts, but inst!=0' % (runnum, lumi))
375  #print 'lumidata[2] ', lumidata[2]
376  except Exception as e:
377  print(str (e))
378  dbsession.transaction().rollback()
379  del dbsession
380  #print 'before return lumidata ', lumidata
381  ## if parameters.lumiXing:
382  ## xingLumiDict = xingLuminosityForRun (dbsession, runnum, parameters)
383  ## mergeXingLumi (lumidata, xingLumiDict)
384  return lumidata
385 
386 
387 def filterDeadtable (inTable, lslist):
388  result = {}
389  if lslist is None:
390  return inTable
391  if len (lslist) == 0: #if request no ls, then return nothing
392  return result
393  for existingLS in inTable.keys():
394  if existingLS in lslist:
395  result[existingLS] = inTable[existingLS]
396  return result
397 
398 
399 def printDeliveredLumi (lumidata, mode):
400  labels = [ ('Run', 'Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Beam Mode')]
401  print(tablePrinter.indent (labels+lumidata, hasHeader = True, separateRows = False,
402  prefix = '| ', postfix = ' |', justify = 'right',
403  delim = ' | ', wrapfunc = lambda x: wrap_onspace (x, 20) ))
404 
405 def dumpData (lumidata, filename):
406  """
407  input params: lumidata [{'fieldname':value}]
408  filename csvname
409  """
410 
411  r = csvReporter.csvReporter(filename)
412  r.writeRows(lumidata)
413 
414 def calculateTotalRecorded (deadtable):
415  """
416  input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]}
417  output: recordedLumi
418  """
419  recordedLumi = 0.0
420  for myls, d in deadtable.items():
421  instLumi = d[1]
422  #deadfrac = float (d[0])/float (d[2]*3564)
423  #print myls, float (d[2])
424  if float (d[2]) == 0.0:
425  deadfrac = 1.0
426  else:
427  deadfrac = float (d[0])/(float (d[2])*float (d[-1]))
428  lstime = lslengthsec (d[3], 3564)
429  recordedLumi += instLumi* (1.0-deadfrac)*lstime
430  return recordedLumi
431 
432 
434  result = []
435  first = inPut[0]
436  last = inPut[0]
437  result.append ([inPut[0]])
438  counter = 0
439  for i in inPut[1:]:
440  if i == last+1:
441  result[counter].append (i)
442  else:
443  counter += 1
444  result.append ([i])
445  last = i
446  return ', '.join (['['+str (min (x))+'-'+str (max (x))+']' for x in result])
447 
448 
449 def calculateEffective (trgtable, totalrecorded):
450  """
451  input: trgtable{hltpath:[l1seed, hltprescale, l1prescale]}, totalrecorded (float)
452  output:{hltpath, recorded}
453  """
454  #print 'inputtrgtable', trgtable
455  result = {}
456  for hltpath, data in trgtable.items():
457  if len (data) == 3:
458  result[hltpath] = totalrecorded/ (data[1]*data[2])
459  else:
460  result[hltpath] = 0.0
461  return result
462 
463 
464 def getDeadfractions (deadtable):
465  """
466  inputtable: {lsnum:[deadtime, instlumi, bit_0, norbits,bit_0_prescale]}
467  output: {lsnum:deadfraction}
468  """
469  result = {}
470  for myls, d in deadtable.items():
471  #deadfrac = float (d[0])/ (float (d[2])*float (3564))
472  if float (d[2]) == 0.0: ##no beam
473  deadfrac = -1.0
474  else:
475  deadfrac = float (d[0])/ (float (d[2])*float(d[-1]))
476  result[myls] = deadfrac
477  return result
478 
479 def printPerLSLumi (lumidata, isVerbose = False):
480  '''
481  input lumidata [['runnumber', 'trgtable{}', 'deadtable{}']]
482  deadtable {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]}
483  '''
484  datatoprint = []
485  totalrow = []
486  labels = [ ('Run', 'LS', 'Delivered', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
487  lastrowlabels = [ ('Selected LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
488  totalDeliveredLS = 0
489  totalSelectedLS = 0
490  totalDelivered = 0.0
491  totalRecorded = 0.0
492 
493  for perrundata in lumidata:
494  runnumber = perrundata[0]
495  deadtable = perrundata[2]
496  lumiresult = lsBylsLumi (deadtable)
497  totalSelectedLS = totalSelectedLS+len (deadtable)
498  for lsnum, dataperls in lumiresult.items():
499  rowdata = []
500  if len (dataperls) == 0:
501  rowdata += [str (runnumber), str (lsnum), 'N/A', 'N/A']
502  else:
503  rowdata += [str (runnumber), str (lsnum), '%.3f' % (dataperls[0]), '%.3f' % (dataperls[1])]
504  totalDelivered = totalDelivered+dataperls[0]
505  totalRecorded = totalRecorded+dataperls[1]
506  datatoprint.append (rowdata)
507  totalrow.append ([str (totalSelectedLS), '%.3f'% (totalDelivered), '%.3f'% (totalRecorded)])
508  print(' == = ')
509  print(tablePrinter.indent (labels+datatoprint, hasHeader = True, separateRows = False, prefix = '| ',
510  postfix = ' |', justify = 'right', delim = ' | ',
511  wrapfunc = lambda x: wrap_onspace_strict (x, 22)))
512  print(' == = Total : ')
513  print(tablePrinter.indent (lastrowlabels+totalrow, hasHeader = True, separateRows = False, prefix = '| ',
514  postfix = ' |', justify = 'right', delim = ' | ',
515  wrapfunc = lambda x: wrap_onspace (x, 20)))
516 
517 
518 def dumpPerLSLumi (lumidata):
519  datatodump = []
520  for perrundata in lumidata:
521  runnumber = perrundata[0]
522  deadtable = perrundata[2]
523  lumiresult = lsBylsLumi (deadtable)
524  for lsnum, dataperls in lumiresult.items():
525  rowdata = []
526  if len (dataperls) == 0:
527  rowdata += [str (runnumber), str (lsnum), 'N/A', 'N/A']
528  else:
529  rowdata += [str (runnumber), str (lsnum), dataperls[0], dataperls[1]]
530  if len (dataperls) > 2:
531  rowdata.extend ( flatten (dataperls[2:]) )
532  datatodump.append (rowdata)
533  return datatodump
534 
535 
536 def printRecordedLumi (lumidata, isVerbose = False, hltpath = ''):
537  datatoprint = []
538  totalrow = []
539  labels = [ ('Run', 'HLT path', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
540  lastrowlabels = [ ('Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
541  if len (hltpath) != 0 and hltpath != 'all':
542  lastrowlabels = [ ('Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'),
543  'Effective '+u' (/\u03bcb) '.encode ('utf-8')+hltpath)]
544  if isVerbose:
545  labels = [ ('Run', 'HLT-path', 'L1-bit', 'L1-presc', 'HLT-presc', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
546  totalSelectedLS = 0
547  totalRecorded = 0.0
548  totalRecordedInPath = 0.0
549 
550  for dataperRun in lumidata:
551  runnum = dataperRun[0]
552  if len (dataperRun[1]) == 0:
553  rowdata = []
554  rowdata += [str (runnum)]+2*['N/A']
555  datatoprint.append (rowdata)
556  continue
557  perlsdata = dataperRun[2]
558  totalSelectedLS = totalSelectedLS+len (perlsdata)
559  recordedLumi = 0.0
560  #norbits = perlsdata.values()[0][3]
561  recordedLumi = calculateTotalRecorded (perlsdata)
562  totalRecorded = totalRecorded+recordedLumi
563  trgdict = dataperRun[1]
564  effective = calculateEffective (trgdict, recordedLumi)
565  if hltpath in trgdict and hltpath in effective:
566  rowdata = []
567  l1bit = trgdict[hltpath][0]
568  if len (trgdict[hltpath]) != 3:
569  if not isVerbose:
570  rowdata += [str (runnum), hltpath, 'N/A']
571  else:
572  rowdata += [str (runnum), hltpath, l1bit, 'N/A', 'N/A', 'N/A']
573  else:
574  if not isVerbose:
575  rowdata += [str (runnum), hltpath, '%.3f'% (effective[hltpath])]
576  else:
577  hltprescale = trgdict[hltpath][1]
578  l1prescale = trgdict[hltpath][2]
579  rowdata += [str (runnum), hltpath, l1bit, str (l1prescale), str (hltprescale),
580  '%.3f'% (effective[hltpath])]
581  totalRecordedInPath = totalRecordedInPath+effective[hltpath]
582  datatoprint.append (rowdata)
583  continue
584 
585  for trg, trgdata in trgdict.items():
586  #print trg, trgdata
587  rowdata = []
588  if trg == trgdict.keys()[0]:
589  rowdata += [str (runnum)]
590  else:
591  rowdata += ['']
592  l1bit = trgdata[0]
593  if len (trgdata) == 3:
594  if not isVerbose:
595  rowdata += [trg, '%.3f'% (effective[trg])]
596  else:
597  hltprescale = trgdata[1]
598  l1prescale = trgdata[2]
599  rowdata += [trg, l1bit, str (l1prescale), str (hltprescale), '%.3f'% (effective[trg])]
600  else:
601  if not isVerbose:
602  rowdata += [trg, 'N/A']
603  else:
604  rowdata += [trg, l1bit, 'N/A', 'N/A', '%.3f'% (effective[trg])]
605  datatoprint.append (rowdata)
606  #print datatoprint
607  print(' == = ')
608  print(tablePrinter.indent (labels+datatoprint, hasHeader = True, separateRows = False, prefix = '| ',
609  postfix = ' |', justify = 'right', delim = ' | ',
610  wrapfunc = lambda x: wrap_onspace_strict (x, 22)))
611 
612  if len (hltpath) != 0 and hltpath != 'all':
613  totalrow.append ([str (totalSelectedLS), '%.3f'% (totalRecorded), '%.3f'% (totalRecordedInPath)])
614  else:
615  totalrow.append ([str (totalSelectedLS), '%.3f'% (totalRecorded)])
616  print(' == = Total : ')
617  print(tablePrinter.indent (lastrowlabels+totalrow, hasHeader = True, separateRows = False, prefix = '| ',
618  postfix = ' |', justify = 'right', delim = ' | ',
619  wrapfunc = lambda x: wrap_onspace (x, 20)))
620  if isVerbose:
621  deadtoprint = []
622  deadtimelabels = [ ('Run', 'Lumi section : Dead fraction')]
623 
624  for dataperRun in lumidata:
625  runnum = dataperRun[0]
626  if len (dataperRun[1]) == 0:
627  deadtoprint.append ([str (runnum), 'N/A'])
628  continue
629  perlsdata = dataperRun[2]
630  #print 'perlsdata 2 : ', perlsdata
631  deadT = getDeadfractions (perlsdata)
632  t = ''
633  for myls, de in deadT.items():
634  if de<0:
635  t += str (myls)+':nobeam '
636  else:
637  t += str (myls)+':'+'%.5f'% (de)+' '
638  deadtoprint.append ([str (runnum), t])
639  print(' == = ')
640  print(tablePrinter.indent (deadtimelabels+deadtoprint, hasHeader = True, separateRows = True, prefix = '| ',
641  postfix = ' |', justify = 'right', delim = ' | ',
642  wrapfunc = lambda x: wrap_onspace (x, 80)))
643 
644 
645 def dumpRecordedLumi (lumidata, hltpath = ''):
646  #labels = ['Run', 'HLT path', 'Recorded']
647  datatodump = []
648  for dataperRun in lumidata:
649  runnum = dataperRun[0]
650  if len (dataperRun[1]) == 0:
651  rowdata = []
652  rowdata += [str (runnum)]+2*['N/A']
653  datatodump.append (rowdata)
654  continue
655  perlsdata = dataperRun[2]
656  recordedLumi = 0.0
657  #norbits = perlsdata.values()[0][3]
658  recordedLumi = calculateTotalRecorded (perlsdata)
659  trgdict = dataperRun[1]
660  effective = calculateEffective (trgdict, recordedLumi)
661  if hltpath in trgdict and hltpath in effective:
662  rowdata = []
663  l1bit = trgdict[hltpath][0]
664  if len (trgdict[hltpath]) != 3:
665  rowdata += [str (runnum), hltpath, 'N/A']
666  else:
667  hltprescale = trgdict[hltpath][1]
668  l1prescale = trgdict[hltpath][2]
669  rowdata += [str (runnum), hltpath, effective[hltpath]]
670  datatodump.append (rowdata)
671  continue
672 
673  for trg, trgdata in trgdict.items():
674  #print trg, trgdata
675  rowdata = []
676  rowdata += [str (runnum)]
677  l1bit = trgdata[0]
678  if len (trgdata) == 3:
679  rowdata += [trg, effective[trg]]
680  else:
681  rowdata += [trg, 'N/A']
682  datatodump.append (rowdata)
683  return datatodump
684 
685 
686 def printOverviewData (delivered, recorded, hltpath = ''):
687  if len (hltpath) == 0 or hltpath == 'all':
688  toprowlabels = [ ('Run', 'Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8') )]
689  lastrowlabels = [ ('Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8') ) ]
690  else:
691  toprowlabels = [ ('Run', 'Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'), 'Effective'+u' (/\u03bcb) '.encode ('utf-8')+hltpath )]
692  lastrowlabels = [ ('Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'), 'Effective '+u' (/\u03bcb) '.encode ('utf-8')+hltpath)]
693  datatable = []
694  totaldata = []
695  totalDeliveredLS = 0
696  totalSelectedLS = 0
697  totalDelivered = 0.0
698  totalRecorded = 0.0
699  totalRecordedInPath = 0.0
700  totaltable = []
701  for runidx, deliveredrowdata in enumerate (delivered):
702  rowdata = []
703  rowdata += [deliveredrowdata[0], deliveredrowdata[1], deliveredrowdata[2]]
704  if deliveredrowdata[1] == 'N/A': #run does not exist
705  if hltpath != '' and hltpath != 'all':
706  rowdata += ['N/A', 'N/A', 'N/A']
707  else:
708  rowdata += ['N/A', 'N/A']
709  datatable.append (rowdata)
710  continue
711  totalDeliveredLS += int (deliveredrowdata[1])
712  totalDelivered += float (deliveredrowdata[2])
713  selectedls = recorded[runidx][2].keys()
714  #print 'runidx ', runidx, deliveredrowdata
715  #print 'selectedls ', selectedls
716  if len (selectedls) == 0:
717  selectedlsStr = '[]'
718  recordedLumi = 0
719  if hltpath != '' and hltpath != 'all':
720  rowdata += [selectedlsStr, 'N/A', 'N/A']
721  else:
722  rowdata += [selectedlsStr, 'N/A']
723  else:
724  selectedlsStr = splitlistToRangeString (selectedls)
725  recordedLumi = calculateTotalRecorded (recorded[runidx][2])
726  lumiinPaths = calculateEffective (recorded[runidx][1], recordedLumi)
727  if hltpath != '' and hltpath != 'all':
728  if hltpath in lumiinPaths:
729  rowdata += [selectedlsStr, '%.3f'% (recordedLumi), '%.3f'% (lumiinPaths[hltpath])]
730  totalRecordedInPath += lumiinPaths[hltpath]
731  else:
732  rowdata += [selectedlsStr, '%.3f'% (recordedLumi), 'N/A']
733  else:
734  #rowdata += [selectedlsStr, '%.3f'% (recordedLumi), '%.3f'% (recordedLumi)]
735  rowdata += [selectedlsStr, '%.3f'% (recordedLumi)]
736  totalSelectedLS += len (selectedls)
737  totalRecorded += recordedLumi
738  datatable.append (rowdata)
739 
740  if hltpath != '' and hltpath != 'all':
741  totaltable = [[str (totalDeliveredLS), '%.3f'% (totalDelivered), str (totalSelectedLS),
742  '%.3f'% (totalRecorded), '%.3f'% (totalRecordedInPath)]]
743  else:
744  totaltable = [[str (totalDeliveredLS), '%.3f'% (totalDelivered), str (totalSelectedLS),
745  '%.3f'% (totalRecorded)]]
746  print(tablePrinter.indent (toprowlabels+datatable, hasHeader = True, separateRows = False, prefix = '| ',
747  postfix = ' |', justify = 'right', delim = ' | ',
748  wrapfunc = lambda x: wrap_onspace (x, 20)))
749  print(' == = Total : ')
750  print(tablePrinter.indent (lastrowlabels+totaltable, hasHeader = True, separateRows = False, prefix = '| ',
751  postfix = ' |', justify = 'right', delim = ' | ',
752  wrapfunc = lambda x: wrap_onspace (x, 20)))
753 
754 
755 def dumpOverview (delivered, recorded, hltpath = ''):
756  #toprowlabels = ['run', 'delivered', 'recorded', 'hltpath']
757  datatable = []
758  for runidx, deliveredrowdata in enumerate (delivered):
759  rowdata = []
760  rowdata += [deliveredrowdata[0], deliveredrowdata[2]]
761  if deliveredrowdata[1] == 'N/A': #run does not exist
762  rowdata += ['N/A', 'N/A']
763  datatable.append (rowdata)
764  continue
765  recordedLumi = calculateTotalRecorded (recorded[runidx][2])
766  lumiinPaths = calculateEffective (recorded[runidx][1], recordedLumi)
767  if hltpath != '' and hltpath != 'all':
768  if hltpath in lumiinPaths:
769  rowdata += [recordedLumi, lumiinPaths[hltpath]]
770  else:
771  rowdata += [recordedLumi, 'N/A']
772  else:
773  rowdata += [recordedLumi, recordedLumi]
774  datatable.append (rowdata)
775  return datatable
776 
777 
778 def xingLuminosityForRun (dbsession, runnum, parameters, lumiXingDict = {},
779  maxLumiSection = None, finecorrections=None):
780  '''Given a run number and a minimum xing luminosity value,
781  returns a dictionary (keyed by (run, lumi section)) where the
782  value is a list of tuples of (xingID, xingLum).
783 
784  - For all xing luminosities, simply set minLumValue to 0.
785 
786  - If you want one dictionary for several runs, pass it in to
787  "lumiXingDict"
788 
789  select
790  s.cmslsnum, d.bxlumivalue, d.bxlumierror, d.bxlumiquality, d.algoname from LUMIDETAIL d, LUMISUMMARY s where s.runnum = 133885 and d.algoname = 'OCC1' and s.lumisummary_id = d.lumisummary_id order by s.startorbit, s.cmslsnum
791  '''
792  try:
793  runnum = int (runnum)
794  dbsession.transaction().start (True)
795  schema = dbsession.schema (parameters.lumischema)
796  if not schema:
797  raise RuntimeError('cannot connect to schema '+ parameters.lumischema)
798  detailOutput = coral.AttributeList()
799  detailOutput.extend ('startorbit', 'unsigned int')
800  detailOutput.extend ('cmslsnum', 'unsigned int')
801  detailOutput.extend ('bxlumivalue', 'blob')
802  detailOutput.extend ('bxlumierror', 'blob')
803  detailOutput.extend ('bxlumiquality', 'blob')
804  detailOutput.extend ('algoname', 'string')
805  detailCondition = coral.AttributeList()
806  detailCondition.extend ('runnum', 'unsigned int')
807  detailCondition.extend ('algoname', 'string')
808  detailCondition['runnum'].setData (runnum)
809  detailCondition['algoname'].setData ('OCC1')
810  query = schema.newQuery()
811  query.addToTableList(nameDealer.lumisummaryTableName(), 's')
812  query.addToTableList(nameDealer.lumidetailTableName(), 'd')
813  query.addToOutputList ('s.STARTORBIT', 'startorbit')
814  query.addToOutputList ('s.CMSLSNUM', 'cmslsnum')
815  query.addToOutputList ('d.BXLUMIVALUE', 'bxlumivalue')
816  query.addToOutputList ('d.BXLUMIERROR', 'bxlumierror')
817  query.addToOutputList ('d.BXLUMIQUALITY', 'bxlumiquality')
818  query.addToOutputList ('d.ALGONAME', 'algoname')
819  query.setCondition ('s.RUNNUM =:runnum and d.ALGONAME =:algoname and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',detailCondition)
820  query.addToOrderList ('s.CMSLSNUM')
821  query.defineOutput (detailOutput)
822  cursor = query.execute()
823  count = 0
824  while next(cursor):
825  ## ## Note: If you are going to break out of this loop early,
826  ## ## make sure you call cursor.close():
827  ##
828  ## if count > 20 :
829  ## cursor.close()
830  ## break
831  ## count += 1
832  cmslsnum = cursor.currentRow()['cmslsnum'].data()
833  algoname = cursor.currentRow()['algoname'].data()
834  bxlumivalue = cursor.currentRow()['bxlumivalue'].data()
835  startorbit = cursor.currentRow()['startorbit'].data()
836 
837  if maxLumiSection and maxLumiSection < cmslsnum:
838  cursor.close()
839  break
840 
841  xingArray = array.array ('f')
842  xingArray.fromstring( bxlumivalue.readline() )
843  numPrinted = 0
844  xingLum = []
845  avginstlumi=0.0
846  if len(xingArray)!=0:
847  avginstlumi=sum(xingArray)
848  for index, lum in enumerate (xingArray):
849  mynorm=parameters.normFactor
850  if finecorrections:
851  lum=lumiCorrections.applyfinecorrectionBX(lum,avginstlumi*mynorm,mynorm,finecorrections[0],finecorrections[1],finecorrections[2])
852  else:
853  lum*=mynorm
854  if lum < parameters.xingMinLum:
855  continue
856  xingLum.append( (index, lum) )
857  lumiXingDict[ (runnum, cmslsnum) ] = xingLum
858  del query
859  dbsession.transaction().commit()
860  return lumiXingDict
861  except Exception as e:
862  print(str (e))
863  print("whoops")
864  dbsession.transaction().rollback()
865  del dbsession
866 
867 
868 def flatten (obj):
869  '''Given nested lists or tuples, returns a single flattened list'''
870  result = []
871  for piece in obj:
872  if hasattr (piece, '__iter__') and not isinstance (piece, str):
873  result.extend( flatten (piece) )
874  else:
875  result.append (piece)
876  return result
877 
878 
879 def mergeXingLumi (triplet, xingLumiDict):
880  '''Given general xing information and a xingLumiDict, the xing
881  luminosity information is merged with the general information'''
882  runNumber = triplet[0]
883  deadTable = triplet[2]
884  for lumi, lumiList in six.iteritems(deadTable):
885  key = ( int(runNumber), int(lumi) )
886  xingLumiValues = xingLumiDict.get (key)
887  if xingLumiValues:
888  lumiList.append( flatten (xingLumiValues) )
889 
890 
891 def setupSession (connectString, siteconfpath, parameters, debug = False):
892  '''returns database session'''
893  connectparser = connectstrParser.connectstrParser (connectString)
894  connectparser.parse()
895  usedefaultfrontierconfig = False
896  cacheconfigpath = ''
897  if connectparser.needsitelocalinfo():
898  if not siteconfpath:
899  cacheconfigpath = os.environ['CMS_PATH']
900  if cacheconfigpath:
901  cacheconfigpath = os.path.join (cacheconfigpath, 'SITECONF', 'local', 'JobConfig', 'site-local-config.xml')
902  else:
903  usedefaultfrontierconfig = True
904  else:
905  cacheconfigpath = siteconfpath
906  cacheconfigpath = os.path.join (cacheconfigpath, 'site-local-config.xml')
908  if usedefaultfrontierconfig:
909  ccp.parseString (parameters.defaultfrontierConfigString)
910  else:
911  ccp.parse (cacheconfigpath)
912  connectString = connectparser.fullfrontierStr (connectparser.schemaname(), ccp.parameterdict())
913  svc = coral.ConnectionService()
914  if debug :
915  msg = coral.MessageStream ('')
916  msg.setMsgVerbosity (coral.message_Level_Debug)
917  parameters.verbose = True
918  session = svc.connect (connectString, accessMode = coral.access_ReadOnly)
919  session.typeConverter().setCppTypeForSqlType ("unsigned int", "NUMBER (10)")
920  session.typeConverter().setCppTypeForSqlType ("unsigned long long", "NUMBER (20)")
921  return session, svc
922 
923 
924 
925 ###==============real api=====###
926 
927 def allruns(schemaHandle,requireRunsummary=True,requireLumisummary=False,requireTrg=False,requireHlt=False):
928  '''
929  find all runs in the DB. By default requires cmsrunsummary table contain the run. The condition can be loosed in situation where db loading failed on certain data portions.
930  '''
931  if not requireRunsummary and not requireLumiummary and not requireTrg and not requireHlt:
932  print('must require at least one table')
933  raise RuntimeError('one table')
934  runresult=[]
935  runlist=[]
936  numdups=0
937  if requireRunsummary:
938  numdups=numdups+1
939  queryHandle=schemaHandle.newQuery()
940  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
941  queryHandle.addToOutputList("RUNNUM","run")
942  #queryBind=coral.AttributeList()
943  result=coral.AttributeList()
944  result.extend("run","unsigned int")
945  queryHandle.defineOutput(result)
946  cursor=queryHandle.execute()
947  while next(cursor):
948  r=cursor.currentRow()['run'].data()
949  runlist.append(r)
950  del queryHandle
951  if requireLumisummary:
952  numdups=numdups+1
953  queryHandle=schemaHandle.newQuery()
954  queryHandle.addToTableList(nameDealer.lumisummaryTableName())
955  queryHandle.addToOutputList("distinct RUNNUM","run")
956  #queryBind=coral.AttributeList()
957  result=coral.AttributeList()
958  result.extend("run","unsigned int")
959  queryHandle.defineOutput(result)
960  cursor=queryHandle.execute()
961  while next(cursor):
962  r=cursor.currentRow()['run'].data()
963  runlist.append(r)
964  del queryHandle
965  if requireTrg:
966  numdups=numdups+1
967  queryHandle=schemaHandle.newQuery()
968  queryHandle.addToTableList(nameDealer.trgTableName())
969  queryHandle.addToOutputList("distinct RUNNUM","run")
970  #queryBind=coral.AttributeList()
971  result=coral.AttributeList()
972  result.extend("run","unsigned int")
973  queryHandle.defineOutput(result)
974  cursor=queryHandle.execute()
975  while next(cursor):
976  r=cursor.currentRow()['run'].data()
977  runlist.append(r)
978  del queryHandle
979  if requireHlt:
980  numdups=numdups+1
981  queryHandle=schemaHandle.newQuery()
982  queryHandle.addToTableList(nameDealer.hltTableName())
983  queryHandle.addToOutputList("distinct RUNNUM","run")
984  #queryBind=coral.AttributeList()
985  result=coral.AttributeList()
986  result.extend("run","unsigned int")
987  queryHandle.defineOutput(result)
988  cursor=queryHandle.execute()
989  while next(cursor):
990  r=cursor.currentRow()['run'].data()
991  runlist.append(r)
992  del queryHandle
993  dupresult=CommonUtil.count_dups(runlist)
994  for dup in dupresult:
995  if dup[1]==numdups:
996  runresult.append(dup[0])
997  runresult.sort()
998  return runresult
999 
1000 def validation(queryHandle,run=None,cmsls=None):
1001  '''retrieve validation data per run or all
1002  input: run. if not run, retrive all; if cmslsnum selection list pesent, filter out unselected result
1003  output: {run:[[cmslsnum,status,comment]]}
1004  '''
1005  result={}
1006  queryHandle.addToTableList(nameDealer.lumivalidationTableName())
1007  queryHandle.addToOutputList('RUNNUM','runnum')
1008  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1009  queryHandle.addToOutputList('FLAG','flag')
1010  queryHandle.addToOutputList('COMMENT','comment')
1011  if run:
1012  queryCondition='RUNNUM=:runnum'
1013  queryBind=coral.AttributeList()
1014  queryBind.extend('runnum','unsigned int')
1015  queryBind['runnum'].setData(run)
1016  queryHandle.setCondition(queryCondition,queryBind)
1017  queryResult=coral.AttributeList()
1018  queryResult.extend('runnum','unsigned int')
1019  queryResult.extend('cmslsnum','unsigned int')
1020  queryResult.extend('flag','string')
1021  queryResult.extend('comment','string')
1022  queryHandle.defineOutput(queryResult)
1023  cursor=queryHandle.execute()
1024  while next(cursor):
1025  runnum=cursor.currentRow()['runnum'].data()
1026  if runnum not in result:
1027  result[runnum]=[]
1028  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1029  flag=cursor.currentRow()['flag'].data()
1030  comment=cursor.currentRow()['comment'].data()
1031  result[runnum].append([cmslsnum,flag,comment])
1032  if run and cmsls and len(cmsls)!=0:
1033  selectedresult={}
1034  for runnum,perrundata in result.items():
1035  for lsdata in perrundata:
1036  if lsdata[0] not in cmsls:
1037  continue
1038  if runnum not in selectedresult:
1039  selectedresult[runnum]=[]
1040  selectedresult[runnum].append(lsdata)
1041  return selectedresult
1042  else:
1043  return result
1044 
1045 def allfills(queryHandle,filtercrazy=True):
1046  '''select distinct fillnum from cmsrunsummary
1047  there are crazy fill numbers. we assume they are not valid runs
1048  '''
1049  result=[]
1050  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
1051  queryHandle.addToOutputList('distinct FILLNUM','fillnum')
1052 
1053  if filtercrazy:
1054  queryCondition='FILLNUM>:zero and FILLNUM<:crazybig'
1055  queryBind=coral.AttributeList()
1056  queryBind.extend('zero','unsigned int')
1057  queryBind.extend('crazybig','unsigned int')
1058  queryBind['zero'].setData(int(0))
1059  queryBind['crazybig'].setData(int(29701))
1060  queryHandle.setCondition(queryCondition,queryBind)
1061  queryResult=coral.AttributeList()
1062  queryResult.extend('fillnum','unsigned int')
1063  queryHandle.defineOutput(queryResult)
1064  cursor=queryHandle.execute()
1065  while next(cursor):
1066  result.append(cursor.currentRow()['fillnum'].data())
1067  result.sort()
1068  return result
1069 def runsummaryByrun(queryHandle,runnum):
1070  '''
1071  select fillnum,sequence,hltkey,to_char(starttime),to_char(stoptime) from cmsrunsummary where runnum=:runnum
1072  output: [fillnum,sequence,hltkey,starttime,stoptime]
1073  '''
1074  t=lumiTime.lumiTime()
1075  result=[]
1076  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
1077  queryCondition=coral.AttributeList()
1078  queryCondition.extend('runnum','unsigned int')
1079  queryCondition['runnum'].setData(int(runnum))
1080  queryHandle.addToOutputList('FILLNUM','fillnum')
1081  queryHandle.addToOutputList('SEQUENCE','sequence')
1082  queryHandle.addToOutputList('HLTKEY','hltkey')
1083  queryHandle.addToOutputList('to_char(STARTTIME,\''+t.coraltimefm+'\')','starttime')
1084  queryHandle.addToOutputList('to_char(STOPTIME,\''+t.coraltimefm+'\')','stoptime')
1085  queryHandle.setCondition('RUNNUM=:runnum',queryCondition)
1086  queryResult=coral.AttributeList()
1087  queryResult.extend('fillnum','unsigned int')
1088  queryResult.extend('sequence','string')
1089  queryResult.extend('hltkey','string')
1090  queryResult.extend('starttime','string')
1091  queryResult.extend('stoptime','string')
1092  queryHandle.defineOutput(queryResult)
1093  cursor=queryHandle.execute()
1094  while next(cursor):
1095  result.append(cursor.currentRow()['fillnum'].data())
1096  result.append(cursor.currentRow()['sequence'].data())
1097  result.append(cursor.currentRow()['hltkey'].data())
1098  result.append(cursor.currentRow()['starttime'].data())
1099  result.append(cursor.currentRow()['stoptime'].data())
1100  #if len(result)!=5:
1101  # print 'wrong runsummary result'
1102  # raise
1103  return result
1104 
1105 def lumisummaryByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09,finecorrections=None):
1106  '''
1107  one can impose beamstatus, beamenergy selections at the SQL query level or process them later from the general result
1108  select cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenery from lumisummary where runnum=:runnum and lumiversion=:lumiversion order by startorbit;
1109  output: [[cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive]]
1110  Note: the non-cmsalive LS are included in the result
1111  '''
1112  result=[]
1113  queryHandle.addToTableList(nameDealer.lumisummaryTableName())
1114  queryCondition=coral.AttributeList()
1115  queryCondition.extend('runnum','unsigned int')
1116  queryCondition.extend('lumiversion','string')
1117  conditionstring='RUNNUM=:runnum and LUMIVERSION=:lumiversion'
1118  queryCondition['runnum'].setData(int(runnum))
1119  queryCondition['lumiversion'].setData(lumiversion)
1120  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1121  queryHandle.addToOutputList('INSTLUMI','instlumi')
1122  queryHandle.addToOutputList('NUMORBIT','numorbit')
1123  queryHandle.addToOutputList('STARTORBIT','startorbit')
1124  queryHandle.addToOutputList('BEAMSTATUS','beamstatus')
1125  queryHandle.addToOutputList('BEAMENERGY','beamenergy')
1126  queryHandle.addToOutputList('CMSALIVE','cmsalive')
1127  if beamstatus and len(beamstatus)!=0:
1128  conditionstring=conditionstring+' and BEAMSTATUS=:beamstatus'
1129  queryCondition.extend('beamstatus','string')
1130  queryCondition['beamstatus'].setData(beamstatus)
1131  if beamenergy:
1132  minBeamenergy=float(beamenergy*(1.0-beamenergyfluctuation))
1133  maxBeamenergy=float(beamenergy*(1.0+beamenergyfluctuation))
1134  conditionstring=conditionstring+' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy'
1135  queryCondition.extend('minBeamenergy','float')
1136  queryCondition.extend('maxBeamenergy','float')
1137  queryCondition['minBeamenergy'].setData(float(minBeamenergy))
1138  queryCondition['maxBeamenergy'].setData(float(maxBeamenergy))
1139  queryResult=coral.AttributeList()
1140  queryResult.extend('cmslsnum','unsigned int')
1141  queryResult.extend('instlumi','float')
1142  queryResult.extend('numorbit','unsigned int')
1143  queryResult.extend('startorbit','unsigned int')
1144  queryResult.extend('beamstatus','string')
1145  queryResult.extend('beamenergy','float')
1146  queryResult.extend('cmsalive','unsigned int')
1147  queryHandle.defineOutput(queryResult)
1148  queryHandle.setCondition(conditionstring,queryCondition)
1149  queryHandle.addToOrderList('startorbit')
1150  cursor=queryHandle.execute()
1151  while next(cursor):
1152  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1153  instlumi=cursor.currentRow()['instlumi'].data()
1154  if finecorrections:
1155  instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1156  numorbit=cursor.currentRow()['numorbit'].data()
1157  startorbit=cursor.currentRow()['startorbit'].data()
1158  beamstatus=cursor.currentRow()['beamstatus'].data()
1159  beamenergy=cursor.currentRow()['beamenergy'].data()
1160  cmsalive=cursor.currentRow()['cmsalive'].data()
1161  result.append([cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive])
1162  return result
1163 
1164 def lumisumByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09,finecorrections=None):
1165  '''
1166  beamenergy unit : GeV
1167  beamenergyfluctuation : fraction allowed to fluctuate around beamenergy value
1168  select instlumi from lumisummary where runnum=:runnum and lumiversion=:lumiversion
1169  output: float sum(instlumi)
1170  Note: the output is the raw result, need to apply LS length in time(sec)
1171  '''
1172  result=[]
1173  queryHandle.addToTableList(nameDealer.lumisummaryTableName())
1174  queryCondition=coral.AttributeList()
1175  queryCondition.extend('runnum','unsigned int')
1176  queryCondition.extend('lumiversion','string')
1177 
1178  queryCondition['runnum'].setData(int(runnum))
1179  queryCondition['lumiversion'].setData(lumiversion)
1180  queryHandle.addToOutputList('INSTLUMI','instlumi')
1181  conditionstring='RUNNUM=:runnum and LUMIVERSION=:lumiversion'
1182  if beamstatus and len(beamstatus)!=0:
1183  conditionstring=conditionstring+' and BEAMSTATUS=:beamstatus'
1184  queryCondition.extend('beamstatus','string')
1185  queryCondition['beamstatus'].setData(beamstatus)
1186  if beamenergy and beamenergy!=0.0:
1187  minBeamenergy=float(beamenergy*(1.0-beamenergyfluctuation))
1188  maxBeamenergy=float(beamenergy*(1.0+beamenergyfluctuation))
1189  conditionstring=conditionstring+' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy'
1190  queryCondition.extend('minBeamenergy','float')
1191  queryCondition.extend('maxBeamenergy','float')
1192  queryCondition['minBeamenergy'].setData(float(minBeamenergy))
1193  queryCondition['maxBeamenergy'].setData(float(maxBeamenergy))
1194  queryHandle.setCondition(conditionstring,queryCondition)
1195  queryResult=coral.AttributeList()
1196  queryResult.extend('instlumi','float')
1197  queryHandle.defineOutput(queryResult)
1198  cursor=queryHandle.execute()
1199  while next(cursor):
1200  instlumi=cursor.currentRow()['instlumi'].data()
1201  if instlumi:
1202  if finecorrections:
1203  instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1204  result.append(instlumi)
1205  if result:
1206  return sum(result)
1207  else:
1208  return 0.0
1209 
1210 def trgbitzeroByrun(queryHandle,runnum):
1211  '''
1212  select cmslsnum,trgcount,deadtime,bitname,prescale from trg where runnum=:runnum and bitnum=0;
1213  output: {cmslsnum:[trgcount,deadtime,bitname,prescale]}
1214  '''
1215  result={}
1216  queryHandle.addToTableList(nameDealer.trgTableName())
1217  queryCondition=coral.AttributeList()
1218  queryCondition.extend('runnum','unsigned int')
1219  queryCondition.extend('bitnum','unsigned int')
1220  queryCondition['runnum'].setData(int(runnum))
1221  queryCondition['bitnum'].setData(int(0))
1222  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1223  queryHandle.addToOutputList('TRGCOUNT','trgcount')
1224  queryHandle.addToOutputList('DEADTIME','deadtime')
1225  queryHandle.addToOutputList('BITNAME','bitname')
1226  queryHandle.addToOutputList('PRESCALE','prescale')
1227  queryHandle.setCondition('RUNNUM=:runnum and BITNUM=:bitnum',queryCondition)
1228  queryResult=coral.AttributeList()
1229  queryResult.extend('cmslsnum','unsigned int')
1230  queryResult.extend('trgcount','unsigned int')
1231  queryResult.extend('deadtime','unsigned int')
1232  queryResult.extend('bitname','string')
1233  queryResult.extend('prescale','unsigned int')
1234  queryHandle.defineOutput(queryResult)
1235  cursor=queryHandle.execute()
1236  while next(cursor):
1237  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1238  trgcount=cursor.currentRow()['trgcount'].data()
1239  deadtime=cursor.currentRow()['deadtime'].data()
1240  bitname=cursor.currentRow()['bitname'].data()
1241  prescale=cursor.currentRow()['prescale'].data()
1242  if cmslsnum not in result:
1243  result[cmslsnum]=[trgcount,deadtime,bitname,prescale]
1244  return result
1245 
1246 def lumisummarytrgbitzeroByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09,finecorrections=None):
1247  '''
1248  select l.cmslsnum,l.instlumi,l.numorbit,l.startorbit,l.beamstatus,l.beamenery,t.trgcount,t.deadtime,t.bitname,t.prescale from trg t,lumisummary l where t.bitnum=:bitnum and l.runnum=:runnum and l.lumiversion=:lumiversion and l.runnum=t.runnum and t.cmslsnum=l.cmslsnum;
1249  Everything you ever need to know about bitzero and avg luminosity. Since we do not know if joint query is better of sperate, support both.
1250  output: {cmslsnum:[instlumi,numorbit,startorbit,beamstatus,beamenergy,bitzerocount,deadtime,bitname,prescale]}
1251  Note: only cmsalive LS are included in the result. Therefore, this function cannot be used for calculating delivered!
1252  '''
1253  result={}
1254  queryHandle.addToTableList(nameDealer.trgTableName(),'t')
1255  queryHandle.addToTableList(nameDealer.lumisummaryTableName(),'l')
1256  queryCondition=coral.AttributeList()
1257  queryCondition.extend('bitnum','unsigned int')
1258  queryCondition.extend('runnum','unsigned int')
1259  queryCondition.extend('lumiversion','string')
1260  queryCondition['bitnum'].setData(int(0))
1261  queryCondition['runnum'].setData(int(runnum))
1262  queryCondition['lumiversion'].setData(lumiversion)
1263 
1264  queryHandle.addToOutputList('l.CMSLSNUM','cmslsnum')
1265  queryHandle.addToOutputList('l.INSTLUMI','instlumi')
1266  queryHandle.addToOutputList('l.NUMORBIT','numorbit')
1267  queryHandle.addToOutputList('l.STARTORBIT','startorbit')
1268  queryHandle.addToOutputList('l.BEAMSTATUS','beamstatus')
1269  queryHandle.addToOutputList('l.BEAMENERGY','beamenergy')
1270  queryHandle.addToOutputList('t.TRGCOUNT','trgcount')
1271  queryHandle.addToOutputList('t.DEADTIME','deadtime')
1272  queryHandle.addToOutputList('t.BITNAME','bitname')
1273  queryHandle.addToOutputList('t.PRESCALE','prescale')
1274  conditionstring='t.BITNUM=:bitnum and l.RUNNUM=:runnum and l.LUMIVERSION=:lumiversion and l.RUNNUM=t.RUNNUM and t.CMSLSNUM=l.CMSLSNUM'
1275  if beamstatus and len(beamstatus)!=0:
1276  conditionstring=conditionstring+' and l.BEAMSTATUS=:beamstatus'
1277  queryCondition.extend('beamstatus','string')
1278  queryCondition['beamstatus'].setData(beamstatus)
1279  if beamenergy and beamenergy!=0.0:
1280  minBeamenergy=float(beamenergy*(1-beamenergyfluctuation))
1281  maxBeamenergy=float(beamenergy*(1+beamenergyfluctuation))
1282  conditionstring=conditionstring+' and l.BEAMENERGY>:minBeamenergy and l.BEAMENERGY<:maxBeamenergy'
1283  queryCondition.extend('minBeamenergy','float')
1284  queryCondition.extend('maxBeamenergy','float')
1285  queryCondition['minBeamenergy'].setData(float(minBeamenergy))
1286  queryCondition['maxBeamenergy'].setData(float(maxBeamenergy))
1287  queryHandle.setCondition(conditionstring,queryCondition)
1288  queryResult=coral.AttributeList()
1289  queryResult.extend('cmslsnum','unsigned int')
1290  queryResult.extend('instlumi','float')
1291  queryResult.extend('numorbit','unsigned int')
1292  queryResult.extend('startorbit','unsigned int')
1293  queryResult.extend('beamstatus','string')
1294  queryResult.extend('beamenergy','float')
1295  queryResult.extend('trgcount','unsigned int')
1296  queryResult.extend('deadtime','unsigned int')
1297  queryResult.extend('bitname','string')
1298  queryResult.extend('prescale','unsigned int')
1299  queryHandle.defineOutput(queryResult)
1300  cursor=queryHandle.execute()
1301  while next(cursor):
1302  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1303  instlumi=cursor.currentRow()['instlumi'].data()
1304  if finecorrections:
1305  instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1306  numorbit=cursor.currentRow()['numorbit'].data()
1307  startorbit=cursor.currentRow()['startorbit'].data()
1308  beamstatus=cursor.currentRow()['beamstatus'].data()
1309  beamenergy=cursor.currentRow()['beamenergy'].data()
1310  trgcount=cursor.currentRow()['trgcount'].data()
1311  deadtime=cursor.currentRow()['deadtime'].data()
1312  bitname=cursor.currentRow()['bitname'].data()
1313  prescale=cursor.currentRow()['prescale'].data()
1314  if cmslsnum not in result:
1315  result[cmslsnum]=[instlumi,numorbit,startorbit,beamstatus,beamenergy,trgcount,deadtime,bitname,prescale]
1316  return result
1317 
1318 def trgBybitnameByrun(queryHandle,runnum,bitname):
1319  '''
1320  select cmslsnum,trgcount,deadtime,bitnum,prescale from trg where runnum=:runnum and bitname=:bitname;
1321  output: {cmslsnum:[trgcount,deadtime,bitnum,prescale]}
1322  '''
1323  result={}
1324  queryHandle.addToTableList(nameDealer.trgTableName())
1325  queryCondition=coral.AttributeList()
1326  queryCondition.extend('runnum','unsigned int')
1327  queryCondition.extend('bitname','string')
1328  queryCondition['runnum'].setData(int(runnum))
1329  queryCondition['bitname'].setData(bitname)
1330  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1331  queryHandle.addToOutputList('TRGCOUNT','trgcount')
1332  queryHandle.addToOutputList('DEADTIME','deadtime')
1333  queryHandle.addToOutputList('BITNUM','bitnum')
1334  queryHandle.addToOutputList('PRESCALE','prescale')
1335  queryHandle.setCondition('RUNNUM=:runnum and BITNAME=:bitname',queryCondition)
1336  queryResult=coral.AttributeList()
1337  queryResult.extend('cmslsnum','unsigned int')
1338  queryResult.extend('trgcount','unsigned int')
1339  queryResult.extend('deadtime','unsigned long long')
1340  queryResult.extend('bitnum','unsigned int')
1341  queryResult.extend('prescale','unsigned int')
1342  queryHandle.defineOutput(queryResult)
1343  cursor=queryHandle.execute()
1344  while next(cursor):
1345  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1346  trgcount=cursor.currentRow()['trgcount'].data()
1347  deadtime=cursor.currentRow()['deadtime'].data()
1348  bitnum=cursor.currentRow()['bitnum'].data()
1349  prescale=cursor.currentRow()['prescale'].data()
1350  if cmslsnum not in result:
1351  result[cmslsnum]=[trgcount,deadtime,bitnum,prescale]
1352  return result
1353 
1354 def trgAllbitsByrun(queryHandle,runnum):
1355  '''
1356  all you ever want to know about trigger
1357  select cmslsnum,trgcount,deadtime,bitnum,bitname,prescale from trg where runnum=:runnum order by bitnum,cmslsnum
1358  this can be changed to blob query later
1359  output: {cmslsnum:{bitname:[bitnum,trgcount,deadtime,prescale]}}
1360  '''
1361  result={}
1362  queryHandle.addToTableList(nameDealer.trgTableName())
1363  queryCondition=coral.AttributeList()
1364  queryCondition.extend('runnum','unsigned int')
1365  queryCondition['runnum'].setData(int(runnum))
1366  queryHandle.addToOutputList('cmslsnum')
1367  queryHandle.addToOutputList('trgcount')
1368  queryHandle.addToOutputList('deadtime')
1369  queryHandle.addToOutputList('bitnum')
1370  queryHandle.addToOutputList('bitname')
1371  queryHandle.addToOutputList('prescale')
1372  queryHandle.setCondition('runnum=:runnum',queryCondition)
1373  queryResult=coral.AttributeList()
1374  queryResult.extend('cmslsnum','unsigned int')
1375  queryResult.extend('trgcount','unsigned int')
1376  queryResult.extend('deadtime','unsigned long long')
1377  queryResult.extend('bitnum','unsigned int')
1378  queryResult.extend('bitname','string')
1379  queryResult.extend('prescale','unsigned int')
1380  queryHandle.defineOutput(queryResult)
1381  queryHandle.addToOrderList('bitnum')
1382  queryHandle.addToOrderList('cmslsnum')
1383  cursor=queryHandle.execute()
1384  while next(cursor):
1385  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1386  trgcount=cursor.currentRow()['trgcount'].data()
1387  deadtime=cursor.currentRow()['deadtime'].data()
1388  bitnum=cursor.currentRow()['bitnum'].data()
1389  bitname=cursor.currentRow()['bitname'].data()
1390  prescale=cursor.currentRow()['prescale'].data()
1391  if cmslsnum not in result:
1392  dataperLS={}
1393  dataperLS[bitname]=[bitnum,trgcount,deadtime,prescale]
1394  result[cmslsnum]=dataperLS
1395  else:
1396  result[cmslsnum][bitname]=[bitnum,trgcount,deadtime,prescale]
1397  return result
1398 
1399 
1400 def hltBypathByrun(queryHandle,runnum,hltpath):
1401  '''
1402  select cmslsnum,inputcount,acceptcount,prescale from hlt where runnum=:runnum and pathname=:pathname
1403  output: {cmslsnum:[inputcount,acceptcount,prescale]}
1404  '''
1405  result={}
1406  queryHandle.addToTableList(nameDealer.hltTableName())
1407  queryCondition=coral.AttributeList()
1408  queryCondition.extend('runnum','unsigned int')
1409  queryCondition.extend('pathname','string')
1410  queryCondition['runnum'].setData(int(runnum))
1411  queryCondition['pathname'].setData(hltpath)
1412  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1413  queryHandle.addToOutputList('INPUTCOUNT','inputcount')
1414  queryHandle.addToOutputList('ACCEPTCOUNT','acceptcount')
1415  queryHandle.addToOutputList('PRESCALE','prescale')
1416  queryHandle.setCondition('RUNNUM=:runnum and PATHNAME=:pathname',queryCondition)
1417  queryResult=coral.AttributeList()
1418  queryResult.extend('cmslsnum','unsigned int')
1419  queryResult.extend('inputcount','unsigned int')
1420  queryResult.extend('acceptcount','unsigned int')
1421  queryResult.extend('prescale','unsigned int')
1422  queryHandle.defineOutput(queryResult)
1423  cursor=queryHandle.execute()
1424  while next(cursor):
1425  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1426  inputcount=cursor.currentRow()['inputcount'].data()
1427  acceptcount=cursor.currentRow()['acceptcount'].data()
1428  prescale=cursor.currentRow()['prescale'].data()
1429  if cmslsnum not in result:
1430  result[cmslsnum]=[inputcount,acceptcount,prescale]
1431  return result
1432 
1433 def hltAllpathByrun(queryHandle,runnum):
1434  '''
1435  select cmslsnum,inputcount,acceptcount,prescale,pathname from hlt where runnum=:runnum
1436  this can be changed to blob query later
1437  output: {cmslsnum:{pathname:[inputcount,acceptcount,prescale]}}
1438  '''
1439  result={}
1440  queryHandle.addToTableList(nameDealer.hltTableName())
1441  queryCondition=coral.AttributeList()
1442  queryCondition.extend('runnum','unsigned int')
1443  queryCondition['runnum'].setData(int(runnum))
1444  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1445  queryHandle.addToOutputList('INPUTCOUNT','inputcount')
1446  queryHandle.addToOutputList('ACCEPTCOUNT','acceptcount')
1447  queryHandle.addToOutputList('PRESCALE','prescale')
1448  queryHandle.addToOutputList('PATHNAME','pathname')
1449  queryHandle.setCondition('RUNNUM=:runnum',queryCondition)
1450  queryResult=coral.AttributeList()
1451  queryResult.extend('cmslsnum','unsigned int')
1452  queryResult.extend('inputcount','unsigned int')
1453  queryResult.extend('acceptcount','unsigned int')
1454  queryResult.extend('prescale','unsigned int')
1455  queryResult.extend('pathname','string')
1456  queryHandle.defineOutput(queryResult)
1457  cursor=queryHandle.execute()
1458  while next(cursor):
1459  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1460  inputcount=cursor.currentRow()['inputcount'].data()
1461  acceptcount=cursor.currentRow()['acceptcount'].data()
1462  prescale=cursor.currentRow()['prescale'].data()
1463  pathname=cursor.currentRow()['pathname'].data()
1464  if cmslsnum not in result:
1465  dataperLS={}
1466  dataperLS[pathname]=[inputcount,acceptcount,prescale]
1467  result[cmslsnum]=dataperLS
1468  else:
1469  result[cmslsnum][pathname]=[inputcount,acceptcount,prescale]
1470  return result
1471 
1472 
1473 def beamIntensityForRun(query,parameters,runnum):
1474  '''
1475  select CMSBXINDEXBLOB,BEAMINTENSITYBLOB_1,BEAMINTENSITYBLOB_2 from LUMISUMMARY where runnum=146315 and LUMIVERSION='0001'
1476 
1477  output : result {startorbit: [(bxidx,beam1intensity,beam2intensity)]}
1478  '''
1479  result={} #{startorbit:[(bxidx,occlumi,occlumierr,beam1intensity,beam2intensity)]}
1480 
1481  lumisummaryOutput=coral.AttributeList()
1482  lumisummaryOutput.extend('cmslsnum','unsigned int')
1483  lumisummaryOutput.extend('startorbit','unsigned int')
1484  lumisummaryOutput.extend('bxindexblob','blob');
1485  lumisummaryOutput.extend('beamintensityblob1','blob');
1486  lumisummaryOutput.extend('beamintensityblob2','blob');
1487  condition=coral.AttributeList()
1488  condition.extend('runnum','unsigned int')
1489  condition.extend('lumiversion','string')
1490  condition['runnum'].setData(int(runnum))
1491  condition['lumiversion'].setData(parameters.lumiversion)
1492 
1493  query.addToTableList(parameters.lumisummaryname)
1494  query.addToOutputList('CMSLSNUM','cmslsnum')
1495  query.addToOutputList('STARTORBIT','startorbit')
1496  query.addToOutputList('CMSBXINDEXBLOB','bxindexblob')
1497  query.addToOutputList('BEAMINTENSITYBLOB_1','beamintensityblob1')
1498  query.addToOutputList('BEAMINTENSITYBLOB_2','beamintensityblob2')
1499  query.setCondition('RUNNUM=:runnum AND LUMIVERSION=:lumiversion',condition)
1500  query.defineOutput(lumisummaryOutput)
1501  cursor=query.execute()
1502  while next(cursor):
1503  #cmslsnum=cursor.currentRow()['cmslsnum'].data()
1504  startorbit=cursor.currentRow()['startorbit'].data()
1505  bxidx=[]
1506  bb1=[]
1507  bb2=[]
1508  bxindexblob=None
1509  beamintensityblob1=None
1510  beamintensityblob2=None
1511  if not cursor.currentRow()["bxindexblob"].isNull():
1512  bxindexblob=cursor.currentRow()['bxindexblob'].data()
1513  if bxindexblob and bxindexblob.readline()!=None:
1514  bxidx=CommonUtil.unpackBlobtoArray(bxindexblob,'h')
1515  if not cursor.currentRow()['beamintensityblob1'].isNull():
1516  beamintensityblob1=cursor.currentRow()['beamintensityblob1'].data()
1517  if beamintensityblob1 and beamintensityblob1.readline()!=None:
1518  bb1=CommonUtil.unpackBlobtoArray(beamintensityblob1,'f')
1519  if not cursor.currentRow()['beamintensityblob2'].isNull():
1520  beamintensityblob2=cursor.currentRow()['beamintensityblob2'].data()
1521  if beamintensityblob2 and beamintensityblob2.readline()!=None:
1522  bb2=CommonUtil.unpackBlobtoArray(beamintensityblob2,'f')
1523  if startorbit not in result:
1524  result[startorbit]=[]
1525  for idx,bxidxvalue in enumerate(bxidx):
1526  try:
1527  b1intensity=bb1[idx]
1528  except IndexError:
1529  b1intensity=0.0
1530  try:
1531  b2intensity=bb2[idx]
1532  except IndexError:
1533  b2intensity=0.0
1534  result[startorbit].append((bxidxvalue,b1intensity,b2intensity))
1535  del bxidx[:]
1536  del bb1[:]
1537  del bb2[:]
1538  return result
1539 
1540 def calibratedDetailForRunLimitresult(query,parameters,runnum,algoname='OCC1',finecorrection=None):
1541  '''select
1542  s.cmslsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality,d.algoname from LUMIDETAIL d,LUMISUMMARY s where s.runnum=133885 and d.algoname='OCC1' and s.lumisummary_id=d.lumisummary_id order by s.startorbit,s.cmslsnum
1543  result={(startorbit,cmslsnum):[(index,lumivalue,lumierr),]}
1544  '''
1545  result={}
1546  detailOutput=coral.AttributeList()
1547  detailOutput.extend('cmslsnum','unsigned int')
1548  detailOutput.extend('startorbit','unsigned int')
1549  detailOutput.extend('bxlumivalue','blob')
1550  detailOutput.extend('bxlumierror','blob')
1551  detailCondition=coral.AttributeList()
1552  detailCondition.extend('runnum','unsigned int')
1553  detailCondition.extend('algoname','string')
1554  detailCondition['runnum'].setData(runnum)
1555  detailCondition['algoname'].setData(algoname)
1556 
1557  query.addToTableList(parameters.lumisummaryname,'s')
1558  query.addToTableList(parameters.lumidetailname,'d')
1559  query.addToOutputList('s.CMSLSNUM','cmslsnum')
1560  query.addToOutputList('s.STARTORBIT','startorbit')
1561  query.addToOutputList('d.BXLUMIVALUE','bxlumivalue')
1562  query.addToOutputList('d.BXLUMIERROR','bxlumierror')
1563  query.addToOutputList('d.BXLUMIQUALITY','bxlumiquality')
1564  query.setCondition('s.RUNNUM=:runnum and d.ALGONAME=:algoname and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',detailCondition)
1565  query.defineOutput(detailOutput)
1566  cursor=query.execute()
1567  while next(cursor):
1568  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1569  bxlumivalue=cursor.currentRow()['bxlumivalue'].data()
1570  bxlumierror=cursor.currentRow()['bxlumierror'].data()
1571  startorbit=cursor.currentRow()['startorbit'].data()
1572  bxlumivalueArray=array.array('f')
1573  bxlumivalueArray.fromstring(bxlumivalue.readline())
1574  bxlumierrorArray=array.array('f')
1575  bxlumierrorArray.fromstring(bxlumierror.readline())
1576  xingLum=[]
1577  #apply selection criteria
1578  maxlumi=0.0
1579  if len(bxlumivalueArray)!=0:
1580  maxlumi=max(bxlumivalueArray)
1581  avginstlumi=0.0
1582  if len(bxlumivalueArray)!=0:
1583  avginstlumi=sum(bxlumivalueArray)
1584  for index,lum in enumerate(bxlumivalueArray):
1585  lumierror = bxlumierrorArray[index]
1586  if lum<max(parameters.xingMinLum,maxlumi*0.2):
1587  continue
1588  mynorm=parameters.normFactor
1589  if finecorrection:
1590  lum=lumiCorrections.applyfinecorrectionBX(lum,avginstlumi*mynorm,mynorm,finecorrection[0],finecorrection[1],finecorrection[2])
1591  lumierror=lumiCorrections.applyfinecorrectionBX(lumierror,avginstlumi*mynorm,mynorm,finecorrection[0],finecorrection[1],finecorrection[2])
1592  else:
1593  lum*=mynorm
1594  lumierror*=mynorm
1595  xingLum.append( (index,lum,lumierror) )
1596  if len(xingLum)!=0:
1597  result[(startorbit,cmslsnum)]=xingLum
1598  return result
1599 
1600 def lumidetailByrunByAlgo(queryHandle,runnum,algoname='OCC1'):
1601  '''
1602  select s.cmslsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality,s.startorbit from LUMIDETAIL d,LUMISUMMARY s where s.runnum=:runnum and d.algoname=:algoname and s.lumisummary_id=d.lumisummary_id order by s.startorbit
1603  output: [[cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit]]
1604  since the output is ordered by time, it has to be in seq list format
1605  '''
1606  result=[]
1607  queryHandle.addToTableList(nameDealer.lumidetailTableName(),'d')
1608  queryHandle.addToTableList(nameDealer.lumisummaryTableName(),'s')
1609  queryCondition=coral.AttributeList()
1610  queryCondition.extend('runnum','unsigned int')
1611  queryCondition.extend('algoname','string')
1612  queryCondition['runnum'].setData(int(runnum))
1613  queryCondition['algoname'].setData(algoname)
1614  queryHandle.addToOutputList('s.CMSLSNUM','cmslsnum')
1615  queryHandle.addToOutputList('d.BXLUMIVALUE','bxlumivalue')
1616  queryHandle.addToOutputList('d.BXLUMIERROR','bxlumierror')
1617  queryHandle.addToOutputList('d.BXLUMIQUALITY','bxlumiquality')
1618  queryHandle.addToOutputList('s.STARTORBIT','startorbit')
1619  queryHandle.setCondition('s.runnum=:runnum and d.algoname=:algoname and s.lumisummary_id=d.lumisummary_id',queryCondition)
1620  queryResult=coral.AttributeList()
1621  queryResult.extend('cmslsnum','unsigned int')
1622  queryResult.extend('bxlumivalue','blob')
1623  queryResult.extend('bxlumierror','blob')
1624  queryResult.extend('bxlumiquality','blob')
1625  queryResult.extend('startorbit','unsigned int')
1626  queryHandle.addToOrderList('s.STARTORBIT')
1627  queryHandle.defineOutput(queryResult)
1628  cursor=queryHandle.execute()
1629  while next(cursor):
1630  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1631  bxlumivalue=cursor.currentRow()['bxlumivalue'].data()
1632  bxlumierror=cursor.currentRow()['bxlumierror'].data()
1633  bxlumiquality=cursor.currentRow()['bxlumiquality'].data()
1634  startorbit=cursor.currentRow()['startorbit'].data()
1635  result.append([cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit])
1636  return result
1637 
1638 def lumidetailAllalgosByrun(queryHandle,runnum):
1639  '''
1640  select s.cmslsnum,d.bxlumivalue,d.bxlumierror,d.bxlumiquality,d.algoname,s.startorbit from LUMIDETAIL d,LUMISUMMARY s where s.runnum=:runnumber and s.lumisummary_id=d.lumisummary_id order by s.startorbit,d.algoname
1641  output: {algoname:{cmslsnum:[bxlumivalue,bxlumierror,bxlumiquality,startorbit]}}
1642  '''
1643  result={}
1644  queryHandle.addToTableList(nameDealer.lumidetailTableName(),'d')
1645  queryHandle.addToTableList(nameDealer.lumisummaryTableName(),'s')
1646  queryCondition=coral.AttributeList()
1647  queryCondition.extend('runnum','unsigned int')
1648  queryCondition['runnum'].setData(int(runnum))
1649  queryHandle.addToOutputList('s.CMSLSNUM','cmslsnum')
1650  queryHandle.addToOutputList('d.BXLUMIVALUE','bxlumivalue')
1651  queryHandle.addToOutputList('d.BXLUMIERROR','bxlumierror')
1652  queryHandle.addToOutputList('d.BXLUMIQUALITY','bxlumiquality')
1653  queryHandle.addToOutputList('d.ALGONAME','algoname')
1654  queryHandle.addToOutputList('s.STARTORBIT','startorbit')
1655  queryHandle.setCondition('s.RUNNUM=:runnum and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',queryCondition)
1656  queryResult=coral.AttributeList()
1657  queryResult.extend('cmslsnum','unsigned int')
1658  queryResult.extend('bxlumivalue','blob')
1659  queryResult.extend('bxlumierror','blob')
1660  queryResult.extend('bxlumiquality','blob')
1661  queryResult.extend('algoname','string')
1662  queryResult.extend('startorbit','unsigned int')
1663  queryHandle.addToOrderList('startorbit')
1664  queryHandle.addToOrderList('algoname')
1665  queryHandle.defineOutput(queryResult)
1666  cursor=queryHandle.execute()
1667  while next(cursor):
1668  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1669  bxlumivalue=cursor.currentRow()['bxlumivalue'].data()
1670  bxlumierror=cursor.currentRow()['bxlumierror'].data()
1671  bxlumiquality=cursor.currentRow()['bxlumiquality'].data()
1672  algoname=cursor.currentRow()['algoname'].data()
1673  startorbit=cursor.currentRow()['startorbit'].data()
1674  if algoname not in result:
1675  dataPerAlgo={}
1676  dataPerAlgo[cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]
1677  result[algoname]=dataPerAlgo
1678  else:
1679  result[algoname][cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]
1680  return result
1681 
1682 def hlttrgMappingByrun(queryHandle,runnum):
1683  '''
1684  select m.hltpathname,m.l1seed from cmsrunsummary r,trghltmap m where r.runnum=:runnum and m.hltkey=r.hltkey
1685  output: {hltpath:l1seed}
1686  '''
1687  result={}
1688  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName(),'r')
1689  queryHandle.addToTableList(nameDealer.trghltMapTableName(),'m')
1690  queryCondition=coral.AttributeList()
1691  queryCondition.extend('runnum','unsigned int')
1692  queryCondition['runnum'].setData(int(runnum))
1693  queryHandle.addToOutputList('m.HLTPATHNAME','hltpathname')
1694  queryHandle.addToOutputList('m.L1SEED','l1seed')
1695  queryHandle.setCondition('r.RUNNUM=:runnum and m.HLTKEY=r.HLTKEY',queryCondition)
1696  queryResult=coral.AttributeList()
1697  queryResult.extend('hltpathname','string')
1698  queryResult.extend('l1seed','string')
1699  queryHandle.defineOutput(queryResult)
1700  cursor=queryHandle.execute()
1701  while next(cursor):
1702  hltpathname=cursor.currentRow()['hltpathname'].data()
1703  l1seed=cursor.currentRow()['l1seed'].data()
1704  if hltpathname not in result:
1705  result[hltpathname]=l1seed
1706  return result
1707 
1708 def runsByfillrange(queryHandle,minFill,maxFill):
1709  '''
1710  find all runs in the fill range inclusive
1711  select runnum,fillnum from cmsrunsummary where fillnum>=:minFill and fillnum<=:maxFill
1712  output: fillDict={fillnum:[runlist]}
1713  '''
1714  result={}
1715  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
1716  queryCondition=coral.AttributeList()
1717  queryCondition.extend('minFill','unsigned int')
1718  queryCondition.extend('maxFill','unsigned int')
1719  queryCondition['minFill'].setData(int(minFill))
1720  queryCondition['maxFill'].setData(int(maxFill))
1721  queryHandle.addToOutputList('RUNNUM','runnum')
1722  queryHandle.addToOutputList('FILLNUM','fillnum')
1723  queryHandle.setCondition('FILLNUM>=:minFill and FILLNUM<=:maxFill',queryCondition)
1724  queryResult=coral.AttributeList()
1725  queryResult.extend('runnum','unsigned int')
1726  queryResult.extend('fillnum','unsigned int')
1727  queryHandle.defineOutput(queryResult)
1728  cursor=queryHandle.execute()
1729  while next(cursor):
1730  runnum=cursor.currentRow()['runnum'].data()
1731  fillnum=cursor.currentRow()['fillnum'].data()
1732  if fillnum not in result:
1733  result[fillnum]=[runnum]
1734  else:
1735  result[fillnum].append(runnum)
1736  return result
1737 
1738 def runsByTimerange(queryHandle,minTime,maxTime):
1739  '''
1740  find all runs in the time range inclusive
1741  the selected run must have started after minTime and finished by maxTime
1742  select runnum,to_char(startTime),to_char(stopTime) from cmsrunsummary where startTime>=timestamp(minTime) and stopTime<=timestamp(maxTime);
1743  input: minTime,maxTime in python obj datetime.datetime
1744  output: {runnum:[starttime,stoptime]} return in python obj datetime.datetime
1745  '''
1746  t=lumiTime.lumiTime()
1747  result={}
1748  coralminTime=coral.TimeStamp(minTime.year,minTime.month,minTime.day,minTime.hour,minTime.minute,minTime.second,0)
1749  coralmaxTime=coral.TimeStamp(maxTime.year,maxTime.month,maxTime.day,maxTime.hour,maxTime.minute,maxTime.second,0)
1750  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
1751  queryCondition=coral.AttributeList()
1752  queryCondition.extend('minTime','time stamp')
1753  queryCondition.extend('maxTime','time stamp')
1754  queryCondition['minTime'].setData(coralminTime)
1755  queryCondition['maxTime'].setData(coralmaxTime)
1756  queryHandle.addToOutputList('RUNNUM','runnum')
1757  queryHandle.addToOutputList('TO_CHAR(STARTTIME,\''+t.coraltimefm+'\')','starttime')
1758  queryHandle.addToOutputList('TO_CHAR(STOPTIME,\''+t.coraltimefm+'\')','stoptime')
1759  queryHandle.setCondition('STARTTIME>=:minTime and STOPTIME<=:maxTime',queryCondition)
1760  queryResult=coral.AttributeList()
1761  queryResult.extend('runnum','unsigned int')
1762  queryResult.extend('starttime','string')
1763  queryResult.extend('stoptime','string')
1764  queryHandle.defineOutput(queryResult)
1765  cursor=queryHandle.execute()
1766  while next(cursor):
1767  runnum=cursor.currentRow()['runnum'].data()
1768  starttimeStr=cursor.currentRow()['starttime'].data()
1769  stoptimeStr=cursor.currentRow()['stoptime'].data()
1770  if runnum not in result:
1771  result[runnum]=[t.StrToDatetime(starttimeStr),t.StrToDatetime(stoptimeStr)]
1772  return result
1773 
1774 if __name__=='__main__':
1775  msg=coral.MessageStream('')
1776  #msg.setMsgVerbosity(coral.message_Level_Debug)
1777  msg.setMsgVerbosity(coral.message_Level_Error)
1778  os.environ['CORAL_AUTH_PATH']='/afs/cern.ch/cms/DB/lumi'
1779  svc = coral.ConnectionService()
1780  connectstr='oracle://cms_orcoff_prod/cms_lumi_prod'
1781  session=svc.connect(connectstr,accessMode=coral.access_ReadOnly)
1782  session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
1783  session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
1784  session.transaction().start(True)
1785  schema=session.nominalSchema()
1786  allruns=allruns(schema,requireLumisummary=True,requireTrg=True,requireHlt=True)
1787  print('allruns in runsummary and lumisummary and trg and hlt ',len(allruns))
1788  #q=schema.newQuery()
1789  #runsummaryOut=runsummaryByrun(q,139400)
1790  #del q
1791  #q=schema.newQuery()
1792  #lumisummaryOut=lumisummaryByrun(q,139400,'0001')
1793  #del q
1794  #q=schema.newQuery()
1795  #lumisummaryOutStablebeam7TeV=lumisummaryByrun(q,139400,'0001',beamstatus='STABLE BEAMS',beamenergy=3.5E003,beamenergyfluctuation=0.09)
1796  #del q
1797  #q=schema.newQuery()
1798  #lumitotal=lumisumByrun(q,139400,'0001')
1799  #del q
1800  #q=schema.newQuery()
1801  #lumitotalStablebeam7TeV=lumisumByrun(q,139400,'0001',beamstatus='STABLE BEAMS',beamenergy=3.5E003,beamenergyfluctuation=0.09)
1802  #del q
1803  #q=schema.newQuery()
1804  #trgbitzero=trgbitzeroByrun(q,139400)
1805  #del q
1806  #q=schema.newQuery()
1807  #lumijointrg=lumisummarytrgbitzeroByrun(q,135525,'0001')
1808  #del q
1809  #q=schema.newQuery()
1810  #lumijointrgStablebeam7TeV=lumisummarytrgbitzeroByrun(q,135525,'0001',beamstatus='STABLE BEAMS',beamenergy=3.5E003,beamenergyfluctuation=0.09)
1811  #del q
1812  #q=schema.newQuery()
1813  #trgforbit=trgBybitnameByrun(q,139400,'L1_ZeroBias')
1814  #del q
1815  #q=schema.newQuery()
1816  #trgallbits=trgAllbitsByrun(q,139400)
1817  #del q
1818  #q=schema.newQuery()
1819  #hltbypath=hltBypathByrun(q,139400,'HLT_Mu5')
1820  #del q
1821  #q=schema.newQuery()
1822  #hltallpath=hltAllpathByrun(q,139400)
1823  #del q
1824  #q=schema.newQuery()
1825  #hlttrgmap=hlttrgMappingByrun(q,139400)
1826  #del q
1827  #q=schema.newQuery()
1828  #occ1detail=lumidetailByrunByAlgo(q,139400,'OCC1')
1829  #del q
1830  #q=schema.newQuery()
1831  #alldetail=lumidetailAllalgosByrun(q,139400)
1832  #del q
1833  #q=schema.newQuery()
1834  #runsbyfill=runsByfillrange(q,1150,1170)
1835  #del q
1836  #now=datetime.datetime.now()
1837  #aweek=datetime.timedelta(weeks=1)
1838  #lastweek=now-aweek
1839  #print lastweek
1840  #q=schema.newQuery()
1841  #runsinaweek=runsByTimerange(q,lastweek,now)
1842  #del q
1843  q=schema.newQuery()
1844  allfills=allfills(q)
1845  del q
1846  session.transaction().commit()
1847  del session
1848  del svc
1849  #print 'runsummaryByrun : ',runsummaryOut
1850  #print
1851  #print 'lumisummaryByrun : ',lumisummaryOut
1852  #print '######'
1853  #print 'lumisummaryByrun stable beams 7TeV : ',lumisummaryOutStablebeam7TeV
1854  #print '######'
1855  #print 'totallumi : ',lumitotal
1856  #print
1857  #print
1858  #print 'totallumi stable beam and 7TeV: ',lumitotalStablebeam7TeV
1859  #print
1860  #print 'trgbitzero : ',trgbitzero
1861  #print
1862  #print 'lumijointrg : ', lumijointrg
1863  #print 'total LS : ',len(lumijointrg)
1864  #print 'lumijointrg stable beams 7TeV :', lumijointrgStablebeam7TeV
1865  #print 'total LS : ',len(lumijointrgStablebeam7TeV)
1866  #print 'trgforbit L1_ZeroBias ',trgforbit
1867  #print
1868  #print 'trgallbits ',trgallbits[1] #big query. be aware of speed
1869  #print
1870  #print 'hltforpath HLT_Mu5',hltbypath
1871  #print
1872  #print 'hltallpath ',hltallpath
1873  #print
1874  #print 'hlttrgmap ',hlttrgmap
1875  #print
1876  #print 'lumidetail occ1 ',len(occ1detail)
1877  #print
1878  #print 'runsbyfill ',runsbyfill
1879  #print
1880  #print 'runsinaweek ',runsinaweek.keys()
1881  print('all fills ',allfills)
def mergeXingLumi(triplet, xingLumiDict)
Definition: start.py:1
def printDeliveredLumi(lumidata, mode)
def splitlistToRangeString(inPut)
def getDeadfractions(deadtable)
def deliveredLumiForRun(dbsession, parameters, runnum, finecorrections=None)
def trgbitzeroByrun(queryHandle, runnum)
def printPerLSLumi(lumidata, isVerbose=False)
def calculateTotalRecorded(deadtable)
def validation(queryHandle, run=None, cmsls=None)
def lumidetailByrunByAlgo(queryHandle, runnum, algoname='OCC1')
def setupSession(connectString, siteconfpath, parameters, debug=False)
def flatten(obj)
def unpackBlobtoArray(iblob, itemtypecode)
Definition: CommonUtil.py:231
def hltBypathByrun(queryHandle, runnum, hltpath)
def hlttrgMappingByrun(queryHandle, runnum)
def lumidetailAllalgosByrun(queryHandle, runnum)
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 runsummaryByrun(queryHandle, runnum)
def dumpPerLSLumi(lumidata)
def lumisummaryTableName()
Definition: nameDealer.py:25
def trgAllbitsByrun(queryHandle, runnum)
def calculateEffective(trgtable, totalrecorded)
def printRecordedLumi(lumidata, isVerbose=False, hltpath='')
def beamIntensityForRun(query, parameters, runnum)
def filterDeadtable(inTable, lslist)
def deliveredLumiForRange(dbsession, parameters, inputRange, finecorrections=None)
Definition: lumiQueryAPI.py:86
def lslengthsec(numorbit, numbx)
Definition: lumiQueryAPI.py:59
def runsByfillrange(queryHandle, minFill, maxFill)
==============temporarilly here======###
Definition: lumiQueryAPI.py:26
def recordedLumiForRange(dbsession, parameters, inputRange, finecorrections=None)
def printOverviewData(delivered, recorded, hltpath='')
def lumivalidationTableName()
Definition: nameDealer.py:85
def runsByTimerange(queryHandle, minTime, maxTime)
def xingLuminosityForRun(dbsession, runnum, parameters, lumiXingDict={}, maxLumiSection=None, finecorrections=None)
def dumpData(lumidata, filename)
def recordedLumiForRun(dbsession, parameters, runnum, lslist=None, finecorrections=None)
def dumpRecordedLumi(lumidata, hltpath='')
def calibratedDetailForRunLimitresult(query, parameters, runnum, algoname='OCC1', finecorrection=None)
def hltTableName()
Definition: nameDealer.py:55
def lsBylsLumi(deadtable)
Definition: lumiQueryAPI.py:64
def lumisummaryByrun(queryHandle, runnum, lumiversion, beamstatus=None, beamenergy=None, beamenergyfluctuation=0.09, finecorrections=None)
def count_dups(l)
Definition: CommonUtil.py:139
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def lumisummarytrgbitzeroByrun(queryHandle, runnum, lumiversion, beamstatus=None, beamenergy=None, beamenergyfluctuation=0.09, finecorrections=None)
def lumisumByrun(queryHandle, runnum, lumiversion, beamstatus=None, beamenergy=None, beamenergyfluctuation=0.09, finecorrections=None)
def cmsrunsummaryTableName()
Definition: nameDealer.py:16
def dumpOverview(delivered, recorded, hltpath='')
def trghltMapTableName()
Definition: nameDealer.py:76
def hltAllpathByrun(queryHandle, runnum)
def trgBybitnameByrun(queryHandle, runnum, bitname)