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 1536 of file trfUtils.py.

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

◆ 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  fields = [''.join(filter(str.isprintable, field)) for field in fields]
1514  if firstline:
1515  firstline = False
1516  tabledict, keylist = self._defineTableDictKeys(header, fields, separator)
1517  if not header:
1518  continue
1519  # from now on, fill the dictionary fields with the input data
1520  i = 0
1521  for field in fields:
1522  # get the corresponding dictionary key from the keylist
1523  key = keylist[i]
1524  # store the field value in the correct list
1525  tabledict[key].append(float(field))
1526  i += 1
1527  f.close()
1528 
1529  return tabledict
1530 

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
covarianceTool.filter
filter
Definition: covarianceTool.py:514
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
Trk::open
@ open
Definition: BinningType.h:40
python.LArMinBiasAlgConfig.float
float
Definition: LArMinBiasAlgConfig.py:65