test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
read_provenance.py
Go to the documentation of this file.
1 class filereader:
2 
3  def __init__(self):
4  self.aList=['Module', 'ESSource']
5 
6  def startswith(self,line):
7  "Checks if the first word of the line starts with any of the aList elements"
8  for item in self.aList:
9  if line.startswith(item):
10  return True
11  return False
12 
13  def readfile(self,nomefile):
14  "Reads the file line by line and searches for the begin and the end of each Module block"
15  aFile = open(nomefile)
16  module = []
17  source = []
18  file_modules = {}
19  insideModuleBlock = False
20  insideParameterBlock = False
21  for line in aFile.readlines():
22  if self.startswith(line):
23  if insideParameterBlock:
24  file_modules[key]=module
25  insideParameterBlock = False
26  #print line[:-1]
27  module=[]
28  module.append(line[:-1])
29  key=line[line.index(':')+2:-1]
30  #print key
31  insideModuleBlock = True
32  insideParameterBlock = False
33  elif (line.startswith(' parameters')) and insideModuleBlock:
34  insideParameterBlock = True
35  module.append(line[:-1])
36  #print line[:-1]
37  elif line.startswith('ESModule') and insideParameterBlock:
38  file_modules[key]=module
39  insideParameterBlock = False
40  insideModuleBlock = False
41  elif (insideParameterBlock):
42  module.append(line[:-1])
43  #print line[:-1]
44 
45 
46  return file_modules
47