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