ATLAS Offline Software
Loading...
Searching...
No Matches
ViewHelper::ViewMerger Class Reference

#include <ViewHelper.h>

Collaboration diagram for ViewHelper::ViewMerger:

Public Member Functions

 ViewMerger (StoreGateSvc *sg, MsgStream &msg)
template<typename T>
StatusCode mergeViewCollection (ViewContainer const &viewVector, SG::ReadHandleKey< T > const &queryKey, EventContext const &sourceContext, T &outputData)
template<typename T>
StatusCode mergeViewCollection (ViewContainer const &viewVector, SG::ReadHandleKey< DataVector< T > > const &queryKey, EventContext const &sourceContext, DataVector< T > &outputData)

Private Attributes

StoreGateSvcm_sg
MsgStream & m_msg

Detailed Description

Definition at line 135 of file ViewHelper.h.

Constructor & Destructor Documentation

◆ ViewMerger()

ViewHelper::ViewMerger::ViewMerger ( StoreGateSvc * sg,
MsgStream & msg )
inline

Definition at line 140 of file ViewHelper.h.

140: m_sg( sg ), m_msg( msg ) {}
StoreGateSvc * m_sg
Definition ViewHelper.h:137
MsgStream & msg
Definition testRead.cxx:32

Member Function Documentation

◆ mergeViewCollection() [1/2]

template<typename T>
StatusCode ViewHelper::ViewMerger::mergeViewCollection ( ViewContainer const & viewVector,
SG::ReadHandleKey< DataVector< T > > const & queryKey,
EventContext const & sourceContext,
DataVector< T > & outputData )
inline

Definition at line 175 of file ViewHelper.h.

176 {
177 //Check that there's a non-const aux store for output bookkeeping
178 if ( !outputData.getStore() )
179 {
180 m_msg << MSG::ERROR << "output data does not have the store" << endmsg;
181 return StatusCode::FAILURE;
182 }
183
184 //Make ReadHandle to access views
185 SG::ReadHandle< DataVector< T > > queryHandle( queryKey, sourceContext );
186
187 //Make accessor for bookkeeping
189
190 //Loop over all views
191 unsigned int offset = outputData.size(); //allow for existing objects in the container
192 for ( const SG::View* inputView : viewVector )
193 {
194 // setProxyDict only supports non-const stores
195 SG::View* nc_inputView ATLAS_THREAD_SAFE = const_cast< SG::View* >( inputView );
196 //Attach the handle to the view
197 StatusCode sc = queryHandle.setProxyDict( nc_inputView );
198 if ( !sc.isSuccess() )
199 {
200 m_msg << MSG::ERROR << "Failed to use view " << inputView->name() << " to read " << queryHandle.key() << endmsg;
201 return sc;
202 }
203
204 //Nothing to do for empty collections
205 if ( queryHandle->empty() )
206 {
207 if (m_msg.level() <= MSG::DEBUG) {
208 m_msg << MSG::DEBUG << "Empty collection " << queryHandle.key() <<" in a view " << inputView->name() <<endmsg;
209 continue;
210 }
211 }
212
213 // Warn about unlocked decorations that won't get copied.
214 for ( SG::auxid_t decor : queryHandle->getDecorIDs() ) {
215 SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
216 m_msg << MSG::WARNING << "mergeViewCollection: skipped unlocked decoration " << queryHandle.key() << "." << r.getName( decor ) << endmsg;
217 }
218
219 //Merge the data
220 for ( const auto inputObject : *queryHandle.cptr() )
221 {
222 //Element-wise copy data (looks a bit weird, but necessary for xAOD objects)
223 T * outputObject = new T();
224 outputData.push_back( outputObject );
225 *outputObject = *inputObject;
226
227 //Add aux data for bookkeeping
228 viewBookkeeper( *outputObject ) = inputView->getROI();
229 }
230
231 if (m_msg.level() <= MSG::DEBUG) {
232 m_msg << MSG::DEBUG << "Copied " << queryHandle->size() << " objects from collection in view " << inputView->name() << endmsg;
233 }
234
235 //Declare remapping
236 auto proxy = inputView->proxy( queryHandle.clid(), queryHandle.key() ); //shouldn't need to test validity since queryHandle already used
237 m_sg->remap( ClassID_traits< DataVector< T > >::ID(),
238 proxy->name(),
239 queryHandle.name(),
240 offset );
241 offset += queryHandle->size();
242 }
243
244 return StatusCode::SUCCESS;
245 }
#define endmsg
std::vector< Identifier > ID
static Double_t sc
#define ATLAS_THREAD_SAFE
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
static AuxTypeRegistry & instance()
Return the singleton registry instance.
int r
Definition globals.cxx:22
::StatusCode StatusCode
StatusCode definition for legacy code.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
unsigned long long T

◆ mergeViewCollection() [2/2]

template<typename T>
StatusCode ViewHelper::ViewMerger::mergeViewCollection ( ViewContainer const & viewVector,
SG::ReadHandleKey< T > const & queryKey,
EventContext const & sourceContext,
T & outputData )
inline

Definition at line 144 of file ViewHelper.h.

145 {
146 //Make a ReadHandle to use
147 SG::ReadHandle<T> queryHandle( queryKey, sourceContext );
148
149 //Loop over all views
150 for ( const SG::View* inputView : viewVector )
151 {
152 // setProxyDict only supports non-const stores
153 SG::View* nc_inputView ATLAS_THREAD_SAFE = const_cast< SG::View* >( inputView );
154 //Attach the handle to the view
155 StatusCode sc = queryHandle.setProxyDict( nc_inputView );
156 if ( !sc.isSuccess() )
157 {
158 m_msg << MSG::ERROR <<"Failed to use view " << inputView->name() << " to read " << queryHandle.key() << " resetting output" << endmsg;
159 outputData.clear();
160 return sc;
161 }
162
163 //Merge the data
164 T inputData = *queryHandle;
165 outputData.insert( outputData.end(), inputData.begin(), inputData.end() );
166 }
167
168 return StatusCode::SUCCESS;
169 }

Member Data Documentation

◆ m_msg

MsgStream& ViewHelper::ViewMerger::m_msg
private

Definition at line 138 of file ViewHelper.h.

◆ m_sg

StoreGateSvc* ViewHelper::ViewMerger::m_sg
private

Definition at line 137 of file ViewHelper.h.


The documentation for this class was generated from the following file: