ATLAS Offline Software
Loading...
Searching...
No Matches
CaloUtils Namespace Reference

Classes

class  ToolWithConstantsTestTool
 Algorithm used for testing ToolWithConstants. More...
class  ExcBadToolConstantVersion
 Exception — version mismatch for tool. More...
class  ExcConstantNotSet
 Exception — constant not set. More...
class  ExcConstantReset
 Exception — constant set more than once. More...
class  ExcBadContextlessRetrieve
 Exception — Bad contextless retrieve. More...
struct  ToolConstantsContext
 Context object for retrieving ToolConstant values. More...
class  IToolConstant
 Internal interface for dealing with a collection of ToolConstants. More...
class  ToolWithConstantsImpl
 Internal implementation object. More...
class  ToolConstant
 Constant of a ToolWithConstants. More...

Concepts

concept  HasProperties
 Concept to test if a class has Gaudi properties.

Functions

void throwExcBadContextlessRetrieve (const std::string &toolName, const std::string &constName)
 Throw a CaloUtils::ExcBadContextlessRetrieve exception.
virtual StatusCode initialize () override
 Hold constants for a tool.
Context context (const EventContext &ctx) const
 Create a Context object.
virtual void writeConstants (std::ostream &stream, const std::string &name, const EventContext &ctx) const
 Dump method (for debugging).
virtual StatusCode mergeConstants (CaloRec::ToolConstants &out, const EventContext &ctx) const override
 Merge our constants into out with the proper prefix.
virtual int toolVersion () const
 Return the version number for this tool.
virtual const std::string & toolType () const
 Return the name of the type of this tool.
std::string excBadToolConstantVersion_format (const std::string &toolName, const std::string &constName, unsigned int toolVersion, unsigned int constVersion)
 Helper: Format exception string.
std::string excConstantNotSet_format (const std::string &toolName, const std::string &constName)
 Helper: Format exception string.
std::string excConstantReset_format (const std::string &toolName, const std::string &constName)
 Helper: Format exception string.
std::string excBadContextlessRetrieve_format (const std::string &toolName, const std::string &constName)
 Helper: Format exception string.

Variables

SG::ReadCondHandleKey< CaloRec::ToolConstantsm_DBHandle { this, "DBHandleKey", "", "" }
 Handle to a ToolConstants conditions object.
StringProperty m_prefix { this, "prefix", "", "" }
 Prefix for finding our constants within the ToolConstants object.
ToolWithConstantsImpl m_impl { this->name(), m_prefix, m_DBHandle }
 Internal implementation object.
Constant< int > m_order { this, "order", 0 }
 Used to fix the ordering of tools when we're initializing from COOL based on a hierarchical tag. Tools should be executed in order of increasing m_order.
Constant< bool > m_isdummy {this, "isDummy", false }
 If true, then this is a dummy tool that should not be executed. This is used for the case of reading from COOL using hierarchical tags: we need to have such tags associated with some object in each folder, regardless of whether or not the correction from that folder is actually used. [Every folder that IOVDbSvc knows about at configuration time needs to have a valid object for the configured tag, else IOVDbSvc will raise a fatal error. But we don't know at configuration time which folders we're actually going to need, so we gotta configure all of them.].

Function Documentation

◆ context()

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

Create a Context object.

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

◆ excBadContextlessRetrieve_format()

std::string CaloUtils::excBadContextlessRetrieve_format ( const std::string & toolName,
const std::string & constName )

Helper: Format exception string.

Definition at line 114 of file Calorimeter/CaloUtils/src/exceptions.cxx.

116{
117 std::ostringstream os;
118 os << "ExcBadContextlessRetrieve: constant " << constName << " in tool " << toolName
119 << " bad contextless retrieve.";
120 return os.str();
121}

◆ excBadToolConstantVersion_format()

std::string CaloUtils::excBadToolConstantVersion_format ( const std::string & toolName,
const std::string & constName,
unsigned int toolVersion,
unsigned int constVersion )

Helper: Format exception string.

Definition at line 20 of file Calorimeter/CaloUtils/src/exceptions.cxx.

24{
25 std::ostringstream os;
26 os << "ExcBadToolConstantVersion: version mismatch for tool " << toolName
27 << " constant " << constName
28 << " constant version " << constVersion
29 << " is larger than tool version " << toolVersion;
30 return os.str();
31}
virtual int toolVersion() const
Return the version number for this tool.

◆ excConstantNotSet_format()

std::string CaloUtils::excConstantNotSet_format ( const std::string & toolName,
const std::string & constName )

Helper: Format exception string.

Definition at line 58 of file Calorimeter/CaloUtils/src/exceptions.cxx.

60{
61 std::ostringstream os;
62 os << "ExcConstantNotSet: constant " << constName << " in tool " << toolName
63 << " was not set.";
64 return os.str();
65}

◆ excConstantReset_format()

std::string CaloUtils::excConstantReset_format ( const std::string & toolName,
const std::string & constName )

Helper: Format exception string.

Definition at line 86 of file Calorimeter/CaloUtils/src/exceptions.cxx.

88{
89 std::ostringstream os;
90 os << "ExcConstantReset: constant " << constName << " in tool " << toolName
91 << " set more than once.";
92 return os.str();
93}

◆ initialize()

virtual StatusCode CaloUtils::initialize ( )
overridevirtual

Hold constants for a tool.

Certain tools, such as correction tools, have a large number of constants associated with them. One does not want to hard-code these constants; instead, the tools should be able to get them either from job options or from a COOL database.

This class extends Gaudi components to manage a set of `Constants', which are like properties but can be set either from job options or from COOL (or possibly defaulted). The constants may either be scalar arithmetic types (floating-point, integer, boolean) or an specialization of CxxUtils::Array<N>. (Note, however, that the values are always stored as single-precision floating-point.)

A Constant may be declared similarly to a Gaudi property. To retrieve its value, call context() and then pass that to the operator() method of the Constant.

This is probably best shown as an example.

*

class MyTool
: public CaloUtils::ToolWithConstants<AthAlgTool>
{
// Define a floating-point constant, with a default value.
Constant<float> m_cf
{ this, "FloatConst", 1.5, "A description" };
// Define an integer constant, with no default value.
Constant<int> m_ci
{ this, "IntConst", "A description" };
// Define a two-dimensional array constant.
// Array constants do not have defaults.
Constant<CxxUtils::Array<2> > m_ca
{ this, "ArrayConst", "A description" };
public:
// The constructor can be delegated to the base class.
using base_base::base_class;
// If you have an initialize() method, you must call the
// base class version.
virtual StatusCode initialize() override
{
ATH_CHECK( base_class::initialize() );
return StatusCode::SUCCESS;
}
void doit (const EventContext& ctx) const
{
// Make a local context object.
Context myctx = context (ctx);
// Retrieve the constants.
float cf = m_cf (myctx);
int ci = m_ci (myctx);
CxxUtils::Array<2> ca = m_ca (myctx);
#define ATH_CHECK
Evaluate an expression and check for errors.
Context context(const EventContext &ctx) const
Create a Context object.
::StatusCode StatusCode
StatusCode definition for legacy code.
void initialize()

Constants that come from COOL are kept in a ToolConstants conditions object; the key of this object is set from the DBHandleKey property. Constants for multiple tools may be combined in a single ToolConstants object. Each tool has a string prefix (unique within such a group) that is added to the constant name when it is looked up in the ToolConstants object.

For data that are stored as inline COOL data, a conditions algorithm is used to populate a ToolConstants object from COOL.

Settings from COOL may be overridden with settings from job options. For values that are arrays, the value should be set as a string. */ template <HasProperties BASE> class ToolWithConstants : public extends<BASE, IToolWithConstants> { public: / Shorthand for derived classes. typedef ToolWithConstants base_class;

/ Inherit constructor. using extends<BASE, IToolWithConstants>::extends;

/ Convenient alias for the Context type. using Context = CaloUtils::ToolConstantsContext;

/ Alias for the Constant type. template <CxxUtils::FromArrayrep T> using Constant = ToolConstant<T>;

/**

Initialize method. Derived classes must call this.

◆ mergeConstants()

virtual StatusCode CaloUtils::mergeConstants ( CaloRec::ToolConstants & out,
const EventContext & ctx ) const
overridevirtual

Merge our constants into out with the proper prefix.

Parameters
[out]outObject to receive our constants.
ctxEvent context.

◆ throwExcBadContextlessRetrieve()

void CaloUtils::throwExcBadContextlessRetrieve ( const std::string & toolName,
const std::string & constName )

Throw a CaloUtils::ExcBadContextlessRetrieve exception.

Parameters
toolNameName of the tool being used.
constNameName of the constant being retrieved.

Definition at line 144 of file Calorimeter/CaloUtils/src/exceptions.cxx.

146{
147 throw ExcBadContextlessRetrieve (toolName, constName);
148}

◆ toolType()

virtual const std::string & CaloUtils::toolType ( ) const
virtual

Return the name of the type of this tool.

A saved set of constants includes both the C++ class name and a version number. Normally, the class name is taken from the Gaudi type() method, but that may be changed by overriding this method. This can be used, for example, when there are tools with distinct C++ classes but which are yet similar enough to combine together.

◆ toolVersion()

virtual int CaloUtils::toolVersion ( ) const
virtual

Return the version number for this tool.

A saved set of constants includes both the C++ class name and a version number. The idea is that the version number can be bumped whenever there's a backwards-incompatible change; this gives some protection against trying to use an old version of a tool with an incompatible newer set of constants.

If you want a tool to have a version number, override this method. Otherwise, it will default to a version number of 0.

◆ writeConstants()

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

Dump method (for debugging).

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

Variable Documentation

◆ m_DBHandle

SG::ReadCondHandleKey<CaloRec::ToolConstants> CaloUtils::m_DBHandle { this, "DBHandleKey", "", "" }
private

Handle to a ToolConstants conditions object.

Definition at line 534 of file ToolWithConstants.h.

535{ this, "DBHandleKey", "", "" };

◆ m_impl

ToolWithConstantsImpl CaloUtils::m_impl { this->name(), m_prefix, m_DBHandle }
private

Internal implementation object.

Definition at line 542 of file ToolWithConstants.h.

542{ this->name(), m_prefix, m_DBHandle };
StringProperty m_prefix
Prefix for finding our constants within the ToolConstants object.
SG::ReadCondHandleKey< CaloRec::ToolConstants > m_DBHandle
Handle to a ToolConstants conditions object.

◆ m_isdummy

Constant<bool> CaloUtils::m_isdummy {this, "isDummy", false }
private

If true, then this is a dummy tool that should not be executed. This is used for the case of reading from COOL using hierarchical tags: we need to have such tags associated with some object in each folder, regardless of whether or not the correction from that folder is actually used. [Every folder that IOVDbSvc knows about at configuration time needs to have a valid object for the configured tag, else IOVDbSvc will raise a fatal error. But we don't know at configuration time which folders we're actually going to need, so we gotta configure all of them.].

Definition at line 560 of file ToolWithConstants.h.

561{this, "isDummy", false };

◆ m_order

Constant<int> CaloUtils::m_order { this, "order", 0 }
private

Used to fix the ordering of tools when we're initializing from COOL based on a hierarchical tag. Tools should be executed in order of increasing m_order.

Definition at line 547 of file ToolWithConstants.h.

548{ this, "order", 0 };

◆ m_prefix

StringProperty CaloUtils::m_prefix { this, "prefix", "", "" }
private

Prefix for finding our constants within the ToolConstants object.

Definition at line 538 of file ToolWithConstants.h.

539{ this, "prefix", "", "" };