ATLAS Offline Software
ViewSubgraphAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "ViewSubgraphAlg.h"
6 #include "AthViews/ViewHelper.h"
7 #include "Gaudi/Property.h"
9 
10 namespace AthViews {
11 
12 ViewSubgraphAlg::ViewSubgraphAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
13  AthAlgorithm( name, pSvcLocator )
14 {
15 }
16 
18 {
19 }
20 
22 {
23  ATH_MSG_INFO ("Initializing " << name() << "...");
24 
25  renounce( m_w_int ); // To test ViewDataVerifier
29  CHECK( m_scheduler.retrieve() );
30 
31  return StatusCode::SUCCESS;
32 }
33 
35 {
36  ATH_MSG_INFO ("Finalizing " << name() << "...");
37 
38  return StatusCode::SUCCESS;
39 }
40 
42 {
43  ATH_MSG_DEBUG ("Executing " << name() << "...");
44 
45  const EventContext& ctx = getContext();
46 
47  //Start scheduler profiling
48  auto profileCallback = [this, slot=ctx.slot()]( IScheduler::OccupancySnapshot snap ) -> void {
49  std::string states = "";
50  for ( int const stateTotal : snap.states[slot] ) {
51  states += std::to_string( stateTotal ) + " ";
52  }
53  ATH_MSG_INFO( "Slot " << slot << " snapshot time " << snap.time.time_since_epoch().count() << " states: " << states );
54  };
55  m_scheduler->recordOccupancy( 0, std::move( profileCallback ) );
56 
57  //Make a vector of dummy data to initialise the views
58  std::vector<int> viewData;
59  auto viewVector = std::make_unique<ViewContainer>();
60  for ( int viewIndex = 0; viewIndex < m_viewNumber; ++viewIndex )
61  {
62  viewData.push_back( ( viewIndex * 10 ) + 10 + ctx.evt() );
63  }
64 
65  //Create the views and populate them
66  CHECK( ViewHelper::makeAndPopulate( m_viewBaseName, //Base name for all views to use
67  viewVector.get(), //Vector to store views
68  m_w_int, //A writehandlekey to use to access the views
69  ctx, //The context of this algorithm
70  viewData ) ); //Data to initialise each view - one view will be made per entry
71 
72  //Attach parent views to existing views
73  if ( m_r_views.key() != "" )
74  {
75  SG::ReadHandle< ViewContainer > parentViewHandle( m_r_views, ctx );
76  if ( parentViewHandle->size() == viewVector->size() )
77  {
78  for ( unsigned int viewIndex = 0; viewIndex < parentViewHandle->size(); ++viewIndex )
79  {
80  ATH_MSG_INFO( "Linking view " << viewVector->at( viewIndex )->name() << " to parent " << parentViewHandle->at( viewIndex )->name() );
81  viewVector->at( viewIndex )->linkParent( parentViewHandle->at( viewIndex ) );
82  }
83  }
84  }
85 
86  //Schedule the algorithms in views
87  CHECK( ViewHelper::scheduleViews( viewVector.get(), //View vector
88  m_viewNodeName, //Name of node to attach views to
89  ctx, //Context to attach the views to
90  m_scheduler.get() ) ); //ServiceHandle for the scheduler
91 
92  //Store the collection of views
93  SG::WriteHandle< ViewContainer > outputViewHandle( m_w_views, ctx );
94  CHECK( outputViewHandle.record( std::move( viewVector ) ) );
95 
96  return StatusCode::SUCCESS;
97 }
98 
99 } //> end namespace AthViews
AthViews::ViewSubgraphAlg::m_scheduler
ServiceHandle< IScheduler > m_scheduler
Containers.
Definition: ViewSubgraphAlg.h:49
AthViews::ViewSubgraphAlg::m_viewNodeName
Gaudi::Property< std::string > m_viewNodeName
Definition: ViewSubgraphAlg.h:54
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthViews::ViewSubgraphAlg::m_viewNumber
Gaudi::Property< int > m_viewNumber
Definition: ViewSubgraphAlg.h:55
ViewContainer::at
const_reference at(size_t pos) const
Definition: View.h:190
AthViews::ViewSubgraphAlg::finalize
virtual StatusCode finalize()
Definition: ViewSubgraphAlg.cxx:34
AthCommonDataStore< AthCommonMsg< Algorithm > >::renounce
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
Definition: AthCommonDataStore.h:380
AthViews::ViewSubgraphAlg::ViewSubgraphAlg
ViewSubgraphAlg()
Default constructor:
AthViews::ViewSubgraphAlg::initialize
virtual StatusCode initialize()
Definition: ViewSubgraphAlg.cxx:21
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
AthViews::ViewSubgraphAlg::execute
virtual StatusCode execute()
Definition: ViewSubgraphAlg.cxx:41
ViewHelper.h
AthViews::ViewSubgraphAlg::m_viewBaseName
Gaudi::Property< std::string > m_viewBaseName
Definition: ViewSubgraphAlg.h:53
WriteHandle.h
Handle class for recording to StoreGate.
AthViews::ViewSubgraphAlg::m_w_int
SG::WriteHandleKey< int > m_w_int
Definition: ViewSubgraphAlg.h:52
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
urldecode::states
states
Definition: urldecode.h:39
ViewHelper::scheduleViews
StatusCode scheduleViews(ViewContainer *viewVector, std::string const &nodeName, EventContext const &sourceContext, SmartIF< IScheduler > scheduler, bool reverseOrder=false)
Definition: ViewHelper.h:84
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthViews::ViewSubgraphAlg::m_r_views
SG::ReadHandleKey< ViewContainer > m_r_views
Definition: ViewSubgraphAlg.h:51
AthAlgorithm
Definition: AthAlgorithm.h:47
ViewHelper::makeAndPopulate
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)
Definition: ViewHelper.h:24
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
ViewContainer::size
size_t size() const
Definition: View.h:178
AthViews
Definition: ViewDataVerifier.cxx:18
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
AthViews::ViewSubgraphAlg::~ViewSubgraphAlg
virtual ~ViewSubgraphAlg()
Destructor:
Definition: ViewSubgraphAlg.cxx:17
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
AthViews::ViewSubgraphAlg::m_w_views
SG::WriteHandleKey< ViewContainer > m_w_views
Definition: ViewSubgraphAlg.h:50
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
ViewSubgraphAlg.h