Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
UnitTestTool1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 
9 //
10 // includes
11 //
12 
14 
15 #include <map>
16 #include <mutex>
17 
18 //
19 // method implementations
20 //
21 
22 namespace asg
23 {
25  UnitTestTool1 (const std::string& val_name)
26  : AsgTool (val_name)
27  {
28  std::scoped_lock lock(m_mutex);
29  ++ m_instances[name()];
30 
31  ANA_MSG_DEBUG ("create UnitTestTool1 " << this);
32  }
33 
34 
35 
38  {
39  ANA_MSG_DEBUG ("destroy UnitTestTool1 " << this);
40 
41  std::scoped_lock lock(m_mutex);
42  -- m_instances[name()];
43  }
44 
45 
46 
48  initialize ()
49  {
50  ANA_MSG_INFO ("initialize UnitTestTool1 " << this);
51  ANA_MSG_INFO (" propertyString: " << m_propertyString);
52  ANA_MSG_INFO (" propertyInt: " << m_propertyInt);
53 
54  if (m_initializeFail)
55  {
56  ATH_MSG_ERROR ("tool configured to fail initialize");
57  return StatusCode::FAILURE;
58  }
59  if (m_isInitialized)
60  {
61  ATH_MSG_ERROR ("initialize called twice");
62  return StatusCode::FAILURE;
63  }
64  m_isInitialized = true;
65  return StatusCode::SUCCESS;
66  }
67 
68 
69 
70  std::string UnitTestTool1 ::
71  getPropertyString () const
72  {
73  return m_propertyString;
74  }
75 
76 
77 
79  getPropertyInt () const
80  {
81  return m_propertyInt;
82  }
83 
84 
85 
87  setPropertyInt (int val_property)
88  {
89  m_propertyInt = val_property;
90  }
91 
92 
93 
95  isInitialized () const
96  {
97  return m_isInitialized;
98  }
99 
100 
101 
103  instance_counts (const std::string& name)
104  {
105  std::scoped_lock lock(m_mutex);
106  auto iter = m_instances.find(name);
107  assert (iter != m_instances.end());
108  return iter->second;
109  }
110 }
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
asg::UnitTestTool1::UnitTestTool1
UnitTestTool1(const std::string &val_name)
standard constructor
Definition: UnitTestTool1.cxx:25
asg::UnitTestTool1::getPropertyString
virtual std::string getPropertyString() const override
get the integer property
Definition: UnitTestTool1.cxx:71
asg
Definition: DataHandleTestTool.h:28
asg::UnitTestTool1::m_propertyString
Gaudi::Property< std::string > m_propertyString
the string property
Definition: UnitTestTool1.h:59
asg::UnitTestTool1::isInitialized
virtual bool isInitialized() const override
get whether we have been initialized
Definition: UnitTestTool1.cxx:95
asg::UnitTestTool1::setPropertyInt
virtual void setPropertyInt(int val_property) override
get the integer property
Definition: UnitTestTool1.cxx:87
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
asg::UnitTestTool1::m_initializeFail
Gaudi::Property< bool > m_initializeFail
whether initialize should fail
Definition: UnitTestTool1.h:65
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
UnitTestTool1.h
asg::UnitTestTool1::instance_counts
static int instance_counts(const std::string &name)
the number of times the tool of the given name has been instantiated
Definition: UnitTestTool1.cxx:103
asg::UnitTestTool1::m_isInitialized
bool m_isInitialized
whether initialize has been called
Definition: UnitTestTool1.h:50
asg::UnitTestTool1::m_propertyInt
Gaudi::Property< int > m_propertyInt
the integer property
Definition: UnitTestTool1.h:62
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
asg::UnitTestTool1::m_mutex
static std::mutex m_mutex
mutex for above map
Definition: UnitTestTool1.h:56
asg::UnitTestTool1::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: UnitTestTool1.cxx:48
asg::UnitTestTool1::getPropertyInt
virtual int getPropertyInt() const override
get the integer property
Definition: UnitTestTool1.cxx:79
asg::UnitTestTool1::~UnitTestTool1
~UnitTestTool1()
standard destructor
Definition: UnitTestTool1.cxx:37
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288