8#include "AthLinks/ElementLink.h"
33 ATH_MSG_ERROR(
"The EventViewCreatorAlgorithm class cannot be used as the InputMaker for an empty step.");
34 return StatusCode::FAILURE;
44 return StatusCode::SUCCESS;
59 ATH_CHECK( viewsHandle.record( std::make_unique<ViewContainer>() ) );
60 auto viewVector = viewsHandle.ptr();
69 cachedViews = cachedRH.
ptr();
76 std::vector<ElementLink<TrigRoiDescriptorCollection>> RoIsFromDecision;
78 if( outputHandle->size() == 0) {
79 ATH_MSG_DEBUG(
"Have no decisions in output handle "<< outputHandle.
key() <<
". Handle is valid but container is empty. "
80 <<
"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.");
82 ATH_MSG_DEBUG(
"Have output " << outputHandle.
key() <<
" with " << outputHandle->size() <<
" elements" );
88 for (
Decision* outputDecision : *outputHandle ) {
91 ATH_MSG_ERROR(
"No '" <<
roiString() <<
"'link was attached by the ROITool. Decision object dump:" << *outputDecision);
92 return StatusCode::FAILURE;
103 size_t cachedIndex = std::numeric_limits<std::size_t>::max();
104 const bool useCached =
checkCache(cachedViews, outputDecision, cachedIndex, matchingCache);
107 auto roiIt =
find(RoIsFromDecision.begin(), RoIsFromDecision.end(), roiEL);
112 const Decision* cached = cachedViews->
at(cachedIndex);
117 ATH_MSG_DEBUG(
"Re-using cached existing view from " << cachedViewEL.
dataID() <<
", index:" << cachedViewEL.
index() <<
" on ROI " << **cachedROIEL);
118 outputDecision->setObjectLink(
viewString(), cachedViewEL );
119 outputDecision->setObjectLink(
roiString(), cachedROIEL );
122 }
else if ( roiIt == RoIsFromDecision.end() ) {
125 RoIsFromDecision.push_back(roiEL);
126 ATH_MSG_DEBUG(
"Found RoI:" << **roiEL <<
" FS=" << (*roiEL)->isFullscan() <<
". Making View.");
128 viewVector->push_back( newView );
153 ATH_MSG_DEBUG(
"Made new View, storing view in viewVector " <<
m_viewsKey.key() <<
" index:" << viewVector->size()-1 );
158 const size_t existingIndex = std::distance(RoIsFromDecision.begin(), roiIt);
159 ATH_MSG_DEBUG(
"Found existing View, stored in view in viewVector " <<
m_viewsKey.key() <<
" index:" << existingIndex );
166 ATH_MSG_DEBUG(
"Launching execution in " << viewVector->size() <<
" unique views" );
173 return StatusCode::SUCCESS;
176bool endsWith(
const std::string& value,
const std::string& ending) {
177 if (ending.size() > value.size()) {
180 return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
197 if (previousStepViews.size()) {
200 const bool previousStepDidNotUsedCachedView =
endsWith(previousView.
dataID(),
"_probe");
201 if (previousStepDidNotUsedCachedView) {
203 ATH_MSG_DEBUG(
"Previous probe step used a probe EventView for this decision object. Do not attempt to use a cached EventView in this step.");
208 bool usedROIMatchingFlag{
false};
211 ATH_MSG_ERROR(
"Called matchInCollection in an EVCA configured with mergeUsingFeature=True, however ROI matching was used instead?! Should not be possible.");
223 const SG::View* view = *(cachedViews->
at(cachedIndex)->objectLink<ViewContainer>(
viewString()));
226 std::vector<LinkInfo<ViewContainer>> viewsToLinkVector =
viewsToLink(outputDecision);
228 const SG::View* toLink = *(toLinkLI.link);
230 bool foundIt =
false;
231 for (
const SG::View* prevLinked : view->getParentLinks()) {
232 if (prevLinked == toLink) {
238 ATH_MSG_DEBUG(
"The cached view from the tag step is not linked to the required views from earlier steps which we need in the probe processing, we cannot re-use it.");
250 for (
const Decision* cachedView : *cachedViews) {
252 if (matchingHash == std::numeric_limits<std::size_t>::max()) {
253 return StatusCode::FAILURE;
259 return StatusCode::SUCCESS;
266 return StatusCode::SUCCESS;
270 ATH_MSG_ERROR(
"Called linkViewToParent on a Decision object which already has been given a '"
271 <<
viewString() <<
"' link. Call this fn BEFORE linking the new View.");
272 return StatusCode::FAILURE;
274 std::vector<LinkInfo<ViewContainer>> viewsToLinkVector =
viewsToLink(outputDecision);
275 if (viewsToLinkVector.size() == 0) {
276 ATH_MSG_ERROR(
"Could not find the parent View, but 'RequireParentView' is true.");
277 return StatusCode::FAILURE;
284 ATH_MSG_DEBUG(
"Will link " << viewsToLinkVector.size() <<
" parent view(s)" );
288 ATH_MSG_DEBUG(
"Parent view linked (" << toLinkLI.link.dataID() <<
", index:" << toLinkLI.link.index() <<
")" );
291 return StatusCode::SUCCESS;
296 auto oneRoIColl = std::make_unique< ConstDataVector<TrigRoiDescriptorCollection> >();
298 oneRoIColl->push_back( *roiEL );
304 ATH_CHECK( handle.record( std::move( oneRoIColl ) ) );
305 return StatusCode::SUCCESS;
312 auto oneObjectCollection = std::make_unique< xAOD::MuonContainer >();
313 auto oneObjectAuxCollection = std::make_unique< xAOD::MuonAuxContainer >();
314 oneObjectCollection->setStore( oneObjectAuxCollection.get() );
317 oneObjectCollection->push_back( copiedMuon );
318 *copiedMuon = *theObject;
320 auto muonCandidate = std::make_unique< ConstDataVector< MuonCandidateCollection > >();
323 if(msLink.isValid() && extTrackLink.isValid()) muonCandidate->push_back(
new MuonCombined::MuonCandidate(msLink, (*extTrackLink)->trackLink(), (*extTrackLink)->index()) );
327 ATH_CHECK( handleMuon.record( std::move( oneObjectCollection ), std::move( oneObjectAuxCollection )) );
330 ATH_CHECK( handleCandidate.record( std::move( muonCandidate ) ) );
332 return StatusCode::SUCCESS;
341 auto oneObjectCollection = std::make_unique< xAOD::JetContainer >();
342 auto oneObjectAuxCollection = std::make_unique< xAOD::JetAuxContainer >();
343 oneObjectCollection->setStore( oneObjectAuxCollection.get() );
346 oneObjectCollection->push_back( copiedJet );
347 *copiedJet = *theObject;
350 ATH_CHECK( handle.record( std::move(oneObjectCollection),std::move(oneObjectAuxCollection) ) );
352 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
bool endsWith(const std::string &value, const std::string &ending)
DataVector< SG::View > ViewContainer
View container for recording in StoreGate.
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
const T * at(size_type n) const
Access an element, as an rvalue.
ElementLink implementation for ROOT usage.
const ID_type & dataID() const
Get the key that we reference, as a string.
index_type index() const
Get the index of the element inside of its container.
bool isValid() const
Test to see if the link can be dereferenced.
SG::WriteHandleKey< xAOD::MuonContainer > m_inViewMuons
Gaudi::Property< bool > m_placeJetInView
StatusCode linkViewToParent(const TrigCompositeUtils::Decision *outputDecision, SG::View *newView) const
Makes sure the views are linked, if configuration requireParentView is set.
Gaudi::Property< bool > m_placeMuonInView
std::vector< TrigCompositeUtils::LinkInfo< ViewContainer > > viewsToLink(const TrigCompositeUtils::Decision *outputDecision) const
Obtain view(s) from most recent prior step(s) which are to be wired up.
Gaudi::Property< std::vector< std::string > > m_viewFallFilter
StatusCode placeRoIInView(const ElementLink< TrigRoiDescriptorCollection > &roi, SG::View *view, const EventContext &context) const
Seeds a newly created view with an ROI collection containing the single seeding ROI.
SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > m_cachedViewsKey
SG::WriteHandleKey< ConstDataVector< TrigRoiDescriptorCollection > > m_inViewRoIs
Gaudi::Property< bool > m_requireParentView
virtual StatusCode initialize() override
StatusCode placeJetInView(const xAOD::Jet *theObject, SG::View *view, const EventContext &context) const
Creates a SG::VIEW_ELEMENTS collection inside a newly created View populated by the jet used to seed ...
virtual StatusCode execute(const EventContext &) const override
SG::WriteHandleKey< ViewContainer > m_viewsKey
bool checkCache(const TrigCompositeUtils::DecisionContainer *cachedViews, const TrigCompositeUtils::Decision *outputDecision, size_t &cachedIndex, MatchingCache &matchingCache) const
Allow for the re-use of EventViews run in a previous Step in another EVCA instance configured to spaw...
EventViewCreatorAlgorithm()
SG::WriteHandleKey< ConstDataVector< MuonCandidateCollection > > m_inViewMuonCandidates
Gaudi::Property< bool > m_reverseViews
Gaudi::Property< bool > m_cacheDisabled
Gaudi::Property< bool > m_viewFallThrough
ToolHandle< IViewCreatorROITool > m_roiTool
SG::WriteHandleKey< xAOD::JetContainer > m_inViewJets
StatusCode placeMuonInView(const xAOD::Muon *theObject, SG::View *view, const EventContext &context) const
Creates a SG::VIEW_ELEMENTS collection inside a newly created View populated by the MuonCombined::Muo...
SmartIF< IScheduler > getScheduler() const
Obtain smart pointer to scheduler in order to schedule newly spawned views.
Gaudi::Property< std::string > m_viewNodeName
StatusCode populateMatchingCacheWithCachedViews(const TrigCompositeUtils::DecisionContainer *cachedViews, MatchingCache &matchingCache) const
We look for matching Decision Objects in a matchingCache.
virtual ~EventViewCreatorAlgorithm()
const_pointer_type ptr()
Dereference the pointer.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
A "view" of the event store (IProxyDict).
void setFilter(std::vector< std::string > const &inputFilter)
Set a filtering rule for anything loaded via fall-through.
void linkParent(const IProxyDict *parent)
Link to the previously used views.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const ElementLink< TrackParticleContainer > & extrapolatedMuonSpectrometerTrackParticleLink() const
Returns an ElementLink to the Extrapolated Muon Spectrometer TrackParticle used in identification of ...
const ElementLink< TrackParticleContainer > & muonSpectrometerTrackParticleLink() const
Returns an ElementLink to the InnerDetector TrackParticle used in identification of this muon.
bool hasObjectLink(const std::string &name, const CLID clid=CLID_NULL) const
Check if a link to an object with a given name and type exists. CLID_NULL to not check type.
std::string find(const std::string &s)
return a remapped string
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
const std::string & viewString()
xAOD::TrigComposite Decision
const std::string & roiString()
const std::string & featureString()
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
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...
xAOD::TrigCompositeContainer DecisionContainer
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)
StatusCode scheduleViews(ViewContainer *viewVector, std::string const &nodeName, EventContext const &sourceContext, SmartIF< IScheduler > scheduler, bool reverseOrder=false)
SG::View * makeView(const std::string &common_name, int const unique_index=-1, bool const allowFallThrough=true)
auto makeHandle(const SG::View *view, const KEY &key, const EventContext &ctx)
Create a view handle from a handle key.
Jet_v1 Jet
Definition of the current "jet version".
Muon_v1 Muon
Reference the current persistent version:
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...