00001
00002 import os,sys
00003 from RecoLuminosity.LumiDB import dataDML,revisionDML,argparse,sessionManager
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','get','overview']
00017 amodetagChoices=['PROTPHYS','HIPHYS']
00018 egevChoices=['3500','450']
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='3500',choices=egevChoices,help='nominal beam energy in GeV')
00024 parser.add_argument('-amodetag',dest='amodetag',action='store',default='PROTPHYS',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
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 elif options.action=='get':
00072 session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
00073 session.transaction().start(True)
00074 schema=session.nominalSchema()
00075 if options.tag is None:
00076 if options.name is not None:
00077 normdataid=dataDML.guessnormIdByName(schema,options.name)
00078 norm=dataDML.luminormById(schema,normdataid)
00079 print 'norm for ',options.name,norm
00080 else:
00081 normdataid=dataDML.guessnormIdByContext(schema,options.amodetag,int(options.egev))
00082 norm=dataDML.luminormById(schema,normdataid)
00083 print 'norm for ',norm
00084 session.transaction().commit()
00085 elif options.action=='overview':
00086 session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
00087 session.transaction().start(True)
00088 schema=session.nominalSchema()
00089 branchfilter=revisionDML.revisionsInBranchName(schema,'NORM')
00090 allnorms=dataDML.mostRecentLuminorms(schema,branchfilter)
00091 print allnorms
00092 session.transaction().commit()
00093 del session
00094 del svc