CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoLuminosity/LumiDB/scripts/dumpPrescale.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 VERSION='1.02'
00003 import os,sys,re
00004 import coral
00005 from RecoLuminosity.LumiDB import argparse,lumiQueryAPI
00006 
00007 def main():
00008     parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Dump Prescale info for selected hltpath and trg path",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
00009     parser.add_argument('-c',dest='connect',action='store',help='connect string to lumiDB,optional',default='frontier://LumiCalc/CMS_LUMI_PROD')
00010     parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file')
00011     parser.add_argument('-r',dest='runnumber',action='store',help='run number')
00012     parser.add_argument('-hltpath',dest='hltpath',action='store',required=True,help='hltpath')
00013     parser.add_argument('-trgbits',dest='trgbits',action='store',help='trgbits',default='all')
00014     parser.add_argument('-siteconfpath',dest='siteconfpath',action='store',help='specific path to site-local-config.xml file, optional. If path undefined, fallback to cern proxy&server')
00015     parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
00016     args=parser.parse_args()
00017     runnumber=args.runnumber
00018     if args.authpath and len(args.authpath)!=0:
00019         os.environ['CORAL_AUTH_PATH']=args.authpath
00020     parameters = lumiQueryAPI.ParametersObject()
00021     session,svc =  lumiQueryAPI.setupSession (args.connect or \
00022                                               'frontier://LumiCalc/CMS_LUMI_PROD',
00023                                                args.siteconfpath,parameters,args.debug)
00024     session.transaction().start(True)
00025     schema=session.nominalSchema()
00026     runlist=[]
00027     if args.debug:
00028         msg=coral.MessageStream('')
00029         msg.setMsgVerbosity(coral.message_Level_Debug)
00030     if args.runnumber:
00031         runlist.append(int(args.runnumber))
00032     else:
00033         runlist=lumiQueryAPI.allruns(schema,True,True,True,True)
00034     runlist.sort()
00035     bitlist=[]
00036     hltpathStr=re.sub('\s','',args.hltpath)
00037     #print bitlistStr
00038     if args.trgbits and args.trgbits!='all':
00039         bitlistStr=args.trgbits
00040         bitlistStr=bitlistStr.strip()
00041         bitlistStr=re.sub('\s','',bitlistStr)
00042         bitlist=bitlistStr.split(',')
00043     result={}#{run:{hltpath:prescle},{trgname:prescale}}
00044     trgdict={}#{run:[(trgname,trgprescale),()]}
00045     hltdict={}#{run:{hltname:hltprescale}}
00046     for runnum in runlist:
00047         q=schema.newQuery()
00048         hltdump=lumiQueryAPI.hltBypathByrun(q,runnum,hltpathStr)
00049         del q
00050         if len(hltdump)>0:
00051             hltdict[runnum]=hltdump[1][-1]
00052         else:
00053             print 'run ',runnum,' hltpath ','"'+hltpathStr+'"','not found'
00054             continue
00055         if not args.trgbits or args.trgbits=='all':
00056             q=schema.newQuery()
00057             l1seeds = lumiQueryAPI.hlttrgMappingByrun(q,runnum)
00058             del q
00059             if len(l1seeds)==0 or not l1seeds.has_key(hltpathStr):
00060                 print 'hlt path',hltpathStr,'has no l1 seed'
00061                 continue
00062             l1seed=l1seeds[hltpathStr]
00063             rmQuotes=l1seed.replace('\"','')
00064             rmOR=rmQuotes.replace(' OR','')
00065             rmNOT=rmOR.replace(' NOT','')
00066             rmAND=rmOR.replace(' AND','')
00067             bitlist=rmAND.split(' ')
00068         if not trgdict.has_key(runnum):
00069             trgdict[runnum]=[]
00070         for bitname in bitlist:
00071             q=schema.newQuery()
00072             trgbitdump=lumiQueryAPI.trgBybitnameByrun(q,runnum,bitname)
00073             del q
00074             if len(trgbitdump)>0:
00075                 trgprescale=trgbitdump[1][-1]
00076                 trgdict[runnum].append((bitname,trgprescale))
00077             else:
00078                 print 'run ',runnum,' bit ','"'+bitname+'"',' not found'
00079                 continue
00080     session.transaction().commit()
00081     del session
00082     del svc
00083     if len(hltdict)<1:
00084         print 'no result found for',hltpathStr
00085         sys.exit(-1)
00086     runs=hltdict.keys()
00087     runs.sort()
00088     for r in runs:
00089         if not hltdict.has_key(r): continue
00090         hltprescale=hltdict[r]
00091         toprint=[str(r),hltpathStr,str(hltprescale)]
00092         if trgdict.has_key(r):
00093             trgbitsinfo=trgdict[r]
00094             for trgbitinfo in trgbitsinfo:
00095                 trgname=trgbitinfo[0]
00096                 toprint.append(trgname)
00097                 trgprescale=trgbitinfo[1]
00098                 toprint.append(str(trgprescale))
00099         print ' '.join(toprint)
00100     #print trgdict
00101     #print hltdict
00102 if __name__=='__main__':
00103     main()
00104