CMS 3D CMS Logo

readProv.py
Go to the documentation of this file.
1 
2 import copy
3 
4 class filereader:
5 
6  class Module:
7  def __init__(self,label='',value=[]):
8  self.label=label
9  self.value=value
10 
11  def __init__(self):
12  self.aList=['Module', 'ESSource']
13 
14  def startswith(self,line):
15  "Checks if the first word of the line starts with any of the aList elements"
16  for item in self.aList:
17  if line.startswith(item):
18  return True
19  return False
20 
21  def readfile(self,nomefile):
22  "Reads the file line by line and searches for the begin and the end of each Module block"
23  aFile = open(nomefile)
24  module=[]
25  value=[]
26  file_modules = {}
27  processHistory=False
28  processing=False
29  insideModuleBlock = False
30  insideParameterBlock = False
31  nprocess=-1
32  key=''
33  for line in aFile.readlines():
34  if line.startswith("Processing History:"):
35  value=[]
36  processHistory=True
37  elif (not line.startswith('---------Event')) and processHistory:
38  splitLine= line.split()
39  if splitLine[3]=='[2]':
40  processing=True
41  value.append(line)
42  elif processing:
43  value.append(line)
44  elif line.startswith('---------Event') and processing:
45  file_modules['Processing']=value
46  processHistory=False
47  processing=False
48  elif self.startswith(line):
49  if insideParameterBlock:
50  module.append(tuple(value))
51  file_modules[key].append(module)
52  insideParameterBlock = False
53  insideModuleBlock = False
54  value=[]
55  module=[]
56  splitLine= line.split()
57  key=splitLine[-1]
58  if key not in file_modules.keys():
59  file_modules[key]=[]
60  module.append(splitLine[-2])
61  value.append(line[:-1])
62  insideModuleBlock = True
63  insideParameterBlock = False
64  elif (line.startswith(' parameters')) and insideModuleBlock:
65  insideParameterBlock = True
66  value.append(line[:-1])
67  elif line.startswith('ESModule') and insideParameterBlock:
68  module.append(tuple(value))
69  file_modules[key].append(module)
70  insideParameterBlock = False
71  insideModuleBlock = False
72  #elif line=='}' and insideParameterBlock:
73  #module.append(tuple(value))
74  #file_modules[key].append(module)
75  #insideParameterBlock = False
76  #insideModuleBlock = False
77  elif (insideParameterBlock):
78  value.append(line[:-1])
79 
80  if insideParameterBlock:
81  module.append(tuple(value))
82  file_modules[key].append(module)
83  insideParameterBlock = False
84  insideModuleBlock = False
85 
86 
87  return file_modules
88 
def readfile(self, nomefile)
Definition: readProv.py:21
def __init__(self, label='', value=[])
Definition: readProv.py:7
def startswith(self, line)
Definition: readProv.py:14