The Gaudi Framework  master (37c0b60a)
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 
22 using namespace Test;
23 
24 //------------------------------------------------------------------------------
25 
26 ViewTester::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;
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;
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 
62 StatusCode 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;
67  return StatusCode::FAILURE;
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 }
Test::ViewTester::initialize
StatusCode initialize() override
Its initialization.
Definition: ViewTester.cpp:30
ViewTester.h
std::string
STL class.
Test::ViewTester::m_inputHandles
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_inputHandles
Definition: ViewTester.h:48
std::move
T move(T... args)
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
Test::ViewTester::m_inpKeys
Gaudi::Property< std::vector< std::string > > m_inpKeys
Definition: ViewTester.h:46
Gaudi::details::LegacyAlgorithmAdapter::setFilterPassed
void setFilterPassed(bool state) const
Set the filter passed flag to the specified state.
Definition: LegacyAlgorithm.cpp:30
ISvcLocator
Definition: ISvcLocator.h:46
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition: Algorithm.h:178
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:58
Gaudi::Algorithm::declareProperty
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
Definition: Algorithm.h:304
Gaudi::Algorithm::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Algorithm.cpp:570
Gaudi::details::LegacyAlgorithmAdapter::getContext
const EventContext & getContext() const
Definition: Algorithm.h:29
std::vector::back
T back(T... args)
DataObjectHandle< DataObject >
Gaudi::DataHandle::Writer
@ Writer
Definition: DataHandle.h:40
Test::ViewTester
Definition: ViewTester.h:25
StatusCode
Definition: StatusCode.h:65
DEBUG_MSG
#define DEBUG_MSG
Definition: ViewTester.cpp:17
Test::ViewTester::m_outputHandles
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_outputHandles
Definition: ViewTester.h:49
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:237
std::to_string
T to_string(T... args)
SmartIF< IScheduler >
Test::ViewTester::m_outKeys
Gaudi::Property< std::vector< std::string > > m_outKeys
Definition: ViewTester.h:47
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
Test::ViewTester::m_baseViewName
Gaudi::Property< std::string > m_baseViewName
Definition: ViewTester.h:52
Test
Definition: ViewTester.h:23
Test::ViewTester::m_viewNumber
Gaudi::Property< unsigned int > m_viewNumber
Definition: ViewTester.h:54
Test::ViewTester::m_viewNodeName
Gaudi::Property< std::string > m_viewNodeName
Definition: ViewTester.h:55
ThreadLocalContext.h
std::vector::emplace_back
T emplace_back(T... args)
Test::ViewTester::execute
StatusCode execute() override
the execution of the algorithm
Definition: ViewTester.cpp:62
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Algorithm::service
StatusCode service(std::string_view name, T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Algorithm.h:206
Gaudi::DataHandle::Reader
@ Reader
Definition: DataHandle.h:40
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Test::ViewTester::ViewTester
ViewTester()
the default constructor is disabled
GPUAvalancheSchedulerSimpleTest.scheduler
scheduler
Definition: GPUAvalancheSchedulerSimpleTest.py:84