8 from __future__
import print_function
11 from RecoLuminosity.LumiDB
import argparse
14 update lumisummary set instlumi=instlumi*:norm where runnum>=:startrun and runnum<=:endrun 17 dbsession.transaction().
start(
False)
18 schema=dbsession.nominalSchema()
20 raise 'cannot connect to schema' 21 if not schema.existsTable(
'LUMISUMMARY'):
22 raise 'non-existing table LUMISUMMARY' 23 inputData=coral.AttributeList()
24 inputData.extend(
'normfactor',
'float')
25 inputData[
'normfactor'].setData(
float(normfactor))
26 inputData.extend(
'startrun',
'unsigned int')
27 inputData[
'startrun'].setData(
int(startrun))
28 inputData.extend(
'endrun',
'unsigned int')
29 inputData[
'endrun'].setData(
int(endrun))
30 nchanged=schema.tableHandle(
'LUMISUMMARY').dataEditor().updateRows(
'INSTLUMI=INSTLUMI*:normfactor',
'RUNNUM>=:startrun AND RUNNUM<=:endrun',inputData)
31 dbsession.transaction().commit()
33 except Exception
as e:
35 dbsession.transaction().rollback()
39 update lumisummary set instlumi=instlumi*:norm where runnum=:run 42 dbsession.transaction().
start(
False)
43 schema=dbsession.nominalSchema()
45 raise 'cannot connect to schema' 46 if not schema.existsTable(
'LUMISUMMARY'):
47 raise 'non-existing table LUMISUMMARY' 48 inputData=coral.AttributeList()
49 inputData.extend(
'normfactor',
'float')
50 inputData[
'normfactor'].setData(
float(normfactor))
51 inputData.extend(
'runnumber',
'unsigned int')
52 inputData[
'runnumber'].setData(
int(runnum))
53 nchanged=schema.tableHandle(
'LUMISUMMARY').dataEditor().updateRows(
'INSTLUMI=INSTLUMI*:normfactor',
'RUNNUM=:runnumber',inputData)
54 dbsession.transaction().commit()
56 except Exception
as e:
58 dbsession.transaction().rollback()
62 parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description=
"apply normalization factor to inst lumi")
63 parser.add_argument(
'-c',dest=
'connectstr',action=
'store',required=
True,help=
'connectstr')
64 parser.add_argument(
'-norm',dest=
'normfactor',action=
'store',required=
True,help=
'normalization factor to apply')
65 parser.add_argument(
'-P',dest=
'authpath',action=
'store',required=
True,help=
'path to authentication file')
66 parser.add_argument(
'-r',dest=
'runnumber',action=
'store',required=
False,help=
'run number')
67 parser.add_argument(
'-startrun',dest=
'startrun',action=
'store',required=
False,help=
'start run for range action')
68 parser.add_argument(
'-endrun',dest=
'endrun',action=
'store',required=
False,help=
'end run for range action')
69 parser.add_argument(
'action',choices=[
'run',
'range'],help=
'calibrate run')
71 parser.add_argument(
'--debug',dest=
'debug',action=
'store_true',help=
'debug')
72 args=parser.parse_args()
73 connectstr=args.connectstr
74 normfactor=args.normfactor
75 if len(args.authpath)!=0:
76 os.environ[
'CORAL_AUTH_PATH']=args.authpath
78 raise '-P authpath argument is required' 79 svc=coral.ConnectionService()
80 session=svc.connect(connectstr,accessMode=coral.access_Update)
82 msg=coral.MessageStream(
'')
83 msg.setMsgVerbosity(coral.message_Level_Debug)
85 if args.action ==
'run':
88 runnumber=args.runnumber
90 raise 'argument -r is required for action run' 92 print(
'connectstr : ',connectstr)
93 print(
'normfactor : ',normfactor)
94 print(
'authpath : ',os.environ[
'CORAL_AUTH_PATH'])
95 print(
'runnumber : ',runnumber)
97 if args.action ==
'range':
101 startrun=args.startrun
103 raise 'argument -startrun is required for action range' 107 raise 'argument -endrun is required for action range' 109 print(
'connectstr : ',connectstr)
110 print(
'normfactor : ',normfactor)
111 print(
'authpath : ',os.environ[
'CORAL_AUTH_PATH'])
112 print(
'startrun : ',startrun)
113 print(
'endrun : ',endrun)
115 print(
'number of rows changed: ',n)
119 if __name__==
'__main__':
S & print(S &os, JobReport::InputFile const &f)
def calibrateRun(dbsession, normfactor, runnum)
def calibrateRange(dbsession, normfactor, startrun, endrun)