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 1041 of file lumiQueryAPI.py.

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

1042 def allfills(queryHandle,filtercrazy=True):
1043  '''select distinct fillnum from cmsrunsummary
1044  there are crazy fill numbers. we assume they are not valid runs
1045  '''
1046  result=[]
1047  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
1048  queryHandle.addToOutputList('distinct FILLNUM','fillnum')
1049 
1050  if filtercrazy:
1051  queryCondition='FILLNUM>:zero and FILLNUM<:crazybig'
1052  queryBind=coral.AttributeList()
1053  queryBind.extend('zero','unsigned int')
1054  queryBind.extend('crazybig','unsigned int')
1055  queryBind['zero'].setData(int(0))
1056  queryBind['crazybig'].setData(int(29701))
1057  queryHandle.setCondition(queryCondition,queryBind)
1058  queryResult=coral.AttributeList()
1059  queryResult.extend('fillnum','unsigned int')
1060  queryHandle.defineOutput(queryResult)
1061  cursor=queryHandle.execute()
1062  while cursor.next():
1063  result.append(cursor.currentRow()['fillnum'].data())
1064  result.sort()
return result
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def cmsrunsummaryTableName
Definition: nameDealer.py:16
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 923 of file lumiQueryAPI.py.

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

924 def allruns(schemaHandle,requireRunsummary=True,requireLumisummary=False,requireTrg=False,requireHlt=False):
925  '''
926  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.
927  '''
928  if not requireRunsummary and not requireLumiummary and not requireTrg and not requireHlt:
929  print 'must require at least one table'
930  raise
931  runresult=[]
932  runlist=[]
933  numdups=0
934  if requireRunsummary:
935  numdups=numdups+1
936  queryHandle=schemaHandle.newQuery()
937  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
938  queryHandle.addToOutputList("RUNNUM","run")
939  #queryBind=coral.AttributeList()
940  result=coral.AttributeList()
941  result.extend("run","unsigned int")
942  queryHandle.defineOutput(result)
943  cursor=queryHandle.execute()
944  while cursor.next():
945  r=cursor.currentRow()['run'].data()
946  runlist.append(r)
947  del queryHandle
948  if requireLumisummary:
949  numdups=numdups+1
950  queryHandle=schemaHandle.newQuery()
951  queryHandle.addToTableList(nameDealer.lumisummaryTableName())
952  queryHandle.addToOutputList("distinct RUNNUM","run")
953  #queryBind=coral.AttributeList()
954  result=coral.AttributeList()
955  result.extend("run","unsigned int")
956  queryHandle.defineOutput(result)
957  cursor=queryHandle.execute()
958  while cursor.next():
959  r=cursor.currentRow()['run'].data()
960  runlist.append(r)
961  del queryHandle
962  if requireTrg:
963  numdups=numdups+1
964  queryHandle=schemaHandle.newQuery()
965  queryHandle.addToTableList(nameDealer.trgTableName())
966  queryHandle.addToOutputList("distinct RUNNUM","run")
967  #queryBind=coral.AttributeList()
968  result=coral.AttributeList()
969  result.extend("run","unsigned int")
970  queryHandle.defineOutput(result)
971  cursor=queryHandle.execute()
972  while cursor.next():
973  r=cursor.currentRow()['run'].data()
974  runlist.append(r)
975  del queryHandle
976  if requireHlt:
977  numdups=numdups+1
978  queryHandle=schemaHandle.newQuery()
979  queryHandle.addToTableList(nameDealer.hltTableName())
980  queryHandle.addToOutputList("distinct RUNNUM","run")
981  #queryBind=coral.AttributeList()
982  result=coral.AttributeList()
983  result.extend("run","unsigned int")
984  queryHandle.defineOutput(result)
985  cursor=queryHandle.execute()
986  while cursor.next():
987  r=cursor.currentRow()['run'].data()
988  runlist.append(r)
989  del queryHandle
990  dupresult=CommonUtil.count_dups(runlist)
991  for dup in dupresult:
992  if dup[1]==numdups:
993  runresult.append(dup[0])
994  runresult.sort()
995  return runresult
def lumisummaryTableName
Definition: nameDealer.py:25
def hltTableName
Definition: nameDealer.py:55
def count_dups
Definition: CommonUtil.py:137
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def trgTableName
Definition: nameDealer.py:52
def cmsrunsummaryTableName
Definition: nameDealer.py:16
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 1469 of file lumiQueryAPI.py.

References python.multivaluedict.append(), data, and CommonUtil.unpackBlobtoArray().

1470 def beamIntensityForRun(query,parameters,runnum):
1471  '''
1472  select CMSBXINDEXBLOB,BEAMINTENSITYBLOB_1,BEAMINTENSITYBLOB_2 from LUMISUMMARY where runnum=146315 and LUMIVERSION='0001'
1473 
1474  output : result {startorbit: [(bxidx,beam1intensity,beam2intensity)]}
1475  '''
1476  result={} #{startorbit:[(bxidx,occlumi,occlumierr,beam1intensity,beam2intensity)]}
1477 
1478  lumisummaryOutput=coral.AttributeList()
1479  lumisummaryOutput.extend('cmslsnum','unsigned int')
1480  lumisummaryOutput.extend('startorbit','unsigned int')
1481  lumisummaryOutput.extend('bxindexblob','blob');
1482  lumisummaryOutput.extend('beamintensityblob1','blob');
1483  lumisummaryOutput.extend('beamintensityblob2','blob');
1484  condition=coral.AttributeList()
1485  condition.extend('runnum','unsigned int')
1486  condition.extend('lumiversion','string')
1487  condition['runnum'].setData(int(runnum))
1488  condition['lumiversion'].setData(parameters.lumiversion)
1489 
1490  query.addToTableList(parameters.lumisummaryname)
1491  query.addToOutputList('CMSLSNUM','cmslsnum')
1492  query.addToOutputList('STARTORBIT','startorbit')
1493  query.addToOutputList('CMSBXINDEXBLOB','bxindexblob')
1494  query.addToOutputList('BEAMINTENSITYBLOB_1','beamintensityblob1')
1495  query.addToOutputList('BEAMINTENSITYBLOB_2','beamintensityblob2')
1496  query.setCondition('RUNNUM=:runnum AND LUMIVERSION=:lumiversion',condition)
1497  query.defineOutput(lumisummaryOutput)
1498  cursor=query.execute()
1499  while cursor.next():
1500  #cmslsnum=cursor.currentRow()['cmslsnum'].data()
1501  startorbit=cursor.currentRow()['startorbit'].data()
1502  bxidx=[]
1503  bb1=[]
1504  bb2=[]
1505  bxindexblob=None
1506  beamintensityblob1=None
1507  beamintensityblob2=None
1508  if not cursor.currentRow()["bxindexblob"].isNull():
1509  bxindexblob=cursor.currentRow()['bxindexblob'].data()
1510  if bxindexblob and bxindexblob.readline()!=None:
1511  bxidx=CommonUtil.unpackBlobtoArray(bxindexblob,'h')
1512  if not cursor.currentRow()['beamintensityblob1'].isNull():
1513  beamintensityblob1=cursor.currentRow()['beamintensityblob1'].data()
1514  if beamintensityblob1 and beamintensityblob1.readline()!=None:
1515  bb1=CommonUtil.unpackBlobtoArray(beamintensityblob1,'f')
1516  if not cursor.currentRow()['beamintensityblob2'].isNull():
1517  beamintensityblob2=cursor.currentRow()['beamintensityblob2'].data()
1518  if beamintensityblob2 and beamintensityblob2.readline()!=None:
1519  bb2=CommonUtil.unpackBlobtoArray(beamintensityblob2,'f')
1520  if not result.has_key(startorbit):
1521  result[startorbit]=[]
1522  for idx,bxidxvalue in enumerate(bxidx):
1523  try:
1524  b1intensity=bb1[idx]
1525  except IndexError:
1526  b1intensity=0.0
1527  try:
1528  b2intensity=bb2[idx]
1529  except IndexError:
1530  b2intensity=0.0
1531  result[startorbit].append((bxidxvalue,b1intensity,b2intensity))
1532  del bxidx[:]
1533  del bb1[:]
1534  del bb2[:]
1535  return result
def unpackBlobtoArray
Definition: CommonUtil.py:229
def beamIntensityForRun
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def lumiQueryAPI.calculateEffective (   trgtable,
  totalrecorded 
)
input: trgtable{hltpath:[l1seed, hltprescale, l1prescale]}, totalrecorded (float)
output:{hltpath, recorded}

Definition at line 445 of file lumiQueryAPI.py.

446 def calculateEffective (trgtable, totalrecorded):
447  """
448  input: trgtable{hltpath:[l1seed, hltprescale, l1prescale]}, totalrecorded (float)
449  output:{hltpath, recorded}
450  """
451  #print 'inputtrgtable', trgtable
452  result = {}
453  for hltpath, data in trgtable.items():
454  if len (data) == 3:
455  result[hltpath] = totalrecorded/ (data[1]*data[2])
456  else:
457  result[hltpath] = 0.0
458  return result
459 
def calculateEffective
def lumiQueryAPI.calculateTotalRecorded (   deadtable)
input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]}
output: recordedLumi

Definition at line 410 of file lumiQueryAPI.py.

411 def calculateTotalRecorded (deadtable):
412  """
413  input: {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]}
414  output: recordedLumi
415  """
416  recordedLumi = 0.0
417  for myls, d in deadtable.items():
418  instLumi = d[1]
419  #deadfrac = float (d[0])/float (d[2]*3564)
420  #print myls, float (d[2])
421  if float (d[2]) == 0.0:
422  deadfrac = 1.0
423  else:
424  deadfrac = float (d[0])/(float (d[2])*float (d[-1]))
425  lstime = lslengthsec (d[3], 3564)
426  recordedLumi += instLumi* (1.0-deadfrac)*lstime
427  return recordedLumi
428 
def calculateTotalRecorded
def lumiQueryAPI.calibratedDetailForRunLimitresult (   query,
  parameters,
  runnum,
  algoname = 'OCC1',
  finecorrection = None 
)
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):[(index,lumivalue,lumierr),]}

Definition at line 1536 of file lumiQueryAPI.py.

References data, and max().

1537 def calibratedDetailForRunLimitresult(query,parameters,runnum,algoname='OCC1',finecorrection=None):
1538  '''select
1539  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
1540  result={(startorbit,cmslsnum):[(index,lumivalue,lumierr),]}
1541  '''
1542  result={}
1543  detailOutput=coral.AttributeList()
1544  detailOutput.extend('cmslsnum','unsigned int')
1545  detailOutput.extend('startorbit','unsigned int')
1546  detailOutput.extend('bxlumivalue','blob')
1547  detailOutput.extend('bxlumierror','blob')
1548  detailCondition=coral.AttributeList()
1549  detailCondition.extend('runnum','unsigned int')
1550  detailCondition.extend('algoname','string')
1551  detailCondition['runnum'].setData(runnum)
1552  detailCondition['algoname'].setData(algoname)
1553 
1554  query.addToTableList(parameters.lumisummaryname,'s')
1555  query.addToTableList(parameters.lumidetailname,'d')
1556  query.addToOutputList('s.CMSLSNUM','cmslsnum')
1557  query.addToOutputList('s.STARTORBIT','startorbit')
1558  query.addToOutputList('d.BXLUMIVALUE','bxlumivalue')
1559  query.addToOutputList('d.BXLUMIERROR','bxlumierror')
1560  query.addToOutputList('d.BXLUMIQUALITY','bxlumiquality')
1561  query.setCondition('s.RUNNUM=:runnum and d.ALGONAME=:algoname and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',detailCondition)
1562  query.defineOutput(detailOutput)
1563  cursor=query.execute()
1564  while cursor.next():
1565  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1566  bxlumivalue=cursor.currentRow()['bxlumivalue'].data()
1567  bxlumierror=cursor.currentRow()['bxlumierror'].data()
1568  startorbit=cursor.currentRow()['startorbit'].data()
1569  bxlumivalueArray=array.array('f')
1570  bxlumivalueArray.fromstring(bxlumivalue.readline())
1571  bxlumierrorArray=array.array('f')
1572  bxlumierrorArray.fromstring(bxlumierror.readline())
1573  xingLum=[]
1574  #apply selection criteria
1575  maxlumi=0.0
1576  if len(bxlumivalueArray)!=0:
1577  maxlumi=max(bxlumivalueArray)
1578  avginstlumi=0.0
1579  if len(bxlumivalueArray)!=0:
1580  avginstlumi=sum(bxlumivalueArray)
1581  for index,lum in enumerate(bxlumivalueArray):
1582  lumierror = bxlumierrorArray[index]
1583  if lum<max(parameters.xingMinLum,maxlumi*0.2):
1584  continue
1585  mynorm=parameters.normFactor
1586  if finecorrection:
1587  lum=lumiCorrections.applyfinecorrectionBX(lum,avginstlumi*mynorm,mynorm,finecorrection[0],finecorrection[1],finecorrection[2])
1588  lumierror=lumiCorrections.applyfinecorrectionBX(lumierror,avginstlumi*mynorm,mynorm,finecorrection[0],finecorrection[1],finecorrection[2])
1589  else:
1590  lum*=mynorm
1591  lumierror*=mynorm
1592  xingLum.append( (index,lum,lumierror) )
1593  if len(xingLum)!=0:
1594  result[(startorbit,cmslsnum)]=xingLum
1595  return result
const T & max(const T &a, const T &b)
def calibratedDetailForRunLimitresult
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def lumiQueryAPI.deliveredLumiForRange (   dbsession,
  parameters,
  inputRange,
  finecorrections = None 
)
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,finecorrections=None):
84  '''Takes either single run as a string or dictionary of run ranges'''
85  lumidata = []
86  runs=[]
87  if isinstance(inputRange, str):
88  runs.append(int(inputRange))
89  else:
90  runs=inputRange.runs()
91  for r in sorted(runs):
92  if parameters.verbose:
93  print "run", run
94  c=None
95  if finecorrections:
96  c=finecorrections[r]
97  lumidata.append( deliveredLumiForRun (dbsession, parameters,r,finecorrections=c) )
98  return lumidata
def deliveredLumiForRange
Definition: lumiQueryAPI.py:82
def lumiQueryAPI.deliveredLumiForRun (   dbsession,
  parameters,
  runnum,
  finecorrections = None 
)
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)

optional corrections=None/(constfactor,afterglowfactor,nonlinearfactor)

Definition at line 158 of file lumiQueryAPI.py.

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

159 def deliveredLumiForRun (dbsession, parameters, runnum, finecorrections=None ):
160  """
161  select sum (INSTLUMI), count (INSTLUMI) from lumisummary where runnum = 124025 and lumiversion = '0001';
162  select INSTLUMI,NUMORBIT from lumisummary where runnum = 124025 and lumiversion = '0001'
163  query result unit E27cm^-2 (= 1 / mb)
164 
165  optional corrections=None/(constfactor,afterglowfactor,nonlinearfactor)
166  """
167  #if parameters.verbose:
168  # print 'deliveredLumiForRun : norm : ', parameters.norm, ' : run : ', runnum
169  #output ['run', 'totalls', 'delivered', 'beammode']
170  delivered = 0.0
171  totalls = 0
172  try:
173  conditionstring="RUNNUM = :runnum AND LUMIVERSION = :lumiversion"
174  dbsession.transaction().start (True)
175  schema = dbsession.nominalSchema()
176  query = schema.tableHandle (nameDealer.lumisummaryTableName()).newQuery()
177  query.addToOutputList("INSTLUMI",'instlumi')
178  query.addToOutputList ("NUMORBIT", "norbits")
179  queryBind = coral.AttributeList()
180  queryBind.extend ("runnum", "unsigned int")
181  queryBind.extend ("lumiversion", "string")
182  queryBind["runnum"].setData (int (runnum))
183  queryBind["lumiversion"].setData (parameters.lumiversion)
184  #print parameters.beammode
185  if len(parameters.beammode)!=0:
186  conditionstring=conditionstring+' and BEAMSTATUS=:beamstatus'
187  queryBind.extend('beamstatus','string')
188  queryBind['beamstatus'].setData(parameters.beammode)
189  result = coral.AttributeList()
190  result.extend ("instlumi", "float")
191  result.extend ("norbits", "unsigned int")
192  query.defineOutput (result)
193  query.setCondition (conditionstring,queryBind)
194  cursor = query.execute()
195  while cursor.next():
196  instlumi = cursor.currentRow()['instlumi'].data()
197  norbits = cursor.currentRow()['norbits'].data()
198  if finecorrections is not None:
199  instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
200  if instlumi is not None and norbits is not None:
201  lstime = lslengthsec(norbits, parameters.NBX)
202  delivered=delivered+instlumi*parameters.norm*lstime
203  totalls+=1
204  del query
205  dbsession.transaction().commit()
206  lumidata = []
207  if delivered == 0.0:
208  lumidata = [str (runnum), 'N/A', 'N/A', 'N/A']
209  else:
210  lumidata = [str (runnum), str (totalls), '%.3f'%delivered, parameters.beammode]
211  return lumidata
212  except Exception, e:
213  print str (e)
214  dbsession.transaction().rollback()
215  del dbsession
def lumisummaryTableName
Definition: nameDealer.py:25
def deliveredLumiForRun
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def lumiQueryAPI.dumpData (   lumidata,
  filename 
)
input params: lumidata [{'fieldname':value}]
              filename csvname

Definition at line 401 of file lumiQueryAPI.py.

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

402 def dumpData (lumidata, filename):
403  """
404  input params: lumidata [{'fieldname':value}]
405  filename csvname
406  """
407 
408  r = csvReporter.csvReporter(filename)
409  r.writeRows(lumidata)
def lumiQueryAPI.dumpOverview (   delivered,
  recorded,
  hltpath = '' 
)

Definition at line 751 of file lumiQueryAPI.py.

References xingLuminosityForRun().

752 def dumpOverview (delivered, recorded, hltpath = ''):
753  #toprowlabels = ['run', 'delivered', 'recorded', 'hltpath']
754  datatable = []
755  for runidx, deliveredrowdata in enumerate (delivered):
756  rowdata = []
757  rowdata += [deliveredrowdata[0], deliveredrowdata[2]]
758  if deliveredrowdata[1] == 'N/A': #run does not exist
759  rowdata += ['N/A', 'N/A']
760  datatable.append (rowdata)
761  continue
762  recordedLumi = calculateTotalRecorded (recorded[runidx][2])
763  lumiinPaths = calculateEffective (recorded[runidx][1], recordedLumi)
764  if hltpath != '' and hltpath != 'all':
765  if lumiinPaths.has_key (hltpath):
766  rowdata += [recordedLumi, lumiinPaths[hltpath]]
767  else:
768  rowdata += [recordedLumi, 'N/A']
769  else:
770  rowdata += [recordedLumi, recordedLumi]
771  datatable.append (rowdata)
772  return datatable
773 
def lumiQueryAPI.dumpPerLSLumi (   lumidata)

Definition at line 514 of file lumiQueryAPI.py.

515 def dumpPerLSLumi (lumidata):
516  datatodump = []
517  for perrundata in lumidata:
518  runnumber = perrundata[0]
519  deadtable = perrundata[2]
520  lumiresult = lsBylsLumi (deadtable)
521  for lsnum, dataperls in lumiresult.items():
522  rowdata = []
523  if len (dataperls) == 0:
524  rowdata += [str (runnumber), str (lsnum), 'N/A', 'N/A']
525  else:
526  rowdata += [str (runnumber), str (lsnum), dataperls[0], dataperls[1]]
527  if len (dataperls) > 2:
528  rowdata.extend ( flatten (dataperls[2:]) )
529  datatodump.append (rowdata)
530  return datatodump
531 
def lumiQueryAPI.dumpRecordedLumi (   lumidata,
  hltpath = '' 
)

Definition at line 641 of file lumiQueryAPI.py.

642 def dumpRecordedLumi (lumidata, hltpath = ''):
643  #labels = ['Run', 'HLT path', 'Recorded']
644  datatodump = []
645  for dataperRun in lumidata:
646  runnum = dataperRun[0]
647  if len (dataperRun[1]) == 0:
648  rowdata = []
649  rowdata += [str (runnum)]+2*['N/A']
650  datatodump.append (rowdata)
651  continue
652  perlsdata = dataperRun[2]
653  recordedLumi = 0.0
654  #norbits = perlsdata.values()[0][3]
655  recordedLumi = calculateTotalRecorded (perlsdata)
656  trgdict = dataperRun[1]
657  effective = calculateEffective (trgdict, recordedLumi)
658  if trgdict.has_key (hltpath) and effective.has_key (hltpath):
659  rowdata = []
660  l1bit = trgdict[hltpath][0]
661  if len (trgdict[hltpath]) != 3:
662  rowdata += [str (runnum), hltpath, 'N/A']
663  else:
664  hltprescale = trgdict[hltpath][1]
665  l1prescale = trgdict[hltpath][2]
666  rowdata += [str (runnum), hltpath, effective[hltpath]]
667  datatodump.append (rowdata)
668  continue
669 
670  for trg, trgdata in trgdict.items():
671  #print trg, trgdata
672  rowdata = []
673  rowdata += [str (runnum)]
674  l1bit = trgdata[0]
675  if len (trgdata) == 3:
676  rowdata += [trg, effective[trg]]
677  else:
678  rowdata += [trg, 'N/A']
679  datatodump.append (rowdata)
680  return datatodump
681 
def dumpRecordedLumi
def lumiQueryAPI.filterDeadtable (   inTable,
  lslist 
)

Definition at line 383 of file lumiQueryAPI.py.

384 def filterDeadtable (inTable, lslist):
385  result = {}
386  if lslist is None:
387  return inTable
388  if len (lslist) == 0: #if request no ls, then return nothing
389  return result
390  for existingLS in inTable.keys():
391  if existingLS in lslist:
392  result[existingLS] = inTable[existingLS]
393  return result
394 
def lumiQueryAPI.flatten (   obj)
Given nested lists or tuples, returns a single flattened list

Definition at line 864 of file lumiQueryAPI.py.

865 def flatten (obj):
866  '''Given nested lists or tuples, returns a single flattened list'''
867  result = []
868  for piece in obj:
869  if hasattr (piece, '__iter__') and not isinstance (piece, basestring):
870  result.extend( flatten (piece) )
871  else:
872  result.append (piece)
873  return result
874 
def lumiQueryAPI.getDeadfractions (   deadtable)
inputtable: {lsnum:[deadtime, instlumi, bit_0, norbits,bit_0_prescale]}
output: {lsnum:deadfraction}

Definition at line 460 of file lumiQueryAPI.py.

461 def getDeadfractions (deadtable):
462  """
463  inputtable: {lsnum:[deadtime, instlumi, bit_0, norbits,bit_0_prescale]}
464  output: {lsnum:deadfraction}
465  """
466  result = {}
467  for myls, d in deadtable.items():
468  #deadfrac = float (d[0])/ (float (d[2])*float (3564))
469  if float (d[2]) == 0.0: ##no beam
470  deadfrac = -1.0
471  else:
472  deadfrac = float (d[0])/ (float (d[2])*float(d[-1]))
473  result[myls] = deadfrac
474  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 1429 of file lumiQueryAPI.py.

References data, and nameDealer.hltTableName().

1430 def hltAllpathByrun(queryHandle,runnum):
1431  '''
1432  select cmslsnum,inputcount,acceptcount,prescale,pathname from hlt where runnum=:runnum
1433  this can be changed to blob query later
1434  output: {cmslsnum:{pathname:[inputcount,acceptcount,prescale]}}
1435  '''
1436  result={}
1437  queryHandle.addToTableList(nameDealer.hltTableName())
1438  queryCondition=coral.AttributeList()
1439  queryCondition.extend('runnum','unsigned int')
1440  queryCondition['runnum'].setData(int(runnum))
1441  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1442  queryHandle.addToOutputList('INPUTCOUNT','inputcount')
1443  queryHandle.addToOutputList('ACCEPTCOUNT','acceptcount')
1444  queryHandle.addToOutputList('PRESCALE','prescale')
1445  queryHandle.addToOutputList('PATHNAME','pathname')
1446  queryHandle.setCondition('RUNNUM=:runnum',queryCondition)
1447  queryResult=coral.AttributeList()
1448  queryResult.extend('cmslsnum','unsigned int')
1449  queryResult.extend('inputcount','unsigned int')
1450  queryResult.extend('acceptcount','unsigned int')
1451  queryResult.extend('prescale','unsigned int')
1452  queryResult.extend('pathname','string')
1453  queryHandle.defineOutput(queryResult)
1454  cursor=queryHandle.execute()
1455  while cursor.next():
1456  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1457  inputcount=cursor.currentRow()['inputcount'].data()
1458  acceptcount=cursor.currentRow()['acceptcount'].data()
1459  prescale=cursor.currentRow()['prescale'].data()
1460  pathname=cursor.currentRow()['pathname'].data()
1461  if not result.has_key(cmslsnum):
1462  dataperLS={}
1463  dataperLS[pathname]=[inputcount,acceptcount,prescale]
1464  result[cmslsnum]=dataperLS
1465  else:
1466  result[cmslsnum][pathname]=[inputcount,acceptcount,prescale]
1467  return result
1468 
def hltTableName
Definition: nameDealer.py:55
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
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 1396 of file lumiQueryAPI.py.

References data, and nameDealer.hltTableName().

1397 def hltBypathByrun(queryHandle,runnum,hltpath):
1398  '''
1399  select cmslsnum,inputcount,acceptcount,prescale from hlt where runnum=:runnum and pathname=:pathname
1400  output: {cmslsnum:[inputcount,acceptcount,prescale]}
1401  '''
1402  result={}
1403  queryHandle.addToTableList(nameDealer.hltTableName())
1404  queryCondition=coral.AttributeList()
1405  queryCondition.extend('runnum','unsigned int')
1406  queryCondition.extend('pathname','string')
1407  queryCondition['runnum'].setData(int(runnum))
1408  queryCondition['pathname'].setData(hltpath)
1409  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1410  queryHandle.addToOutputList('INPUTCOUNT','inputcount')
1411  queryHandle.addToOutputList('ACCEPTCOUNT','acceptcount')
1412  queryHandle.addToOutputList('PRESCALE','prescale')
1413  queryHandle.setCondition('RUNNUM=:runnum and PATHNAME=:pathname',queryCondition)
1414  queryResult=coral.AttributeList()
1415  queryResult.extend('cmslsnum','unsigned int')
1416  queryResult.extend('inputcount','unsigned int')
1417  queryResult.extend('acceptcount','unsigned int')
1418  queryResult.extend('prescale','unsigned int')
1419  queryHandle.defineOutput(queryResult)
1420  cursor=queryHandle.execute()
1421  while cursor.next():
1422  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1423  inputcount=cursor.currentRow()['inputcount'].data()
1424  acceptcount=cursor.currentRow()['acceptcount'].data()
1425  prescale=cursor.currentRow()['prescale'].data()
1426  if not result.has_key(cmslsnum):
1427  result[cmslsnum]=[inputcount,acceptcount,prescale]
1428  return result
def hltTableName
Definition: nameDealer.py:55
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
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 1678 of file lumiQueryAPI.py.

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

1679 def hlttrgMappingByrun(queryHandle,runnum):
1680  '''
1681  select m.hltpathname,m.l1seed from cmsrunsummary r,trghltmap m where r.runnum=:runnum and m.hltkey=r.hltkey
1682  output: {hltpath:l1seed}
1683  '''
1684  result={}
1685  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName(),'r')
1686  queryHandle.addToTableList(nameDealer.trghltMapTableName(),'m')
1687  queryCondition=coral.AttributeList()
1688  queryCondition.extend('runnum','unsigned int')
1689  queryCondition['runnum'].setData(int(runnum))
1690  queryHandle.addToOutputList('m.HLTPATHNAME','hltpathname')
1691  queryHandle.addToOutputList('m.L1SEED','l1seed')
1692  queryHandle.setCondition('r.RUNNUM=:runnum and m.HLTKEY=r.HLTKEY',queryCondition)
1693  queryResult=coral.AttributeList()
1694  queryResult.extend('hltpathname','string')
1695  queryResult.extend('l1seed','string')
1696  queryHandle.defineOutput(queryResult)
1697  cursor=queryHandle.execute()
1698  while cursor.next():
1699  hltpathname=cursor.currentRow()['hltpathname'].data()
1700  l1seed=cursor.currentRow()['l1seed'].data()
1701  if not result.has_key(hltpathname):
1702  result[hltpathname]=l1seed
1703  return result
def trghltMapTableName
Definition: nameDealer.py:76
def hlttrgMappingByrun
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def cmsrunsummaryTableName
Definition: nameDealer.py:16
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 1634 of file lumiQueryAPI.py.

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

1635 def lumidetailAllalgosByrun(queryHandle,runnum):
1636  '''
1637  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
1638  output: {algoname:{cmslsnum:[bxlumivalue,bxlumierror,bxlumiquality,startorbit]}}
1639  '''
1640  result={}
1641  queryHandle.addToTableList(nameDealer.lumidetailTableName(),'d')
1642  queryHandle.addToTableList(nameDealer.lumisummaryTableName(),'s')
1643  queryCondition=coral.AttributeList()
1644  queryCondition.extend('runnum','unsigned int')
1645  queryCondition['runnum'].setData(int(runnum))
1646  queryHandle.addToOutputList('s.CMSLSNUM','cmslsnum')
1647  queryHandle.addToOutputList('d.BXLUMIVALUE','bxlumivalue')
1648  queryHandle.addToOutputList('d.BXLUMIERROR','bxlumierror')
1649  queryHandle.addToOutputList('d.BXLUMIQUALITY','bxlumiquality')
1650  queryHandle.addToOutputList('d.ALGONAME','algoname')
1651  queryHandle.addToOutputList('s.STARTORBIT','startorbit')
1652  queryHandle.setCondition('s.RUNNUM=:runnum and s.LUMISUMMARY_ID=d.LUMISUMMARY_ID',queryCondition)
1653  queryResult=coral.AttributeList()
1654  queryResult.extend('cmslsnum','unsigned int')
1655  queryResult.extend('bxlumivalue','blob')
1656  queryResult.extend('bxlumierror','blob')
1657  queryResult.extend('bxlumiquality','blob')
1658  queryResult.extend('algoname','string')
1659  queryResult.extend('startorbit','unsigned int')
1660  queryHandle.addToOrderList('startorbit')
1661  queryHandle.addToOrderList('algoname')
1662  queryHandle.defineOutput(queryResult)
1663  cursor=queryHandle.execute()
1664  while cursor.next():
1665  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1666  bxlumivalue=cursor.currentRow()['bxlumivalue'].data()
1667  bxlumierror=cursor.currentRow()['bxlumierror'].data()
1668  bxlumiquality=cursor.currentRow()['bxlumiquality'].data()
1669  algoname=cursor.currentRow()['algoname'].data()
1670  startorbit=cursor.currentRow()['startorbit'].data()
1671  if not result.has_key(algoname):
1672  dataPerAlgo={}
1673  dataPerAlgo[cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]
1674  result[algoname]=dataPerAlgo
1675  else:
1676  result[algoname][cmslsnum]=[bxlumivalue,bxlumierror,bxlumiquality,startorbit]
1677  return result
def lumisummaryTableName
Definition: nameDealer.py:25
def lumidetailTableName
Definition: nameDealer.py:34
def lumidetailAllalgosByrun
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
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 1596 of file lumiQueryAPI.py.

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

1597 def lumidetailByrunByAlgo(queryHandle,runnum,algoname='OCC1'):
1598  '''
1599  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
1600  output: [[cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit]]
1601  since the output is ordered by time, it has to be in seq list format
1602  '''
1603  result=[]
1604  queryHandle.addToTableList(nameDealer.lumidetailTableName(),'d')
1605  queryHandle.addToTableList(nameDealer.lumisummaryTableName(),'s')
1606  queryCondition=coral.AttributeList()
1607  queryCondition.extend('runnum','unsigned int')
1608  queryCondition.extend('algoname','string')
1609  queryCondition['runnum'].setData(int(runnum))
1610  queryCondition['algoname'].setData(algoname)
1611  queryHandle.addToOutputList('s.CMSLSNUM','cmslsnum')
1612  queryHandle.addToOutputList('d.BXLUMIVALUE','bxlumivalue')
1613  queryHandle.addToOutputList('d.BXLUMIERROR','bxlumierror')
1614  queryHandle.addToOutputList('d.BXLUMIQUALITY','bxlumiquality')
1615  queryHandle.addToOutputList('s.STARTORBIT','startorbit')
1616  queryHandle.setCondition('s.runnum=:runnum and d.algoname=:algoname and s.lumisummary_id=d.lumisummary_id',queryCondition)
1617  queryResult=coral.AttributeList()
1618  queryResult.extend('cmslsnum','unsigned int')
1619  queryResult.extend('bxlumivalue','blob')
1620  queryResult.extend('bxlumierror','blob')
1621  queryResult.extend('bxlumiquality','blob')
1622  queryResult.extend('startorbit','unsigned int')
1623  queryHandle.addToOrderList('s.STARTORBIT')
1624  queryHandle.defineOutput(queryResult)
1625  cursor=queryHandle.execute()
1626  while cursor.next():
1627  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1628  bxlumivalue=cursor.currentRow()['bxlumivalue'].data()
1629  bxlumierror=cursor.currentRow()['bxlumierror'].data()
1630  bxlumiquality=cursor.currentRow()['bxlumiquality'].data()
1631  startorbit=cursor.currentRow()['startorbit'].data()
1632  result.append([cmslsnum,bxlumivalue,bxlumierror,bxlumiquality,startorbit])
1633  return result
def lumisummaryTableName
Definition: nameDealer.py:25
def lumidetailByrunByAlgo
def lumidetailTableName
Definition: nameDealer.py:34
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def lumiQueryAPI.lumisumByrun (   queryHandle,
  runnum,
  lumiversion,
  beamstatus = None,
  beamenergy = None,
  beamenergyfluctuation = 0.09,
  finecorrections = None 
)
beamenergy unit : GeV
beamenergyfluctuation : fraction allowed to fluctuate around beamenergy value
select instlumi from lumisummary where runnum=:runnum and lumiversion=:lumiversion
output: float sum(instlumi)
Note: the output is the raw result, need to apply LS length in time(sec)

Definition at line 1160 of file lumiQueryAPI.py.

References data, and nameDealer.lumisummaryTableName().

1161 def lumisumByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09,finecorrections=None):
1162  '''
1163  beamenergy unit : GeV
1164  beamenergyfluctuation : fraction allowed to fluctuate around beamenergy value
1165  select instlumi from lumisummary where runnum=:runnum and lumiversion=:lumiversion
1166  output: float sum(instlumi)
1167  Note: the output is the raw result, need to apply LS length in time(sec)
1168  '''
1169  result=[]
1170  queryHandle.addToTableList(nameDealer.lumisummaryTableName())
1171  queryCondition=coral.AttributeList()
1172  queryCondition.extend('runnum','unsigned int')
1173  queryCondition.extend('lumiversion','string')
1174 
1175  queryCondition['runnum'].setData(int(runnum))
1176  queryCondition['lumiversion'].setData(lumiversion)
1177  queryHandle.addToOutputList('INSTLUMI','instlumi')
1178  conditionstring='RUNNUM=:runnum and LUMIVERSION=:lumiversion'
1179  if beamstatus and len(beamstatus)!=0:
1180  conditionstring=conditionstring+' and BEAMSTATUS=:beamstatus'
1181  queryCondition.extend('beamstatus','string')
1182  queryCondition['beamstatus'].setData(beamstatus)
1183  if beamenergy and beamenergy!=0.0:
1184  minBeamenergy=float(beamenergy*(1.0-beamenergyfluctuation))
1185  maxBeamenergy=float(beamenergy*(1.0+beamenergyfluctuation))
1186  conditionstring=conditionstring+' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy'
1187  queryCondition.extend('minBeamenergy','float')
1188  queryCondition.extend('maxBeamenergy','float')
1189  queryCondition['minBeamenergy'].setData(float(minBeamenergy))
1190  queryCondition['maxBeamenergy'].setData(float(maxBeamenergy))
1191  queryHandle.setCondition(conditionstring,queryCondition)
1192  queryResult=coral.AttributeList()
1193  queryResult.extend('instlumi','float')
1194  queryHandle.defineOutput(queryResult)
1195  cursor=queryHandle.execute()
1196  while cursor.next():
1197  instlumi=cursor.currentRow()['instlumi'].data()
1198  if instlumi:
1199  if finecorrections:
1200  instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1201  result.append(instlumi)
1202  if result:
1203  return sum(result)
1204  else:
1205  return 0.0
def lumisummaryTableName
Definition: nameDealer.py:25
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def lumiQueryAPI.lumisummaryByrun (   queryHandle,
  runnum,
  lumiversion,
  beamstatus = None,
  beamenergy = None,
  beamenergyfluctuation = 0.09,
  finecorrections = None 
)
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 1101 of file lumiQueryAPI.py.

References data, and nameDealer.lumisummaryTableName().

1102 def lumisummaryByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09,finecorrections=None):
1103  '''
1104  one can impose beamstatus, beamenergy selections at the SQL query level or process them later from the general result
1105  select cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenery from lumisummary where runnum=:runnum and lumiversion=:lumiversion order by startorbit;
1106  output: [[cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive]]
1107  Note: the non-cmsalive LS are included in the result
1108  '''
1109  result=[]
1110  queryHandle.addToTableList(nameDealer.lumisummaryTableName())
1111  queryCondition=coral.AttributeList()
1112  queryCondition.extend('runnum','unsigned int')
1113  queryCondition.extend('lumiversion','string')
1114  conditionstring='RUNNUM=:runnum and LUMIVERSION=:lumiversion'
1115  queryCondition['runnum'].setData(int(runnum))
1116  queryCondition['lumiversion'].setData(lumiversion)
1117  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1118  queryHandle.addToOutputList('INSTLUMI','instlumi')
1119  queryHandle.addToOutputList('NUMORBIT','numorbit')
1120  queryHandle.addToOutputList('STARTORBIT','startorbit')
1121  queryHandle.addToOutputList('BEAMSTATUS','beamstatus')
1122  queryHandle.addToOutputList('BEAMENERGY','beamenergy')
1123  queryHandle.addToOutputList('CMSALIVE','cmsalive')
1124  if beamstatus and len(beamstatus)!=0:
1125  conditionstring=conditionstring+' and BEAMSTATUS=:beamstatus'
1126  queryCondition.extend('beamstatus','string')
1127  queryCondition['beamstatus'].setData(beamstatus)
1128  if beamenergy:
1129  minBeamenergy=float(beamenergy*(1.0-beamenergyfluctuation))
1130  maxBeamenergy=float(beamenergy*(1.0+beamenergyfluctuation))
1131  conditionstring=conditionstring+' and BEAMENERGY>:minBeamenergy and BEAMENERGY<:maxBeamenergy'
1132  queryCondition.extend('minBeamenergy','float')
1133  queryCondition.extend('maxBeamenergy','float')
1134  queryCondition['minBeamenergy'].setData(float(minBeamenergy))
1135  queryCondition['maxBeamenergy'].setData(float(maxBeamenergy))
1136  queryResult=coral.AttributeList()
1137  queryResult.extend('cmslsnum','unsigned int')
1138  queryResult.extend('instlumi','float')
1139  queryResult.extend('numorbit','unsigned int')
1140  queryResult.extend('startorbit','unsigned int')
1141  queryResult.extend('beamstatus','string')
1142  queryResult.extend('beamenergy','float')
1143  queryResult.extend('cmsalive','unsigned int')
1144  queryHandle.defineOutput(queryResult)
1145  queryHandle.setCondition(conditionstring,queryCondition)
1146  queryHandle.addToOrderList('startorbit')
1147  cursor=queryHandle.execute()
1148  while cursor.next():
1149  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1150  instlumi=cursor.currentRow()['instlumi'].data()
1151  if finecorrections:
1152  instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1153  numorbit=cursor.currentRow()['numorbit'].data()
1154  startorbit=cursor.currentRow()['startorbit'].data()
1155  beamstatus=cursor.currentRow()['beamstatus'].data()
1156  beamenergy=cursor.currentRow()['beamenergy'].data()
1157  cmsalive=cursor.currentRow()['cmsalive'].data()
1158  result.append([cmslsnum,instlumi,numorbit,startorbit,beamstatus,beamenergy,cmsalive])
1159  return result
def lumisummaryTableName
Definition: nameDealer.py:25
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def lumiQueryAPI.lumisummarytrgbitzeroByrun (   queryHandle,
  runnum,
  lumiversion,
  beamstatus = None,
  beamenergy = None,
  beamenergyfluctuation = 0.09,
  finecorrections = None 
)
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 1242 of file lumiQueryAPI.py.

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

1243 def lumisummarytrgbitzeroByrun(queryHandle,runnum,lumiversion,beamstatus=None,beamenergy=None,beamenergyfluctuation=0.09,finecorrections=None):
1244  '''
1245  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;
1246  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.
1247  output: {cmslsnum:[instlumi,numorbit,startorbit,beamstatus,beamenergy,bitzerocount,deadtime,bitname,prescale]}
1248  Note: only cmsalive LS are included in the result. Therefore, this function cannot be used for calculating delivered!
1249  '''
1250  result={}
1251  queryHandle.addToTableList(nameDealer.trgTableName(),'t')
1252  queryHandle.addToTableList(nameDealer.lumisummaryTableName(),'l')
1253  queryCondition=coral.AttributeList()
1254  queryCondition.extend('bitnum','unsigned int')
1255  queryCondition.extend('runnum','unsigned int')
1256  queryCondition.extend('lumiversion','string')
1257  queryCondition['bitnum'].setData(int(0))
1258  queryCondition['runnum'].setData(int(runnum))
1259  queryCondition['lumiversion'].setData(lumiversion)
1260 
1261  queryHandle.addToOutputList('l.CMSLSNUM','cmslsnum')
1262  queryHandle.addToOutputList('l.INSTLUMI','instlumi')
1263  queryHandle.addToOutputList('l.NUMORBIT','numorbit')
1264  queryHandle.addToOutputList('l.STARTORBIT','startorbit')
1265  queryHandle.addToOutputList('l.BEAMSTATUS','beamstatus')
1266  queryHandle.addToOutputList('l.BEAMENERGY','beamenergy')
1267  queryHandle.addToOutputList('t.TRGCOUNT','trgcount')
1268  queryHandle.addToOutputList('t.DEADTIME','deadtime')
1269  queryHandle.addToOutputList('t.BITNAME','bitname')
1270  queryHandle.addToOutputList('t.PRESCALE','prescale')
1271  conditionstring='t.BITNUM=:bitnum and l.RUNNUM=:runnum and l.LUMIVERSION=:lumiversion and l.RUNNUM=t.RUNNUM and t.CMSLSNUM=l.CMSLSNUM'
1272  if beamstatus and len(beamstatus)!=0:
1273  conditionstring=conditionstring+' and l.BEAMSTATUS=:beamstatus'
1274  queryCondition.extend('beamstatus','string')
1275  queryCondition['beamstatus'].setData(beamstatus)
1276  if beamenergy and beamenergy!=0.0:
1277  minBeamenergy=float(beamenergy*(1-beamenergyfluctuation))
1278  maxBeamenergy=float(beamenergy*(1+beamenergyfluctuation))
1279  conditionstring=conditionstring+' and l.BEAMENERGY>:minBeamenergy and l.BEAMENERGY<:maxBeamenergy'
1280  queryCondition.extend('minBeamenergy','float')
1281  queryCondition.extend('maxBeamenergy','float')
1282  queryCondition['minBeamenergy'].setData(float(minBeamenergy))
1283  queryCondition['maxBeamenergy'].setData(float(maxBeamenergy))
1284  queryHandle.setCondition(conditionstring,queryCondition)
1285  queryResult=coral.AttributeList()
1286  queryResult.extend('cmslsnum','unsigned int')
1287  queryResult.extend('instlumi','float')
1288  queryResult.extend('numorbit','unsigned int')
1289  queryResult.extend('startorbit','unsigned int')
1290  queryResult.extend('beamstatus','string')
1291  queryResult.extend('beamenergy','float')
1292  queryResult.extend('trgcount','unsigned int')
1293  queryResult.extend('deadtime','unsigned int')
1294  queryResult.extend('bitname','string')
1295  queryResult.extend('prescale','unsigned int')
1296  queryHandle.defineOutput(queryResult)
1297  cursor=queryHandle.execute()
1298  while cursor.next():
1299  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1300  instlumi=cursor.currentRow()['instlumi'].data()
1301  if finecorrections:
1302  instlumi=lumiCorrections.applyfinecorrection(instlumi,finecorrections[0],finecorrections[1],finecorrections[2])
1303  numorbit=cursor.currentRow()['numorbit'].data()
1304  startorbit=cursor.currentRow()['startorbit'].data()
1305  beamstatus=cursor.currentRow()['beamstatus'].data()
1306  beamenergy=cursor.currentRow()['beamenergy'].data()
1307  trgcount=cursor.currentRow()['trgcount'].data()
1308  deadtime=cursor.currentRow()['deadtime'].data()
1309  bitname=cursor.currentRow()['bitname'].data()
1310  prescale=cursor.currentRow()['prescale'].data()
1311  if not result.has_key(cmslsnum):
1312  result[cmslsnum]=[instlumi,numorbit,startorbit,beamstatus,beamenergy,trgcount,deadtime,bitname,prescale]
1313  return result
def lumisummaryTableName
Definition: nameDealer.py:25
def lumisummarytrgbitzeroByrun
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def trgTableName
Definition: nameDealer.py:52
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 875 of file lumiQueryAPI.py.

876 def mergeXingLumi (triplet, xingLumiDict):
877  '''Given general xing information and a xingLumiDict, the xing
878  luminosity information is merged with the general information'''
879  runNumber = triplet[0]
880  deadTable = triplet[2]
881  for lumi, lumiList in deadTable.iteritems():
882  key = ( int(runNumber), int(lumi) )
883  xingLumiValues = xingLumiDict.get (key)
884  if xingLumiValues:
885  lumiList.append( flatten (xingLumiValues) )
886 
def lumiQueryAPI.printDeliveredLumi (   lumidata,
  mode 
)

Definition at line 395 of file lumiQueryAPI.py.

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

Definition at line 682 of file lumiQueryAPI.py.

References relativeConstraints.keys.

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

Definition at line 475 of file lumiQueryAPI.py.

476 def printPerLSLumi (lumidata, isVerbose = False):
477  '''
478  input lumidata [['runnumber', 'trgtable{}', 'deadtable{}']]
479  deadtable {lsnum:[deadtime, instlumi, bit_0, norbits,prescale]}
480  '''
481  datatoprint = []
482  totalrow = []
483  labels = [ ('Run', 'LS', 'Delivered', 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
484  lastrowlabels = [ ('Selected LS', 'Delivered'+u' (/\u03bcb)'.encode ('utf-8'), 'Recorded'+u' (/\u03bcb)'.encode ('utf-8'))]
485  totalDeliveredLS = 0
486  totalSelectedLS = 0
487  totalDelivered = 0.0
488  totalRecorded = 0.0
489 
490  for perrundata in lumidata:
491  runnumber = perrundata[0]
492  deadtable = perrundata[2]
493  lumiresult = lsBylsLumi (deadtable)
494  totalSelectedLS = totalSelectedLS+len (deadtable)
495  for lsnum, dataperls in lumiresult.items():
496  rowdata = []
497  if len (dataperls) == 0:
498  rowdata += [str (runnumber), str (lsnum), 'N/A', 'N/A']
499  else:
500  rowdata += [str (runnumber), str (lsnum), '%.3f' % (dataperls[0]), '%.3f' % (dataperls[1])]
501  totalDelivered = totalDelivered+dataperls[0]
502  totalRecorded = totalRecorded+dataperls[1]
503  datatoprint.append (rowdata)
504  totalrow.append ([str (totalSelectedLS), '%.3f'% (totalDelivered), '%.3f'% (totalRecorded)])
505  print ' == = '
506  print tablePrinter.indent (labels+datatoprint, hasHeader = True, separateRows = False, prefix = '| ',
507  postfix = ' |', justify = 'right', delim = ' | ',
508  wrapfunc = lambda x: wrap_onspace_strict (x, 22))
509  print ' == = Total : '
510  print tablePrinter.indent (lastrowlabels+totalrow, hasHeader = True, separateRows = False, prefix = '| ',
511  postfix = ' |', justify = 'right', delim = ' | ',
512  wrapfunc = lambda x: wrap_onspace (x, 20))
513 
def lumiQueryAPI.printRecordedLumi (   lumidata,
  isVerbose = False,
  hltpath = '' 
)

Definition at line 532 of file lumiQueryAPI.py.

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

Definition at line 99 of file lumiQueryAPI.py.

References reco.if(), and recordedLumiForRun().

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

Definition at line 216 of file lumiQueryAPI.py.

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

Referenced by recordedLumiForRange().

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

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

1705 def runsByfillrange(queryHandle,minFill,maxFill):
1706  '''
1707  find all runs in the fill range inclusive
1708  select runnum,fillnum from cmsrunsummary where fillnum>=:minFill and fillnum<=:maxFill
1709  output: fillDict={fillnum:[runlist]}
1710  '''
1711  result={}
1712  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
1713  queryCondition=coral.AttributeList()
1714  queryCondition.extend('minFill','unsigned int')
1715  queryCondition.extend('maxFill','unsigned int')
1716  queryCondition['minFill'].setData(int(minFill))
1717  queryCondition['maxFill'].setData(int(maxFill))
1718  queryHandle.addToOutputList('RUNNUM','runnum')
1719  queryHandle.addToOutputList('FILLNUM','fillnum')
1720  queryHandle.setCondition('FILLNUM>=:minFill and FILLNUM<=:maxFill',queryCondition)
1721  queryResult=coral.AttributeList()
1722  queryResult.extend('runnum','unsigned int')
1723  queryResult.extend('fillnum','unsigned int')
1724  queryHandle.defineOutput(queryResult)
1725  cursor=queryHandle.execute()
1726  while cursor.next():
1727  runnum=cursor.currentRow()['runnum'].data()
1728  fillnum=cursor.currentRow()['fillnum'].data()
1729  if not result.has_key(fillnum):
1730  result[fillnum]=[runnum]
1731  else:
1732  result[fillnum].append(runnum)
1733  return result
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def cmsrunsummaryTableName
Definition: nameDealer.py:16
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 1734 of file lumiQueryAPI.py.

References nameDealer.cmsrunsummaryTableName(), and data.

1735 def runsByTimerange(queryHandle,minTime,maxTime):
1736  '''
1737  find all runs in the time range inclusive
1738  the selected run must have started after minTime and finished by maxTime
1739  select runnum,to_char(startTime),to_char(stopTime) from cmsrunsummary where startTime>=timestamp(minTime) and stopTime<=timestamp(maxTime);
1740  input: minTime,maxTime in python obj datetime.datetime
1741  output: {runnum:[starttime,stoptime]} return in python obj datetime.datetime
1742  '''
1743  t=lumiTime.lumiTime()
1744  result={}
1745  coralminTime=coral.TimeStamp(minTime.year,minTime.month,minTime.day,minTime.hour,minTime.minute,minTime.second,0)
1746  coralmaxTime=coral.TimeStamp(maxTime.year,maxTime.month,maxTime.day,maxTime.hour,maxTime.minute,maxTime.second,0)
1747  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
1748  queryCondition=coral.AttributeList()
1749  queryCondition.extend('minTime','time stamp')
1750  queryCondition.extend('maxTime','time stamp')
1751  queryCondition['minTime'].setData(coralminTime)
1752  queryCondition['maxTime'].setData(coralmaxTime)
1753  queryHandle.addToOutputList('RUNNUM','runnum')
1754  queryHandle.addToOutputList('TO_CHAR(STARTTIME,\''+t.coraltimefm+'\')','starttime')
1755  queryHandle.addToOutputList('TO_CHAR(STOPTIME,\''+t.coraltimefm+'\')','stoptime')
1756  queryHandle.setCondition('STARTTIME>=:minTime and STOPTIME<=:maxTime',queryCondition)
1757  queryResult=coral.AttributeList()
1758  queryResult.extend('runnum','unsigned int')
1759  queryResult.extend('starttime','string')
1760  queryResult.extend('stoptime','string')
1761  queryHandle.defineOutput(queryResult)
1762  cursor=queryHandle.execute()
1763  while cursor.next():
1764  runnum=cursor.currentRow()['runnum'].data()
1765  starttimeStr=cursor.currentRow()['starttime'].data()
1766  stoptimeStr=cursor.currentRow()['stoptime'].data()
1767  if not result.has_key(runnum):
1768  result[runnum]=[t.StrToDatetime(starttimeStr),t.StrToDatetime(stoptimeStr)]
1769  return result
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def cmsrunsummaryTableName
Definition: nameDealer.py:16
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 1065 of file lumiQueryAPI.py.

References nameDealer.cmsrunsummaryTableName(), and data.

1066 def runsummaryByrun(queryHandle,runnum):
1067  '''
1068  select fillnum,sequence,hltkey,to_char(starttime),to_char(stoptime) from cmsrunsummary where runnum=:runnum
1069  output: [fillnum,sequence,hltkey,starttime,stoptime]
1070  '''
1071  t=lumiTime.lumiTime()
1072  result=[]
1073  queryHandle.addToTableList(nameDealer.cmsrunsummaryTableName())
1074  queryCondition=coral.AttributeList()
1075  queryCondition.extend('runnum','unsigned int')
1076  queryCondition['runnum'].setData(int(runnum))
1077  queryHandle.addToOutputList('FILLNUM','fillnum')
1078  queryHandle.addToOutputList('SEQUENCE','sequence')
1079  queryHandle.addToOutputList('HLTKEY','hltkey')
1080  queryHandle.addToOutputList('to_char(STARTTIME,\''+t.coraltimefm+'\')','starttime')
1081  queryHandle.addToOutputList('to_char(STOPTIME,\''+t.coraltimefm+'\')','stoptime')
1082  queryHandle.setCondition('RUNNUM=:runnum',queryCondition)
1083  queryResult=coral.AttributeList()
1084  queryResult.extend('fillnum','unsigned int')
1085  queryResult.extend('sequence','string')
1086  queryResult.extend('hltkey','string')
1087  queryResult.extend('starttime','string')
1088  queryResult.extend('stoptime','string')
1089  queryHandle.defineOutput(queryResult)
1090  cursor=queryHandle.execute()
1091  while cursor.next():
1092  result.append(cursor.currentRow()['fillnum'].data())
1093  result.append(cursor.currentRow()['sequence'].data())
1094  result.append(cursor.currentRow()['hltkey'].data())
1095  result.append(cursor.currentRow()['starttime'].data())
1096  result.append(cursor.currentRow()['stoptime'].data())
1097  #if len(result)!=5:
1098  # print 'wrong runsummary result'
1099  # raise
1100  return result
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def cmsrunsummaryTableName
Definition: nameDealer.py:16
def lumiQueryAPI.setupSession (   connectString,
  siteconfpath,
  parameters,
  debug = False 
)
returns database session

Definition at line 887 of file lumiQueryAPI.py.

888 def setupSession (connectString, siteconfpath, parameters, debug = False):
889  '''returns database session'''
890  connectparser = connectstrParser.connectstrParser (connectString)
891  connectparser.parse()
892  usedefaultfrontierconfig = False
893  cacheconfigpath = ''
894  if connectparser.needsitelocalinfo():
895  if not siteconfpath:
896  cacheconfigpath = os.environ['CMS_PATH']
897  if cacheconfigpath:
898  cacheconfigpath = os.path.join (cacheconfigpath, 'SITECONF', 'local', 'JobConfig', 'site-local-config.xml')
899  else:
900  usedefaultfrontierconfig = True
901  else:
902  cacheconfigpath = siteconfpath
903  cacheconfigpath = os.path.join (cacheconfigpath, 'site-local-config.xml')
905  if usedefaultfrontierconfig:
906  ccp.parseString (parameters.defaultfrontierConfigString)
907  else:
908  ccp.parse (cacheconfigpath)
909  connectString = connectparser.fullfrontierStr (connectparser.schemaname(), ccp.parameterdict())
910  svc = coral.ConnectionService()
911  if debug :
912  msg = coral.MessageStream ('')
913  msg.setMsgVerbosity (coral.message_Level_Debug)
914  parameters.verbose = True
915  session = svc.connect (connectString, accessMode = coral.access_ReadOnly)
916  session.typeConverter().setCppTypeForSqlType ("unsigned int", "NUMBER (10)")
917  session.typeConverter().setCppTypeForSqlType ("unsigned long long", "NUMBER (20)")
918  return session, svc
919 
920 
def lumiQueryAPI.splitlistToRangeString (   inPut)

Definition at line 429 of file lumiQueryAPI.py.

430 def splitlistToRangeString (inPut):
431  result = []
432  first = inPut[0]
433  last = inPut[0]
434  result.append ([inPut[0]])
435  counter = 0
436  for i in inPut[1:]:
437  if i == last+1:
438  result[counter].append (i)
439  else:
440  counter += 1
441  result.append ([i])
442  last = i
443  return ', '.join (['['+str (min (x))+'-'+str (max (x))+']' for x in result])
444 
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 1350 of file lumiQueryAPI.py.

References data, and nameDealer.trgTableName().

1351 def trgAllbitsByrun(queryHandle,runnum):
1352  '''
1353  all you ever want to know about trigger
1354  select cmslsnum,trgcount,deadtime,bitnum,bitname,prescale from trg where runnum=:runnum order by bitnum,cmslsnum
1355  this can be changed to blob query later
1356  output: {cmslsnum:{bitname:[bitnum,trgcount,deadtime,prescale]}}
1357  '''
1358  result={}
1359  queryHandle.addToTableList(nameDealer.trgTableName())
1360  queryCondition=coral.AttributeList()
1361  queryCondition.extend('runnum','unsigned int')
1362  queryCondition['runnum'].setData(int(runnum))
1363  queryHandle.addToOutputList('cmslsnum')
1364  queryHandle.addToOutputList('trgcount')
1365  queryHandle.addToOutputList('deadtime')
1366  queryHandle.addToOutputList('bitnum')
1367  queryHandle.addToOutputList('bitname')
1368  queryHandle.addToOutputList('prescale')
1369  queryHandle.setCondition('runnum=:runnum',queryCondition)
1370  queryResult=coral.AttributeList()
1371  queryResult.extend('cmslsnum','unsigned int')
1372  queryResult.extend('trgcount','unsigned int')
1373  queryResult.extend('deadtime','unsigned long long')
1374  queryResult.extend('bitnum','unsigned int')
1375  queryResult.extend('bitname','string')
1376  queryResult.extend('prescale','unsigned int')
1377  queryHandle.defineOutput(queryResult)
1378  queryHandle.addToOrderList('bitnum')
1379  queryHandle.addToOrderList('cmslsnum')
1380  cursor=queryHandle.execute()
1381  while cursor.next():
1382  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1383  trgcount=cursor.currentRow()['trgcount'].data()
1384  deadtime=cursor.currentRow()['deadtime'].data()
1385  bitnum=cursor.currentRow()['bitnum'].data()
1386  bitname=cursor.currentRow()['bitname'].data()
1387  prescale=cursor.currentRow()['prescale'].data()
1388  if not result.has_key(cmslsnum):
1389  dataperLS={}
1390  dataperLS[bitname]=[bitnum,trgcount,deadtime,prescale]
1391  result[cmslsnum]=dataperLS
1392  else:
1393  result[cmslsnum][bitname]=[bitnum,trgcount,deadtime,prescale]
1394  return result
1395 
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def trgTableName
Definition: nameDealer.py:52
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 1206 of file lumiQueryAPI.py.

References data, and nameDealer.trgTableName().

1207 def trgbitzeroByrun(queryHandle,runnum):
1208  '''
1209  select cmslsnum,trgcount,deadtime,bitname,prescale from trg where runnum=:runnum and bitnum=0;
1210  output: {cmslsnum:[trgcount,deadtime,bitname,prescale]}
1211  '''
1212  result={}
1213  queryHandle.addToTableList(nameDealer.trgTableName())
1214  queryCondition=coral.AttributeList()
1215  queryCondition.extend('runnum','unsigned int')
1216  queryCondition.extend('bitnum','unsigned int')
1217  queryCondition['runnum'].setData(int(runnum))
1218  queryCondition['bitnum'].setData(int(0))
1219  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1220  queryHandle.addToOutputList('TRGCOUNT','trgcount')
1221  queryHandle.addToOutputList('DEADTIME','deadtime')
1222  queryHandle.addToOutputList('BITNAME','bitname')
1223  queryHandle.addToOutputList('PRESCALE','prescale')
1224  queryHandle.setCondition('RUNNUM=:runnum and BITNUM=:bitnum',queryCondition)
1225  queryResult=coral.AttributeList()
1226  queryResult.extend('cmslsnum','unsigned int')
1227  queryResult.extend('trgcount','unsigned int')
1228  queryResult.extend('deadtime','unsigned int')
1229  queryResult.extend('bitname','string')
1230  queryResult.extend('prescale','unsigned int')
1231  queryHandle.defineOutput(queryResult)
1232  cursor=queryHandle.execute()
1233  while cursor.next():
1234  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1235  trgcount=cursor.currentRow()['trgcount'].data()
1236  deadtime=cursor.currentRow()['deadtime'].data()
1237  bitname=cursor.currentRow()['bitname'].data()
1238  prescale=cursor.currentRow()['prescale'].data()
1239  if not result.has_key(cmslsnum):
1240  result[cmslsnum]=[trgcount,deadtime,bitname,prescale]
1241  return result
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def trgTableName
Definition: nameDealer.py:52
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 1314 of file lumiQueryAPI.py.

References data, and nameDealer.trgTableName().

1315 def trgBybitnameByrun(queryHandle,runnum,bitname):
1316  '''
1317  select cmslsnum,trgcount,deadtime,bitnum,prescale from trg where runnum=:runnum and bitname=:bitname;
1318  output: {cmslsnum:[trgcount,deadtime,bitnum,prescale]}
1319  '''
1320  result={}
1321  queryHandle.addToTableList(nameDealer.trgTableName())
1322  queryCondition=coral.AttributeList()
1323  queryCondition.extend('runnum','unsigned int')
1324  queryCondition.extend('bitname','string')
1325  queryCondition['runnum'].setData(int(runnum))
1326  queryCondition['bitname'].setData(bitname)
1327  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1328  queryHandle.addToOutputList('TRGCOUNT','trgcount')
1329  queryHandle.addToOutputList('DEADTIME','deadtime')
1330  queryHandle.addToOutputList('BITNUM','bitnum')
1331  queryHandle.addToOutputList('PRESCALE','prescale')
1332  queryHandle.setCondition('RUNNUM=:runnum and BITNAME=:bitname',queryCondition)
1333  queryResult=coral.AttributeList()
1334  queryResult.extend('cmslsnum','unsigned int')
1335  queryResult.extend('trgcount','unsigned int')
1336  queryResult.extend('deadtime','unsigned long long')
1337  queryResult.extend('bitnum','unsigned int')
1338  queryResult.extend('prescale','unsigned int')
1339  queryHandle.defineOutput(queryResult)
1340  cursor=queryHandle.execute()
1341  while cursor.next():
1342  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1343  trgcount=cursor.currentRow()['trgcount'].data()
1344  deadtime=cursor.currentRow()['deadtime'].data()
1345  bitnum=cursor.currentRow()['bitnum'].data()
1346  prescale=cursor.currentRow()['prescale'].data()
1347  if not result.has_key(cmslsnum):
1348  result[cmslsnum]=[trgcount,deadtime,bitnum,prescale]
1349  return result
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def trgTableName
Definition: nameDealer.py:52
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 996 of file lumiQueryAPI.py.

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

997 def validation(queryHandle,run=None,cmsls=None):
998  '''retrieve validation data per run or all
999  input: run. if not run, retrive all; if cmslsnum selection list pesent, filter out unselected result
1000  output: {run:[[cmslsnum,status,comment]]}
1001  '''
1002  result={}
1003  queryHandle.addToTableList(nameDealer.lumivalidationTableName())
1004  queryHandle.addToOutputList('RUNNUM','runnum')
1005  queryHandle.addToOutputList('CMSLSNUM','cmslsnum')
1006  queryHandle.addToOutputList('FLAG','flag')
1007  queryHandle.addToOutputList('COMMENT','comment')
1008  if run:
1009  queryCondition='RUNNUM=:runnum'
1010  queryBind=coral.AttributeList()
1011  queryBind.extend('runnum','unsigned int')
1012  queryBind['runnum'].setData(run)
1013  queryHandle.setCondition(queryCondition,queryBind)
1014  queryResult=coral.AttributeList()
1015  queryResult.extend('runnum','unsigned int')
1016  queryResult.extend('cmslsnum','unsigned int')
1017  queryResult.extend('flag','string')
1018  queryResult.extend('comment','string')
1019  queryHandle.defineOutput(queryResult)
1020  cursor=queryHandle.execute()
1021  while cursor.next():
1022  runnum=cursor.currentRow()['runnum'].data()
1023  if not result.has_key(runnum):
1024  result[runnum]=[]
1025  cmslsnum=cursor.currentRow()['cmslsnum'].data()
1026  flag=cursor.currentRow()['flag'].data()
1027  comment=cursor.currentRow()['comment'].data()
1028  result[runnum].append([cmslsnum,flag,comment])
1029  if run and cmsls and len(cmsls)!=0:
1030  selectedresult={}
1031  for runnum,perrundata in result.items():
1032  for lsdata in perrundata:
1033  if lsdata[0] not in cmsls:
1034  continue
1035  if not selectedresult.has_key(runnum):
1036  selectedresult[runnum]=[]
1037  selectedresult[runnum].append(lsdata)
1038  return selectedresult
1039  else:
1040  return result
def lumivalidationTableName
Definition: nameDealer.py:85
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def lumiQueryAPI.xingLuminosityForRun (   dbsession,
  runnum,
  parameters,
  lumiXingDict = {},
  maxLumiSection = None,
  finecorrections = 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 775 of file lumiQueryAPI.py.

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

Referenced by dumpOverview().

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

Variable Documentation

tuple lumiQueryAPI.allfills = allfills(q)

Definition at line 1840 of file lumiQueryAPI.py.

Referenced by allfills().

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

Definition at line 1782 of file lumiQueryAPI.py.

Referenced by allruns().

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

Definition at line 1776 of file lumiQueryAPI.py.

Referenced by spf::SherpackFetcher.FnFileGet().

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

Definition at line 1771 of file lumiQueryAPI.py.

Referenced by FWGUIEventDataAdder.addNewItem(), DDXMLElement.appendText(), edm::service::ELdestination.changeFile(), edm::service::ELdestination.clearSummary(), cond::DecodingKey.createFromInputFile(), DDI::Specific.createPartSelections(), cond::RelationalAuthenticationService::RelationalAuthenticationService.credentials(), edm::JobReport.dumpFiles(), HLTScalersClient.endLuminosityBlock(), DDLMap.errorOut(), RPCConst.etaFromTowerNum(), cond::DecodingKey.flush(), edm::service::ELdestination.flush(), DDXMLElement.get(), DDXMLElement.getDDName(), EcalCondDBInterface.getEcalLogicID(), cond.getLoginName(), DDXMLElement.getText(), cond::CredentialStore.importForPrincipal(), triggerExpression::HLTReader.init(), cond::DecodingKey.init(), cond::CredentialStore.installAdmin(), RPCConst.iptFromPt(), ora::ContainerSchema.mapping(), MuonDDDConstants.MuonDDDConstants(), DQMNet.onPeerData(), FWFileEntry.openFile(), jsoncollector::FastMonitor.outputFullHistoDataPoint(), QualityTester.performTests(), egHLT::TrigCodes::TrigBitSetMap.printCodes(), DDLTubs.processElement(), DDLTrapezoid.processElement(), DDLAlgoPosPart.processElement(), DDLPolyGenerator.processElement(), DDLRotationAndReflection.processElement(), DDLCompositeMaterial.processElement(), DDLVector.processElement(), DDLRotationByAxis.processOne(), RPCConst.ptFromIpt(), fwriter::EventContainer.putNewEvent(), cond::SQLReport.putOnFile(), cond::FileReader.read(), readRemote(), RecoProducerFP420.RecoProducerFP420(), DQMNet.releaseFromWait(), CmsShowMainBase.reloadConfiguration(), cond::CredentialStore.removeConnection(), cond::CredentialStore.removePrincipal(), edm::JobReport.reportAnalysisFile(), edm::JobReport.reportError(), edm::JobReport.reportFallbackAttempt(), edm::JobReport.reportMemoryInfo(), edm::JobReport.reportMessageInfo(), edm::JobReport.reportPerformanceForModule(), edm::JobReport.reportPerformanceSummary(), edm::JobReport.reportRandomStateFile(), edm::JobReport.reportSkippedEvent(), edm::JobReport.reportSkippedFile(), DQMNet.requestObjectData(), DCCTBBlockPrototype.seeIfIsPossibleToIncrement(), DQMImplNet< DQMNet::Object >.sendObjectListToPeers(), CmsShowMainBase.sendVersionInfo(), edm::StreamerOutputModuleBase.serializeEvent(), cond::CredentialStore.setPermission(), Tm.setToString(), cond::CredentialStore.setUpForService(), TrackingRecHit.sharesInput(), edm::service::ELdestination.summarization(), edm::service::ELdestination.summary(), DDXMLElement.throwError(), cond::CredentialStore.unsetPermission(), edm::StreamerOutputModuleBase.write(), RawEventOutputModuleForBU< Consumer >.write(), and FRDEventOutputModule< Consumer >.write().

tuple lumiQueryAPI.q = schema.newQuery()

Definition at line 1839 of file lumiQueryAPI.py.

Referenced by JetAnaPythia< Jet >.analyze(), TrackParameterAnalyzer.analyze(), DisplayGeom.analyze(), PhotonValidator.analyze(), HLTScalers.analyze(), CaloRecHitMetaCollection.at(), AlignmentTrackSelector.basicCuts(), HcalPulseShapes.beginRun(), PhysicsTools::AtomicId.build(), CandCombinerBase< OutputCollection, CandPtr >.combine(), AnalyticalCurvilinearJacobian.computeFullJacobian(), Conv4HitsReco.ConversionCandidate(), VVIObjDetails.cosint(), sistripvvi::VVIObjDetails.cosint(), TtFullLepKinSolver.cubic(), TwoBodyDecayModel.curvilinearToCartesianJacobian(), PhysicsTools::VarProcessor.deriv(), FWEveDigitSetScalableMarkerGL.DirectDraw(), lhef.domToLines(), EEQuadrant(), ConfigurationDBHandler.endElement(), lhef::LHEReader::XMLHandler.endElement(), LMFSeqDat.fetchByRunNumber(), TrackAnalyzer.fillHistosForState(), PrimaryVertexAnalyzer4PU.fillTrackHistos(), edm::ParameterSet.fromString(), GammaFunctionGenerator.gammaFrac(), lumi::idDealer.generateNextIDForTable(), EvtPlaneProducer::GenPlane.getAngle(), TiXmlBase.GetEntity(), lumi::idDealer.getIDforTable(), MonitorElement.getQReport(), PrimaryVertexAnalyzer4PU.getSimTrkParameters(), pftools::CaloEllipse.getTheta(), L1MuGMTSortRankUnit.getVeryLowQualityLevel(), gen::Herwig6Instance.give(), ConversionFastHelix.helixStateAtVertex(), FastHelix.helixStateAtVertex(), HLTDeDxFilter.hltFilter(), GflashTrajectory.initializeTrajectory(), JacobianCartesianToCurvilinear.JacobianCartesianToCurvilinear(), JacobianCartesianToLocal.JacobianCartesianToLocal(), JacobianCurvilinearToCartesian.JacobianCurvilinearToCartesian(), JacobianLocalToCartesian.JacobianLocalToCartesian(), reco::TrackProbabilityTagInfo.jetProbability(), JetProbabilityComputer.jetProbability(), JetBProbabilityComputer.jetProbability(), 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(), NtpProducer< C >.produce(), L3MuonCandidateProducerFromMuons.produce(), TtSemiEvtSolutionMaker.produce(), TtHadEvtSolutionMaker.produce(), L2MuonCandidateProducer.produce(), L3MuonCandidateProducer.produce(), FFTJetPileupProcessor.produce(), Herwig6Hadronizer.pythiaStatusCode(), reco::Conversion.quality(), reco::TrackBase.quality(), GSUtilities.quantile(), SusyPostProcessor.QuantilePlots(), RealQuadEquation.RealQuadEquation(), HcalCableMapper.record(), FWOverlapTableView.refreshTable3D(), 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(), sistripvvi::VVIObjDetails.sincosint(), VVIObjDetails.sinint(), sistripvvi::VVIObjDetails.sinint(), L1MuGMTSortRankUnit.sort_rank(), L1MuGMTLFSortRankPtQLUT.SpecificLookup(), L1MuGMTLFMergeRankPtQLUT.SpecificLookup(), L1MuGMTLFSortRankEtaQLUT.SpecificLookup(), L1MuGMTLFMergeRankEtaQLUT.SpecificLookup(), L1MuGMTLFMergeRankEtaQLUT.SpecificLookup_flag(), L1MuGMTLFMergeRankEtaQLUT.SpecificLookup_rank_etaq(), L1MuGMTLFSortRankEtaQLUT.SpecificLookup_rank_etaq(), L1MuGMTLFSortRankPtQLUT.SpecificLookup_rank_ptq(), L1MuGMTLFMergeRankPtQLUT.SpecificLookup_rank_ptq(), L1MuGMTLFSortRankEtaQLUT.SpecificLookup_vlq(), TauValidation.spinEffectsZH(), PhysicsTools.split(), ConversionFastHelix.straightLineStateAtVertex(), FastHelix.straightLineStateAtVertex(), TiXmlBase.StringEqual(), edm::service::ELoutput.summarization(), L1MuGMTLFSortRankPtQLUT.TheLookupFunction(), L1MuGMTLFMergeRankEtaQLUT.TheLookupFunction(), L1MuonPixelTrackFitter.valInversePt(), SiStripClusterInfo.variance(), VVIObj.VVIObj(), sistripvvi::VVIObj.VVIObj(), VVIObjF.VVIObjF(), and DCULVRVoltagesDat.writeArrayDB().

tuple lumiQueryAPI.schema = session.nominalSchema()

Definition at line 1781 of file lumiQueryAPI.py.

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

Definition at line 1777 of file lumiQueryAPI.py.

tuple lumiQueryAPI.svc = coral.ConnectionService()

Definition at line 1775 of file lumiQueryAPI.py.