ATLAS Offline Software
Loading...
Searching...
No Matches
ViewCreatorFetchFromViewROITool.cxx
Go to the documentation of this file.
1
2/*
3Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4*/
5
9
10using namespace TrigCompositeUtils;
11
12ViewCreatorFetchFromViewROITool::ViewCreatorFetchFromViewROITool(const std::string& type, const std::string& name, const IInterface* parent)
13 : base_class(type, name, parent)
14 {}
15
16
18 ATH_CHECK(m_roisWriteHandleKey.initialize());
19 ATH_CHECK(m_inViewRoIKey.initialize());
20 renounce(m_inViewRoIKey); // Will be read from in-View
21
23 return StatusCode::SUCCESS;
24}
25
26
29
30 for ( Decision* outputDecision : decisions ) {
31 LinkInfo<ViewContainer> viewToFetchFrom;
32 if(!m_viewToFetchFrom.empty()){
33 // Look for a specific View, keyed by the View's SG key
34 const std::vector<LinkInfo<ViewContainer>> myViews = findLinks<ViewContainer>(outputDecision, viewString(), TrigDefs::allFeaturesOfType);
35 bool found = false;
36 for(const LinkInfo<ViewContainer>& v : myViews){
37 ATH_MSG_DEBUG("view "<<v.link.dataID());
38 if(v.link.dataID() == m_viewToFetchFrom or v.link.dataID() == m_viewToFetchFromProbe) {
39 found = true;
40 viewToFetchFrom = v;
41 break;
42 }
43 }
44 if(!found){
45 ATH_MSG_ERROR("Of the " << myViews.size() << " Views in the history of Decision object with index " << outputDecision->index()
46 << ", none came from a View called " << m_viewToFetchFrom);
47 return StatusCode::FAILURE;
48 }
49 }
50 else{
51
52 // Assume the most recent View is the one we fetch from, and that there is exactly one most recent View after any merging
53 const std::vector<LinkInfo<ViewContainer>> myView = findLinks<ViewContainer>(outputDecision, viewString(), TrigDefs::lastFeatureOfType);
54 if (myView.size() != 1) {
55 ATH_MSG_ERROR("Did not find exactly one most-recent '" << viewString() << "' for Decision object index " << outputDecision->index()
56 << ", found " << myView.size());
57 if (myView.size() > 1) {
58 ATH_MSG_ERROR("Was this Decision Object was merged after having followed different reconstruction paths in previous Steps?");
59 ATH_MSG_ERROR("Need more information about which of these Views to look in to find the desired '" << m_inViewRoIKey.key() << "' TrigRoiDescriptorCollection");
60 }
61 return StatusCode::FAILURE;
62 }
63 viewToFetchFrom = myView.at(0);
64 }
65 ATH_CHECK(viewToFetchFrom.isValid());
66
68 ATH_CHECK(roiReadHandle.isValid());
69
70 if (roiReadHandle->size() != 1) {
71 ATH_MSG_ERROR("In-view ROI collection '" << m_inViewRoIKey.key() << "' for Decision object index " << outputDecision->index()
72 << " has " << roiReadHandle->size() << " TrigRoiDescriptor inside. We require exactly one.");
73 return StatusCode::FAILURE;
74 }
75
76 if (!m_doResize) { //default
77 // This ROI was created in a View, it cannot currently be written out.
78 // Make a copy in the full-event context, which can be recorded.
79 roisWriteHandle->push_back( new TrigRoiDescriptor( *(roiReadHandle->at(0)) ) );
80 }
81 else { // force resize
82 auto oldroi = roiReadHandle->at(0);
83 ATH_MSG_DEBUG( " Old ROI size " << " eta="<< oldroi->eta() << " +- " << oldroi->etaPlus()-oldroi->eta() \
84 << " phi="<< oldroi->phi() << " +- " << oldroi->phiPlus()-oldroi->phi() \
85 << " zed="<< oldroi->zed() << " +- " << oldroi->zedPlus()-oldroi->zed());
86 ATH_MSG_DEBUG( " New size (eta,phi,zed): " << m_roiEtaWidth.value() << ", " << m_roiPhiWidth.value() << ", " << m_roiZedWidth.value() );
87 const double reta = oldroi->eta();
88 const double retap = (m_roiEtaWidth>0 ? reta + m_roiEtaWidth : oldroi->etaPlus());
89 const double retam = (m_roiEtaWidth>0 ? reta - m_roiEtaWidth : oldroi->etaMinus());
90 const double rphi = oldroi->phi();
91 const double rphip = (m_roiPhiWidth>0 ? rphi + m_roiPhiWidth : oldroi->phiPlus());
92 const double rphim = (m_roiPhiWidth>0 ? rphi - m_roiPhiWidth : oldroi->phiMinus());
93 const double rzed = oldroi->zed();
94 const double rzedp = (m_roiZedWidth>0 ? rzed + m_roiZedWidth : oldroi->zedPlus());
95 const double rzedm = (m_roiZedWidth>0 ? rzed - m_roiZedWidth : oldroi->zedMinus());
96 std::unique_ptr<TrigRoiDescriptor> roi = std::make_unique<TrigRoiDescriptor>(reta, retam, retap, rphi, rphim, rphip, rzed, rzedm, rzedp);
97 ATH_MSG_DEBUG( " New ROI size " << " eta="<< roi->eta() << " +- " << roi->etaPlus()-roi->eta() \
98 << " phi="<< roi->phi() << " +- " << roi->phiPlus()-roi->phi() \
99 << " zed="<< roi->zed() << " +- " << roi->zedPlus()-roi->zed());
100 roisWriteHandle->push_back( roi.release() );
101 }
102
103 const ElementLink<TrigRoiDescriptorCollection> newRoiEL = ElementLink<TrigRoiDescriptorCollection>(*roisWriteHandle, roisWriteHandle->size() - 1, ctx);
104
105 outputDecision->setObjectLink(roiString(), newRoiEL);
106 }
107
108 return StatusCode::SUCCESS;
109}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Athena::TPCnvVers::Current TrigRoiDescriptor
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Gaudi::Property< std::string > m_viewToFetchFrom
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_inViewRoIKey
virtual StatusCode attachROILinks(TrigCompositeUtils::DecisionContainer &decisions, const EventContext &ctx) const override
Tool interface method.
ViewCreatorFetchFromViewROITool(const std::string &type, const std::string &name, const IInterface *parent)
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 & viewString()
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.
static const unsigned int allFeaturesOfType
Run 3 "enum". Return all features along legs (still with type and container checks)
auto makeHandle(const SG::View *view, const KEY &key, const EventContext &ctx)
Create a view handle from a handle key.
Definition ViewHelper.h:273
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22
ElementLink< T > link
Link to the feature.
Definition LinkInfo.h:55