Exemple #1
0
def main():
    from RecoLuminosity.LumiDB import sessionManager,queryDataSource    
    parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="migrate lumidb schema",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('-c',dest='connect',action='store',required=False,default='oracle://devdb10/cms_xiezhen_dev',help='connect string to dest db(required)')
    parser.add_argument('-lumisource',dest='lumisource',action='store',required=False,default='oracle://cms_orcoff_prod/CMS_LUMI_PROD',help='connect string to source lumi db')
    #parser.add_argument('-runinfo',dest='runinfo',action='store',required=False,default='oracle://cms_orcoff_prod/CMS_RUNINFO',help='connect string to runinfo db')
    parser.add_argument('-P',dest='authpath',action='store',required=False,default='/afs/cern.ch/user/x/xiezhen',help='path to authentication file')
    parser.add_argument('-r',dest='runnumber',action='store',required=True,help='run number')
    parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
    args=parser.parse_args()
    runnumber=int(args.runnumber)
    print('processing run ',runnumber)
    #runinfosvc=sessionManager.sessionManager(args.runinfo,authpath=args.authpath,debugON=args.debug)
    lumisvc=sessionManager.sessionManager(args.lumisource,authpath=args.authpath,debugON=args.debug)
    destsvc=sessionManager.sessionManager(args.connect,authpath=args.authpath,debugON=args.debug)    
    #runinfosession=runinfosvc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    
    lumisession=lumisvc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    try:
        #[l1key,amodetag,egev,sequence,hltkey,fillnum,starttime,stoptime]=queryDataSource.runsummary(runinfosession,'CMS_RUNINFO',runnumber,complementalOnly=False)
        #print 'runsummary ',[l1key,amodetag,egev,sequence,hltkey,fillnum,starttime,stoptime]
        lumidata=queryDataSource.uncalibratedlumiFromOldLumi(lumisession,runnumber)
       #print 'lumidata ',lumidata
        [bitnames,trglsdata]=queryDataSource.trgFromOldLumi(lumisession,runnumber)
       #print 'trg data ',bitnames,trglsdata 
        [pathnames,hltlsdata]=queryDataSource.hltFromOldLumi(lumisession,runnumber)
       #print 'hlt data ',pathnames,hltlsdata
        lumisession.transaction().commit()
        #runinfosession.transaction().commit()
        del lumisession
        del lumisvc
        #del runinfosession
        #del runinfosvc
        destsession=destsvc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
        destsession.transaction().start(False)
        branchrevision_id=DATABRANCH_ID
        #print 'data branchid ',branchrevision_id
        #dataDML.insertRunSummaryData(destsession.nominalSchema(),runnumber,[l1key,amodetag,egev,sequence,hltkey,fillnum,starttime,stoptime],complementalOnly=False)
        (lumirevid,lumientryid,lumidataid)=dataDML.addLumiRunDataToBranch(destsession.nominalSchema(),runnumber,[args.lumisource],(branchrevision_id,'DATA'))
        bitzeroname=bitnames.split(',')[0]
        trgrundata=[args.lumisource,bitzeroname,bitnames]
        (trgrevid,trgentryid,trgdataid)=dataDML.addTrgRunDataToBranch(destsession.nominalSchema(),runnumber,trgrundata,(branchrevision_id,'DATA'))
        hltrundata=[pathnames,args.lumisource]
        (hltrevid,hltentryid,hltdataid)=dataDML.addHLTRunDataToBranch(destsession.nominalSchema(),runnumber,hltrundata,(branchrevision_id,'DATA'))
        destsession.transaction().commit()
        dataDML.bulkInsertLumiLSSummary(destsession,runnumber,lumidataid,lumidata,500)
        #
        dataDML.bulkInsertTrgLSData(destsession,runnumber,trgdataid,trglsdata,500)
        dataDML.bulkInsertHltLSData(destsession,runnumber,hltdataid,hltlsdata,500)
        del destsession
        del destsvc
    except:
        raise
def lumi_context(action, runs_lumis):
    svc = sessionManager.sessionManager('frontier://LumiCalc/CMS_LUMI_PROD')
    session = svc.openSession(isReadOnly=True, cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    session.transaction().start(True)

    datatagid, datatagname = revisionDML.currentDataTag(session.nominalSchema())
    dataidmap = revisionDML.dataIdsByTagId(session.nominalSchema(), datatagid, runlist=runs_lumis.keys(), withcomment=False)
    assert dataidmap

    session.transaction().commit()

    if action == 'trgbyls':
        session.transaction().start(True)
        result = lumiCalcAPI.trgForIds(session.nominalSchema(), runs_lumis, dataidmap, trgbitname=None, trgbitnamepattern='*', withL1Count=False, withPrescale=True)
        session.transaction().commit()
    elif action == 'hltbyls':
        session.transaction().start(True)
        result = lumiCalcAPI.hltForIds(session.nominalSchema(), runs_lumis, dataidmap, hltpathname=None, hltpathpattern='*', withL1Pass=False, withHLTAccept=False)
        session.transaction().commit()
    elif action == 'hltmenu':
        session.transaction().start(True)
        result = lumiCalcAPI.hltpathsForRange(session.nominalSchema(), runs_lumis, hltpathname=None, hltpathpattern='*')
        session.transaction().commit()
    del session
    del svc

    return result
Exemple #3
0
def main(*args):
    parser = argparse.ArgumentParser(
        prog=os.path.basename(sys.argv[0]),
        description="Patch HLT prescale from text file",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    allowedActions = ['v2']
    parser.add_argument('action',
                        choices=allowedActions,
                        help='command actions')
    parser.add_argument('-c',
                        dest='connect',
                        action='store',
                        required=True,
                        help='connect string to lumiDB,optional',
                        default=None)
    parser.add_argument('-P',
                        dest='authpath',
                        action='store',
                        required=True,
                        help='path to authentication file')
    parser.add_argument('-i',
                        dest='ifile',
                        action='store',
                        required=True,
                        help='patch data file ')
    parser.add_argument('-lsmin',
                        dest='lsmin',
                        action='store',
                        default=1,
                        required=False,
                        help='minimum ls to patch')
    parser.add_argument('-lsmax',
                        dest='lsmax',
                        action='store',
                        default=None,
                        required=False,
                        help='max ls to patch')
    parser.add_argument('--debug',
                        dest='debug',
                        action='store_true',
                        required=False,
                        help='debug ')
    options = parser.parse_args()
    (runnum, lsboundaries, pathinfo) = parseInfile(options.ifile)
    (pathnames, dataresult) = parsepresc(pathinfo, options.lsmin,
                                         options.lsmax, lsboundaries)
    print pathnames
    os.environ['CORAL_AUTH_PATH'] = options.authpath
    msg = coral.MessageStream('')
    msg.setMsgVerbosity(coral.message_Level_Error)
    svc = sessionManager.sessionManager(options.connect,
                                        authpath=options.authpath,
                                        debugON=options.debug)
    dbsession = svc.openSession(isReadOnly=False,
                                cpp2sqltype=[('unsigned int', 'NUMBER(10)'),
                                             ('unsigned long long',
                                              'NUMBER(20)')])
    patchV2(dbsession, runnum, pathnames, dataresult)
    del dbsession
    del svc
Exemple #4
0
def main():
    parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="list lumi data availability")
    # add required arguments
    parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
    # add optional arguments
    parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file')
    parser.add_argument('-siteconfpath',dest='siteconfpath',action='store',
			default=None,
                        required=False,
			help='specific path to site-local-config.xml file, optional. If path undefined, fallback to cern proxy&server')
    parser.add_argument('action',choices=['listrun'],help='command actions')
    parser.add_argument('--minrun',
			dest='minrun',
			action='store',
			type=int,
			help='min run number')
    parser.add_argument('--maxrun',
			dest='maxrun',
			action='store',
			type=int,
			help='max run number')
    parser.add_argument('--minfill',
			dest='minfill',
			type=int,
			action='store',
			help='min fill number')
    parser.add_argument('--maxfill',
			dest='maxfill',
			type=int,
			action='store',
			help='max fill number')
    parser.add_argument('--verbose',
			dest='verbose',
			action='store_true',
			help='verbose mode for printing' )
    parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
    # parse arguments
    options=parser.parse_args()
    if options.authpath:
        os.environ['CORAL_AUTH_PATH'] = options.authpath
    svc=sessionManager.sessionManager(options.connect,authpath=options.authpath,debugON=options.debug)
    session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    reqTrg=True
    reqHLT=False
    session.transaction().start(True)
    schema=session.nominalSchema()
    runlist=lumiCalcAPI.runList(schema,None,runmin=options.minrun,runmax=options.maxrun,startT=None,stopT=None,l1keyPattern=None,hltkeyPattern=None,amodetag=None,nominalEnergy=None,energyFlut=None,requiretrg=reqTrg,requirehlt=reqHLT)
    session.transaction().commit()
    if options.action == 'listrun':
	    if not runlist:
	        print '[]'
		sys.exit(0)
	    singlelist=listRemoveDuplicate(runlist)
	    singlelist.sort()
	    print singlelist
    del session
    del svc
Exemple #5
0
def main(*args):
    parser = argparse.ArgumentParser(
        prog=os.path.basename(sys.argv[0]),
        description="Lumi fake",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    allowedActions = ['v2']
    parser.add_argument('action',
                        choices=allowedActions,
                        help='command actions')
    parser.add_argument('-c',
                        dest='connect',
                        action='store',
                        required=True,
                        help='connect string to lumiDB,optional',
                        default=None)
    parser.add_argument('-P',
                        dest='authpath',
                        action='store',
                        required=True,
                        help='path to authentication file')
    parser.add_argument('-r',
                        dest='runnumber',
                        action='store',
                        type=int,
                        required=True,
                        help='run number')
    parser.add_argument('-i',
                        dest='ifile',
                        action='store',
                        required=True,
                        help='patch data file ')
    parser.add_argument('--debug',
                        dest='debug',
                        action='store_true',
                        required=False,
                        help='debug ')
    options = parser.parse_args()
    os.environ['CORAL_AUTH_PATH'] = options.authpath
    perlsrawdata = parseInputFile(options.ifile)
    print(perlsrawdata)
    msg = coral.MessageStream('')
    msg.setMsgVerbosity(coral.message_Level_Error)
    svc = sessionManager.sessionManager(options.connect,
                                        authpath=options.authpath,
                                        debugON=options.debug)
    dbsession = svc.openSession(isReadOnly=False,
                                cpp2sqltype=[('unsigned int', 'NUMBER(10)'),
                                             ('unsigned long long',
                                              'NUMBER(20)')])
    if options.action == 'v2':
        updateLSTrg(dbsession, options.runnumber, perlsrawdata)
    #elif options.action=='v1' :
    #    summaryidlsmap=insertLumiSummarydata(dbsession,options.runnumber,perlsrawdata,deliveredonly=options.deliveredonly)
    #    if perbunchrawdata:
    #        insertLumiDetaildata(dbsession,perlsrawdata,perbunchrawdata,summaryidlsmap)
    del dbsession
    del svc
Exemple #6
0
def recordedInvMicrobarns(json) :
    jsonALT = dict([(int(run),sum([range(begin,end+1) for begin,end in lumis],[])) for run,lumis in json.items()])

    session = sessionManager.sessionManager("frontier://LumiCalc/CMS_LUMI_PROD").openSession( cpp2sqltype = [('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    session.transaction().start(True)
    lumidata = lumiCalcAPI.lumiForRange( session.nominalSchema(),
                                         jsonALT,
                                         norm = 1.0,
                                         finecorrections = lumiCorrections.pixelcorrectionsForRange(session.nominalSchema(),jsonALT.keys()),
                                         lumitype='PIXEL',
                                         branchName='DATA')
    return sum( sum(data[6] for data in lumis) for run,lumis in lumidata.iteritems() if lumis)
def lumi_context(action, runs_lumis):
    svc = sessionManager.sessionManager('frontier://LumiCalc/CMS_LUMI_PROD')
    session = svc.openSession(isReadOnly=True,
                              cpp2sqltype=[('unsigned int', 'NUMBER(10)'),
                                           ('unsigned long long', 'NUMBER(20)')
                                           ])
    session.transaction().start(True)

    datatagid, datatagname = revisionDML.currentDataTag(
        session.nominalSchema())
    dataidmap = revisionDML.dataIdsByTagId(session.nominalSchema(),
                                           datatagid,
                                           runlist=runs_lumis.keys(),
                                           withcomment=False)
    assert dataidmap

    session.transaction().commit()

    if action == 'trgbyls':
        session.transaction().start(True)
        result = lumiCalcAPI.trgForIds(session.nominalSchema(),
                                       runs_lumis,
                                       dataidmap,
                                       trgbitname=None,
                                       trgbitnamepattern='*',
                                       withL1Count=False,
                                       withPrescale=True)
        session.transaction().commit()
    elif action == 'hltbyls':
        session.transaction().start(True)
        result = lumiCalcAPI.hltForIds(session.nominalSchema(),
                                       runs_lumis,
                                       dataidmap,
                                       hltpathname=None,
                                       hltpathpattern='*',
                                       withL1Pass=False,
                                       withHLTAccept=False)
        session.transaction().commit()
    elif action == 'hltmenu':
        session.transaction().start(True)
        result = lumiCalcAPI.hltpathsForRange(session.nominalSchema(),
                                              runs_lumis,
                                              hltpathname=None,
                                              hltpathpattern='*')
        session.transaction().commit()
    del session
    del svc

    return result
Exemple #8
0
def main(*args):
    parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "Lumi fake",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    allowedActions = ['v1', 'v2']
    parser.add_argument('action',choices=allowedActions,
                        help='command actions')
    parser.add_argument('-c',dest='connect',action='store',
                        required=True,
                        help='connect string to lumiDB,optional',
                        default=None)
    parser.add_argument('-P',dest='authpath',action='store',
                        required=True,
                        help='path to authentication file')
    parser.add_argument('-r',dest='runnumber',action='store',
                        type=int,
                        required=True,
                        help='run number')
    parser.add_argument('-isummary',dest='summaryfile',action='store',
                        required=True,
                        help='lumi summary file ')
    parser.add_argument('-idetail',dest='detailfile',action='store',
                        required=False,
                        help='lumi detail file ')
    parser.add_argument('--delivered-only',dest='deliveredonly',action='store_true',
                        help='without fine correction on calibration' )
    #
    parser.add_argument('--debug',dest='debug',action='store_true',
                        help='debug')
    options=parser.parse_args()
    os.environ['CORAL_AUTH_PATH'] = options.authpath
        
    perlsrawdata=parseLSFile(options.summaryfile)
    print perlsrawdata
    perbunchrawdata={}
    if options.detailfile:
        perbunchrawdata=parsebunchFile(options.detailfile)
        print sum(perbunchrawdata.values())
    msg=coral.MessageStream('')
    msg.setMsgVerbosity(coral.message_Level_Error)
    svc=sessionManager.sessionManager(options.connect,authpath=options.authpath,debugON=options.debug)
    dbsession=svc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    if options.action=='v2':
        insertLumischemaV2(dbsession,options.runnumber,options.summaryfile,perlsrawdata,perbunchrawdata,deliveredonly=options.deliveredonly)
    elif options.action=='v1' :
        summaryidlsmap=insertLumiSummarydata(dbsession,options.runnumber,perlsrawdata,deliveredonly=options.deliveredonly)
        if perbunchrawdata:
            insertLumiDetaildata(dbsession,perlsrawdata,perbunchrawdata,summaryidlsmap)
    del dbsession
    del svc
Exemple #9
0
def main(*args):
    parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "Lumi fake",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('-c',dest='connect',action='store',
                        required=True,
                        help='connect string to lumiDB,optional',
                        default=None)
    parser.add_argument('-P',dest='authpath',action='store',
                        required=True,
                        help='path to authentication file')
    parser.add_argument('-r',dest='runnumber',action='store',
                        type=int,
                        required=True,
                        help='run number')
    parser.add_argument('-isummary',dest='summaryfile',action='store',
                        required=True,
                        help='lumi summary file ')
    parser.add_argument('-idetail',dest='detailfile',action='store',
                        required=False,
                        help='lumi detail file ')
    parser.add_argument('--delivered-only',dest='deliveredonly',action='store_true',
                        help='without trigger' )
    #
    parser.add_argument('--debug',dest='debug',action='store_true',
                        help='debug')
    options=parser.parse_args()
    os.environ['CORAL_AUTH_PATH'] = options.authpath
        
    perlsrawdata=parseLSFile(options.summaryfile)
    
    #print perlsrawdata
    perbunchrawdata={}
    bxdistribution={}
    msg=coral.MessageStream('')
    msg.setMsgVerbosity(coral.message_Level_Error)
    svc=sessionManager.sessionManager(options.connect,authpath=options.authpath,debugON=options.debug)
    dbsession=svc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    dbsession.transaction().start(True)
    oldlumidataid=dataDML.guessLumiDataIdByRunInBranch(dbsession.nominalSchema(),options.runnumber,'LUMIDATA','DATA')
    if oldlumidataid:
        perbunchrawdata=fetchOldData(dbsession.nominalSchema(),oldlumidataid)
    elif options.detailfile:
        bxdistribution=parsebunchFile(options.detailfile)
    dbsession.transaction().commit()
    #print perlsrawdata
    #print perbunchrawdata
    insertLumischemaV2(dbsession,options.runnumber,options.summaryfile,perlsrawdata,perbunchrawdata,bxdistribution,deliveredonly=options.deliveredonly)
    del dbsession
    del svc
Exemple #10
0
def main(*args):
    parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "Lumi fake",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('-c',dest='connect',action='store',
                        required=True,
                        help='connect string to lumiDB,optional',
                        default=None)
    parser.add_argument('-P',dest='authpath',action='store',
                        required=True,
                        help='path to authentication file')
    parser.add_argument('-r',dest='runnumber',action='store',
                        type=int,
                        required=True,
                        help='run number')
    parser.add_argument('-isummary',dest='summaryfile',action='store',
                        required=True,
                        help='lumi summary file ')
    parser.add_argument('-idetail',dest='detailfile',action='store',
                        required=False,
                        help='lumi detail file ')
    parser.add_argument('--delivered-only',dest='deliveredonly',action='store_true',
                        help='without trigger' )
    #
    parser.add_argument('--debug',dest='debug',action='store_true',
                        help='debug')
    options=parser.parse_args()
    os.environ['CORAL_AUTH_PATH'] = options.authpath
        
    perlsrawdata=parseLSFile(options.summaryfile)
    
    #print perlsrawdata
    perbunchrawdata={}
    bxdistribution={}
    msg=coral.MessageStream('')
    msg.setMsgVerbosity(coral.message_Level_Error)
    svc=sessionManager.sessionManager(options.connect,authpath=options.authpath,debugON=options.debug)
    dbsession=svc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    dbsession.transaction().start(True)
    oldlumidataid=dataDML.guessLumiDataIdByRunInBranch(dbsession.nominalSchema(),options.runnumber,'LUMIDATA','DATA')
    if oldlumidataid:
        perbunchrawdata=fetchOldData(dbsession.nominalSchema(),oldlumidataid)
    elif options.detailfile:
        bxdistribution=parsebunchFile(options.detailfile)
    dbsession.transaction().commit()
    #print perlsrawdata
    #print perbunchrawdata
    insertLumischemaV2(dbsession,options.runnumber,options.summaryfile,perlsrawdata,perbunchrawdata,bxdistribution,deliveredonly=options.deliveredonly)
    del dbsession
    del svc
Exemple #11
0
def  main(*args):
    parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "Patch HLT prescale from text file",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    allowedActions = ['v2']
    parser.add_argument('action',choices=allowedActions,
                        help='command actions')
    parser.add_argument('-c',dest='connect',action='store',
                        required=True,
                        help='connect string to lumiDB,optional',
                        default=None)
    parser.add_argument('-P',dest='authpath',action='store',
                        required=True,
                        help='path to authentication file')
    parser.add_argument('-i',dest='ifile',action='store',
                        required=True,
                        help='patch data file ')
    parser.add_argument('-lsmin',dest='lsmin',action='store',
                        default=1,
                        required=False,
                        help='minimum ls to patch')
    parser.add_argument('-lsmax',dest='lsmax',action='store',
                        default=None,
                        required=False,
                        help='max ls to patch')
    parser.add_argument('--debug',dest='debug',action='store_true',
                        required=False,
                        help='debug ')
    options=parser.parse_args()
    (runnum,lsboundaries,pathinfo)=parseInfile(options.ifile)
    (pathnames,dataresult)=parsepresc(pathinfo,options.lsmin,options.lsmax,lsboundaries)
    print(pathnames)
    os.environ['CORAL_AUTH_PATH'] = options.authpath      
    msg=coral.MessageStream('')
    msg.setMsgVerbosity(coral.message_Level_Error)
    svc=sessionManager.sessionManager(options.connect,authpath=options.authpath,debugON=options.debug)
    dbsession=svc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    patchV2(dbsession,runnum,pathnames,dataresult)
    del dbsession
    del svc
Exemple #12
0
 if not options.begrun and not options.indir:
     print '[ERROR] must specify at least -b or -i'
     sys.exit(13)
 begrun = 0
 if options.begrun:
     begrun = options.begrun
 if options.indir and os.path.exists(options.indir) and os.path.isdir(
         options.indir):
     maxrunindir = findmaxrun(options.indir)
     if maxrunindir > begrun:
         begrun = maxrunindir
 if not begrun:
     print '[ERROR] cannot find the begin run'
     sys.exit(14)
 sourcesvc = sessionManager.sessionManager(options.sourcestr,
                                           authpath=options.pth,
                                           debugON=False)
 sourcesession = sourcesvc.openSession(isReadOnly=True,
                                       cpp2sqltype=[('unsigned int',
                                                     'NUMBER(10)'),
                                                    ('unsigned long long',
                                                     'NUMBER(20)')])
 sourcesession.transaction().start(True)
 sourcerunlist = getrunsInCurrentData(sourcesession.nominalSchema(),
                                      minrun=begrun,
                                      maxrun=options.endrun)
 sourcesession.transaction().commit()
 sourcerunlist.sort()
 #print 'source ',len(sourcerunlist),sourcerunlist
 destsvc = sessionManager.sessionManager(options.deststr,
                                         authpath=options.pth,
Exemple #13
0
         )
     if options.action in ['create', 'insert']:
         if not options.normfile:
             raise RuntimeError(
                 'argument -f normfile is required for insert action')
 if options.action in ['setdefault', 'unsetdefault']:
     if not options.lumitype:
         raise RuntimeError(
             'argument --lumitype lumitype is required for setdefault/unsetdefault action'
         )
     if not options.normname:
         raise RuntimeError(
             'argument --name normname is required for setdefault/unsetdefault action'
         )
 svc = sessionManager.sessionManager(options.connect,
                                     authpath=options.authpath,
                                     siteconfpath=options.siteconfpath)
 ############################################################
 #  create,insert
 ############################################################
 if options.action in ['create', 'insert']:
     dbsession = svc.openSession(isReadOnly=False,
                                 cpp2sqltype=[
                                     ('unsigned int', 'NUMBER(10)'),
                                     ('unsigned long long', 'NUMBER(20)')
                                 ])
     normfileparser = normFileParser.normFileParser(options.normfile)
     normdata = normfileparser.parse()
     normdefinitionDict = normdata[0]  #{defoption:value}
     normvalues = normdata[1]  #[{dataoption:value}]
     dbsession.transaction().start(False)
Exemple #14
0
def lumidb(run_lumi_dict, action='delivered', lumi_report=False):
    "Call lumidb to get luminosity numbers"
    actions = ['overview', 'delivered', 'recorded', 'lumibyls', 'lumibylsXing']
    if action not in actions:
        raise Exception('Unsupported action="%s", please check from %s' %
                        (action, actions))
    beamModeChoices = ['stable']
    amodetagChoices = ['PROTPHYS', 'IONPHYS', 'PAPHYS']
    xingAlgoChoices = ['OCC1', 'OCC2', 'ET']

    #
    # parse arguments
    #
    connect = 'frontier://LumiCalc/CMS_LUMI_PROD'
    authpath = None
    scalefactor = 1.0
    beamfluctuation = 0.2
    minbiasxsec = 69300.0  # minbias cross-secvtion in ub
    xingMinLum = 1e-03  # Minimum perbunch luminosity to print, default=1e-03/ub
    xingAlgo = 'OCC1'
    hltpath = None
    outputfile = None
    siteconfpath = None
    withoutNorm = False
    withoutCheckforupdate = False
    fillnum = None
    nowarning = True
    debug = False
    beamenergy = None
    amodetag = None
    reqrunmin = None
    reqfillmin = None
    reqtimemin = None
    reqrunmax = None
    reqfillmax = None
    reqtimemax = None
    timeFilter = [None, None]
    pbeammode = None
    iresults = []
    reqTrg = False
    reqHlt = False
    svc = sessionManager.sessionManager(connect,
                                        authpath,
                                        siteconfpath,
                                        debugON=debug)
    session = svc.openSession(isReadOnly=True,
                              cpp2sqltype=[('unsigned int', 'NUMBER(10)'),
                                           ('unsigned long long', 'NUMBER(20)')
                                           ])

    ##############################################################
    # check run/ls list
    ##############################################################
    irunlsdict = {}
    rruns = []
    session.transaction().start(True)
    irunlsdict = run_lumi_dict
    iresults = []
    runlist = lumiCalcAPI.runList(session.nominalSchema(),
                                  fillnum,
                                  runmin=reqrunmin,
                                  runmax=reqrunmax,
                                  fillmin=reqfillmin,
                                  fillmax=reqfillmax,
                                  startT=reqtimemin,
                                  stopT=reqtimemax,
                                  l1keyPattern=None,
                                  hltkeyPattern=None,
                                  amodetag=amodetag,
                                  nominalEnergy=beamenergy,
                                  energyFlut=beamfluctuation,
                                  requiretrg=False,
                                  requirehlt=False)
    rruns = [val for val in runlist if val in irunlsdict.keys()]
    for selectedrun in irunlsdict.keys(
    ):  #if there's further filter on the runlist,clean input dict
        if selectedrun not in rruns:
            del irunlsdict[selectedrun]
    ##############################################################
    # check datatag
    # #############################################################
    datatagid, datatagname = revisionDML.currentDataTag(
        session.nominalSchema())
    dataidmap=revisionDML.dataIdsByTagId(\
            session.nominalSchema(), datatagid,
            runlist=rruns, withcomment=False)
    session.transaction().commit()
    if not dataidmap:
        print_warning('No data found in LumiDB for given set run lumi section')
        return 0, '/ub'  # return lumi, units

    normvalueDict = {}
    ##################
    # ls level       #
    ##################
    session.transaction().start(True)
    GrunsummaryData = lumiCalcAPI.runsummaryMap(session.nominalSchema(),
                                                irunlsdict)
    if action == 'delivered':
        result = lumiCalcAPI.deliveredLumiForIds(session.nominalSchema(),
                                                 irunlsdict,
                                                 dataidmap,
                                                 runsummaryMap=GrunsummaryData,
                                                 beamstatusfilter=pbeammode,
                                                 timeFilter=timeFilter,
                                                 normmap=normvalueDict,
                                                 lumitype='HF')
        if lumi_report:
            lumiReport.toScreenTotDelivered(result,
                                            iresults,
                                            scalefactor,
                                            irunlsdict=irunlsdict,
                                            noWarning=nowarning,
                                            toFile=outputfile)

        # result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),calibratedlumierr(6),(bxidxlist,bxvalues,bxerrs)(7),(bxidx,b1intensities,b2intensities)(8),fillnum(9),pu(10)]}
        totlumi = 0
        for run, val in result.items():
            for llist in val:
                if irunlsdict[run]:
                    if llist[0] in irunlsdict[
                            run]:  # select only lumis from input run ls dict
                        totlumi += llist[5]
                else:
                    totlumi += llist[5]
        totlumival, lumiunit = CommonUtil.guessUnit(totlumi)
        return totlumival, lumiunit
    if action == 'overview':
        result = lumiCalcAPI.lumiForIds(session.nominalSchema(),
                                        irunlsdict,
                                        dataidmap,
                                        runsummaryMap=GrunsummaryData,
                                        beamstatusfilter=pbeammode,
                                        timeFilter=timeFilter,
                                        normmap=normvalueDict,
                                        lumitype='HF')
        lumiReport.toScreenOverview(result,
                                    iresults,
                                    scalefactor,
                                    irunlsdict=irunlsdict,
                                    noWarning=nowarning,
                                    toFile=outputfile)
    if action == 'lumibyls':
        if not hltpath:
            result = lumiCalcAPI.lumiForIds(session.nominalSchema(),
                                            irunlsdict,
                                            dataidmap,
                                            runsummaryMap=GrunsummaryData,
                                            beamstatusfilter=pbeammode,
                                            timeFilter=timeFilter,
                                            normmap=normvalueDict,
                                            lumitype='HF',
                                            minbiasXsec=minbiasxsec)
            lumiReport.toScreenLumiByLS(result,
                                        iresults,
                                        scalefactor,
                                        irunlsdict=irunlsdict,
                                        noWarning=nowarning,
                                        toFile=outputfile)
        else:
            hltname = hltpath
            hltpat = None
            if hltname == '*' or hltname == 'all':
                hltname = None
            elif 1 in [c in hltname for c in '*?[]']:  #is a fnmatch pattern
                hltpat = hltname
                hltname = None
            result = lumiCalcAPI.effectiveLumiForIds(
                session.nominalSchema(),
                irunlsdict,
                dataidmap,
                runsummaryMap=GrunsummaryData,
                beamstatusfilter=pbeammode,
                timeFilter=timeFilter,
                normmap=normvalueDict,
                hltpathname=hltname,
                hltpathpattern=hltpat,
                withBXInfo=False,
                bxAlgo=None,
                xingMinLum=xingMinLum,
                withBeamIntensity=False,
                lumitype='HF')
            lumiReport.toScreenLSEffective(result,
                                           iresults,
                                           scalefactor,
                                           irunlsdict=irunlsdict,
                                           noWarning=nowarning,
                                           toFile=outputfile)
    if action == 'recorded':  #recorded actually means effective because it needs to show all the hltpaths...
        hltname = hltpath
        hltpat = None
        if hltname is not None:
            if hltname == '*' or hltname == 'all':
                hltname = None
            elif 1 in [c in hltname for c in '*?[]']:  #is a fnmatch pattern
                hltpat = hltname
                hltname = None
        result = lumiCalcAPI.effectiveLumiForIds(session.nominalSchema(),
                                                 irunlsdict,
                                                 dataidmap,
                                                 runsummaryMap=GrunsummaryData,
                                                 beamstatusfilter=pbeammode,
                                                 timeFilter=timeFilter,
                                                 normmap=normvalueDict,
                                                 hltpathname=hltname,
                                                 hltpathpattern=hltpat,
                                                 withBXInfo=False,
                                                 bxAlgo=None,
                                                 xingMinLum=xingMinLum,
                                                 withBeamIntensity=False,
                                                 lumitype='HF')
        lumiReport.toScreenTotEffective(result,
                                        iresults,
                                        scalefactor,
                                        irunlsdict=irunlsdict,
                                        noWarning=nowarning,
                                        toFile=outputfile)
    if action == 'lumibylsXing':
        result = lumiCalcAPI.lumiForIds(session.nominalSchema(),
                                        irunlsdict,
                                        dataidmap,
                                        runsummaryMap=GrunsummaryData,
                                        beamstatusfilter=pbeammode,
                                        timeFilter=timeFilter,
                                        normmap=normvalueDict,
                                        withBXInfo=True,
                                        bxAlgo=xingAlgo,
                                        xingMinLum=xingMinLum,
                                        withBeamIntensity=False,
                                        lumitype='HF')
        outfile = outputfile
        if not outfile:
            print '[WARNING] no output file given. lumibylsXing writes per-bunch lumi only to default file lumibylsXing.csv'
            outfile = 'lumibylsXing.csv'
        lumiReport.toCSVLumiByLSXing(result,
                                     scalefactor,
                                     outfile,
                                     irunlsdict=irunlsdict,
                                     noWarning=nowarning)
    session.transaction().commit()
    del session
    del svc
Exemple #15
0
#!/usr/bin/env python
from __future__ import print_function

VERSION = '2.00'
import os, sys, array
import coral
from RecoLuminosity.LumiDB import sessionManager, dataDML, CommonUtil

DATABRANCH_ID = 3
if __name__ == '__main__':
    myconstr = 'oracle://cms_orcoff_prod/cms_lumi_prod'
    svc = sessionManager.sessionManager(myconstr,
                                        authpath='/afs/cern.ch/user/x/xiezhen',
                                        debugON=False)
    session = svc.openSession(isReadOnly=True,
                              cpp2sqltype=[('unsigned int', 'NUMBER(10)'),
                                           ('unsigned long long', 'NUMBER(20)')
                                           ])
    session.transaction().start(True)
    schema = session.nominalSchema()
    runs = dataDML.runList(schema,
                           fillnum=1616,
                           runmin=160403,
                           runmax=160957,
                           nominalEnergy=3500.0)
    print(runs)
    myrun = runs[0]
    runsummary = dataDML.runsummary(schema, myrun)
    print(runsummary)
    normid = dataDML.guessnormIdByContext(schema, 'PROTPHYS', 3500)
    normval = dataDML.luminormById(schema, normid)[2]
Exemple #16
0
 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')
 parser.add_argument('--debug',dest='debug',action='store_true',help='debug')
 options=parser.parse_args()
 if options.authpath:
     os.environ['CORAL_AUTH_PATH']=options.authpath
 #
 #pre-check
 #
 if options.action=='add':
     if not options.authpath:
         raise RuntimeError('argument -P authpath is required for add action')
     if not options.input:
         raise RuntimeError('argument -input input is required for add action')
     if not options.name:
         raise RuntimeError('argument -name name is required for add action')
 svc=sessionManager.sessionManager(options.connect,authpath=options.authpath,siteconfpath=options.siteconfpath)
 session=None
 
 if options.action=='add':
     session=svc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])        
     #
     # add norm factor
     #
     session.transaction().start(False)
     schema=session.nominalSchema()
     (revision_id,branch_id)=revisionDML.branchInfoByName(schema,'NORM')
     dataDML.addNormToBranch(schema,options.name,options.amodetag,float(options.input),int(options.egev),{},(revision_id,'NORM'))
     session.transaction().commit()
 elif options.action=='list':
     session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
     session.transaction().start(True)
        inputData['algomask_l'].setData(algo_l)
        inputData['techmask'].setData(tech)
        inputData['runnum'].setData(runnum)
        r = db.singleUpdate(nameDealer.trgdataTableName(), setClause,
                            updateCondition, inputData)
        if r > 0:
            print 'updated'


if __name__ == '__main__':
    #pth='/afs/cern.ch/user/l/lumipro/'
    pth = '/nfshome0/xiezhen/authwriter'
    #sourcestr='oracle://cms_orcon_adg/cms_gt'
    sourcestr = 'oracle://cms_omds_lb/cms_gt'
    sourcesvc = sessionManager.sessionManager(sourcestr,
                                              authpath=pth,
                                              debugON=False)
    sourcesession = sourcesvc.openSession(isReadOnly=True,
                                          cpp2sqltype=[('short', 'NUMBER(1)'),
                                                       ('unsigned int',
                                                        'NUMBER(10)'),
                                                       ('unsigned long long',
                                                        'NUMBER(20)')])

    #deststr='oracle://cms_orcoff_prep/cms_lumi_dev_offline'
    deststr = 'oracle://cms_orcon_prod/cms_lumi_prod'
    destsvc = sessionManager.sessionManager(deststr,
                                            authpath=pth,
                                            debugON=False)
    destsession = destsvc.openSession(isReadOnly=False,
                                      cpp2sqltype=[
Exemple #18
0
def lumidb(run_lumi_dict, action='delivered', lumi_report=False):
    "Call lumidb to get luminosity numbers"
    actions  = ['overview', 'delivered', 'recorded', 'lumibyls', 'lumibylsXing']
    if  action not in actions:
        raise Exception('Unsupported action="%s", please check from %s' % (action, actions))
    beamModeChoices = ['stable']
    amodetagChoices = ['PROTPHYS', 'IONPHYS', 'PAPHYS' ]
    xingAlgoChoices = ['OCC1', 'OCC2', 'ET']

    #
    # parse arguments
    #  
    connect='frontier://LumiCalc/CMS_LUMI_PROD'
    authpath = None
    scalefactor = 1.0
    beamfluctuation = 0.2
    minbiasxsec = 69300.0 # minbias cross-secvtion in ub
    xingMinLum = 1e-03 # Minimum perbunch luminosity to print, default=1e-03/ub
    xingAlgo = 'OCC1'
    hltpath = None
    outputfile = None
    siteconfpath = None
    withoutNorm = False
    withoutCheckforupdate = False
    fillnum = None
    nowarning = True
    debug = False
    beamenergy = None
    amodetag = None
    reqrunmin=None
    reqfillmin=None
    reqtimemin=None
    reqrunmax=None
    reqfillmax=None
    reqtimemax=None
    timeFilter=[None,None]
    pbeammode = None
    iresults=[]
    reqTrg=False
    reqHlt=False
    svc = sessionManager.sessionManager(connect, authpath, siteconfpath, debugON=debug)
    session=svc.openSession(isReadOnly=True,
            cpp2sqltype=[('unsigned int', 'NUMBER(10)'), ('unsigned long long', 'NUMBER(20)')])

    ##############################################################
    # check run/ls list
    ##############################################################
    irunlsdict={}
    rruns=[]
    session.transaction().start(True)
    irunlsdict = run_lumi_dict
    iresults = []
    runlist=lumiCalcAPI.runList(session.nominalSchema(),
            fillnum, runmin=reqrunmin, runmax=reqrunmax,
            fillmin=reqfillmin, fillmax=reqfillmax,
            startT=reqtimemin, stopT=reqtimemax,
            l1keyPattern=None, hltkeyPattern=None,
            amodetag=amodetag, nominalEnergy=beamenergy,
            energyFlut=beamfluctuation,
            requiretrg=False, requirehlt=False)
    rruns = [val for val in runlist if val in irunlsdict.keys()]
    for selectedrun in irunlsdict.keys():#if there's further filter on the runlist,clean input dict
        if selectedrun not in rruns:
            del irunlsdict[selectedrun]
    ##############################################################
    # check datatag
    # #############################################################       
    datatagid, datatagname = revisionDML.currentDataTag(session.nominalSchema())
    dataidmap=revisionDML.dataIdsByTagId(\
            session.nominalSchema(), datatagid,
            runlist=rruns, withcomment=False)
    session.transaction().commit()
    if not dataidmap:
        print_warning('No data found in LumiDB for given set run lumi section')
        return 0, '/ub' # return lumi, units
                
    normvalueDict={}
    ##################
    # ls level       #
    ##################
    session.transaction().start(True)
    GrunsummaryData=lumiCalcAPI.runsummaryMap(session.nominalSchema(),irunlsdict)
    if  action == 'delivered':
        result=lumiCalcAPI.deliveredLumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,lumitype='HF')
        if  lumi_report:
            lumiReport.toScreenTotDelivered(result,iresults,scalefactor,irunlsdict=irunlsdict,noWarning=nowarning,toFile=outputfile)

        # result {run:[lumilsnum(0),cmslsnum(1),timestamp(2),beamstatus(3),beamenergy(4),deliveredlumi(5),calibratedlumierr(6),(bxidxlist,bxvalues,bxerrs)(7),(bxidx,b1intensities,b2intensities)(8),fillnum(9),pu(10)]}
        totlumi = 0
        for run, val in result.items():
            for llist in val:
                if  irunlsdict[run]:
                    if  llist[0] in irunlsdict[run]: # select only lumis from input run ls dict
                        totlumi += llist[5]
                else:
                    totlumi += llist[5]
        totlumival, lumiunit = CommonUtil.guessUnit(totlumi)
        return totlumival, lumiunit
    if  action == 'overview':
        result=lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,lumitype='HF')
        lumiReport.toScreenOverview(result,iresults,scalefactor,irunlsdict=irunlsdict,noWarning=nowarning,toFile=outputfile)
    if  action == 'lumibyls':
        if not hltpath:
            result=lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,lumitype='HF',minbiasXsec=minbiasxsec)
            lumiReport.toScreenLumiByLS(result,iresults,scalefactor,irunlsdict=irunlsdict,noWarning=nowarning,toFile=outputfile)            
        else:
            hltname=hltpath
            hltpat=None
            if hltname=='*' or hltname=='all':
                hltname=None
            elif 1 in [c in hltname for c in '*?[]']: #is a fnmatch pattern
                hltpat=hltname
                hltname=None
            result=lumiCalcAPI.effectiveLumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,hltpathname=hltname,hltpathpattern=hltpat,withBXInfo=False,bxAlgo=None,xingMinLum=xingMinLum,withBeamIntensity=False,lumitype='HF')
            lumiReport.toScreenLSEffective(result,iresults,scalefactor,irunlsdict=irunlsdict,noWarning=nowarning,toFile=outputfile)
    if  action == 'recorded':#recorded actually means effective because it needs to show all the hltpaths...
        hltname=hltpath
        hltpat=None
        if hltname is not None:
            if hltname=='*' or hltname=='all':
                hltname=None
            elif 1 in [c in hltname for c in '*?[]']: #is a fnmatch pattern
                hltpat=hltname
                hltname=None
        result=lumiCalcAPI.effectiveLumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,hltpathname=hltname,hltpathpattern=hltpat,withBXInfo=False,bxAlgo=None,xingMinLum=xingMinLum,withBeamIntensity=False,lumitype='HF')
        lumiReport.toScreenTotEffective(result,iresults,scalefactor,irunlsdict=irunlsdict,noWarning=nowarning,toFile=outputfile)
    if  action == 'lumibylsXing':
        result=lumiCalcAPI.lumiForIds(session.nominalSchema(),irunlsdict,dataidmap,runsummaryMap=GrunsummaryData,beamstatusfilter=pbeammode,timeFilter=timeFilter,normmap=normvalueDict,withBXInfo=True,bxAlgo=xingAlgo,xingMinLum=xingMinLum,withBeamIntensity=False,lumitype='HF')
        outfile=outputfile
        if  not outfile:
            print '[WARNING] no output file given. lumibylsXing writes per-bunch lumi only to default file lumibylsXing.csv'
            outfile='lumibylsXing.csv'           
        lumiReport.toCSVLumiByLSXing(result,scalefactor,outfile,irunlsdict=irunlsdict,noWarning=nowarning)
    session.transaction().commit()
    del session
    del svc 
Exemple #19
0
#!/usr/bin/env python
VERSION='2.00'
import os,sys,array
import coral
from RecoLuminosity.LumiDB import sessionManager,dataDML,CommonUtil
DATABRANCH_ID=3
if __name__=='__main__':
    myconstr='oracle://cms_orcoff_prod/cms_lumi_prod'
    svc=sessionManager.sessionManager(myconstr,authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
    session=svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    session.transaction().start(True)
    schema=session.nominalSchema()
    runs=dataDML.runList(schema,fillnum=1616,runmin=160403,runmax=160957,nominalEnergy=3500.0)
    print runs
    myrun=runs[0]
    runsummary=dataDML.runsummary(schema,myrun)
    print runsummary
    normid=dataDML.guessnormIdByContext(schema,'PROTPHYS',3500)
    normval=dataDML.luminormById(schema,normid)[2]
    print 'norm in use ',normval
    (lumidataid,trgdataid,hltdataid)=dataDML.guessDataIdByRun(schema,myrun)
    print 'all dataids ',lumidataid,trgdataid,hltdataid
    (runnum,lumiLSdata)=dataDML.lumiLSById(schema,lumidataid)
    
    lumils=lumiLSdata.keys()
    lumils.sort()
    for lsnum in lumils:
        print 'lumilsnum,cmslsnum,instlumi ',lsnum,lumiLSdata[lsnum][0],lumiLSdata[lsnum][1]*normval
        
    (runnum,trgLSdata)=dataDML.trgLSById(schema,trgdataid)
    cmsls=trgLSdata.keys()
Exemple #20
0
            print('[DEBUG] diff in number of ls ',cmslsa,cmslsb)
            return True
        if beamstatusa!=beamstatusb:
            print('[DEBUG] diff in beamstatus ',beamstatusa,beamstatusb)
            return True
        if beamenergya!=beamenergyb:
            print('[DEBUG] diff in beamenergy ',beamenergya,beamenergyb)
            return True
        if abs(delivereda-deliveredb)>0.009:
            print('[DEBUG] diff in recorded ',delivereda,deliveredb)
            return True
        if abs(recordeda-recordedb)>0.009:
            print('[DEBUG] diff in recorded ',recordeda,recordedb)
            return True
        return False
if __name__ == "__main__" :
    allcsvfiles=glob.glob('??????.csv')
    sourcestr='oracle://cms_orcon_prod/cms_lumi_prod'
    pth='/nfshome0/xiezhen'
    sourcesvc=sessionManager.sessionManager(sourcestr,authpath=pth,debugON=False)
    sourcesession=sourcesvc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    sourcesession.transaction().start(True)
    for csvfile in allcsvfiles:
        runnum=int(csvfile.split('.')[0])
        dbresult=getresultfromdb(sourcesession.nominalSchema(),runnum)
        fileresult=parselumibylsfile(runnum,csvfile)
        diffresult=isdifferent(fileresult,dbresult)
        print(runnum,int(diffresult))
    sourcesession.transaction().commit()

Exemple #21
0
                     help='end LS to be replaced with file data'
                     )
 parser.add_argument('--comment',action='store',
                     required=False,
                     default='',
                     help='patch comment'
                    )
 parser.add_argument('--debug',dest='debug',action='store_true',
                     help='debug'
                     )
 options=parser.parse_args()
 begLS=int(options.begLS)
 endLS=int(options.endLS)
 inputfilename=os.path.abspath(options.inputfile)
 lumidatafromfile=lumiDataFromfile(inputfilename)
 sourcesvc=sessionManager.sessionManager(options.sourcestr,authpath=options.authpath,debugON=False)
 sourcesession=sourcesvc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
 sourcesession.transaction().start(True)
 qHandle=sourcesession.nominalSchema().newQuery()
 sourcetagid=0
 sourcelumiid=0
 try:
     qHandle.addToTableList( nameDealer.tagRunsTableName() )
     qHandle.addToOutputList('TAGID')
     qHandle.addToOutputList('LUMIDATAID')
     qCondition=coral.AttributeList()
     qCondition.extend('runnum','unsigned int')
     qCondition['runnum'].setData(int(options.runnum))
     qResult=coral.AttributeList()
     qResult.extend('TAGID','unsigned long long')
     qResult.extend('LUMIDATAID','unsigned long long')
Exemple #22
0
    return intlumiuptorun

if __name__=='__main__':
    parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "intlumiSum",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    # parse arguments
    parser.add_argument('-c',dest='connect',action='store',required=False,help='connect string to lumiDB',default='oracle://cms_orcon_prod/cms_lumi_prod')
    parser.add_argument('-P',dest='authpath',action='store',required=False,help='authentication.xml dir',default='/afs/cern.ch/cms/lumi')
    parser.add_argument('-i',dest='inputfile',action='store',required=False,help='input file full name',default='/afs/cern.ch/cms/lumi/pp7TeVstable-2011delivered-zerocorrection.csv')
    parser.add_argument('--dryrun',dest='dryrun',action='store_true',
                        help='only print pasing result')
    parser.add_argument('--debug',dest='debug',action='store_true',
                        help='debug mode')
    
    options=parser.parse_args()
    ifilename=options.inputfile
    irunlumimap= parselumifile(ifilename)
    intlumitorun=lumiuptorun(irunlumimap)
    if options.dryrun:
        print(intlumitorun)
        exit(0)
    if options.authpath:
        os.environ['CORAL_AUTH_PATH'] = options.authpath
    
    svc=sessionManager.sessionManager(options.connect,authpath=options.authpath,debugON=options.debug)
    session=svc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
    insertIntglumiData(session,intlumitorun,bulksize=1000)        
    del session
    del svc 

    
def main():
    from RecoLuminosity.LumiDB import sessionManager, queryDataSource
    parser = argparse.ArgumentParser(
        prog=os.path.basename(sys.argv[0]),
        description="migrate lumidb schema",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('-c',
                        dest='connect',
                        action='store',
                        required=False,
                        default='oracle://devdb10/cms_xiezhen_dev',
                        help='connect string to dest db(required)')
    parser.add_argument('-lumisource',
                        dest='lumisource',
                        action='store',
                        required=False,
                        default='oracle://cms_orcoff_prod/CMS_LUMI_PROD',
                        help='connect string to source lumi db')
    #parser.add_argument('-runinfo',dest='runinfo',action='store',required=False,default='oracle://cms_orcoff_prod/CMS_RUNINFO',help='connect string to runinfo db')
    parser.add_argument('-P',
                        dest='authpath',
                        action='store',
                        required=False,
                        default='/afs/cern.ch/user/x/xiezhen',
                        help='path to authentication file')
    parser.add_argument('-r',
                        dest='runnumber',
                        action='store',
                        required=True,
                        help='run number')
    parser.add_argument('--debug',
                        dest='debug',
                        action='store_true',
                        help='debug')
    args = parser.parse_args()
    runnumber = int(args.runnumber)
    print 'processing run ', runnumber
    #runinfosvc=sessionManager.sessionManager(args.runinfo,authpath=args.authpath,debugON=args.debug)
    lumisvc = sessionManager.sessionManager(args.lumisource,
                                            authpath=args.authpath,
                                            debugON=args.debug)
    destsvc = sessionManager.sessionManager(args.connect,
                                            authpath=args.authpath,
                                            debugON=args.debug)
    #runinfosession=runinfosvc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])

    lumisession = lumisvc.openSession(isReadOnly=True,
                                      cpp2sqltype=[
                                          ('unsigned int', 'NUMBER(10)'),
                                          ('unsigned long long', 'NUMBER(20)')
                                      ])
    try:
        #[l1key,amodetag,egev,sequence,hltkey,fillnum,starttime,stoptime]=queryDataSource.runsummary(runinfosession,'CMS_RUNINFO',runnumber,complementalOnly=False)
        #print 'runsummary ',[l1key,amodetag,egev,sequence,hltkey,fillnum,starttime,stoptime]
        lumidata = queryDataSource.uncalibratedlumiFromOldLumi(
            lumisession, runnumber)
        #print 'lumidata ',lumidata
        [bitnames,
         trglsdata] = queryDataSource.trgFromOldLumi(lumisession, runnumber)
        #print 'trg data ',bitnames,trglsdata
        [pathnames,
         hltlsdata] = queryDataSource.hltFromOldLumi(lumisession, runnumber)
        #print 'hlt data ',pathnames,hltlsdata
        lumisession.transaction().commit()
        #runinfosession.transaction().commit()
        del lumisession
        del lumisvc
        #del runinfosession
        #del runinfosvc
        destsession = destsvc.openSession(isReadOnly=False,
                                          cpp2sqltype=[('unsigned int',
                                                        'NUMBER(10)'),
                                                       ('unsigned long long',
                                                        'NUMBER(20)')])
        destsession.transaction().start(False)
        branchrevision_id = DATABRANCH_ID
        #print 'data branchid ',branchrevision_id
        #dataDML.insertRunSummaryData(destsession.nominalSchema(),runnumber,[l1key,amodetag,egev,sequence,hltkey,fillnum,starttime,stoptime],complementalOnly=False)
        (lumirevid, lumientryid, lumidataid) = dataDML.addLumiRunDataToBranch(
            destsession.nominalSchema(), runnumber, [args.lumisource],
            (branchrevision_id, 'DATA'))
        bitzeroname = bitnames.split(',')[0]
        trgrundata = [args.lumisource, bitzeroname, bitnames]
        (trgrevid, trgentryid, trgdataid) = dataDML.addTrgRunDataToBranch(
            destsession.nominalSchema(), runnumber, trgrundata,
            (branchrevision_id, 'DATA'))
        hltrundata = [pathnames, args.lumisource]
        (hltrevid, hltentryid, hltdataid) = dataDML.addHLTRunDataToBranch(
            destsession.nominalSchema(), runnumber, hltrundata,
            (branchrevision_id, 'DATA'))
        destsession.transaction().commit()
        dataDML.bulkInsertLumiLSSummary(destsession, runnumber, lumidataid,
                                        lumidata, 500)
        #
        dataDML.bulkInsertTrgLSData(destsession, runnumber, trgdataid,
                                    trglsdata, 500)
        dataDML.bulkInsertHltLSData(destsession, runnumber, hltdataid,
                                    hltlsdata, 500)
        del destsession
        del destsvc
    except:
        raise
Exemple #24
0
        db.singleUpdate(lumitableName,setClause,updateCondition,inputData)
        
if __name__ == "__main__" :
    dbstr='oracle://cms_orcon_prod/cms_lumi_prod'
    authpath='/nfshome0/xiezhen/authwriter'
    f='runstarttime.dat'
    runlengthfile='nlsperrun-pixel.dat'
    dfmt='%d-%m-%Y %H:%M:%S'
    t=parsetimefile(f,dfmt)
    timedrunlist=t.keys()
    r=parserunlength(runlengthfile)
    output={}#{(run,lumidataid):[[date,nls]]}
    for (run,lumidataid) in r.keys():
        nls=r[(run,lumidataid)]
        if run in timedrunlist:
            runstarttime=t[run]
            runstoptime=runstarttime+nls*datetime.timedelta(seconds=23.31)
            output[(run,lumidataid)]=[runstarttime,runstoptime,nls]
    try:
        lumisvc=sessionManager.sessionManager(dbstr,authpath=authpath,debugON=False)
        lumisession=lumisvc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
        lumisession.transaction().start(False)
        updatedb(lumisession.nominalSchema(),output,'PIXEL')
        lumisession.transaction().commit()
        del lumisession
        del lumisvc
    except:
        raise
    

Exemple #25
0
                     )
 parser.add_argument('--comment',action='store',
                     required=False,
                     help='patch comment'
                    )
 parser.add_argument('--singlerun',action='store',
                     required=False,
                     default=None,
                     help='pick single run from input file'
                    )
 parser.add_argument('--debug',dest='debug',action='store_true',
                     help='debug'
                     )
 options=parser.parse_args()
 svc=sessionManager.sessionManager(options.connect,
                                   authpath=options.authpath,
                                   debugON=options.debug)
 session=svc.openSession(isReadOnly=False,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
 inputfilename=os.path.abspath(options.inputfile)
 parseresult=parseInputFile(inputfilename,options.singlerun)
 runlist=parseresult.keys()
 irunlsdict={}
 for run in runlist:
     irunlsdict[run]=None
 session.transaction().start(True)
 (pixellumibranchid,pixellumibranchparent)=revisionDML.branchInfoByName(session.nominalSchema(),'DATA')
 print 'pixellumibranchid ',pixellumibranchid,' pixellumibranchparent ',pixellumibranchparent
 pixellumibranchinfo=(pixellumibranchid,'DATA')
 (pixel_tagid,pixel_tagname)=revisionDML.currentDataTag(session.nominalSchema(),lumitype='PIXEL')
 (hf_tagid,hf_tagname)=revisionDML.currentDataTag(session.nominalSchema(),lumitype='HF')    
 hfdataidmap=revisionDML.dataIdsByTagId(session.nominalSchema(),hf_tagid,runlist,withcomment=False,lumitype='HF')
Exemple #26
0
    f = 'runstarttime.dat'
    runlengthfile = 'nlsperrun-pixel.dat'
    dfmt = '%d-%m-%Y %H:%M:%S'
    t = parsetimefile(f, dfmt)
    timedrunlist = t.keys()
    r = parserunlength(runlengthfile)
    output = {}  #{(run,lumidataid):[[date,nls]]}
    for (run, lumidataid) in r.keys():
        nls = r[(run, lumidataid)]
        if run in timedrunlist:
            runstarttime = t[run]
            runstoptime = runstarttime + nls * datetime.timedelta(
                seconds=23.31)
            output[(run, lumidataid)] = [runstarttime, runstoptime, nls]
    try:
        lumisvc = sessionManager.sessionManager(dbstr,
                                                authpath=authpath,
                                                debugON=False)
        lumisession = lumisvc.openSession(isReadOnly=False,
                                          cpp2sqltype=[('unsigned int',
                                                        'NUMBER(10)'),
                                                       ('unsigned long long',
                                                        'NUMBER(20)')])
        lumisession.transaction().start(False)
        updatedb(lumisession.nominalSchema(), output, 'PIXEL')
        lumisession.transaction().commit()
        del lumisession
        del lumisvc
    except:
        raise