Package PyFoam :: Package LogAnalysis :: Module GeneralLineAnalyzer
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.LogAnalysis.GeneralLineAnalyzer

  1  #  ICE Revision: $Id: /local/openfoam/Python/PyFoam/PyFoam/LogAnalysis/GeneralLineAnalyzer.py 7014 2010-11-21T23:14:21.485436Z bgschaid  $  
  2  """Line analyzer with output and the capability to store lines""" 
  3   
  4  from LogLineAnalyzer import LogLineAnalyzer 
  5  from PyFoam.Basics.OutFileCollection import OutFileCollection 
  6  from PyFoam.Basics.TimeLineCollection import TimeLineCollection 
  7   
8 -class GeneralLineAnalyzer(LogLineAnalyzer):
9 """Base class for analyzers that write data to files and store time-lines 10 11 Combines the capabilities of TimeLineLineAnalyzer and FileLineAnalyzer""" 12
13 - def __init__(self, 14 doTimelines=False, 15 doFiles=False, 16 titles=[], 17 accumulation=None, 18 singleFile=False, 19 progressTemplate=None, 20 startTime=None, 21 endTime=None):
22 """ 23 @param titles: The titles of the data elements 24 @param progressTemplate: Progress output to be reported 25 """ 26 LogLineAnalyzer.__init__(self) 27 28 self.doTimelines=doTimelines 29 self.doFiles=doFiles 30 self.singleFile=singleFile 31 32 self.files=None 33 self.titles=titles 34 35 self.setTitles(titles) 36 37 accu="first" 38 if accumulation!=None: 39 accu=accumulation 40 if self.doTimelines: 41 self.lines=TimeLineCollection(accumulation=accu) 42 else: 43 self.lines=None 44 45 self.startTime=startTime 46 self.endTime=endTime 47 48 self.master=None 49 50 self.didProgress=False 51 self.progressTemplate=progressTemplate
52
53 - def setMaster(self,master):
54 """Assign another line-analyzer that will do the actual data gathering""" 55 self.master=master 56 if self.lines and self.master.lines: 57 self.master.lines.addSlave(self.lines)
58
59 - def setTitles(self,titles):
60 """ 61 Sets the titles anew 62 @param titles: the new titles 63 """ 64 if self.doFiles: 65 self.titles=titles 66 if self.files!=None: 67 self.files.setTitles(titles)
68
69 - def setDirectory(self,oDir):
70 """Creates the OutFileCollection-object""" 71 if self.doFiles: 72 self.files=OutFileCollection(oDir, 73 titles=self.titles, 74 singleFile=self.singleFile) 75 else: 76 self.files=None
77
78 - def timeChanged(self):
79 """Sets the current time in the timelines""" 80 if self.doTimelines: 81 try: 82 time=float(self.getTime()) 83 if (self.startTime==None or time>=self.startTime) and (self.endTime==None or time<=self.endTime): 84 self.lines.setTime(self.getTime()) 85 except ValueError: 86 pass 87 self.didProgress=False
88
89 - def getTimeline(self,name):
90 """@param name: Name of the timeline to return 91 @return: the timeline as two list: the times and the values""" 92 if self.doTimelines: 93 return self.lines.getTimes(),self.lines.getValues(name) 94 else: 95 return [],[]
96
97 - def doAnalysis(self,line):
98 """General analysis method. Derived classes should instead override callbacks""" 99 100 m=self.exp.match(line) 101 if m!=None: 102 self.startAnalysis(m) 103 104 if self.doTimelines: 105 try: 106 time=float(self.getTime()) 107 if (self.startTime==None or time>=self.startTime) and (self.endTime==None or time<=self.endTime): 108 self.addToTimelines(m) 109 except ValueError: 110 pass 111 if self.doFiles: 112 self.addToFiles(m) 113 114 self.endAnalysis(m) 115 116 if not self.didProgress and self.progressTemplate: 117 myProgress=self.progressTemplate 118 for i,g in enumerate(m.groups()): 119 myProgress=myProgress.replace("$%d" % i,g) 120 self.writeProgress(myProgress) 121 122 self.didProgress=False
123
124 - def startAnalysis(self,match):
125 """Method at the start of a successfull match""" 126 pass
127
128 - def endAnalysis(self,match):
129 """Method at the end of a successfull match""" 130 pass
131
132 - def addToTimelines(self,match):
133 """Method that adds matched data to timelines 134 135 @param match: data matched by a regular expression""" 136 137 pass
138
139 - def addToFiles(self,match):
140 """Method that adds matched data to files 141 142 @param match: data matched by a regular expression""" 143 144 pass
145
146 - def tearDown(self):
147 """Closes files""" 148 LogLineAnalyzer.tearDown(self) 149 150 if self.files!=None: 151 self.files.close()
152