ATLAS Offline Software
ViewCreatorFetchFromViewROITool.cxx
Go to the documentation of this file.
1 
2 /*
3 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 */
5 
7 #include "AthViews/ViewHelper.h"
9 
10 using namespace TrigCompositeUtils;
11 
12 ViewCreatorFetchFromViewROITool::ViewCreatorFetchFromViewROITool(const std::string& type, const std::string& name, const IInterface* parent)
13  : base_class(type, name, parent)
14  {}
15 
16 
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 }
TrigCompositeUtils::LinkInfo::link
ElementLink< T > link
Link to the feature.
Definition: LinkInfo.h:61
TrigCompositeUtils::LinkInfo::isValid
bool isValid() const
Definition: LinkInfo.h:43
ViewCreatorFetchFromViewROITool::m_viewToFetchFrom
Gaudi::Property< std::string > m_viewToFetchFrom
Definition: ViewCreatorFetchFromViewROITool.h:45
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ViewCreatorFetchFromViewROITool::m_viewToFetchFromProbe
std::string m_viewToFetchFromProbe
Definition: ViewCreatorFetchFromViewROITool.h:61
ViewHelper::makeHandle
SG::ReadHandle< T > makeHandle(const SG::View *view, const SG::ReadHandleKey< T > &rhKey, const EventContext &context)
navigate from the TrigComposite to nearest view and fetch object from it
Definition: ViewHelper.h:265
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
ViewHelper.h
ViewCreatorFetchFromViewROITool::ViewCreatorFetchFromViewROITool
ViewCreatorFetchFromViewROITool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: ViewCreatorFetchFromViewROITool.cxx:12
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ViewCreatorFetchFromViewROITool::m_roisWriteHandleKey
SG::WriteHandleKey< TrigRoiDescriptorCollection > m_roisWriteHandleKey
Definition: ViewCreatorFetchFromViewROITool.h:39
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
test_pyathena.parent
parent
Definition: test_pyathena.py:15
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
TrigCompositeUtils::createAndStoreNoAux
SG::WriteHandle< CONT > createAndStoreNoAux(const SG::WriteHandleKey< CONT > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Creates and right away records the Container CONT with the key.
ViewCreatorFetchFromViewROITool::m_roiEtaWidth
Gaudi::Property< double > m_roiEtaWidth
Definition: ViewCreatorFetchFromViewROITool.h:51
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:101
ViewCreatorFetchFromViewROITool::attachROILinks
virtual StatusCode attachROILinks(TrigCompositeUtils::DecisionContainer &decisions, const EventContext &ctx) const override
Tool interface method.
Definition: ViewCreatorFetchFromViewROITool.cxx:27
RoiDescriptor::zed
virtual double zed() const override final
Definition: RoiDescriptor.h:102
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ViewCreatorFetchFromViewROITool::m_roiZedWidth
Gaudi::Property< double > m_roiZedWidth
Definition: ViewCreatorFetchFromViewROITool.h:57
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
ViewCreatorFetchFromViewROITool::m_roiPhiWidth
Gaudi::Property< double > m_roiPhiWidth
Definition: ViewCreatorFetchFromViewROITool.h:54
ViewCreatorFetchFromViewROITool::m_doResize
Gaudi::Property< bool > m_doResize
Definition: ViewCreatorFetchFromViewROITool.h:48
python.PyAthena.v
v
Definition: PyAthena.py:154
SG::WriteHandle< TrigRoiDescriptorCollection >
RoiDescriptor::etaPlus
virtual double etaPlus() const override final
gets eta at zedPlus
Definition: RoiDescriptor.h:115
ViewCreatorFetchFromViewROITool.h
TrigCompositeUtils::LinkInfo
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition: LinkInfo.h:28
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
RoiDescriptor::phi
virtual double phi() const override final
Methods to retrieve data members.
Definition: RoiDescriptor.h:100
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
RoiDescriptor::eta
virtual double eta() const override final
Definition: RoiDescriptor.h:101
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
TrigCompositeUtils::roiString
const std::string & roiString()
Definition: TrigCompositeUtilsRoot.cxx:876
TrigRoiDescriptor
Athena::TPCnvVers::Current TrigRoiDescriptor
Definition: TrigSteeringEventTPCnv.cxx:68
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
RoiDescriptor::phiPlus
virtual double phiPlus() const override final
gets phiPlus
Definition: RoiDescriptor.h:118
ViewCreatorFetchFromViewROITool::initialize
virtual StatusCode initialize() override
Definition: ViewCreatorFetchFromViewROITool.cxx:17
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrigCompositeUtils::viewString
const std::string & viewString()
Definition: TrigCompositeUtilsRoot.cxx:880
TrigRoiDescriptorCollection.h
ViewCreatorFetchFromViewROITool::m_inViewRoIKey
SG::ReadHandleKey< TrigRoiDescriptorCollection > m_inViewRoIKey
Definition: ViewCreatorFetchFromViewROITool.h:42
RoiDescriptor::zedPlus
virtual double zedPlus() const override final
z at the most forward end of the RoI
Definition: RoiDescriptor.h:112