| The Gaudi Framework v32r1 (f65d50dc)

ViewTester.cpp
Go to the documentation of this file.
1 #include "ViewTester.h"
2 #include "GaudiKernel/ThreadLocalContext.h"
3
4 DECLARE_COMPONENT( Test::ViewTester )
5
6 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
7 #define DEBUG_MSG ON_DEBUG debug()
8
9 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
10 #define VERBOSE_MSG ON_VERBOSE verbose()
11
12 using namespace Test;
13
14 //------------------------------------------------------------------------------
15
16 ViewTester::ViewTester( const std::string& name, // the algorithm instance name
17 ISvcLocator* pSvc )
18 : GaudiAlgorithm( name, pSvc ) {}
19
20 StatusCode ViewTester::initialize() {
21 auto sc = GaudiAlgorithm::initialize();
22 if ( !sc ) return sc;
23
24 // This is a bit ugly. There is no way to declare a vector of DataObjectHandles, so
25 // we need to wait until initialize when we've read in the input and output key
26 // properties, and know their size, and then turn them
27 // into Handles and register them with the framework by calling declareProperty. We
28 // could call declareInput/declareOutput on them too.
29
30 int i = 0;
31 for ( auto k : m_inpKeys ) {
32 DEBUG_MSG << "adding input key " << k << endmsg;
33 m_inputHandles.emplace_back( std::make_unique<DataObjectHandle<DataObject>>( k, Gaudi::DataHandle::Reader, this ) );
34 declareProperty( "dummy_in_" + std::to_string( i ), *( m_inputHandles.back() ) );
35 i++;
36 }
37
38 i = 0;
39 for ( auto k : m_outKeys ) {
40 DEBUG_MSG << "adding output key " << k << endmsg;
41 m_outputHandles.emplace_back(
42 std::make_unique<DataObjectHandle<DataObject>>( k, Gaudi::DataHandle::Writer, this ) );
43 declareProperty( "dummy_out_" + std::to_string( i ), *( m_outputHandles.back() ) );
44 i++;
45 }
46
47 return sc;
48 }
49
50 //------------------------------------------------------------------------------
51
52 StatusCode ViewTester::execute() // the execution of the algorithm
53 {
54 SmartIF<IScheduler> scheduler( serviceLocator()->service( "AvalancheSchedulerSvc" ) );
55 if ( !scheduler ) {
56 fatal() << "Unable to load AvalancheSchedulerSvc" << endmsg;
57 return StatusCode::FAILURE;
58 }
59
60 const auto& context = getContext();
61
62 // Report if currently running in a view
63 if ( !context.hasExtension<std::string>() )
64 info() << "Running in whole event context" << endmsg;
65 else
66 info() << "Running in view " << context.getExtension<std::string>() << endmsg;
67
68 // If a node name is specified (and not already in view), do view scheduling
69 if ( !m_viewNodeName.empty() && !context.hasExtension<std::string>() ) {
70 if ( m_viewNumber > 0 ) {
71 // Make views
72 for ( unsigned int viewIndex = 0; viewIndex < m_viewNumber; ++viewIndex ) {
73 // Make event context for the view
74 auto viewContext = std::make_unique<EventContext>( context.evt(), context.slot() );
75 const std::string& viewName = viewContext->setExtension( m_baseViewName + std::to_string( viewIndex ) );
76
77 StatusCode sc = scheduler->scheduleEventView( &context, m_viewNodeName, std::move( viewContext ) );
78 if ( sc.isSuccess() )
79 info() << "Attached view " << viewName << " to node " << m_viewNodeName.toString() << " for " << context
80 << endmsg;
81 else
82 error() << "Unable to attach view " << viewName << " to node " << m_viewNodeName.toString() << " for "
83 << context << endmsg;
84 }
85 } else {
86 // Disable the view node if there are no views
87 scheduler->scheduleEventView( &context, m_viewNodeName, nullptr );
88 }
89 }
90
91 VERBOSE_MSG << "outputs number: " << m_outputHandles.size() << endmsg;
92 for ( auto& outputHandle : m_outputHandles ) {
93 if ( !outputHandle->isValid() ) continue;
94
95 VERBOSE_MSG << "put to TS: " << outputHandle->objKey() << endmsg;
96 outputHandle->put( std::make_unique<DataObject>() );
97 }
98
99 setFilterPassed( true );
100
101 return StatusCode::SUCCESS;
102 }
103
104 //------------------------------------------------------------------------------
105
106 StatusCode ViewTester::finalize() // the finalization of the algorithm
107 {
108 return GaudiAlgorithm::finalize();
109 }
110
111 //------------------------------------------------------------------------------
Test::ViewTester::m_outputHandles
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_outputHandles
Definition: ViewTester.h:41
SmartIF< IScheduler >
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:42
ThreadLocalContext.h
ViewTester.h
std::to_string
T to_string(T... args)
Test::ViewTester::initialize
StatusCode initialize() override
Its initialization.
Definition: ViewTester.cpp:20
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
Test::ViewTester::finalize
StatusCode finalize() override
the finalization of the algorithm
Definition: ViewTester.cpp:106
Test::ViewTester::m_baseViewName
Gaudi::Property< std::string > m_baseViewName
Definition: ViewTester.h:44
Gaudi::DataHandle::Reader
Definition: DataHandle.h:29
Test::ViewTester
Definition: ViewTester.h:15
std::string
STL class.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
DEBUG_MSG
#define DEBUG_MSG
Definition: ViewTester.cpp:7
DataObjectHandle< DataObject >
Test::ViewTester::m_viewNodeName
Gaudi::Property< std::string > m_viewNodeName
Definition: ViewTester.h:47
Test::ViewTester::m_inpKeys
Gaudi::Property< std::vector< std::string > > m_inpKeys
Definition: ViewTester.h:38
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
GaudiAlgorithm::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiAlgorithm.cpp:55
GaudiAlgorithm
The useful base class for data processing algorithms.
Definition: GaudiAlgorithm.h:94
Test::ViewTester::m_outKeys
Gaudi::Property< std::vector< std::string > > m_outKeys
Definition: ViewTester.h:39
Test
Definition: ViewTester.h:13
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
GaudiCommon< Algorithm >::context
const std::string & context() const
Returns the "context" string. Used to identify different processing states.
Definition: GaudiCommon.h:707
Test::ViewTester::execute
StatusCode execute() override
the execution of the algorithm
Definition: ViewTester.cpp:52
std::move
T move(T... args)
VERBOSE_MSG
#define VERBOSE_MSG
Definition: ViewTester.cpp:10
std::vector::size
T size(T... args)
Test::ViewTester::ViewTester
ViewTester()
the default constructor is disabled
AtlasMCRecoFullPrecedenceDump.scheduler
scheduler
Definition: AtlasMCRecoFullPrecedenceDump.py:33
std::vector::back
T back(T... args)
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
Gaudi::DataHandle::Writer
Definition: DataHandle.h:29
Test::ViewTester::m_inputHandles
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_inputHandles
Definition: ViewTester.h:40
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
std::vector::emplace_back
T emplace_back(T... args)
Test::ViewTester::m_viewNumber
Gaudi::Property< unsigned int > m_viewNumber
Definition: ViewTester.h:46