CMS 3D CMS Logo

dumpWBM.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from __future__ import print_function
3 VERSION='1.02'
4 import os,sys
5 import coral
6 from RecoLuminosity.LumiDB import argparse
7 
9  def __init__(self):
10  self.debug=False
11  self.norbits=2**18
12  self.nbx=3564
13  self.wbmdb=''
14  self.wbmschema='CMS_WBM'
15  self.deadtable='LEVEL1_TRIGGER_CONDITIONS'
16  self.algotable='LEVEL1_TRIGGER_ALGO_CONDITIONS'
17  self.techtable='LEVEL1_TRIGGER_TECH_CONDITIONS'
18 def bitzeroForRun(dbsession,c,runnum):
19  '''
20  select LUMISEGMENTNR,GTALGOCOUNTS from CMS_WBM.LEVEL1_TRIGGER_ALGO_CONDITIONS where RUNNUMBER=:runnumber and BIT=0 order by LUMISEGMENTNR
21  '''
22  result={}
23  try:
24  dbsession.transaction().start(True)
25  schema=dbsession.schema(c.wbmschema)
26  if not schema:
27  raise Exception('cannot connect to schema'+c.wbmschema)
28  if not schema.existsTable(c.algotable):
29  raise Exception('non-existing view'+c.algotable)
30 
31  query=schema.newQuery()
32  algoBindVarList=coral.AttributeList()
33  algoBindVarList.extend("runnumber","unsigned int")
34  algoBindVarList.extend("bitnumber","unsigned int")
35  algoBindVarList["runnumber"].setData(int(runnum))
36  algoBindVarList["bitnumber"].setData(int(0))
37  query.addToTableList(c.algotable)
38  query.addToOutputList("LUMISEGMENTNR","lsnr")
39  query.addToOutputList('GTALGOCOUNTS','bitcount')
40  query.setCondition('RUNNUMBER=:runnumber AND BIT=:bitnumber',algoBindVarList)
41  query.addToOrderList('LUMISEGMENTNR')
42 
43  bitzeroOutput=coral.AttributeList()
44  bitzeroOutput.extend("lsnr","unsigned int")
45  bitzeroOutput.extend('bitcount','unsigned int')
46 
47  query.defineOutput(bitzeroOutput)
48  cursor=query.execute()
49  while next(cursor):
50  cmslsnum=cursor.currentRow()['lsnr'].data()
51  bitcount=cursor.currentRow()['bitcount'].data()
52  result[cmslsnum]=bitcount
53  del query
54  dbsession.transaction().commit()
55  return result
56  except Exception as e:
57  print(str(e))
58  dbsession.transaction().rollback()
59  del dbsession
60 
61 def deadcountForRun(dbsession,c,runnum):
62  '''
63  select DEADTIMEBEAMACTIVE from cms_wbm.LEVEL1_TRIGGER_CONDITIONS where RUNNUMBER=133881 order by LUMISEGMENTNR
64  '''
65  result={}
66  try:
67  dbsession.transaction().start(True)
68  schema=dbsession.schema(c.wbmschema)
69  if not schema:
70  raise Exception('cannot connect to schema '+c.wbmschema)
71  if not schema.existsTable(c.deadtable):
72  raise Exception('non-existing table '+c.deadtable)
73 
74  deadOutput=coral.AttributeList()
75  deadOutput.extend("lsnr","unsigned int")
76  deadOutput.extend("deadcount","unsigned long long")
77 
78  deadBindVarList=coral.AttributeList()
79  deadBindVarList.extend("RUNNUMBER","unsigned int")
80  deadBindVarList["RUNNUMBER"].setData(int(runnum))
81 
82  query=schema.newQuery()
83  query.addToTableList(c.deadtable)
84  query.addToOutputList('LUMISEGMENTNR','lsnr')
85  query.addToOutputList('DEADTIMEBEAMACTIVE','deadcount')
86  query.setCondition('RUNNUMBER=:runnumber',deadBindVarList)
87  query.addToOrderList('LUMISEGMENTNR')
88  query.defineOutput(deadOutput)
89 
90  cursor=query.execute()
91  while next(cursor):
92  cmslsnum=cursor.currentRow()['lsnr'].data()
93  deadcount=cursor.currentRow()['deadcount'].data()
94  result[cmslsnum]=deadcount
95  #print 'deadcount',deadcount
96  del query
97  dbsession.transaction().commit()
98  return result
99  except Exception as e:
100  print(str(e))
101  dbsession.transaction().rollback()
102  del dbsession
103 
104 def main():
105  c=constants()
106  parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Dump trigger info in wbm")
107  parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to trigger DB(required)')
108  parser.add_argument('-P',dest='authpath',action='store',required=True,help='path to authentication file')
109  parser.add_argument('-r',dest='runnumber',action='store',required=True,help='run number')
110  parser.add_argument('action',choices=['deadtime','deadfraction'],help='dump deadfraction')
111  parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
112  args=parser.parse_args()
113  runnumber=args.runnumber
114  c.wbmdb=args.connect
115  if args.authpath and len(args.authpath)!=0:
116  os.environ['CORAL_AUTH_PATH']=args.authpath
117  #print 'authpath ',args.authpath
118  svc=coral.ConnectionService()
119  #print 'about to access ',c.wbmdb
120  session=svc.connect(c.wbmdb,accessMode=coral.access_ReadOnly)
121  session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
122  session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
123  if args.debug:
124  msg=coral.MessageStream('')
125  msg.setMsgVerbosity(coral.message_Level_Debug)
126 
127  if args.action == 'deadtime':
128  deadresult=deadcountForRun(session,c,runnumber)
129  if deadresult and len(deadresult)!=0:
130  print('run',runnumber)
131  print('ls deadcount')
132  for cmsls,deadcount in deadresult.items():
133  print(cmsls,deadcount)
134  else:
135  print('no deadtime found for run ',runnumber)
136 
137  if args.action == 'deadfraction':
138  deadresult=deadcountForRun(session,c,runnumber)
139  bitzeroresult=bitzeroForRun(session,c,runnumber)
140  print('run',runnumber)
141  print('ls deadfraction')
142  if deadresult and len(deadresult)!=0:
143  #print 'run',runnumber
144  #print 'ls deadfraction'
145  for cmsls,deadcount in deadresult.items():
146  bitzero=bitzeroresult[cmsls]
147  bitzero_prescale=1.0
148  if int(runnumber)>=146315:
149  bitzero_prescale=17.0
150  if bitzero==0:
151  print(cmsls,'no beam')
152  else:
153  print(cmsls,'%.5f'%float(float(deadcount)/(float(bitzero)*bitzero_prescale)))
154  else:
155  print('no deadtime found for run ',runnumber)
156  del session
157  del svc
158 
159 if __name__=='__main__':
160  main()
161 
Definition: start.py:1
def main()
Definition: dumpWBM.py:104
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def bitzeroForRun(dbsession, c, runnum)
Definition: dumpWBM.py:18
def deadcountForRun(dbsession, c, runnum)
Definition: dumpWBM.py:61
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def __init__(self)
Definition: dumpWBM.py:9
Definition: main.py:1
#define str(s)