ATLAS Offline Software
Public Member Functions | Private Member Functions | List of all members
python.trfUtils.memFileToTable Class Reference

Extract a table of data from a txt file. More...

Collaboration diagram for python.trfUtils.memFileToTable:

Public Member Functions

def getTable (self, filename, header=None, separator="\t")
 

Private Member Functions

def _defineTableDictKeys (self, header, fields, separator)
 Define the keys for the tabledict dictionary. More...
 

Detailed Description

Extract a table of data from a txt file.

E.g. header="Time nprocs nthreads wtime stime utime pss rss swap vmem" or the first line in the file each of which will become keys in the dictionary, whose corresponding values are stored in lists, with the entries corresponding to the values in the rows of the input file. The output dictionary will have the format {'Time': [ .. data from first row .. ], 'VMEM': [.. data from second row], ..}

Parameters
filenamename of input text file, full path (string).
headerheader string.
separatorseparator character (char).
Returns
dictionary.

Definition at line 1500 of file trfUtils.py.

Member Function Documentation

◆ _defineTableDictKeys()

def python.trfUtils.memFileToTable._defineTableDictKeys (   self,
  header,
  fields,
  separator 
)
private

Define the keys for the tabledict dictionary.

Parameters
headerheader string.
fieldsheader content string.
separatorseparator character (char).
Returns
tabledict (dictionary), keylist (ordered list with dictionary key names).

Definition at line 1535 of file trfUtils.py.

1535  def _defineTableDictKeys(self, header, fields, separator):
1536  tabledict = {}
1537  keylist = []
1538 
1539  if not header:
1540  # get the dictionary keys from the header of the file
1541  for key in fields:
1542  # first line defines the header, whose elements will be used as dictionary keys
1543  if key == '':
1544  continue
1545  if key.endswith('\n'):
1546  key = key[:-1]
1547  tabledict[key] = []
1548  keylist.append(key)
1549  else:
1550  # get the dictionary keys from the provided header
1551  keys = header.split(separator)
1552  for key in keys:
1553  if key == '':
1554  continue
1555  if key.endswith('\n'):
1556  key = key[:-1]
1557  tabledict[key] = []
1558  keylist.append(key)
1559 
1560  return tabledict, keylist
1561 
1562 

◆ getTable()

def python.trfUtils.memFileToTable.getTable (   self,
  filename,
  header = None,
  separator = "\t" 
)

Definition at line 1502 of file trfUtils.py.

1502  def getTable(self, filename, header=None, separator="\t"):
1503  tabledict = {}
1504  keylist = []
1505  try:
1506  f = open(filename, 'r')
1507  except Exception as e:
1508  msg.warning("failed to open file: {0}, {1}".format(filename, e))
1509  else:
1510  firstline = True
1511  for line in f:
1512  fields = line.split(separator)
1513  if firstline:
1514  firstline = False
1515  tabledict, keylist = self._defineTableDictKeys(header, fields, separator)
1516  if not header:
1517  continue
1518  # from now on, fill the dictionary fields with the input data
1519  i = 0
1520  for field in fields:
1521  # get the corresponding dictionary key from the keylist
1522  key = keylist[i]
1523  # store the field value in the correct list
1524  tabledict[key].append(float(field))
1525  i += 1
1526  f.close()
1527 
1528  return tabledict
1529 

The documentation for this class was generated from the following file:
vtune_athena.format
format
Definition: vtune_athena.py:14
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
Trk::open
@ open
Definition: BinningType.h:40
readCCLHist.float
float
Definition: readCCLHist.py:83