CMS 3D CMS Logo

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