ATLAS Offline Software
Loading...
Searching...
No Matches
SortedInputFileCreator.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3__doc__ = """
4Create a sorted event-tag POOL file from a set of Athena files, using SortedEventTagWriter
5"""
6
7
9 """Creates a POOL file of event references sorted by an EventInfo attribute"""
10
11 def execute(self, inputFiles, outputFile, sortAttribute="LumiBlockN"):
12 """Sort the events of the input files and write them to outputFile
13 in ascending order of sortAttribute, read from the input attribute list"""
14 inputs = [inputFiles] if isinstance(inputFiles, str) else list(inputFiles)
15
16 from AthenaConfiguration.AllConfigFlags import initConfigFlags
17 from AthenaConfiguration.ComponentFactory import CompFactory
18 from AthenaConfiguration.MainServicesConfig import MainEvgenServicesCfg
19 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
20 from AthenaPoolCnvSvc.PoolWriteConfig import PoolWriteCfg
21
22 flags = initConfigFlags()
23 flags.Input.Files = inputs
24 flags.lock()
25
26 # Set up the main services and configure the input and output
27 acc = MainEvgenServicesCfg(flags)
28 acc.merge(PoolReadCfg(flags))
29 acc.merge(PoolWriteCfg(flags))
30 acc.addEventAlgo(CompFactory.SortedEventTagWriter(OutputFile=outputFile,
31 SortAttribute=sortAttribute))
32 if acc.run().isFailure():
33 raise RuntimeError("Sorting of input files failed")
34
35 def _executeQuiet(self, *args, **kwargs):
36 import os
37 # Athena messaging writes to the file descriptor, so redirect it (child process only)
38 devnull = os.open(os.devnull, os.O_WRONLY)
39 os.dup2(devnull, 1)
40 self.execute(*args, **kwargs)
41
42 def executeInSubprocess(self, *args, quiet=True, **kwargs):
43 """Run execute() in a forked process; quiet=True discards its stdout"""
44 import multiprocessing
45 # Default start method changed from fork to spawn in python 3.14.
46 # Need to force it back.
47 multiprocessing.set_start_method('fork', force=True)
48 target = self._executeQuiet if quiet else self.execute
49 process = multiprocessing.Process(target=target, args=args, kwargs=kwargs)
50 process.start()
51 process.join() # Wait for completion
52 return process.exitcode
execute(self, inputFiles, outputFile, sortAttribute="LumiBlockN")