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 , typename CONT >
SG::WriteDecorHandle< CONT, T > makeHandle (const SG::View *view, const SG::WriteDecorHandleKey< CONT > &dKey, const EventContext &context)
 
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 25 of file ViewHelper.h.

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

◆ makeHandle() [1/2]

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 259 of file ViewHelper.h.

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

◆ makeHandle() [2/2]

template<typename T , typename CONT >
SG::WriteDecorHandle<CONT, T> ViewHelper::makeHandle ( const SG::View view,
const SG::WriteDecorHandleKey< CONT > &  dKey,
const EventContext &  context 
)

Definition at line 273 of file ViewHelper.h.

274  {
275  SG::View* nview ATLAS_THREAD_SAFE = const_cast< SG::View* >( view ); //We need it until reading from const IProxyDict is supported
276 
277  auto handle = SG::makeHandle<T>(dKey, context );
278  if ( handle.setProxyDict( nview ).isFailure() ) {
279  //We ignore it because the handle will be invalid anyway if this call is unsuccessful
280  throw std::runtime_error( "Can't make WriteDecorHandle of key " + dKey.key() + " type " + ClassID_traits<T>::typeName() + " in view " + view->name() );
281  }
282  return handle;
283  }

◆ 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 291 of file ViewHelper.h.

292  {
293  auto proxy = view->proxy( handle.clid(), handle.key() );
294  if ( proxy == nullptr ) throw std::runtime_error( "Attempting to make element link with invalid key " + handle.key() );
295  return ElementLink<T>( proxy->name(), index );
296  }

◆ 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 242 of file ViewHelper.h.

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

◆ 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 67 of file ViewHelper.h.

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

◆ scheduleViews()

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

Definition at line 85 of file ViewHelper.h.

87  {
88  //Require the information of the extended context (should always be there, but check anyway)
89  if ( !Atlas::hasExtendedEventContext( sourceContext ) ) {
90  return StatusCode::FAILURE;
91  }
92  Atlas::ExtendedEventContext const extendedContext = Atlas::getExtendedEventContext( sourceContext );
93 
94  //Prevent view nesting - test if source context has view attached
95  if ( dynamic_cast< SG::View* >( extendedContext.proxy() ) ) {
96  return StatusCode::FAILURE;
97  }
98 
99  //Retrieve the scheduler
100  if ( !scheduler ) {
101  return StatusCode::FAILURE;
102  }
103 
104  if ( viewVector->empty() ) {
105 
106  //Disable the node if no views
107  return scheduler->scheduleEventView( &sourceContext, nodeName, 0 );
108  }
109  else {
110  if ( reverseOrder ) {
111  for ( auto iter = viewVector->rbegin(); iter != viewVector->rend(); ++iter ) {
112 
113  //Schedule each view in reverse (should make no difference, just a debugging tool)
114  if ( scheduleSingleView( *iter, nodeName, sourceContext,
115  extendedContext.conditionsRun(), scheduler ).isFailure() ) {
116  return StatusCode::FAILURE;
117  }
118  }
119  }
120  else {
121  for ( SG::View* view : *viewVector ) {
122 
123  //Schedule each view
124  if ( scheduleSingleView( view, nodeName, sourceContext,
125  extendedContext.conditionsRun(), scheduler ).isFailure() ) {
126  return StatusCode::FAILURE;
127  }
128  }
129  }
130  }
131 
132  return StatusCode::SUCCESS;
133  }
ViewContainer::rbegin
reverse_iterator rbegin()
Definition: View.h:184
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:185
ViewHelper::scheduleSingleView
StatusCode scheduleSingleView(SG::View *view, std::string const &nodeName, EventContext const &sourceContext, EventIDBase::number_type conditionsRun, SmartIF< IScheduler > scheduler)
Definition: ViewHelper.h:67
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:177
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
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:174
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:176
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