ATLAS Offline Software
AsgComponentFactories.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 //
9 // includes
10 //
11 
13 
14 #include <AsgTools/IAsgTool.h>
16 #include <tbb/concurrent_unordered_map.h>
17 
18 //
19 // method implementations
20 //
21 
22 namespace asg
23 {
24 #ifdef XAOD_STANDALONE
25 
26  namespace
27  {
28  tbb::concurrent_unordered_map<std::string, std::function<std::unique_ptr<AsgComponent>(const std::string& name)>> s_factories;
29  }
30 
31 
32 
33  StatusCode registerComponentFactory (const std::string& type, const std::function<std::unique_ptr<AsgComponent>(const std::string& name)>& factory)
34  {
35  using namespace msgComponentConfig;
36  if (!s_factories.emplace (type, factory).second)
37  {
38  ATH_MSG_ERROR ("attempt to register a factory for type " << type << " that already has a factory");
39  return StatusCode::FAILURE;
40  }
41  return StatusCode::SUCCESS;
42  }
43 
44 
45 
46  const std::function<std::unique_ptr<AsgComponent>(const std::string& name)> *getComponentFactory (const std::string& type)
47  {
48  auto iter = s_factories.find (type);
49  if (iter == s_factories.end())
50  return nullptr;
51  return &iter->second;
52  }
53 
54 #endif
55 }
asg
Definition: DataHandleTestTool.h:28
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
IAsgTool.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AsgComponentFactories.h
MessageCheckAsgTools.h