ATLAS Offline Software
Loading...
Searching...
No Matches
ViewCreatorPreviousROITool.cxx
Go to the documentation of this file.
1
2/*
3Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4*/
5
8
9#include <map>
10
11using namespace TrigCompositeUtils;
12
13ViewCreatorPreviousROITool::ViewCreatorPreviousROITool(const std::string& type, const std::string& name, const IInterface* parent)
14 : base_class(type, name, parent)
15 {}
16
19 return StatusCode::SUCCESS;
20}
21
22StatusCode ViewCreatorPreviousROITool::attachROILinks(TrigCompositeUtils::DecisionContainer& decisions, const EventContext& ctx) const {
23 // Locate "roi" for each Decision object from previous step, re-attach the ElementLink as "roi" to the current Decision object.
24 // I.e. don't update the "roi", just re-use the one from the previous Step.
25
26 for ( Decision* outputDecision : decisions ) {
27 const std::vector<LinkInfo<TrigRoiDescriptorCollection>> myROIs = findLinks<TrigRoiDescriptorCollection>(outputDecision, roiString(), TrigDefs::lastFeatureOfType);
28
29 int location = -1;
30
31 if (myROIs.size() == 0) {
32 ATH_MSG_ERROR("Found zero '" << roiString() << "' for Decision object index " << outputDecision->index());
33 } else if (myROIs.size() == 1) {
34 location = 0;
35 } else if (not m_roiSGKey.empty()) { // Note: Also requires that size be > 1
36 for (size_t i = 0; i < myROIs.size(); ++i) {
37 if (myROIs.at(i).link.dataID() == m_roiSGKey) {
38 ATH_MSG_DEBUG("Found " << myROIs.size() << " RoI links. However, successfully resolved the ambiguity using roiSGKey=" << m_roiSGKey << ", taking index " << location);
39 location = i;
40 break;
41 }
42 }
43 }
44
45 if (location == -1) {
46 ATH_MSG_ERROR("Did not find exactly one '" << roiString() << "' for Decision object index " << outputDecision->index()
47 << ", found " << myROIs.size() << ". Unable to supply single ROI to spawn EventView on.");
48 for (const auto& li : myROIs) {
49 ATH_MSG_ERROR(" -- " << li.link.dataID() << ":" << li.link.index() << ". Dump:" << *(li.source));
50 }
51 return StatusCode::FAILURE;
52 }
53
54 outputDecision->setObjectLink(roiString(), myROIs.at(location).link);
55 }
56
57 // If this property is set, we actually want to copy the ROIs into a new container. For disambiguation purposes
58 if (!m_roisWriteHandleKey.empty()) {
59 std::map<ElementLink<TrigRoiDescriptorCollection>, ElementLink<TrigRoiDescriptorCollection>> oldToNew;
61
62 for ( Decision* outputDecision : decisions ) {
63
64 // Only copy each unique ROI once into the output collection.
67 if (oldToNew.count(oldRoI) == 1) {
68 newRoI = oldToNew[oldRoI];
69 } else {
70 roisWriteHandle->push_back( new TrigRoiDescriptor( **oldRoI ) );
71 newRoI = ElementLink<TrigRoiDescriptorCollection>(*roisWriteHandle, roisWriteHandle->size() - 1, ctx);
72 oldToNew[oldRoI] = newRoI;
73 }
74
75 // Update the link. Note: overwries the link set of L54
76 outputDecision->setObjectLink(roiString(), newRoI);
77 }
78 }
79
80
81 return StatusCode::SUCCESS;
82}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Athena::TPCnvVers::Current TrigRoiDescriptor
Gaudi::Property< std::string > m_roiSGKey
ViewCreatorPreviousROITool(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode initialize() override
virtual StatusCode attachROILinks(TrigCompositeUtils::DecisionContainer &decisions, const EventContext &ctx) const override
Tool interface method.
SG::WriteHandleKey< TrigRoiDescriptorCollection > m_roisWriteHandleKey
SG::WriteHandle< CONT > createAndStoreNoAux(const SG::WriteHandleKey< CONT > &key, const EventContext &ctx)
Creates and right away records the Container CONT with the key.
const std::string & roiString()
void findLinks(const Decision *start, const std::string &linkName, std::vector< LinkInfo< T > > &links, unsigned int behaviour=TrigDefs::allFeaturesOfType, std::set< const xAOD::TrigComposite * > *fullyExploredFrom=nullptr)
search back the TC links for the object of type T linked to the one of TC (recursively) Populates pro...
static const unsigned int lastFeatureOfType
Run 3 "enum". Only return the final feature along each route through the navigation.