ATLAS Offline Software
Loading...
Searching...
No Matches
python.TurnDataReader.TurnDataReader Class Reference
Collaboration diagram for python.TurnDataReader.TurnDataReader:

Public Member Functions

 __init__ (self, infile=None)
 readData (self)

Public Attributes

bool verbose = False
 infile = infile
 data = None

Detailed Description

Definition at line 15 of file TurnDataReader.py.

Constructor & Destructor Documentation

◆ __init__()

python.TurnDataReader.TurnDataReader.__init__ ( self,
infile = None )

Definition at line 17 of file TurnDataReader.py.

17 def __init__(self, infile=None):
18
19 self.verbose = False
20
21 # File to read data from
22 self.infile = infile
23
24 # dict keyed by pseudoLB number containing dict by algorithm with data Tuple
25 # (turns, counts) = self.data[lb][algName]
26 self.data = None
27

Member Function Documentation

◆ readData()

python.TurnDataReader.TurnDataReader.readData ( self)

Definition at line 28 of file TurnDataReader.py.

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 # Open input file
36 try:
37 f = open(self.infile, 'r')
38 except IOError as e:
39 print('Error opening file', self.infile)
40 print(e)
41 return self.data
42
43 # Initialize our new dictionary
44 self.data = dict()
45
46 # Must parse lines looking for either LB records or algorithm type
47
48 # pseudoLB record (number followed by two text records
49 matchlb = re.compile(r'^([0-9]+) (\S+) (\S+)$')
50
51 # algorithm name (only thing on the line)
52 matchalg = re.compile(r'^(\S+)$')
53
54 # Current algorithm read in file
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 # Hack to realign these properly. This will probably bite us in the ass someday
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 # Do we have a valid algorithm?
79 if algId is None:
80 print('TurnDataReader.readData() found data record with no algorithm defined in', self.infile)
81 print(line)
82 sys.exit()
83
84 # save data
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 # Decode Nitesh's into my values, just hardcode here
99 algId = m.group(1)
100 if algId is None:
101 print('TurnDataReader.readData() found unrecognized algorithm name in', self.infile)
102 print(line)
103 sys.exit()
104
105 f.close()
106 return self.data
107
108# Test by running from command line
void print(char *figname, TCanvas *c1)

Member Data Documentation

◆ data

python.TurnDataReader.TurnDataReader.data = None

Definition at line 26 of file TurnDataReader.py.

◆ infile

python.TurnDataReader.TurnDataReader.infile = infile

Definition at line 22 of file TurnDataReader.py.

◆ verbose

bool python.TurnDataReader.TurnDataReader.verbose = False

Definition at line 19 of file TurnDataReader.py.


The documentation for this class was generated from the following file: