CMS 3D CMS Logo

dumpRunInfo.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 VERSION='1.02'
3 import os,sys
4 import re
5 import coral
6 from RecoLuminosity.LumiDB import argparse
7 
9  def __init__(self):
10  self.debug=False
11  self.runinfodb=''
12  self.runinfoschema='CMS_RUNINFO'
13  self.runsessionparameterTable='RUNSESSION_PARAMETER'
14  self.hltconfname='CMS.LVL0:HLT_KEY_DESCRIPTION'
15  self.tsckeyname='CMS.TRG:TSC_KEY'
16  self.fillnumname='CMS.SCAL:FILLN'
17 def fillnumForRun(dbsession,c,runnum):
18  '''select string_value from cms_runinfo.runsession_parameter where runnumber=129265 and name='CMS.SCAL:FILLN' and rownum<=1;
19 
20  '''
21  result=''
22  try:
23  dbsession.transaction().start(True)
24  schema=dbsession.schema(c.runinfoschema)
25  if not schema:
26  raise Exception('cannot connect to schema '+c.runinfoschema)
27  if not schema.existsTable(c.runsessionparameterTable):
28  raise Exception('non-existing table '+c.runsessionparameterTable)
29 
30  fillOutput=coral.AttributeList()
31  fillOutput.extend("fillnum","string")
32 
33  bindVarList=coral.AttributeList()
34  bindVarList.extend("name","string")
35  bindVarList.extend("runnumber","unsigned int")
36 
37  bindVarList["name"].setData(c.fillnumname)
38  bindVarList["runnumber"].setData(int(runnum))
39 
40  query=schema.newQuery()
41  query.addToTableList(c.runsessionparameterTable)
42  query.addToOutputList('STRING_VALUE','value')
43  query.setCondition('NAME=:name AND RUNNUMBER=:runnumber',bindVarList)
44  query.limitReturnedRows(1)
45  query.defineOutput(fillOutput)
46 
47  cursor=query.execute()
48  while next(cursor):
49  result=cursor.currentRow()['fillnum'].data()
50  del query
51  dbsession.transaction().commit()
52  #print result
53  return result
54  except Exception as e:
55  print str(e)
56  dbsession.transaction().rollback()
57  del dbsession
58 
59 def hltkeyForRun(dbsession,c,runnum):
60  '''
61  select runnumber,string_value from cms_runinfo.runsession_parameter where name=:runsessionparametername and runnumber=:runnum
62  '''
63  result={}
64  try:
65  dbsession.transaction().start(True)
66  schema=dbsession.schema(c.runinfoschema)
67  if not schema:
68  raise Exception('cannot connect to schema '+c.runinfoschema)
69  if not schema.existsTable(c.runsessionparameterTable):
70  raise Exception('non-existing table '+c.runsessionparameterTable)
71 
72  hltkeyOutput=coral.AttributeList()
73  hltkeyOutput.extend("runnum","unsigned int")
74  hltkeyOutput.extend("hltkey","string")
75 
76  bindVarList=coral.AttributeList()
77  bindVarList.extend("name","string")
78  bindVarList.extend("runnumber","unsigned int")
79 
80  bindVarList["name"].setData(c.hltconfname)
81  bindVarList["runnumber"].setData(int(runnum))
82 
83  query=schema.newQuery()
84  query.addToTableList(c.runsessionparameterTable)
85  query.addToOutputList('RUNNUMBER','runnumber')
86  query.addToOutputList('STRING_VALUE','value')
87  query.setCondition('NAME=:name AND RUNNUMBER=:runnumber',bindVarList)
88  query.defineOutput(hltkeyOutput)
89 
90  cursor=query.execute()
91  while next(cursor):
92  runnum=cursor.currentRow()['runnum'].data()
93  hltkey=cursor.currentRow()['hltkey'].data()
94  result[runnum]=hltkey
95  del query
96  dbsession.transaction().commit()
97  #print result
98  return result
99  except Exception as e:
100  print str(e)
101  dbsession.transaction().rollback()
102  del dbsession
103 
104 def l1keyForRun(dbsession,c,runnum):
105  '''
106  select runnumber,string_value from cms_runinfo.runsession_parameter where name=:runsessionparametername and runnumber=:runnum
107  '''
108  result={}
109  try:
110  dbsession.transaction().start(True)
111  schema=dbsession.schema(c.runinfoschema)
112  if not schema:
113  raise Exception('cannot connect to schema '+c.runinfoschema)
114  if not schema.existsTable(c.runsessionparameterTable):
115  raise Exception('non-existing table '+c.runsessionparameterTable)
116 
117  l1keyOutput=coral.AttributeList()
118  l1keyOutput.extend("runnum","unsigned int")
119  l1keyOutput.extend("l1key","string")
120 
121  bindVarList=coral.AttributeList()
122  bindVarList.extend("name","string")
123  bindVarList.extend("runnumber","unsigned int")
124 
125  bindVarList["name"].setData(c.tsckeyname)
126  bindVarList["runnumber"].setData(int(runnum))
127 
128  query=schema.newQuery()
129  query.addToTableList(c.runsessionparameterTable)
130  query.addToOutputList('RUNNUMBER','runnumber')
131  query.addToOutputList('STRING_VALUE','value')
132  query.setCondition('NAME=:name AND RUNNUMBER=:runnumber',bindVarList)
133  query.defineOutput(l1keyOutput)
134 
135  cursor=query.execute()
136  while next(cursor):
137  runnum=cursor.currentRow()['runnum'].data()
138  l1key=cursor.currentRow()['l1key'].data()
139  result[runnum]=l1key
140  del query
141  dbsession.transaction().commit()
142  #print result
143  return result
144  except Exception as e:
145  print str(e)
146  dbsession.transaction().rollback()
147  del dbsession
148 
149 def main():
150  c=constants()
151  parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Dump Run info")
152  parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to trigger DB(required)')
153  parser.add_argument('-P',dest='authpath',action='store',required=True,help='path to authentication file')
154  parser.add_argument('-r',dest='runnumber',action='store',required=True,help='run number')
155  parser.add_argument('action',choices=['hltkey','l1key','fill'],help='information to show')
156  parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
157  parser.add_argument('--collision-only',dest='collisiononly',action='store_true',help='return only collision runs')
158  args=parser.parse_args()
159  runnumber=args.runnumber
160  c.runinfodb=args.connect
161  if args.authpath and len(args.authpath)!=0:
162  os.environ['CORAL_AUTH_PATH']=args.authpath
163  svc=coral.ConnectionService()
164  session=svc.connect(c.runinfodb,accessMode=coral.access_ReadOnly)
165  session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
166  session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
167  if args.debug:
168  msg=coral.MessageStream('')
169  msg.setMsgVerbosity(coral.message_Level_Debug)
170 
171  if args.action == 'hltkey':
172  p=re.compile(r'^/cdaq/physics/.+')
173  result=hltkeyForRun(session,c,runnumber)
174  print 'runnumber hltkey'
175  for runnum,hltkey in result.items():
176  if not args.collisiononly:
177  print runnum,hltkey
178  if args.collisiononly and re.match(p,hltkey):
179  fillnum=fillnumForRun(session,c,runnumber)
180  if len(fillnum)!=0:
181  print runnum,hltkey
182  if args.action == 'l1key':
183  p=re.compile(r'^TSC_.+_collisions_.+')
184  result=l1keyForRun(session,c,runnumber)
185  print 'runnumber tsc_key'
186  for runnum,l1key in result.items():
187  if not args.collisiononly:
188  print runnum,l1key
189  if args.collisiononly and re.match(p,l1key):
190  fillnum=fillnumForRun(session,c,runnumber)
191  if len(fillnum)!=0:
192  print runnum,l1key
193  if args.action == 'fill':
194  result=fillnumForRun(session,c,runnumber)
195  print 'runnumber fill'
196  if not args.collisiononly:
197  print runnumber,result
198  else:
199  if len(result)!=0:
200  print runnumber,result
201  del session
202  del svc
203 
204 if __name__=='__main__':
205  main()
206 
Definition: start.py:1
def l1keyForRun(dbsession, c, runnum)
Definition: dumpRunInfo.py:104
def hltkeyForRun(dbsession, c, runnum)
Definition: dumpRunInfo.py:59
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
Definition: main.py:1
def fillnumForRun(dbsession, c, runnum)
Definition: dumpRunInfo.py:17