ATLAS Offline Software
TagInfoMgrConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator, ConfigurationError
3 from AthenaConfiguration.ComponentFactory import CompFactory
4 
5 
6 def TagInfoMgrCfg(flags, tagValuePairs={}):
7  # Sanity check:
8  if not isinstance(tagValuePairs, dict):
9  raise ConfigurationError("Parameter extraTagValuePairs is supposed to be a dictionary")
10 
11  # Build project-version string for the TagInfoMgr
12  from os import getenv
13  project = getenv("AtlasProject", "Unknown")
14  version = getenv("AtlasVersion", "Unknown")
15  atlasRelease=project+"-"+version
16 
17  tagValuePairs.update({"AtlasRelease" : atlasRelease})
18 
19  from Campaigns.Utils import Campaign
20  if flags.Input.isMC and flags.Input.MCCampaign is not Campaign.Unknown:
21  tagValuePairs.update({"mc_campaign" : flags.Input.MCCampaign.value})
22 
23  result = ComponentAccumulator()
24  result.addService(CompFactory.TagInfoMgr(ExtraTagValuePairs=tagValuePairs), primary=True)
25  return result
26 
27 
28 if __name__ == "__main__":
29  from AthenaConfiguration.AllConfigFlags import initConfigFlags
30  from AthenaConfiguration.TestDefaults import defaultTestFiles
31  flags = initConfigFlags()
32  flags.Input.Files = defaultTestFiles.RDO_RUN2
33  flags.lock()
34 
35  acc = TagInfoMgrCfg( flags, {"SomeKey": "SomeValue"} )
36  acc2 = TagInfoMgrCfg( flags, {"OtherKey": "OtherValue", "SomeKey": "SomeValue"} )
37  acc.merge(acc2)
38 
39  assert "SomeKey" in acc.getService("TagInfoMgr").ExtraTagValuePairs
40  assert "OtherKey" in acc.getService("TagInfoMgr").ExtraTagValuePairs
41  acc.store( open( "test.pkl", "wb" ) )
42  print("All OK")
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.TagInfoMgrConfig.TagInfoMgrCfg
def TagInfoMgrCfg(flags, tagValuePairs={})
Definition: TagInfoMgrConfig.py:6
Trk::open
@ open
Definition: BinningType.h:40
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28