ATLAS Offline Software
Loading...
Searching...
No Matches
TestInputMaker.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TestInputMaker.h"
9#include <vector>
10
11namespace HLTTest {
12
13 TestInputMaker::TestInputMaker( const std::string& name,
14 ISvcLocator* pSvcLocator )
15 : InputMakerBase( name, pSvcLocator ) {}
16
17
19
21 ATH_MSG_INFO ("Initializing " << name() << "...");
22
23 // specific:
24 ATH_MSG_DEBUG("Will produce output reco collections: " << m_recoOutput);
25 CHECK( m_recoOutput.initialize() );
26 return StatusCode::SUCCESS;
27 }
28
30 ATH_MSG_INFO( "Finalizing " << name() << "..." );
31
32 return StatusCode::SUCCESS;
33 }
34
35
36 StatusCode TestInputMaker::execute( const EventContext& context ) const {
37 ATH_MSG_DEBUG( "Executing " << name() << "..." );
38
39 // call base class helper method to read input decisions, loop over them create outputs and connect them, returns with outputHandles filled
41 CHECK (decisionInputToOutput(context, outputHandle));
42
43 // output collection, as a view container so it can be given const features
44 auto reco_output = std::make_unique<xAOD::TrigCompositeContainer>();
45 auto aux = std::make_unique<xAOD::TrigCompositeAuxContainer>();
46 reco_output->setStore( aux.get() );
47 std::vector<const FeatureOBJ*> featuresFromDecision; // used to check for duplicate features linked to different inputHandles
48
49 // loop over output decisions, navigate to inputs
50 if( not outputHandle.isValid() ) {
51 ATH_MSG_ERROR( "TestInputMaker: Got no decisions from output "<< outputHandle.key() << " because handle not valid");
52 return StatusCode::FAILURE;
53 }
54 if( outputHandle->size() == 0){ // input filtered out
55 ATH_MSG_ERROR( "TestInputMaker: Got no decisions from output "<< outputHandle.key()<<": handle is valid but container is empty.");
56 return StatusCode::FAILURE;
57 }
58
59 ATH_MSG_DEBUG( "TestInputMaker: Got output "<< outputHandle.key()<<" with " << outputHandle->size() << " elements" );
60 // loop over output decisions in container of outputHandle, follow link to inputDecision
61 int count =0;
62 for (const auto outputDecision : *outputHandle){
63 const std::vector<ElementLink<DecisionContainer>> inputLinks = getLinkToPrevious(outputDecision);
64 ATH_MSG_DEBUG("Element "<< count << " has " << inputLinks.size() <<" previous links");
65 for (const auto& input: inputLinks){
66 ATH_MSG_DEBUG( " -- Got seed link to input "<<input.dataID() <<" and index "<< input.index() );
67 const Decision* inputDecision = *input;
68 const auto roiELInfo = TrigCompositeUtils::findLink<TrigRoiDescriptorCollection>( inputDecision, m_roisLink.value());
69 CHECK( roiELInfo.isValid() );
70
71 // retrieve input feature from input decision (TrigComposite), will in this case be a TrigRoiDescriptor
72 const auto featureLinkInfo = TrigCompositeUtils::findLink<FeatureContainer>( inputDecision, m_linkName.value());
73 CHECK( featureLinkInfo.isValid() );
74
75 // link input reco object to outputDecision
76 const auto featureLink = featureLinkInfo.link;
77 const FeatureOBJ* feature = *featureLink;
78 ATH_MSG_DEBUG(" -- Found feature " <<m_linkName.value() <<":" << **featureLink);
79
80 // merge reco outputs that are linked to the same feature (RoI): this avoids processing the same RoI from TC decisions from different chains
81
82 // avoid adding the same feature multiple times: check if not in container, if not add it
83 if ( find(featuresFromDecision.begin(), featuresFromDecision.end(), feature) == featuresFromDecision.end() ){
84 featuresFromDecision.push_back(feature); // just to keep track of which we have used
85 // create the "reco" output: this would normally be a copy of the reco input or something derived from it, e.g. detector data inside a RoI. A TrigComposite is used here just for a trivial example.
86 auto newFeature = new xAOD::TrigComposite;
87 reco_output->push_back(newFeature);
88 newFeature->setObjectLink(m_linkName.value(), featureLink);
89 ATH_MSG_DEBUG(" -- Added " <<m_linkName.value() << " and " << m_roisLink.value() << " to reco object");
90 }
91 }//loop over previous inputs
92 // For early tests, create TC, link to RoiD, push back onto TCC.
93 // Later will output RoID collection directly via tool.
94 count++;
95 } // loop over decisions
96
97 // Finally, record output
98 ATH_MSG_DEBUG("Produced "<<reco_output->size() <<" reco objects and stored in "<<m_recoOutput);
99 auto reco_outputHandle = SG::makeHandle(m_recoOutput, context);
100 CHECK( reco_outputHandle.record(std::move(reco_output), std::move(aux)) );
101
102 // call base class helper method to print some debug messages summarising the content of the outputHandles.
103 if (msgLvl(MSG::DEBUG)) debugPrintOut(context, outputHandle);
104
105 return StatusCode::SUCCESS;
106 }
107
108
109} //> 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.
bool msgLvl(const MSG::Level lvl) const
TrigRoiDescriptor FeatureOBJ
StringProperty m_linkName
virtual StatusCode finalize() override
virtual StatusCode execute(const EventContext &) const override
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_recoOutput
virtual StatusCode initialize() override
StatusCode decisionInputToOutput(const EventContext &context, SG::WriteHandle< TrigCompositeUtils::DecisionContainer > &outputHandle) const
does the standard handling of input decisions: read from handles with all the checks,...
StringProperty m_roisLink
const SG::WriteHandleKey< TrigCompositeUtils::DecisionContainer > & decisionOutputs() const
methods for derived classes to access handles of the base class input and output decisions; other rea...
void debugPrintOut(const EventContext &context, SG::WriteHandle< TrigCompositeUtils::DecisionContainer > &outputHandle) const
provides debug printout of the output of the algorithm
InputMakerBase(const std::string &name, ISvcLocator *pSvcLocator)
constructor, to be called by sub-class constructors
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
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 ...
const std::vector< ElementLink< DecisionContainer > > getLinkToPrevious(const Decision *d)
returns links to previous decision object 'seed'
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
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...
TrigComposite_v1 TrigComposite
Declare the latest version of the class.