CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/RecoLuminosity/LumiDB/scripts/dumpWBM.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
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         self.norbits=2**18
00011         self.nbx=3564
00012         self.wbmdb=''
00013         self.wbmschema='CMS_WBM'
00014         self.deadtable='LEVEL1_TRIGGER_CONDITIONS'
00015         self.algotable='LEVEL1_TRIGGER_ALGO_CONDITIONS'
00016         self.techtable='LEVEL1_TRIGGER_TECH_CONDITIONS'
00017 def bitzeroForRun(dbsession,c,runnum):
00018     '''
00019       select LUMISEGMENTNR,GTALGOCOUNTS from CMS_WBM.LEVEL1_TRIGGER_ALGO_CONDITIONS where RUNNUMBER=:runnumber and BIT=0 order by LUMISEGMENTNR
00020     '''
00021     result={}
00022     try:
00023         dbsession.transaction().start(True)
00024         schema=dbsession.schema(c.wbmschema)
00025         if not schema:
00026             raise Exception,'cannot connect to schema'+c.wbmschema
00027         if not schema.existsTable(c.algotable):
00028             raise Exception,'non-existing view'+c.algotable
00029         
00030         query=schema.newQuery()
00031         algoBindVarList=coral.AttributeList()
00032         algoBindVarList.extend("runnumber","unsigned int")
00033         algoBindVarList.extend("bitnumber","unsigned int")
00034         algoBindVarList["runnumber"].setData(int(runnum))
00035         algoBindVarList["bitnumber"].setData(int(0))
00036         query.addToTableList(c.algotable)
00037         query.addToOutputList("LUMISEGMENTNR","lsnr")
00038         query.addToOutputList('GTALGOCOUNTS','bitcount')
00039         query.setCondition('RUNNUMBER=:runnumber AND BIT=:bitnumber',algoBindVarList)
00040         query.addToOrderList('LUMISEGMENTNR')
00041 
00042         bitzeroOutput=coral.AttributeList()
00043         bitzeroOutput.extend("lsnr","unsigned int")
00044         bitzeroOutput.extend('bitcount','unsigned int')
00045         
00046         query.defineOutput(bitzeroOutput)
00047         cursor=query.execute()
00048         while cursor.next():
00049             cmslsnum=cursor.currentRow()['lsnr'].data()
00050             bitcount=cursor.currentRow()['bitcount'].data()
00051             result[cmslsnum]=bitcount
00052         del query
00053         dbsession.transaction().commit()
00054         return result
00055     except Exception,e:
00056         print str(e)
00057         dbsession.transaction().rollback()
00058         del dbsession
00059 
00060 def deadcountForRun(dbsession,c,runnum):
00061     '''
00062     select DEADTIMEBEAMACTIVE from cms_wbm.LEVEL1_TRIGGER_CONDITIONS where RUNNUMBER=133881 order by LUMISEGMENTNR
00063     '''
00064     result={}
00065     try:   
00066         dbsession.transaction().start(True)
00067         schema=dbsession.schema(c.wbmschema)
00068         if not schema:
00069             raise Exception,'cannot connect to schema '+c.wbmschema
00070         if not schema.existsTable(c.deadtable):
00071             raise Exception,'non-existing table '+c.deadtable
00072 
00073         deadOutput=coral.AttributeList()
00074         deadOutput.extend("lsnr","unsigned int")
00075         deadOutput.extend("deadcount","unsigned long long")
00076         
00077         deadBindVarList=coral.AttributeList()
00078         deadBindVarList.extend("RUNNUMBER","unsigned int")
00079         deadBindVarList["RUNNUMBER"].setData(int(runnum))
00080         
00081         query=schema.newQuery()
00082         query.addToTableList(c.deadtable)
00083         query.addToOutputList('LUMISEGMENTNR','lsnr')
00084         query.addToOutputList('DEADTIMEBEAMACTIVE','deadcount')
00085         query.setCondition('RUNNUMBER=:runnumber',deadBindVarList)
00086         query.addToOrderList('LUMISEGMENTNR')
00087         query.defineOutput(deadOutput)
00088         
00089         cursor=query.execute()
00090         while cursor.next():
00091             cmslsnum=cursor.currentRow()['lsnr'].data()
00092             deadcount=cursor.currentRow()['deadcount'].data()
00093             result[cmslsnum]=deadcount
00094             #print 'deadcount',deadcount
00095         del query
00096         dbsession.transaction().commit()
00097         return result
00098     except Exception,e:
00099         print str(e)
00100         dbsession.transaction().rollback()
00101         del dbsession
00102         
00103 def main():
00104     c=constants()
00105     parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Dump trigger info in wbm")
00106     parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to trigger DB(required)')
00107     parser.add_argument('-P',dest='authpath',action='store',required=True,help='path to authentication file')
00108     parser.add_argument('-r',dest='runnumber',action='store',required=True,help='run number')
00109     parser.add_argument('action',choices=['deadtime','deadfraction'],help='dump deadfraction')
00110     parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
00111     args=parser.parse_args()
00112     runnumber=args.runnumber
00113     c.wbmdb=args.connect
00114     if args.authpath and len(args.authpath)!=0:
00115         os.environ['CORAL_AUTH_PATH']=args.authpath
00116     #print 'authpath ',args.authpath
00117     svc=coral.ConnectionService()
00118     #print 'about to access ',c.wbmdb
00119     session=svc.connect(c.wbmdb,accessMode=coral.access_ReadOnly)
00120     session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
00121     session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
00122     if args.debug:
00123         msg=coral.MessageStream('')
00124         msg.setMsgVerbosity(coral.message_Level_Debug)
00125         
00126     if args.action == 'deadtime':
00127         deadresult=deadcountForRun(session,c,runnumber)
00128         if deadresult and len(deadresult)!=0:
00129             print 'run',runnumber
00130             print 'ls deadcount'
00131             for cmsls,deadcount in deadresult.items():
00132                 print cmsls,deadcount
00133         else:
00134             print 'no deadtime found for run ',runnumber
00135             
00136     if args.action == 'deadfraction':
00137         deadresult=deadcountForRun(session,c,runnumber)
00138         bitzeroresult=bitzeroForRun(session,c,runnumber)
00139         print 'run',runnumber
00140         print 'ls deadfraction'
00141         if deadresult and len(deadresult)!=0:
00142             #print 'run',runnumber
00143             #print 'ls deadfraction'
00144             for cmsls,deadcount in deadresult.items():
00145                 bitzero=bitzeroresult[cmsls]
00146                 bitzero_prescale=1.0
00147                 if int(runnumber)>=146315:
00148                     bitzero_prescale=17.0
00149                 if bitzero==0:
00150                     print cmsls,'no beam'
00151                 else:
00152                     print cmsls,'%.5f'%float(float(deadcount)/(float(bitzero)*bitzero_prescale))
00153         else:
00154             print 'no deadtime found for run ',runnumber
00155     del session
00156     del svc
00157         
00158 if __name__=='__main__':
00159     main()
00160