本文整理汇总了Python中FWCore.PythonUtilities.LumiList.LumiList.writeJSON方法的典型用法代码示例。如果您正苦于以下问题:Python LumiList.writeJSON方法的具体用法?Python LumiList.writeJSON怎么用?Python LumiList.writeJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FWCore.PythonUtilities.LumiList.LumiList
的用法示例。
在下文中一共展示了LumiList.writeJSON方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getStrangeRuns
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
def getStrangeRuns(self):
hltInfoByLs =self.analysisOutput()
strangeRunsLumis = LumiList( lumis = [[int(hltInf[0]),int(hltInf[1])] for hltInf in hltInfoByLs if not int(hltInf[2][1]) >= 1] )
if self.jsonOutput:
strangeRunsLumis.writeJSON(jsonOutput+"_strange")
else:
return strangeRunsLumis
示例2: getPrescaledRuns
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
def getPrescaledRuns(self):
hltInfoByLs =self.analysisOutput()
prescaledRunsAndLumis = LumiList( lumis = [[int(hltInf[0]),int(hltInf[1])] for hltInf in hltInfoByLs if int(hltInf[2][1]) >= 1] )
if self.jsonOutput:
prescaledRunsAndLumis.writeJSON(jsonOutput+"_prescaled")
return jsonOutput+"_prescaled"
else:
return prescaledRunsAndLumis
示例3: getGoodRuns
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
def getGoodRuns(self):
hltInfoByLs =self.analysisOutput()
goodRunsAndLumis = LumiList(lumis = [[int(hltInf[0]),int(hltInf[1])] for hltInf in hltInfoByLs if int(hltInf[2][1]) == 1] )
if self.jsonOutput:
goodRunsAndLumis.writeJSON(jsonOutput+"_good")
return jsonOutput+"_good"
else:
return goodRunsAndLumis
示例4: savejsons
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
def savejsons(self, processed):
jsondir = os.path.join(self.__plotdir, 'jsons')
if not os.path.exists(jsondir):
os.makedirs(jsondir)
res = {}
for label in processed:
jsondir = os.path.join('jsons', label)
if not os.path.exists(os.path.join(self.__plotdir, jsondir)):
os.makedirs(os.path.join(self.__plotdir, jsondir))
lumis = LumiList(lumis=processed[label])
lumis.writeJSON(os.path.join(self.__plotdir, jsondir, 'processed.json'))
res[label] = [(os.path.join(jsondir, 'processed.json'), 'processed')]
published = os.path.join(self.__workdir, label, 'published.json')
if os.path.isfile(published):
shutil.copy(published, os.path.join(self.__plotdir, jsondir))
res[label] += [(os.path.join(jsondir, 'published.json'), 'published')]
return res
示例5: shortenJson
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
def shortenJson(jsonFile,minRun=0,maxRun=-1,output=None,debug=False):
from copy import deepcopy
runList = jsonFile
if isinstance(runList,LumiList):
runList = deepcopy(jsonFile)
else:
runList = LumiList (filename = jsonFile) # Read in first JSON file
allRuns = runList.getRuns()
runsToRemove=[]
for run in allRuns:
if int(run) < minRun:
runsToRemove.append (run)
if maxRun > 0 and int(run) > maxRun:
runsToRemove.append (run)
if debug:
print " runsToRemove ",runsToRemove
runList.removeRuns (runsToRemove)
if output:
runList.writeJSON (output)
else:
return runList
示例6: makeJSON
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
def makeJSON(optlist):
outdir = optlist[0]
basedir = optlist[1]
lastUnblindRun = optlist[2]
name = optlist[3]
files = optlist[4:]
s = sampleInfo(name,basedir,files)
#lumi set for this sample
mergedLumisUnblind = set()
mergedLumisBlinded = set()
for f in s.fileList:
file = TFile.Open(f)
if file == None: continue
# only keep necessary branches
t = file.Get("TreeMaker2/PreSelection")
if t == None: continue
t.SetBranchStatus("*",0)
t.SetBranchStatus("RunNum",1)
t.SetBranchStatus("LumiBlockNum",1)
#get tree entries
nentries = t.GetEntries()
if nentries==0: continue
t.SetEstimate(nentries)
t.Draw("RunNum:LumiBlockNum","","goff")
v1 = t.GetV1(); v1.SetSize(t.GetSelectedRows()); a1 = array.array('d',v1); v1 = None;
v2 = t.GetV2(); v2.SetSize(t.GetSelectedRows()); a2 = array.array('d',v2); v2 = None;
#loop over tree entries
for run,ls in izip(a1,a2):
irun = int(run)
ils = int(ls)
if irun <= lastUnblindRun or lastUnblindRun==-1:
if not (irun,ils) in mergedLumisUnblind:
mergedLumisUnblind.add((irun,ils))
else:
if not (irun,ils) in mergedLumisBlinded:
mergedLumisBlinded.add((irun,ils))
file.Close()
### end loop over files in sample
#convert the runlumis from list of pairs to dict: [(123,3), (123,4), (123,5), (123,7), (234,6)] => {123 : [3,4,5,7], 234 : [6]}
mLumisDictUnblind = {}
mLumisDictBlinded = {}
for k, v in mergedLumisUnblind:
mLumisDictUnblind.setdefault(k, []).append(int(v))
for k, v in mergedLumisBlinded:
mLumisDictBlinded.setdefault(k, []).append(int(v))
#make lumi list from dict
mergedLumiListUnblind = LumiList(runsAndLumis=mLumisDictUnblind)
mergedLumiListBlinded = LumiList(runsAndLumis=mLumisDictBlinded)
if mergedLumiListUnblind:
outfile = outdir+'/lumiSummary_unblind_'+s.outName+'.json'
mergedLumiListUnblind.writeJSON(outfile)
print "wrote "+outfile
if mergedLumiListBlinded:
outfile = outdir+'/lumiSummary_blinded_'+s.outName+'.json'
mergedLumiListBlinded.writeJSON(outfile)
print "wrote "+outfile
示例7: set
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
ls = set(l for r,l in lumi_mask)
if ls == set([-1]):
is_mc = True
elif -1 in ls:
raise ValueError('batch for dataset %s has lumis -1 and others' % dataset)
else:
is_mc = False
if not is_mc:
job_control = '''
lumi_mask = pick_events.json
total_number_of_lumis = -1
lumis_per_job = 1'''
ll = LumiList(lumis=lumi_mask)
ll.writeJSON('pick_events.json')
else:
job_control = '''
total_number_of_events = -1
events_per_job = 100000'''
scheduler = 'condor' if 'condor' in sys.argv else 'glite'
open('crab.cfg', 'wt').write(crab_cfg % locals())
pset = open('pick_events.py').read()
pset += '\nevents_to_process = '
pset += pformat(events_to_process)
pset += '\nset_events_to_process(process, events_to_process)\n'
open('pick_events_crab.py', 'wt').write(pset)
if not just_testing:
示例8: main
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
def main(argv = None):
"""Main routine of the script.
Arguments:
- `argv`: arguments passed to the main routine
"""
if argv == None:
argv = sys.argv[1:]
parser = argparse.ArgumentParser(
description="Create JSON selection for a given magnetic field.")
parser.add_argument("-i", "--input", dest="input", metavar="JSON",
type=str, help="input JSON file")
parser.add_argument("-o", "--output", dest="output", metavar="JSON",
type=str, help="output JSON file")
parser.add_argument("--min", dest="min", metavar="RUN", type=int,
help="first run to be considered in the selection")
parser.add_argument("--max", dest="max", metavar="RUN", type=int,
help="last run to be considered in the selection")
parser.add_argument("--epsilon", dest="epsilon", metavar="TESLA",
default=0.1, type=float,
help="precision of the filter (default: %(default)s T)")
parser.add_argument("--debug", dest="debug", action="store_true",
help="show more verbose output")
required = parser.add_argument_group("required arguments")
required.add_argument("--b-field", dest="bfield", metavar="TESLA",
required=True, type=float,
help="magnetic field to filter")
args = parser.parse_args(argv)
try:
if args.input == None and (args.min == None or args.max == None):
msg = ("If no input JSON file ('--input') is provided, you have to "
"explicitly provide the first ('--min') and last ('--max') "
"run.")
raise RuntimeError(msg)
if args.min != None and args.max != None and args.min > args.max:
msg = "First run ({min:d}) is after last run ({max:d})."
msg = msg.format(**args.__dict__)
raise RuntimeError(msg)
if args.max != None and args.max <= 0:
msg = "Last run must be greater than zero: max = {0:d} <= 0."
msg = msg.format(args.max)
raise RuntimeError(msg)
except RuntimeError as e:
if args.debug: raise
print ">>>", os.path.splitext(os.path.basename(__file__))[0]+":", str(e)
sys.exit(1)
lumi_list = None if not args.input else LumiList(filename = args.input)
input_runs = None if not lumi_list else [int(r) for r in lumi_list.getRuns()]
# Run registry API: https://twiki.cern.ch/twiki/bin/viewauth/CMS/DqmRrApi
URL = "http://runregistry.web.cern.ch/runregistry/"
api = rrapi.RRApi(URL, debug = args.debug)
if api.app != "user": return
column_list = ("number",)
min_run = args.min if args.min != None else input_runs[0]
max_run = args.max if args.max != None else input_runs[-1]
bfield_min = args.bfield - args.epsilon
bfield_max = args.bfield + args.epsilon
constraints = {
"datasetExists": "= true",
"number": ">= {0:d} and <= {1:d}".format(min_run, max_run),
"bfield": "> {0:f} and < {1:f}".format(bfield_min, bfield_max)
}
run_list = [item["number"] for item in
api.data(workspace = "GLOBAL", table = "runsummary",
template = "json", columns = column_list,
filter = constraints)]
if lumi_list != None:
runs_to_remove = []
for run in input_runs:
if run not in run_list: runs_to_remove.append(run)
lumi_list.removeRuns(runs_to_remove)
else:
lumi_list = LumiList(runs = run_list)
if args.output != None:
lumi_list.writeJSON(args.output)
with open(args.output+".args", "w") as f:
f.write(" ".join(argv)+"\n")
else:
print lumi_list
示例9: len
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
parser.add_option ('--output', dest='output', type='string',
help='Save output to file OUTPUT')
# required parameters
(options, args) = parser.parse_args()
if not len (args):
raise RuntimeError("Must provide at least one input file")
minMaxRE = re.compile (r'(\S+):(\d+)-(\d*)')
finalList = LumiList()
for filename in args:
minRun = maxRun = 0
match = minMaxRE.search (filename)
if match:
filename = match.group(1)
minRun = int( match.group(2) )
try:
maxRun = int( match.group(3) )
except:
pass
if maxRun and minRun > maxRun:
raise RuntimeError("Minimum value (%d) is greater than maximum value (%d) for file '%s'" % (minRun, maxRun, filename))
localList = LumiList (filename = filename)
filterRuns (localList, minRun, maxRun)
finalList = finalList | localList
if options.output:
finalList.writeJSON (options.output)
else:
print finalList
示例10: len
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
if len (eventList) > 20:
options.crab = True
if options.crab:
##########
## CRAB ##
##########
if options.runInteractive:
raise RuntimeError, "This job is can not be run interactive, but rather by crab. Please call without '--runInteractive' flag."
runsAndLumis = [ (event.run, event.lumi) for event in eventList]
json = LumiList (lumis = runsAndLumis)
eventsToProcess = '\n'.join(\
sorted( [ "%d:%d" % (event.run, event.event) for event in eventList ] ) )
crabDict = setupCrabDict (options)
json.writeJSON (crabDict['json'])
target = open (crabDict['runEvent'], 'w')
target.write ("%s\n" % eventsToProcess)
target.close()
target = open (crabDict['crabcfg'], 'w')
target.write (crabTemplate % crabDict)
target.close
print "Please visit CRAB twiki for instructions on how to setup environment for CRAB:\nhttps://twiki.cern.ch/twiki/bin/viewauth/CMS/SWGuideCrab\n"
if options.crabCondor:
print "You are running on condor. Please make sure you have read instructions on\nhttps://twiki.cern.ch/twiki/bin/view/CMS/CRABonLPCCAF\n"
if not os.path.exists ('%s/.profile' % os.environ.get('HOME')):
print "** WARNING: ** You are missing ~/.profile file. Please see CRABonLPCCAF instructions above.\n"
print "Setup your environment for CRAB. Then edit %(crabcfg)s to make any desired changed. The run:\n\ncrab -create -cfg %(crabcfg)s\ncrab -submit\n" % crabDict
else:
示例11: NotImplementedError
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
#!/usr/bin/env python
raise NotImplementedError('run2 sample arch')
import sys, os
from FWCore.PythonUtilities.LumiList import LumiList
from JMTucker.Tools.ROOTTools import *
import JMTucker.Tools.Samples as Samples
for fn in sys.argv[1:]:
if os.path.isfile(fn):
print fn
name = os.path.basename(fn).replace('.root', '')
sample = getattr(Samples, name)
f = ROOT.TFile(fn)
t = f.Get('evids/event_ids')
n = t.GetEntries()
n2 = int(sample.nevents_orig/2 * sample.ana_filter_eff)
print '%30s: %s %s %s' % (name, n, n2, '\033[36;7m not equal \033[m' if n != n2 else '')
rles = list(detree(t))
assert len(rles) == n
ll = LumiList(lumis=[(r,l) for r,l,e in rles])
ll.writeJSON('%s.json' % name)
示例12: LumiList
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
commaRE = re.compile (r',')
alphaList = LumiList (filename = args[0]) # Read in first JSON file
allLumis = alphaList.getLumis()
count_lumis = 0
for (run, lumi) in allLumis:
count_lumis += 1
lumis_per_sec = count_lumis/options.sec
print 'Found %s lumis in file.' % count_lumis
print 'Splitting into %s sections with %s lumis each.' % (options.sec, lumis_per_sec)
count_lumis = 0
for sec in range(options.sec):
ibegin = sec*lumis_per_sec
iend = ibegin + lumis_per_sec
if sec == options.sec - 1:
iend = len(allLumis)
tempList = LumiList (lumis = allLumis[ibegin:iend])
print 'Part %s: num lumis = %s' % (sec+1, len(tempList.getLumis()))
count_lumis += len(tempList.getLumis())
filename = '%s_%s_%s' % (options.outbase, sec+1, options.outend)
tempList.writeJSON (filename)
print 'Total lumis = %s' % count_lumis
示例13: list
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
if args.migrate_parents:
parents_to_migrate = list(set([p['parent_logical_file_name'] for p in block['file_parent_list']]))
migrate_parents(parents_to_migrate, dbs)
if len(block.data['files']) > 0:
try:
inserted = True
dbs['local'].insertBulkBlock(block.data)
db.update_published(block.get_publish_update())
logging.info('block inserted: %s' % block['block']['block_name'])
except HTTPError, e:
logging.critical(e)
first_job += args.block_size
if inserted:
published.update({'dataset': block['dataset']['dataset']})
info = das_interface.get_info(published)
lumis = LumiList(lumis=sum(info.lumis.values(), []))
json = os.path.join(workdir, label, 'published.json')
lumis.writeJSON(json)
logging.info('publishing dataset %s complete' % label)
logging.info('json file of published runs and lumis saved to %s' % json)
if len(missing) > 0:
template = "the following job(s) have not been published because their output could not be found: {0}"
logging.warning(template.format(", ".join(map(str, missing))))
示例14: float
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
if args.intersect:
edmLumis = edmLumis & impLumis
reclumiData=None
dellumiData=None
if lumiCalc is not None:
print "Accessing LumiDB... can take a while..."
dellumiData=lumiCalc.deliveredLumiForRange(edmLumis.getCompactList())
reclumiData=lumiCalc.recordedLumiForRange(edmLumis.getCompactList())
totalRec = 0.0
totalDel = 0.0
for dpr in dellumiData:
if dpr[2] != 'N/A':
totalDel += float(dpr[2])
for dpr in reclumiData:
totalRec += lumiCalc.calculateTotalRecorded(dpr[2])
print "Delivered Luminosity: ",totalDel
print "Recorded Luminosity: ",totalRec
if args.outputJSON:
edmLumis.writeJSON(outputJSON)
if args.printJSON:
print edmLumis.getCompactList()
if args.printCMSSWString:
print edmLumis.getCMSSWString()
if lumiCalc is not None:
del lumiCalc
示例15: len
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import writeJSON [as 别名]
parser.add_option ('--output', dest='output', type='string',
help='Save output to file OUTPUT')
# required parameters
(options, args) = parser.parse_args()
if len (args) != 1:
raise RuntimeError, "Must provide exactly one input file"
if options.min and options.max and options.min > options.max:
raise RuntimeError, "Minimum value (%d) is greater than maximum value (%d)" % (options.min, options.max)
commaRE = re.compile (r',')
runsToRemove = []
for chunk in options.runs:
runs = commaRE.split (chunk)
runsToRemove.extend (runs)
alphaList = LumiList (filename = args[0]) # Read in first JSON file
allRuns = alphaList.getRuns()
for run in allRuns:
if options.min and int(run) < options.min:
runsToRemove.append (run)
if options.max and int(run) > options.max:
runsToRemove.append (run)
alphaList.removeRuns (runsToRemove)
if options.output:
alphaList.writeJSON (options.output)
else:
print alphaList