ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.TurnDataReader.TurnDataReader Class Reference
Collaboration diagram for python.TurnDataReader.TurnDataReader:

Public Member Functions

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

Public Attributes

 verbose
 
 infile
 
 data
 

Detailed Description

Definition at line 16 of file TurnDataReader.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 18 of file TurnDataReader.py.

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

Member Function Documentation

◆ readData()

def python.TurnDataReader.TurnDataReader.readData (   self)

Definition at line 29 of file TurnDataReader.py.

29  def readData(self):
30 
31  self.data = None
32  if self.infile is None:
33  print('TurnDataReader.readData() called with infile == None!')
34  return self.data
35 
36  # Open input file
37  try:
38  f = open(self.infile, 'r')
39  except IOError as e:
40  print('Error opening file', self.infile)
41  print(e)
42  return self.data
43 
44  # Initialize our new dictionary
45  self.data = dict()
46 
47  # Must parse lines looking for either LB records or algorithm type
48 
49  # pseudoLB record (number followed by two text records
50  matchlb = re.compile(r'^([0-9]+) (\S+) (\S+)$')
51 
52  # algorithm name (only thing on the line)
53  matchalg = re.compile(r'^(\S+)$')
54 
55  # Current algorithm read in file
56  algId = None
57 
58  for line in f.readlines():
59 
60  if self.verbose: print(line, end=' ')
61 
62  m = matchlb.search(line)
63  if m:
64  if self.verbose: print('Found data record match:', m.group(1), m.group(2), m.group(3))
65  lb = int(m.group(1))
66  # Hack to realign these properly. This will probably bite us in the ass someday
67  lb -= 1
68 
69  if m.group(2) == 'nan':
70  counts = 0.
71  else:
72  counts = float(m.group(2))
73 
74  if m.group(3) == 'nan':
75  turns = 0.
76  else:
77  turns = float(m.group(3))
78 
79  # Do we have a valid algorithm?
80  if algId is None:
81  print('TurnDataReader.readData() found data record with no algorithm defined in', self.infile)
82  print(line)
83  sys.exit()
84 
85  # save data
86  if lb not in self.data:
87  self.data[lb] = dict()
88 
89  self.data[lb][algId] = (turns, counts)
90 
91  if self.verbose:
92  print('Alg:', algId, 'LB:', lb, 'Turns:', turns, 'Counts:', counts)
93  continue
94 
95  m = matchalg.search(line)
96  if m:
97  if self.verbose: print('Found new algorithm:', m.group(1))
98 
99  # Decode Nitesh's into my values, just hardcode here
100  algId = m.group(1)
101  if algId is None:
102  print('TurnDataReader.readData() found unrecognized algorithm name in', self.infile)
103  print(line)
104  sys.exit()
105 
106  f.close()
107  return self.data
108 
109 # Test by running from command line

Member Data Documentation

◆ data

python.TurnDataReader.TurnDataReader.data

Definition at line 27 of file TurnDataReader.py.

◆ infile

python.TurnDataReader.TurnDataReader.infile

Definition at line 23 of file TurnDataReader.py.

◆ verbose

python.TurnDataReader.TurnDataReader.verbose

Definition at line 20 of file TurnDataReader.py.


The documentation for this class was generated from the following file:
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
readCCLHist.float
float
Definition: readCCLHist.py:83