Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Classes | Functions | Variables
python.trfValidation Namespace Reference

Classes

class  athenaLogFileReport
 Logfile suitable for scanning logfiles with an athena flavour, i.e., lines of the form "SERVICE LOGLEVEL MESSAGE". More...
 
class  eventMatch
 Small class used for vailiadating event counts between input and output files. More...
 
class  ignorePatterns
 Class of patterns that can be ignored from athena logfiles. More...
 
class  logFileReport
 A class holding report information from scanning a logfile This is pretty much a virtual class, fill in the specific methods when you know what type of logfile you are dealing with. More...
 
class  scriptLogFileReport
 

Functions

def corruptionTestPool (filename, verbose=False)
 
def corruptionTestBS (filename)
 
def returnIntegrityOfFile (file, functionName)
 return integrity of file using appropriate validation function @ detail This method returns the integrity of a specified file using a @ specified validation function. More...
 
def performStandardFileValidation (dictionary, io, parallelMode=False, multithreadedMode=False)
 perform standard file validation @ detail This method performs standard file validation in either serial or @ parallel and updates file integrity metadata. More...
 

Variables

 msg
 

Function Documentation

◆ corruptionTestBS()

def python.trfValidation.corruptionTestBS (   filename)

Definition at line 87 of file trfValidation.py.

87 def corruptionTestBS(filename):
88  # First try AtlListBSEvents -c %filename:
89  cmd = ['AtlListBSEvents', '-c', filename]
90  p = Popen(cmd, shell=False, stdout=PIPE, stderr=STDOUT, close_fds=True)
91  while p.poll() is None:
92  line = p.stdout.readline()
93  if line:
94  msg.info("AtlListBSEvents Report: %s", line.strip())
95  rc = p.returncode
96  return rc
97 
98 

◆ corruptionTestPool()

def python.trfValidation.corruptionTestPool (   filename,
  verbose = False 
)

Definition at line 35 of file trfValidation.py.

35 def corruptionTestPool(filename, verbose=False):
36  if not os.access(filename, os.R_OK):
37  msg.info("ERROR can't access file %s", filename)
38  return -1
39 
40  ROOT = RootUtils.import_root()
41 
42  try:
43  f = ROOT.TFile.Open(filename)
44  except Exception:
45  msg.info("Can't open file %s", filename)
46  return -1
47 
48  nEvents = None
49 
50  keys = f.GetListOfKeys()
51  for k in keys:
52  try:
53  tn = k.GetName()
54  t = f.Get(tn)
55  if not isinstance(t, ROOT.TTree): return
56  except Exception:
57  msg.info("Can't get tree %s from file %s", tn, filename)
58  f.Close()
59  return -1
60 
61  if (verbose): msg.info("Working on tree %s", tn)
62  n = t.GetEntriesFast()
63  for i in range(n):
64  s = t.GetEntry(i)
65  if s <= 0:
66  msg.info("Tree %s: Found corruption in event %i", i, n)
67  f.Close()
68  return -2
69  else:
70  if verbose and i > 0 and i % 100 == 0:
71  msg.info("Checking event %s", i)
72  msg.info("Tree %s: %i event(s) ok", tn, n)
73 
74  # Use CollectionTree determine the number of events
75  if tn == 'CollectionTree':
76  nEvents = n
77  pass # end of loop over trees
78 
79  f.Close()
80  msg.info("ROOT file %s looks ok", filename)
81  if n is None:
82  msg.info("Failed to determine number of events in file %s. No tree named 'CollectionTree'", filename)
83  return 0
84  return nEvents
85 
86 # @brief Check BS file for corruption

◆ performStandardFileValidation()

def python.trfValidation.performStandardFileValidation (   dictionary,
  io,
  parallelMode = False,
  multithreadedMode = False 
)

perform standard file validation @ detail This method performs standard file validation in either serial or @ parallel and updates file integrity metadata.

Definition at line 757 of file trfValidation.py.

757 def performStandardFileValidation(dictionary, io, parallelMode = False, multithreadedMode=False):
758  if parallelMode is False:
759  msg.info('Starting legacy (serial) file validation')
760  for (key, arg) in dictionary.items():
761  if not isinstance(arg, argFile):
762  continue
763  if not arg.io == io:
764  continue
765  if arg.auxiliaryFile:
766  continue
767 
768  msg.info('Validating data type %s...', key)
769 
770  for fname in arg.value:
771  msg.info('Validating file %s...', fname)
772 
773  if io == "output":
774  msg.info('{0}: Testing corruption...'.format(fname))
775  if multithreadedMode:
776  os.environ['TRF_MULTITHREADED_VALIDATION']='TRUE'
777  if arg.getSingleMetadata(fname, 'integrity') is True:
778  msg.info('Corruption test passed.')
779  elif arg.getSingleMetadata(fname, 'integrity') is False:
780  msg.error('Corruption test failed.')
781  raise trfExceptions.TransformValidationException(trfExit.nameToCode('TRF_EXEC_VALIDATION_FAIL'), 'File %s did not pass corruption test' % fname)
782  elif arg.getSingleMetadata(fname, 'integrity') == 'UNDEFINED':
783  msg.info('No corruption test defined.')
784  elif arg.getSingleMetadata(fname, 'integrity') is None:
785  msg.error('Could not check for file integrity')
786  raise trfExceptions.TransformValidationException(trfExit.nameToCode('TRF_EXEC_VALIDATION_FAIL'), 'File %s might be missing' % fname)
787  else:
788  msg.error('Unknown rc from corruption test.')
789  raise trfExceptions.TransformValidationException(trfExit.nameToCode('TRF_EXEC_VALIDATION_FAIL'), 'File %s did not pass corruption test' % fname)
790 
791 
792  msg.info('{0}: Testing event count...'.format(fname))
793  if arg.getSingleMetadata(fname, 'nentries') is not None:
794  msg.info('Event counting test passed ({0!s} events).'.format(arg.getSingleMetadata(fname, 'nentries')))
795  else:
796  msg.error('Event counting test failed.')
797  raise trfExceptions.TransformValidationException(trfExit.nameToCode('TRF_EXEC_VALIDATION_FAIL'), 'File %s did not pass corruption test' % fname)
798 
799 
800  msg.info('{0}: Checking if guid exists...'.format(fname))
801  if arg.getSingleMetadata(fname, 'file_guid') is None:
802  msg.error('Guid could not be determined.')
803  raise trfExceptions.TransformValidationException(trfExit.nameToCode('TRF_EXEC_VALIDATION_FAIL'), 'File %s did not pass corruption test' % fname)
804  elif arg.getSingleMetadata(fname, 'file_guid') == 'UNDEFINED':
805  msg.info('Guid not defined.')
806  else:
807  msg.info('Guid is %s', arg.getSingleMetadata(fname, 'file_guid'))
808  msg.info('Stopping legacy (serial) file validation')
809  if parallelMode is True:
810  msg.info('Starting parallel file validation')
811  # Create lists of files and args. These lists are to be used with zip in
812  # order to check and update file integrity metadata as appropriate.
813  fileList = []
814  argList = []
815  # Create a list of the integrity functions for files.
816  integrityFunctionList = []
817  # Create a list for collation of file validation jobs for submission to
818  # the parallel job processor.
819  jobs = []
820  for (key, arg) in dictionary.items():
821  if not isinstance(arg, argFile):
822  continue
823  if not arg.io == io:
824  continue
825  msg.debug('Collating list of files for validation')
826  for fname in arg.value:
827  msg.debug('Appending file {fileName} to list of files for validation'.format(fileName = str(fname)))
828  # Append the current file to the file list.
829  fileList.append(fname)
830  # Append the current arg to the arg list.
831  argList.append(arg)
832  # Append the current integrity function name to the integrity
833  # function list if it exists. If it does not exist, raise an
834  # exception.
835  if arg.integrityFunction:
836  integrityFunctionList.append(arg.integrityFunction)
837  else:
838  msg.error('Validation function for file {fileName} not available for parallel file validation'.format(fileName = str(fname)))
839  raise trfExceptions.TransformValidationException(trfExit.nameToCode('TRF_EXEC_VALIDATION_FAIL'), 'Validation function for file %s not available for parallel file validation' % str(fname))
840  # Compose a job for validation of the current file using the
841  # appropriate validation function, which is derived from the
842  # associated data attribute arg.integrityFunction.
843  jobs.append(
844  trfUtils.Job(
845  name = "validation of file {fileName}".format(
846  fileName = str(fname)),
847  workFunction = returnIntegrityOfFile,
848  workFunctionKeywordArguments = {
849  'file': fname,
850  'functionName': arg.integrityFunction
851  },
852  workFunctionTimeout = 600
853  )
854  )
855  # Contain the file validation jobs in a job group for submission to the
856  # parallel job processor.
857  jobGroup1 = trfUtils.JobGroup(
858  name = "standard file validation",
859  jobs = jobs
860  )
861  # Prepare the parallel job processor.
862  parallelJobProcessor1 = trfUtils.ParallelJobProcessor()
863  # Submit the file validation jobs to the parallel job processor.
864  msg.info('Submitting file validation jobs to parallel job processor')
865  parallelJobProcessor1.submit(jobSubmission = jobGroup1)
866  resultsList = parallelJobProcessor1.getResults()
867  msg.info('Parallel file validation complete')
868  # Update file metadata with integrity results using the lists fileList,
869  # argList and resultsList.
870  msg.info('Processing file integrity results')
871  for currentFile, currentArg, currentIntegrityFunction, currentResult in zip(fileList, argList, integrityFunctionList, resultsList):
872  msg.info('{IO} file {fileName} has integrity status {integrityStatus} as determined by integrity function {integrityFunction}'.format(
873  IO = str(io),
874  fileName = str(currentFile),
875  integrityStatus = str(currentResult),
876  integrityFunction = str(currentIntegrityFunction)
877  ))
878  # If the first (Boolean) element of the result tuple for the current
879  # file is True, update the integrity metadata. If it is False, raise
880  # an exception.
881  if currentResult[0] is True:
882  msg.info('Updating integrity metadata for file {fileName}'.format(fileName = str(currentFile)))
883  currentArg._setMetadata(files=[currentFile,], metadataKeys={'integrity': currentResult[0]})
884  else:
885  exceptionMessage = "{IO} file validation failure on file {fileName} with integrity status {integrityStatus} as determined by integrity function {integrityFunction}".format(
886  IO = str(io),
887  fileName = str(currentFile),
888  integrityStatus = str(currentResult),
889  integrityFunction = str(currentIntegrityFunction)
890  )
891  msg.error("exception message: {exceptionMessage}".format(
892  exceptionMessage = exceptionMessage
893  ))
894  if io == 'input':
895  exitCodeName = 'TRF_INPUT_FILE_VALIDATION_FAIL'
896  elif io == 'output':
897  exitCodeName = 'TRF_OUTPUT_FILE_VALIDATION_FAIL'
898  raise trfExceptions.TransformValidationException(
899  trfExit.nameToCode(exitCodeName),
900  exceptionMessage
901  )
902  # Perform a check to determine if the file integrity metadata is
903  # correct.
904  if currentArg.getSingleMetadata(currentFile, metadataKey = 'integrity', populate = False) == currentResult[0]:
905  msg.debug("file integrity metadata update successful")
906  else:
907  msg.error("file integrity metadata update unsuccessful")
908  msg.info('Stopping parallel file validation')
909 
910 

◆ returnIntegrityOfFile()

def python.trfValidation.returnIntegrityOfFile (   file,
  functionName 
)

return integrity of file using appropriate validation function @ detail This method returns the integrity of a specified file using a @ specified validation function.

Definition at line 744 of file trfValidation.py.

744 def returnIntegrityOfFile(file, functionName):
745  try:
746  import PyJobTransforms.trfFileValidationFunctions as trfFileValidationFunctions
747  except Exception as exception:
748  msg.error('Failed to import module PyJobTransforms.trfFileValidationFunctions with error {error}'.format(error = exception))
749  raise
750  validationFunction = getattr(trfFileValidationFunctions, functionName)
751  return validationFunction(file)
752 
753 

Variable Documentation

◆ msg

python.trfValidation.msg

Definition at line 21 of file trfValidation.py.

vtune_athena.format
format
Definition: vtune_athena.py:14
PyJobTransforms.trfFileValidationFunctions
Transform file validation functions.
python.trfValidation.returnIntegrityOfFile
def returnIntegrityOfFile(file, functionName)
return integrity of file using appropriate validation function @ detail This method returns the integ...
Definition: trfValidation.py:744
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.trfValidation.corruptionTestPool
def corruptionTestPool(filename, verbose=False)
Definition: trfValidation.py:35
python.trfValidation.performStandardFileValidation
def performStandardFileValidation(dictionary, io, parallelMode=False, multithreadedMode=False)
perform standard file validation @ detail This method performs standard file validation in either ser...
Definition: trfValidation.py:757
python.trfValidation.corruptionTestBS
def corruptionTestBS(filename)
Definition: trfValidation.py:87
str
Definition: BTagTrackIpAccessor.cxx:11