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