diff options
author | Mac Mollison <mollison@cs.unc.edu> | 2009-02-01 15:39:05 -0500 |
---|---|---|
committer | Mac Mollison <mollison@cs.unc.edu> | 2009-02-01 15:39:05 -0500 |
commit | 8471eb80c262a6ad66b4c20effaaf3a59adf9aef (patch) | |
tree | a4112432d484dc76a271d9cf12e2a447b59e1eb1 | |
parent | 645d2388371d97cd106f6e68cd9ef7a722010166 (diff) |
Created Trace object
-rwxr-xr-x | sta.py | 36 |
1 files changed, 18 insertions, 18 deletions
@@ -10,24 +10,24 @@ from sta_output import * | |||
10 | from sta_types import * | 10 | from sta_types import * |
11 | 11 | ||
12 | 12 | ||
13 | |||
14 | |||
15 | ################## | 13 | ################## |
16 | # Business logic # | 14 | # Business logic # |
17 | ################## | 15 | ################## |
18 | 16 | class Trace: | |
19 | def trace_iter(files): | 17 | def __init__(self,files): |
20 | """Returns an iterator for iterating over trace(s) and producing records.""" | 18 | self.iter = self.make_iter(files) |
21 | for file in files: | 19 | def make_iter(self, files): |
22 | f = open(file,'rb') | 20 | for file in files: |
23 | while True: | 21 | f = open(file,'rb') |
24 | try: | 22 | while True: |
25 | data = f.read(st_record_size) | 23 | try: |
26 | typenum = struct.unpack_from('<b',data)[0] | 24 | data = f.read(st_record_size) |
27 | type = get_type(typenum) | 25 | typenum = struct.unpack_from('<b',data)[0] |
28 | values = struct.unpack_from(StHeader.format + type.format,data) | 26 | type = get_type(typenum) |
29 | record = dict(zip(type.keys,values)) | 27 | values = struct.unpack_from(StHeader.format + |
30 | yield record | 28 | type.format,data) |
31 | except struct.error: | 29 | record = dict(zip(type.keys,values)) |
32 | f.close() | 30 | yield record |
33 | break | 31 | except struct.error: |
32 | f.close() | ||
33 | break | ||