本文整理汇总了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()
#.........这里部分代码省略.........