ATLAS Offline Software
InputMakerForRoI.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "InputMakerForRoI.h"
9 #include <vector>
10 
15 
16 InputMakerForRoI:: InputMakerForRoI( const std::string& name, ISvcLocator* pSvcLocator )
17  : InputMakerBase( name, pSvcLocator ) {}
18 
19 
21  ATH_MSG_DEBUG("Will produce output RoI collections: " << m_RoIs);
23  if (not m_roiTool.empty()) ATH_CHECK( m_roiTool.retrieve() );
24  if (m_roiTool.empty() and not m_isEmptyStep) {
25  ATH_MSG_ERROR(name() << " was not supplied an ROI tool.");
26  return StatusCode::FAILURE;
27  }
28  return StatusCode::SUCCESS;
29 }
30 
31 StatusCode InputMakerForRoI::execute( const EventContext& context ) const {
32  ATH_MSG_DEBUG( "Executing " << name() << "..." );
33 
34  // create the output decisions from the input collections
36  ATH_CHECK(outputHandle.isValid());
37  ATH_CHECK(decisionInputToOutput(context, outputHandle));
38 
39 
40  if( outputHandle->size() == 0) {
41  ATH_MSG_DEBUG( "Have no decisions in output handle "<< outputHandle.key() << ". Handle is valid but container is empty. "
42  << "This can happen if a ROI-based HLT chain leg was activated in a chain whose L1 item which does not explicitly require the ROI.");
43  } else {
44  ATH_MSG_DEBUG( "Have output " << outputHandle.key() << " with " << outputHandle->size() << " elements" );
45  }
46 
47  // Find and link to the output Decision objects the ROIs to run over
48  if (not m_roiTool.empty()) ATH_CHECK( m_roiTool->attachROILinks(*outputHandle, context) );
49 
50  if (m_RoIs.empty()) {
51  ATH_MSG_DEBUG("No concrete output ROI collection required from this InputMaker.");
52  return StatusCode::SUCCESS;
53  }
54 
55  // Prepare Outputs
56  std::unique_ptr<TrigRoiDescriptorCollection> outputRoIColl = std::make_unique<TrigRoiDescriptorCollection>();
57 
58  std::vector <ElementLink<TrigRoiDescriptorCollection> > RoIsFromDecision; // used to check for duplicate RoIs
59 
60  // loop over output decisions in container of outputHandle, collect RoIs to process
61  for (const Decision* outputDecision : *outputHandle) {
62 
63  if (!outputDecision->hasObjectLink(roiString(), ClassID_traits<TrigRoiDescriptorCollection>::ID())) {
64  ATH_MSG_ERROR("No '" << roiString() << "'link was attached by the ROITool. Decision object dump:" << *outputDecision);
65  return StatusCode::FAILURE;
66  }
67  const ElementLink<TrigRoiDescriptorCollection> roiEL = outputDecision->objectLink<TrigRoiDescriptorCollection>(roiString());
68  ATH_CHECK(roiEL.isValid());
69 
70  // Avoid adding the same ROI multiple times: check if not in container, if not add it
71  if ( find(RoIsFromDecision.begin(), RoIsFromDecision.end(), roiEL) == RoIsFromDecision.end() ) {
72  RoIsFromDecision.push_back(roiEL); // just to keep track of which we have used
73  const TrigRoiDescriptor* roi = *roiEL;
74  ATH_MSG_DEBUG("Adding RoI to be processed:" <<*roi<<" FS="<<roi->isFullscan());
75 
76  TrigRoiDescriptor* newroi = new TrigRoiDescriptor(*roi); //use copy constructor
77  outputRoIColl->push_back(newroi);
78  }
79 
80  } // loop over decisions
81 
82  // Finally, record output
83  ATH_MSG_DEBUG("Produced "<<outputRoIColl->size() <<" output RoIs");
84  auto roi_outputHandle = SG::makeHandle(m_RoIs, context);
85  ATH_CHECK( roi_outputHandle.record(std::move(outputRoIColl)) );
86 
87 
88  return StatusCode::SUCCESS;
89 }
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
InputMakerForRoI::execute
virtual StatusCode execute(const EventContext &) const override
Definition: InputMakerForRoI.cxx:31
InputMakerForRoI::InputMakerForRoI
InputMakerForRoI(const std::string &name, ISvcLocator *pSvcLocator)
Definition: InputMakerForRoI.cxx:16
TrigCompositeUtils::DecisionContainer
xAOD::TrigCompositeContainer DecisionContainer
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigCompositeContainer.h:21
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
InputMakerForRoI.h
InputMakerBase
Input Makers are used at the start of a sequence: retrieve filtered collection via the input decision...
Definition: InputMakerBase.h:20
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
TrigCompositeUtils.h
TrigRoiDescriptor
nope - should be used for standalone also, perhaps need to protect the class def bits #ifndef XAOD_AN...
Definition: TrigRoiDescriptor.h:56
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
InputMakerForRoI::initialize
virtual StatusCode initialize() override
Definition: InputMakerForRoI.cxx:20
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
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
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
InputMakerForRoI::m_roiTool
ToolHandle< IViewCreatorROITool > m_roiTool
Definition: InputMakerForRoI.h:36
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
TrigCompositeAuxContainer.h
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
InputMakerForRoI::m_RoIs
SG::WriteHandleKey< TrigRoiDescriptorCollection > m_RoIs
Definition: InputMakerForRoI.h:33
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TrigCompositeUtils::Decision
xAOD::TrigComposite Decision
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:20
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
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
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
InputMakerBase::m_isEmptyStep
Gaudi::Property< bool > m_isEmptyStep
Definition: InputMakerBase.h:56
TrigRoiDescriptorCollection
Definition: TrigRoiDescriptorCollection.h:21
RoiDescriptor::isFullscan
virtual bool isFullscan() const override final
is this a full scan RoI?
Definition: RoiDescriptor.h:132
TrigCompositeUtils::roiString
const std::string & roiString()
Definition: TrigCompositeUtilsRoot.cxx:878
TrigRoiDescriptor
Athena::TPCnvVers::Current TrigRoiDescriptor
Definition: TrigSteeringEventTPCnv.cxx:68
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrigRoiDescriptorCollection.h