Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 import copy
0003 
0004 class filereader:
0005 
0006     class Module:
0007         def __init__(self,label='',value=[]):
0008             self.label=label
0009             self.value=value
0010 
0011     def __init__(self):
0012         self.aList=['Module', 'ESSource']
0013         
0014     def startswith(self,line):
0015         "Checks if the first word of the line starts with any of the aList elements"
0016         for item in self.aList:
0017             if line.startswith(item):
0018                 return True
0019         return False    
0020 
0021     def readfile(self,nomefile):
0022         "Reads the file line by line and searches for the begin and the end of each Module block"       
0023         aFile = open(nomefile)
0024         module=[]
0025         value=[]
0026         file_modules = {}
0027         processHistory=False
0028         processing=False
0029         insideModuleBlock = False
0030         insideParameterBlock = False
0031         nprocess=-1
0032         key=''
0033         for line in aFile.readlines():
0034             if line.startswith("Processing History:"):
0035                 value=[]
0036                 processHistory=True
0037             elif (not line.startswith('---------Event')) and processHistory:
0038                 splitLine= line.split()
0039                 if splitLine[3]=='[2]':
0040                     processing=True
0041                     value.append(line)
0042                 elif  processing:
0043                     value.append(line)
0044             elif line.startswith('---------Event') and processing:
0045                 file_modules['Processing']=value
0046                 processHistory=False
0047                 processing=False
0048             elif self.startswith(line):
0049                 if  insideParameterBlock:
0050                     module.append(tuple(value))
0051                     file_modules[key].append(module)
0052                     insideParameterBlock = False
0053                     insideModuleBlock = False  ###controllare
0054                 value=[]
0055                 module=[]
0056                 splitLine= line.split()
0057                 key=splitLine[-1]
0058                 if key not in file_modules.keys():
0059                     file_modules[key]=[]
0060                 module.append(splitLine[-2])
0061                 value.append(line[:-1])
0062                 insideModuleBlock = True
0063                 insideParameterBlock = False
0064             elif (line.startswith(' parameters')) and insideModuleBlock:
0065                 insideParameterBlock = True
0066                 value.append(line[:-1])
0067             elif line.startswith('ESModule') and insideParameterBlock:
0068                 module.append(tuple(value))
0069                 file_modules[key].append(module)
0070                 insideParameterBlock = False
0071                 insideModuleBlock = False
0072             #elif line=='}' and insideParameterBlock:
0073                 #module.append(tuple(value))
0074                 #file_modules[key].append(module)
0075                 #insideParameterBlock = False
0076                 #insideModuleBlock = False
0077             elif (insideParameterBlock):
0078                 value.append(line[:-1])
0079             
0080         if   insideParameterBlock:
0081             module.append(tuple(value))
0082             file_modules[key].append(module)
0083             insideParameterBlock = False
0084             insideModuleBlock = False 
0085 
0086         
0087         return file_modules 
0088