ATLAS Offline Software
TrigHIEventShapeHypoAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "Gaudi/Property.h"
10 
12  ISvcLocator* pSvcLocator) :
13  ::HypoBase(name, pSvcLocator) {}
14 
15 
17  ATH_CHECK(m_hypoTools.retrieve());
18  ATH_CHECK(m_esKey.initialize());
19  return StatusCode::SUCCESS;
20 }
21 
22 StatusCode TrigHIEventShapeHypoAlg::execute(const EventContext& context) const {
23  ATH_MSG_DEBUG ("Executing " << name() << "...");
24 
25  // Retrieve the HI event shape container
26  auto esHandle = SG::makeHandle(m_esKey, context);
27  ATH_CHECK(esHandle.isValid());
28  ATH_MSG_DEBUG("Retrieving HI event shape container using key: " << esHandle.key());
29  const xAOD::HIEventShapeContainer* eventShapeContainer = esHandle.get();
30 
31  // Retrieve the previous Decisions made before running this hypo
32  auto prevDecisionsHandle = SG::makeHandle(decisionInput(), context);
33  ATH_CHECK(prevDecisionsHandle.isValid());
34  ATH_MSG_DEBUG("Running with " << prevDecisionsHandle->size() << " implicit ReadHandles for previous decisions");
35  const TrigCompositeUtils::DecisionContainer* prevDecisions = prevDecisionsHandle.get();
36 
37  // Make a new Decisions container which will contain the new Decision object created by this hypo
39  TrigCompositeUtils::DecisionContainer* newDecisions = decisionOutputHandle.ptr();
40 
41  // Make trigger decisions and save to "newDecisions"
42  ATH_CHECK(decide(eventShapeContainer, newDecisions, prevDecisions, context));
43 
44  // Common debug printing
45  ATH_CHECK(hypoBaseOutputProcessing(decisionOutputHandle));
46 
47  return StatusCode::SUCCESS;
48 }
49 
50 
53  const TrigCompositeUtils::DecisionContainer* oldDecisions,
54  const EventContext& context) const {
55 
56  ATH_MSG_DEBUG("Executing decide() of " << name());
57  if (oldDecisions->size() != 1) {
58  ATH_MSG_ERROR("TrigHIEventShapeHypoAlg requires there to be exactly one previous Decision object, but found " << oldDecisions->size());
59  return StatusCode::FAILURE;
60  }
61  const TrigCompositeUtils::Decision* previousDecision = oldDecisions->at(0);
62 
63  if (eventShapeContainer->size()==0) {
64  ATH_MSG_ERROR("There are no HIEventShape objects in the container");
65  return StatusCode::FAILURE;
66  }
67 
68  // Create output Decision object, link it to prevDecision and its "feature"
69  auto newDecision = TrigCompositeUtils::newDecisionIn(newDecisions, previousDecision, TrigCompositeUtils::hypoAlgNodeName(), context);
70  ElementLink<xAOD::HIEventShapeContainer> esElementLink = ElementLink<xAOD::HIEventShapeContainer>(*eventShapeContainer, /*index*/ 0);
71  newDecision->setObjectLink<xAOD::HIEventShapeContainer>(TrigCompositeUtils::featureString(), esElementLink);
72 
73  // Get set of active chains
74  const TrigCompositeUtils::DecisionIDContainer previousDecisionIDs{
75  TrigCompositeUtils::decisionIDs(previousDecision).begin(),
76  TrigCompositeUtils::decisionIDs(previousDecision).end()
77  };
78 
79  for (const auto& tool: m_hypoTools) {
80  ATH_MSG_DEBUG("About to decide for " << tool->name());
81 
82  auto decisionId = tool->getId();
83  if (TrigCompositeUtils::passed(decisionId.numeric(), previousDecisionIDs)) {
84  ATH_MSG_DEBUG("Passed previous trigger step");
85 
86  bool pass;
87  ATH_CHECK(tool->decide(eventShapeContainer, pass));
88 
89  if (pass) {
90  ATH_MSG_DEBUG("Passed " << tool->name());
91  TrigCompositeUtils::addDecisionID(decisionId, newDecision);
92  }
93  else {
94  ATH_MSG_DEBUG("Didn't pass " << tool->name());
95  }
96  }
97  else {
98  ATH_MSG_DEBUG("Didn't pass previous trigger step");
99  }
100  }
101 
102  return StatusCode::SUCCESS;
103 }
104 
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
TrigHIEventShapeHypoAlg::m_esKey
SG::ReadHandleKey< xAOD::HIEventShapeContainer > m_esKey
Definition: TrigHIEventShapeHypoAlg.h:38
TrigCompositeUtils.h
TrigCompositeUtils::newDecisionIn
Decision * newDecisionIn(DecisionContainer *dc, const std::string &name)
Helper method to create a Decision object, place it in the container and return a pointer to it.
Definition: TrigCompositeUtilsRoot.cxx:46
TrigHIEventShapeHypoAlg::m_hypoTools
ToolHandleArray< ITrigHIEventShapeHypoTool > m_hypoTools
Definition: TrigHIEventShapeHypoAlg.h:36
TrigCompositeUtils::hypoAlgNodeName
const std::string & hypoAlgNodeName()
Definition: TrigCompositeUtilsRoot.cxx:906
TrigCompositeUtils::addDecisionID
void addDecisionID(DecisionID id, Decision *d)
Appends the decision (given as ID) to the decision object.
Definition: TrigCompositeUtilsRoot.cxx:61
DataVector::get
const T * get(size_type n) const
Access an element, as an rvalue.
HypoBase::decisionInput
const SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > & decisionInput() const
methods for derived classes to access handles of the base class input other read/write handles may be...
Definition: HypoBase.cxx:16
TrigCompositeUtils::createAndStore
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
Definition: TrigCompositeUtilsRoot.cxx:30
TrigHIEventShapeHypoAlg::initialize
virtual StatusCode initialize() override
Definition: TrigHIEventShapeHypoAlg.cxx:16
TrigHIEventShapeHypoAlg::TrigHIEventShapeHypoAlg
TrigHIEventShapeHypoAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigHIEventShapeHypoAlg.cxx:11
HypoBase::decisionOutput
const SG::WriteHandleKey< TrigCompositeUtils::DecisionContainer > & decisionOutput() const
methods for derived classes to access handles of the base class output other read/write handles may b...
Definition: HypoBase.cxx:20
TrigHIEventShapeHypoAlg.h
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HypoBase::hypoBaseOutputProcessing
StatusCode hypoBaseOutputProcessing(SG::WriteHandle< TrigCompositeUtils::DecisionContainer > &outputHandle, MSG::Level lvl=MSG::DEBUG) const
Base class function to be called once slice specific code has finished. Handles debug printing and va...
Definition: HypoBase.cxx:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:886
TrigHIEventShapeHypoAlg::execute
virtual StatusCode execute(const EventContext &context) const override
Definition: TrigHIEventShapeHypoAlg.cxx:22
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
HypoBase
Hypothesis algorithms take the output of reco algorithms and the decision from the preceeding InputMa...
Definition: HypoBase.h:13
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
TrigCompositeUtils::DecisionIDContainer
std::set< DecisionID > DecisionIDContainer
Definition: TrigComposite_v1.h:28
HLTIdentifier.h
TrigCompositeUtils::decisionIDs
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Definition: TrigCompositeUtilsRoot.cxx:67
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrigHIEventShapeHypoAlg::decide
StatusCode decide(const xAOD::HIEventShapeContainer *eventShapeContainer, TrigCompositeUtils::DecisionContainer *newDecisions, const TrigCompositeUtils::DecisionContainer *oldDecisions, const EventContext &context) const
Definition: TrigHIEventShapeHypoAlg.cxx:51