Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:14

0001 class filereader:
0002 
0003     def __init__(self):
0004         self.aList=['Module', 'ESSource']
0005 
0006     def startswith(self,line):
0007         "Checks if the first word of the line starts with any of the aList elements"
0008         for item in self.aList:
0009             if line.startswith(item):
0010                 return True
0011         return False    
0012 
0013     def readfile(self,nomefile):
0014         "Reads the file line by line and searches for the begin and the end of each Module block"       
0015         aFile = open(nomefile)
0016         module = []
0017         source = []
0018         file_modules = {}
0019         insideModuleBlock = False
0020         insideParameterBlock = False
0021         for line in aFile.readlines():
0022             if self.startswith(line):
0023                 if  insideParameterBlock:
0024                     file_modules[key]=module
0025                     insideParameterBlock = False
0026                     #print line[:-1]
0027                 module=[]
0028                 module.append(line[:-1])
0029                 key=line[line.index(':')+2:-1]
0030                 #print key
0031                 insideModuleBlock = True
0032                 insideParameterBlock = False
0033             elif (line.startswith(' parameters')) and insideModuleBlock:
0034                 insideParameterBlock = True
0035                 module.append(line[:-1])
0036                 #print line[:-1]
0037             elif line.startswith('ESModule') and insideParameterBlock:
0038                 file_modules[key]=module
0039                 insideParameterBlock = False
0040                 insideModuleBlock = False
0041             elif (insideParameterBlock):
0042                 module.append(line[:-1])
0043                 #print line[:-1]
0044 
0045         
0046         return file_modules 
0047