21 def preExecute(self, input = set(), output =
set()):
22
23
24
25
26 listEvtCommand = ['AtlListBSEvents', '-l']
27 listEvtCommand.extend(self.conf.argdict['inputBSFile'].value)
28
29
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
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)
44 evtnumber = int(evtstr)
45
46
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
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
72
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
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
std::vector< std::string > split(const std::string &s, const std::string &t=":")