2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5#include "AthViews/ViewHelper.h"
7template < class CONTAINER >
8StatusCode TrigBjetHypoAlgBase::retrieveCollectionFromView( const EventContext& context,
9 ElementLinkVector< CONTAINER >& EL,
10 const SG::ReadHandleKey< CONTAINER >& inputKey,
11 const TrigCompositeUtils::Decision* prevDecision ) const {
13 ElementLink< ViewContainer > viewEL = prevDecision->objectLink< ViewContainer >( TrigCompositeUtils::viewString() );
14 ATH_CHECK( viewEL.isValid() );
15 ATH_MSG_DEBUG( "Retrieved View" );
17 SG::ReadHandle< CONTAINER > Handle = ViewHelper::makeHandle( *viewEL, inputKey, context );
18 ATH_CHECK( Handle.isValid() );
19 ATH_MSG_DEBUG ( "EventView " << (*viewEL)->name() << " has object's container of size: " << Handle->size() );
21 for ( unsigned int index(0); index < Handle->size(); index++ ) {
22 ElementLink< CONTAINER > toAdd = ViewHelper::makeLink< CONTAINER >( *viewEL, Handle, index );
23 ATH_CHECK( toAdd.isValid() );
24 EL.push_back( toAdd );
27 return StatusCode::SUCCESS;
30template < class CONTAINER >
31StatusCode TrigBjetHypoAlgBase::retrieveObjectFromNavigation( const EventContext& context,
32 const std::string& linkName,
33 ElementLink< CONTAINER >& EL,
34 const TrigCompositeUtils::Decision* prevDecision ) const {
36 const std::vector< TrigCompositeUtils::LinkInfo< CONTAINER > > myObj =
37 TrigCompositeUtils::findLinks< CONTAINER >(context, prevDecision, linkName.c_str(), TrigDefs::lastFeatureOfType);
39 if ( myObj.size() != 1 ) {
40 ATH_MSG_ERROR( "Did not find only 1 object for link `" << linkName << "` stored in navigation!" );
41 return StatusCode::FAILURE;
44 ATH_CHECK( myObj.at(0).isValid() );
45 EL = myObj.at(0).link;
47 return StatusCode::SUCCESS;
50template < class CONTAINER >
51StatusCode TrigBjetHypoAlgBase::retrieveCollectionFromNavigation( const EventContext& context,
52 const std::string& linkName,
53 ElementLinkVector< CONTAINER >& objELs,
54 const TrigCompositeUtils::DecisionContainer* prevDecisionContainer ) const {
56 for ( const TrigCompositeUtils::Decision *prevDecision : *prevDecisionContainer ) {
57 ElementLink< CONTAINER > objEL;
58 CHECK( retrieveObjectFromNavigation( context, linkName, objEL, prevDecision ) );
59 objELs.push_back( objEL ) ;
62 return StatusCode::SUCCESS;
72template < class CONTAINER >
73StatusCode TrigBjetHypoAlgBase::retrieveObjectFromStoreGate( const EventContext& context,
74 ElementLinkVector< CONTAINER >& ELs,
75 const SG::ReadHandleKey< CONTAINER >& inputKey ) const {
77 ATH_MSG_DEBUG( "Retrieving object from StoreGate from " << inputKey.key() );
79 SG::ReadHandle< CONTAINER > ContainerHandle = SG::makeHandle( inputKey,context );
80 CHECK( ContainerHandle.isValid() );
81 const CONTAINER *Collection = ContainerHandle.get();
83 for (const auto* obj : *Collection) {
84 ElementLink< CONTAINER > Link = ElementLink< CONTAINER >(*Collection, obj->index());
85 ELs.push_back( Link );
88 return StatusCode::SUCCESS;
91template < class CONTAINER >
92StatusCode TrigBjetHypoAlgBase::retrieveObjectFromEventView( const EventContext& context,
93 ElementLinkVector< CONTAINER >& ELs,
94 const SG::ReadHandleKey< CONTAINER >& inputKey,
95 const TrigCompositeUtils::DecisionContainer* prevDevisionContainer ) const {
97 ATH_MSG_DEBUG( "Retrieving object from Event View from " << inputKey.key() );
99 // This vector is for checking we are not reading more than once from the same View, thus retrieving the same objects multiple times!
100 std::vector< ElementLink< ViewContainer > > readViews;
102 for ( const TrigCompositeUtils::Decision* previousDecision: *prevDevisionContainer ) {
104 ElementLink< ViewContainer > viewEL = previousDecision->objectLink< ViewContainer >( TrigCompositeUtils::viewString() );
105 ATH_CHECK( viewEL.isValid() );
106 ATH_MSG_DEBUG( "Retrieved View" );
108 bool alreadyUsed = false;
109 for ( const ElementLink< ViewContainer >& storedViews : readViews ) {
110 if ( viewEL == storedViews ) {
111 ATH_MSG_DEBUG( "We have already used this view!" );
116 if ( alreadyUsed ) continue;
118 readViews.push_back( viewEL );
120 SG::ReadHandle< CONTAINER > Handle = ViewHelper::makeHandle( *viewEL, inputKey, context );
121 ATH_CHECK( Handle.isValid() );
122 ATH_MSG_DEBUG ( "EventView " << (*viewEL)->name() << " has object's container of size: " << Handle->size() );
125 for ( auto it = Handle->begin(); it != Handle->end(); ++it, ++Counter ) {
126 ElementLink< CONTAINER > EL = ViewHelper::makeLink< CONTAINER >( *viewEL, Handle, Counter );
127 ATH_CHECK( EL.isValid() );
132 return StatusCode::SUCCESS;
138template< class CONTAINER >
139StatusCode TrigBjetHypoAlgBase::attachObjectLinkToDecisionFromStoreGate( TrigCompositeUtils::Decision& outputDecision,
140 const SG::ReadHandleKey< CONTAINER >& objectKey,
141 const std::string& objLink,
142 int objIndex ) const {
145 ATH_MSG_DEBUG( "Adding object with link name '" << objLink << "'" );
146 outputDecision.setObjectLink( objLink,ElementLink< CONTAINER >( objectKey.key(),objIndex ) );
148 return StatusCode::SUCCESS;
151template< class CONTAINER >
152StatusCode TrigBjetHypoAlgBase::attachObjectLinkToDecisionsFromStoreGate( std::vector< TrigCompositeUtils::Decision* >& outputDecisions,
153 const SG::ReadHandleKey< CONTAINER >& objectKey,
154 const std::string& objLink,
155 int forcedIndex ) const {
157 for ( unsigned int index(0); index < outputDecisions.size(); index++ ) {
159 int objIndex = index;
160 // This is used for primary vertex (one single obj attached to every output decisions)
161 if ( forcedIndex >= 0 )
162 objIndex = forcedIndex;
164 // Get the correct decisions
165 TrigCompositeUtils::Decision* outputDecision = outputDecisions.at( index );
167 CHECK( attachObjectLinkToDecisionFromStoreGate( *outputDecision,
173 return StatusCode::SUCCESS;
177template< class CONTAINER >
178StatusCode TrigBjetHypoAlgBase::attachObjectLinkToDecisionFromEventView( const EventContext& context,
179 TrigCompositeUtils::Decision& outputDecision,
180 const SG::ReadHandleKey< CONTAINER >& objectKey,
181 const std::string& objLink,
182 int objIndex ) const {
184 // Check navigation is set properly
185 if ( not outputDecision.hasObjectCollectionLinks( TrigCompositeUtils::seedString() ) ) {
186 ATH_MSG_ERROR( "Trying to add object link with handle key '" << objectKey.key() << "' to output decision with link name '" << objLink <<"'" );
187 ATH_MSG_ERROR( "But output decision does not have link to seed collection!" );
188 return StatusCode::FAILURE;
191 // Get parent decision
192 const std::vector<ElementLink< TrigCompositeUtils::DecisionContainer >> mySeeds = outputDecision.objectCollectionLinks< TrigCompositeUtils::DecisionContainer >( TrigCompositeUtils::seedString() );
193 const TrigCompositeUtils::Decision inputDecision = **mySeeds.back();
195 // Get object link from view, taken from the input decision
196 ElementLink< ViewContainer > viewEL = inputDecision.objectLink< ViewContainer >( TrigCompositeUtils::viewString() );
197 ATH_CHECK( viewEL.isValid() );
199 SG::ReadHandle< CONTAINER > calObjectHandle = ViewHelper::makeHandle( *viewEL, objectKey, context );
200 ATH_CHECK( calObjectHandle.isValid() );
202 ElementLink< CONTAINER > objEL = ViewHelper::makeLink( *viewEL, calObjectHandle, objIndex );
203 ATH_CHECK( objEL.isValid() );
206 ATH_MSG_DEBUG( "Adding object with link name '" << objLink << "'" );
207 outputDecision.setObjectLink( objLink,objEL );
209 return StatusCode::SUCCESS;
212template< class CONTAINER >
213StatusCode TrigBjetHypoAlgBase::attachObjectLinkToDecisionsFromEventView( const EventContext& context,
214 std::vector< TrigCompositeUtils::Decision* >& outputDecisions,
215 const SG::ReadHandleKey< CONTAINER >& objectKey,
216 const std::string& objLink,
217 int forcedIndex ) const {
219 for ( unsigned int index(0); index<outputDecisions.size(); index++ ) {
221 int objIndex = index;
222 // This is used for primary vertex (one single obj attached to every output decisions)
223 if ( forcedIndex >= 0 )
224 objIndex = forcedIndex;
226 // Get the correct decision
227 TrigCompositeUtils::Decision* outputDecision = outputDecisions.at( index );
229 CHECK( attachObjectLinkToDecisionFromEventView( context,
236 return StatusCode::SUCCESS;
239template < class CONTAINER >
240StatusCode TrigBjetHypoAlgBase::attachObjectCollectionLinkToDecisionsFromEventView( const EventContext& context,
241 std::vector< TrigCompositeUtils::Decision* >& outputDecisions,
242 const SG::ReadHandleKey< CONTAINER >& objectKey,
243 const std::string& objLink ) const {
245 for ( TrigCompositeUtils::Decision* outputDecision : outputDecisions ) {
247 // Check navigation is set properly
248 if ( not outputDecision->hasObjectCollectionLinks( TrigCompositeUtils::seedString() ) ) {
249 ATH_MSG_ERROR( "Trying to add object collection link with handle key '" << objectKey.key() << "' to output decision with link name '" << objLink <<"'" );
250 ATH_MSG_ERROR( "But output decision does not have link to seed collection!" );
251 return StatusCode::FAILURE;
254 // Get corresponding input decision
255 const std::vector<ElementLink< TrigCompositeUtils::DecisionContainer >> mySeeds = outputDecision->objectCollectionLinks< TrigCompositeUtils::DecisionContainer >( TrigCompositeUtils::seedString() );
256 const TrigCompositeUtils::Decision* inputDecision = *mySeeds.back();
258 // Get object link from view, taken from the input decision
259 ElementLink< ViewContainer > viewEL = inputDecision->objectLink< ViewContainer >( TrigCompositeUtils::viewString() );
260 ATH_CHECK( viewEL.isValid() );
262 SG::ReadHandle< CONTAINER > calObjectHandle = ViewHelper::makeHandle( *viewEL,objectKey,context );
263 ATH_CHECK( calObjectHandle.isValid() );
265 // Create Collection to be linked
266 std::vector<ElementLink< CONTAINER >> objELs;
267 for ( unsigned int i(0); i<calObjectHandle->size(); i++ ) {
268 ElementLink< CONTAINER > objEL = ViewHelper::makeLink( *viewEL, calObjectHandle, i );
269 ATH_CHECK( objEL.isValid() );
270 objELs.push_back( objEL );
274 ATH_MSG_DEBUG( "Adding object collection with link name '" << objLink << "' and size " << objELs.size() );
275 outputDecision->addObjectCollectionLinks( objLink,objELs );
278 return StatusCode::SUCCESS;