ATLAS Offline Software
ToolWithConstants.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
3  */
13 
14 
15 namespace 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 {
41  return StatusCode::SUCCESS;
42 }
43 
44 
51 ToolWithConstantsImpl::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 
67 {
68  m_declaredConstants.push_back (c);
69 }
70 
71 
79  const std::string& name,
80  const EventContext& ctx) const
81 {
82  stream << "Member: m_constants" << std::endl;
84  if (!m_DBHandle.empty()) {
86  stream << "Member: m_DBconstants" << std::endl;
87  consts->writeConstants (stream,name);
88  }
89 }
90 
91 
102  int toolVersion,
103  Context& myctx,
104  bool isDummy,
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
CaloUtils::ToolWithConstantsImpl::m_constants
CaloRec::ToolConstants m_constants
For settings made from JO.
Definition: ToolWithConstants.h:177
CaloRec::ToolConstants::writeConstants
void writeConstants(std::ostream &stream, const std::string &name) const
Writes out constants in a python-like format.
Definition: ToolConstants.cxx:126
CaloUtils::ToolWithConstantsImpl::addConstant
void addConstant(IToolConstant *c)
Add a new constant to the tool.
Definition: ToolWithConstants.cxx:66
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
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
Definition: ToolWithConstantsTestTool.h:21
make_hlt_rep.rep
rep
Definition: make_hlt_rep.py:32
CaloUtils::ToolWithConstantsImpl::m_toolName
std::string m_toolName
Name of the owning tool.
Definition: ToolWithConstants.h:168
ToolWithConstants.h
Hold constants for a tool.
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
CaloRec::ToolConstants::hasrep
bool hasrep(const std::string &key) const
Test to see if a given key is present.
Definition: ToolConstants.cxx:101
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
SG::ReadCondHandle::retrieve
const_pointer_type retrieve()
Definition: ReadCondHandle.h:162
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
CaloUtils::ToolWithConstantsImpl::Context
ToolConstantsContext Context
Definition: ToolWithConstants.h:105
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloUtils::ToolWithConstantsImpl::m_declaredConstants
std::vector< IToolConstant * > m_declaredConstants
All constants declared to this tool.
Definition: ToolWithConstants.h:183
CaloUtils::ToolWithConstantsImpl::context
Context context(const EventContext &ctx) const
Create a Context object.
Definition: ToolWithConstants.cxx:51
CaloUtils::IToolConstant
Internal interface for dealing with a collection of ToolConstants.
Definition: ToolWithConstants.h:81
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
SG::ReadCondHandleKey< CaloRec::ToolConstants >
CaloRec::ToolConstants
Container for the tool constants managed by ToolWithConstants.
Definition: ToolConstants.h:32
constants
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:1
CaloRec::Arrayrep
Representation class for Array's.
Definition: Control/CxxUtils/CxxUtils/Arrayrep.h:62
CaloUtils::ExcConstantNotSet
Exception — constant not set.
Definition: Calorimeter/CaloUtils/CaloUtils/exceptions.h:55
CaloUtils::ToolConstantsContext
Context object for retrieving ToolConstant values.
Definition: ToolWithConstants.h:61
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
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::ToolConstantsContext::m_constants
const CaloRec::ToolConstants * m_constants
Definition: ToolWithConstants.h:71
CaloUtils::ToolWithConstantsImpl::ToolWithConstantsImpl
ToolWithConstantsImpl(const std::string &toolName, const std::string &prefix, SG::ReadCondHandleKey< CaloRec::ToolConstants > &DBHandle)
Constructor.
Definition: ToolWithConstants.cxx:25
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
CaloUtils::ToolWithConstantsImpl::m_DBHandle
SG::ReadCondHandleKey< CaloRec::ToolConstants > & m_DBHandle
Handle to a ToolConstants conditions object.
Definition: ToolWithConstants.h:180
python.compressB64.c
def c
Definition: compressB64.py:93
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
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::ToolWithConstantsImpl::initialize
StatusCode initialize()
Initialize.
Definition: ToolWithConstants.cxx:38
CaloUtils::ToolWithConstantsImpl::m_prefix
const std::string & m_prefix
The prefix of this constant in COOL.
Definition: ToolWithConstants.h:174