本文整理汇总了Python中myutils.BetterConfigParser.get方法的典型用法代码示例。如果您正苦于以下问题:Python BetterConfigParser.get方法的具体用法?Python BetterConfigParser.get怎么用?Python BetterConfigParser.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类myutils.BetterConfigParser
的用法示例。
在下文中一共展示了BetterConfigParser.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: diffConfigFile
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
def diffConfigFile(tag1, tag2, fileName):
print("file:", fileName)
config1 = BetterConfigParser()
config2 = BetterConfigParser()
config1.read(tag1 + 'config/' + fileName)
config2.read(tag2 + 'config/' + fileName)
sections = list(set(config1.sections() + config2.sections()))
commonSections = [x for x in sections if x in config1.sections() and x in config2.sections()]
print("common sections:", commonSections)
for section in commonSections:
firstItemInSection = True
items1d = {x[0]:x[1] for x in config1.items(section, raw=True)}
items2d = {x[0]:x[1] for x in config2.items(section, raw=True)}
items1 = [x[0] for x in config1.items(section, raw=True)]
items2 = [x[0] for x in config2.items(section, raw=True)]
items = list(set(items1 + items2))
commonItems = list(set([x for x in items if x in items1 and x in items2]))
for item in commonItems:
if item not in os.environ:
try:
item1 = config1.get(section, item)
item2 = config2.get(section, item)
item1 = items1d[item]
item2 = items2d[item]
if item1 != item2:
if firstItemInSection:
firstItemInSection = False
print('-'*80)
print(' \x1b[34m' + fileName + '\x1b[0m: ' + section)
print('-'*80)
print(section + ':' + item)
d = difflib.Differ()
result = list(d.compare([item1], [item2]))
for line in result:
if line.startswith('+'):
color = '\x1b[31m'
elif line.startswith('-'):
color = '\x1b[32m'
elif line.startswith('?'):
color = '\x1b[34m'
print(' '+color+line+'\x1b[0m')
except Exception as e:
pass
示例2: OptionParser
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
import os
argv = sys.argv
#------------------------------------------------------------------------------
# prepare sample .txt files from ntuple folders
#------------------------------------------------------------------------------
#get files info from config
parser = OptionParser()
parser.add_option("-C", "--config", dest="config", default=[], action="append",
help="directory config")
(opts, args) = parser.parse_args(argv)
config = BetterConfigParser()
config.read(opts.config)
inputPath = config.get('Directories', 'samplepath')
outputPath = config.get('Directories', 'samplefiles')
print 'INPUT: ', inputPath
print 'OUTPUT:', outputPath
print '-'*80
if '/pnfs/' in inputPath:
inputPath = '/pnfs/' + inputPath.split('/pnfs/')[-1]
sampleNameReplacementRules = {
'RunIISummer16MiniAODv2_': '',
}
sampleFileReplacementRules = {
'/pnfs/psi.ch/cms/trivcat': ''
}
# find all folders which contain ntuples
示例3: float
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
sampleName = section
sampleNameShort = '_'.join(sampleName.split('_')[0:7]).strip()
if '_ext' in sampleName:
sampleNameShort = sampleNameShort.split('_ext')[0]
elif '_backup' in sampleName:
sampleNameShort = sampleNameShort.split('_backup')[0]
if sampleNameShort in sampleDict:
sampleDict[sampleNameShort].append(sampleName)
else:
sampleDict[sampleNameShort] = [sampleName]
if verify:
extweight = 0
try:
extweight = float(config.get(section, 'extweight'))
except:
pass
sampleWeights[sampleNameShort] = float(sampleWeights[sampleNameShort]) + extweight if sampleNameShort in sampleWeights else extweight
if verify:
for sampleNameShort,totalWeight in sampleWeights.iteritems():
if sampleNameShort in sampleDict and len(sampleDict[sampleNameShort])>1:
print sampleNameShort,":",totalWeight
else:
for sample,extParts in sampleDict.iteritems():
if len(extParts) > 1:
print '-'*80
print sample,":"
getExtWeights(config,extParts)
示例4: BetterConfigParser
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
sys.exit(123)
en = opts.tag
#create the list with the samples to run over
samplesList=opts.samples.split(",")
timestamp = time.asctime().replace(' ','_').replace(':','-')
if(debugPrintOUts): print 'samplesList',samplesList
if(debugPrintOUts): print 'timestamp',timestamp
# the list of the config is taken from the path config
pathconfig = BetterConfigParser()
pathconfig.read('%sconfig/paths'%(en))
_configs = pathconfig.get('Configuration','List').split(" ")
configs = [ '%sconfig/'%(en) + c for c in _configs ]
if(debugPrintOUts): print 'configs',configs
if(debugPrintOUts): print 'opts.ftag',opts.ftag
if not opts.ftag == '':
tagDir = pathconfig.get('Directories','tagDir')
# DEBUG PURPOSE ONLY
# sys.exit()
if(debugPrintOUts): print 'tagDir',tagDir
DirStruct={'tagDir':tagDir,'ftagdir':'%s/%s/'%(tagDir,opts.ftag),'logpath':'%s/%s/%s/'%(tagDir,opts.ftag,'Logs'),'plotpath':'%s/%s/%s/'%(tagDir,opts.ftag,'Plots'),'limitpath':'%s/%s/%s/'%(tagDir,opts.ftag,'Limits'),'confpath':'%s/%s/%s/'%(tagDir,opts.ftag,'config') }
if(debugPrintOUts): print 'DirStruct',DirStruct
示例5: BetterConfigParser
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
#parser.add_option("-P", "--path", dest="path", default="",
# help="path to samples")
parser.add_option("-S", "--samples", dest="names", default="",
help="samples you want to run on")
parser.add_option("-C", "--config", dest="config", default=[], action="append",
help="configuration defining the plots to make")
(opts, args) = parser.parse_args(argv)
if opts.config =="":
opts.config = "config"
from myutils import BetterConfigParser, ParseInfo
print opts.config
config = BetterConfigParser()
config.read(opts.config)
anaTag = config.get("Analysis","tag")
TrainFlag = eval(config.get('Analysis','TrainFlag'))
btagLibrary = config.get('BTagReshaping','library')
samplesinfo=config.get('Directories','samplesinfo')
VHbbNameSpace=config.get('VHbbNameSpace','library')
ROOT.gSystem.Load(VHbbNameSpace)
AngLikeBkgs=eval(config.get('AngularLike','backgrounds'))
ang_yield=eval(config.get('AngularLike','yields'))
#path=opts.path
pathIN = config.get('Directories','SYSin')
pathOUT = config.get('Directories','SYSout')
tmpDir = os.environ["TMPDIR"]
print 'INput samples:\t%s'%pathIN
示例6: BetterConfigParser
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
parser.add_option("-A", "--apply", dest="apply", default=True, action="store_true",
help="configuration defining the")
parser.add_option("-W", "--weight", dest="weights", default=True, action="store_false",
help="Calculate the weights")
parser.add_option("-V", "--validate", dest="validate", default=False, action="store_false",
help="Make validation plot the weights")
(opts, args) = parser.parse_args(argv)
if opts.config =="":
opts.config = "config"
from myutils import BetterConfigParser
print opts.config
config = BetterConfigParser()
config.read(opts.config)
prefix = config.get('lheWeights','prefix')
newpostfix = config.get('lheWeights','newpostfix')
inclusive = config.get('lheWeights','inclusive')
files = eval(config.get('lheWeights','fileList'))
lheBin = eval(config.get('lheWeights','lheBin'))
print '\n========= Looping over Drell Yan Samples ==========\n'
fileList = []
for file in files:
new_entry = [prefix+file+'.root',files[file],[]]
print new_entry
if file == inclusive:
fileList.insert(0, new_entry)
else:
fileList.append(new_entry)
示例7: BetterConfigParser
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
parser.add_option("-V", "--variable", dest="variable", default="",
help="variable for shape analysis")
parser.add_option("-C", "--config", dest="config", default=[], action="append",
help="configuration file")
(opts, args) = parser.parse_args(argv)
config = BetterConfigParser()
config.read(opts.config)
var=opts.variable
#-------------------------------------------------------------------------------
# Add external macros
#ROOT.gSystem.CompileMacro("../plugins/PU.C")
#--read variables from config---------------------------------------------------
# 7 or 8TeV Analysis
anaTag = config.get("Analysis","tag")
# Directories:
Wdir=config.get('Directories','Wdir')
vhbbpath=config.get('Directories','vhbbpath')
samplesinfo=config.get('Directories','samplesinfo')
path = config.get('Directories','dcSamples')
outpath=config.get('Directories','limits')
try:
os.stat(outpath)
except:
os.mkdir(outpath)
# parse histogram config:
treevar = config.get('dc:%s'%var,'var')
name = config.get('dc:%s'%var,'wsVarName')
示例8: TBmaster
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
class TBmaster(object):
def __init__(self, TB, client, psiSubscription, Logger, color='black', psiVersion='psi46expert'):
self.TB = TB
self.client = client
self.psiSubscription = psiSubscription
self.color = color
self.Logger = Logger
self.TBSubscription = '/TB%s'%self.TB
self.client.subscribe(self.TBSubscription)
self.dir = ''
self.psiVersion = psiVersion
if self.psiVersion.lower().endswith("psi46expert"):
self.version ='psi46expert'
elif self.psiVersion.lower().endswith("pyxar"):
self.version ='pyxar'
elif self.psiVersion.lower().endswith("pxar"):
self.version ='pxar'
else:
self.version = 'unknown'
self.failed = False
self.busy = False
self.testName ='unkown'
self.testNo = -1
self.TestEnd = False
self.DoTest= False
self.ClosePSI= False
self.Abort = False
self.LogFile = ""
self.RootFile = ""
# default value in Vcal units, -1 means use untrimmed parameters
# this setting is overwritten if [Test Trim] is specified in the ini file
# containg testParameters=Vcal=*
self.trimVcal = -1
self.init = BetterConfigParser()
self.init.read("../config/elComandante.ini")
try:
testParameters = self.init.get('Test Trim','testParameters')
pos1 = testParameters.find("=")
if pos1 > 0:
testParametersName = testParameters[0:pos1]
testParametersValue = testParameters[pos1+1:]
if testParametersName.lower() == "vcal":
self.trimVcal = int(testParametersValue)
self.Logger << "TB%s: using option '-T %s' when calling pxar"%(self.TB, self.trimVcal)
except:
self.Logger << "TB%s: no [Test Trim] section found in ini file, using untrimmed parameters"%self.TB
def _spawn(self,executestr):
my_env = os.environ
if my_env.has_key("LD_PRELOAD"):
my_env["LD_PRELOAD"] = "/opt/glibc-2.14/lib/libc.so.6:" + my_env["LD_PRELOAD"]
else:
my_env["LD_PRELOAD"] = "/opt/glibc-2.14/lib/libc.so.6:"
self.proc = subprocess.Popen([executestr,''], shell = True, stdout = subprocess.PIPE, stdin = subprocess.PIPE, env = my_env)
self.busy = True
def _kill(self):
try:
self.proc.kill()
self.Logger.warning("PSI%s KILLED"%self.TB)
except:
self.Logger.warning("nothing to be killed")
def _abort(self):
self.Logger.warning('ABORT!')
self._kill()
self.Abort = False
return True
def _resetVariables(self):
self.busy = False
self.failed = False
self.TestEnd = False
self.DoTest = False
self.ClosePSI = False
self.Abort = False
def _readAllSoFar(self, retVal = ''):
while (select.select([self.proc.stdout],[],[],0)[0]!=[]) and self.proc.poll() is None:
retVal += self.proc.stdout.read(1)
return retVal
@staticmethod
def findError(stat):
return any([Error in stat for Error in ['error','Error','anyOtherString','command not found']])
def _readout(self):
internalFailed = False
self.Logger << '>>> Aquire Testboard %s <<<'%self.TB
# self._answer(self)
while self.proc.poll() is None and self.ClosePSI==False:
if self.Abort:
internalFailed = self._abort()
lines = ['']
lines = self._readAllSoFar(lines[-1]).split('\n')
for a in range(len(lines)-1):
line=lines[a]
hesays=line.rstrip()
self.client.send(self.TBSubscription,'%s\n'%hesays)
#.........这里部分代码省略.........
示例9: OptionParser
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
# Import heppy configurations
argv = sys.argv
parser = OptionParser()
parser.add_option("-S", "--samples", dest="names", default="",
help="samples you want to run on")
parser.add_option("-C", "--config", dest="config", default=[], action="append",
help="configuration defining the plots to make")
(opts, args) = parser.parse_args(argv)
if opts.config =="":
opts.config = "config"
config = BetterConfigParser()
config.read(opts.config)
samplesinfo = config.get('Directories','samplesinfo')
tmpDir = os.environ["TMPDIR"]
pathIN = config.get('Directories','SYSout')
pathOUT = config.get('Directories','SYSout')
name = config.get('TrainRegression', 'name')
namelist = opts.names.split(',')
info = ParseInfo(samplesinfo,pathIN)
# Now load kinFit modules/namspaces
ROOT.gSystem.Load("libPhysicsToolsKinFitter.so")
示例10: BetterConfigParser
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
parser.add_option("-r","--regions", dest="regions", default='',
help="cut region identifiers, separated by comma")
parser.add_option("-t","--type", dest="fitType", default='',
help="shapes_prefit, shapes_fit_b, shapes_fit_s")
(opts, args) = parser.parse_args(argv)
if opts.config == "":
opts.config = ["config"]
# Import after configure to get help message
from myutils import BetterConfigParser, mvainfo, ParseInfo
config = BetterConfigParser()
config.read(opts.config)
if len(opts.fitType) < 1:
if config.has_option('Fit','FitType'):
opts.fitType = config.get('Fit','FitType')
else:
opts.fitType = "shapes_prefit"
# run plotter
if len(opts.regions) < 1:
regions = eval(config.get('Fit', 'regions')).keys()
else:
regions = opts.regions.split(',')
for region in regions:
plotter = PostfitPlotter(config=config, region=region, directory=opts.fitType)
plotter.prepare()
plotter.run()
示例11: OptionParser
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
parser = OptionParser()
parser.add_option("-C", "--config", dest="config", default=[], action="append",
help="directory config")
parser.add_option("-S", "--sampleIdentifier", dest="sampleIdentifier", default="",
help="samples you want to run on")
parser.add_option("-f", "--fileList", dest="fileList", default="",
help="list of files you want to run on")
parser.add_option("-l", "--limit", dest="limit", default=None,
help="max number of files to process")
(opts, args) = parser.parse_args(argv)
config = BetterConfigParser()
config.read(opts.config)
fileList = FileList.decompress(opts.fileList) if len(opts.fileList)>0 else None
pathOUT = config.get('Directories','PREPout')
samplesinfo=config.get('Directories','samplesinfo')
samplefiles = config.get('Directories','samplefiles')
sampleconf = BetterConfigParser()
sampleconf.read(samplesinfo)
whereToLaunch = config.get('Configuration','whereToLaunch')
info = ParseInfo(samplesinfo, None)
samples = [x for x in info if not x.subsample and (len(opts.sampleIdentifier) == 0 or x.identifier in opts.sampleIdentifier.split(','))]
treeCopier = copytreePSI.CopyTreePSI(config=config)
if opts.limit and len(samples) > int(opts.limit):
samples= samples[:int(opts.limit)]
for sample in samples:
treeCopier.copytreePSI(pathIN=samplefiles, pathOUT=pathOUT, folderName=sample.identifier, skimmingCut=sample.addtreecut, fileList=fileList)
示例12: __init__
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
class XbbRun:
def __init__(self, opts):
# get file list
self.filelist = FileList.decompress(opts.fileList) if len(opts.fileList) > 0 else None
print "len(filelist)",len(self.filelist),
if len(self.filelist) > 0:
print "filelist[0]:", self.filelist[0]
else:
print ''
# config
self.debug = 'XBBDEBUG' in os.environ
self.verifyCopy = True
self.opts = opts
self.config = BetterConfigParser()
self.config.read(opts.config)
samplesinfo = self.config.get('Directories', 'samplesinfo')
self.channel = self.config.get('Configuration', 'channel')
# load namespace, TODO
VHbbNameSpace = self.config.get('VHbbNameSpace', 'library')
ROOT.gSystem.Load(VHbbNameSpace)
# directories
self.pathIN = self.config.get('Directories', opts.inputDir)
self.pathOUT = self.config.get('Directories', opts.outputDir)
self.tmpDir = self.config.get('Directories', 'scratch')
print 'INput samples:\t%s'%self.pathIN
print 'OUTput samples:\t%s'%self.pathOUT
self.fileLocator = FileLocator(config=self.config)
# check if given sample identifier uniquely matches a samples from config
matchingSamples = ParseInfo(samplesinfo, self.pathIN).find(identifier=opts.sampleIdentifier)
if len(matchingSamples) != 1:
print "ERROR: need exactly 1 sample identifier as input with -S !!"
print matchingSamples
exit(1)
self.sample = matchingSamples[0]
# collections
self.collections = [x.strip() for x in opts.addCollections.split(',') if len(x.strip()) > 0] if len(opts.addCollections.strip())>0 else []
if len(self.collections) < 1:
print "\x1b[31mWARNING: no collections added! Specify the collections to add with the --addCollections option!\x1b[0m"
print 'collections to add:', self.collections
self.collections = self.parseCollectionList(self.collections)
print 'after parsing:', self.collections
# temorary folder to save the files of this job on the scratch
temporaryName = self.sample.identifier + '/' + uuid.uuid4().hex
# input files
self.subJobs = []
if opts.join:
print("INFO: join input files! This is an experimental feature!")
# translate naming convention of .txt file to imported files after the prep step
inputFileNamesAfterPrep = [self.fileLocator.getFilenameAfterPrep(x) for x in self.filelist]
self.subJobs.append({
'inputFileNames': self.filelist,
'localInputFileNames': ["{path}/{subfolder}/{filename}".format(path=self.pathIN, subfolder=self.sample.identifier, filename=localFileName) for localFileName in inputFileNamesAfterPrep],
'outputFileName': "{path}/{subfolder}/{filename}".format(path=self.pathOUT, subfolder=self.sample.identifier, filename=inputFileNamesAfterPrep[0]),
'tmpFileName': "{path}/{subfolder}/{filename}".format(path=self.tmpDir, subfolder=temporaryName, filename=inputFileNamesAfterPrep[0]),
})
else:
# create separate subjob for all files (default!)
for inputFileName in self.filelist:
inputFileNamesAfterPrep = [self.fileLocator.getFilenameAfterPrep(inputFileName)]
self.subJobs.append({
'inputFileNames': [inputFileName],
'localInputFileNames': ["{path}/{subfolder}/{filename}".format(path=self.pathIN, subfolder=self.sample.identifier, filename=localFileName) for localFileName in inputFileNamesAfterPrep],
'outputFileName': "{path}/{subfolder}/{filename}".format(path=self.pathOUT, subfolder=self.sample.identifier, filename=inputFileNamesAfterPrep[0]),
'tmpFileName': "{path}/{subfolder}/{filename}".format(path=self.tmpDir, subfolder=temporaryName, filename=inputFileNamesAfterPrep[0]),
})
# lists of single modules can be given instead of a module, "--addCollections Sys.all"
# [Sys]
# all = ['Sys.Vtype', 'Sys.Leptons', ...]
# TODO: make it fully recursive
def parseCollectionList(self, collections):
collectionsListsReplaced = []
for collection in collections:
if '.' in collection:
section = collection.split('.')[0]
key = collection.split('.')[1]
listExpression = self.config.get(section, key).strip()
if listExpression.startswith('[') and listExpression.endswith(']'):
listParsed = eval(listExpression)
for i in listParsed:
collectionsListsReplaced.append(i)
else:
collectionsListsReplaced.append(collection)
else:
collectionsListsReplaced.append(collection)
#.........这里部分代码省略.........
示例13: BetterConfigParser
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
parser.add_option("-M", "--max-events", dest='maxEvents', default=10000,
help="max number of events per file. Default 10000")
(opts, args) = parser.parse_args(argv)
if opts.config =="":
opts.config = "config"
config = BetterConfigParser()
config.read(opts.config)
import ROOT
ROOT.gROOT.SetBatch(True)
namelistIN=opts.samples
namelist=namelistIN.split(',')
samplesinfo=config.get('Directories','samplesinfo')
INpath=config.get('Directories','samplepath')+'/envW/sys/'
OUTpath=INpath # for the moemnt OUTpath = INpath ->> TO FIX
info = parse_info(samplesinfo,INpath)
for job in info:
if eval(job.active):
if job.name in namelist:
#get trees:
print INpath+'/'+job.prefix+job.identifier+'.root'
sourceFile = ROOT.TFile.Open(INpath+'/'+job.prefix+job.identifier+'.root','read')
Tree = sourceFile.Get('tree')
obj = ROOT.TObject
nentries = Tree.GetEntries()
print nentries
示例14: BetterConfigParser
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
opts.config = "config"
from myutils import BetterConfigParser, printc, ParseInfo, mvainfo, StackMaker, HistoMaker
print opts.config
opts.config.append('heppy13TeVconfig/vhbbPlotDef.ini')
config = BetterConfigParser()
config.read(opts.config)
#path = opts.path
region = opts.region
# additional blinding cut:
addBlindingCut = None
if config.has_option('Plot_general','addBlindingCut'):
addBlindingCut = config.get('Plot_general','addBlindingCut')
print 'adding add. blinding cut'
#get locations:
Wdir=config.get('Directories','Wdir')
samplesinfo=config.get('Directories','samplesinfo')
path = config.get('Directories','plottingSamples')
section='Plot:%s'%region
info = ParseInfo(samplesinfo,path)
#----------Histo from trees------------
def doPlot():
vars = (config.get(section, 'vars')).split(',')
示例15: BetterConfigParser
# 需要导入模块: from myutils import BetterConfigParser [as 别名]
# 或者: from myutils.BetterConfigParser import get [as 别名]
# opts.config.append('13TeVconfig/vhbbPlotDef.ini')
# print 'Plot Config List: ',opts.config
config = BetterConfigParser()
config.read(opts.config)
# path = opts.path
region = opts.region
batch = opts.batch
print batch
# additional blinding cut:
addBlindingCut = None
if config.has_option("Plot_general", "addBlindingCut"):
addBlindingCut = config.get("Plot_general", "addBlindingCut")
print "adding add. blinding cut"
# get locations:
Wdir = config.get("Directories", "Wdir")
# the samples_nosplit.cfg file in 13TeV
samplesinfo = config.get("Directories", "samplesinfo")
# which directory to take the samples from(sys_out currently)
path = config.get("Directories", "plottingSamples")
# Add external macros
# For batch jobs lock the compliation
# lock = Lock()