ATLAS Offline Software
Classes | Functions
ViewHelper Namespace Reference

Classes

class  ViewMerger
 

Functions

template<typename T >
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)
 
StatusCode scheduleSingleView (SG::View *view, std::string const &nodeName, EventContext const &sourceContext, EventIDBase::number_type conditionsRun, SmartIF< IScheduler > scheduler)
 
StatusCode scheduleViews (ViewContainer *viewVector, std::string const &nodeName, EventContext const &sourceContext, SmartIF< IScheduler > scheduler, bool reverseOrder=false)
 
SG::ViewmakeView (const std::string &common_name, int const unique_index=-1, bool const allowFallThrough=true)
 
template<typename T >
SG::ReadHandle< T > makeHandle (const SG::View *view, const SG::ReadHandleKey< T > &rhKey, const EventContext &context)
 navigate from the TrigComposite to nearest view and fetch object from it More...
 
template<typename T >
ElementLink< T > makeLink (const SG::View *view, const SG::ReadHandle< T > &handle, size_t index)
 Create EL to a collection in view. More...
 

Function Documentation

◆ makeAndPopulate()

template<typename T >
StatusCode ViewHelper::makeAndPopulate ( std::string const viewNameRoot,
ViewContainer viewVector,
SG::WriteHandleKey< T > const populateKey,
EventContext const sourceContext,
std::vector< T > const inputData,
bool const  allowFallThrough = true 
)
inline

Definition at line 24 of file ViewHelper.h.

27  {
28  //Check for spaces in the name
29  if ( viewNameRoot.find( ' ' ) != std::string::npos )
30  {
31  return StatusCode::FAILURE;
32  }
33 
34  //Make a WriteHandle to use
35  SG::WriteHandle<T> populateHandle( populateKey, sourceContext );
36 
37  //Loop over all input data
38  unsigned int const viewNumber = inputData.size();
39  for ( unsigned int viewIndex = 0; viewIndex < viewNumber; ++viewIndex )
40  {
41  //Create view
42  SG::View * outputView = new SG::View( viewNameRoot, viewIndex, allowFallThrough );
43  viewVector->push_back( outputView );
44 
45  //Attach a handle to the view
46  StatusCode sc = populateHandle.setProxyDict( outputView );
47  if ( !sc.isSuccess() )
48  {
49  viewVector->clear();
50  return sc;
51  }
52 
53  //Populate the view
54  sc = populateHandle.record( std::make_unique< T >( inputData[ viewIndex ] ) );
55  if ( !sc.isSuccess() )
56  {
57  viewVector->clear();
58  return sc;
59  }
60  }
61 
62  return StatusCode::SUCCESS;
63  }

◆ makeHandle()

template<typename T >
SG::ReadHandle<T> ViewHelper::makeHandle ( const SG::View view,
const SG::ReadHandleKey< T > &  rhKey,
const EventContext &  context 
)

navigate from the TrigComposite to nearest view and fetch object from it

Returns
handle (can be invalid)

Definition at line 258 of file ViewHelper.h.

259  {
260  SG::View* nview ATLAS_THREAD_SAFE = const_cast< SG::View* >( view ); //We need it until reading from const IProxyDict is supported
261 
262  auto handle = SG::makeHandle( rhKey, context );
263  if ( handle.setProxyDict( nview ).isFailure() ) {
264  //We ignore it because the handle will be invalid anyway if this call is unsuccessful
265  throw std::runtime_error( "Can't make ReadHandle of key " + rhKey.key() + " type " + ClassID_traits<T>::typeName() + " in view " + view->name() );
266  }
267  return handle;
268  }

◆ makeLink()

template<typename T >
ElementLink<T> ViewHelper::makeLink ( const SG::View view,
const SG::ReadHandle< T > &  handle,
size_t  index 
)

Create EL to a collection in view.

Warning
no checks are made as to the validity of the created EL

Definition at line 276 of file ViewHelper.h.

277  {
278  auto proxy = view->proxy( handle.clid(), handle.key() );
279  if ( proxy == nullptr ) throw std::runtime_error( "Attempting to make element link with invalid key " + handle.key() );
280  return ElementLink<T>( proxy->name(), index );
281  }

◆ makeView()

SG::View* ViewHelper::makeView ( const std::string &  common_name,
int const  unique_index = -1,
bool const  allowFallThrough = true 
)
inline
  • unique_index - gets appended to the view name if >= 0

Definition at line 241 of file ViewHelper.h.

242  {
243  //Check for spaces in the name
244  if ( common_name.find( ' ' ) != std::string::npos )
245  {
246  return nullptr;
247  }
248 
249  return new SG::View( common_name, unique_index, allowFallThrough );
250  }

◆ scheduleSingleView()

StatusCode ViewHelper::scheduleSingleView ( SG::View view,
std::string const nodeName,
EventContext const sourceContext,
EventIDBase::number_type  conditionsRun,
SmartIF< IScheduler >  scheduler 
)
inline

Definition at line 66 of file ViewHelper.h.

68  {
69  //Make a new context with the view attached
70  auto viewContext = std::make_unique< EventContext >( sourceContext );
71  if ( view->getROI().isValid() ) {
72  Atlas::setExtendedEventContext( *viewContext,
73  Atlas::ExtendedEventContext( view, conditionsRun, *view->getROI() ) );
74  } else {
75  Atlas::setExtendedEventContext( *viewContext,
76  Atlas::ExtendedEventContext( view, conditionsRun ) );
77  }
78 
79  //Attach the view to the named node
80  return scheduler->scheduleEventView( &sourceContext, nodeName, std::move( viewContext ) );
81  }

◆ scheduleViews()

StatusCode ViewHelper::scheduleViews ( ViewContainer viewVector,
std::string const nodeName,
EventContext const sourceContext,
SmartIF< IScheduler >  scheduler,
bool  reverseOrder = false 
)
inline

Definition at line 84 of file ViewHelper.h.

86  {
87  //Require the information of the extended context (should always be there, but check anyway)
88  if ( !Atlas::hasExtendedEventContext( sourceContext ) ) {
89  return StatusCode::FAILURE;
90  }
91  Atlas::ExtendedEventContext const extendedContext = Atlas::getExtendedEventContext( sourceContext );
92 
93  //Prevent view nesting - test if source context has view attached
94  if ( dynamic_cast< SG::View* >( extendedContext.proxy() ) ) {
95  return StatusCode::FAILURE;
96  }
97 
98  //Retrieve the scheduler
99  if ( !scheduler ) {
100  return StatusCode::FAILURE;
101  }
102 
103  if ( viewVector->empty() ) {
104 
105  //Disable the node if no views
106  return scheduler->scheduleEventView( &sourceContext, nodeName, 0 );
107  }
108  else {
109  if ( reverseOrder ) {
110  for ( auto iter = viewVector->rbegin(); iter != viewVector->rend(); ++iter ) {
111 
112  //Schedule each view in reverse (should make no difference, just a debugging tool)
113  if ( scheduleSingleView( *iter, nodeName, sourceContext,
114  extendedContext.conditionsRun(), scheduler ).isFailure() ) {
115  return StatusCode::FAILURE;
116  }
117  }
118  }
119  else {
120  for ( SG::View* view : *viewVector ) {
121 
122  //Schedule each view
123  if ( scheduleSingleView( view, nodeName, sourceContext,
124  extendedContext.conditionsRun(), scheduler ).isFailure() ) {
125  return StatusCode::FAILURE;
126  }
127  }
128  }
129  }
130 
131  return StatusCode::SUCCESS;
132  }
ViewContainer::rbegin
reverse_iterator rbegin()
Definition: View.h:187
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
Atlas::ExtendedEventContext::conditionsRun
EventIDBase::number_type conditionsRun() const
Definition: ExtendedEventContext.h:38
index
Definition: index.py:1
Atlas::hasExtendedEventContext
bool hasExtendedEventContext(const EventContext &ctx)
Test whether a context object has an extended context installed.
Definition: ExtendedEventContext.cxx:23
ViewContainer::rend
reverse_iterator rend()
Definition: View.h:188
ViewHelper::scheduleSingleView
StatusCode scheduleSingleView(SG::View *view, std::string const &nodeName, EventContext const &sourceContext, EventIDBase::number_type conditionsRun, SmartIF< IScheduler > scheduler)
Definition: ViewHelper.h:66
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
ViewContainer::clear
void clear()
Definition: View.h:180
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
Atlas::getExtendedEventContext
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
Definition: ExtendedEventContext.cxx:32
ViewContainer::push_back
void push_back(SG::View *ptr)
Definition: View.h:177
Atlas::ExtendedEventContext
Definition: ExtendedEventContext.h:23
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:40
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
ViewContainer::empty
bool empty() const
Definition: View.h:179
SG::View
Definition: View.h:25
Atlas::setExtendedEventContext
void setExtendedEventContext(EventContext &ctx, ExtendedEventContext &&ectx)
Move an extended context into a context object.
Definition: ExtendedEventContext.cxx:50
drawFromPickle.view
view
Definition: drawFromPickle.py:294