ATLAS Offline Software
ToolBox.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Local includes
7 
8 namespace ORUtils
9 {
10 
11  //-------------------------------------------------------------------------
12  // Constructor
13  //-------------------------------------------------------------------------
14  ToolBox::ToolBox(const std::string& name, parentType_t* theParent)
15  : asg::AsgMessaging(name),
16  masterTool("", theParent),
17  eleEleORT("", theParent),
18  eleMuORT("", theParent),
19  eleJetORT("", theParent),
20  muJetORT("", theParent),
21  tauEleORT("", theParent),
22  tauMuORT("", theParent),
23  tauJetORT("", theParent),
24  phoEleORT("", theParent),
25  phoMuORT("", theParent),
26  phoJetORT("", theParent),
27  eleFatJetORT("", theParent),
28  jetFatJetORT("", theParent),
29  m_parent(theParent)
30  {}
31 
32  //-------------------------------------------------------------------------
33  // Attach and initialize the tools
34  //-------------------------------------------------------------------------
36  {
37 
38 #ifndef XAOD_STANDALONE
39  // For now, in Athena, things only work with private tools.
40  // See ATLASG-957 for more details.
41  if(!m_parent) {
42  ATH_MSG_ERROR("For now, if you want to use the ToolBox in Athena, " <<
43  "the tools must be private to some algorithm, tool, etc.");
44  return StatusCode::FAILURE;
45  }
46 #endif
47 
48  // Initialize the overlap tools
49  ATH_CHECK( initTool(eleEleORT, "EleEleORT") );
50  ATH_CHECK( initTool(eleMuORT, "EleMuORT") );
51  ATH_CHECK( initTool(eleJetORT, "EleJetORT") );
52  ATH_CHECK( initTool(muJetORT, "MuJetORT") );
53  ATH_CHECK( initTool(tauEleORT, "TauEleORT") );
54  ATH_CHECK( initTool(tauMuORT, "TauMuORT") );
55  ATH_CHECK( initTool(tauJetORT, "TauJetORT") );
56  ATH_CHECK( initTool(phoEleORT, "PhoEleORT") );
57  ATH_CHECK( initTool(phoMuORT, "PhoMuORT") );
58  ATH_CHECK( initTool(phoJetORT, "PhoJetORT") );
59  ATH_CHECK( initTool(eleFatJetORT, "EleFatJetORT") );
60  ATH_CHECK( initTool(jetFatJetORT, "JetFatJetORT") );
61 
62  // Initialize the master tool
63  ATH_CHECK( initMaster() );
64 
65  return StatusCode::SUCCESS;
66  }
67 
68  //-------------------------------------------------------------------------
69  // Get a list of all overlap tool handles
70  //-------------------------------------------------------------------------
71  std::vector<ToolBox::OverlapHandle_t*> ToolBox::getOverlapTools()
72  {
73  // This is somewhat error prone, but better than not having it.
74  std::vector<OverlapHandle_t*> tools;
75  tools.reserve(13);
76  if(!eleEleORT.empty()) tools.push_back(&eleEleORT);
77  if(!eleMuORT.empty()) tools.push_back(&eleMuORT);
78  if(!eleJetORT.empty()) tools.push_back(&eleJetORT);
79  if(!muJetORT.empty()) tools.push_back(&muJetORT);
80  if(!tauEleORT.empty()) tools.push_back(&tauEleORT);
81  if(!tauMuORT.empty()) tools.push_back(&tauMuORT);
82  if(!tauJetORT.empty()) tools.push_back(&tauJetORT);
83  if(!phoEleORT.empty()) tools.push_back(&phoEleORT);
84  if(!phoMuORT.empty()) tools.push_back(&phoMuORT);
85  if(!phoJetORT.empty()) tools.push_back(&phoJetORT);
86  if(!eleFatJetORT.empty()) tools.push_back(&eleFatJetORT);
87  if(!jetFatJetORT.empty()) tools.push_back(&jetFatJetORT);
88  return tools;
89  }
90 
91  //-------------------------------------------------------------------------
92  // Initialize one overlap tool
93  //-------------------------------------------------------------------------
94  StatusCode ToolBox::initTool(OverlapHandle_t& handle, const std::string& key)
95  {
96  // Handle must be non-empty
97  if(!handle.empty()) {
98  ATH_MSG_DEBUG("Initializing " << handle.name());
99  ATH_MSG_DEBUG(" type " << handle.type());
100  ATH_MSG_DEBUG(" isInitialized " << handle.isInitialized());
101 
102  // Initialize the handle - WB: NO DON'T DO THIS ...
103  // the naming of the tool implies it's a subtool, so it mustn't be created before
104  // the parent tool is, because otherwise the parent tool doesn't get configured properly
105  // if the configuration has been done on the C++ side (the state of the joboptionsvc hasn't
106  // been updated yet) ... triggering the initialization would trigger the creation of the master tool
107  // because it's deemed to be a parent by the naming convention parent.child
108 
109  // Add it to the master tool
110  if(!masterTool.empty()) {
111  ATH_CHECK( masterTool.setProperty(key, handle) );
112  }
113  }
114  return StatusCode::SUCCESS;
115  }
116 
117  //-------------------------------------------------------------------------
118  // Initialize master tool
119  //-------------------------------------------------------------------------
121  {
122  // For now, we look for a non-empty "type"
123  if(!masterTool.empty()) {
124  ATH_MSG_DEBUG("Initializing master " << masterTool.name());
125  ATH_MSG_DEBUG(" type " << masterTool.type());
126  ATH_MSG_DEBUG(" isInitialized " << masterTool.isInitialized());
127  if(!masterTool.isInitialized()) {
129  }
130  }
131  return StatusCode::SUCCESS;
132  }
133 
134 } // namespace ORUtils
asg::AnaToolHandle::initialize
StatusCode initialize()
initialize the tool
ORUtils::ToolBox::m_parent
parentType_t * m_parent
Pointer to the parent component for the tool handles.
Definition: ToolBox.h:95
asg::AnaToolHandle< IOverlapTool >
ORUtils::ToolBox::eleMuORT
OverlapHandle_t eleMuORT
Definition: ToolBox.h:70
ORUtils::ToolBox::ToolBox
ToolBox(const std::string &name="ORToolBox", parentType_t *theParent=nullptr)
Basic constructor with name and parent.
Definition: ToolBox.cxx:14
asg
Definition: DataHandleTestTool.h:28
ORUtils::ToolBox::eleFatJetORT
OverlapHandle_t eleFatJetORT
Definition: ToolBox.h:79
asg::AnaToolHandle::setProperty
StatusCode setProperty(const std::string &property, const T2 &value)
set the given property of the tool.
ORUtils
Definition: AltMuJetOverlapTool.h:20
ORUtils::ToolBox::parentType_t
INamedInterface parentType_t
Aliases.
Definition: ToolBox.h:44
ToolBox.h
ORUtils::ToolBox::muJetORT
OverlapHandle_t muJetORT
Definition: ToolBox.h:72
ORUtils::ToolBox::eleJetORT
OverlapHandle_t eleJetORT
Definition: ToolBox.h:71
asg::AnaToolHandle::type
const std::string & type() const noexcept
the type configured for this AnaToolHandle
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ORUtils::ToolBox::getOverlapTools
std::vector< OverlapHandle_t * > getOverlapTools()
Get a list of all handles to loop over.
Definition: ToolBox.cxx:71
ORUtils::ToolBox::tauEleORT
OverlapHandle_t tauEleORT
Definition: ToolBox.h:73
ORUtils::ToolBox::jetFatJetORT
OverlapHandle_t jetFatJetORT
Definition: ToolBox.h:80
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ORUtils::ToolBox::tauMuORT
OverlapHandle_t tauMuORT
Definition: ToolBox.h:74
ORUtils::ToolBox::initialize
StatusCode initialize()
Attach and initialize all tools.
Definition: ToolBox.cxx:35
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ORUtils::ToolBox::tauJetORT
OverlapHandle_t tauJetORT
Definition: ToolBox.h:75
ORUtils::ToolBox::initTool
StatusCode initTool(OverlapHandle_t &handle, const std::string &key)
Initialize and attach one overlap tool.
Definition: ToolBox.cxx:94
ORUtils::ToolBox::phoMuORT
OverlapHandle_t phoMuORT
Definition: ToolBox.h:77
ORUtils::ToolBox::phoEleORT
OverlapHandle_t phoEleORT
Definition: ToolBox.h:76
tools
Definition: DataQuality/ZLumiScripts/python/tools/__init__.py:1
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
asg::AnaToolHandle::name
const std::string & name() const noexcept
the name configured for this AnaToolHandle
ORUtils::ToolBox::eleEleORT
OverlapHandle_t eleEleORT
Definition: ToolBox.h:69
asg::AnaToolHandle::isInitialized
bool isInitialized() const noexcept
whether initialize has been called successfully, i.e.
ORUtils::ToolBox::masterTool
MasterHandle_t masterTool
Master overlap removal tool handle.
Definition: ToolBox.h:64
ORUtils::ToolBox::phoJetORT
OverlapHandle_t phoJetORT
Definition: ToolBox.h:78
asg::AnaToolHandle::empty
bool empty() const
whether this ToolHandle is completely empty, i.e.
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
ORUtils::ToolBox::initMaster
StatusCode initMaster()
Initialize master tool.
Definition: ToolBox.cxx:120