ATLAS Offline Software
ViewCreatorPreviousROITool.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 
8 
9 #include <map>
10 
11 using namespace TrigCompositeUtils;
12 
13 ViewCreatorPreviousROITool::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 
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 }
ViewCreatorPreviousROITool::attachROILinks
virtual StatusCode attachROILinks(TrigCompositeUtils::DecisionContainer &decisions, const EventContext &ctx) const override
Tool interface method.
Definition: ViewCreatorPreviousROITool.cxx:22
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
ViewCreatorPreviousROITool.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
ViewCreatorPreviousROITool::m_roiSGKey
Gaudi::Property< std::string > m_roiSGKey
Definition: ViewCreatorPreviousROITool.h:32
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
python.sizes.location
string location
Definition: sizes.py:11
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.
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
ViewCreatorPreviousROITool::initialize
virtual StatusCode initialize() override
Definition: ViewCreatorPreviousROITool.cxx:17
xAOD::decisions
decisions
Definition: TrigComposite_v1.cxx:81
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ViewCreatorPreviousROITool::m_roisWriteHandleKey
SG::WriteHandleKey< TrigRoiDescriptorCollection > m_roisWriteHandleKey
Definition: ViewCreatorPreviousROITool.h:35
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::WriteHandle< TrigRoiDescriptorCollection >
TrigRoiDescriptorCollection
Definition: TrigRoiDescriptorCollection.h:21
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
TrigCompositeUtils::roiString
const std::string & roiString()
Definition: TrigCompositeUtilsRoot.cxx:878
ViewCreatorPreviousROITool::ViewCreatorPreviousROITool
ViewCreatorPreviousROITool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: ViewCreatorPreviousROITool.cxx:13
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