ATLAS Offline Software
Loading...
Searching...
No Matches
ViewSubgraphAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "ViewSubgraphAlg.h"
7#include "Gaudi/Property.h"
9
10namespace AthViews {
11
13{
14 ATH_MSG_INFO ("Initializing " << name() << "...");
15
16 renounce( m_w_int ); // To test ViewDataVerifier
17 CHECK( m_w_int.initialize() );
18 CHECK( m_w_views.initialize() );
19 CHECK( m_r_views.initialize( SG::AllowEmpty ) );
20 CHECK( m_scheduler.retrieve() );
21
22 return StatusCode::SUCCESS;
23}
24
26{
27 ATH_MSG_INFO ("Finalizing " << name() << "...");
28
29 return StatusCode::SUCCESS;
30}
31
32StatusCode ViewSubgraphAlg::execute(const EventContext& ctx) const
33{
34 ATH_MSG_DEBUG ("Executing " << name() << "...");
35
36 //Start scheduler profiling
37 auto profileCallback = [this, slot=ctx.slot()]( IScheduler::OccupancySnapshot snap ) -> void {
38 std::string states = "";
39 for ( int const stateTotal : snap.states[slot] ) {
40 states += std::to_string( stateTotal ) + " ";
41 }
42 ATH_MSG_INFO( "Slot " << slot << " snapshot time " << snap.time.time_since_epoch().count() << " states: " << states );
43 };
44 m_scheduler->recordOccupancy( 0, std::move( profileCallback ) );
45
46 //Make a vector of dummy data to initialise the views
47 std::vector<int> viewData;
48 auto viewVector = std::make_unique<ViewContainer>();
49 for ( int viewIndex = 0; viewIndex < m_viewNumber; ++viewIndex )
50 {
51 viewData.push_back( ( viewIndex * 10 ) + 10 + ctx.evt() );
52 }
53
54 //Create the views and populate them
55 CHECK( ViewHelper::makeAndPopulate( m_viewBaseName, //Base name for all views to use
56 viewVector.get(), //Vector to store views
57 m_w_int, //A writehandlekey to use to access the views
58 ctx, //The context of this algorithm
59 viewData ) ); //Data to initialise each view - one view will be made per entry
60
61 //Attach parent views to existing views
62 if ( m_r_views.key() != "" )
63 {
64 SG::ReadHandle< ViewContainer > parentViewHandle( m_r_views, ctx );
65 if ( parentViewHandle->size() == viewVector->size() )
66 {
67 for ( unsigned int viewIndex = 0; viewIndex < parentViewHandle->size(); ++viewIndex )
68 {
69 ATH_MSG_INFO( "Linking view " << viewVector->at( viewIndex )->name() << " to parent " << parentViewHandle->at( viewIndex )->name() );
70 viewVector->at( viewIndex )->linkParent( parentViewHandle->at( viewIndex ) );
71 }
72 }
73 }
74
75 //Schedule the algorithms in views
76 CHECK( ViewHelper::scheduleViews( viewVector.get(), //View vector
77 m_viewNodeName, //Name of node to attach views to
78 ctx, //Context to attach the views to
79 m_scheduler.get() ) ); //ServiceHandle for the scheduler
80
81 //Store the collection of views
82 SG::WriteHandle< ViewContainer > outputViewHandle( m_w_views, ctx );
83 CHECK( outputViewHandle.record( std::move( viewVector ) ) );
84
85 return StatusCode::SUCCESS;
86}
87
88} //> end namespace AthViews
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
Handle class for recording to StoreGate.
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)
Gaudi::Property< int > m_viewNumber
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteHandleKey< ViewContainer > m_w_views
SG::ReadHandleKey< ViewContainer > m_r_views
Gaudi::Property< std::string > m_viewBaseName
Gaudi::Property< std::string > m_viewNodeName
virtual StatusCode finalize() override
ServiceHandle< IScheduler > m_scheduler
SG::WriteHandleKey< int > m_w_int
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
StatusCode scheduleViews(ViewContainer *viewVector, std::string const &nodeName, EventContext const &sourceContext, SmartIF< IScheduler > scheduler, bool reverseOrder=false)
Definition ViewHelper.h:85
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:25