The Gaudi Framework  v30r5 (c7afbd0d)
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 {
20 }
21 
23 {
24  auto sc = GaudiAlgorithm::initialize();
25  if ( !sc ) return sc;
26 
27  // This is a bit ugly. There is no way to declare a vector of DataObjectHandles, so
28  // we need to wait until initialize when we've read in the input and output key
29  // properties, and know their size, and then turn them
30  // into Handles and register them with the framework by calling declareProperty. We
31  // could call declareInput/declareOutput on them too.
32 
33  int i = 0;
34  for ( auto k : m_inpKeys ) {
35  DEBUG_MSG << "adding input key " << k << endmsg;
37  declareProperty( "dummy_in_" + std::to_string( i ), *( m_inputHandles.back() ) );
38  i++;
39  }
40 
41  i = 0;
42  for ( auto k : m_outKeys ) {
43  DEBUG_MSG << "adding output key " << k << endmsg;
45  std::make_unique<DataObjectHandle<DataObject>>( k, Gaudi::DataHandle::Writer, this ) );
46  declareProperty( "dummy_out_" + std::to_string( i ), *( m_outputHandles.back() ) );
47  i++;
48  }
49 
50  return sc;
51 }
52 
53 //------------------------------------------------------------------------------
54 
55 StatusCode ViewTester::execute() // the execution of the algorithm
56 {
57  SmartIF<IScheduler> scheduler( serviceLocator()->service( "AvalancheSchedulerSvc" ) );
58  if ( !scheduler ) {
59  fatal() << "Unable to load AvalancheSchedulerSvc" << endmsg;
60  return StatusCode::FAILURE;
61  }
62 
63  const auto& context = getContext();
64 
65  // Report if currently running in a view
66  if ( !context.hasExtension<std::string>() )
67  info() << "Running in whole event context" << endmsg;
68  else
69  info() << "Running in view " << context.getExtension<std::string>() << endmsg;
70 
71  // If a node name is specified (and not already in view), do view scheduling
72  if ( !m_viewNodeName.empty() && !context.hasExtension<std::string>() ) {
73  if ( m_viewNumber > 0 ) {
74  // Make views
75  for ( unsigned int viewIndex = 0; viewIndex < m_viewNumber; ++viewIndex ) {
76  // Make event context for the view
77  auto viewContext = std::make_unique<EventContext>( context.evt(), context.slot() );
78  const std::string& viewName = viewContext->setExtension( m_baseViewName + std::to_string( viewIndex ) );
79 
80  StatusCode sc = scheduler->scheduleEventView( &context, m_viewNodeName, std::move( viewContext ) );
81  if ( sc.isSuccess() )
82  info() << "Attached view " << viewName << " to node " << m_viewNodeName.toString() << " for " << context
83  << endmsg;
84  else
85  error() << "Unable to attach view " << viewName << " to node " << m_viewNodeName.toString() << " for "
86  << context << endmsg;
87  }
88  } else {
89  // Disable the view node if there are no views
90  scheduler->scheduleEventView( &context, m_viewNodeName, nullptr );
91  }
92  }
93 
94  VERBOSE_MSG << "outputs number: " << m_outputHandles.size() << endmsg;
95  for ( auto& outputHandle : m_outputHandles ) {
96  if ( !outputHandle->isValid() ) continue;
97 
98  VERBOSE_MSG << "put to TS: " << outputHandle->objKey() << endmsg;
99  outputHandle->put( std::move( std::make_unique<DataObject>() ) );
100  }
101 
102  setFilterPassed( true );
103 
104  return StatusCode::SUCCESS;
105 }
106 
107 //------------------------------------------------------------------------------
108 
109 StatusCode ViewTester::finalize() // the finalization of the algorithm
110 {
111  return GaudiAlgorithm::finalize();
112 }
113 
114 //------------------------------------------------------------------------------
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_outputHandles
Definition: ViewTester.h:43
constexpr static const auto FAILURE
Definition: StatusCode.h:88
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
void setFilterPassed(bool state) const override
Set the filter passed flag to the specified state.
Definition: Algorithm.cpp:785
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
StatusCode initialize() override
standard initialization method
bool isSuccess() const
Definition: StatusCode.h:287
T to_string(T...args)
StatusCode initialize() override
Its initialization.
Definition: ViewTester.cpp:22
StatusCode finalize() override
the finalization of the algorithm
Definition: ViewTester.cpp:109
const std::string & context() const
Returns the "context" string. Used to identify different processing states.
Definition: GaudiCommon.h:739
Gaudi::Property< std::string > m_baseViewName
Definition: ViewTester.h:46
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:49
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Gaudi::Property< std::vector< std::string > > m_inpKeys
Definition: ViewTester.h:40
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
StatusCode finalize() override
standard finalization method
const EventContext & getContext() const override
get the context
Definition: Algorithm.h:437
The useful base class for data processing algorithms.
Gaudi::Property< std::vector< std::string > > m_outKeys
Definition: ViewTester.h:41
StatusCode execute() override
the execution of the algorithm
Definition: ViewTester.cpp:55
T move(T...args)
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Algorithm.cpp:828
#define VERBOSE_MSG
Definition: ViewTester.cpp:10
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T size(T...args)
ViewTester()
the default constructor is disabled
T back(T...args)
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
Definition: Algorithm.h:371
std::vector< std::unique_ptr< DataObjectHandle< DataObject > > > m_inputHandles
Definition: ViewTester.h:42
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:232
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:209
T emplace_back(T...args)
Gaudi::Property< unsigned int > m_viewNumber
Definition: ViewTester.h:48