ATLAS Offline Software
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 
11 namespace 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
InputMakerBase::decisionInputToOutput
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,...
Definition: InputMakerBase.cxx:43
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
xAOD::TrigComposite
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:16
InputMakerBase
Input Makers are used at the start of a sequence: retrieve filtered collection via the input decision...
Definition: InputMakerBase.h:20
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
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
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
HLTTest::TestInputMaker::TestInputMaker
TestInputMaker()
TrigCompositeUtils.h
HLTTest::TestInputMaker::initialize
virtual StatusCode initialize() override
Definition: TestInputMaker.cxx:20
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HLTTest::TestInputMaker::finalize
virtual StatusCode finalize() override
Definition: TestInputMaker.cxx:29
xAOD::TrigComposite_v1::setObjectLink
bool setObjectLink(const std::string &name, const ElementLink< CONTAINER > &link)
Set the link to an object.
TrigCompositeUtils::getLinkToPrevious
const std::vector< ElementLink< DecisionContainer > > getLinkToPrevious(const Decision *d)
returns links to previous decision object 'seed'
Definition: TrigCompositeUtilsRoot.cxx:156
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
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
TestInputMaker.h
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
TrigCompositeAuxContainer.h
InputMakerBase::m_roisLink
StringProperty m_roisLink
Definition: InputMakerBase.h:50
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
HLTTest::TestInputMaker::~TestInputMaker
virtual ~TestInputMaker()
Definition: TestInputMaker.cxx:18
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
HLTTest::TestInputMaker::execute
virtual StatusCode execute(const EventContext &) const override
Definition: TestInputMaker.cxx:36
HLTTest::TestInputMaker::m_recoOutput
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_recoOutput
Definition: TestInputMaker.h:43
InputMakerBase::decisionOutputs
const SG::WriteHandleKey< TrigCompositeUtils::DecisionContainer > & decisionOutputs() const
methods for derived classes to access handles of the base class input and output decisions; other rea...
Definition: InputMakerBase.cxx:21
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
HLTTest::TestInputMaker::m_linkName
StringProperty m_linkName
Definition: TestInputMaker.h:45
InputMakerBase::debugPrintOut
void debugPrintOut(const EventContext &context, SG::WriteHandle< TrigCompositeUtils::DecisionContainer > &outputHandle) const
provides debug printout of the output of the algorithm
Definition: InputMakerBase.cxx:200
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
DEBUG
#define DEBUG
Definition: page_access.h:11
HLTTest
Definition: ITestHypoTool.cxx:9
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrigRoiDescriptorCollection.h