00001
00002 VERSION='1.02'
00003 import os,sys
00004 import coral
00005 from RecoLuminosity.LumiDB import argparse
00006
00007 class constants(object):
00008 def __init__(self):
00009 self.debug=False
00010
00011
00012 self.gtmondb=''
00013
00014 self.gtmonschema='CMS_GT_MON'
00015 self.deadviewname='GT_MON_TRIG_DEAD_VIEW'
00016 self.algoviewname='GT_MON_TRIG_ALGO_VIEW'
00017
00018 def bitzeroForRun(dbsession,c,runnum):
00019 '''
00020 select lsnr,counts,prescale from CMS_GT_MON.GT_MON_TRIG_ALGO_VIEW where runnr=:runnumber and algobit=:bitnum order by lsnr
00021 '''
00022 result={}
00023 try:
00024 dbsession.transaction().start(True)
00025 schema=dbsession.schema(c.gtmonschema)
00026 if not schema:
00027 raise 'cannot connect to schema',c.gtmonschema
00028 if not schema.existsView(c.algoviewname):
00029 raise 'non-existing view',c.algoviewname
00030
00031 bitOutput=coral.AttributeList()
00032 bitOutput.extend("lsnr","unsigned int")
00033 bitOutput.extend("algocount","unsigned int")
00034 bitBindVarList=coral.AttributeList()
00035 bitBindVarList.extend("runnumber","unsigned int")
00036 bitBindVarList.extend("bitnum","unsigned int")
00037 bitBindVarList["runnumber"].setData(int(runnum))
00038 bitBindVarList["bitnum"].setData(0)
00039
00040 query=schema.newQuery()
00041 query.addToTableList(c.algoviewname)
00042 query.addToOutputList('LSNR','lsnr')
00043 query.addToOutputList('COUNTS','algocount')
00044 query.setCondition('RUNNR=:runnumber AND ALGOBIT=:bitnum',bitBindVarList)
00045 query.addToOrderList('lsnr')
00046 query.defineOutput(bitOutput)
00047
00048 cursor=query.execute()
00049 while cursor.next():
00050 cmslsnum=cursor.currentRow()['lsnr'].data()
00051 algocount=cursor.currentRow()['algocount'].data()
00052 result[cmslsnum]=algocount
00053 del query
00054 dbsession.transaction().commit()
00055
00056 return result
00057 except Exception,e:
00058 print str(e)
00059 dbsession.transaction().rollback()
00060 del dbsession
00061
00062 def deadcountForRun(dbsession,c,runnum):
00063 '''
00064 select counts,lsnr from cms_gt_mon.gt_mon_trig_dead_view where runnr=:runnumber and deadcounter=:countername order by lsnr;
00065 '''
00066 result={}
00067 try:
00068 dbsession.transaction().start(True)
00069 schema=dbsession.schema(c.gtmonschema)
00070 if not schema:
00071 raise 'cannot connect to schema',c.gtmonschema
00072 if not schema.existsView(c.deadviewname):
00073 raise 'non-existing view',c.deadviewname
00074
00075 deadOutput=coral.AttributeList()
00076 deadOutput.extend("lsnr","unsigned int")
00077 deadOutput.extend("deadcount","unsigned long long")
00078
00079 deadBindVarList=coral.AttributeList()
00080 deadBindVarList.extend("runnumber","unsigned int")
00081 deadBindVarList.extend("countername","string")
00082 deadBindVarList["runnumber"].setData(int(runnum))
00083 deadBindVarList["countername"].setData('DeadtimeBeamActive')
00084
00085 query=schema.newQuery()
00086 query.addToTableList(c.deadviewname)
00087 query.addToOutputList('LSNR','lsnr')
00088 query.addToOutputList('COUNTS','deadcount')
00089 query.setCondition('RUNNR=:runnumber AND DEADCOUNTER=:countername',deadBindVarList)
00090 query.addToOrderList('lsnr')
00091 query.defineOutput(deadOutput)
00092
00093 cursor=query.execute()
00094 while cursor.next():
00095 cmslsnum=cursor.currentRow()['lsnr'].data()
00096 deadcount=cursor.currentRow()['deadcount'].data()
00097 result[cmslsnum]=deadcount
00098 del query
00099 dbsession.transaction().commit()
00100 return result
00101 except Exception,e:
00102 print str(e)
00103 dbsession.transaction().rollback()
00104 del dbsession
00105
00106 def main():
00107 c=constants()
00108 parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Dump GT info")
00109 parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to trigger DB(required)')
00110 parser.add_argument('-P',dest='authpath',action='store',required=True,help='path to authentication file')
00111 parser.add_argument('-r',dest='runnumber',action='store',required=True,help='run number')
00112 parser.add_argument('action',choices=['deadtime','deadfraction'],help='dump deadtime beamacrive count')
00113 parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
00114 args=parser.parse_args()
00115 runnumber=args.runnumber
00116 c.gtmondb=args.connect
00117 if args.authpath and len(args.authpath)!=0:
00118 os.environ['CORAL_AUTH_PATH']=args.authpath
00119 svc=coral.ConnectionService()
00120 session=svc.connect(c.gtmondb,accessMode=coral.access_ReadOnly)
00121 session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
00122 session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
00123 if args.debug:
00124 msg=coral.MessageStream('')
00125 msg.setMsgVerbosity(coral.message_Level_Debug)
00126
00127 if args.action == 'deadtime':
00128 deadresult=deadcountForRun(session,c,runnumber)
00129 if deadresult and len(deadresult)!=0:
00130 print 'run',runnumber
00131 print 'ls deadcount'
00132 for cmsls,deadcount in deadresult.items():
00133 print cmsls,deadcount
00134 else:
00135 print 'no deadtime found for run ',runnumber
00136
00137 if args.action == 'deadfraction':
00138 deadresult=deadcountForRun(session,c,runnumber)
00139 bitzeroresult=bitzeroForRun(session,c,runnumber)
00140 if deadresult and len(deadresult)!=0:
00141 print 'run',runnumber
00142 print 'ls deadfraction'
00143 for cmsls,deadcount in deadresult.items():
00144 bitzero_count=bitzeroresult[cmsls]
00145 bitzero_prescale=1.0
00146 if int(runnumber)>=146315:
00147 bitzero_prescale=17.0
00148 if bitzero_count==0:
00149 print cmsls,'no beam'
00150 else:
00151 print cmsls,'%.5f'%float(float(deadcount)/(float(bitzero_count)*bitzero_prescale))
00152 else:
00153 print 'no deadtime found for run ',runnumber
00154
00155 del session
00156 del svc
00157
00158 if __name__=='__main__':
00159 main()
00160