ATLAS Offline Software
Public Member Functions | Private Attributes | Friends | List of all members
FilterReporterParams Class Referencefinal

a handle for applying algorithm filter decisions More...

#include <FilterReporterParams.h>

Inheritance diagram for FilterReporterParams:
Collaboration diagram for FilterReporterParams:

Public Member Functions

template<typename T >
 FilterReporterParams (T *owner, std::string val_filterKey, std::string val_filterDescription)
 standard constructor More...
 
StatusCode initialize (bool enabled=true)
 do anything we need to do in initialize More...
 
std::string summary ()
 report the status of filtering More...
 
const std::string & key () const
 retrieve the key name More...
 
const SG::ReadHandleKey< xAOD::EventInfo > & eventInfoKey () const
 retrieve the event info read handle key More...
 
ServiceHandle< ICutFlowSvc > & cutFlowSvc ()
 retrieve the CutFlowSvc handle reference 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

std::function< void(bool, const EventContext *ctx)> m_setFilterPassed
 the function to call setFilterPassed() on the algorithm More...
 
bool m_isInitialized {false}
 whether the handle was initialized More...
 
bool m_isEnabled {false}
 whether the handle was initialized More...
 
std::atomic< unsigned > m_passed {0}
 the count of passed and total events More...
 
std::atomic< unsigned > m_total {0}
 
std::string m_filterKey
 output key of the filter More...
 
std::string m_filterDescription
 description what this filter does More...
 
SG::ReadHandleKey< xAOD::EventInfom_eventInfoKey
 event info read handle key More...
 
CutIdentifier m_cutID {}
 the CutIdentifier for this filter algorithm More...
 
ServiceHandle< ICutFlowSvcm_cutFlowSvc
 the handle to the service holding tables of cut-flows for filtering algs. More...
 
std::function< MsgStream &()> m_msg
 the message stream we use More...
 

Friends

class FilterReporter
 

Detailed Description

a handle for applying algorithm filter decisions

This is meant to replace the old/traditional mechanism for recording filter decisions by algorithms, i.e. calling setFilterPassed() on the algorithm base class. This allows to selectively add filter capabilties to algorithms without having to derive from a dedicated algorithm class like AthFilterAlgorithm.

One of the particular reasons to handle filter decisions through a handle is that it makes it fairly easy to add instrumentation (e.g. reporting to the cut flow service), without having to make changes to the base class or indeed without having any extra code in the base class at all. Also it makes sure that only the actual filter algorithms expose properties related to reporting filter decisions (though that would also be true when using a base class).

This should in principle work with any algorithm (or we should be able to make it work with any algorithm). While there isn't any intrinsic reason one couldn't have more than one filter handle per algorithm, that is currently (02 Mar 20) not supported, but could be added on request.

Currently (02 Mar 20) none of the member functions is marked const, which is deliberate to prevent them being called from a reentrant algorithm. I suspect if we ever want to use this in AthenaMT, we will add a second set of member functions that is marked const and will take an event context as an argument.

Definition at line 57 of file FilterReporterParams.h.

Constructor & Destructor Documentation

◆ FilterReporterParams()

template<typename T >
FilterReporterParams::FilterReporterParams ( T *  owner,
std::string  val_filterKey,
std::string  val_filterDescription 
)
explicit

standard constructor

Guarantee
strong
Failures
out of memory I

Definition at line 171 of file FilterReporterParams.h.

175  : AsgMessagingForward (owner)
176  , m_setFilterPassed ([owner] (bool val_setFilterPassed, const EventContext *ctx)
177  {
178 #ifndef XAOD_STANDALONE
179  owner->execState (*ctx).setFilterPassed (val_setFilterPassed);
180 #else
181  (void)ctx;
182  owner->setFilterPassed (val_setFilterPassed);
183 #endif
184  })
185  , m_filterKey (std::move (val_filterKey))
186  , m_filterDescription (std::move (val_filterDescription))
187  , m_eventInfoKey (owner, "EventInfoKey", "EventInfo", "event info used for cutflow")
188 #ifndef XAOD_STANDALONE
189  , m_cutFlowSvc ("CutFlowSvc/CutFlowSvc", owner->name())
190 #endif
191 {
192  owner->declareProperty("FilterKey", m_filterKey,
193  "output filter key");
194  owner->declareProperty("FilterDescription", m_filterDescription,
195  "describe to the CutFlowSvc what this filter does");
196 
197 #ifndef XAOD_STANDALONE
198  owner->declareProperty("CutFlowSvc", m_cutFlowSvc,
199  "handle to the ICutFlowSvc instance this filtering algorithm"
200  " will use for building the flow of cuts.");
201 #endif
202 }

Member Function Documentation

◆ cutFlowSvc()

ServiceHandle< ICutFlowSvc > & FilterReporterParams::cutFlowSvc ( )
inline

retrieve the CutFlowSvc handle reference

Definition at line 214 of file FilterReporterParams.h.

215 {
216  return m_cutFlowSvc;
217 }

◆ eventInfoKey()

const SG::ReadHandleKey< xAOD::EventInfo > & FilterReporterParams::eventInfoKey ( ) const
inline

retrieve the event info read handle key

Definition at line 206 of file FilterReporterParams.h.

207 {
208  return m_eventInfoKey;
209 }

◆ initialize()

StatusCode FilterReporterParams::initialize ( bool  enabled = true)

do anything we need to do in initialize

Guarantee
strong
Failures
configuration/initialization errors
Author
Nils Krumnack
Tadej Novak

Definition at line 23 of file FilterReporterParams.cxx.

25 {
26  if (m_isInitialized)
27  {
28  return StatusCode::SUCCESS;
29  }
30 
31  m_isEnabled = enabled;
32 
34 
35 #ifndef XAOD_STANDALONE
36  if (m_isEnabled && !m_cutFlowSvc.empty())
37  {
38  ANA_CHECK (m_cutFlowSvc.retrieve());
39 
40  m_cutID = m_cutFlowSvc->registerFilter (m_filterKey, m_filterDescription, false);
41  if (m_cutID == 0)
42  {
43  ANA_MSG_ERROR ("problem registering myself with the CutFlowSvc");
44  return StatusCode::FAILURE;
45  }
46  }
47 #endif
48 
49  // currently not doing anything here, but presumably if we want to
50  // add instrumentation, we may/will need to do some initialization
51  // work here.
52 
53  m_isInitialized = true;
54  return StatusCode::SUCCESS;
55 }

◆ key()

const std::string& FilterReporterParams::key ( ) const
inline

retrieve the key name

Definition at line 92 of file FilterReporterParams.h.

92 { return m_filterKey; }

◆ 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  }

◆ summary()

std::string FilterReporterParams::summary ( )

report the status of filtering

Returns
a summary string

Definition at line 59 of file FilterReporterParams.cxx.

61 {
62  if (!m_isInitialized)
63  {
64  return std::string();
65  }
66 
67  std::stringstream stream;
68  stream << "accepted " << m_passed << " out of " << m_total << " events for filter "
69  << m_filterKey << " (" << m_filterDescription << ")";
70 
71  return stream.str();
72 }

Friends And Related Function Documentation

◆ FilterReporter

friend class FilterReporter
friend

Definition at line 115 of file FilterReporterParams.h.

Member Data Documentation

◆ m_cutFlowSvc

ServiceHandle<ICutFlowSvc> FilterReporterParams::m_cutFlowSvc
private

the handle to the service holding tables of cut-flows for filtering algs.

Definition at line 160 of file FilterReporterParams.h.

◆ m_cutID

CutIdentifier FilterReporterParams::m_cutID {}
private

the CutIdentifier for this filter algorithm

Definition at line 155 of file FilterReporterParams.h.

◆ m_eventInfoKey

SG::ReadHandleKey<xAOD::EventInfo> FilterReporterParams::m_eventInfoKey
private

event info read handle key

Definition at line 149 of file FilterReporterParams.h.

◆ m_filterDescription

std::string FilterReporterParams::m_filterDescription
private

description what this filter does

Definition at line 145 of file FilterReporterParams.h.

◆ m_filterKey

std::string FilterReporterParams::m_filterKey
private

output key of the filter

Definition at line 141 of file FilterReporterParams.h.

◆ m_isEnabled

bool FilterReporterParams::m_isEnabled {false}
private

whether the handle was initialized

Definition at line 130 of file FilterReporterParams.h.

◆ m_isInitialized

bool FilterReporterParams::m_isInitialized {false}
private

whether the handle was initialized

Definition at line 126 of file FilterReporterParams.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_passed

std::atomic<unsigned> FilterReporterParams::m_passed {0}
mutableprivate

the count of passed and total events

While we currently don't run in multi-threaded mode, this is atomic in case we ever use it with reentrant algorithms.

Definition at line 137 of file FilterReporterParams.h.

◆ m_setFilterPassed

std::function<void(bool, const EventContext *ctx)> FilterReporterParams::m_setFilterPassed
private

the function to call setFilterPassed() on the algorithm

This is using a std::function object, so as to avoid tying this to a particular algorithm class.

Definition at line 122 of file FilterReporterParams.h.

◆ m_total

std::atomic<unsigned> FilterReporterParams::m_total {0}
private

Definition at line 137 of file FilterReporterParams.h.


The documentation for this class was generated from the following files:
FilterReporterParams::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
event info read handle key
Definition: FilterReporterParams.h:149
asg::AsgMessagingForward::m_msg
std::function< MsgStream &()> m_msg
the message stream we use
Definition: AsgMessagingForward.h:77
FilterReporterParams::m_cutID
CutIdentifier m_cutID
the CutIdentifier for this filter algorithm
Definition: FilterReporterParams.h:155
FilterReporterParams::m_isInitialized
bool m_isInitialized
whether the handle was initialized
Definition: FilterReporterParams.h:126
FilterReporterParams::m_filterDescription
std::string m_filterDescription
description what this filter does
Definition: FilterReporterParams.h:145
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
FilterReporterParams::m_isEnabled
bool m_isEnabled
whether the handle was initialized
Definition: FilterReporterParams.h:130
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
asg::AsgMessagingForward::msg
MsgStream & msg() const
The standard message stream.
Definition: AsgMessagingForward.cxx:24
FilterReporterParams::m_setFilterPassed
std::function< void(bool, const EventContext *ctx)> m_setFilterPassed
the function to call setFilterPassed() on the algorithm
Definition: FilterReporterParams.h:122
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
FilterReporterParams::m_filterKey
std::string m_filterKey
output key of the filter
Definition: FilterReporterParams.h:141
asg::AsgMessagingForward::AsgMessagingForward
AsgMessagingForward(T *owner)
forwarding constructor
Definition: AsgMessagingForward.h:83
FilterReporterParams::m_cutFlowSvc
ServiceHandle< ICutFlowSvc > m_cutFlowSvc
the handle to the service holding tables of cut-flows for filtering algs.
Definition: FilterReporterParams.h:160
FilterReporterParams::m_total
std::atomic< unsigned > m_total
Definition: FilterReporterParams.h:137
FilterReporterParams::m_passed
std::atomic< unsigned > m_passed
the count of passed and total events
Definition: FilterReporterParams.h:137