ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Reconstruction
RecJobTransforms
python
recoTransforms.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2025 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
longlist = subprocess.check_output(listEvtCommand).decode(
'utf-8'
)
32
try
:
33
for
line
in
longlist.split(
"\n"
):
34
if
line.startswith(
"Index="
):
35
try
:
36
splitStrings = line.split(
" "
)
37
runprefix, runstr = splitStrings[1].
split
(
"="
)
38
evtprefix, evtstr = splitStrings[2].
split
(
"="
)
39
# Check sanity
40
if
runprefix !=
"Run"
or
evtprefix !=
"Event"
:
41
msg.warning(
"Failed to understand this line from AtlListBSEvents (1): %s"
, line)
42
else
:
43
runnumber = int(runstr)
# noqa: F841
44
evtnumber = int(evtstr)
# noqa: F841
45
# We build up a string key as "RUN-EVENT", so that we can take advantage of
46
# the fast hash search against a dictionary
47
rawEventList[runstr +
"-"
+ evtstr] =
True
48
msg.debug(
"Identified run %s, event %s in input RAW files"
, runstr, evtstr)
49
except
ValueError:
50
msg.warning(
"Failed to understand this line from AtlListBSEvents (2): %s"
, line)
51
except
subprocess.CalledProcessError
as
e:
52
errMsg =
"Call to AtlListBSEvents failed: {0}"
.format(e)
53
msg.error(errMsg)
54
raise
trfExceptions.TransformExecutionException
(trfExit.nameToCode(
"TRF_EXEC_SETUP_FAIL"
), errMsg)
55
msg.info(
"Found %d events as skim candidates in RAW inputs"
, len(rawEventList))
56
57
# Now open the list of filter events, and check through them
58
slimmedFilterFile =
"slimmedFilterFile.{0}"
.format(os.getpid())
59
with
open(slimmedFilterFile,
"w"
)
as
slimFF, open(self.conf.argdict[
'filterFile'
].value)
as
masterFF:
60
count = 0
61
for
line
in
masterFF:
62
try
:
63
runstr, evtstr = str(line).
split
()
64
if
runstr +
"-"
+ evtstr
in
rawEventList:
65
msg.debug(
"Found run %s, event %s in master filter list"
, runstr, evtstr)
66
os.write(slimFF.fileno(), line.encode(
'utf-8'
))
67
count += 1
68
except
ValueError
as
e:
69
msg.warning(
"Failed to understand this line from master filter file: %s %s"
, line, e)
70
if
count == 0:
71
# If there are no matched events, create a bogus request for run and event 0 to keep
72
# AtlCopyBSEvent.exe CLI
73
msg.info(
"No events matched in this input file - empty RAW file output will be made"
)
74
os.write(slimFF.fileno(), b
"0 0\n"
)
75
msg.info(
"Matched %d lines from the master filter file against input events; wrote these to %s"
, count, slimmedFilterFile)
76
77
# Build up the right command line for AtlCopyBSEvent
78
79
events =
''
80
for
line
in
open(slimmedFilterFile):
81
events +=
'%s,'
% line.split()[-1]
82
events = events[:-1]
83
84
self.
_cmd
= [
'AtlCopyBSEvent'
]
85
86
self.
_cmd
.extend((
'-e'
, events))
87
self.
_cmd
.extend((
'-o'
, self.conf.argdict[
'outputBS_SKIMFile'
].value[0]))
88
self.
_cmd
.extend(self.conf.argdict[
'inputBSFile'
].value)
89
90
super(skimRawExecutor, self).
preExecute
()
91
python.recoTransforms.skimRawExecutor
Executor for skimming RAW events according to a list of run and event numbers.
Definition
recoTransforms.py:19
python.recoTransforms.skimRawExecutor.preExecute
preExecute(self, input=set(), output=set())
Definition
recoTransforms.py:21
python.recoTransforms.skimRawExecutor._cmd
list _cmd
Definition
recoTransforms.py:84
python.trfExceptions.TransformExecutionException
Base class for execution exceptions.
Definition
trfExceptions.py:63
set
STL class.
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition
hcg.cxx:179
PyJobTransforms.trfExe
Transform execution functions.
PyJobTransforms.trfExitCodes
Module for transform exit codes.
Generated on
for ATLAS Offline Software by
1.17.0