ATLAS Offline Software
EndOfEventFilterAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "EndOfEventFilterAlg.h"
7 #include "StoreGate/ReadHandle.h"
8 
9 #include <sstream>
10 
11 namespace {
12  std::string printVector(const std::vector<std::string>& vec) {
13  std::ostringstream ss;
14  ss << "[";
15  bool first{true};
16  for (const std::string& elem : vec) {
17  if (first) {first=false;}
18  else {ss << ", ";}
19  ss << elem;
20  }
21  ss << "]";
22  return ss.str();
23  }
24 }
25 
26 EndOfEventFilterAlg::EndOfEventFilterAlg(const std::string& name, ISvcLocator* pSvcLocator)
27 : AthReentrantAlgorithm(name,pSvcLocator) {}
28 
30  ATH_CHECK(m_hltSeedingSummaryKey.initialize());
32  if (m_chainName.value().empty()) {
33  ATH_MSG_ERROR("The " << m_chainName.name() << " property was not set");
34  return StatusCode::FAILURE;
35  }
37 
38  if (msgLvl(MSG::DEBUG)) {
39  std::ostringstream ss{"This filter will pass when chain "};
40  ss << m_chainId.numeric() << " / " << m_chainId.name() << " is active";
41  if (m_streamFilter.value().empty()) {
42  ss << ". No stream filtering will be applied.";
43  } else {
44  ss << " and the event is accepted to at least one of the following streams: ";
45  ss << printVector(m_streamFilter.value());
46  }
47  ATH_MSG_DEBUG(ss.str());
48  }
49 
50  return StatusCode::SUCCESS;
51 }
52 
53 StatusCode EndOfEventFilterAlg::execute(const EventContext& context) const {
56 
57  if (!m_streamFilter.value().empty()) {
59  ATH_CHECK(streamsSummary.isValid());
60  const auto it = std::find_first_of(streamsSummary->cbegin(), streamsSummary->cend(),
61  m_streamFilter.value().cbegin(), m_streamFilter.value().cend());
62  if (it == streamsSummary->cend()) {
63  setFilterPassed(false, context);
64  ATH_MSG_DEBUG("Setting filter status to failed because none of the listed streams passed: "
65  << printVector(m_streamFilter.value()));
66  return StatusCode::SUCCESS;
67  }
68  ATH_MSG_DEBUG("At least one of the listed streams passed: " << printVector(m_streamFilter.value())
69  << ". The first stream found to pass is " << *it
70  << ". Continue to checking the chain prescale status.");
71  }
72 
74  ATH_CHECK(hltSeedingSummary.isValid());
75  const auto it = std::find_if(hltSeedingSummary->begin(), hltSeedingSummary->end(),
76  [](const Decision* d){return d->name()=="unprescaled";});
77  if (it==hltSeedingSummary->end()) {
78  ATH_MSG_ERROR("Failed to find \"unprescaled\" Decision in " << m_hltSeedingSummaryKey.key());
79  return StatusCode::FAILURE;
80  }
81  const Decision* activeChains = *it;
83  TrigCompositeUtils::decisionIDs(activeChains, activeChainIDs);
84  const bool filterStatus = TrigCompositeUtils::passed(m_chainId, activeChainIDs);
85  ATH_MSG_DEBUG("Setting filter status to " << (filterStatus ? "passed" : "failed") << " because the chain "
86  << m_chainId.name() << " is " << (filterStatus ? "unprescaled" : "prescaled") << " in this event");
87  setFilterPassed(filterStatus, context);
88  return StatusCode::SUCCESS;
89 }
EndOfEventFilterAlg::EndOfEventFilterAlg
EndOfEventFilterAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: EndOfEventFilterAlg.cxx:26
EndOfEventFilterAlg::m_streamsSummaryKey
SG::ReadHandleKey< std::vector< std::string > > m_streamsSummaryKey
Definition: EndOfEventFilterAlg.h:32
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
TrigCompositeUtils::DecisionContainer
xAOD::TrigCompositeContainer DecisionContainer
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigCompositeContainer.h:21
TrigCompositeUtils::passed
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
Definition: TrigCompositeUtilsRoot.cxx:117
TrigCompositeUtils.h
HLT::Identifier::numeric
TrigCompositeUtils::DecisionID numeric() const
numeric ID
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:47
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
hist_file_dump.d
d
Definition: hist_file_dump.py:137
skel.it
it
Definition: skel.GENtoEVGEN.py:423
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
EndOfEventFilterAlg::initialize
virtual StatusCode initialize() override
Definition: EndOfEventFilterAlg.cxx:29
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
EndOfEventFilterAlg::m_chainName
Gaudi::Property< std::string > m_chainName
Definition: EndOfEventFilterAlg.h:35
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EndOfEventFilterAlg.h
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
HLT::Identifier
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TrigCompositeUtils::Decision
xAOD::TrigComposite Decision
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:20
EndOfEventFilterAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: EndOfEventFilterAlg.cxx:53
TrigCompositeUtils::DecisionIDContainer
std::set< DecisionID > DecisionIDContainer
Definition: TrigComposite_v1.h:28
DeMoScan.first
bool first
Definition: DeMoScan.py:534
DEBUG
#define DEBUG
Definition: page_access.h:11
TrigCompositeUtils::decisionIDs
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Definition: TrigCompositeUtilsRoot.cxx:67
HLT::Identifier::name
std::string name() const
reports human redable name if it is enabled or, empty string
Definition: HLTIdentifier.cxx:14
ReadHandle.h
Handle class for reading from StoreGate.
EndOfEventFilterAlg::m_streamFilter
Gaudi::Property< std::vector< std::string > > m_streamFilter
Definition: EndOfEventFilterAlg.h:38
EndOfEventFilterAlg::m_chainId
HLT::Identifier m_chainId
Definition: EndOfEventFilterAlg.h:42
TrigComposite.h
EndOfEventFilterAlg::m_hltSeedingSummaryKey
SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > m_hltSeedingSummaryKey
Definition: EndOfEventFilterAlg.h:29
AthReentrantAlgorithm::setFilterPassed
virtual void setFilterPassed(bool state, const EventContext &ctx) const
Definition: AthReentrantAlgorithm.h:139