ATLAS Offline Software
Loading...
Searching...
No Matches
CaloUtils::ToolWithConstantsImpl Class Reference

Internal implementation object. More...

#include <ToolWithConstants.h>

Collaboration diagram for CaloUtils::ToolWithConstantsImpl:

Public Types

using Context = ToolConstantsContext

Public Member Functions

 ToolWithConstantsImpl (const std::string &toolName, const std::string &prefix, SG::ReadCondHandleKey< CaloRec::ToolConstants > &DBHandle)
 Constructor.
StatusCode initialize ()
 Initialize.
Context context (const EventContext &ctx) const
 Create a Context object.
void addConstant (IToolConstant *c)
 Add a new constant to the tool.
void writeConstants (std::ostream &stream, const std::string &name, const EventContext &ctx) const
 Dump method (for debugging)
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.

Public Attributes

std::string m_toolName
 Name of the owning tool.
const std::string & m_prefix
 The prefix of this constant in COOL.
CaloRec::ToolConstants m_constants
 For settings made from JO.
SG::ReadCondHandleKey< CaloRec::ToolConstants > & m_DBHandle
 Handle to a ToolConstants conditions object.
std::vector< IToolConstant * > m_declaredConstants
 All constants declared to this tool.

Detailed Description

Internal implementation object.

Allows factoring out code which doesn't depend on template parameters.

Definition at line 101 of file ToolWithConstants.h.

Member Typedef Documentation

◆ Context

Constructor & Destructor Documentation

◆ ToolWithConstantsImpl()

CaloUtils::ToolWithConstantsImpl::ToolWithConstantsImpl ( const std::string & toolName,
const std::string & prefix,
SG::ReadCondHandleKey< CaloRec::ToolConstants > & DBHandle )

Constructor.

Parameters
toolNameName of the tool.
prefixConstant prefix in COOL.
DBHandleHandle key for the conditions object.

Definition at line 24 of file ToolWithConstants.cxx.

28 : m_toolName (toolName),
29 m_prefix (prefix),
30 m_DBHandle (DBHandle)
31{
32}
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.

Member Function Documentation

◆ addConstant()

void CaloUtils::ToolWithConstantsImpl::addConstant ( IToolConstant * c)

Add a new constant to the tool.

Parameters
cConstant to add.

Definition at line 66 of file ToolWithConstants.cxx.

67{
68 m_declaredConstants.push_back (c);
69}
std::vector< IToolConstant * > m_declaredConstants
All constants declared to this tool.

◆ context()

ToolWithConstantsImpl::Context CaloUtils::ToolWithConstantsImpl::context ( const EventContext & ctx) const

Create a Context object.

This can then be passed to Constant::operator().

Definition at line 51 of file ToolWithConstants.cxx.

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}

◆ initialize()

StatusCode CaloUtils::ToolWithConstantsImpl::initialize ( )

Initialize.

Definition at line 38 of file ToolWithConstants.cxx.

39{
40 ATH_CHECK( m_DBHandle.initialize (SG::AllowEmpty) );
41 return StatusCode::SUCCESS;
42}
#define ATH_CHECK
Evaluate an expression and check for errors.

◆ mergeConstants()

StatusCode CaloUtils::ToolWithConstantsImpl::mergeConstants ( const std::string & typeName,
int toolVersion,
Context & myctx,
bool isDummy,
CaloRec::ToolConstants & out ) const

Merge our constants into out with the proper prefix.

Parameters
typeNameName of the type of the tool.
toolVersionVersion of the tool.
myctxInternal Context structure.
isDummyisDummy constant from the tool
[out]outObject to receive our constants.

Definition at line 101 of file ToolWithConstants.cxx.

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}
#define REPORT_ERROR_WITH_CONTEXT(SC, CONTEXT_NAME)
Report an error, with an explicitly specified context name.
CaloRec::ToolConstants m_constants
For settings made from JO.

◆ writeConstants()

void CaloUtils::ToolWithConstantsImpl::writeConstants ( std::ostream & stream,
const std::string & name,
const EventContext & ctx ) const

Dump method (for debugging)

Parameters
streamOstream to which to write.
nameName to go in output
ctxEvent context.

Definition at line 78 of file ToolWithConstants.cxx.

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}

Member Data Documentation

◆ m_constants

CaloRec::ToolConstants CaloUtils::ToolWithConstantsImpl::m_constants

For settings made from JO.

Definition at line 176 of file ToolWithConstants.h.

◆ m_DBHandle

SG::ReadCondHandleKey<CaloRec::ToolConstants>& CaloUtils::ToolWithConstantsImpl::m_DBHandle

Handle to a ToolConstants conditions object.

Definition at line 179 of file ToolWithConstants.h.

◆ m_declaredConstants

std::vector<IToolConstant*> CaloUtils::ToolWithConstantsImpl::m_declaredConstants

All constants declared to this tool.

Definition at line 182 of file ToolWithConstants.h.

◆ m_prefix

const std::string& CaloUtils::ToolWithConstantsImpl::m_prefix

The prefix of this constant in COOL.

Definition at line 173 of file ToolWithConstants.h.

◆ m_toolName

std::string CaloUtils::ToolWithConstantsImpl::m_toolName

Name of the owning tool.

Definition at line 167 of file ToolWithConstants.h.


The documentation for this class was generated from the following files: