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

Source Code for Module PyFoam.LogAnalysis.GeneralLineAnalyzer

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