ATLAS Offline Software
Loading...
Searching...
No Matches
TestHypoAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TestHypoAlg.h"
6
7namespace HLTTest {
8
9 TestHypoAlg::TestHypoAlg( const std::string& name, ISvcLocator* pSvcLocator )
10 : ::HypoBase( name, pSvcLocator ) {}
11
13
15 ATH_MSG_INFO ("Initializing " << name() << "...");
16 ATH_MSG_DEBUG("Link name is "<<m_linkName.value());
17 if ( not m_recoInput.key().empty() )
18 CHECK( m_recoInput.initialize() );
19 CHECK( m_tools.retrieve() );
20 return StatusCode::SUCCESS;
21 }
22
23 StatusCode TestHypoAlg::finalize() {
24 ATH_MSG_INFO( "Finalizing " << name() << "..." );
25 return StatusCode::SUCCESS;
26 }
27
28
29 StatusCode TestHypoAlg::execute( const EventContext& context ) const {
30 // new output decisions
32 auto decisions = outputHandle.ptr();
33
34 ATH_MSG_DEBUG( "Executing " << name() << "..." );
35 if ( m_recoInput.key().empty() ) {
36 ATH_MSG_DEBUG( "No input configured, output decisions will be empty" );
37 return StatusCode::SUCCESS;
38 }
39
40 auto previousDecisionsHandle = SG::makeHandle( decisionInput(), context );
41 if( not previousDecisionsHandle.isValid() ) {//implicit
42 ATH_MSG_DEBUG( "No implicit RH for previous decisions "<< decisionInput().key()<<": is this expected?" );
43 return StatusCode::SUCCESS;
44 }
45
46 ATH_MSG_DEBUG( "Running with "<< previousDecisionsHandle->size() <<" decisions from the input implicit ReadHandle");
47
48 auto recoInput = SG::makeHandle(m_recoInput, context);
49 ATH_MSG_DEBUG( " and with "<< recoInput->size() <<" reco inputs");
50
51
52 // find features:
53 std::vector<const FeatureOBJ*> featureFromDecision;
54 for ( const auto previousDecision: *previousDecisionsHandle ) {
55 const auto linkInfo = TrigCompositeUtils::findLink<FeatureContainer>(previousDecision, m_linkName.value());
56 const auto featureLink = linkInfo.link;
57 CHECK( featureLink.isValid() );
58 const FeatureOBJ* feature = *featureLink;
59 featureFromDecision.push_back( feature);
60 }
61 ATH_MSG_DEBUG("Found "<<featureFromDecision.size()<<" features "<<m_linkName.value() <<" mapped from input decisions");
62
63 //map reco object and decision: find in reco obejct the initial RoI and map it to the correct decision
64 size_t reco_counter = 0;
65 for (const auto recoobj: *recoInput){
66 const auto roiInfo = TrigCompositeUtils::findLink<TrigRoiDescriptorCollection>( recoobj, "initialRoI" );
67 const auto roiEL = roiInfo.link;
68 CHECK( roiEL.isValid() );
69
70 const auto featureInfo = TrigCompositeUtils::findLink<FeatureContainer>( recoobj, m_linkName.value() );
71 const auto featurelink = featureInfo.link;
72 CHECK( featurelink.isValid() );
73 if ( not featurelink.isValid() ) {
74 ATH_MSG_ERROR( " Can not find reference to " + m_linkName.value() + " from the decision" );
75 return StatusCode::FAILURE;
76 }
77
78 ATH_MSG_DEBUG(" Found link from the reco object to feature "<<m_linkName.value() );
79 const FeatureOBJ* feature = *featurelink;
80 // find the same roi in the previous decisions
81 bool foundFeatureInDecision=false;
82 size_t pos=distance(featureFromDecision.begin(), find(featureFromDecision.begin(), featureFromDecision.end(), feature));
83 if (pos < featureFromDecision.size()){
84 foundFeatureInDecision=true;
85 }
86
87 if (foundFeatureInDecision){
88 ATH_MSG_DEBUG(" Found link from the reco object to the previous decision at position "<<pos);
89 auto d = newDecisionIn(decisions);
90 d->setObjectLink( "feature", ElementLink<xAOD::TrigCompositeContainer>(m_recoInput.key(), reco_counter) );// feature used by the Tool
91 d->setObjectLink( m_linkName.value(), featurelink );
92 linkToPrevious( d, decisionInput().key(), pos );
93 }
94 else{
95 ATH_MSG_DEBUG( " Can not find reference to this feature " + m_linkName.value() + " from reco object " << reco_counter <<" in any previous decision" );
96 }
97 reco_counter++;
98 }
99
100 if (decisions->size()>0){
101 for ( auto tool: m_tools ) {
102 CHECK( tool->decide( decisions ) );
103 }
104 }
105
106 ATH_MSG_DEBUG( "Exiting with "<< outputHandle->size() <<" decisions");
107
108 //debug
109 for (auto outh: *outputHandle){
111 TrigCompositeUtils::decisionIDs( outh, objDecisions );
112
113 ATH_MSG_DEBUG("Number of positive decisions for this output: " << objDecisions.size() );
114
115 for ( TrigCompositeUtils::DecisionID id : objDecisions ) {
116 ATH_MSG_DEBUG( " --- found decision " << HLT::Identifier( id ) );
117 }
118 }
119
120 return StatusCode::SUCCESS;
121 }
122
123} //> end namespace HLTTest
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_recoInput
Definition TestHypoAlg.h:44
TrigRoiDescriptor FeatureOBJ
Definition TestHypoAlg.h:35
ToolHandleArray< ITestHypoTool > m_tools
Definition TestHypoAlg.h:43
virtual StatusCode finalize() override
virtual StatusCode execute(const EventContext &context) const override
StringProperty m_linkName
Definition TestHypoAlg.h:45
virtual StatusCode initialize() override
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:18
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:22
HypoBase(const std::string &name, ISvcLocator *pSvcLocator)
constructor, to be called by sub-class constructors
Definition HypoBase.cxx:12
pointer_type ptr()
Dereference the pointer.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
unsigned int DecisionID
const Decision * find(const Decision *start, const std::function< bool(const Decision *)> &filter)
traverses Decision object links for another Decision object fulfilling the prerequisite specified by ...
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.
std::set< DecisionID > DecisionIDContainer
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
LinkInfo< T > findLink(const Decision *start, const std::string &linkName, const bool suppressMultipleLinksWarning=false)
Perform a recursive search for ElementLinks of type T and name 'linkName', starting from Decision obj...
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.