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

Source Code for Module PyFoam.LogAnalysis.GeneralLineAnalyzer

  1  #  ICE Revision: $Id: GeneralLineAnalyzer.py 8292 2007-12-12 15:22:00Z 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,doTimelines=False,doFiles=False,titles=[]):
14 """ 15 @param titles: The titles of the data elements 16 """ 17 LogLineAnalyzer.__init__(self) 18 19 self.doTimelines=doTimelines 20 self.doFiles=doFiles 21 22 self.files=None 23 self.titles=titles 24 25 self.setTitles(titles) 26 if self.doTimelines: 27 self.lines=TimeLineCollection() 28 else: 29 self.lines=None
30
31 - def setTitles(self,titles):
32 """ 33 Sets the titles anew 34 @param titles: the new titles 35 """ 36 if self.doFiles: 37 self.titles=titles 38 if self.files!=None: 39 self.files.setTitles(titles)
40
41 - def setDirectory(self,oDir):
42 """Creates the OutFileCollection-object""" 43 if self.doFiles: 44 self.files=OutFileCollection(oDir,titles=self.titles) 45 else: 46 self.files=None
47
48 - def timeChanged(self):
49 """Sets the current time in the timelines""" 50 if self.doTimelines: 51 self.lines.setTime(self.getTime())
52
53 - def getTimeline(self,name):
54 """@param name: Name of the timeline to return 55 @return: the timeline as two list: the times and the values""" 56 if self.doTimelines: 57 return self.lines.getTimes(),self.lines.getValues(name) 58 else: 59 return [],[]
60
61 - def doAnalysis(self,line):
62 """General analysis method. Derived classes should instead override callbacks""" 63 64 m=self.exp.match(line) 65 if m!=None: 66 self.startAnalysis(m) 67 68 if self.doTimelines: 69 self.addToTimelines(m) 70 if self.doFiles: 71 self.addToFiles(m) 72 73 self.endAnalysis(m)
74
75 - def startAnalysis(self,match):
76 """Method at the start of a successfull match""" 77 pass
78
79 - def endAnalysis(self,match):
80 """Method at the end of a successfull match""" 81 pass
82
83 - def addToTimelines(self,match):
84 """Method that adds matched data to timelines 85 86 @param match: data matched by a regular expression""" 87 88 pass
89
90 - def addToFiles(self,match):
91 """Method that adds matched data to files 92 93 @param match: data matched by a regular expression""" 94 95 pass
96
97 - def tearDown(self):
98 """Closes files""" 99 LogLineAnalyzer.tearDown(self) 100 101 if self.files!=None: 102 self.files.close()
103