CMS 3D CMS Logo

normFileParser.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import ConfigParser,os.path
3 
4 #################################
5 #norm file format spec
6 #lines beginning with a semicolon ';' a pound sign '#' or the letters 'REM' (uppercase or lowercase) will be ignored.
7 #section uppercase
8 # [NORMDEFINITION] #section required only if first create
9 # name=HFtest #priority to commandline --name option if present
10 # comment=
11 # lumitype=
12 # istypedefault=
13 # [NORMDATA Since] # section required
14 # since=
15 # corrector=
16 # norm_occ1=
17 # norm_occ2=
18 # amodetag=
19 # egev=
20 # comment=
21 # ...
22 #################################
23 
25  def __init__(self,filename):
26  self.__parser=ConfigParser.ConfigParser()
27  self.__inifilename=filename
28  self.__defsectionname='NormDefinition'
29  self.__datasectionname='NormData'
30  def parse(self):
31  '''
32  output:
33  [ {defoption:value},[{dataoption:value}] ]
34  '''
35  if not os.path.exists(self.__inifilename) or not os.path.isfile(self.__inifilename):
36  raise ValueError(self.__inifilename+' is not a file or does not exist')
37  self.__parser.read(self.__inifilename)
38  result=[]
39  defsectionResult={}
40  datasectionResult=[]
41  sections=self.__parser.sections()
42  for section in sections:
43  thisectionresult={}
44  options=self.__parser.options(section)
45  for o in options:
46  try:
47  thisectionresult[o]=self.__parser.get(section,o)
48  except:
49  continue
50  if section==self.__defsectionname:
51  defsectionResult=thisectionresult
52  elif self.__datasectionname in section:
53  datasectionResult.append(thisectionresult)
54  return [defsectionResult,datasectionResult]
55 
56 if __name__ == "__main__":
57  s='../test/norm_HFV2.cfg'
58  parser=normFileParser(s)
59  print(parser.parse())
60 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def __init__(self, filename)
norm file format spec lines beginning with a semicolon ';' a pound sign '#' or the letters 'REM' (upp...