CMS 3D CMS Logo

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