The Gaudi Framework master (934d2c3c)
Loading...
Searching...
No Matches
ViewTester.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 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
12// Framework includes
18
19// STL includes
20#include <memory>
21#include <string>
22#include <vector>
23
24//------------------------------------------------------------------------------
25
30namespace Test {
31
32 class ViewTester : public Algorithm {
33
34 public:
35 bool isClonable() const override { return true; }
36
38 StatusCode execute() override;
40 StatusCode initialize() override;
41
42 ViewTester( const std::string& name, // the algorithm instance name
43 ISvcLocator* pSvc ); // the Service Locator
44
45 private:
47 ViewTester(); // no default constructor
49 ViewTester( const ViewTester& ); // no copy constructor
51 ViewTester& operator=( const ViewTester& ); // no assignement
52
57
58 // View config
59 Gaudi::Property<std::string> m_baseViewName{ this, "baseViewName", "view",
60 "Views to be named this, plus a numerical index" };
61 Gaudi::Property<unsigned int> m_viewNumber{ this, "viewNumber", 0, "How many views to make" };
62 Gaudi::Property<std::string> m_viewNodeName{ this, "viewNodeName", "viewNode", "Name of node to attach views to" };
63 };
64} // namespace Test
66
68
69#define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
70#define DEBUG_MSG ON_DEBUG debug()
71
72#define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
73#define VERBOSE_MSG ON_VERBOSE verbose()
74
75using namespace Test;
76
77//------------------------------------------------------------------------------
78
79ViewTester::ViewTester( const std::string& name, // the algorithm instance name
80 ISvcLocator* pSvc )
81 : Algorithm( name, pSvc ) {}
82
84 auto sc = Algorithm::initialize();
85 if ( !sc ) return sc;
86
87 // This is a bit ugly. There is no way to declare a vector of DataObjectHandles, so
88 // we need to wait until initialize when we've read in the input and output key
89 // properties, and know their size, and then turn them
90 // into Handles and register them with the framework by calling declareProperty. We
91 // could call declareInput/declareOutput on them too.
92
93 int i = 0;
94 for ( auto k : m_inpKeys ) {
95 DEBUG_MSG << "adding input key " << k << endmsg;
96 m_inputHandles.emplace_back( std::make_unique<DataObjectHandle<DataObject>>( k, Gaudi::DataHandle::Reader, this ) );
97 declareProperty( "dummy_in_" + std::to_string( i ), *( m_inputHandles.back() ) );
98 i++;
99 }
100
101 i = 0;
102 for ( auto k : m_outKeys ) {
103 DEBUG_MSG << "adding output key " << k << endmsg;
104 m_outputHandles.emplace_back(
105 std::make_unique<DataObjectHandle<DataObject>>( k, Gaudi::DataHandle::Writer, this ) );
106 declareProperty( "dummy_out_" + std::to_string( i ), *( m_outputHandles.back() ) );
107 i++;
108 }
109
110 return sc;
111}
112
113//------------------------------------------------------------------------------
114
115StatusCode ViewTester::execute() // the execution of the algorithm
116{
117 SmartIF<IScheduler> scheduler( serviceLocator()->service( "AvalancheSchedulerSvc" ) );
118 if ( !scheduler ) {
119 fatal() << "Unable to load AvalancheSchedulerSvc" << endmsg;
120 return StatusCode::FAILURE;
121 }
122
123 const auto& context = getContext();
124
125 // Report if currently running in a view
126 if ( !context.hasExtension<std::string>() )
127 info() << "Running in whole event context" << endmsg;
128 else
129 info() << "Running in view " << context.getExtension<std::string>() << endmsg;
130
131 // If a node name is specified (and not already in view), do view scheduling
132 if ( !m_viewNodeName.empty() && !context.hasExtension<std::string>() ) {
133 if ( m_viewNumber > 0 ) {
134 // Make views
135 for ( unsigned int viewIndex = 0; viewIndex < m_viewNumber; ++viewIndex ) {
136 // Make event context for the view
137 auto viewContext = std::make_unique<EventContext>( context.evt(), context.slot() );
138 const std::string& viewName = viewContext->setExtension( m_baseViewName + std::to_string( viewIndex ) );
139
140 StatusCode sc = scheduler->scheduleEventView( &context, m_viewNodeName, std::move( viewContext ) );
141 if ( sc.isSuccess() )
142 info() << "Attached view " << viewName << " to node " << m_viewNodeName.value() << " for " << context
143 << endmsg;
144 else
145 error() << "Unable to attach view " << viewName << " to node " << m_viewNodeName.value() << " for " << context
146 << endmsg;
147 }
148 } else {
149 // Disable the view node if there are no views
150 scheduler->scheduleEventView( &context, m_viewNodeName, nullptr ).ignore();
151 }
152 }
153
154 setFilterPassed( true );
155
156 return StatusCode::SUCCESS;
157}
#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)
constexpr _OI move(_II __first, _II __last, _OI __result)
constexpr const_reference back() const noexcept
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").
Implementation of property with value of concrete type.
Definition Property.h:35
const ValueType & value() const
Definition Property.h:246
auto empty() const
Definition Property.h:272
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:302
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
Gaudi::Property< std::string > m_viewNodeName
Gaudi::Property< std::vector< std::string > > m_inpKeys
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_outputHandles
Gaudi::Property< std::string > m_baseViewName
ViewTester(const ViewTester &)
the copy constructor is disabled
Gaudi::Property< unsigned int > m_viewNumber
bool isClonable() const override
Gaudi::Property< std::vector< std::string > > m_outKeys
ViewTester()
the default constructor is disabled
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_inputHandles
ViewTester(const std::string &name, ISvcLocator *pSvc)
StatusCode initialize() override
Its initialization.
ViewTester & operator=(const ViewTester &)
the assignement operator is disabled
StatusCode execute() override
the execution of the algorithm