ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
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 ) {}

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() ) {
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
238  proxy->name(),
239  queryHandle.name(),
240  offset );
241  offset += queryHandle->size();
242  }
243 
244  return StatusCode::SUCCESS;
245  }

◆ 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:
beamspotman.r
def r
Definition: beamspotman.py:672
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:407
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:639
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:61
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:37
DataVector< T >
ViewHelper::ViewMerger::m_sg
StoreGateSvc * m_sg
Definition: ViewHelper.h:137
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
StoreGateSvc::remap
void remap(CLID clid, const TKEY &source, const TKEY &target, off_t index_offset)
Declare a remapping.
ViewHelper::ViewMerger::m_msg
MsgStream & m_msg
Definition: ViewHelper.h:138
DEBUG
#define DEBUG
Definition: page_access.h:11
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
SG::View
A "view" of the event store (IProxyDict).
Definition: View.h:46
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35