ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Calorimeter
CaloUtils
src
ToolWithConstants.cxx
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
3
*/
10
11
12
#include "
CaloUtils/ToolWithConstants.h
"
13
14
15
namespace
CaloUtils
{
16
17
24
ToolWithConstantsImpl::ToolWithConstantsImpl
25
(
const
std::string& toolName,
26
const
std::string& prefix,
27
SG::ReadCondHandleKey<CaloRec::ToolConstants>
& DBHandle)
28
:
m_toolName
(toolName),
29
m_prefix
(prefix),
30
m_DBHandle
(DBHandle)
31
{
32
}
33
34
38
StatusCode
ToolWithConstantsImpl::initialize
()
39
{
40
ATH_CHECK
(
m_DBHandle
.initialize (
SG::AllowEmpty
) );
41
return
StatusCode::SUCCESS;
42
}
43
44
50
ToolWithConstantsImpl::Context
51
ToolWithConstantsImpl::context
(
const
EventContext& ctx)
const
52
{
53
const
CaloRec::ToolConstants
*
constants
=
nullptr
;
54
if
(!
m_DBHandle
.empty()) {
55
SG::ReadCondHandle<CaloRec::ToolConstants>
consts (
m_DBHandle
, ctx);
56
constants
= consts.
retrieve
();
57
}
58
return
Context
(
constants
, ctx);
59
}
60
61
66
void
ToolWithConstantsImpl::addConstant
(
IToolConstant
* c)
67
{
68
m_declaredConstants
.push_back (c);
69
}
70
71
78
void
ToolWithConstantsImpl::writeConstants
(std::ostream& stream,
79
const
std::string& name,
80
const
EventContext& ctx)
const
81
{
82
stream <<
"Member: m_constants"
<< std::endl;
83
m_constants
.writeConstants (stream,name);
84
if
(!
m_DBHandle
.empty()) {
85
SG::ReadCondHandle<CaloRec::ToolConstants>
consts (
m_DBHandle
, ctx);
86
stream <<
"Member: m_DBconstants"
<< std::endl;
87
consts->writeConstants (stream,name);
88
}
89
}
90
91
100
StatusCode
101
ToolWithConstantsImpl::mergeConstants
(
const
std::string& typeName,
102
int
toolVersion
,
103
Context
& myctx,
104
bool
isDummy,
105
CaloRec::ToolConstants
& out)
const
106
{
107
if
(out.clsname().empty()) {
108
out.clsname (typeName);
109
out.version (
toolVersion
);
110
}
111
else
if
(out.clsname() != typeName) {
112
REPORT_ERROR_WITH_CONTEXT
(StatusCode::FAILURE,
m_toolName
)
113
<<
"Trying to write to ToolConstants for tools of differing types: "
114
<< out.clsname() <<
" and "
<< typeName;
115
return
StatusCode::FAILURE;
116
}
117
else
if
(out.version() !=
toolVersion
) {
118
REPORT_ERROR_WITH_CONTEXT
(StatusCode::FAILURE,
m_toolName
)
119
<<
"Trying to write to ToolConstants for differing versions of tool "
120
<< out.clsname() <<
": "
<< out.version() <<
" and "
<<
toolVersion
;
121
return
StatusCode::FAILURE;
122
}
123
124
for
(
IToolConstant
* c :
m_declaredConstants
) {
125
std::string cname = c->name();
126
std::string prefname = this->
m_prefix
+ cname;
127
const
CaloRec::Arrayrep
* rep =
nullptr
;
128
if
(
m_constants
.hasrep (cname)) {
129
rep = &
m_constants
.getrep (
m_toolName
, cname);
130
}
131
if
(!c->setFromJO() &&
132
myctx.
m_constants
&&
133
myctx.
m_constants
->
hasrep
(prefname))
134
{
135
rep = &myctx.
m_constants
->
getrep
(
m_toolName
, prefname);
136
}
137
if
(!rep) {
138
throw
ExcConstantNotSet
(
m_toolName
, cname);
139
}
140
141
if
(!isDummy || cname ==
"isDummy"
)
142
out.setrep (this->
m_prefix
+ cname, *rep);
143
}
144
return
StatusCode::SUCCESS;
145
}
146
147
148
}
// namespace CaloUtils
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
REPORT_ERROR_WITH_CONTEXT
#define REPORT_ERROR_WITH_CONTEXT(SC, CONTEXT_NAME)
Report an error, with an explicitly specified context name.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:333
ToolWithConstants.h
Hold constants for a tool.
CaloRec::ToolConstants
Container for the tool constants managed by ToolWithConstants.
Definition
ToolConstants.h:32
CaloRec::ToolConstants::hasrep
bool hasrep(const std::string &key) const
Test to see if a given key is present.
Definition
ToolConstants.cxx:101
CaloRec::ToolConstants::getrep
const CxxUtils::Arrayrep & getrep(const std::string &context, const std::string &key) const
Look up an entry.
Definition
ToolConstants.cxx:59
CaloUtils::ExcConstantNotSet
Exception — constant not set.
Definition
Calorimeter/CaloUtils/CaloUtils/exceptions.h:55
CaloUtils::IToolConstant
Internal interface for dealing with a collection of ToolConstants.
Definition
ToolWithConstants.h:80
CaloUtils::ToolWithConstantsImpl::writeConstants
void writeConstants(std::ostream &stream, const std::string &name, const EventContext &ctx) const
Dump method (for debugging).
Definition
ToolWithConstants.cxx:78
CaloUtils::ToolWithConstantsImpl::context
Context context(const EventContext &ctx) const
Create a Context object.
Definition
ToolWithConstants.cxx:51
CaloUtils::ToolWithConstantsImpl::m_constants
CaloRec::ToolConstants m_constants
For settings made from JO.
Definition
ToolWithConstants.h:176
CaloUtils::ToolWithConstantsImpl::initialize
StatusCode initialize()
Initialize.
Definition
ToolWithConstants.cxx:38
CaloUtils::ToolWithConstantsImpl::m_declaredConstants
std::vector< IToolConstant * > m_declaredConstants
All constants declared to this tool.
Definition
ToolWithConstants.h:182
CaloUtils::ToolWithConstantsImpl::addConstant
void addConstant(IToolConstant *c)
Add a new constant to the tool.
Definition
ToolWithConstants.cxx:66
CaloUtils::ToolWithConstantsImpl::ToolWithConstantsImpl
ToolWithConstantsImpl(const std::string &toolName, const std::string &prefix, SG::ReadCondHandleKey< CaloRec::ToolConstants > &DBHandle)
Constructor.
Definition
ToolWithConstants.cxx:25
CaloUtils::ToolWithConstantsImpl::mergeConstants
StatusCode mergeConstants(const std::string &typeName, int toolVersion, Context &myctx, bool isDummy, CaloRec::ToolConstants &out) const
Merge our constants into out with the proper prefix.
Definition
ToolWithConstants.cxx:101
CaloUtils::ToolWithConstantsImpl::m_toolName
std::string m_toolName
Name of the owning tool.
Definition
ToolWithConstants.h:167
CaloUtils::ToolWithConstantsImpl::Context
ToolConstantsContext Context
Definition
ToolWithConstants.h:104
CaloUtils::ToolWithConstantsImpl::m_prefix
const std::string & m_prefix
The prefix of this constant in COOL.
Definition
ToolWithConstants.h:173
CaloUtils::ToolWithConstantsImpl::m_DBHandle
SG::ReadCondHandleKey< CaloRec::ToolConstants > & m_DBHandle
Handle to a ToolConstants conditions object.
Definition
ToolWithConstants.h:179
SG::ReadCondHandleKey
Definition
ReadCondHandleKey.h:21
SG::ReadCondHandle
Definition
ReadCondHandle.h:40
SG::ReadCondHandle::retrieve
const_pointer_type retrieve()
Definition
ReadCondHandle.h:161
CaloUtils
Definition
ToolWithConstantsTestTool.h:21
CaloUtils::toolVersion
virtual int toolVersion() const
Return the version number for this tool.
SG::AllowEmpty
@ AllowEmpty
Definition
StoreGate/StoreGate/VarHandleKey.h:27
constants
Definition
Calorimeter/CaloClusterCorrection/python/constants.py:1
CaloRec::Arrayrep
Representation class for Array's.
Definition
Control/CxxUtils/CxxUtils/Arrayrep.h:62
CaloUtils::ToolConstantsContext::m_constants
const CaloRec::ToolConstants * m_constants
Definition
ToolWithConstants.h:70
Generated on
for ATLAS Offline Software by
1.17.0