ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
CP::OutOfValidityHelper Class Referencefinal

a helper to translate a CP::CorrectionCode into a ::StatusCode More...

#include <OutOfValidityHelper.h>

Inheritance diagram for CP::OutOfValidityHelper:
Collaboration diagram for CP::OutOfValidityHelper:

Public Member Functions

template<typename T >
 OutOfValidityHelper (T *owner, const std::string &propertyName="outOfValidity", const std::string &propertyDescription="how to handle out of validity results")
 standard constructor More...
 
::StatusCode initialize ()
 standard initialize More...
 
::StatusCode check (const xAOD::IParticle &particle, const CP::CorrectionCode &code, const char *context) const
 check the correction code and do the proper thing More...
 
bool get (const xAOD::IParticle &particle) const
 retrieve the OutOfValidity decision, where true = particle passes validity check More...
 
bool msgLvl (const MSG::Level lvl) const
 Test the output level of the object. More...
 
MsgStream & msg () const
 The standard message stream. More...
 
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream. More...
 

Private Attributes

unsigned m_action {unsigned (OutOfValidityAction::ABORT)}
 the action to take More...
 
std::unique_ptr< ISelectionWriteAccessorm_write_accessor
 the accessor if we apply one More...
 
std::unique_ptr< ISelectionReadAccessorm_read_accessor
 
std::string m_decorationName
 the decoration name we use (if we have one) More...
 
bool m_isInitialized = false
 whether we have been initialized More...
 
std::function< MsgStream &()> m_msg
 the message stream we use More...
 

Detailed Description

a helper to translate a CP::CorrectionCode into a ::StatusCode

The prolem is OutOfValidityRange which does not have an equivalent in StatusCode and which does not have a unique, correct handling in all situations. This helper allows to configure a variety of behaviors via properties.

Definition at line 72 of file OutOfValidityHelper.h.

Constructor & Destructor Documentation

◆ OutOfValidityHelper()

template<typename T >
CP::OutOfValidityHelper::OutOfValidityHelper ( T *  owner,
const std::string &  propertyName = "outOfValidity",
const std::string &  propertyDescription = "how to handle out of validity results" 
)

standard constructor

Definition at line 119 of file OutOfValidityHelper.h.

122  : asg::AsgMessagingForward (owner)
123  {
124  owner->declareProperty (propertyName, m_action,
125  propertyDescription);
126  owner->declareProperty (propertyName + "Deco", m_decorationName,
127  "decoration to set alongside action described by " + propertyName);
128  }

Member Function Documentation

◆ check()

StatusCode CP::OutOfValidityHelper::check ( const xAOD::IParticle particle,
const CP::CorrectionCode code,
const char *  context 
) const

check the correction code and do the proper thing

Definition at line 38 of file OutOfValidityHelper.cxx.

42  {
43  assert (m_isInitialized);
44 
45  switch (code)
46  {
48  if (m_write_accessor) m_write_accessor->setBool (particle, true);
49  return StatusCode::SUCCESS;
51  return StatusCode::FAILURE;
53  if (m_write_accessor) m_write_accessor->setBool (particle, false);
54  switch (OutOfValidityAction (m_action))
55  {
57  ANA_MSG_ERROR ("encountered OutOfValidity: " << context);
58  return StatusCode::FAILURE;
60  ANA_MSG_WARNING ("encountered OutOfValidity: " << context);
61  return StatusCode::SUCCESS;
63  return StatusCode::SUCCESS;
64  }
65  }
66  ANA_MSG_ERROR (__FILE__ << ":" << __LINE__ << ": invalid enum value encountered " << code << " " << int (m_action));
67  return StatusCode::FAILURE;
68  }

◆ get()

bool CP::OutOfValidityHelper::get ( const xAOD::IParticle particle) const

retrieve the OutOfValidity decision, where true = particle passes validity check

Definition at line 70 of file OutOfValidityHelper.cxx.

71  {
72  return m_read_accessor->getBool(particle);
73  }

◆ initialize()

StatusCode CP::OutOfValidityHelper::initialize ( )

standard initialize

Definition at line 24 of file OutOfValidityHelper.cxx.

26  {
27  if (!m_decorationName.empty())
28  {
31  }
32 
33  m_isInitialized = true;
34  return StatusCode::SUCCESS;
35  }

◆ msg() [1/2]

MsgStream & asg::AsgMessagingForward::msg ( ) const
inherited

The standard message stream.

Returns
A reference to the default message stream of this object.

Definition at line 24 of file AsgMessagingForward.cxx.

25  {
26  return m_msg();
27  }

◆ msg() [2/2]

MsgStream & asg::AsgMessagingForward::msg ( const MSG::Level  lvl) const
inherited

The standard message stream.

Parameters
lvlThe message level to set the stream to
Returns
A reference to the default message stream, set to level "lvl"

Definition at line 29 of file AsgMessagingForward.cxx.

30  {
31  MsgStream& msg = m_msg ();
32  msg << lvl;
33  return msg;
34  }

◆ msgLvl()

bool asg::AsgMessagingForward::msgLvl ( const MSG::Level  lvl) const
inherited

Test the output level of the object.

Parameters
lvlThe message level to test against
Returns
boolean Indicting if messages at given level will be printed
true If messages at level "lvl" will be printed

Definition at line 11 of file AsgMessagingForward.cxx.

12  {
13  MsgStream& msg = m_msg();
14  if (msg.level() <= lvl)
15  {
16  msg << lvl;
17  return true;
18  } else
19  {
20  return false;
21  }
22  }

Member Data Documentation

◆ m_action

unsigned CP::OutOfValidityHelper::m_action {unsigned (OutOfValidityAction::ABORT)}
private

the action to take

Definition at line 97 of file OutOfValidityHelper.h.

◆ m_decorationName

std::string CP::OutOfValidityHelper::m_decorationName
private

the decoration name we use (if we have one)

Definition at line 106 of file OutOfValidityHelper.h.

◆ m_isInitialized

bool CP::OutOfValidityHelper::m_isInitialized = false
private

whether we have been initialized

This is only used in debug mode to indicate a programming fault. Otherwise it is too easy for users to forget to initialize this object.

Definition at line 114 of file OutOfValidityHelper.h.

◆ m_msg

std::function<MsgStream& ()> asg::AsgMessagingForward::m_msg
privateinherited

the message stream we use

This used to be a simple pointer to the MsgStream itself, but in AthenaMT the actual object used is local to the thread. So instead of pointing to it directly we are now using a function to look it up, which will get the thread-local object.

Definition at line 77 of file AsgMessagingForward.h.

◆ m_read_accessor

std::unique_ptr<ISelectionReadAccessor> CP::OutOfValidityHelper::m_read_accessor
private

Definition at line 102 of file OutOfValidityHelper.h.

◆ m_write_accessor

std::unique_ptr<ISelectionWriteAccessor> CP::OutOfValidityHelper::m_write_accessor
private

the accessor if we apply one

Definition at line 101 of file OutOfValidityHelper.h.


The documentation for this class was generated from the following files:
asg::AsgMessagingForward::m_msg
std::function< MsgStream &()> m_msg
the message stream we use
Definition: AsgMessagingForward.h:77
CP::OutOfValidityHelper::m_write_accessor
std::unique_ptr< ISelectionWriteAccessor > m_write_accessor
the accessor if we apply one
Definition: OutOfValidityHelper.h:101
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
asg::AsgMessagingForward
base class to forward messages to another class
Definition: AsgMessagingForward.h:29
CP::OutOfValidityAction::SILENT
@ SILENT
don't print anything and return success
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
CP::makeSelectionWriteAccessor
StatusCode makeSelectionWriteAccessor(const std::string &name, std::unique_ptr< ISelectionWriteAccessor > &accessor, bool defaultToChar)
Produces a simple ISelectionWriteAccessor accessing the given decoration.
Definition: ISelectionAccessor.cxx:170
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
asg::AsgMessagingForward::msg
MsgStream & msg() const
The standard message stream.
Definition: AsgMessagingForward.cxx:24
CP::OutOfValidityAction::ABORT
@ ABORT
print an error message and return a failure status code (triggering an abort)
CP::CorrectionCode::OutOfValidityRange
@ OutOfValidityRange
Input object is out of validity range.
Definition: CorrectionCode.h:37
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
histSizes.code
code
Definition: histSizes.py:129
CP::OutOfValidityHelper::m_action
unsigned m_action
the action to take
Definition: OutOfValidityHelper.h:97
CP::OutOfValidityAction
OutOfValidityAction
the action to perform on encountering an OutOfValidityRange in OutOfValidityHelper
Definition: OutOfValidityHelper.h:36
ANA_MSG_WARNING
#define ANA_MSG_WARNING(xmsg)
Macro printing warning messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:292
CP::OutOfValidityHelper::m_read_accessor
std::unique_ptr< ISelectionReadAccessor > m_read_accessor
Definition: OutOfValidityHelper.h:102
CP::OutOfValidityHelper::m_decorationName
std::string m_decorationName
the decoration name we use (if we have one)
Definition: OutOfValidityHelper.h:106
CP::OutOfValidityAction::WARNING
@ WARNING
print a warning message and return a success status code.
CP::makeSelectionReadAccessor
StatusCode makeSelectionReadAccessor(const std::string &expr, std::unique_ptr< ISelectionReadAccessor > &accessor, bool defaultToChar)
make the ISelectionReadAccessor for the given name
Definition: ISelectionAccessor.cxx:54
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
CP::OutOfValidityHelper::m_isInitialized
bool m_isInitialized
whether we have been initialized
Definition: OutOfValidityHelper.h:114