ATLAS Offline Software
recoTransforms.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 
5 
6 import os
7 import subprocess
8 
9 import logging
10 msg = logging.getLogger(__name__)
11 
12 import PyJobTransforms.trfExceptions as trfExceptions
13 
14 from PyJobTransforms.trfExitCodes import trfExit
15 from PyJobTransforms.trfExe import scriptExecutor
16 
17 
19 class skimRawExecutor(scriptExecutor):
20 
21  def preExecute(self, input = set(), output = set()):
22  # First we need to strip the filter file down to events that are present
23  # in the RAW file we are going to skim. This is because the HI workflow
24  # will provide millions of events in their filter file, more than acmd.py
25  # can cope with.
26  listEvtCommand = ['AtlListBSEvents', '-l']
27  listEvtCommand.extend(self.conf.argdict['inputBSFile'].value)
28  # For best lookup speed, we store the runnumber/eventnumber in a dictionary (set would also
29  # be fast)
30  rawEventList = {}
31  try:
32  for line in subprocess.check_output(listEvtCommand).split("\n"):
33  if line.startswith("Index="):
34  try:
35  splitStrings = line.split(" ")
36  runprefix, runstr = splitStrings[1].split("=")
37  evtprefix, evtstr = splitStrings[2].split("=")
38  # Check sanity
39  if runprefix != "Run" or evtprefix != "Event":
40  msg.warning("Failed to understand this line from AtlListBSEvents: %s", line)
41  else:
42  runnumber = int(runstr) # noqa: F841
43  evtnumber = int(evtstr) # noqa: F841
44  # We build up a string key as "RUN-EVENT", so that we can take advantage of
45  # the fast hash search against a dictionary
46  rawEventList[runstr + "-" + evtstr] = True
47  msg.debug("Identified run %s, event %s in input RAW files", runstr, evtstr)
48  except ValueError:
49  msg.warning("Failed to understand this line from AtlListBSEvents: %s", line)
50  except subprocess.CalledProcessError as e:
51  errMsg = "Call to AtlListBSEvents failed: {0}".format(e)
52  msg.error(errMsg)
53  raise trfExceptions.TransformExecutionException(trfExit.nameToCode("TRF_EXEC_SETUP_FAIL"), errMsg)
54  msg.info("Found %d events as skim candidates in RAW inputs", len(rawEventList))
55 
56  # Now open the list of filter events, and check through them
57  slimmedFilterFile = "slimmedFilterFile.{0}".format(os.getpid())
58  with open(slimmedFilterFile, "w") as slimFF, open(self.conf.argdict['filterFile'].value) as masterFF:
59  count = 0
60  for line in masterFF:
61  try:
62  runstr, evtstr = line.split()
63  if runstr + "-" + evtstr in rawEventList:
64  msg.debug("Found run %s, event %s in master filter list", runstr, evtstr)
65  os.write(slimFF.fileno(), line)
66  count += 1
67  except ValueError as e:
68  msg.warning("Failed to understand this line from master filter file: %s %s", line, e)
69  if count == 0:
70  # If there are no matched events, create a bogus request for run and event 0 to keep
71  # AtlCopyBSEvent.exe CLI
72  msg.info("No events matched in this input file - empty RAW file output will be made")
73  os.write(slimFF.fileno(), "0 0\n")
74  msg.info("Matched %d lines from the master filter file against input events; wrote these to %s", count, slimmedFilterFile)
75 
76  # Build up the right command line for acmd.py
77  self._cmd = ['acmd.py', 'filter-files']
78 
79  self._cmd.extend(('-o', self.conf.argdict['outputBS_SKIMFile'].value[0]))
80  self._cmd.extend(('-s', slimmedFilterFile))
81  self._cmd.extend(self.conf.argdict['inputBSFile'].value)
82 
83  super(skimRawExecutor, self).preExecute()
84 
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
PyJobTransforms.trfExitCodes
Module for transform exit codes.
python.trfExceptions.TransformExecutionException
Base class for execution exceptions.
Definition: trfExceptions.py:62
python.recoTransforms.skimRawExecutor._cmd
_cmd
Definition: recoTransforms.py:77
python.recoTransforms.skimRawExecutor
Executor for skimming RAW events according to a list of run and event numbers.
Definition: recoTransforms.py:19
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
PyJobTransforms.trfExe
Transform execution functions.
Trk::open
@ open
Definition: BinningType.h:40
ActsTrk::detail::MakeDerivedVariant::extend
constexpr std::variant< Args..., T > extend(const std::variant< Args... > &, const T &)
Definition: MakeDerivedVariant.h:17
python.recoTransforms.skimRawExecutor.preExecute
def preExecute(self, input=set(), output=set())
Definition: recoTransforms.py:21
Trk::split
@ split
Definition: LayerMaterialProperties.h:38