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 KEY >
auto makeHandle (const SG::View *view, const KEY &key, const EventContext &ctx)
 Create a view handle from a handle key. More...
 
template<typename T , typename CONT >
SG::WriteDecorHandle< CONT, T > makeHandle (const SG::View *view, const SG::WriteDecorHandleKey< CONT > &dKey, const EventContext &context)
 Create WriteDecorHandle for given view and WriteDecorHandleKey. 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 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 KEY >
auto ViewHelper::makeHandle ( const SG::View view,
const KEY &  key,
const EventContext &  ctx 
)

Create a view handle from a handle key.

Template Parameters
KEYKey type
Parameters
viewView object
keyVarHandleKey
ctxEventContext
Returns
Handle corresponding to the key type (can be invalid)

Definition at line 273 of file ViewHelper.h.

274  {
275  // setProxyDict only supports non-const stores
276  SG::View* nview ATLAS_THREAD_SAFE = const_cast< SG::View* >( view );
277  auto handle = SG::makeHandle( key, ctx );
278  handle.setProxyDict( nview ).ignore(); // can never fail
279  return handle;
280  }

◆ 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 
)

Create WriteDecorHandle for given view and WriteDecorHandleKey.

Template Parameters
TDecoration type (e.g. float)
CONTContainer type
Parameters
viewView object
dKeyWriteDecorHandleKey for the decoration to be written through the view
ctxEventContext
Returns
WriteDecorHandleKey (can be invalid)

Definition at line 293 of file ViewHelper.h.

295  {
296  // setProxyDict only supports non-const stores
297  SG::View* nview ATLAS_THREAD_SAFE = const_cast< SG::View* >( view );
298  auto handle = SG::makeHandle<T>(dKey, context );
299  handle.setProxyDict( nview ).ignore(); // can never fail
300  return handle;
301  }

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

310  {
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() );
313  return ElementLink<T>( proxy->name(), index );
314  }

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

253  {
254  //Check for spaces in the name
255  if ( common_name.find( ' ' ) != std::string::npos )
256  {
257  return nullptr;
258  }
259 
260  return new SG::View( common_name, unique_index, allowFallThrough );
261  }

◆ 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  }
createLinkingScheme.iter
iter
Definition: createLinkingScheme.py:62
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:407
DataVector::rend
const_reverse_iterator rend() const noexcept
Return a const_reverse_iterator pointing at the beginning of the collection.
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
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
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
Atlas::getExtendedEventContext
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
Definition: ExtendedEventContext.cxx:32
Atlas::ExtendedEventContext
Definition: ExtendedEventContext.h:23
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DataVector::rbegin
const_reverse_iterator rbegin() const noexcept
Return a const_reverse_iterator pointing past the end of the collection.
DataVector::clear
void clear()
Erase all the elements in the collection.
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
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
Atlas::setExtendedEventContext
void setExtendedEventContext(EventContext &ctx, ExtendedEventContext &&ectx)
Move an extended context into a context object.
Definition: ExtendedEventContext.cxx:70
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
drawFromPickle.view
view
Definition: drawFromPickle.py:294
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37