ATLAS Offline Software
Loading...
Searching...
No Matches
TrigBjetHypoAlgBase.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "AthViews/ViewHelper.h"
6
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 {
12
13 ElementLink< ViewContainer > viewEL = prevDecision->objectLink< ViewContainer >( TrigCompositeUtils::viewString() );
14 ATH_CHECK( viewEL.isValid() );
15 ATH_MSG_DEBUG( "Retrieved View" );
16
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() );
20
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 );
25 }
26
27 return StatusCode::SUCCESS;
28}
29
30template < class CONTAINER >
31StatusCode TrigBjetHypoAlgBase::retrieveObjectFromNavigation( const EventContext& context,
32 const std::string& linkName,
33 ElementLink< CONTAINER >& EL,
34 const TrigCompositeUtils::Decision* prevDecision ) const {
35
36 const std::vector< TrigCompositeUtils::LinkInfo< CONTAINER > > myObj =
37 TrigCompositeUtils::findLinks< CONTAINER >(context, prevDecision, linkName.c_str(), TrigDefs::lastFeatureOfType);
38
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;
42 }
43
44 ATH_CHECK( myObj.at(0).isValid() );
45 EL = myObj.at(0).link;
46
47 return StatusCode::SUCCESS;
48}
49
50template < class CONTAINER >
51StatusCode TrigBjetHypoAlgBase::retrieveCollectionFromNavigation( const EventContext& context,
52 const std::string& linkName,
53 ElementLinkVector< CONTAINER >& objELs,
54 const TrigCompositeUtils::DecisionContainer* prevDecisionContainer ) const {
55
56 for ( const TrigCompositeUtils::Decision *prevDecision : *prevDecisionContainer ) {
57 ElementLink< CONTAINER > objEL;
58 CHECK( retrieveObjectFromNavigation( context, linkName, objEL, prevDecision ) );
59 objELs.push_back( objEL ) ;
60 }
61
62 return StatusCode::SUCCESS;
63}
64
65
66
67
68
69
70
71
72template < class CONTAINER >
73StatusCode TrigBjetHypoAlgBase::retrieveObjectFromStoreGate( const EventContext& context,
74 ElementLinkVector< CONTAINER >& ELs,
75 const SG::ReadHandleKey< CONTAINER >& inputKey ) const {
76
77 ATH_MSG_DEBUG( "Retrieving object from StoreGate from " << inputKey.key() );
78
79 SG::ReadHandle< CONTAINER > ContainerHandle = SG::makeHandle( inputKey,context );
80 CHECK( ContainerHandle.isValid() );
81 const CONTAINER *Collection = ContainerHandle.get();
82
83 for (const auto* obj : *Collection) {
84 ElementLink< CONTAINER > Link = ElementLink< CONTAINER >(*Collection, obj->index());
85 ELs.push_back( Link );
86 }
87
88 return StatusCode::SUCCESS;
89}
90
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 {
96
97 ATH_MSG_DEBUG( "Retrieving object from Event View from " << inputKey.key() );
98
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;
101
102 for ( const TrigCompositeUtils::Decision* previousDecision: *prevDevisionContainer ) {
103 // get View
104 ElementLink< ViewContainer > viewEL = previousDecision->objectLink< ViewContainer >( TrigCompositeUtils::viewString() );
105 ATH_CHECK( viewEL.isValid() );
106 ATH_MSG_DEBUG( "Retrieved View" );
107
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!" );
112 alreadyUsed = true;
113 break;
114 }
115 }
116 if ( alreadyUsed ) continue;
117
118 readViews.push_back( viewEL );
119
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() );
123
124 size_t Counter = 0;
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() );
128 ELs.push_back( EL );
129 }
130 }
131
132 return StatusCode::SUCCESS;
133}
134
135
136
137
138template< class CONTAINER >
139StatusCode TrigBjetHypoAlgBase::attachObjectLinkToDecisionFromStoreGate( TrigCompositeUtils::Decision& outputDecision,
140 const SG::ReadHandleKey< CONTAINER >& objectKey,
141 const std::string& objLink,
142 int objIndex ) const {
143
144 // Do the linking
145 ATH_MSG_DEBUG( "Adding object with link name '" << objLink << "'" );
146 outputDecision.setObjectLink( objLink,ElementLink< CONTAINER >( objectKey.key(),objIndex ) );
147
148 return StatusCode::SUCCESS;
149}
150
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 {
156
157 for ( unsigned int index(0); index < outputDecisions.size(); index++ ) {
158
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;
163
164 // Get the correct decisions
165 TrigCompositeUtils::Decision* outputDecision = outputDecisions.at( index );
166
167 CHECK( attachObjectLinkToDecisionFromStoreGate( *outputDecision,
168 objectKey,
169 objLink,
170 objIndex ) );
171 }
172
173 return StatusCode::SUCCESS;
174}
175
176
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 {
183
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;
189 }
190
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();
194
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() );
198
199 SG::ReadHandle< CONTAINER > calObjectHandle = ViewHelper::makeHandle( *viewEL, objectKey, context );
200 ATH_CHECK( calObjectHandle.isValid() );
201
202 ElementLink< CONTAINER > objEL = ViewHelper::makeLink( *viewEL, calObjectHandle, objIndex );
203 ATH_CHECK( objEL.isValid() );
204
205 // Do the linking
206 ATH_MSG_DEBUG( "Adding object with link name '" << objLink << "'" );
207 outputDecision.setObjectLink( objLink,objEL );
208
209 return StatusCode::SUCCESS;
210}
211
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 {
218
219 for ( unsigned int index(0); index<outputDecisions.size(); index++ ) {
220
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;
225
226 // Get the correct decision
227 TrigCompositeUtils::Decision* outputDecision = outputDecisions.at( index );
228
229 CHECK( attachObjectLinkToDecisionFromEventView( context,
230 *outputDecision,
231 objectKey,
232 objLink,
233 objIndex ) );
234 }
235
236 return StatusCode::SUCCESS;
237}
238
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 {
244
245 for ( TrigCompositeUtils::Decision* outputDecision : outputDecisions ) {
246
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;
252 }
253
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();
257
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() );
261
262 SG::ReadHandle< CONTAINER > calObjectHandle = ViewHelper::makeHandle( *viewEL,objectKey,context );
263 ATH_CHECK( calObjectHandle.isValid() );
264
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 );
271 }
272
273 // Do the linking
274 ATH_MSG_DEBUG( "Adding object collection with link name '" << objLink << "' and size " << objELs.size() );
275 outputDecision->addObjectCollectionLinks( objLink,objELs );
276 }
277
278 return StatusCode::SUCCESS;
279}
280
281
282
283