10 from RecoLuminosity.LumiDB
import argparse
13 update lumisummary set instlumi=instlumi*:norm where runnum>=:startrun and runnum<=:endrun 16 dbsession.transaction().
start(
False)
17 schema=dbsession.nominalSchema()
19 raise 'cannot connect to schema' 20 if not schema.existsTable(
'LUMISUMMARY'):
21 raise 'non-existing table LUMISUMMARY' 22 inputData=coral.AttributeList()
23 inputData.extend(
'normfactor',
'float')
24 inputData[
'normfactor'].setData(
float(normfactor))
25 inputData.extend(
'startrun',
'unsigned int')
26 inputData[
'startrun'].setData(
int(startrun))
27 inputData.extend(
'endrun',
'unsigned int')
28 inputData[
'endrun'].setData(
int(endrun))
29 nchanged=schema.tableHandle(
'LUMISUMMARY').dataEditor().updateRows(
'INSTLUMI=INSTLUMI*:normfactor',
'RUNNUM>=:startrun AND RUNNUM<=:endrun',inputData)
30 dbsession.transaction().commit()
32 except Exception
as e:
34 dbsession.transaction().rollback()
38 update lumisummary set instlumi=instlumi*:norm where runnum=:run 41 dbsession.transaction().
start(
False)
42 schema=dbsession.nominalSchema()
44 raise 'cannot connect to schema' 45 if not schema.existsTable(
'LUMISUMMARY'):
46 raise 'non-existing table LUMISUMMARY' 47 inputData=coral.AttributeList()
48 inputData.extend(
'normfactor',
'float')
49 inputData[
'normfactor'].setData(
float(normfactor))
50 inputData.extend(
'runnumber',
'unsigned int')
51 inputData[
'runnumber'].setData(
int(runnum))
52 nchanged=schema.tableHandle(
'LUMISUMMARY').dataEditor().updateRows(
'INSTLUMI=INSTLUMI*:normfactor',
'RUNNUM=:runnumber',inputData)
53 dbsession.transaction().commit()
55 except Exception
as e:
57 dbsession.transaction().rollback()
61 parser =
argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description=
"apply normalization factor to inst lumi")
62 parser.add_argument(
'-c',dest=
'connectstr',action=
'store',required=
True,help=
'connectstr')
63 parser.add_argument(
'-norm',dest=
'normfactor',action=
'store',required=
True,help=
'normalization factor to apply')
64 parser.add_argument(
'-P',dest=
'authpath',action=
'store',required=
True,help=
'path to authentication file')
65 parser.add_argument(
'-r',dest=
'runnumber',action=
'store',required=
False,help=
'run number')
66 parser.add_argument(
'-startrun',dest=
'startrun',action=
'store',required=
False,help=
'start run for range action')
67 parser.add_argument(
'-endrun',dest=
'endrun',action=
'store',required=
False,help=
'end run for range action')
68 parser.add_argument(
'action',choices=[
'run',
'range'],help=
'calibrate run')
70 parser.add_argument(
'--debug',dest=
'debug',action=
'store_true',help=
'debug')
71 args=parser.parse_args()
72 connectstr=args.connectstr
73 normfactor=args.normfactor
74 if len(args.authpath)!=0:
75 os.environ[
'CORAL_AUTH_PATH']=args.authpath
77 raise '-P authpath argument is required' 78 svc=coral.ConnectionService()
79 session=svc.connect(connectstr,accessMode=coral.access_Update)
81 msg=coral.MessageStream(
'')
82 msg.setMsgVerbosity(coral.message_Level_Debug)
84 if args.action ==
'run':
87 runnumber=args.runnumber
89 raise 'argument -r is required for action run' 91 print 'connectstr : ',connectstr
92 print 'normfactor : ',normfactor
93 print 'authpath : ',os.environ[
'CORAL_AUTH_PATH']
94 print 'runnumber : ',runnumber
96 if args.action ==
'range':
100 startrun=args.startrun
102 raise 'argument -startrun is required for action range' 106 raise 'argument -endrun is required for action range' 108 print 'connectstr : ',connectstr
109 print 'normfactor : ',normfactor
110 print 'authpath : ',os.environ[
'CORAL_AUTH_PATH']
111 print 'startrun : ',startrun
112 print 'endrun : ',endrun
114 print 'number of rows changed: ',n
118 if __name__==
'__main__':
def calibrateRun(dbsession, normfactor, runnum)
def calibrateRange(dbsession, normfactor, startrun, endrun)