The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
ViewTester.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#include "ViewTester.h"
13
15
16#define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
17#define DEBUG_MSG ON_DEBUG debug()
18
19#define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
20#define VERBOSE_MSG ON_VERBOSE verbose()
21
22using namespace Test;
23
24//------------------------------------------------------------------------------
25
26ViewTester::ViewTester( const std::string& name, // the algorithm instance name
27 ISvcLocator* pSvc )
28 : Algorithm( name, pSvc ) {}
29
31 auto sc = Algorithm::initialize();
32 if ( !sc ) return sc;
33
34 // This is a bit ugly. There is no way to declare a vector of DataObjectHandles, so
35 // we need to wait until initialize when we've read in the input and output key
36 // properties, and know their size, and then turn them
37 // into Handles and register them with the framework by calling declareProperty. We
38 // could call declareInput/declareOutput on them too.
39
40 int i = 0;
41 for ( auto k : m_inpKeys ) {
42 DEBUG_MSG << "adding input key " << k << endmsg;
43 m_inputHandles.emplace_back( std::make_unique<DataObjectHandle<DataObject>>( k, Gaudi::DataHandle::Reader, this ) );
44 declareProperty( "dummy_in_" + std::to_string( i ), *( m_inputHandles.back() ) );
45 i++;
46 }
47
48 i = 0;
49 for ( auto k : m_outKeys ) {
50 DEBUG_MSG << "adding output key " << k << endmsg;
51 m_outputHandles.emplace_back(
52 std::make_unique<DataObjectHandle<DataObject>>( k, Gaudi::DataHandle::Writer, this ) );
53 declareProperty( "dummy_out_" + std::to_string( i ), *( m_outputHandles.back() ) );
54 i++;
55 }
56
57 return sc;
58}
59
60//------------------------------------------------------------------------------
61
62StatusCode ViewTester::execute() // the execution of the algorithm
63{
64 SmartIF<IScheduler> scheduler( serviceLocator()->service( "AvalancheSchedulerSvc" ) );
65 if ( !scheduler ) {
66 fatal() << "Unable to load AvalancheSchedulerSvc" << endmsg;
68 }
69
70 const auto& context = getContext();
71
72 // Report if currently running in a view
73 if ( !context.hasExtension<std::string>() )
74 info() << "Running in whole event context" << endmsg;
75 else
76 info() << "Running in view " << context.getExtension<std::string>() << endmsg;
77
78 // If a node name is specified (and not already in view), do view scheduling
79 if ( !m_viewNodeName.empty() && !context.hasExtension<std::string>() ) {
80 if ( m_viewNumber > 0 ) {
81 // Make views
82 for ( unsigned int viewIndex = 0; viewIndex < m_viewNumber; ++viewIndex ) {
83 // Make event context for the view
84 auto viewContext = std::make_unique<EventContext>( context.evt(), context.slot() );
85 const std::string& viewName = viewContext->setExtension( m_baseViewName + std::to_string( viewIndex ) );
86
87 StatusCode sc = scheduler->scheduleEventView( &context, m_viewNodeName, std::move( viewContext ) );
88 if ( sc.isSuccess() )
89 info() << "Attached view " << viewName << " to node " << m_viewNodeName.value() << " for " << context
90 << endmsg;
91 else
92 error() << "Unable to attach view " << viewName << " to node " << m_viewNodeName.value() << " for " << context
93 << endmsg;
94 }
95 } else {
96 // Disable the view node if there are no views
97 scheduler->scheduleEventView( &context, m_viewNodeName, nullptr ).ignore();
98 }
99 }
100
101 setFilterPassed( true );
102
103 return StatusCode::SUCCESS;
104}
#define DEBUG_MSG
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition Algorithm.h:98
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
Definition Algorithm.h:286
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition Algorithm.h:175
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
const std::string & name() const override
The identifying name of the algorithm object.
SmartIF< IService > service(std::string_view name, const bool createIf=true, const bool quiet=false) const
Return a pointer to the service identified by name (or "type/name")
void setFilterPassed(bool state) const
Set the filter passed flag to the specified state.
const EventContext & getContext() const
Definition Algorithm.h:29
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isSuccess() const
Definition StatusCode.h:314
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
Gaudi::Property< std::string > m_viewNodeName
Definition ViewTester.h:57
Gaudi::Property< std::vector< std::string > > m_inpKeys
Definition ViewTester.h:48
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_outputHandles
Definition ViewTester.h:51
Gaudi::Property< std::string > m_baseViewName
Definition ViewTester.h:54
Gaudi::Property< unsigned int > m_viewNumber
Definition ViewTester.h:56
Gaudi::Property< std::vector< std::string > > m_outKeys
Definition ViewTester.h:49
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_inputHandles
Definition ViewTester.h:50
ViewTester(const std::string &name, ISvcLocator *pSvc)
StatusCode initialize() override
Its initialization.
StatusCode execute() override
the execution of the algorithm