10 from RecoLuminosity.LumiDB
import normDML,revisionDML,argparse,sessionManager,lumiReport,normFileParser,CommonUtil
20 if __name__ ==
'__main__':
21 parser=argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description=
"Luminosity normalization/correction management tool",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
22 allowedActions=[
'list',
'create',
'insert',
'setdefault',
'unsetdefault']
23 parser.add_argument(
'action',choices=allowedActions,help=
'command actions')
24 parser.add_argument(
'-c',
28 help=
'connect string to lumiDB,optional',default=
'frontier://LumiCalc/CMS_LUMI_PROD')
29 parser.add_argument(
'-P',
32 help=
'path to authentication file,optional')
33 parser.add_argument(
'--name',
37 parser.add_argument(
'--lumitype',
41 parser.add_argument(
'-f',
44 help=
'norm definition file. Required for all update actions')
45 parser.add_argument(
'--siteconfpath',
48 help=
'specific path to site-local-config.xml file, optional. If path undefined, fallback to cern proxy&server')
49 parser.add_argument(
'--firstsince',
53 help=
'pick only the pieces with since>=firstsince to insert')
54 parser.add_argument(
'--debug',
58 options=parser.parse_args()
60 os.environ[
'CORAL_AUTH_PATH']=options.authpath
64 if options.action
in [
'create',
'insert',
'setdefault',
'unsetdefault']:
65 if not options.connect:
66 raise RuntimeError(
'argument -c connect is required for create/insert/updatedefault action')
67 if not options.authpath:
68 raise RuntimeError(
'argument -P authpath is required for create/insert/updatedefault action')
69 if options.action
in [
'create',
'insert']:
70 if not options.normfile:
71 raise RuntimeError(
'argument -f normfile is required for insert action')
72 if options.action
in [
'setdefault',
'unsetdefault']:
73 if not options.lumitype:
74 raise RuntimeError(
'argument --lumitype lumitype is required for setdefault/unsetdefault action')
75 if not options.normname:
76 raise RuntimeError(
'argument --name normname is required for setdefault/unsetdefault action')
81 if options.action
in [
'create',
'insert'] :
82 dbsession=svc.openSession(isReadOnly=
False,cpp2sqltype=[(
'unsigned int',
'NUMBER(10)'),(
'unsigned long long',
'NUMBER(20)')])
84 normdata=normfileparser.parse()
85 normdefinitionDict=normdata[0]
86 normvalues=normdata[1]
87 dbsession.transaction().
start(
False)
90 normname=options.normname
92 if 'name' in normdefinitionDict
and normdefinitionDict[
'name']:
93 normname=normdefinitionDict[
'name']
95 raise RuntimeError(
'[ERROR] normname undefined')
98 lumitype=options.lumitype
100 if 'lumitype' in normdefinitionDict
and normdefinitionDict[
'lumitype']:
101 lumitype=normdefinitionDict[
'lumitype']
103 if 'istypedefault' in normdefinitionDict
and normdefinitionDict[
'istypedefault']:
104 istypedefault=
int(normdefinitionDict[
'istypedefault'])
106 if 'comment' in normdefinitionDict:
107 commentStr=normdefinitionDict[
'comment']
109 if options.action==
'create':
111 branchinfo=(revision_id,
'NORM')
112 (normrev_id,normentry_id,normdata_id)=
normDML.createNorm(dbsession.nominalSchema(),normname,lumitype,istypedefault,branchinfo,comment=commentStr)
115 for normvalueDict
in normvalues:
116 if 'corrector' not in normvalueDict
or not normvalueDict[
'corrector']:
117 raise RuntimeError(
'parameter corrector is required for create/insert action')
118 if 'since' not in normvalueDict
or not normvalueDict[
'since']:
119 raise RuntimeError(
'parameter since is required for create/insert action')
120 correctorStr=normvalueDict[
'corrector']
121 sincerun=
int(normvalueDict[
'since'])
122 if options.firstsince:
123 if sincerun<
int(options.firstsince):
125 amodetag=normvalueDict[
'amodetag']
126 egev=
int(normvalueDict[
'egev'])
127 detailcomment=normvalueDict[
'comment']
130 for param
in parameterlist:
131 parameterDict[param]=normvalueDict[param]
132 normDML.insertValueToNormId(dbsession.nominalSchema(),normdata_id,sincerun,correctorStr,amodetag,egev,parameterDict,comment=detailcomment)
133 dbsession.transaction().commit()
138 if options.action
in [
'setdefault',
'unsetdefault']:
139 dbsession=svc.openSession(isReadOnly=
False,cpp2sqltype=[(
'unsigned int',
'NUMBER(10)'),(
'unsigned long long',
'NUMBER(20)')])
140 dbsession.transaction().
start(
False)
141 if options.action==
'setdefault':
143 if options.action==
'unsetdefault':
145 dbsession.transaction().commit()
149 if options.action==
'list':
150 dbsession=svc.openSession(isReadOnly=
True,cpp2sqltype=[(
'unsigned int',
'NUMBER(10)'),(
'unsigned long long',
'NUMBER(20)')])
151 dbsession.transaction().
start(
True)
154 normdataid=norminfo[0]
157 elif options.lumitype:
159 for normname,normid
in luminormidmap.items():
166 dbsession.transaction().commit()
def normInfoByName(schema, normname)
def normIdByName(schema, normname)
def allNorms(schema)
Norm/Correction/version DML API # # Author: Zhen Xie #.
def normIdByType(schema, lumitype='HF', defaultonly=True)
def insertValueToNormId(schema, normdataid, sincerun, corrector, amodetag, egev, parameters, comment='')
def promoteNormToTypeDefault(schema, normname, lumitype)
def createNorm(schema, normname, lumitype, istypedefault, branchinfo, comment='')
def toScreenNormDetail(normname, norminfo, normvalues)
def branchInfoByName(schema, branchName)
def normValueById(schema, normid)
def demoteNormFromTypeDefault(schema, normname, lumitype)
def parselumicorrector(correctorStr)
norm file format spec lines beginning with a semicolon ';' a pound sign '#' or the letters 'REM' (upp...
def toScreenNormSummary(allnorms)