ATLAS Offline Software
EVNTMerge_Skeleton.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 import sys
4 from PyJobTransforms.CommonRunArgsToFlags import commonRunArgsToFlags
5 from PyJobTransforms.TransformUtils import processPreExec, processPreInclude, processPostExec, processPostInclude
6 
7 # force no legacy job properties
8 from AthenaCommon import JobProperties
9 JobProperties.jobPropertiesDisallowed = True
10 
11 
12 def fromRunArgs(runArgs):
13  from AthenaCommon.Logging import logging
14  log = logging.getLogger("EVNTMerge")
15  log.info("****************** STARTING EVNT MERGING *****************")
16 
17  log.info("**** Transformation run arguments")
18  log.info(str(runArgs))
19 
20  log.info("**** Setting-up configuration flags")
21  from AthenaConfiguration.AllConfigFlags import initConfigFlags
22  flags = initConfigFlags()
23 
24  from AthenaConfiguration.Enums import ProductionStep
25  flags.Common.ProductionStep = ProductionStep.Generation
26 
27  commonRunArgsToFlags(runArgs, flags)
28 
29  if hasattr(runArgs, "inputEVNTFile"):
30  flags.Input.Files = runArgs.inputEVNTFile
31  else:
32  raise RuntimeError("No input EVNT file defined")
33 
34  if hasattr(runArgs, "outputEVNT_MRGFile"):
35  if runArgs.outputEVNT_MRGFile == "None":
36  flags.Output.EVNTFileName = ""
37  # TODO decide if we need a specific EVNT_MRGFileName flag
38  else:
39  flags.Output.EVNTFileName = runArgs.outputEVNT_MRGFile
40  else:
41  raise RuntimeError("No outputEVNT_MRGFile defined")
42 
43  # Pre-include
44  processPreInclude(runArgs, flags)
45 
46  # Pre-exec
47  processPreExec(runArgs, flags)
48 
49  # To respect --athenaopts
50  flags.fillFromArgs()
51 
52  # Lock flags
53  flags.lock()
54 
55  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
56  cfg = MainServicesCfg(flags)
57 
58  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
59  cfg.merge(PoolReadCfg(flags))
60 
61  # Ensure proper metadata propagation
62  from IOVDbSvc.IOVDbSvcConfig import IOVDbSvcCfg
63  cfg.merge(IOVDbSvcCfg(flags))
64 
65  from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg
66  cfg.merge(OutputStreamCfg(flags, "EVNT", disableEventTag = True, takeItemsFromInput = True, extendProvenanceRecord = False))
67 
68  # Add in-file MetaData
69  from xAODMetaDataCnv.InfileMetaDataConfig import SetupMetaDataForStreamCfg
70  cfg.merge(SetupMetaDataForStreamCfg(flags, "EVNT", disableEventTag=True))
71 
72  # Post-include
73  processPostInclude(runArgs, flags, cfg)
74 
75  # Post-exec
76  processPostExec(runArgs, flags, cfg)
77 
78  # Write AMI tag into in-file metadata
79  from PyUtils.AMITagHelperConfig import AMITagCfg
80  cfg.merge(AMITagCfg(flags, runArgs))
81 
82 
83  from AthenaConfiguration.AutoConfigFlags import GetFileMD
84  hepmc_version = GetFileMD(flags.Input.Files).get("hepmc_version", None)
85  if hepmc_version is not None:
86  if hepmc_version == "2":
87  hepmc_version = "HepMC2"
88  elif hepmc_version == "3":
89  hepmc_version = "HepMC3"
90  log.info("Input file was produced with %s", hepmc_version)
91  from EventInfoMgt.TagInfoMgrConfig import TagInfoMgrCfg
92  cfg.merge(TagInfoMgrCfg(flags, tagValuePairs={"hepmc_version": hepmc_version}))
93 
94  import time
95  tic = time.time()
96  # Run the final accumulator
97  sc = cfg.run()
98  log.info("Ran EVNTMerge_tf in " + str(time.time()-tic) + " seconds")
99 
100  sys.exit(not sc.isSuccess())
python.TransformUtils.processPreExec
def processPreExec(runArgs, flags)
Definition: Tools/PyJobTransforms/python/TransformUtils.py:41
python.TransformUtils.processPostExec
def processPostExec(runArgs, flags, cfg)
Definition: Tools/PyJobTransforms/python/TransformUtils.py:50
python.OutputStreamConfig.OutputStreamCfg
def OutputStreamCfg(flags, streamName, ItemList=[], MetadataItemList=[], disableEventTag=False, trigNavThinningSvc=None, takeItemsFromInput=False, extendProvenanceRecord=True, AcceptAlgs=[], HelperTools=[])
Definition: OutputStreamConfig.py:12
python.AutoConfigFlags.GetFileMD
def GetFileMD(filenames, allowEmpty=True)
Definition: AutoConfigFlags.py:51
python.TransformUtils.processPostInclude
def processPostInclude(runArgs, flags, cfg)
Definition: Tools/PyJobTransforms/python/TransformUtils.py:69
python.TransformUtils.processPreInclude
def processPreInclude(runArgs, flags)
Definition: Tools/PyJobTransforms/python/TransformUtils.py:62
python.TagInfoMgrConfig.TagInfoMgrCfg
def TagInfoMgrCfg(flags, tagValuePairs={})
Definition: TagInfoMgrConfig.py:6
python.EVNTMerge_Skeleton.fromRunArgs
def fromRunArgs(runArgs)
Definition: EVNTMerge_Skeleton.py:12
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:256
python.CommonRunArgsToFlags.commonRunArgsToFlags
def commonRunArgsToFlags(runArgs, configFlags)
Definition: CommonRunArgsToFlags.py:12
python.IOVDbSvcConfig.IOVDbSvcCfg
def IOVDbSvcCfg(flags, **kwargs)
Definition: IOVDbSvcConfig.py:19
python.AMITagHelperConfig.AMITagCfg
def AMITagCfg(flags, runArgs=None, fixBroken=False)
Definition: AMITagHelperConfig.py:77
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
str
Definition: BTagTrackIpAccessor.cxx:11
InfileMetaDataConfig.SetupMetaDataForStreamCfg
def SetupMetaDataForStreamCfg(flags, streamName="", AcceptAlgs=None, createMetadata=None, propagateMetadataFromInput=True, *args, **kwargs)
Definition: InfileMetaDataConfig.py:216
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69