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 5448 2009-08-23T19:30:38.116117Z 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 startTime=None, 20 endTime=None):
21 """ 22 @param titles: The titles of the data elements 23 """ 24 LogLineAnalyzer.__init__(self) 25 26 self.doTimelines=doTimelines 27 self.doFiles=doFiles 28 self.singleFile=singleFile 29 30 self.files=None 31 self.titles=titles 32 33 self.setTitles(titles) 34 35 accu="first" 36 if accumulation!=None: 37 accu=accumulation 38 if self.doTimelines: 39 self.lines=TimeLineCollection(accumulation=accu) 40 else: 41 self.lines=None 42 43 self.startTime=startTime 44 self.endTime=endTime 45 46 self.master=None
47
48 - def setMaster(self,master):
49 """Assign another line-analyzer that will do the actual data gathering""" 50 self.master=master 51 if self.lines and self.master.lines: 52 self.master.lines.addSlave(self.lines)
53
54 - def setTitles(self,titles):
55 """ 56 Sets the titles anew 57 @param titles: the new titles 58 """ 59 if self.doFiles: 60 self.titles=titles 61 if self.files!=None: 62 self.files.setTitles(titles)
63
64 - def setDirectory(self,oDir):
65 """Creates the OutFileCollection-object""" 66 if self.doFiles: 67 self.files=OutFileCollection(oDir, 68 titles=self.titles, 69 singleFile=self.singleFile) 70 else: 71 self.files=None
72
73 - def timeChanged(self):
74 """Sets the current time in the timelines""" 75 if self.doTimelines: 76 try: 77 time=float(self.getTime()) 78 if (self.startTime==None or time>=self.startTime) and (self.endTime==None or time<=self.endTime): 79 self.lines.setTime(self.getTime()) 80 except ValueError: 81 pass
82
83 - def getTimeline(self,name):
84 """@param name: Name of the timeline to return 85 @return: the timeline as two list: the times and the values""" 86 if self.doTimelines: 87 return self.lines.getTimes(),self.lines.getValues(name) 88 else: 89 return [],[]
90
91 - def doAnalysis(self,line):
92 """General analysis method. Derived classes should instead override callbacks""" 93 94 m=self.exp.match(line) 95 if m!=None: 96 self.startAnalysis(m) 97 98 if self.doTimelines: 99 try: 100 time=float(self.getTime()) 101 if (self.startTime==None or time>=self.startTime) and (self.endTime==None or time<=self.endTime): 102 self.addToTimelines(m) 103 except ValueError: 104 pass 105 if self.doFiles: 106 self.addToFiles(m) 107 108 self.endAnalysis(m)
109
110 - def startAnalysis(self,match):
111 """Method at the start of a successfull match""" 112 pass
113
114 - def endAnalysis(self,match):
115 """Method at the end of a successfull match""" 116 pass
117
118 - def addToTimelines(self,match):
119 """Method that adds matched data to timelines 120 121 @param match: data matched by a regular expression""" 122 123 pass
124
125 - def addToFiles(self,match):
126 """Method that adds matched data to files 127 128 @param match: data matched by a regular expression""" 129 130 pass
131
132 - def tearDown(self):
133 """Closes files""" 134 LogLineAnalyzer.tearDown(self) 135 136 if self.files!=None: 137 self.files.close()
138