当前位置: 首页>>代码示例>>Python>>正文


Python CommonUtil.tolegalJSON方法代码示例

本文整理汇总了Python中RecoLuminosity.LumiDB.CommonUtil.tolegalJSON方法的典型用法代码示例。如果您正苦于以下问题:Python CommonUtil.tolegalJSON方法的具体用法?Python CommonUtil.tolegalJSON怎么用?Python CommonUtil.tolegalJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RecoLuminosity.LumiDB.CommonUtil的用法示例。


在下文中一共展示了CommonUtil.tolegalJSON方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from RecoLuminosity.LumiDB import CommonUtil [as 别名]
# 或者: from RecoLuminosity.LumiDB.CommonUtil import tolegalJSON [as 别名]
def main():
    parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description = "Lumi Validation",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    allowedActions = ['batchupdate','update','dump']
    allowedFlags = ['UNKNOWN','GOOD','BAD','SUSPECT']
    # parse arguments
    parser.add_argument('action',choices=allowedActions,help='command actions')
    parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
    parser.add_argument('-P',dest='authpath',action='store',required=True,help='path to authentication file')
    parser.add_argument('-i',dest='inputfile',action='store',help='lumi range selection file,required for batchupdate action')
    parser.add_argument('-o',dest='outputfile',action='store',help='output to csv file')
    parser.add_argument('-r',dest='runnumber',action='store',type=int,help='run number,optional')
    parser.add_argument('-runls',dest='runls',action='store',help='selection string,optional. Example [1234:[],4569:[1,1],[2,100]]')
    parser.add_argument('-flag',dest='flag',action='store',default='UNKNOWN',help='flag string,optional')
    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')
    options=parser.parse_args()
    if options.flag.upper() not in allowedFlags:
        print 'unrecognised flag ',options.flag.upper()
        raise
    os.environ['CORAL_AUTH_PATH'] = options.authpath
    connectstring=options.connect
    svc = coral.ConnectionService()
    msg=coral.MessageStream('')
    if options.debug:
        msg.setMsgVerbosity(coral.message_Level_Debug)
    else:
        msg.setMsgVerbosity(coral.message_Level_Error)
    session=svc.connect(connectstring,accessMode=coral.access_Update)
    session.typeConverter().setCppTypeForSqlType("unsigned int","NUMBER(10)")
    session.typeConverter().setCppTypeForSqlType("unsigned long long","NUMBER(20)")
    
    result={}#parsing result {run:[[ls,status,comment]]}
    if options.debug :
        msg=coral.MessageStream('')
        msg.setMsgVerbosity(coral.message_Level_Debug)
    
    if options.action=='batchupdate':
        #populate from csv file, require -i argument
        if not options.inputfile:
            print 'inputfile -i option is required for batchupdate'
            raise
        csvReader=csv.reader(open(options.inputfile),delimiter=',')
        for row in csvReader:
            if len(row)==0:
                continue
            fieldrun=str(row[0]).strip()
            fieldls=str(row[1]).strip()
            fieldstatus=row[2]
            fieldcomment=row[3]
            if not result.has_key(int(fieldrun)):
                result[int(fieldrun)]=[]
            result[int(fieldrun)].append([int(fieldls),fieldstatus,fieldcomment])
        insertupdateValidationData(session,result)
    if options.action=='update':
        #update flag interactively, require -runls argument
        #runls={run:[]} populate all CMSLSNUM found in LUMISUMMARY
        #runls={run:[[1,1],[2,5]],run:[[1,1],[2,5]]}
        #default value
        if not options.runls and not options.runnumber:
            print 'option -runls or -r is required for update'
            raise
        if not options.flag:
            print 'option -flag is required for update'
            raise
        if options.flag.upper() not in allowedFlags:
            print 'unrecognised flag ',options.flag
            raise
        if options.runnumber:
            runlsjson='{"'+str(options.runnumber)+'":[]}'
        elif options.runls:
            runlsjson=CommonUtil.tolegalJSON(options.runls)
        sparser=selectionParser.selectionParser(runlsjson)
        runsandls=sparser.runsandls()
        commentStr='NA'
        statusStr=options.flag
        for run,lslist in runsandls.items():
            if not result.has_key(run):
                result[run]=[]
            for ls in lslist:
                result[run].append([ls,statusStr,commentStr])
        insertupdateValidationData(session,result)
    if options.action=='dump':
        if options.runls or options.inputfile:
            if options.runls:
                runlsjson=CommonUtil.tolegalJSON(options.runls)
                sparser=selectionParser.selectionParser(runlsjson)
                runsandls=sparser.runsandls()
            if options.inputfile:
                p=inputFilesetParser.inputFilesetParser(options.inputfile)
                runsandls=p.runsandls()
            for runnum,lslist in runsandls.items():
                dataperrun=getValidationData(session,run=runnum,cmsls=lslist)
                if dataperrun.has_key(runnum):
                    result[runnum]=dataperrun[runnum]
                else:
                    result[runnum]=[]
        else:
            result=getValidationData(session,run=options.runnumber)
        runs=result.keys()
        runs.sort()
#.........这里部分代码省略.........
开发者ID:fabozzi,项目名称:ST_44,代码行数:103,代码来源:lumiValidate.py


注:本文中的RecoLuminosity.LumiDB.CommonUtil.tolegalJSON方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。