ATLAS Offline Software
Loading...
Searching...
No Matches
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
StatusCode initialize (bool enabled=true)
 do anything we need to do in initialize
std::string summary ()
 report the status of filtering
const std::string & key () const
 retrieve the key name
const std::string & description () const
 retrieve the key description
const SG::ReadHandleKey< xAOD::EventInfo > & eventInfoKey () const
 retrieve the event info read handle key
ServiceHandle< ICutFlowSvc > & cutFlowSvc ()
 retrieve the CutFlowSvc handle reference
bool msgLvl (const MSG::Level lvl) const
 Test the output level of the object.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.

Private Attributes

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

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 176 of file FilterReporterParams.h.

180 : AsgMessagingForward (owner)
181 , m_setFilterPassed ([owner] (bool val_setFilterPassed, const EventContext *ctx)
182 {
183#ifndef XAOD_STANDALONE
184 owner->execState (*ctx).setFilterPassed (val_setFilterPassed);
185#else
186 (void)ctx;
187 owner->setFilterPassed (val_setFilterPassed);
188#endif
189 })
190 , m_filterKey (std::move (val_filterKey))
191 , m_filterDescription (std::move (val_filterDescription))
192 , m_eventInfoKey (owner, "EventInfoKey", "EventInfo", "event info used for cutflow")
193#ifndef XAOD_STANDALONE
194 , m_cutFlowSvc ("CutFlowSvc/CutFlowSvc", owner->name())
195#endif
196{
197 owner->declareProperty("FilterKey", m_filterKey,
198 "output filter key");
199 owner->declareProperty("FilterDescription", m_filterDescription,
200 "describe to the CutFlowSvc what this filter does");
201
202#ifndef XAOD_STANDALONE
203 owner->declareProperty("CutFlowSvc", m_cutFlowSvc,
204 "handle to the ICutFlowSvc instance this filtering algorithm"
205 " will use for building the flow of cuts.");
206#endif
207}
std::string m_filterDescription
description what this filter does
std::function< void(bool, const EventContext *ctx)> m_setFilterPassed
the function to call setFilterPassed() on the algorithm
ServiceHandle< ICutFlowSvc > m_cutFlowSvc
the handle to the service holding tables of cut-flows for filtering algs.
std::string m_filterKey
output key of the filter
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
event info read handle key
AsgMessagingForward(T *owner)
forwarding constructor

Member Function Documentation

◆ cutFlowSvc()

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

retrieve the CutFlowSvc handle reference

Definition at line 219 of file FilterReporterParams.h.

220{
221 return m_cutFlowSvc;
222}

◆ description()

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

retrieve the key description

Definition at line 97 of file FilterReporterParams.h.

97{ return m_filterDescription; }

◆ eventInfoKey()

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

retrieve the event info read handle key

Definition at line 211 of file FilterReporterParams.h.

212{
213 return m_eventInfoKey;
214}

◆ 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{
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}
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
bool m_isInitialized
whether the handle was initialized
bool m_isEnabled
whether the handle was initialized
CutIdentifier m_cutID
the CutIdentifier for this filter algorithm

◆ 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 }
std::function< MsgStream &()> m_msg
the message stream we use

◆ 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 }
MsgStream & msg() const
The standard message stream.

◆ 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}
std::atomic< unsigned > m_passed
the count of passed and total events
std::atomic< unsigned > m_total

◆ FilterReporter

friend class FilterReporter
friend

Definition at line 120 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 165 of file FilterReporterParams.h.

◆ m_cutID

CutIdentifier FilterReporterParams::m_cutID {}
private

the CutIdentifier for this filter algorithm

Definition at line 160 of file FilterReporterParams.h.

160{};

◆ m_eventInfoKey

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

event info read handle key

Definition at line 154 of file FilterReporterParams.h.

◆ m_filterDescription

std::string FilterReporterParams::m_filterDescription
private

description what this filter does

Definition at line 150 of file FilterReporterParams.h.

◆ m_filterKey

std::string FilterReporterParams::m_filterKey
private

output key of the filter

Definition at line 146 of file FilterReporterParams.h.

◆ m_isEnabled

bool FilterReporterParams::m_isEnabled {false}
private

whether the handle was initialized

Definition at line 135 of file FilterReporterParams.h.

135{false};

◆ m_isInitialized

bool FilterReporterParams::m_isInitialized {false}
private

whether the handle was initialized

Definition at line 131 of file FilterReporterParams.h.

131{false};

◆ 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 142 of file FilterReporterParams.h.

142{0}, m_total {0};

◆ 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 127 of file FilterReporterParams.h.

◆ m_total

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

Definition at line 142 of file FilterReporterParams.h.

142{0}, m_total {0};

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