Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ViewTester.cpp
Go to the documentation of this file.
1 #include "ViewTester.h"
3 
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 
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;
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;
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::move( 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 //------------------------------------------------------------------------------
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_outputHandles
Definition: ViewTester.h:41
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
StatusCode initialize() override
standard initialization method
const EventContext & getContext() const
Definition: Algorithm.h:20
bool isSuccess() const
Definition: StatusCode.h:267
void setFilterPassed(bool state) const
Set the filter passed flag to the specified state.
T to_string(T...args)
StatusCode initialize() override
Its initialization.
Definition: ViewTester.cpp:20
StatusCode service(const std::string &name, T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn&#39;t already exist.
Definition: Algorithm.h:215
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
StatusCode finalize() override
the finalization of the algorithm
Definition: ViewTester.cpp:106
const std::string & context() const
Returns the "context" string. Used to identify different processing states.
Definition: GaudiCommon.h:708
Gaudi::Property< std::string > m_baseViewName
Definition: ViewTester.h:44
virtual StatusCode scheduleEventView(const EventContext *sourceContext, const std::string &nodeName, std::unique_ptr< EventContext > viewContext)=0
Method to inform the scheduler about event views.
STL class.
#define DECLARE_COMPONENT(type)
#define DEBUG_MSG
Definition: ViewTester.cpp:7
Gaudi::Property< std::string > m_viewNodeName
Definition: ViewTester.h:47
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
Definition: Algorithm.h:338
Gaudi::Property< std::vector< std::string > > m_inpKeys
Definition: ViewTester.h:38
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode finalize() override
standard finalization method
The useful base class for data processing algorithms.
Gaudi::Property< std::vector< std::string > > m_outKeys
Definition: ViewTester.h:39
StatusCode execute() override
the execution of the algorithm
Definition: ViewTester.cpp:52
T move(T...args)
#define VERBOSE_MSG
Definition: ViewTester.cpp:10
T size(T...args)
ViewTester()
the default constructor is disabled
T back(T...args)
constexpr static const auto FAILURE
Definition: StatusCode.h:86
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Algorithm.cpp:679
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_inputHandles
Definition: ViewTester.h:40
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
T emplace_back(T...args)
Gaudi::Property< unsigned int > m_viewNumber
Definition: ViewTester.h:46