CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions | Variables
lumiQueryAPI Namespace Reference

Classes

class  ParametersObject
 ==============temporarilly here======### More...
 

Functions

def allfills
 
def allruns
 ==============real api=====### More...
 
def beamIntensityForRun
 
def calculateEffective
 
def calculateTotalRecorded
 
def calibratedDetailForRunLimitresult
 
def deliveredLumiForRange
 
def deliveredLumiForRun
 
def dumpData
 
def dumpOverview
 
def dumpPerLSLumi
 
def dumpRecordedLumi
 
def filterDeadtable
 
def flatten
 
def getDeadfractions
 
def hltAllpathByrun
 
def hltBypathByrun
 
def hlttrgMappingByrun
 
def lsBylsLumi
 
def lslengthsec
 
def lumidetailAllalgosByrun
 
def lumidetailByrunByAlgo
 
def lumisumByrun
 
def lumisummaryByrun
 
def lumisummarytrgbitzeroByrun
 
def mergeXingLumi
 
def printDeliveredLumi
 
def printOverviewData
 
def printPerLSLumi
 
def printRecordedLumi
 
def recordedLumiForRange
 
def recordedLumiForRun
 
def runsByfillrange
 
def runsByTimerange
 
def runsummaryByrun
 
def setupSession
 
def splitlistToRangeString
 
def trgAllbitsByrun
 
def trgbitzeroByrun
 
def trgBybitnameByrun
 
def validation
 
def xingLuminosityForRun
 

Variables

tuple allfills = allfills(q)
 
tuple allruns = allruns(schema,requireLumisummary=True,requireTrg=True,requireHlt=True)
 
string connectstr = 'oracle://cms_orcoff_prod/cms_lumi_prod'
 
tuple msg = coral.MessageStream('')
 
tuple q = schema.newQuery()
 
tuple schema = session.nominalSchema()
 
tuple session = svc.connect(connectstr,accessMode=coral.access_ReadOnly)
 
tuple svc = coral.ConnectionService()
 

Function Documentation

def lumiQueryAPI.allfills (   queryHandle,
  filtercrazy = True 
)
select distinct fillnum from cmsrunsummary
there are crazy fill numbers. we assume they are not valid runs

Definition at line 1020 of file lumiQueryAPI.py.

References allfills, nameDealer.cmsrunsummaryTableName(), and runTheMatrix.data.

Referenced by lumiSumPlot.main().

1021 def allfills(queryHandle,filtercrazy=True):
1022  '''select distinct fillnum from cmsrunsummary
1023  there are crazy fill numbers. we assume they are not valid runs
1024  '''
1025  result=[]
1026  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
1027  queryHandle.addToOutputList('distinct FILLNUM','fillnum')
1028 
1029  if filtercrazy:
1030  queryCondition='FILLNUM>:zero and FILLNUM<:crazybig'
1031  queryBind=coral.AttributeList()
1032  queryBind.extend('zero','unsigned int')
1033  queryBind.extend('crazybig','unsigned int')
1034  queryBind['zero'].setData(int(0))
1035  queryBind['crazybig'].setData(int(29701))
1036  queryHandle.setCondition(queryCondition,queryBind)
1037  queryResult=coral.AttributeList()
1038  queryResult.extend('fillnum','unsigned int')
1039  queryHandle.defineOutput(queryResult)
1040  cursor=queryHandle.execute()
1041  while cursor.next():
1042  result.append(cursor.currentRow()['fillnum'].data())
1043  result.sort()
return result
def cmsrunsummaryTableName
Definition: nameDealer.py:14
def lumiQueryAPI.allruns (   schemaHandle,
  requireRunsummary = True,
  requireLumisummary = False,
  requireTrg = False,
  requireHlt = False 
)

==============real api=====###

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.

Definition at line 902 of file lumiQueryAPI.py.

References allruns, nameDealer.cmsrunsummaryTableName(), CommonUtil.count_dups(), runTheMatrix.data, nameDealer.hltTableName(), nameDealer.lumisummaryTableName(), and nameDealer.trgTableName().

Referenced by lumiPlotFiller.create2011RunList(), lumiPlotFiller.createRunList(), dumpPrescale.main(), and lumiSumPlot.main().

903 def allruns(schemaHandle,requireRunsummary=True,requireLumisummary=False,requireTrg=False,requireHlt=False):
904  '''
905  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.
906  '''
907  if not requireRunsummary and not requireLumiummary and not requireTrg and not requireHlt:
908  print 'must require at least one table'
909  raise
910  runresult=[]
911  runlist=[]
912  numdups=0
913  if requireRunsummary:
914  numdups=numdups+1
915  queryHandle=schemaHandle.newQuery()
916  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
917  queryHandle.addToOutputList("RUNNUM","run")
918  #queryBind=coral.AttributeList()
919  result=coral.AttributeList()
920  result.extend("run","unsigned int")
921  queryHandle.defineOutput(result)
922  cursor=queryHandle.execute()
923  while cursor.next():
924  r=cursor.currentRow()['run'].data()
925  runlist.append(r)
926  del queryHandle
927  if requireLumisummary:
928  numdups=numdups+1
929  queryHandle=schemaHandle.newQuery()
930  queryHandle.addToTableList(nameDealer.lumisummaryTableName())
931  queryHandle.addToOutputList("distinct RUNNUM","run")
932  #queryBind=coral.AttributeList()
933  result=coral.AttributeList()
934  result.extend("run","unsigned int")
935  queryHandle.defineOutput(result)
936  cursor=queryHandle.execute()
937  while cursor.next():
938  r=cursor.currentRow()['run'].data()
939  runlist.append(r)
940  del queryHandle
941  if requireTrg:
942  numdups=numdups+1
943  queryHandle=schemaHandle.newQuery()
944  queryHandle.addToTableList(nameDealer.trgTableName())
945  queryHandle.addToOutputList("distinct RUNNUM","run")
946  #queryBind=coral.AttributeList()
947  result=coral.AttributeList()
948  result.extend("run","unsigned int")
949  queryHandle.defineOutput(result)
950  cursor=queryHandle.execute()
951  while cursor.next():
952  r=cursor.currentRow()['run'].data()
953  runlist.append(r)
954  del queryHandle
955  if requireHlt:
956  numdups=numdups+1
957  queryHandle=schemaHandle.newQuery()
958  queryHandle.addToTableList(nameDealer.hltTableName())
959  queryHandle.addToOutputList("distinct RUNNUM","run")
960  #queryBind=coral.AttributeList()
961  result=coral.AttributeList()
962  result.extend("run","unsigned int")
963  queryHandle.defineOutput(result)
964  cursor=queryHandle.execute()
965  while cursor.next():
966  r=cursor.currentRow()['run'].data()
967  runlist.append(r)
968  del queryHandle
969  dupresult=CommonUtil.count_dups(runlist)
970  for dup in dupresult:
971  if dup[1]==numdups:
972  runresult.append(dup[0])
973  runresult.sort()
974  return runresult
def lumisummaryTableName
Definition: nameDealer.py:20
def hltTableName
Definition: nameDealer.py:38
def count_dups
Definition: CommonUtil.py:43
def trgTableName
Definition: nameDealer.py:35
def cmsrunsummaryTableName
Definition: nameDealer.py:14
def lumiQueryAPI.beamIntensityForRun (   query,
  parameters,
  runnum 
)
select CMSBXINDEXBLOB,BEAMINTENSITYBLOB_1,BEAMINTENSITYBLOB_2 from LUMISUMMARY where runnum=146315 and LUMIVERSION='0001'

output : result {startorbit: [(bxidx,beam1intensity,beam2intensity)]}

Definition at line 1437 of file lumiQueryAPI.py.

References python.multivaluedict.append(), and runTheMatrix.data.

Referenced by specificLumi-2011.getSpecificLumi(), and specificLumi.getSpecificLumi().

1438 def beamIntensityForRun(query,parameters,runnum):
1439  '''
1440  select CMSBXINDEXBLOB,BEAMINTENSITYBLOB_1,BEAMINTENSITYBLOB_2 from LUMISUMMARY where runnum=146315 and LUMIVERSION='0001'
1441 
1442  output : result {startorbit: [(bxidx,beam1intensity,beam2intensity)]}
1443  '''
1444  result={} #{startorbit:[(bxidx,occlumi,occlumierr,beam1intensity,beam2intensity)]}
1445 
1446  lumisummaryOutput=coral.AttributeList()
1447  lumisummaryOutput.extend('cmslsnum','unsigned int')
1448  lumisummaryOutput.extend('startorbit','unsigned int')
1449  lumisummaryOutput.extend('bxindexblob','blob');
1450  lumisummaryOutput.extend('beamintensityblob1','blob');
1451  lumisummaryOutput.extend('beamintensityblob2','blob');
1452  condition=coral.AttributeList()
1453  condition.extend('runnum','unsigned int')
1454  condition.extend('lumiversion','string')
1455  condition['runnum'].setData(int(runnum))
1456  condition['lumiversion'].setData(parameters.lumiversion)
1457 
1458  query.addToTableList(parameters.lumisummaryname)
1459  query.addToOutputList('CMSLSNUM','cmslsnum')
1460  query.addToOutputList('STARTORBIT','startorbit')
1461  query.addToOutputList('CMSBXINDEXBLOB','bxindexblob')
1462  query.addToOutputList('BEAMINTENSITYBLOB_1','beamintensityblob1')
1463  query.addToOutputList('BEAMINTENSITYBLOB_2','beamintensityblob2')
1464  query.setCondition('RUNNUM=:runnum AND LUMIVERSION=:lumiversion',condition)
1465  query.defineOutput(lumisummaryOutput)
1466  cursor=query.execute()
1467  while cursor.next():
1468  #cmslsnum=cursor.currentRow()['cmslsnum'].data()
1469  startorbit=cursor.currentRow()['startorbit'].data()
1470  if not cursor.currentRow()["bxindexblob"].isNull():
1471  bxindexblob=cursor.currentRow()['bxindexblob'].data()
1472  beamintensityblob1=cursor.currentRow()['beamintensityblob1'].data()
1473  beamintensityblob2=cursor.currentRow()['beamintensityblob2'].data()
1474  if bxindexblob.readline() is not None and beamintensityblob1.readline() is not None and beamintensityblob2.readline() is not None:
1475  bxidx=array.array('h')
1476  bxidx.fromstring(bxindexblob.readline())
1477  bb1=array.array('f')
1478  bb1.fromstring(beamintensityblob1.readline())
1479  bb2=array.array('f')
1480  bb2.fromstring(beamintensityblob2.readline())
1481  for index,bxidxvalue in enumerate(bxidx):
1482  if not result.has_key(startorbit):
1483  result[startorbit]=[]
1484  b1intensity=bb1[index]
1485  b2intensity=bb2[index]
1486  result[startorbit].append((bxidxvalue,b1intensity,b2intensity))
1487  return result
def beamIntensityForRun
def lumiQueryAPI.calculateEffective (   trgtable,
  totalrecorded 
)
input: trgtable{hltpath:[l1seed, hltprescale, l1prescale]}, totalrecorded (float)
output:{hltpath, recorded}

Definition at line 430 of file lumiQueryAPI.py.

431 def calculateEffective (trgtable, totalrecorded):
432  """
433  input: trgtable{hltpath:[l1seed, hltprescale, l1prescale]}, totalrecorded (float)
434  output:{hltpath, recorded}
435  """
436  #print 'inputtrgtable', trgtable
437  result = {}
438  for hltpath, data in trgtable.items():
439  if len (data) == 3:
440  result[hltpath] = totalrecorded/ (data[1]*data[2])
441  else:
442  result[hltpath] = 0.0
443  return result
444 
def calculateEffective
def lumiQueryAPI.calculateTotalRecorded (   deadtable)
input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]}
output: recordedLumi

Definition at line 395 of file lumiQueryAPI.py.

396 def calculateTotalRecorded (deadtable):
397  """
398  input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]}
399  output: recordedLumi
400  """
401  recordedLumi = 0.0
402  for myls, d in deadtable.items():
403  instLumi = d[1]
404  #deadfrac = float (d[0])/float (d[2]*3564)
405  #print myls, float (d[2])
406  if float (d[2]) == 0.0:
407  deadfrac = 1.0
408  else:
409  deadfrac = float (d[0])/(float (d[2])*float (d[-1]))
410  lstime = lslengthsec (d[3], 3564)
411  recordedLumi += instLumi* (1.0-deadfrac)*lstime
412  return recordedLumi
413 
def calculateTotalRecorded
def lumiQueryAPI.calibratedDetailForRunLimitresult (   query,
  parameters,
  runnum,
  algoname = 'OCC1' 
)
select 
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
result={(startorbit,cmslsnum):[(lumivalue,lumierr),]}

Definition at line 1488 of file lumiQueryAPI.py.

References runTheMatrix.data, and max().

Referenced by specificLumi-2011.getSpecificLumi(), and specificLumi.getSpecificLumi().

1489 def calibratedDetailForRunLimitresult(query,parameters,runnum,algoname='OCC1'):
1490  '''select
1491  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
1492  result={(startorbit,cmslsnum):[(lumivalue,lumierr),]}
1493  '''
1494  result={}
1495  detailOutput=coral.AttributeList()
1496  detailOutput.extend('cmslsnum','unsigned int')
1497  detailOutput.extend('startorbit','unsigned int')
1498  detailOutput.extend('bxlumivalue','blob')
1499  detailOutput.extend('bxlumierror','blob')
1500  detailCondition=coral.AttributeList()
1501  detailCondition.extend('runnum','unsigned int')
1502  detailCondition.extend('algoname','string')
1503  detailCondition['runnum'].setData(runnum)
1504  detailCondition['algoname'].setData(algoname)
1505 
1506  query.addToTableList(parameters.lumisummaryname,'s')
1507  query.addToTableList(parameters.lumidetailname,'d')
1508  query.addToOutputList('s.CMSLSNUM','cmslsnum')
1509  query.addToOutputList('s.STARTORBIT','startorbit')
1510  query.addToOutputList('d.BXLUMIVALUE','bxlumivalue')
1511  query.addToOutputList('d.BXLUMIERROR','bxlumierror')
1512  query.addToOutputList('d.BXLUMIQUALITY','bxlumiquality')
1513  query.setCondition('s.RUNNUM=:runnum and d.ALGONAME=:algoname and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',detailCondition)
1514  query.defineOutput(detailOutput)
1515  cursor=query.execute()
1516  while cursor.next():
1517  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1518  bxlumivalue=cursor.currentRow()['bxlumivalue'].data()
1519  bxlumierror=cursor.currentRow()['bxlumierror'].data()
1520  startorbit=cursor.currentRow()['startorbit'].data()
1521 
1522  bxlumivalueArray=array.array('f')
1523  bxlumivalueArray.fromstring(bxlumivalue.readline())
1524  bxlumierrorArray=array.array('f')
1525  bxlumierrorArray.fromstring(bxlumierror.readline())
1526  xingLum=[]
1527  #apply selection criteria
1528  maxlumi=max(bxlumivalueArray)*parameters.normFactor
1529  for index,lum in enumerate(bxlumivalueArray):
1530  lum *= parameters.normFactor
1531  lumierror = bxlumierrorArray[index]*parameters.normFactor
1532  if lum<max(parameters.xingMinLum,maxlumi*0.2):
1533  continue
1534  xingLum.append( (index,lum,lumierror) )
1535  if len(xingLum)!=0:
1536  result[(startorbit,cmslsnum)]=xingLum
1537  return result
const T & max(const T &a, const T &b)
def calibratedDetailForRunLimitresult
def lumiQueryAPI.deliveredLumiForRange (   dbsession,
  parameters,
  inputRange 
)
Takes either single run as a string or dictionary of run ranges

Definition at line 82 of file lumiQueryAPI.py.

82 
83 def deliveredLumiForRange (dbsession, parameters, inputRange):
84  '''Takes either single run as a string or dictionary of run ranges'''
85  lumidata = []
86  # is this a single string?
87  if isinstance (inputRange, str):
88  lumidata.append( deliveredLumiForRun (dbsession, parameters, inputRange) )
89  else:
90  # if not, it's one of these dictionary things
91  for run in sorted( inputRange.runs() ):
92  if parameters.verbose:
93  print "run", run
94  lumidata.append( deliveredLumiForRun (dbsession, parameters, run) )
95  #print lumidata
96  return lumidata
97 
def deliveredLumiForRange
Definition: lumiQueryAPI.py:82
def lumiQueryAPI.deliveredLumiForRun (   dbsession,
  parameters,
  runnum 
)
select sum (INSTLUMI), count (INSTLUMI) from lumisummary where runnum = 124025 and lumiversion = '0001';
select INSTLUMI,NUMORBIT  from lumisummary where runnum = 124025 and lumiversion = '0001'
query result unit E27cm^-2 (= 1 / mb)

Definition at line 143 of file lumiQueryAPI.py.

References runTheMatrix.data, lslengthsec(), and nameDealer.lumisummaryTableName().

144 def deliveredLumiForRun (dbsession, parameters, runnum):
145  """
146  select sum (INSTLUMI), count (INSTLUMI) from lumisummary where runnum = 124025 and lumiversion = '0001';
147  select INSTLUMI,NUMORBIT from lumisummary where runnum = 124025 and lumiversion = '0001'
148  query result unit E27cm^-2 (= 1 / mb)"""
149  #if parameters.verbose:
150  # print 'deliveredLumiForRun : norm : ', parameters.norm, ' : run : ', runnum
151  #output ['run', 'totalls', 'delivered', 'beammode']
152  delivered = 0.0
153  totalls = 0
154  try:
155  conditionstring="RUNNUM = :runnum AND LUMIVERSION = :lumiversion"
156  dbsession.transaction().start (True)
157  schema = dbsession.nominalSchema()
158  query = schema.tableHandle (nameDealer.lumisummaryTableName()).newQuery()
159  #query.addToOutputList ("sum (INSTLUMI)", "totallumi")
160  #query.addToOutputList ("count (INSTLUMI)", "totalls")
161  query.addToOutputList("INSTLUMI",'instlumi')
162  query.addToOutputList ("NUMORBIT", "norbits")
163  queryBind = coral.AttributeList()
164  queryBind.extend ("runnum", "unsigned int")
165  queryBind.extend ("lumiversion", "string")
166  queryBind["runnum"].setData (int (runnum))
167  queryBind["lumiversion"].setData (parameters.lumiversion)
168  #print parameters.beammode
169  if len(parameters.beammode)!=0:
170  conditionstring=conditionstring+' and BEAMSTATUS=:beamstatus'
171  queryBind.extend('beamstatus','string')
172  queryBind['beamstatus'].setData(parameters.beammode)
173  result = coral.AttributeList()
174  result.extend ("instlumi", "float")
175  result.extend ("norbits", "unsigned int")
176  query.defineOutput (result)
177  query.setCondition (conditionstring,queryBind)
178  #query.limitReturnedRows (1)
179  #query.groupBy ('NUMORBIT')
180  cursor = query.execute()
181  while cursor.next():
182  instlumi = cursor.currentRow()['instlumi'].data()
183  norbits = cursor.currentRow()['norbits'].data()
184 
185  if instlumi is not None and norbits is not None:
186  lstime = lslengthsec(norbits, parameters.NBX)
187  delivered=delivered+instlumi*parameters.norm*lstime
188  totalls+=1
189  del query
190  dbsession.transaction().commit()
191  lumidata = []
192  if delivered == 0.0:
193  lumidata = [str (runnum), 'N/A', 'N/A', 'N/A']
194  else:
195  lumidata = [str (runnum), str (totalls), '%.3f'%delivered, parameters.beammode]
196  return lumidata
197  except Exception, e:
198  print str (e)
199  dbsession.transaction().rollback()
200  del dbsession
def lumisummaryTableName
Definition: nameDealer.py:20
def deliveredLumiForRun
def lumiQueryAPI.dumpData (   lumidata,
  filename 
)
input params: lumidata [{'fieldname':value}]
              filename csvname

Definition at line 386 of file lumiQueryAPI.py.

Referenced by CastorDbXml.dumpObject(), and HcalDbXml.dumpObject().

387 def dumpData (lumidata, filename):
388  """
389  input params: lumidata [{'fieldname':value}]
390  filename csvname
391  """
392 
393  r = csvReporter.csvReporter(filename)
394  r.writeRows(lumidata)
def lumiQueryAPI.dumpOverview (   delivered,
  recorded,
  hltpath = '' 
)

Definition at line 736 of file lumiQueryAPI.py.

References xingLuminosityForRun().

737 def dumpOverview (delivered, recorded, hltpath = ''):
738  #toprowlabels = ['run', 'delivered', 'recorded', 'hltpath']
739  datatable = []
740  for runidx, deliveredrowdata in enumerate (delivered):
741  rowdata = []
742  rowdata += [deliveredrowdata[0], deliveredrowdata[2]]
743  if deliveredrowdata[1] == 'N/A': #run does not exist
744  rowdata += ['N/A', 'N/A']
745  datatable.append (rowdata)
746  continue
747  recordedLumi = calculateTotalRecorded (recorded[runidx][2])
748  lumiinPaths = calculateEffective (recorded[runidx][1], recordedLumi)
749  if hltpath != '' and hltpath != 'all':
750  if lumiinPaths.has_key (hltpath):
751  rowdata += [recordedLumi, lumiinPaths[hltpath]]
752  else:
753  rowdata += [recordedLumi, 'N/A']
754  else:
755  rowdata += [recordedLumi, recordedLumi]
756  datatable.append (rowdata)
757  return datatable
758 
def lumiQueryAPI.dumpPerLSLumi (   lumidata)

Definition at line 499 of file lumiQueryAPI.py.

500 def dumpPerLSLumi (lumidata):
501  datatodump = []
502  for perrundata in lumidata:
503  runnumber = perrundata[0]
504  deadtable = perrundata[2]
505  lumiresult = lsBylsLumi (deadtable)
506  for lsnum, dataperls in lumiresult.items():
507  rowdata = []
508  if len (dataperls) == 0:
509  rowdata += [str (runnumber), str (lsnum), 'N/A', 'N/A']
510  else:
511  rowdata += [str (runnumber), str (lsnum), dataperls[0], dataperls[1]]
512  if len (dataperls) > 2:
513  rowdata.extend ( flatten (dataperls[2:]) )
514  datatodump.append (rowdata)
515  return datatodump
516 
def lumiQueryAPI.dumpRecordedLumi (   lumidata,
  hltpath = '' 
)

Definition at line 626 of file lumiQueryAPI.py.

627 def dumpRecordedLumi (lumidata, hltpath = ''):
628  #labels = ['Run', 'HLT path', 'Recorded']
629  datatodump = []
630  for dataperRun in lumidata:
631  runnum = dataperRun[0]
632  if len (dataperRun[1]) == 0:
633  rowdata = []
634  rowdata += [str (runnum)]+2*['N/A']
635  datatodump.append (rowdata)
636  continue
637  perlsdata = dataperRun[2]
638  recordedLumi = 0.0
639  #norbits = perlsdata.values()[0][3]
640  recordedLumi = calculateTotalRecorded (perlsdata)
641  trgdict = dataperRun[1]
642  effective = calculateEffective (trgdict, recordedLumi)
643  if trgdict.has_key (hltpath) and effective.has_key (hltpath):
644  rowdata = []
645  l1bit = trgdict[hltpath][0]
646  if len (trgdict[hltpath]) != 3:
647  rowdata += [str (runnum), hltpath, 'N/A']
648  else:
649  hltprescale = trgdict[hltpath][1]
650  l1prescale = trgdict[hltpath][2]
651  rowdata += [str (runnum), hltpath, effective[hltpath]]
652  datatodump.append (rowdata)
653  continue
654 
655  for trg, trgdata in trgdict.items():
656  #print trg, trgdata
657  rowdata = []
658  rowdata += [str (runnum)]
659  l1bit = trgdata[0]
660  if len (trgdata) == 3:
661  rowdata += [trg, effective[trg]]
662  else:
663  rowdata += [trg, 'N/A']
664  datatodump.append (rowdata)
665  return datatodump
666 
def dumpRecordedLumi
def lumiQueryAPI.filterDeadtable (   inTable,
  lslist 
)

Definition at line 368 of file lumiQueryAPI.py.

369 def filterDeadtable (inTable, lslist):
370  result = {}
371  if lslist is None:
372  return inTable
373  if len (lslist) == 0: #if request no ls, then return nothing
374  return result
375  for existingLS in inTable.keys():
376  if existingLS in lslist:
377  result[existingLS] = inTable[existingLS]
378  return result
379 
def lumiQueryAPI.flatten (   obj)
Given nested lists or tuples, returns a single flattened list

Definition at line 843 of file lumiQueryAPI.py.

Referenced by python.rootplot.root2matplotlib.Hist2D.box(), and python.rootplot.core.divide_axes().

844 def flatten (obj):
845  '''Given nested lists or tuples, returns a single flattened list'''
846  result = []
847  for piece in obj:
848  if hasattr (piece, '__iter__') and not isinstance (piece, basestring):
849  result.extend( flatten (piece) )
850  else:
851  result.append (piece)
852  return result
853 
def lumiQueryAPI.getDeadfractions (   deadtable)
inputtable: {lsnum:[deadtime, instlumi, bit_0, norbits,bit_0_prescale]}
output: {lsnum:deadfraction}

Definition at line 445 of file lumiQueryAPI.py.

446 def getDeadfractions (deadtable):
447  """
448  inputtable: {lsnum:[deadtime, instlumi, bit_0, norbits,bit_0_prescale]}
449  output: {lsnum:deadfraction}
450  """
451  result = {}
452  for myls, d in deadtable.items():
453  #deadfrac = float (d[0])/ (float (d[2])*float (3564))
454  if float (d[2]) == 0.0: ##no beam
455  deadfrac = -1.0
456  else:
457  deadfrac = float (d[0])/ (float (d[2])*float(d[-1]))
458  result[myls] = deadfrac
459  return result
def getDeadfractions
def lumiQueryAPI.hltAllpathByrun (   queryHandle,
  runnum 
)
select cmslsnum,inputcount,acceptcount,prescale,pathname from hlt where runnum=:runnum
this can be changed to blob query later
output: {cmslsnum:{pathname:[inputcount,acceptcount,prescale]}}

Definition at line 1397 of file lumiQueryAPI.py.

References runTheMatrix.data, and nameDealer.hltTableName().

1398 def hltAllpathByrun(queryHandle,runnum):
1399  '''
1400  select cmslsnum,inputcount,acceptcount,prescale,pathname from hlt where runnum=:runnum
1401  this can be changed to blob query later
1402  output: {cmslsnum:{pathname:[inputcount,acceptcount,prescale]}}
1403  '''
1404  result={}
1405  queryHandle.addToTableList(nameDealer.hltTableName())
1406  queryCondition=coral.AttributeList()
1407  queryCondition.extend('runnum','unsigned int')
1408  queryCondition['runnum'].setData(int(runnum))
1409  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1410  queryHandle.addToOutputList('INPUTCOUNT','inputcount')
1411  queryHandle.addToOutputList('ACCEPTCOUNT','acceptcount')
1412  queryHandle.addToOutputList('PRESCALE','prescale')
1413  queryHandle.addToOutputList('PATHNAME','pathname')
1414  queryHandle.setCondition('RUNNUM=:runnum',queryCondition)
1415  queryResult=coral.AttributeList()
1416  queryResult.extend('cmslsnum','unsigned int')
1417  queryResult.extend('inputcount','unsigned int')
1418  queryResult.extend('acceptcount','unsigned int')
1419  queryResult.extend('prescale','unsigned int')
1420  queryResult.extend('pathname','string')
1421  queryHandle.defineOutput(queryResult)
1422  cursor=queryHandle.execute()
1423  while cursor.next():
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  pathname=cursor.currentRow()['pathname'].data()
1429  if not result.has_key(cmslsnum):
1430  dataperLS={}
1431  dataperLS[pathname]=[inputcount,acceptcount,prescale]
1432  result[cmslsnum]=dataperLS
1433  else:
1434  result[cmslsnum][pathname]=[inputcount,acceptcount,prescale]
1435  return result
1436 
def hltTableName
Definition: nameDealer.py:38
def lumiQueryAPI.hltBypathByrun (   queryHandle,
  runnum,
  hltpath 
)
select cmslsnum,inputcount,acceptcount,prescale from hlt where runnum=:runnum and pathname=:pathname
output: {cmslsnum:[inputcount,acceptcount,prescale]}

Definition at line 1364 of file lumiQueryAPI.py.

References runTheMatrix.data, and nameDealer.hltTableName().

Referenced by lumiSumPlot.getLumiInfoForRuns(), and dumpPrescale.main().

1365 def hltBypathByrun(queryHandle,runnum,hltpath):
1366  '''
1367  select cmslsnum,inputcount,acceptcount,prescale from hlt where runnum=:runnum and pathname=:pathname
1368  output: {cmslsnum:[inputcount,acceptcount,prescale]}
1369  '''
1370  result={}
1371  queryHandle.addToTableList(nameDealer.hltTableName())
1372  queryCondition=coral.AttributeList()
1373  queryCondition.extend('runnum','unsigned int')
1374  queryCondition.extend('pathname','string')
1375  queryCondition['runnum'].setData(int(runnum))
1376  queryCondition['pathname'].setData(hltpath)
1377  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1378  queryHandle.addToOutputList('INPUTCOUNT','inputcount')
1379  queryHandle.addToOutputList('ACCEPTCOUNT','acceptcount')
1380  queryHandle.addToOutputList('PRESCALE','prescale')
1381  queryHandle.setCondition('RUNNUM=:runnum and PATHNAME=:pathname',queryCondition)
1382  queryResult=coral.AttributeList()
1383  queryResult.extend('cmslsnum','unsigned int')
1384  queryResult.extend('inputcount','unsigned int')
1385  queryResult.extend('acceptcount','unsigned int')
1386  queryResult.extend('prescale','unsigned int')
1387  queryHandle.defineOutput(queryResult)
1388  cursor=queryHandle.execute()
1389  while cursor.next():
1390  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1391  inputcount=cursor.currentRow()['inputcount'].data()
1392  acceptcount=cursor.currentRow()['acceptcount'].data()
1393  prescale=cursor.currentRow()['prescale'].data()
1394  if not result.has_key(cmslsnum):
1395  result[cmslsnum]=[inputcount,acceptcount,prescale]
1396  return result
def hltTableName
Definition: nameDealer.py:38
def lumiQueryAPI.hlttrgMappingByrun (   queryHandle,
  runnum 
)
select m.hltpathname,m.l1seed from cmsrunsummary r,trghltmap m where r.runnum=:runnum and m.hltkey=r.hltkey
output: {hltpath:l1seed}

Definition at line 1620 of file lumiQueryAPI.py.

References nameDealer.cmsrunsummaryTableName(), runTheMatrix.data, and nameDealer.trghltMapTableName().

Referenced by lumiSumPlot.getLumiInfoForRuns(), and dumpPrescale.main().

1621 def hlttrgMappingByrun(queryHandle,runnum):
1622  '''
1623  select m.hltpathname,m.l1seed from cmsrunsummary r,trghltmap m where r.runnum=:runnum and m.hltkey=r.hltkey
1624  output: {hltpath:l1seed}
1625  '''
1626  result={}
1627  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName(),'r')
1628  queryHandle.addToTableList(nameDealer.trghltMapTableName(),'m')
1629  queryCondition=coral.AttributeList()
1630  queryCondition.extend('runnum','unsigned int')
1631  queryCondition['runnum'].setData(int(runnum))
1632  queryHandle.addToOutputList('m.HLTPATHNAME','hltpathname')
1633  queryHandle.addToOutputList('m.L1SEED','l1seed')
1634  queryHandle.setCondition('r.RUNNUM=:runnum and m.HLTKEY=r.HLTKEY',queryCondition)
1635  queryResult=coral.AttributeList()
1636  queryResult.extend('hltpathname','string')
1637  queryResult.extend('l1seed','string')
1638  queryHandle.defineOutput(queryResult)
1639  cursor=queryHandle.execute()
1640  while cursor.next():
1641  hltpathname=cursor.currentRow()['hltpathname'].data()
1642  l1seed=cursor.currentRow()['l1seed'].data()
1643  if not result.has_key(hltpathname):
1644  result[hltpathname]=l1seed
1645  return result
def trghltMapTableName
Definition: nameDealer.py:47
def hlttrgMappingByrun
def cmsrunsummaryTableName
Definition: nameDealer.py:14
def lumiQueryAPI.lsBylsLumi (   deadtable)
input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale...]}
output: {lsnum:[instlumi, recordedlumi...]}

Definition at line 60 of file lumiQueryAPI.py.

60 
61 def lsBylsLumi (deadtable):
62  """
63  input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale...]}
64  output: {lsnum:[instlumi, recordedlumi...]}
65  """
66  result = {}
67  for myls, deadArray in deadtable.items():
68  lstime = lslengthsec (deadArray[3], 3564)
69  instlumi = deadArray[1] * lstime
70  if float( deadArray[2] ) == 0.0:
71  deadfrac = 1.0
72  else:
73  deadfrac = float (deadArray[0]) / (float (deadArray[2])*float(deadArray[4]))
74  recordedLumi = instlumi * (1.0 - deadfrac)
75  myLsList = [instlumi, recordedLumi]
76  #print myls,instlumi,recordedLumi,lstime,deadfrac
77  if len (deadArray) > 5:
78  myLsList.extend (deadArray[5:])
79  result[myls] = myLsList
80  return result
81 
def lumiQueryAPI.lslengthsec (   numorbit,
  numbx 
)

Definition at line 55 of file lumiQueryAPI.py.

Referenced by deliveredLumiForRun().

55 
56 def lslengthsec (numorbit, numbx):
57  #print numorbit, numbx
58  l = numorbit * numbx * 25.0e-09
59  return l
def lumiQueryAPI.lumidetailAllalgosByrun (   queryHandle,
  runnum 
)
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
output: {algoname:{cmslsnum:[bxlumivalue,bxlumierror,bxlumiquality,startorbit]}}

Definition at line 1576 of file lumiQueryAPI.py.

References runTheMatrix.data, nameDealer.lumidetailTableName(), and nameDealer.lumisummaryTableName().

1577 def lumidetailAllalgosByrun(queryHandle,runnum):
1578  '''
1579  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
1580  output: {algoname:{cmslsnum:[bxlumivalue,bxlumierror,bxlumiquality,startorbit]}}
1581  '''
1582  result={}
1583  queryHandle.addToTableList(nameDealer.lumidetailTableName(),'d')
1584  queryHandle.addToTableList(nameDealer.lumisummaryTableName(),'s')
1585  queryCondition=coral.AttributeList()
1586  queryCondition.extend('runnum','unsigned int')
1587  queryCondition['runnum'].setData(int(runnum))
1588  queryHandle.addToOutputList('s.CMSLSNUM','cmslsnum')
1589  queryHandle.addToOutputList('d.BXLUMIVALUE','bxlumivalue')
1590  queryHandle.addToOutputList('d.BXLUMIERROR','bxlumierror')
1591  queryHandle.addToOutputList('d.BXLUMIQUALITY','bxlumiquality')
1592  queryHandle.addToOutputList('d.ALGONAME','algoname')
1593  queryHandle.addToOutputList('s.STARTORBIT','startorbit')
1594  queryHandle.setCondition('s.RUNNUM=:runnum and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',queryCondition)
1595  queryResult=coral.AttributeList()
1596  queryResult.extend('cmslsnum','unsigned int')
1597  queryResult.extend('bxlumivalue','blob')
1598  queryResult.extend('bxlumierror','blob')
1599  queryResult.extend('bxlumiquality','blob')
1600  queryResult.extend('algoname','string')
1601  queryResult.extend('startorbit','unsigned int')
1602  queryHandle.addToOrderList('startorbit')
1603  queryHandle.addToOrderList('algoname')
1604  queryHandle.defineOutput(queryResult)
1605  cursor=queryHandle.execute()
1606  while cursor.next():
1607  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1608  bxlumivalue=cursor.currentRow()['bxlumivalue'].data()
1609  bxlumierror=cursor.currentRow()['bxlumierror'].data()
1610  bxlumiquality=cursor.currentRow()['bxlumiquality'].data()
1611  algoname=cursor.currentRow()['algoname'].data()
1612  startorbit=cursor.currentRow()['startorbit'].data()
1613  if not result.has_key(algoname):
1614  dataPerAlgo={}
1615  dataPerAlgo[cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]
1616  result[algoname]=dataPerAlgo
1617  else:
1618  result[algoname][cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]
1619  return result
def lumisummaryTableName
Definition: nameDealer.py:20
def lumidetailTableName
Definition: nameDealer.py:25
def lumidetailAllalgosByrun
def lumiQueryAPI.lumidetailByrunByAlgo (   queryHandle,
  runnum,
  algoname = 'OCC1' 
)
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
output: [[cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit]]
since the output is ordered by time, it has to be in seq list format

Definition at line 1538 of file lumiQueryAPI.py.

References runTheMatrix.data, nameDealer.lumidetailTableName(), and nameDealer.lumisummaryTableName().

1539 def lumidetailByrunByAlgo(queryHandle,runnum,algoname='OCC1'):
1540  '''
1541  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
1542  output: [[cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit]]
1543  since the output is ordered by time, it has to be in seq list format
1544  '''
1545  result=[]
1546  queryHandle.addToTableList(nameDealer.lumidetailTableName(),'d')
1547  queryHandle.addToTableList(nameDealer.lumisummaryTableName(),'s')
1548  queryCondition=coral.AttributeList()
1549  queryCondition.extend('runnum','unsigned int')
1550  queryCondition.extend('algoname','string')
1551  queryCondition['runnum'].setData(int(runnum))
1552  queryCondition['algoname'].setData(algoname)
1553  queryHandle.addToOutputList('s.CMSLSNUM','cmslsnum')
1554  queryHandle.addToOutputList('d.BXLUMIVALUE','bxlumivalue')
1555  queryHandle.addToOutputList('d.BXLUMIERROR','bxlumierror')
1556  queryHandle.addToOutputList('d.BXLUMIQUALITY','bxlumiquality')
1557  queryHandle.addToOutputList('s.STARTORBIT','startorbit')
1558  queryHandle.setCondition('s.runnum=:runnum and d.algoname=:algoname and s.lumisummary_id=d.lumisummary_id',queryCondition)
1559  queryResult=coral.AttributeList()
1560  queryResult.extend('cmslsnum','unsigned int')
1561  queryResult.extend('bxlumivalue','blob')
1562  queryResult.extend('bxlumierror','blob')
1563  queryResult.extend('bxlumiquality','blob')
1564  queryResult.extend('startorbit','unsigned int')
1565  queryHandle.addToOrderList('s.STARTORBIT')
1566  queryHandle.defineOutput(queryResult)
1567  cursor=queryHandle.execute()
1568  while cursor.next():
1569  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1570  bxlumivalue=cursor.currentRow()['bxlumivalue'].data()
1571  bxlumierror=cursor.currentRow()['bxlumierror'].data()
1572  bxlumiquality=cursor.currentRow()['bxlumiquality'].data()
1573  startorbit=cursor.currentRow()['startorbit'].data()
1574  result.append([cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit])
1575  return result
def lumisummaryTableName
Definition: nameDealer.py:20
def lumidetailByrunByAlgo
def lumidetailTableName
Definition: nameDealer.py:25
def lumiQueryAPI.lumisumByrun (   queryHandle,
  runnum,
  lumiversion,
  beamstatus = None,
  beamenergy = None,
  beamenergyfluctuation = 0.09 
)
beamenergy unit : GeV
beamenergyfluctuation : fraction allowed to fluctuate around beamenergy value
select sum(instlumi) from lumisummary where runnum=:runnum and lumiversion=:lumiversion
output: float totallumi
Note: the output is the raw result, need to apply LS length in time(sec)

Definition at line 1137 of file lumiQueryAPI.py.

References runTheMatrix.data, and nameDealer.lumisummaryTableName().

Referenced by lumiSumPlot.getLumiInfoForRuns().

1138 def lumisumByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09):
1139  '''
1140  beamenergy unit : GeV
1141  beamenergyfluctuation : fraction allowed to fluctuate around beamenergy value
1142  select sum(instlumi) from lumisummary where runnum=:runnum and lumiversion=:lumiversion
1143  output: float totallumi
1144  Note: the output is the raw result, need to apply LS length in time(sec)
1145  '''
1146  result=0.0
1147  queryHandle.addToTableList(nameDealer.lumisummaryTableName())
1148  queryCondition=coral.AttributeList()
1149  queryCondition.extend('runnum','unsigned int')
1150  queryCondition.extend('lumiversion','string')
1151 
1152  queryCondition['runnum'].setData(int(runnum))
1153  queryCondition['lumiversion'].setData(lumiversion)
1154  queryHandle.addToOutputList('sum(INSTLUMI)','lumitotal')
1155  conditionstring='RUNNUM=:runnum and LUMIVERSION=:lumiversion'
1156  if beamstatus and len(beamstatus)!=0:
1157  conditionstring=conditionstring+' and BEAMSTATUS=:beamstatus'
1158  queryCondition.extend('beamstatus','string')
1159  queryCondition['beamstatus'].setData(beamstatus)
1160  if beamenergy and beamenergy!=0.0:
1161  minBeamenergy=float(beamenergy*(1.0-beamenergyfluctuation))
1162  maxBeamenergy=float(beamenergy*(1.0+beamenergyfluctuation))
1163  conditionstring=conditionstring+' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy'
1164  queryCondition.extend('minBeamenergy','float')
1165  queryCondition.extend('maxBeamenergy','float')
1166  queryCondition['minBeamenergy'].setData(float(minBeamenergy))
1167  queryCondition['maxBeamenergy'].setData(float(maxBeamenergy))
1168  queryHandle.setCondition(conditionstring,queryCondition)
1169  queryResult=coral.AttributeList()
1170  queryResult.extend('lumitotal','float')
1171  queryHandle.defineOutput(queryResult)
1172  cursor=queryHandle.execute()
1173  while cursor.next():
1174  result=cursor.currentRow()['lumitotal'].data()
1175  return result
def lumisummaryTableName
Definition: nameDealer.py:20
def lumiQueryAPI.lumisummaryByrun (   queryHandle,
  runnum,
  lumiversion,
  beamstatus = None,
  beamenergy = None,
  beamenergyfluctuation = 0.09 
)
one can impose beamstatus, beamenergy selections at the SQL query level or process them later from the general result
select cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenery from lumisummary where runnum=:runnum and lumiversion=:lumiversion order by startorbit;
output: [[cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive]]
Note: the non-cmsalive LS are included in the result

Definition at line 1080 of file lumiQueryAPI.py.

References runTheMatrix.data, and nameDealer.lumisummaryTableName().

Referenced by lumiInstPlot.getInstLumiPerLS(), lumiSumPlot.getLumiInfoForRuns(), lumiSumPlot.getLumiOrderByLS(), lumiInstPlot.getLumiPerRun(), lumiCalc.getPerLSData(), specificLumi-2011.getSpecificLumi(), specificLumi.getSpecificLumi(), and lumiValidate.insertupdateValidationData().

1081 def lumisummaryByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09):
1082  '''
1083  one can impose beamstatus, beamenergy selections at the SQL query level or process them later from the general result
1084  select cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenery from lumisummary where runnum=:runnum and lumiversion=:lumiversion order by startorbit;
1085  output: [[cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive]]
1086  Note: the non-cmsalive LS are included in the result
1087  '''
1088  result=[]
1089  queryHandle.addToTableList(nameDealer.lumisummaryTableName())
1090  queryCondition=coral.AttributeList()
1091  queryCondition.extend('runnum','unsigned int')
1092  queryCondition.extend('lumiversion','string')
1093  conditionstring='RUNNUM=:runnum and LUMIVERSION=:lumiversion'
1094  queryCondition['runnum'].setData(int(runnum))
1095  queryCondition['lumiversion'].setData(lumiversion)
1096  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1097  queryHandle.addToOutputList('INSTLUMI','instlumi')
1098  queryHandle.addToOutputList('NUMORBIT','numorbit')
1099  queryHandle.addToOutputList('STARTORBIT','startorbit')
1100  queryHandle.addToOutputList('BEAMSTATUS','beamstatus')
1101  queryHandle.addToOutputList('BEAMENERGY','beamenergy')
1102  queryHandle.addToOutputList('CMSALIVE','cmsalive')
1103  if beamstatus and len(beamstatus)!=0:
1104  conditionstring=conditionstring+' and BEAMSTATUS=:beamstatus'
1105  queryCondition.extend('beamstatus','string')
1106  queryCondition['beamstatus'].setData(beamstatus)
1107  if beamenergy:
1108  minBeamenergy=float(beamenergy*(1.0-beamenergyfluctuation))
1109  maxBeamenergy=float(beamenergy*(1.0+beamenergyfluctuation))
1110  conditionstring=conditionstring+' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy'
1111  queryCondition.extend('minBeamenergy','float')
1112  queryCondition.extend('maxBeamenergy','float')
1113  queryCondition['minBeamenergy'].setData(float(minBeamenergy))
1114  queryCondition['maxBeamenergy'].setData(float(maxBeamenergy))
1115  queryResult=coral.AttributeList()
1116  queryResult.extend('cmslsnum','unsigned int')
1117  queryResult.extend('instlumi','float')
1118  queryResult.extend('numorbit','unsigned int')
1119  queryResult.extend('startorbit','unsigned int')
1120  queryResult.extend('beamstatus','string')
1121  queryResult.extend('beamenergy','float')
1122  queryResult.extend('cmsalive','unsigned int')
1123  queryHandle.defineOutput(queryResult)
1124  queryHandle.setCondition(conditionstring,queryCondition)
1125  queryHandle.addToOrderList('startorbit')
1126  cursor=queryHandle.execute()
1127  while cursor.next():
1128  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1129  instlumi=cursor.currentRow()['instlumi'].data()
1130  numorbit=cursor.currentRow()['numorbit'].data()
1131  startorbit=cursor.currentRow()['startorbit'].data()
1132  beamstatus=cursor.currentRow()['beamstatus'].data()
1133  beamenergy=cursor.currentRow()['beamenergy'].data()
1134  cmsalive=cursor.currentRow()['cmsalive'].data()
1135  result.append([cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive])
1136  return result
def lumisummaryTableName
Definition: nameDealer.py:20
def lumiQueryAPI.lumisummarytrgbitzeroByrun (   queryHandle,
  runnum,
  lumiversion,
  beamstatus = None,
  beamenergy = None,
  beamenergyfluctuation = 0.09 
)
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; 
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.
output: {cmslsnum:[instlumi,numorbit,startorbit,beamstatus,beamenergy,bitzerocount,deadtime,bitname,prescale]}
Note: only cmsalive LS are included in the result. Therefore, this function cannot be used for calculating delivered!

Definition at line 1212 of file lumiQueryAPI.py.

References runTheMatrix.data, nameDealer.lumisummaryTableName(), and nameDealer.trgTableName().

Referenced by lumiSumPlot.getLumiInfoForRuns(), and lumiSumPlot.getLumiOrderByLS().

1213 def lumisummarytrgbitzeroByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09):
1214  '''
1215  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;
1216  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.
1217  output: {cmslsnum:[instlumi,numorbit,startorbit,beamstatus,beamenergy,bitzerocount,deadtime,bitname,prescale]}
1218  Note: only cmsalive LS are included in the result. Therefore, this function cannot be used for calculating delivered!
1219  '''
1220  result={}
1221  queryHandle.addToTableList(nameDealer.trgTableName(),'t')
1222  queryHandle.addToTableList(nameDealer.lumisummaryTableName(),'l')
1223  queryCondition=coral.AttributeList()
1224  queryCondition.extend('bitnum','unsigned int')
1225  queryCondition.extend('runnum','unsigned int')
1226  queryCondition.extend('lumiversion','string')
1227  queryCondition['bitnum'].setData(int(0))
1228  queryCondition['runnum'].setData(int(runnum))
1229  queryCondition['lumiversion'].setData(lumiversion)
1230 
1231  queryHandle.addToOutputList('l.CMSLSNUM','cmslsnum')
1232  queryHandle.addToOutputList('l.INSTLUMI','instlumi')
1233  queryHandle.addToOutputList('l.NUMORBIT','numorbit')
1234  queryHandle.addToOutputList('l.STARTORBIT','startorbit')
1235  queryHandle.addToOutputList('l.BEAMSTATUS','beamstatus')
1236  queryHandle.addToOutputList('l.BEAMENERGY','beamenergy')
1237  queryHandle.addToOutputList('t.TRGCOUNT','trgcount')
1238  queryHandle.addToOutputList('t.DEADTIME','deadtime')
1239  queryHandle.addToOutputList('t.BITNAME','bitname')
1240  queryHandle.addToOutputList('t.PRESCALE','prescale')
1241  conditionstring='t.BITNUM=:bitnum and l.RUNNUM=:runnum and l.LUMIVERSION=:lumiversion and l.RUNNUM=t.RUNNUM and t.CMSLSNUM=l.CMSLSNUM'
1242  if beamstatus and len(beamstatus)!=0:
1243  conditionstring=conditionstring+' and l.BEAMSTATUS=:beamstatus'
1244  queryCondition.extend('beamstatus','string')
1245  queryCondition['beamstatus'].setData(beamstatus)
1246  if beamenergy and beamenergy!=0.0:
1247  minBeamenergy=float(beamenergy*(1-beamenergyfluctuation))
1248  maxBeamenergy=float(beamenergy*(1+beamenergyfluctuation))
1249  conditionstring=conditionstring+' and l.BEAMENERGY>:minBeamenergy and l.BEAMENERGY<:maxBeamenergy'
1250  queryCondition.extend('minBeamenergy','float')
1251  queryCondition.extend('maxBeamenergy','float')
1252  queryCondition['minBeamenergy'].setData(float(minBeamenergy))
1253  queryCondition['maxBeamenergy'].setData(float(maxBeamenergy))
1254  queryHandle.setCondition(conditionstring,queryCondition)
1255  queryResult=coral.AttributeList()
1256  queryResult.extend('cmslsnum','unsigned int')
1257  queryResult.extend('instlumi','float')
1258  queryResult.extend('numorbit','unsigned int')
1259  queryResult.extend('startorbit','unsigned int')
1260  queryResult.extend('beamstatus','string')
1261  queryResult.extend('beamenergy','float')
1262  queryResult.extend('trgcount','unsigned int')
1263  queryResult.extend('deadtime','unsigned int')
1264  queryResult.extend('bitname','string')
1265  queryResult.extend('prescale','unsigned int')
1266  queryHandle.defineOutput(queryResult)
1267  cursor=queryHandle.execute()
1268  while cursor.next():
1269  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1270  instlumi=cursor.currentRow()['instlumi'].data()
1271  numorbit=cursor.currentRow()['numorbit'].data()
1272  startorbit=cursor.currentRow()['startorbit'].data()
1273  beamstatus=cursor.currentRow()['beamstatus'].data()
1274  beamenergy=cursor.currentRow()['beamenergy'].data()
1275  trgcount=cursor.currentRow()['trgcount'].data()
1276  deadtime=cursor.currentRow()['deadtime'].data()
1277  bitname=cursor.currentRow()['bitname'].data()
1278  prescale=cursor.currentRow()['prescale'].data()
1279  if not result.has_key(cmslsnum):
1280  result[cmslsnum]=[instlumi,numorbit,startorbit,beamstatus,beamenergy,trgcount,deadtime,bitname,prescale]
1281  return result
def lumisummaryTableName
Definition: nameDealer.py:20
def lumisummarytrgbitzeroByrun
def trgTableName
Definition: nameDealer.py:35
def lumiQueryAPI.mergeXingLumi (   triplet,
  xingLumiDict 
)
Given general xing information and a xingLumiDict, the xing
luminosity information is merged with the general information

Definition at line 854 of file lumiQueryAPI.py.

855 def mergeXingLumi (triplet, xingLumiDict):
856  '''Given general xing information and a xingLumiDict, the xing
857  luminosity information is merged with the general information'''
858  runNumber = triplet[0]
859  deadTable = triplet[2]
860  for lumi, lumiList in deadTable.iteritems():
861  key = ( int(runNumber), int(lumi) )
862  xingLumiValues = xingLumiDict.get (key)
863  if xingLumiValues:
864  lumiList.append( flatten (xingLumiValues) )
865 
def lumiQueryAPI.printDeliveredLumi (   lumidata,
  mode 
)

Definition at line 380 of file lumiQueryAPI.py.

381 def printDeliveredLumi (lumidata, mode):
382  labels = [ ('Run', 'Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Beam Mode')]
383  print tablePrinter.indent (labels+lumidata, hasHeader = True, separateRows = False,
384  prefix = '| ', postfix = ' |', justify = 'right',
385  delim = ' | ', wrapfunc = lambda x: wrap_onspace (x, 20) )
def printDeliveredLumi
def lumiQueryAPI.printOverviewData (   delivered,
  recorded,
  hltpath = '' 
)

Definition at line 667 of file lumiQueryAPI.py.

References relativeConstraints.keys.

668 def printOverviewData (delivered, recorded, hltpath = ''):
669  if len (hltpath) == 0 or hltpath == 'all':
670  toprowlabels = [ ('Run', 'Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8') )]
671  lastrowlabels = [ ('Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8') ) ]
672  else:
673  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 )]
674  lastrowlabels = [ ('Delivered LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'), 'Effective '+u' (/\u03bcb) '.encode ('utf-8')+hltpath)]
675  datatable = []
676  totaldata = []
677  totalDeliveredLS = 0
678  totalSelectedLS = 0
679  totalDelivered = 0.0
680  totalRecorded = 0.0
681  totalRecordedInPath = 0.0
682  totaltable = []
683  for runidx, deliveredrowdata in enumerate (delivered):
684  rowdata = []
685  rowdata += [deliveredrowdata[0], deliveredrowdata[1], deliveredrowdata[2]]
686  if deliveredrowdata[1] == 'N/A': #run does not exist
687  if hltpath != '' and hltpath != 'all':
688  rowdata += ['N/A', 'N/A', 'N/A']
689  else:
690  rowdata += ['N/A', 'N/A']
691  datatable.append (rowdata)
692  continue
693  totalDeliveredLS += int (deliveredrowdata[1])
694  totalDelivered += float (deliveredrowdata[2])
695  selectedls = recorded[runidx][2].keys()
696  #print 'runidx ', runidx, deliveredrowdata
697  #print 'selectedls ', selectedls
698  if len (selectedls) == 0:
699  selectedlsStr = '[]'
700  recordedLumi = 0
701  if hltpath != '' and hltpath != 'all':
702  rowdata += [selectedlsStr, 'N/A', 'N/A']
703  else:
704  rowdata += [selectedlsStr, 'N/A']
705  else:
706  selectedlsStr = splitlistToRangeString (selectedls)
707  recordedLumi = calculateTotalRecorded (recorded[runidx][2])
708  lumiinPaths = calculateEffective (recorded[runidx][1], recordedLumi)
709  if hltpath != '' and hltpath != 'all':
710  if lumiinPaths.has_key (hltpath):
711  rowdata += [selectedlsStr, '%.3f'% (recordedLumi), '%.3f'% (lumiinPaths[hltpath])]
712  totalRecordedInPath += lumiinPaths[hltpath]
713  else:
714  rowdata += [selectedlsStr, '%.3f'% (recordedLumi), 'N/A']
715  else:
716  #rowdata += [selectedlsStr, '%.3f'% (recordedLumi), '%.3f'% (recordedLumi)]
717  rowdata += [selectedlsStr, '%.3f'% (recordedLumi)]
718  totalSelectedLS += len (selectedls)
719  totalRecorded += recordedLumi
720  datatable.append (rowdata)
721 
722  if hltpath != '' and hltpath != 'all':
723  totaltable = [[str (totalDeliveredLS), '%.3f'% (totalDelivered), str (totalSelectedLS),
724  '%.3f'% (totalRecorded), '%.3f'% (totalRecordedInPath)]]
725  else:
726  totaltable = [[str (totalDeliveredLS), '%.3f'% (totalDelivered), str (totalSelectedLS),
727  '%.3f'% (totalRecorded)]]
728  print tablePrinter.indent (toprowlabels+datatable, hasHeader = True, separateRows = False, prefix = '| ',
729  postfix = ' |', justify = 'right', delim = ' | ',
730  wrapfunc = lambda x: wrap_onspace (x, 20))
731  print ' == = Total : '
732  print tablePrinter.indent (lastrowlabels+totaltable, hasHeader = True, separateRows = False, prefix = '| ',
733  postfix = ' |', justify = 'right', delim = ' | ',
734  wrapfunc = lambda x: wrap_onspace (x, 20))
735 
def printOverviewData
def lumiQueryAPI.printPerLSLumi (   lumidata,
  isVerbose = False 
)
input lumidata  [['runnumber', 'trgtable{}', 'deadtable{}']]
deadtable {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]}

Definition at line 460 of file lumiQueryAPI.py.

461 def printPerLSLumi (lumidata, isVerbose = False):
462  '''
463  input lumidata [['runnumber', 'trgtable{}', 'deadtable{}']]
464  deadtable {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]}
465  '''
466  datatoprint = []
467  totalrow = []
468  labels = [ ('Run', 'LS', 'Delivered', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
469  lastrowlabels = [ ('Selected LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
470  totalDeliveredLS = 0
471  totalSelectedLS = 0
472  totalDelivered = 0.0
473  totalRecorded = 0.0
474 
475  for perrundata in lumidata:
476  runnumber = perrundata[0]
477  deadtable = perrundata[2]
478  lumiresult = lsBylsLumi (deadtable)
479  totalSelectedLS = totalSelectedLS+len (deadtable)
480  for lsnum, dataperls in lumiresult.items():
481  rowdata = []
482  if len (dataperls) == 0:
483  rowdata += [str (runnumber), str (lsnum), 'N/A', 'N/A']
484  else:
485  rowdata += [str (runnumber), str (lsnum), '%.3f' % (dataperls[0]), '%.3f' % (dataperls[1])]
486  totalDelivered = totalDelivered+dataperls[0]
487  totalRecorded = totalRecorded+dataperls[1]
488  datatoprint.append (rowdata)
489  totalrow.append ([str (totalSelectedLS), '%.3f'% (totalDelivered), '%.3f'% (totalRecorded)])
490  print ' == = '
491  print tablePrinter.indent (labels+datatoprint, hasHeader = True, separateRows = False, prefix = '| ',
492  postfix = ' |', justify = 'right', delim = ' | ',
493  wrapfunc = lambda x: wrap_onspace_strict (x, 22))
494  print ' == = Total : '
495  print tablePrinter.indent (lastrowlabels+totalrow, hasHeader = True, separateRows = False, prefix = '| ',
496  postfix = ' |', justify = 'right', delim = ' | ',
497  wrapfunc = lambda x: wrap_onspace (x, 20))
498 
def lumiQueryAPI.printRecordedLumi (   lumidata,
  isVerbose = False,
  hltpath = '' 
)

Definition at line 517 of file lumiQueryAPI.py.

518 def printRecordedLumi (lumidata, isVerbose = False, hltpath = ''):
519  datatoprint = []
520  totalrow = []
521  labels = [ ('Run', 'HLT path', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
522  lastrowlabels = [ ('Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
523  if len (hltpath) != 0 and hltpath != 'all':
524  lastrowlabels = [ ('Selected LS', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'),
525  'Effective '+u' (/\u03bcb) '.encode ('utf-8')+hltpath)]
526  if isVerbose:
527  labels = [ ('Run', 'HLT-path', 'L1-bit', 'L1-presc', 'HLT-presc', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
528  totalSelectedLS = 0
529  totalRecorded = 0.0
530  totalRecordedInPath = 0.0
531 
532  for dataperRun in lumidata:
533  runnum = dataperRun[0]
534  if len (dataperRun[1]) == 0:
535  rowdata = []
536  rowdata += [str (runnum)]+2*['N/A']
537  datatoprint.append (rowdata)
538  continue
539  perlsdata = dataperRun[2]
540  totalSelectedLS = totalSelectedLS+len (perlsdata)
541  recordedLumi = 0.0
542  #norbits = perlsdata.values()[0][3]
543  recordedLumi = calculateTotalRecorded (perlsdata)
544  totalRecorded = totalRecorded+recordedLumi
545  trgdict = dataperRun[1]
546  effective = calculateEffective (trgdict, recordedLumi)
547  if trgdict.has_key (hltpath) and effective.has_key (hltpath):
548  rowdata = []
549  l1bit = trgdict[hltpath][0]
550  if len (trgdict[hltpath]) != 3:
551  if not isVerbose:
552  rowdata += [str (runnum), hltpath, 'N/A']
553  else:
554  rowdata += [str (runnum), hltpath, l1bit, 'N/A', 'N/A', 'N/A']
555  else:
556  if not isVerbose:
557  rowdata += [str (runnum), hltpath, '%.3f'% (effective[hltpath])]
558  else:
559  hltprescale = trgdict[hltpath][1]
560  l1prescale = trgdict[hltpath][2]
561  rowdata += [str (runnum), hltpath, l1bit, str (l1prescale), str (hltprescale),
562  '%.3f'% (effective[hltpath])]
563  totalRecordedInPath = totalRecordedInPath+effective[hltpath]
564  datatoprint.append (rowdata)
565  continue
566 
567  for trg, trgdata in trgdict.items():
568  #print trg, trgdata
569  rowdata = []
570  if trg == trgdict.keys()[0]:
571  rowdata += [str (runnum)]
572  else:
573  rowdata += ['']
574  l1bit = trgdata[0]
575  if len (trgdata) == 3:
576  if not isVerbose:
577  rowdata += [trg, '%.3f'% (effective[trg])]
578  else:
579  hltprescale = trgdata[1]
580  l1prescale = trgdata[2]
581  rowdata += [trg, l1bit, str (l1prescale), str (hltprescale), '%.3f'% (effective[trg])]
582  else:
583  if not isVerbose:
584  rowdata += [trg, 'N/A']
585  else:
586  rowdata += [trg, l1bit, 'N/A', 'N/A', '%.3f'% (effective[trg])]
587  datatoprint.append (rowdata)
588  #print datatoprint
589  print ' == = '
590  print tablePrinter.indent (labels+datatoprint, hasHeader = True, separateRows = False, prefix = '| ',
591  postfix = ' |', justify = 'right', delim = ' | ',
592  wrapfunc = lambda x: wrap_onspace_strict (x, 22))
593 
594  if len (hltpath) != 0 and hltpath != 'all':
595  totalrow.append ([str (totalSelectedLS), '%.3f'% (totalRecorded), '%.3f'% (totalRecordedInPath)])
596  else:
597  totalrow.append ([str (totalSelectedLS), '%.3f'% (totalRecorded)])
598  print ' == = Total : '
599  print tablePrinter.indent (lastrowlabels+totalrow, hasHeader = True, separateRows = False, prefix = '| ',
600  postfix = ' |', justify = 'right', delim = ' | ',
601  wrapfunc = lambda x: wrap_onspace (x, 20))
602  if isVerbose:
603  deadtoprint = []
604  deadtimelabels = [ ('Run', 'Lumi section : Dead fraction')]
605 
606  for dataperRun in lumidata:
607  runnum = dataperRun[0]
608  if len (dataperRun[1]) == 0:
609  deadtoprint.append ([str (runnum), 'N/A'])
610  continue
611  perlsdata = dataperRun[2]
612  #print 'perlsdata 2 : ', perlsdata
613  deadT = getDeadfractions (perlsdata)
614  t = ''
615  for myls, de in deadT.items():
616  if de<0:
617  t += str (myls)+':nobeam '
618  else:
619  t += str (myls)+':'+'%.5f'% (de)+' '
620  deadtoprint.append ([str (runnum), t])
621  print ' == = '
622  print tablePrinter.indent (deadtimelabels+deadtoprint, hasHeader = True, separateRows = True, prefix = '| ',
623  postfix = ' |', justify = 'right', delim = ' | ',
624  wrapfunc = lambda x: wrap_onspace (x, 80))
625 
def printRecordedLumi
def lumiQueryAPI.recordedLumiForRange (   dbsession,
  parameters,
  inputRange 
)
Takes either single run as a string or dictionary of run ranges

Definition at line 98 of file lumiQueryAPI.py.

References if().

98 
99 def recordedLumiForRange (dbsession, parameters, inputRange):
100  '''Takes either single run as a string or dictionary of run ranges'''
101  lumidata = []
102  # is this a single string?
103  if isinstance (inputRange, str):
104  lumiDataPiece = recordedLumiForRun (dbsession, parameters, inputRange)
105  if parameters.lumiXing:
106  # get the xing information for the run
107  xingLumiDict = xingLuminosityForRun (dbsession, inputRange,
108  parameters)
109  mergeXingLumi (lumiDataPiece, xingLumiDict)
110  lumidata.append (lumiDataPiece)
111 
112  else:
113  # we want to collapse the lists so that every run is considered once.
114  runLsDict = {}
115  maxLumiSectionDict = {}
116  for (run, lslist) in sorted (inputRange.runsandls().items() ):
117  if(len(lslist)!=0):
118  maxLumiSectionDict[run] = max ( max (lslist),
119  maxLumiSectionDict.get(run,0) )
120  runLsDict.setdefault (run, []).append (lslist)
121  for run, metaLsList in sorted (runLsDict.iteritems()):
122  if parameters.verbose:
123  print "run", run
124  runLumiData = []
125  for lslist in metaLsList:
126  runLumiData.append( recordedLumiForRun (dbsession, parameters,
127  run, lslist) )
128  if parameters.lumiXing:
129  # get the xing information once for the whole run
130  xingLumiDict = xingLuminosityForRun (dbsession, run,
131  parameters,
132  maxLumiSection = \
133  maxLumiSectionDict[run])
134  # merge it with every piece of lumi data for this run
135  for lumiDataPiece in runLumiData:
136  mergeXingLumi (lumiDataPiece, xingLumiDict)
137  lumidata.append (lumiDataPiece)
138  else:
139  lumidata.extend( runLumiData )
140  return lumidata
141 
142 
def recordedLumiForRange
Definition: lumiQueryAPI.py:98
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
def lumiQueryAPI.recordedLumiForRun (   dbsession,
  parameters,
  runnum,
  lslist = None 
)
lslist = [] means take none in the db
lslist = None means to take all in the db
output: ['runnumber', 'trgtable{}', 'deadtable{}']

Definition at line 201 of file lumiQueryAPI.py.

References nameDealer.cmsrunsummaryTableName(), runTheMatrix.data, nameDealer.hltTableName(), nameDealer.lumisummaryTableName(), nameDealer.trghltMapTableName(), and nameDealer.trgTableName().

202 def recordedLumiForRun (dbsession, parameters, runnum, lslist = None):
203  """
204  lslist = [] means take none in the db
205  lslist = None means to take all in the db
206  output: ['runnumber', 'trgtable{}', 'deadtable{}']
207  """
208  recorded = 0.0
209  lumidata = [] #[runnumber, trgtable, deadtable]
210  trgtable = {} #{hltpath:[l1seed, hltprescale, l1prescale]}
211  deadtable = {} #{lsnum:[deadtime, instlumi, bit_0, norbits,bitzero_prescale]}
212  lumidata.append (runnum)
213  lumidata.append (trgtable)
214  lumidata.append (deadtable)
215  collectedseeds = [] #[ (hltpath, l1seed)]
216  conditionstring='trghltmap.HLTKEY = cmsrunsummary.HLTKEY AND cmsrunsummary.RUNNUM = :runnumber'
217  try:
218  dbsession.transaction().start (True)
219  schema = dbsession.nominalSchema()
220  query = schema.newQuery()
221  query.addToTableList (nameDealer.cmsrunsummaryTableName(), 'cmsrunsummary')
222  query.addToTableList (nameDealer.trghltMapTableName(), 'trghltmap')#small table first
223  queryCondition = coral.AttributeList()
224  queryCondition.extend ("runnumber", "unsigned int")
225  queryCondition["runnumber"].setData (int (runnum))
226  query.setCondition (conditionstring,queryCondition)
227  query.addToOutputList ("trghltmap.HLTPATHNAME", "hltpathname")
228  query.addToOutputList ("trghltmap.L1SEED", "l1seed")
229  result = coral.AttributeList()
230  result.extend ("hltpathname", "string")
231  result.extend ("l1seed", "string")
232  query.defineOutput (result)
233  cursor = query.execute()
234  while cursor.next():
235  hltpathname = cursor.currentRow()["hltpathname"].data()
236  l1seed = cursor.currentRow()["l1seed"].data()
237  collectedseeds.append ( (hltpathname, l1seed))
238  #print 'collectedseeds ', collectedseeds
239  del query
240  dbsession.transaction().commit()
241  #loop over hltpath
242  for (hname, sname) in collectedseeds:
243  l1bitname = hltTrgSeedMapper.findUniqueSeed (hname, sname)
244  #print 'found unque seed ', hname, l1bitname
245  if l1bitname:
246  lumidata[1][hname] = []
247  lumidata[1][hname].append (l1bitname.replace ('\"', ''))
248  dbsession.transaction().start (True)
249  schema = dbsession.nominalSchema()
250  hltprescQuery = schema.tableHandle (nameDealer.hltTableName()).newQuery()
251  hltprescQuery.addToOutputList ("PATHNAME", "hltpath")
252  hltprescQuery.addToOutputList ("PRESCALE", "hltprescale")
253  hltprescCondition = coral.AttributeList()
254  hltprescCondition.extend ('runnumber', 'unsigned int')
255  hltprescCondition.extend ('cmslsnum', 'unsigned int')
256  hltprescCondition.extend ('inf', 'unsigned int')
257  hltprescResult = coral.AttributeList()
258  hltprescResult.extend ('hltpath', 'string')
259  hltprescResult.extend ('hltprescale', 'unsigned int')
260  hltprescQuery.defineOutput (hltprescResult)
261  hltprescCondition['runnumber'].setData (int (runnum))
262  hltprescCondition['cmslsnum'].setData (1)
263  hltprescCondition['inf'].setData (0)
264  hltprescQuery.setCondition ("RUNNUM = :runnumber and CMSLSNUM = :cmslsnum and PRESCALE != :inf",
265  hltprescCondition)
266  cursor = hltprescQuery.execute()
267  while cursor.next():
268  hltpath = cursor.currentRow()['hltpath'].data()
269  hltprescale = cursor.currentRow()['hltprescale'].data()
270  if lumidata[1].has_key (hltpath):
271  lumidata[1][hltpath].append (hltprescale)
272 
273  cursor.close()
274  del hltprescQuery
275  dbsession.transaction().commit()
276  dbsession.transaction().start (True)
277  schema = dbsession.nominalSchema()
278  query = schema.newQuery()
279  query.addToTableList (nameDealer.trgTableName(), 'trg')
280  query.addToTableList (nameDealer.lumisummaryTableName(), 'lumisummary')#small table first--right-most
281  queryCondition = coral.AttributeList()
282  queryCondition.extend ("runnumber", "unsigned int")
283  queryCondition.extend ("lumiversion", "string")
284  queryCondition["runnumber"].setData (int (runnum))
285  queryCondition["lumiversion"].setData (parameters.lumiversion)
286  conditionstring='lumisummary.RUNNUM =:runnumber and lumisummary.LUMIVERSION =:lumiversion AND lumisummary.CMSLSNUM=trg.CMSLSNUM and lumisummary.RUNNUM=trg.RUNNUM'
287  if len(parameters.beammode)!=0:
288  conditionstring=conditionstring+' and lumisummary.BEAMSTATUS=:beamstatus'
289  queryCondition.extend('beamstatus','string')
290  queryCondition['beamstatus'].setData(parameters.beammode)
291  query.setCondition(conditionstring,queryCondition)
292  query.addToOutputList ("lumisummary.CMSLSNUM", "cmsls")
293  query.addToOutputList ("lumisummary.INSTLUMI", "instlumi")
294  query.addToOutputList ("lumisummary.NUMORBIT", "norbits")
295  query.addToOutputList ("trg.TRGCOUNT", "trgcount")
296  query.addToOutputList ("trg.BITNAME", "bitname")
297  query.addToOutputList ("trg.DEADTIME", "trgdeadtime")
298  query.addToOutputList ("trg.PRESCALE", "trgprescale")
299  query.addToOutputList ("trg.BITNUM", "trgbitnum")
300 
301  result = coral.AttributeList()
302  result.extend ("cmsls", "unsigned int")
303  result.extend ("instlumi", "float")
304  result.extend ("norbits", "unsigned int")
305  result.extend ("trgcount", "unsigned int")
306  result.extend ("bitname", "string")
307  result.extend ("trgdeadtime", "unsigned long long")
308  result.extend ("trgprescale", "unsigned int")
309  result.extend ("trgbitnum", "unsigned int")
310  trgprescalemap = {}
311  query.defineOutput (result)
312  cursor = query.execute()
313  while cursor.next():
314  cmsls = cursor.currentRow()["cmsls"].data()
315  instlumi = cursor.currentRow()["instlumi"].data()*parameters.norm
316  norbits = cursor.currentRow()["norbits"].data()
317  trgcount = cursor.currentRow()["trgcount"].data()
318  trgbitname = cursor.currentRow()["bitname"].data()
319  trgdeadtime = cursor.currentRow()["trgdeadtime"].data()
320  trgprescale = cursor.currentRow()["trgprescale"].data()
321  trgbitnum = cursor.currentRow()["trgbitnum"].data()
322  if cmsls == 1:
323  if not trgprescalemap.has_key (trgbitname):
324  trgprescalemap[trgbitname] = trgprescale
325  if trgbitnum == 0:
326  if not deadtable.has_key (cmsls):
327  deadtable[cmsls] = []
328  deadtable[cmsls].append (trgdeadtime)
329  deadtable[cmsls].append (instlumi)
330  deadtable[cmsls].append (trgcount)
331  deadtable[cmsls].append (norbits)
332  deadtable[cmsls].append (trgprescale)
333  cursor.close()
334  del query
335  dbsession.transaction().commit()
336 
337  #
338  #consolidate results
339  #
340  #trgtable
341  #print 'trgprescalemap', trgprescalemap
342  #print lumidata[1]
343  for hpath, trgdataseq in lumidata[1].items():
344  bitn = trgdataseq[0]
345  if trgprescalemap.has_key (bitn) and len (trgdataseq) == 2:
346  lumidata[1][hpath].append (trgprescalemap[bitn])
347  #filter selected cmsls
348  lumidata[2] = filterDeadtable (deadtable, lslist)
349  #print 'lslist ',lslist
350  if not parameters.noWarnings:
351  if len(lumidata[2])!=0:
352  for lumi, deaddata in lumidata[2].items():
353  if deaddata[1] == 0.0 and deaddata[2]!=0 and deaddata[0]!=0:
354  print '[Warning] : run %s :ls %d has 0 instlumi but trigger has data' % (runnum, lumi)
355  if (deaddata[2] == 0 or deaddata[0] == 0) and deaddata[1]!=0.0:
356  print '[Warning] : run %s :ls %d has 0 dead counts or 0 zerobias bit counts, but inst!=0' % (runnum, lumi)
357  #print 'lumidata[2] ', lumidata[2]
358  except Exception, e:
359  print str (e)
360  dbsession.transaction().rollback()
361  del dbsession
362  #print 'before return lumidata ', lumidata
363  ## if parameters.lumiXing:
364  ## xingLumiDict = xingLuminosityForRun (dbsession, runnum, parameters)
365  ## mergeXingLumi (lumidata, xingLumiDict)
366  return lumidata
367 
def recordedLumiForRun
def lumisummaryTableName
Definition: nameDealer.py:20
def trghltMapTableName
Definition: nameDealer.py:47
def hltTableName
Definition: nameDealer.py:38
def trgTableName
Definition: nameDealer.py:35
def cmsrunsummaryTableName
Definition: nameDealer.py:14
def lumiQueryAPI.runsByfillrange (   queryHandle,
  minFill,
  maxFill 
)
find all runs in the fill range inclusive
select runnum,fillnum from cmsrunsummary where fillnum>=:minFill and fillnum<=:maxFill
output: fillDict={fillnum:[runlist]}

Definition at line 1646 of file lumiQueryAPI.py.

References python.multivaluedict.append(), nameDealer.cmsrunsummaryTableName(), and runTheMatrix.data.

Referenced by specificLumi-2011.getFillFromDB(), specificLumi.getFillFromDB(), and lumiSumPlot.main().

1647 def runsByfillrange(queryHandle,minFill,maxFill):
1648  '''
1649  find all runs in the fill range inclusive
1650  select runnum,fillnum from cmsrunsummary where fillnum>=:minFill and fillnum<=:maxFill
1651  output: fillDict={fillnum:[runlist]}
1652  '''
1653  result={}
1654  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
1655  queryCondition=coral.AttributeList()
1656  queryCondition.extend('minFill','unsigned int')
1657  queryCondition.extend('maxFill','unsigned int')
1658  queryCondition['minFill'].setData(int(minFill))
1659  queryCondition['maxFill'].setData(int(maxFill))
1660  queryHandle.addToOutputList('RUNNUM','runnum')
1661  queryHandle.addToOutputList('FILLNUM','fillnum')
1662  queryHandle.setCondition('FILLNUM>=:minFill and FILLNUM<=:maxFill',queryCondition)
1663  queryResult=coral.AttributeList()
1664  queryResult.extend('runnum','unsigned int')
1665  queryResult.extend('fillnum','unsigned int')
1666  queryHandle.defineOutput(queryResult)
1667  cursor=queryHandle.execute()
1668  while cursor.next():
1669  runnum=cursor.currentRow()['runnum'].data()
1670  fillnum=cursor.currentRow()['fillnum'].data()
1671  if not result.has_key(fillnum):
1672  result[fillnum]=[runnum]
1673  else:
1674  result[fillnum].append(runnum)
1675  return result
def cmsrunsummaryTableName
Definition: nameDealer.py:14
def lumiQueryAPI.runsByTimerange (   queryHandle,
  minTime,
  maxTime 
)
find all runs in the time range inclusive
the selected run must have started after minTime and finished by maxTime
select runnum,to_char(startTime),to_char(stopTime) from cmsrunsummary where startTime>=timestamp(minTime) and stopTime<=timestamp(maxTime);
input: minTime,maxTime in python obj datetime.datetime
output: {runnum:[starttime,stoptime]} return in python obj datetime.datetime

Definition at line 1676 of file lumiQueryAPI.py.

References nameDealer.cmsrunsummaryTableName(), and runTheMatrix.data.

Referenced by lumiInstPlot.main(), and lumiSumPlot.main().

1677 def runsByTimerange(queryHandle,minTime,maxTime):
1678  '''
1679  find all runs in the time range inclusive
1680  the selected run must have started after minTime and finished by maxTime
1681  select runnum,to_char(startTime),to_char(stopTime) from cmsrunsummary where startTime>=timestamp(minTime) and stopTime<=timestamp(maxTime);
1682  input: minTime,maxTime in python obj datetime.datetime
1683  output: {runnum:[starttime,stoptime]} return in python obj datetime.datetime
1684  '''
1685  t=lumiTime.lumiTime()
1686  result={}
1687  coralminTime=coral.TimeStamp(minTime.year,minTime.month,minTime.day,minTime.hour,minTime.minute,minTime.second,0)
1688  coralmaxTime=coral.TimeStamp(maxTime.year,maxTime.month,maxTime.day,maxTime.hour,maxTime.minute,maxTime.second,0)
1689  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
1690  queryCondition=coral.AttributeList()
1691  queryCondition.extend('minTime','time stamp')
1692  queryCondition.extend('maxTime','time stamp')
1693  queryCondition['minTime'].setData(coralminTime)
1694  queryCondition['maxTime'].setData(coralmaxTime)
1695  queryHandle.addToOutputList('RUNNUM','runnum')
1696  queryHandle.addToOutputList('TO_CHAR(STARTTIME,\''+t.coraltimefm+'\')','starttime')
1697  queryHandle.addToOutputList('TO_CHAR(STOPTIME,\''+t.coraltimefm+'\')','stoptime')
1698  queryHandle.setCondition('STARTTIME>=:minTime and STOPTIME<=:maxTime',queryCondition)
1699  queryResult=coral.AttributeList()
1700  queryResult.extend('runnum','unsigned int')
1701  queryResult.extend('starttime','string')
1702  queryResult.extend('stoptime','string')
1703  queryHandle.defineOutput(queryResult)
1704  cursor=queryHandle.execute()
1705  while cursor.next():
1706  runnum=cursor.currentRow()['runnum'].data()
1707  starttimeStr=cursor.currentRow()['starttime'].data()
1708  stoptimeStr=cursor.currentRow()['stoptime'].data()
1709  if not result.has_key(runnum):
1710  result[runnum]=[t.StrToDatetime(starttimeStr),t.StrToDatetime(stoptimeStr)]
1711  return result
def cmsrunsummaryTableName
Definition: nameDealer.py:14
def lumiQueryAPI.runsummaryByrun (   queryHandle,
  runnum 
)
select fillnum,sequence,hltkey,to_char(starttime),to_char(stoptime) from cmsrunsummary where runnum=:runnum
output: [fillnum,sequence,hltkey,starttime,stoptime]

Definition at line 1044 of file lumiQueryAPI.py.

References nameDealer.cmsrunsummaryTableName(), and runTheMatrix.data.

Referenced by specificLumi-2011.getFillFromDB(), specificLumi.getFillFromDB(), lumiInstPlot.getInstLumiPerLS(), lumiSumPlot.getLumiOrderByLS(), lumiInstPlot.getLumiPerRun(), and lumiCalc.getPerLSData().

1045 def runsummaryByrun(queryHandle,runnum):
1046  '''
1047  select fillnum,sequence,hltkey,to_char(starttime),to_char(stoptime) from cmsrunsummary where runnum=:runnum
1048  output: [fillnum,sequence,hltkey,starttime,stoptime]
1049  '''
1050  t=lumiTime.lumiTime()
1051  result=[]
1052  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
1053  queryCondition=coral.AttributeList()
1054  queryCondition.extend('runnum','unsigned int')
1055  queryCondition['runnum'].setData(int(runnum))
1056  queryHandle.addToOutputList('FILLNUM','fillnum')
1057  queryHandle.addToOutputList('SEQUENCE','sequence')
1058  queryHandle.addToOutputList('HLTKEY','hltkey')
1059  queryHandle.addToOutputList('to_char(STARTTIME,\''+t.coraltimefm+'\')','starttime')
1060  queryHandle.addToOutputList('to_char(STOPTIME,\''+t.coraltimefm+'\')','stoptime')
1061  queryHandle.setCondition('RUNNUM=:runnum',queryCondition)
1062  queryResult=coral.AttributeList()
1063  queryResult.extend('fillnum','unsigned int')
1064  queryResult.extend('sequence','string')
1065  queryResult.extend('hltkey','string')
1066  queryResult.extend('starttime','string')
1067  queryResult.extend('stoptime','string')
1068  queryHandle.defineOutput(queryResult)
1069  cursor=queryHandle.execute()
1070  while cursor.next():
1071  result.append(cursor.currentRow()['fillnum'].data())
1072  result.append(cursor.currentRow()['sequence'].data())
1073  result.append(cursor.currentRow()['hltkey'].data())
1074  result.append(cursor.currentRow()['starttime'].data())
1075  result.append(cursor.currentRow()['stoptime'].data())
1076  #if len(result)!=5:
1077  # print 'wrong runsummary result'
1078  # raise
1079  return result
def cmsrunsummaryTableName
Definition: nameDealer.py:14
def lumiQueryAPI.setupSession (   connectString,
  siteconfpath,
  parameters,
  debug = False 
)
returns database session

Definition at line 866 of file lumiQueryAPI.py.

867 def setupSession (connectString, siteconfpath, parameters, debug = False):
868  '''returns database session'''
869  connectparser = connectstrParser.connectstrParser (connectString)
870  connectparser.parse()
871  usedefaultfrontierconfig = False
872  cacheconfigpath = ''
873  if connectparser.needsitelocalinfo():
874  if not siteconfpath:
875  cacheconfigpath = os.environ['CMS_PATH']
876  if cacheconfigpath:
877  cacheconfigpath = os.path.join (cacheconfigpath, 'SITECONF', 'local', 'JobConfig', 'site-local-config.xml')
878  else:
879  usedefaultfrontierconfig = True
880  else:
881  cacheconfigpath = siteconfpath
882  cacheconfigpath = os.path.join (cacheconfigpath, 'site-local-config.xml')
884  if usedefaultfrontierconfig:
885  ccp.parseString (parameters.defaultfrontierConfigString)
886  else:
887  ccp.parse (cacheconfigpath)
888  connectString = connectparser.fullfrontierStr (connectparser.schemaname(), ccp.parameterdict())
889  svc = coral.ConnectionService()
890  if debug :
891  msg = coral.MessageStream ('')
892  msg.setMsgVerbosity (coral.message_Level_Debug)
893  parameters.verbose = True
894  session = svc.connect (connectString, accessMode = coral.access_ReadOnly)
895  session.typeConverter().setCppTypeForSqlType ("unsigned int", "NUMBER (10)")
896  session.typeConverter().setCppTypeForSqlType ("unsigned long long", "NUMBER (20)")
897  return session, svc
898 
899 
def lumiQueryAPI.splitlistToRangeString (   inPut)

Definition at line 414 of file lumiQueryAPI.py.

415 def splitlistToRangeString (inPut):
416  result = []
417  first = inPut[0]
418  last = inPut[0]
419  result.append ([inPut[0]])
420  counter = 0
421  for i in inPut[1:]:
422  if i == last+1:
423  result[counter].append (i)
424  else:
425  counter += 1
426  result.append ([i])
427  last = i
428  return ', '.join (['['+str (min (x))+'-'+str (max (x))+']' for x in result])
429 
def splitlistToRangeString
def lumiQueryAPI.trgAllbitsByrun (   queryHandle,
  runnum 
)
all you ever want to know about trigger
select cmslsnum,trgcount,deadtime,bitnum,bitname,prescale from trg where runnum=:runnum order by  bitnum,cmslsnum
this can be changed to blob query later
output: {cmslsnum:{bitname:[bitnum,trgcount,deadtime,prescale]}}

Definition at line 1318 of file lumiQueryAPI.py.

References runTheMatrix.data, and nameDealer.trgTableName().

1319 def trgAllbitsByrun(queryHandle,runnum):
1320  '''
1321  all you ever want to know about trigger
1322  select cmslsnum,trgcount,deadtime,bitnum,bitname,prescale from trg where runnum=:runnum order by bitnum,cmslsnum
1323  this can be changed to blob query later
1324  output: {cmslsnum:{bitname:[bitnum,trgcount,deadtime,prescale]}}
1325  '''
1326  result={}
1327  queryHandle.addToTableList(nameDealer.trgTableName())
1328  queryCondition=coral.AttributeList()
1329  queryCondition.extend('runnum','unsigned int')
1330  queryCondition['runnum'].setData(int(runnum))
1331  queryHandle.addToOutputList('cmslsnum')
1332  queryHandle.addToOutputList('trgcount')
1333  queryHandle.addToOutputList('deadtime')
1334  queryHandle.addToOutputList('bitnum')
1335  queryHandle.addToOutputList('bitname')
1336  queryHandle.addToOutputList('prescale')
1337  queryHandle.setCondition('runnum=:runnum',queryCondition)
1338  queryResult=coral.AttributeList()
1339  queryResult.extend('cmslsnum','unsigned int')
1340  queryResult.extend('trgcount','unsigned int')
1341  queryResult.extend('deadtime','unsigned long long')
1342  queryResult.extend('bitnum','unsigned int')
1343  queryResult.extend('bitname','string')
1344  queryResult.extend('prescale','unsigned int')
1345  queryHandle.defineOutput(queryResult)
1346  queryHandle.addToOrderList('bitnum')
1347  queryHandle.addToOrderList('cmslsnum')
1348  cursor=queryHandle.execute()
1349  while cursor.next():
1350  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1351  trgcount=cursor.currentRow()['trgcount'].data()
1352  deadtime=cursor.currentRow()['deadtime'].data()
1353  bitnum=cursor.currentRow()['bitnum'].data()
1354  bitname=cursor.currentRow()['bitname'].data()
1355  prescale=cursor.currentRow()['prescale'].data()
1356  if not result.has_key(cmslsnum):
1357  dataperLS={}
1358  dataperLS[bitname]=[bitnum,trgcount,deadtime,prescale]
1359  result[cmslsnum]=dataperLS
1360  else:
1361  result[cmslsnum][bitname]=[bitnum,trgcount,deadtime,prescale]
1362  return result
1363 
def trgTableName
Definition: nameDealer.py:35
def lumiQueryAPI.trgbitzeroByrun (   queryHandle,
  runnum 
)
select cmslsnum,trgcount,deadtime,bitname,prescale from trg where runnum=:runnum and bitnum=0;
output: {cmslsnum:[trgcount,deadtime,bitname,prescale]}

Definition at line 1176 of file lumiQueryAPI.py.

References runTheMatrix.data, and nameDealer.trgTableName().

Referenced by lumiInstPlot.getLumiPerRun(), and lumiCalc.getPerLSData().

1177 def trgbitzeroByrun(queryHandle,runnum):
1178  '''
1179  select cmslsnum,trgcount,deadtime,bitname,prescale from trg where runnum=:runnum and bitnum=0;
1180  output: {cmslsnum:[trgcount,deadtime,bitname,prescale]}
1181  '''
1182  result={}
1183  queryHandle.addToTableList(nameDealer.trgTableName())
1184  queryCondition=coral.AttributeList()
1185  queryCondition.extend('runnum','unsigned int')
1186  queryCondition.extend('bitnum','unsigned int')
1187  queryCondition['runnum'].setData(int(runnum))
1188  queryCondition['bitnum'].setData(int(0))
1189  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1190  queryHandle.addToOutputList('TRGCOUNT','trgcount')
1191  queryHandle.addToOutputList('DEADTIME','deadtime')
1192  queryHandle.addToOutputList('BITNAME','bitname')
1193  queryHandle.addToOutputList('PRESCALE','prescale')
1194  queryHandle.setCondition('RUNNUM=:runnum and BITNUM=:bitnum',queryCondition)
1195  queryResult=coral.AttributeList()
1196  queryResult.extend('cmslsnum','unsigned int')
1197  queryResult.extend('trgcount','unsigned int')
1198  queryResult.extend('deadtime','unsigned int')
1199  queryResult.extend('bitname','string')
1200  queryResult.extend('prescale','unsigned int')
1201  queryHandle.defineOutput(queryResult)
1202  cursor=queryHandle.execute()
1203  while cursor.next():
1204  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1205  trgcount=cursor.currentRow()['trgcount'].data()
1206  deadtime=cursor.currentRow()['deadtime'].data()
1207  bitname=cursor.currentRow()['bitname'].data()
1208  prescale=cursor.currentRow()['prescale'].data()
1209  if not result.has_key(cmslsnum):
1210  result[cmslsnum]=[trgcount,deadtime,bitname,prescale]
1211  return result
def trgTableName
Definition: nameDealer.py:35
def lumiQueryAPI.trgBybitnameByrun (   queryHandle,
  runnum,
  bitname 
)
select cmslsnum,trgcount,deadtime,bitnum,prescale from trg where runnum=:runnum and bitname=:bitname;
output: {cmslsnum:[trgcount,deadtime,bitnum,prescale]}

Definition at line 1282 of file lumiQueryAPI.py.

References runTheMatrix.data, and nameDealer.trgTableName().

Referenced by lumiSumPlot.getLumiInfoForRuns(), and dumpPrescale.main().

1283 def trgBybitnameByrun(queryHandle,runnum,bitname):
1284  '''
1285  select cmslsnum,trgcount,deadtime,bitnum,prescale from trg where runnum=:runnum and bitname=:bitname;
1286  output: {cmslsnum:[trgcount,deadtime,bitnum,prescale]}
1287  '''
1288  result={}
1289  queryHandle.addToTableList(nameDealer.trgTableName())
1290  queryCondition=coral.AttributeList()
1291  queryCondition.extend('runnum','unsigned int')
1292  queryCondition.extend('bitname','string')
1293  queryCondition['runnum'].setData(int(runnum))
1294  queryCondition['bitname'].setData(bitname)
1295  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1296  queryHandle.addToOutputList('TRGCOUNT','trgcount')
1297  queryHandle.addToOutputList('DEADTIME','deadtime')
1298  queryHandle.addToOutputList('BITNUM','bitnum')
1299  queryHandle.addToOutputList('PRESCALE','prescale')
1300  queryHandle.setCondition('RUNNUM=:runnum and BITNAME=:bitname',queryCondition)
1301  queryResult=coral.AttributeList()
1302  queryResult.extend('cmslsnum','unsigned int')
1303  queryResult.extend('trgcount','unsigned int')
1304  queryResult.extend('deadtime','unsigned long long')
1305  queryResult.extend('bitnum','unsigned int')
1306  queryResult.extend('prescale','unsigned int')
1307  queryHandle.defineOutput(queryResult)
1308  cursor=queryHandle.execute()
1309  while cursor.next():
1310  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1311  trgcount=cursor.currentRow()['trgcount'].data()
1312  deadtime=cursor.currentRow()['deadtime'].data()
1313  bitnum=cursor.currentRow()['bitnum'].data()
1314  prescale=cursor.currentRow()['prescale'].data()
1315  if not result.has_key(cmslsnum):
1316  result[cmslsnum]=[trgcount,deadtime,bitnum,prescale]
1317  return result
def trgTableName
Definition: nameDealer.py:35
def lumiQueryAPI.validation (   queryHandle,
  run = None,
  cmsls = None 
)
retrieve validation data per run or all
input: run. if not run, retrive all; if cmslsnum selection list pesent, filter out unselected result
output: {run:[[cmslsnum,status,comment]]}

Definition at line 975 of file lumiQueryAPI.py.

References python.multivaluedict.append(), runTheMatrix.data, and nameDealer.lumivalidationTableName().

Referenced by lumiValidate.getValidationData(), and lumiCalc.getValidationData().

976 def validation(queryHandle,run=None,cmsls=None):
977  '''retrieve validation data per run or all
978  input: run. if not run, retrive all; if cmslsnum selection list pesent, filter out unselected result
979  output: {run:[[cmslsnum,status,comment]]}
980  '''
981  result={}
982  queryHandle.addToTableList(nameDealer.lumivalidationTableName())
983  queryHandle.addToOutputList('RUNNUM','runnum')
984  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
985  queryHandle.addToOutputList('FLAG','flag')
986  queryHandle.addToOutputList('COMMENT','comment')
987  if run:
988  queryCondition='RUNNUM=:runnum'
989  queryBind=coral.AttributeList()
990  queryBind.extend('runnum','unsigned int')
991  queryBind['runnum'].setData(run)
992  queryHandle.setCondition(queryCondition,queryBind)
993  queryResult=coral.AttributeList()
994  queryResult.extend('runnum','unsigned int')
995  queryResult.extend('cmslsnum','unsigned int')
996  queryResult.extend('flag','string')
997  queryResult.extend('comment','string')
998  queryHandle.defineOutput(queryResult)
999  cursor=queryHandle.execute()
1000  while cursor.next():
1001  runnum=cursor.currentRow()['runnum'].data()
1002  if not result.has_key(runnum):
1003  result[runnum]=[]
1004  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1005  flag=cursor.currentRow()['flag'].data()
1006  comment=cursor.currentRow()['comment'].data()
1007  result[runnum].append([cmslsnum,flag,comment])
1008  if run and cmsls and len(cmsls)!=0:
1009  selectedresult={}
1010  for runnum,perrundata in result.items():
1011  for lsdata in perrundata:
1012  if lsdata[0] not in cmsls:
1013  continue
1014  if not selectedresult.has_key(runnum):
1015  selectedresult[runnum]=[]
1016  selectedresult[runnum].append(lsdata)
1017  return selectedresult
1018  else:
1019  return result
def lumivalidationTableName
Definition: nameDealer.py:56
def lumiQueryAPI.xingLuminosityForRun (   dbsession,
  runnum,
  parameters,
  lumiXingDict = {},
  maxLumiSection = None 
)
Given a run number and a minimum xing luminosity value,
returns a dictionary (keyed by (run, lumi section)) where the
value is a list of tuples of (xingID, xingLum).

- For all xing luminosities, simply set minLumValue to 0.

- If you want one dictionary for several runs, pass it in to
  "lumiXingDict"


select 
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

Definition at line 760 of file lumiQueryAPI.py.

References runTheMatrix.data, nameDealer.lumidetailTableName(), and nameDealer.lumisummaryTableName().

Referenced by dumpOverview().

761  maxLumiSection = None):
762  '''Given a run number and a minimum xing luminosity value,
763  returns a dictionary (keyed by (run, lumi section)) where the
764  value is a list of tuples of (xingID, xingLum).
765 
766  - For all xing luminosities, simply set minLumValue to 0.
767 
768  - If you want one dictionary for several runs, pass it in to
769  "lumiXingDict"
770 
771 
772  select
773  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
774  '''
775  try:
776  runnum = int (runnum)
777  dbsession.transaction().start (True)
778  schema = dbsession.schema (parameters.lumischema)
779  if not schema:
780  raise 'cannot connect to schema ', parameters.lumischema
781  detailOutput = coral.AttributeList()
782  detailOutput.extend ('startorbit', 'unsigned int')
783  detailOutput.extend ('cmslsnum', 'unsigned int')
784  detailOutput.extend ('bxlumivalue', 'blob')
785  detailOutput.extend ('bxlumierror', 'blob')
786  detailOutput.extend ('bxlumiquality', 'blob')
787  detailOutput.extend ('algoname', 'string')
788  detailCondition = coral.AttributeList()
789  detailCondition.extend ('runnum', 'unsigned int')
790  detailCondition.extend ('algoname', 'string')
791  detailCondition['runnum'].setData (runnum)
792  detailCondition['algoname'].setData ('OCC1')
793  query = schema.newQuery()
794  query.addToTableList(nameDealer.lumisummaryTableName(), 's')
795  query.addToTableList(nameDealer.lumidetailTableName(), 'd')
796  query.addToOutputList ('s.STARTORBIT', 'startorbit')
797  query.addToOutputList ('s.CMSLSNUM', 'cmslsnum')
798  query.addToOutputList ('d.BXLUMIVALUE', 'bxlumivalue')
799  query.addToOutputList ('d.BXLUMIERROR', 'bxlumierror')
800  query.addToOutputList ('d.BXLUMIQUALITY', 'bxlumiquality')
801  query.addToOutputList ('d.ALGONAME', 'algoname')
802  query.setCondition ('s.RUNNUM =:runnum and d.ALGONAME =:algoname and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',detailCondition)
803  query.addToOrderList ('s.CMSLSNUM')
804  query.defineOutput (detailOutput)
805  cursor = query.execute()
806  count = 0
807  while cursor.next():
808  ## ## Note: If you are going to break out of this loop early,
809  ## ## make sure you call cursor.close():
810  ##
811  ## if count > 20 :
812  ## cursor.close()
813  ## break
814  ## count += 1
815  cmslsnum = cursor.currentRow()['cmslsnum'].data()
816  algoname = cursor.currentRow()['algoname'].data()
817  bxlumivalue = cursor.currentRow()['bxlumivalue'].data()
818  startorbit = cursor.currentRow()['startorbit'].data()
819 
820  if maxLumiSection and maxLumiSection < cmslsnum:
821  cursor.close()
822  break
823 
824  xingArray = array.array ('f')
825  xingArray.fromstring( bxlumivalue.readline() )
826  numPrinted = 0
827  xingLum = []
828  for index, lum in enumerate (xingArray):
829  lum *= parameters.normFactor
830  if lum < parameters.xingMinLum:
831  continue
832  xingLum.append( (index, lum) )
833  lumiXingDict[ (runnum, cmslsnum) ] = xingLum
834  del query
835  dbsession.transaction().commit()
836  return lumiXingDict
837  except Exception, e:
838  print str (e)
839  print "whoops"
840  dbsession.transaction().rollback()
841  del dbsession
842 
def lumisummaryTableName
Definition: nameDealer.py:20
def lumidetailTableName
Definition: nameDealer.py:25

Variable Documentation

tuple lumiQueryAPI.allfills = allfills(q)

Definition at line 1782 of file lumiQueryAPI.py.

Referenced by allfills().

tuple lumiQueryAPI.allruns = allruns(schema,requireLumisummary=True,requireTrg=True,requireHlt=True)

Definition at line 1724 of file lumiQueryAPI.py.

Referenced by allruns().

string lumiQueryAPI.connectstr = 'oracle://cms_orcoff_prod/cms_lumi_prod'

Definition at line 1718 of file lumiQueryAPI.py.

tuple lumiQueryAPI.msg = coral.MessageStream('')

Definition at line 1713 of file lumiQueryAPI.py.

tuple lumiQueryAPI.q = schema.newQuery()

Definition at line 1781 of file lumiQueryAPI.py.

Referenced by JetAnaPythia< Jet >.analyze(), PhotonValidator.analyze(), L1TdeCSCTF.analyze(), TrackParameterAnalyzer.analyze(), HLTScalers.analyze(), CaloRecHitMetaCollection.at(), AlignmentTrackSelector.basicCuts(), PhysicsTools::AtomicId.build(), CandCombinerBase< OutputCollection, CandPtr >.combine(), AnalyticalCurvilinearJacobian.computeFullJacobian(), VVIObjDetails.cosint(), TtFullLepKinSolver.cubic(), TwoBodyDecayModel.curvilinearToCartesianJacobian(), PhysicsTools::VarProcessor.deriv(), lhef.domToLines(), EEQuadrant(), ConfigurationDBHandler.endElement(), lhef::LHEReader::XMLHandler.endElement(), LMFSeqDat.fetchByRunNumber(), TrackAnalyzer.fillHistosForState(), PrimaryVertexAnalyzer4PU.fillTrackHistos(), edm::Guid.fromString(), edm::ParameterSet.fromString(), GammaFunctionGenerator.gammaFrac(), lumi::idDealer.generateNextIDForTable(), TiXmlBase.GetEntity(), lumi::idDealer.getIDforTable(), MonitorElement.getQReport(), PrimaryVertexAnalyzer4PU.getSimTrkParameters(), pftools::CaloEllipse.getTheta(), L1MuGMTSortRankUnit.getVeryLowQualityLevel(), gen::Herwig6Instance.give(), ConversionFastHelix.helixStateAtVertex(), FastHelix.helixStateAtVertex(), GflashTrajectory.initializeTrajectory(), SeedFromConsecutiveHitsStraightLineCreator.initialKinematic(), RoadSearchTrackCandidateMakerAlgorithm.initialTrajectory(), JacobianCartesianToCurvilinear.JacobianCartesianToCurvilinear(), JacobianCartesianToLocal.JacobianCartesianToLocal(), JacobianCurvilinearToCartesian.JacobianCurvilinearToCartesian(), JacobianCurvilinearToLocal.JacobianCurvilinearToLocal(), JacobianLocalToCartesian.JacobianLocalToCartesian(), JacobianLocalToCurvilinear.JacobianLocalToCurvilinear(), reco::TrackProbabilityTagInfo.jetProbability(), JetProbabilityComputer.jetProbability(), JetBProbabilityComputer.jetProbability(), SteppingHelixPropagator.makeAtomStep(), match(), L1MuGMTMerger.merge_rank(), MergeRootfile(), NtpProducer< C >.NtpProducer(), edm::Guid.operator=(), edm::Guid.operator==(), HcalPacker.pack(), trigger::TriggerObject.particle(), RawParticle.PDGcharge(), CastorNominalCoderTemplate.process(), HcalNominalCoderTemplate.process(), HcalBeamMonitor.processEvent(), L3MuonCandidateProducerFromMuons.produce(), NtpProducer< C >.produce(), TtSemiEvtSolutionMaker.produce(), TtHadEvtSolutionMaker.produce(), L2MuonCandidateProducer.produce(), L3MuonCandidateProducer.produce(), Herwig6Hadronizer.pythiaStatusCode(), reco::Conversion.quality(), reco::TrackBase.quality(), GSUtilities.quantile(), RealQuadEquation.RealQuadEquation(), HcalCableMapper.record(), L1MuDTEtaProcessor.runEtaTrackFinder(), CustomPDGParser.s_charge(), BPhysicsOniaDQM.selGlobalMuon(), MuScleFitMuonSelector.selGlobalMuon(), MuScleFit.selGlobalMuon(), RawParticle.setCharge(), ObjectValidator.setEBRecHitCollection(), ObjectValidator.setEcalChannelStatus(), ObjectValidator.setEcalSeverityLevelAlgo(), ObjectValidator.setEERecHitCollection(), ObjectValidator.setHcalChannelQuality(), ObjectValidator.setHcalSeverityLevelComputer(), CSCCorrelatedLCTDigi.setQuality(), pat::HardEventHypothesis.setQuality(), reco::Conversion.setQuality(), reco::TrackBase.setQuality(), GenEventInfoProduct.setScales(), VVIObjDetails.sincosint(), VVIObjDetails.sinint(), HelixExtrapolatorToLine2Order.solve3rdOrder(), L1MuGMTSortRankUnit.sort_rank(), L1MuGMTLFMergeRankPtQLUT.SpecificLookup(), L1MuGMTLFSortRankPtQLUT.SpecificLookup(), L1MuGMTLFMergeRankEtaQLUT.SpecificLookup(), L1MuGMTLFSortRankEtaQLUT.SpecificLookup(), L1MuGMTLFMergeRankEtaQLUT.SpecificLookup_flag(), L1MuGMTLFSortRankEtaQLUT.SpecificLookup_rank_etaq(), L1MuGMTLFMergeRankEtaQLUT.SpecificLookup_rank_etaq(), L1MuGMTLFSortRankPtQLUT.SpecificLookup_rank_ptq(), L1MuGMTLFMergeRankPtQLUT.SpecificLookup_rank_ptq(), L1MuGMTLFSortRankEtaQLUT.SpecificLookup_vlq(), PhysicsTools.split(), ConversionFastHelix.straightLineStateAtVertex(), FastHelix.straightLineStateAtVertex(), TiXmlBase.StringEqual(), edm::service::ELfwkJobReport.summarization(), edm::service::ELoutput.summarization(), edm::ELlog4cplus.summarization(), L1MuGMTLFSortRankPtQLUT.TheLookupFunction(), L1MuGMTLFMergeRankEtaQLUT.TheLookupFunction(), L1MuonPixelTrackFitter.valInversePt(), SiStripClusterInfo.variance(), VVIObj.VVIObj(), and DCULVRVoltagesDat.writeArrayDB().

tuple lumiQueryAPI.schema = session.nominalSchema()

Definition at line 1723 of file lumiQueryAPI.py.

tuple lumiQueryAPI.session = svc.connect(connectstr,accessMode=coral.access_ReadOnly)

Definition at line 1719 of file lumiQueryAPI.py.

tuple lumiQueryAPI.svc = coral.ConnectionService()

Definition at line 1717 of file lumiQueryAPI.py.