8#include "AthLinks/ElementLink.h"
41 ATH_MSG_ERROR(
"The EventViewCreatorAlgorithm class cannot be used as the InputMaker for an empty step.");
42 return StatusCode::FAILURE;
52 return StatusCode::SUCCESS;
67 ATH_CHECK( viewsHandle.record( std::make_unique<ViewContainer>() ) );
68 auto viewVector = viewsHandle.ptr();
77 cachedViews = cachedRH.
ptr();
84 std::vector<ElementLink<TrigRoiDescriptorCollection>> RoIsFromDecision;
86 if( outputHandle->size() == 0) {
87 ATH_MSG_DEBUG(
"Have no decisions in output handle "<< outputHandle.
key() <<
". Handle is valid but container is empty. "
88 <<
"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.");
90 ATH_MSG_DEBUG(
"Have output " << outputHandle.
key() <<
" with " << outputHandle->size() <<
" elements" );
96 for (
Decision* outputDecision : *outputHandle ) {
99 ATH_MSG_ERROR(
"No '" <<
roiString() <<
"'link was attached by the ROITool. Decision object dump:" << *outputDecision);
100 return StatusCode::FAILURE;
111 size_t cachedIndex = std::numeric_limits<std::size_t>::max();
112 const bool useCached =
checkCache(cachedViews, outputDecision, cachedIndex, matchingCache);
115 auto roiIt =
find(RoIsFromDecision.begin(), RoIsFromDecision.end(), roiEL);
120 const Decision* cached = cachedViews->
at(cachedIndex);
125 ATH_MSG_DEBUG(
"Re-using cached existing view from " << cachedViewEL.
dataID() <<
", index:" << cachedViewEL.
index() <<
" on ROI " << **cachedROIEL);
126 outputDecision->setObjectLink(
viewString(), cachedViewEL );
127 outputDecision->setObjectLink(
roiString(), cachedROIEL );
130 }
else if ( roiIt == RoIsFromDecision.end() ) {
133 RoIsFromDecision.push_back(roiEL);
134 ATH_MSG_DEBUG(
"Found RoI:" << **roiEL <<
" FS=" << (*roiEL)->isFullscan() <<
". Making View.");
136 viewVector->push_back( newView );
161 ATH_MSG_DEBUG(
"Made new View, storing view in viewVector " <<
m_viewsKey.key() <<
" index:" << viewVector->size()-1 );
166 const size_t existingIndex = std::distance(RoIsFromDecision.begin(), roiIt);
167 ATH_MSG_DEBUG(
"Found existing View, stored in view in viewVector " <<
m_viewsKey.key() <<
" index:" << existingIndex );
174 ATH_MSG_DEBUG(
"Launching execution in " << viewVector->size() <<
" unique views" );
181 return StatusCode::SUCCESS;
184bool endsWith(
const std::string& value,
const std::string& ending) {
185 if (ending.size() > value.size()) {
188 return std::equal(ending.rbegin(), ending.rend(), value.rbegin());
205 if (previousStepViews.size()) {
208 const bool previousStepDidNotUsedCachedView =
endsWith(previousView.
dataID(),
"_probe");
209 if (previousStepDidNotUsedCachedView) {
211 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.");
216 bool usedROIMatchingFlag{
false};
217 bool result =
matchInCollection(cachedViews, outputDecision, cachedIndex, usedROIMatchingFlag, matchingCache);
219 ATH_MSG_ERROR(
"Called matchInCollection in an EVCA configured with mergeUsingFeature=True, however ROI matching was used instead?! Should not be possible.");
231 const SG::View* view = *(cachedViews->
at(cachedIndex)->objectLink<ViewContainer>(
viewString()));
234 std::vector<LinkInfo<ViewContainer>> viewsToLinkVector =
viewsToLink(outputDecision);
236 const SG::View* toLink = *(toLinkLI.link);
238 bool foundIt =
false;
239 for (
const SG::View* prevLinked : view->getParentLinks()) {
240 if (prevLinked == toLink) {
246 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.");
258 for (
const Decision* cachedView : *cachedViews) {
260 if (matchingHash == std::numeric_limits<std::size_t>::max()) {
261 return StatusCode::FAILURE;
267 return StatusCode::SUCCESS;
274 return StatusCode::SUCCESS;
278 ATH_MSG_ERROR(
"Called linkViewToParent on a Decision object which already has been given a '"
279 <<
viewString() <<
"' link. Call this fn BEFORE linking the new View.");
280 return StatusCode::FAILURE;
282 std::vector<LinkInfo<ViewContainer>> viewsToLinkVector =
viewsToLink(outputDecision);
283 if (viewsToLinkVector.size() == 0) {
284 ATH_MSG_ERROR(
"Could not find the parent View, but 'RequireParentView' is true.");
285 return StatusCode::FAILURE;
292 ATH_MSG_DEBUG(
"Will link " << viewsToLinkVector.size() <<
" parent view(s)" );
296 ATH_MSG_DEBUG(
"Parent view linked (" << toLinkLI.link.dataID() <<
", index:" << toLinkLI.link.index() <<
")" );
299 return StatusCode::SUCCESS;
304 auto oneRoIColl = std::make_unique< ConstDataVector<TrigRoiDescriptorCollection> >();
306 oneRoIColl->push_back( *roiEL );
312 ATH_CHECK( handle.record( std::move( oneRoIColl ) ) );
313 return StatusCode::SUCCESS;
320 auto oneObjectCollection = std::make_unique< xAOD::MuonContainer >();
321 auto oneObjectAuxCollection = std::make_unique< xAOD::MuonAuxContainer >();
322 oneObjectCollection->setStore( oneObjectAuxCollection.get() );
324 xAOD::Muon* copiedMuon = oneObjectCollection->push_back( std::make_unique<xAOD::Muon>());
326 *copiedMuon = *theObject;
328 auto muonCandidate = std::make_unique< ConstDataVector< MuonCandidateCollection > >();
329 auto* msLink = theObject->
trackParticle(xAOD::Muon::TrackParticleType::MuonSpectrometerTrackParticle);
330 auto* extTrackLink = theObject->
trackParticle(xAOD::Muon::TrackParticleType::ExtrapolatedMuonSpectrometerTrackParticle);
331 if(msLink && extTrackLink) {
333 muonCandidate->push_back( std::make_unique<MuonCombined::MuonCandidate>(
makeLink(msLink),
334 extTrackLink->trackLink(),
335 extTrackLink->index()) );
339 ATH_CHECK( handleMuon.record( std::move( oneObjectCollection ), std::move( oneObjectAuxCollection )) );
342 ATH_CHECK( handleCandidate.record( std::move( muonCandidate ) ) );
344 return StatusCode::SUCCESS;
353 auto oneObjectCollection = std::make_unique< xAOD::JetContainer >();
354 auto oneObjectAuxCollection = std::make_unique< xAOD::JetAuxContainer >();
355 oneObjectCollection->setStore( oneObjectAuxCollection.get() );
358 oneObjectCollection->push_back( copiedJet );
359 *copiedJet = *theObject;
362 ATH_CHECK( handle.record( std::move(oneObjectCollection),std::move(oneObjectAuxCollection) ) );
364 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
bool endsWith(const std::string &value, const std::string &ending)
ElementLink< xAOD::TrackParticleContainer > makeLink(const xAOD::TrackParticle *track)
size_t size() const
Number of registered mappings.
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
Check if the element can be found.
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 TrackParticle * trackParticle(TrackParticleType type) const
Returns a pointer (which can be NULL) to the 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".
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
Muon_v1 Muon
Reference the current persistent version:
static constexpr CLID ID()
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...