00001
00002 import os,sys
00003 from RecoLuminosity.LumiDB import dataDML,revisionDML,argparse,sessionManager,lumiReport
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 if __name__ == '__main__':
00015 parser=argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Lumi Normalization factor",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
00016 allowedActions=['add','list']
00017 amodetagChoices=['PROTPHYS','IONPHYS','PAPHYS']
00018 egevChoices=['3500','450','1380']
00019 parser.add_argument('action',choices=allowedActions,help='command actions')
00020 parser.add_argument('-c',dest='connect',action='store',required=False,help='connect string to lumiDB,optional',default='frontier://LumiCalc/CMS_LUMI_PROD')
00021 parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file,optional')
00022 parser.add_argument('-name',dest='name',action='store',help='lumi norm factor name')
00023 parser.add_argument('-egev',dest='egev',action='store',default=None,help='single beam energy in GeV')
00024 parser.add_argument('-amodetag',dest='amodetag',action='store',default=None,choices=amodetagChoices,help='accelerator mode')
00025 parser.add_argument('-input',dest='input',action='store',help='input lumi value. Option for add action only')
00026 parser.add_argument('-tag',dest='tag',action='store',help='version of the norm factor')
00027 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')
00028 parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
00029 options=parser.parse_args()
00030 if options.authpath:
00031 os.environ['CORAL_AUTH_PATH']=options.authpath
00032
00033
00034
00035 if options.action=='add':
00036 if not options.authpath:
00037 raise RuntimeError('argument -P authpath is required for add action')
00038 if not options.input:
00039 raise RuntimeError('argument -input input is required for add action')
00040 if not options.name:
00041 raise RuntimeError('argument -name name is required for add action')
00042 svc=sessionManager.sessionManager(options.connect,authpath=options.authpath,siteconfpath=options.siteconfpath)
00043 session=None
00044
00045 if options.action=='add':
00046 session=svc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
00047
00048
00049
00050 session.transaction().start(False)
00051 schema=session.nominalSchema()
00052 (revision_id,branch_id)=revisionDML.branchInfoByName(schema,'NORM')
00053 dataDML.addNormToBranch(schema,options.name,options.amodetag,float(options.input),int(options.egev),{},(revision_id,'NORM'))
00054 session.transaction().commit()
00055 elif options.action=='list':
00056 session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
00057 session.transaction().start(True)
00058 schema=session.nominalSchema()
00059 if options.tag is None:
00060 if options.name is None and options.amodetag is None and options.egev is None:
00061 branchfilter=revisionDML.revisionsInBranchName(schema,'NORM')
00062 allnorms=dataDML.mostRecentLuminorms(schema,branchfilter)
00063 lumiReport.toScreenNorm(allnorms)
00064 elif options.name is not None:
00065 normdataid=dataDML.guessnormIdByName(schema,options.name)
00066 norm=dataDML.luminormById(schema,normdataid)
00067 nname=norm[0]
00068 namodetag=norm[1]
00069 nnormval=norm[2]
00070 negev=norm[3]
00071 lumiReport.toScreenNorm({nname:[namodetag,nnormval,negev]})
00072 else:
00073 amodetag=options.amodetag
00074 if options.amodetag is None:
00075 print '[Warning] -amodetag is not specified, assume PROTPHYS'
00076 amodetag='PROTPHYS'
00077 egev=options.egev
00078 if options.egev is None:
00079 print '[Warning] -egev is not specified, assume 3500'
00080 egev='3500'
00081 normdataid=dataDML.guessnormIdByContext(schema,amodetag,int(egev))
00082 norm=dataDML.luminormById(schema,normdataid)
00083 nname=norm[0]
00084 namodetag=norm[1]
00085 nnormval=norm[2]
00086 negev=norm[3]
00087 lumiReport.toScreenNorm({nname:[namodetag,nnormval,negev]})
00088 session.transaction().commit()
00089 del session
00090 del svc