CMS 3D CMS Logo

dumpTrg.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.gtmondb=''
14  #self.gtmondb='oracle://cms_omds_lb/CMS_GT_MON'
15  self.gtmonschema='CMS_GT_MON'
16  self.deadviewname='GT_MON_TRIG_DEAD_VIEW'
17  self.algoviewname='GT_MON_TRIG_ALGO_VIEW'
18 
19 def bitzeroForRun(dbsession,c,runnum):
20  '''
21  select lsnr,counts,prescale from CMS_GT_MON.GT_MON_TRIG_ALGO_VIEW where runnr=:runnumber and algobit=:bitnum order by lsnr
22  '''
23  result={}
24  try:
25  dbsession.transaction().start(True)
26  schema=dbsession.schema(c.gtmonschema)
27  if not schema:
28  raise RuntimeError('cannot connect to schema '+c.gtmonschema)
29  if not schema.existsView(c.algoviewname):
30  raise RuntimeError('non-existing view '+c.algoviewname)
31 
32  bitOutput=coral.AttributeList()
33  bitOutput.extend("lsnr","unsigned int")
34  bitOutput.extend("algocount","unsigned int")
35  bitBindVarList=coral.AttributeList()
36  bitBindVarList.extend("runnumber","unsigned int")
37  bitBindVarList.extend("bitnum","unsigned int")
38  bitBindVarList["runnumber"].setData(int(runnum))
39  bitBindVarList["bitnum"].setData(0)
40 
41  query=schema.newQuery()
42  query.addToTableList(c.algoviewname)
43  query.addToOutputList('LSNR','lsnr')
44  query.addToOutputList('COUNTS','algocount')
45  query.setCondition('RUNNR=:runnumber AND ALGOBIT=:bitnum',bitBindVarList)
46  query.addToOrderList('lsnr')
47  query.defineOutput(bitOutput)
48 
49  cursor=query.execute()
50  while next(cursor):
51  cmslsnum=cursor.currentRow()['lsnr'].data()
52  algocount=cursor.currentRow()['algocount'].data()
53  result[cmslsnum]=algocount
54  del query
55  dbsession.transaction().commit()
56  #print result
57  return result
58  except Exception as e:
59  print(str(e))
60  dbsession.transaction().rollback()
61  del dbsession
62 
63 def deadcountForRun(dbsession,c,runnum):
64  '''
65  select counts,lsnr from cms_gt_mon.gt_mon_trig_dead_view where runnr=:runnumber and deadcounter=:countername order by lsnr;
66  '''
67  result={}
68  try:
69  dbsession.transaction().start(True)
70  schema=dbsession.schema(c.gtmonschema)
71  if not schema:
72  raise RuntimeError('cannot connect to schema '+c.gtmonschema)
73  if not schema.existsView(c.deadviewname):
74  raise RuntimeError('non-existing view '+c.deadviewname)
75 
76  deadOutput=coral.AttributeList()
77  deadOutput.extend("lsnr","unsigned int")
78  deadOutput.extend("deadcount","unsigned long long")
79 
80  deadBindVarList=coral.AttributeList()
81  deadBindVarList.extend("runnumber","unsigned int")
82  deadBindVarList.extend("countername","string")
83  deadBindVarList["runnumber"].setData(int(runnum))
84  deadBindVarList["countername"].setData('DeadtimeBeamActive')
85 
86  query=schema.newQuery()
87  query.addToTableList(c.deadviewname)
88  query.addToOutputList('LSNR','lsnr')
89  query.addToOutputList('COUNTS','deadcount')
90  query.setCondition('RUNNR=:runnumber AND DEADCOUNTER=:countername',deadBindVarList)
91  query.addToOrderList('lsnr')
92  query.defineOutput(deadOutput)
93 
94  cursor=query.execute()
95  while next(cursor):
96  cmslsnum=cursor.currentRow()['lsnr'].data()
97  deadcount=cursor.currentRow()['deadcount'].data()
98  result[cmslsnum]=deadcount
99  del query
100  dbsession.transaction().commit()
101  return result
102  except Exception as e:
103  print(str(e))
104  dbsession.transaction().rollback()
105  del dbsession
106 
107 def main():
108  c=constants()
109  parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Dump GT info")
110  parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to trigger DB(required)')
111  parser.add_argument('-P',dest='authpath',action='store',required=True,help='path to authentication file')
112  parser.add_argument('-r',dest='runnumber',action='store',required=True,help='run number')
113  parser.add_argument('action',choices=['deadtime','deadfraction'],help='dump deadtime beamacrive count')
114  parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
115  args=parser.parse_args()
116  runnumber=args.runnumber
117  c.gtmondb=args.connect
118  if args.authpath and len(args.authpath)!=0:
119  os.environ['CORAL_AUTH_PATH']=args.authpath
120  svc=coral.ConnectionService()
121  session=svc.connect(c.gtmondb,accessMode=coral.access_ReadOnly)
122  session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
123  session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
124  if args.debug:
125  msg=coral.MessageStream('')
126  msg.setMsgVerbosity(coral.message_Level_Debug)
127 
128  if args.action == 'deadtime':
129  deadresult=deadcountForRun(session,c,runnumber)
130  if deadresult and len(deadresult)!=0:
131  print('run',runnumber)
132  print('ls deadcount')
133  for cmsls,deadcount in deadresult.items():
134  print(cmsls,deadcount)
135  else:
136  print('no deadtime found for run ',runnumber)
137 
138  if args.action == 'deadfraction':
139  deadresult=deadcountForRun(session,c,runnumber)
140  bitzeroresult=bitzeroForRun(session,c,runnumber)
141  if deadresult and len(deadresult)!=0:
142  print('run',runnumber)
143  print('ls deadfraction')
144  for cmsls,deadcount in deadresult.items():
145  bitzero_count=bitzeroresult[cmsls]
146  bitzero_prescale=1.0
147  if int(runnumber)>=146315:
148  bitzero_prescale=17.0
149  if bitzero_count==0:
150  print(cmsls,'no beam')
151  else:
152  print(cmsls,'%.5f'%float(float(deadcount)/(float(bitzero_count)*bitzero_prescale)))
153  else:
154  print('no deadtime found for run ',runnumber)
155 
156  del session
157  del svc
158 
159 if __name__=='__main__':
160  main()
161 
Definition: start.py:1
def main()
Definition: dumpTrg.py:107
def deadcountForRun(dbsession, c, runnum)
Definition: dumpTrg.py:63
def __init__(self)
Definition: dumpTrg.py:9
def bitzeroForRun(dbsession, c, runnum)
Definition: dumpTrg.py:19
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
Definition: main.py:1
#define str(s)