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

Source Code for Module PyFoam.LogAnalysis.GeneralLineAnalyzer

 1  """Line analyzer with output and the capability to store lines""" 
 2   
 3  from LogLineAnalyzer import LogLineAnalyzer 
 4  from PyFoam.Basics.OutFileCollection import OutFileCollection 
 5  from PyFoam.Basics.TimeLineCollection import TimeLineCollection 
 6   
7 -class GeneralLineAnalyzer(LogLineAnalyzer):
8 """Base class for analyzers that write data to files and store time-lines 9 10 Combines the capabilities of TimeLineLineAnalyzer and FileLineAnalyzer""" 11
12 - def __init__(self,doTimelines=False,doFiles=False,titles=[]):
13 """ 14 @param titles: The titles of the data elements 15 """ 16 LogLineAnalyzer.__init__(self) 17 18 self.doTimelines=doTimelines 19 self.doFiles=doFiles 20 21 self.files=None 22 self.titles=titles 23 24 self.setTitles(titles) 25 if self.doTimelines: 26 self.lines=TimeLineCollection() 27 else: 28 self.lines=None
29
30 - def setTitles(self,titles):
31 """ 32 Sets the titles anew 33 @param titles: the new titles 34 """ 35 if self.doFiles: 36 self.titles=titles 37 if self.files!=None: 38 self.files.setTitles(titles)
39
40 - def setDirectory(self,oDir):
41 """Creates the OutFileCollection-object""" 42 if self.doFiles: 43 self.files=OutFileCollection(oDir,titles=self.titles) 44 else: 45 self.files=None
46
47 - def timeChanged(self):
48 """Sets the current time in the timelines""" 49 if self.doTimelines: 50 self.lines.setTime(self.getTime())
51
52 - def getTimeline(self,name):
53 """@param name: Name of the timeline to return 54 @return: the timeline as two list: the times and the values""" 55 if self.doTimelines: 56 return self.lines.getTimes(),self.lines.getValues(name) 57 else: 58 return [],[]
59
60 - def doAnalysis(self,line):
61 """General analysis method. Derived classes should instead override callbacks""" 62 63 m=self.exp.match(line) 64 if m!=None: 65 self.startAnalysis(m) 66 67 if self.doTimelines: 68 self.addToTimelines(m) 69 if self.doFiles: 70 self.addToFiles(m) 71 72 self.endAnalysis(m)
73
74 - def startAnalysis(self,match):
75 """Method at the start of a successfull match""" 76 pass
77
78 - def endAnalysis(self,match):
79 """Method at the end of a successfull match""" 80 pass
81
82 - def addToTimelines(self,match):
83 """Method that adds matched data to timelines 84 85 @param match: data matched by a regular expression""" 86 87 pass
88
89 - def addToFiles(self,match):
90 """Method that adds matched data to files 91 92 @param match: data matched by a regular expression""" 93 94 pass
95