ATLAS Offline Software
Public Member Functions | Private Attributes | Static Private Attributes | List of all members
python.trfReports.trfFileReport Class Reference

Class to contain metadata for file types. More...

Inheritance diagram for python.trfReports.trfFileReport:
Collaboration diagram for python.trfReports.trfFileReport:

Public Member Functions

def __init__ (self, fileArg)
 Constructor. More...
 
def python (self, fast=False, type='full')
 Get a python representation of file report @detail Returns the python representation of this file report which is a list of dictionaries (a la Tier 0) More...
 
def singleFilePython (self, filename, fast=False, type='full', basename=True)
 Return unique metadata for a single file in an argFile class. More...
 
def classicEltreeList (self, fast=False)
 Return an element tree representation of the classic file report @detail Returns a list of eltree entities giving the classic metadata of a files for this argument. More...
 
def classicSingleEltree (self, filename, fast=False)
 Return file metadata in 'classic' POOLFILECATALOG format. More...
 
def classicPython (self, fast=False)
 Return file metadata in classic Tier 0 python style. More...
 
def classicSinglePython (self, filename, fast=False)
 Return single file metadata in classic Tier 0 python style. More...
 

Private Attributes

 _fileArg
 

Static Private Attributes

 _internalToClassicMap
 
 _internalToGpickleMap
 
 _internalToGpickleMoreMap
 

Detailed Description

Class to contain metadata for file types.

Definition at line 393 of file trfReports.py.

Constructor & Destructor Documentation

◆ __init__()

def python.trfReports.trfFileReport.__init__ (   self,
  fileArg 
)

Constructor.

Parameters

Definition at line 416 of file trfReports.py.

416  def __init__(self, fileArg):
417  self._fileArg = fileArg
418 

Member Function Documentation

◆ classicEltreeList()

def python.trfReports.trfFileReport.classicEltreeList (   self,
  fast = False 
)

Return an element tree representation of the classic file report @detail Returns a list of eltree entities giving the classic metadata of a files for this argument.

This is a list so that it can be attached as a series of nodes into the final PFC description of the job

Returns
List of ElementTree.Element objects

Definition at line 501 of file trfReports.py.

501  def classicEltreeList(self, fast = False):
502  treeList = []
503  for fname in self._fileArg.value:
504  treeList.append(self.classicSingleEltree(fname, fast = fast))
505 
506  return treeList
507 
508 

◆ classicPython()

def python.trfReports.trfFileReport.classicPython (   self,
  fast = False 
)

Return file metadata in classic Tier 0 python style.

Parameters
fastPrevent external metadata calls if true
Returns
List of file metadata dictionaries

Definition at line 543 of file trfReports.py.

543  def classicPython(self, fast = False):
544  fileList = []
545  for fname in self._fileArg.value:
546  fileList.append(self.classicSinglePython(fname, fast = fast))
547  return fileList
548 

◆ classicSingleEltree()

def python.trfReports.trfFileReport.classicSingleEltree (   self,
  filename,
  fast = False 
)

Return file metadata in 'classic' POOLFILECATALOG format.

Parameters
filenameFilename to generate Element object for
fastPrevent external metadata calls if true

Definition at line 512 of file trfReports.py.

512  def classicSingleEltree(self, filename, fast = False):
513  if filename not in self._fileArg.value:
514  raise trfExceptions.TransformReportException(trfExit.nameToCode('TRF_INTERNAL_REPORT_ERROR'),
515  'Unknown file ({0}) in the file report for {1}'.format(filename, self._fileArg))
516  tree = ElementTree.Element('File', ID = str(self._fileArg.getSingleMetadata(fname = filename, metadataKey = 'file_guid', populate = not fast)))
517  for myKey, classicKey in self._internalToClassicMap.items():
518  # beam_type is tricky - we return only the first list value,
519  # (but remember, protect against funny stuff!)
520  if myKey == 'beam_type':
521  beamType = self._fileArg.getSingleMetadata(fname = filename, metadataKey = myKey, populate = not fast)
522  if isinstance(beamType, list):
523  if len(beamType) == 0:
524  ElementTree.SubElement(tree, 'metadata', att_name = classicKey, att_value = '')
525  else:
526  ElementTree.SubElement(tree, 'metadata', att_name = classicKey, att_value = str(beamType[0]))
527  else:
528  # This is really not normal, but best we can do is str conversion
529  ElementTree.SubElement(tree, 'metadata', att_name = classicKey, att_value = str(beamType))
530  else:
531  ElementTree.SubElement(tree, 'metadata', att_name = classicKey,
532  att_value = str(self._fileArg.getSingleMetadata(fname = filename, metadataKey = myKey, populate = not fast)))
533  # Now add the metadata which is stored at the whole argument level
534  ElementTree.SubElement(tree, 'metadata', att_name = 'fileType', att_value = str(self._fileArg.type))
535  if self._fileArg.dataset is not None:
536  ElementTree.SubElement(tree, 'metadata', att_name = 'dataset', att_value = self._fileArg.dataset)
537 
538  return tree
539 

◆ classicSinglePython()

def python.trfReports.trfFileReport.classicSinglePython (   self,
  filename,
  fast = False 
)

Return single file metadata in classic Tier 0 python style.

Parameters
fastPrevent external metadata calls if true

Definition at line 552 of file trfReports.py.

552  def classicSinglePython(self, filename, fast = False):
553  if filename not in self._fileArg.value:
554  raise trfExceptions.TransformReportException(trfExit.nameToCode('TRF_INTERNAL_REPORT_ERROR'),
555  'Unknown file ({0}) in the file report for {1}'.format(filename, self._fileArg))
556  # Direct population of some keys
557  fileDict = {'lfn' : filename,
558  'dataset' : self._fileArg.dataset,
559  }
560  # Fill in the mapped 'primary' keys
561  for myKey, classicKey in self._internalToGpickleMap.items():
562  fileDict[classicKey] = self._fileArg.getSingleMetadata(fname = filename, metadataKey = myKey, populate = not fast)
563  if classicKey == 'checkSum' and fileDict[classicKey] == 'UNDEFINED':
564  # Old style is that we give back None when we don't know
565  fileDict[classicKey] = None
566  elif fileDict[classicKey] == 'UNDEFINED':
567  # Suppress things we don't generally expect to know
568  del fileDict[classicKey]
569  # Base 'more' stuff which is known by the argFile itself
570  fileDict['more'] = {'metadata' : {'fileType' : self._fileArg.type}}
571  for myKey, classicKey in self._internalToGpickleMoreMap.items():
572  value = self._fileArg.getSingleMetadata(fname = filename, metadataKey = myKey, populate = not fast)
573  if value != 'UNDEFINED':
574  fileDict['more']['metadata'][classicKey] = value
575 
576  return fileDict
577 
578 

◆ python()

def python.trfReports.trfFileReport.python (   self,
  fast = False,
  type = 'full' 
)

Get a python representation of file report @detail Returns the python representation of this file report which is a list of dictionaries (a la Tier 0)

Parameters
typeReport type (e.g., None = normal or fast)
baseHow extensive to make the report: name or full

Definition at line 424 of file trfReports.py.

424  def python(self, fast = False, type = 'full'):
425  # First entity contains shared properties - same for all files in this argFile
426  if type == 'name':
427  fileArgProps = {'dataset': self._fileArg.dataset,
428  'nentries': self._fileArg.getnentries(fast),
429  'subFiles' : []}
430  elif type == 'full':
431  fileArgProps = {'dataset' : self._fileArg.dataset,
432  'type' : self._fileArg.type,
433  'subFiles' : [],
434  'argName' : self._fileArg.name,
435  }
436  else:
437  raise trfExceptions.TransformReportException(trfExit.nameToCode('TRF_INTERNAL_REPORT_ERROR'),
438  'Unknown file report type ({0}) in the file report for {1}'.format(type, self._fileArg))
439 
440 
443  uniqueBasenames = set([ os.path.basename(fname) for fname in self._fileArg.value ])
444  uniqueDirectories = set([ os.path.dirname(os.path.relpath(os.path.normpath(fname))) for fname in self._fileArg.value ])
445  if len(uniqueBasenames) != len(self._fileArg.value):
446  msg.info('Detected two files with the same basename in a file argument - report for file {0} will be produced with the path as a key'.format(self._fileArg))
447  basenameReport = False
448  elif len(uniqueDirectories) > 1:
449  msg.warning('Detected output files in different directories - report for file {0} will be produced with the path as a key'.format(self._fileArg))
450  basenameReport = False
451  else:
452  basenameReport = True
453  suppressed = []
454  for fname in self._fileArg.value:
455  subFile = None
456  if basenameReport:
457  subFile = self.singleFilePython(fname, fast = fast, type = type)
458  else:
459  subFile = self.singleFilePython(fname, fast = fast, type = type, basename = False)
460  if subFile is not None:
461  # if nentries == 0 for DRAW, suppress subfile from report
462  if 'nentries' in subFile and subFile['nentries'] == 0 and isinstance(self._fileArg, trfArgClasses.argBSFile):
463  msg.info('Suppressing file {0}, nentries is 0'.format(subFile['name']))
464  suppressed.append(subFile['name'])
465  else:
466  fileArgProps['subFiles'].append(subFile)
467 
468  return fileArgProps
469 

◆ singleFilePython()

def python.trfReports.trfFileReport.singleFilePython (   self,
  filename,
  fast = False,
  type = 'full',
  basename = True 
)

Return unique metadata for a single file in an argFile class.

Parameters
filenameFile for which report should be generated
typeType of report to produce
fastGenerate a fast report, i.e., no external matadata calls
Returns
Python report dictionary

Definition at line 475 of file trfReports.py.

475  def singleFilePython(self, filename, fast = False, type = 'full', basename = True):
476  if filename not in self._fileArg.value:
477  raise trfExceptions.TransformReportException(trfExit.nameToCode('TRF_INTERNAL_REPORT_ERROR'),
478  'Unknown file ({0}) in the file report for {1}'.format(filename, self._fileArg))
479  if basename:
480  entry = {'name': os.path.basename(filename)}
481  else:
482  entry = {'name': os.path.relpath(os.path.normpath(filename))}
483  if type == 'name':
484  # For 'name' we return only the GUID
485  entry.update(self._fileArg.getMetadata(files = filename, populate = not fast, metadataKeys = ['file_guid'])[filename])
486  elif type == 'full':
487  # Suppress io because it's the key at a higher level and _exists because it's internal
488  entry.update(self._fileArg.getMetadata(files = filename, populate = not fast, maskMetadataKeys = ['io', '_exists', 'integrity', 'file_type'])[filename])
489  else:
490  raise trfExceptions.TransformReportException(trfExit.nameToCode('TRF_INTERNAL_REPORT_ERROR'),
491  'Unknown file report type ({0}) in the file report for {1}'.format(type, self._fileArg))
492 
493  return entry
494 
495 

Member Data Documentation

◆ _fileArg

python.trfReports.trfFileReport._fileArg
private

Definition at line 417 of file trfReports.py.

◆ _internalToClassicMap

python.trfReports.trfFileReport._internalToClassicMap
staticprivate

Definition at line 396 of file trfReports.py.

◆ _internalToGpickleMap

python.trfReports.trfFileReport._internalToGpickleMap
staticprivate

Definition at line 403 of file trfReports.py.

◆ _internalToGpickleMoreMap

python.trfReports.trfFileReport._internalToGpickleMoreMap
staticprivate

Definition at line 409 of file trfReports.py.


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
getMetadata
Definition: getMetadata.py:1
python.MadGraphUtils.python
string python
Definition: MadGraphUtils.py:14
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
str
Definition: BTagTrackIpAccessor.cxx:11