28 def readData(self):
29
30 self.data = None
31 if self.infile is None:
32 print(
'TurnDataReader.readData() called with infile == None!')
33 return self.data
34
35
36 try:
37 f = open(self.infile, 'r')
38 except IOError as e:
39 print(
'Error opening file', self.infile)
41 return self.data
42
43
44 self.data = dict()
45
46
47
48
49 matchlb = re.compile(r'^([0-9]+) (\S+) (\S+)$')
50
51
52 matchalg = re.compile(r'^(\S+)$')
53
54
55 algId = None
56
57 for line in f.readlines():
58
59 if self.verbose:
print(line, end=
' ')
60
61 m = matchlb.search(line)
62 if m:
63 if self.verbose:
print(
'Found data record match:', m.group(1), m.group(2), m.group(3))
64 lb = int(m.group(1))
65
66 lb -= 1
67
68 if m.group(2) == 'nan':
69 counts = 0.
70 else:
71 counts = float(m.group(2))
72
73 if m.group(3) == 'nan':
74 turns = 0.
75 else:
76 turns = float(m.group(3))
77
78
79 if algId is None:
80 print(
'TurnDataReader.readData() found data record with no algorithm defined in', self.infile)
82 sys.exit()
83
84
85 if lb not in self.data:
86 self.data[lb] = dict()
87
88 self.data[lb][algId] = (turns, counts)
89
90 if self.verbose:
91 print(
'Alg:', algId,
'LB:', lb,
'Turns:', turns,
'Counts:', counts)
92 continue
93
94 m = matchalg.search(line)
95 if m:
96 if self.verbose:
print(
'Found new algorithm:', m.group(1))
97
98
99 algId = m.group(1)
100 if algId is None:
101 print(
'TurnDataReader.readData() found unrecognized algorithm name in', self.infile)
103 sys.exit()
104
105 f.close()
106 return self.data
107
108
void print(char *figname, TCanvas *c1)