5#ifndef ATHVIEWS_VIEWHELPER_HH
6#define ATHVIEWS_VIEWHELPER_HH
8#include "GaudiKernel/SmartIF.h"
9#include "GaudiKernel/IScheduler.h"
10#include "GaudiKernel/EventContext.h"
11#include "GaudiKernel/StatusCode.h"
24 template<
typename T >
27 std::vector< T >
const& inputData,
bool const allowFallThrough =
true )
30 if ( viewNameRoot.find(
' ' ) != std::string::npos )
32 return StatusCode::FAILURE;
39 unsigned int const viewNumber = inputData.size();
40 for (
unsigned int viewIndex = 0; viewIndex < viewNumber; ++viewIndex )
43 SG::View * outputView =
new SG::View( viewNameRoot, viewIndex, allowFallThrough );
48 if ( !
sc.isSuccess() )
55 sc = populateHandle.
record( std::make_unique< T >( inputData[ viewIndex ] ) );
56 if ( !
sc.isSuccess() )
63 return StatusCode::SUCCESS;
68 EventIDBase::number_type conditionsRun, SmartIF<IScheduler> scheduler )
71 auto viewContext = std::make_unique< EventContext >( sourceContext );
72 if ( view->getROI().isValid() ) {
81 return scheduler->scheduleEventView( &sourceContext, nodeName, std::move( viewContext ) );
86 EventContext
const& sourceContext, SmartIF<IScheduler> scheduler,
bool reverseOrder =
false )
90 return StatusCode::FAILURE;
95 if (
dynamic_cast< SG::View*
>( extendedContext.proxy() ) ) {
96 return StatusCode::FAILURE;
101 return StatusCode::FAILURE;
104 if ( viewVector->
empty() ) {
107 return scheduler->scheduleEventView( &sourceContext, nodeName, 0 );
110 if ( reverseOrder ) {
111 for (
auto iter = viewVector->
rbegin(); iter != viewVector->
rend(); ++iter ) {
116 return StatusCode::FAILURE;
121 for (
SG::View* view : *viewVector ) {
126 return StatusCode::FAILURE;
132 return StatusCode::SUCCESS;
143 template<
typename T >
150 for (
const SG::View* inputView : viewVector )
156 if ( !
sc.isSuccess() )
158 m_msg << MSG::ERROR <<
"Failed to use view " << inputView->name() <<
" to read " << queryHandle.
key() <<
" resetting output" <<
endmsg;
164 T inputData = *queryHandle;
165 outputData.insert( outputData.end(), inputData.begin(), inputData.end() );
168 return StatusCode::SUCCESS;
174 template<
typename T >
178 if ( !outputData.getStore() )
180 m_msg << MSG::ERROR <<
"output data does not have the store" <<
endmsg;
181 return StatusCode::FAILURE;
191 unsigned int offset = outputData.
size();
192 for (
const SG::View* inputView : viewVector )
198 if ( !
sc.isSuccess() )
200 m_msg << MSG::ERROR <<
"Failed to use view " << inputView->name() <<
" to read " << queryHandle.
key() <<
endmsg;
205 if ( queryHandle->empty() )
207 if (
m_msg.level() <= MSG::DEBUG) {
208 m_msg << MSG::DEBUG <<
"Empty collection " << queryHandle.
key() <<
" in a view " << inputView->name() <<
endmsg;
214 for (
SG::auxid_t decor : queryHandle->getDecorIDs() ) {
216 m_msg << MSG::WARNING <<
"mergeViewCollection: skipped unlocked decoration " << queryHandle.
key() <<
"." <<
r.getName( decor ) <<
endmsg;
220 for (
const auto inputObject : *queryHandle.
cptr() )
223 T * outputObject =
new T();
225 *outputObject = *inputObject;
228 viewBookkeeper( *outputObject ) = inputView->getROI();
231 if (
m_msg.level() <= MSG::DEBUG) {
232 m_msg << MSG::DEBUG <<
"Copied " << queryHandle->size() <<
" objects from collection in view " << inputView->name() <<
endmsg;
236 auto proxy = inputView->proxy( queryHandle.
clid(), queryHandle.
key() );
241 offset += queryHandle->size();
244 return StatusCode::SUCCESS;
252 inline SG::View*
makeView(
const std::string& common_name,
int const unique_index = -1,
bool const allowFallThrough =
true )
255 if ( common_name.find(
' ' ) != std::string::npos )
260 return new SG::View( common_name, unique_index, allowFallThrough );
272 template<
typename KEY>
278 handle.setProxyDict( nview ).ignore();
292 template<
typename T,
typename CONT>
294 const EventContext& context )
299 handle.setProxyDict( nview ).ignore();
311 auto proxy = view->proxy( handle.
clid(), handle.
key() );
312 if ( proxy ==
nullptr )
throw std::runtime_error(
"Attempting to make element link with invalid key " + handle.
key() );
Base class for elements of a container that can have aux data.
std::vector< Identifier > ID
An STL vector of pointers that by default owns its pointed-to elements.
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
Handle class for recording to StoreGate.
DataVector< SG::View > ViewContainer
View container for recording in StoreGate.
#define ATLAS_THREAD_SAFE
EventIDBase::number_type conditionsRun() const
const_reverse_iterator rend() const noexcept
Return a const_reverse_iterator pointing at the beginning of the collection.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_reverse_iterator rbegin() const noexcept
Return a const_reverse_iterator pointing past the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
void clear()
Erase all the elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
ElementLink implementation for ROOT usage.
SG::Accessor< T, ALLOC > Accessor
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Property holding a SG store/key/clid from which a ReadHandle is made.
const_pointer_type cptr()
Dereference the pointer.
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
virtual StatusCode setProxyDict(IProxyDict *store)
Explicitly set the event store.
CLID clid() const
Return the class ID for the referenced object.
const std::string & name() const
Return the StoreGate ID for the referenced object.
A "view" of the event store (IProxyDict).
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Handle class for adding a decoration to an object.
Property holding a SG store/key/clid from which a WriteHandle is made.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
The Athena Transient Store API.
StatusCode mergeViewCollection(ViewContainer const &viewVector, SG::ReadHandleKey< T > const &queryKey, EventContext const &sourceContext, T &outputData)
StatusCode mergeViewCollection(ViewContainer const &viewVector, SG::ReadHandleKey< DataVector< T > > const &queryKey, EventContext const &sourceContext, DataVector< T > &outputData)
ViewMerger(StoreGateSvc *sg, MsgStream &msg)
void setExtendedEventContext(EventContext &ctx, ExtendedEventContext &&ectx)
Move an extended context into a context object.
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
bool hasExtendedEventContext(const EventContext &ctx)
Test whether a context object has an extended context installed.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
size_t auxid_t
Identifier for a particular aux data item.
StatusCode scheduleViews(ViewContainer *viewVector, std::string const &nodeName, EventContext const &sourceContext, SmartIF< IScheduler > scheduler, bool reverseOrder=false)
ElementLink< T > makeLink(const SG::View *view, const SG::ReadHandle< T > &handle, size_t index)
Create EL to a collection in view.
SG::View * makeView(const std::string &common_name, int const unique_index=-1, bool const allowFallThrough=true)
StatusCode scheduleSingleView(SG::View *view, std::string const &nodeName, EventContext const &sourceContext, EventIDBase::number_type conditionsRun, SmartIF< IScheduler > scheduler)
StatusCode makeAndPopulate(std::string const &viewNameRoot, ViewContainer *viewVector, SG::WriteHandleKey< T > const &populateKey, EventContext const &sourceContext, std::vector< T > const &inputData, bool const allowFallThrough=true)
auto makeHandle(const SG::View *view, const KEY &key, const EventContext &ctx)
Create a view handle from a handle key.
Default, invalid implementation of ClassID_traits.