ATLAS Offline Software
Loading...
Searching...
No Matches
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
13
14
15namespace CaloUtils {
16
17
25 (const std::string& toolName,
26 const std::string& prefix,
28 : m_toolName (toolName),
29 m_prefix (prefix),
30 m_DBHandle (DBHandle)
31{
32}
33
34
39{
40 ATH_CHECK( m_DBHandle.initialize (SG::AllowEmpty) );
41 return StatusCode::SUCCESS;
42}
43
44
51ToolWithConstantsImpl::context (const EventContext& ctx) const
52{
53 const CaloRec::ToolConstants* constants = nullptr;
54 if (!m_DBHandle.empty()) {
56 constants = consts.retrieve();
57 }
58 return Context (constants, ctx);
59}
60
61
70
71
78void 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()) {
86 stream << "Member: m_DBconstants" << std::endl;
87 consts->writeConstants (stream,name);
88 }
89}
90
91
100StatusCode
101ToolWithConstantsImpl::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
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define REPORT_ERROR_WITH_CONTEXT(SC, CONTEXT_NAME)
Report an error, with an explicitly specified context name.
Hold constants for a tool.
Container for the tool constants managed by ToolWithConstants.
bool hasrep(const std::string &key) const
Test to see if a given key is present.
const CxxUtils::Arrayrep & getrep(const std::string &context, const std::string &key) const
Look up an entry.
Internal interface for dealing with a collection of ToolConstants.
void writeConstants(std::ostream &stream, const std::string &name, const EventContext &ctx) const
Dump method (for debugging)
Context context(const EventContext &ctx) const
Create a Context object.
CaloRec::ToolConstants m_constants
For settings made from JO.
std::vector< IToolConstant * > m_declaredConstants
All constants declared to this tool.
void addConstant(IToolConstant *c)
Add a new constant to the tool.
ToolWithConstantsImpl(const std::string &toolName, const std::string &prefix, SG::ReadCondHandleKey< CaloRec::ToolConstants > &DBHandle)
Constructor.
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.
std::string m_toolName
Name of the owning tool.
const std::string & m_prefix
The prefix of this constant in COOL.
SG::ReadCondHandleKey< CaloRec::ToolConstants > & m_DBHandle
Handle to a ToolConstants conditions object.
const_pointer_type retrieve()
Representation class for Array's.
const CaloRec::ToolConstants * m_constants