CMS 3D CMS Logo

Functions

applyCalibration Namespace Reference

Functions

def calibrateRange
def calibrateRun
def main

Function Documentation

def applyCalibration::calibrateRange (   dbsession,
  normfactor,
  startrun,
  endrun 
)
update lumisummary set instlumi=instlumi*:norm where runnum>=:startrun and runnum<=:endrun

Definition at line 11 of file applyCalibration.py.

00012                                                         :
00013     '''
00014     update lumisummary set instlumi=instlumi*:norm where runnum>=:startrun and runnum<=:endrun
00015     '''
00016     try:
00017         dbsession.transaction().start(False)
00018         schema=dbsession.nominalSchema()
00019         if not schema:
00020             raise 'cannot connect to schema'
00021         if not schema.existsTable('LUMISUMMARY'):
00022             raise 'non-existing table LUMISUMMARY'
00023         inputData=coral.AttributeList()
00024         inputData.extend('normfactor','float')
00025         inputData['normfactor'].setData(float(normfactor))
00026         inputData.extend('startrun','unsigned int')
00027         inputData['startrun'].setData(int(startrun))
00028         inputData.extend('endrun','unsigned int')
00029         inputData['endrun'].setData(int(endrun))
00030         nchanged=schema.tableHandle('LUMISUMMARY').dataEditor().updateRows('INSTLUMI=INSTLUMI*:normfactor','RUNNUM>=:startrun AND RUNNUM<=:endrun',inputData)
00031         dbsession.transaction().commit()
00032         return nchanged
00033     except Exception,e:
00034         print str(e)
00035         dbsession.transaction().rollback()
        del dbsession
def applyCalibration::calibrateRun (   dbsession,
  normfactor,
  runnum 
)
update lumisummary set instlumi=instlumi*:norm where runnum=:run 

Definition at line 36 of file applyCalibration.py.

00037                                              :
00038     '''
00039     update lumisummary set instlumi=instlumi*:norm where runnum=:run 
00040     '''
00041     try:
00042         dbsession.transaction().start(False)
00043         schema=dbsession.nominalSchema()
00044         if not schema:
00045             raise 'cannot connect to schema'
00046         if not schema.existsTable('LUMISUMMARY'):
00047             raise 'non-existing table LUMISUMMARY'
00048         inputData=coral.AttributeList()
00049         inputData.extend('normfactor','float')
00050         inputData['normfactor'].setData(float(normfactor))
00051         inputData.extend('runnumber','unsigned int')
00052         inputData['runnumber'].setData(int(runnum))
00053         nchanged=schema.tableHandle('LUMISUMMARY').dataEditor().updateRows('INSTLUMI=INSTLUMI*:normfactor','RUNNUM=:runnumber',inputData)
00054         dbsession.transaction().commit()
00055         return nchanged
00056     except Exception,e:
00057         print str(e)
00058         dbsession.transaction().rollback()
00059         del dbsession
        
def applyCalibration::main ( )

Definition at line 60 of file applyCalibration.py.

00061           :
00062     parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="apply normalization factor to inst lumi")
00063     parser.add_argument('-c',dest='connectstr',action='store',required=True,help='connectstr')
00064     parser.add_argument('-norm',dest='normfactor',action='store',required=True,help='normalization factor to apply')
00065     parser.add_argument('-P',dest='authpath',action='store',required=True,help='path to authentication file')
00066     parser.add_argument('-r',dest='runnumber',action='store',required=False,help='run number')
00067     parser.add_argument('-startrun',dest='startrun',action='store',required=False,help='start run for range action')
00068     parser.add_argument('-endrun',dest='endrun',action='store',required=False,help='end run for range action')
00069     parser.add_argument('action',choices=['run','range'],help='calibrate run')
00070     
00071     parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
00072     args=parser.parse_args()
00073     connectstr=args.connectstr
00074     normfactor=args.normfactor
00075     if len(args.authpath)!=0:
00076         os.environ['CORAL_AUTH_PATH']=args.authpath
00077     else:
00078         raise '-P authpath argument is required'
00079     svc=coral.ConnectionService()
00080     session=svc.connect(connectstr,accessMode=coral.access_Update)
00081     if args.debug:
00082         msg=coral.MessageStream('')
00083         msg.setMsgVerbosity(coral.message_Level_Debug)
00084     n=0
00085     if args.action == 'run':
00086         runnumber=0
00087         if args.runnumber:
00088             runnumber=args.runnumber
00089         else:
00090             raise 'argument -r is required for action run'
00091         if args.debug:
00092             print 'connectstr : ',connectstr
00093             print 'normfactor : ',normfactor
00094             print 'authpath : ',os.environ['CORAL_AUTH_PATH']
00095             print 'runnumber : ',runnumber
00096         n=calibrateRun(session,normfactor,runnumber)
00097     if args.action == 'range':
00098         startrun=0
00099         endrun=0
00100         if args.startrun:
00101             startrun=args.startrun
00102         else:
00103             raise 'argument -startrun is required for action range'
00104         if args.endrun:
00105             endrun=args.endrun
00106         else:
00107             raise 'argument -endrun is required for action range'
00108         if args.debug:
00109             print 'connectstr : ',connectstr
00110             print 'normfactor : ',normfactor
00111             print 'authpath : ',os.environ['CORAL_AUTH_PATH']
00112             print 'startrun : ',startrun
00113             print 'endrun : ',endrun
00114         n=calibrateRange(session,normfactor,startrun,endrun)
00115     print 'number of rows changed: ',n
00116     del session
00117     del svc