ATLAS Offline Software
UnitTestTool2.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 
9 //
10 // includes
11 //
12 
14 
16 
17 //
18 // method implementations
19 //
20 
21 namespace asg
22 {
24  UnitTestTool2 (const std::string& val_name)
25  : AsgTool (val_name),
26  m_regPublicHandle ("", nullptr),
27  m_regPrivateHandle ("", this),
28  m_anaPublicHandle ("asg::UnitTestTool1/anaPublicHandle", nullptr),
29  m_anaPrivateHandle ("asg::UnitTestTool1/anaPrivateHandle", this)
30  {
31  declareProperty ("allowEmpty", m_allowEmpty);
32 
33  declareProperty ("regPublicHandle", m_regPublicHandle);
34  declareProperty ("regPrivateHandle", m_regPrivateHandle);
35  m_anaPublicHandle.declarePropertyFor (this, "anaPublicHandle");
36  m_anaPrivateHandle.declarePropertyFor (this, "anaPrivateHandle");
37  }
38 
39 
40 
42  initialize ()
43  {
44  m_anaPublicHandle.setAllowEmpty (m_allowEmpty);
45  m_anaPrivateHandle.setAllowEmpty (m_allowEmpty);
46 
47  m_wasUserConfiguredPublic = m_anaPublicHandle.isUserConfigured();
48  ANA_CHECK (m_anaPublicHandle.setProperty ("propertyInt", 111));
49  ANA_CHECK (m_anaPublicHandle.initialize ());
50 
52  ANA_CHECK (m_anaPrivateHandle.setProperty ("propertyInt", 222));
53  ANA_CHECK (m_anaPrivateHandle.initialize ());
54 
55  for (auto& handle : m_regPrivateArray)
56  ANA_CHECK (handle.retrieve());
57 
58  return StatusCode::SUCCESS;
59  }
60 
61 
62 
64  toolHandleEmpty (const std::string& handleName) const
65  {
66  if (handleName == "regPublicHandle")
67  return m_regPublicHandle.empty();
68  if (handleName == "regPrivateHandle")
69  return m_regPrivateHandle.empty();
70  if (handleName == "anaPublicHandle")
71  return m_anaPublicHandle.empty();
72  if (handleName == "anaPrivateHandle")
73  return m_anaPrivateHandle.empty();
74  throw std::runtime_error ("unknown handle: " + handleName);
75  }
76 
77 
78 
80  getToolHandle (const std::string& handleName) const
81  {
82  if (handleName == "regPublicHandle")
83  return &*m_regPublicHandle;
84  if (handleName == "regPrivateHandle")
85  return &*m_regPrivateHandle;
86  if (handleName == "anaPublicHandle")
87  return &*m_anaPublicHandle;
88  if (handleName == "anaPrivateHandle")
89  return &*m_anaPrivateHandle;
90  throw std::runtime_error ("unknown handle: " + handleName);
91  }
92 
93 
94 
96  retrieveToolHandle (const std::string& handleName) const
97  {
98  if (handleName == "regPublicHandle")
99  return m_regPublicHandle.retrieve ();
100  if (handleName == "regPrivateHandle")
101  return m_regPrivateHandle.retrieve ();
102  throw std::runtime_error ("unknown handle: " + handleName);
103  }
104 
105 
106 
108  wasUserConfigured (const std::string& handleName) const
109  {
110  if (handleName == "anaPublicHandle")
112  if (handleName == "anaPrivateHandle")
114  throw std::runtime_error ("unknown handle: " + handleName);
115  }
116 
117 
118 
119  const ToolHandleArray<IUnitTestTool1>& UnitTestTool2 ::
120  getArray () const
121  {
122  return m_regPrivateArray;
123  }
124 }
asg::UnitTestTool2::m_wasUserConfiguredPrivate
bool m_wasUserConfiguredPrivate
Definition: UnitTestTool2.h:75
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
asg::UnitTestTool2::m_allowEmpty
bool m_allowEmpty
Definition: UnitTestTool2.h:78
asg::UnitTestTool2::m_regPrivateArray
ToolHandleArray< IUnitTestTool1 > m_regPrivateArray
Definition: UnitTestTool2.h:68
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
asg::UnitTestTool2::toolHandleEmpty
virtual bool toolHandleEmpty(const std::string &handleName) const override
whether the given ToolHandle is empty
Definition: UnitTestTool2.cxx:64
asg::UnitTestTool2::m_anaPublicHandle
AnaToolHandle< IUnitTestTool1 > m_anaPublicHandle
Definition: UnitTestTool2.h:62
asg
Definition: DataHandleTestTool.h:28
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
asg::IUnitTestTool1
the interface for UnitTestTool1
Definition: IUnitTestTool1.h:19
asg::UnitTestTool2::m_wasUserConfiguredPublic
bool m_wasUserConfiguredPublic
Definition: UnitTestTool2.h:72
asg::UnitTestTool2::wasUserConfigured
virtual bool wasUserConfigured(const std::string &handleName) const override
whether the AnaToolHandle was user configured
Definition: UnitTestTool2.cxx:108
asg::UnitTestTool2::getArray
virtual const ToolHandleArray< IUnitTestTool1 > & getArray() const override
get the tool handle array
Definition: UnitTestTool2.cxx:120
asg::UnitTestTool2::m_anaPrivateHandle
AnaToolHandle< IUnitTestTool1 > m_anaPrivateHandle
Definition: UnitTestTool2.h:65
UnitTestTool2.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
UnitTestTool1.h
asg::UnitTestTool2::initialize
StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: UnitTestTool2.cxx:42
asg::UnitTestTool2::retrieveToolHandle
virtual StatusCode retrieveToolHandle(const std::string &handleName) const override
call retrieve on the regular ToolHandle
Definition: UnitTestTool2.cxx:96
asg::UnitTestTool2::UnitTestTool2
UnitTestTool2(const std::string &val_name)
standard constructor
Definition: UnitTestTool2.cxx:24
asg::UnitTestTool2::getToolHandle
virtual const IUnitTestTool1 * getToolHandle(const std::string &handleName) const override
get the tool from the regular ToolHandle
Definition: UnitTestTool2.cxx:80
asg::UnitTestTool2::m_regPrivateHandle
ToolHandle< IUnitTestTool1 > m_regPrivateHandle
Definition: UnitTestTool2.h:59
asg::UnitTestTool2::m_regPublicHandle
ToolHandle< IUnitTestTool1 > m_regPublicHandle
Definition: UnitTestTool2.h:56