The Gaudi Framework  v30r4 (9b837755)
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  std::make_unique<DataObjectHandle<DataObject>>( k, Gaudi::v1::DataHandle::Reader, this ) );
38  declareProperty( "dummy_in_" + std::to_string( i ), *( m_inputHandles.back() ) );
39  i++;
40  }
41 
42  i = 0;
43  for ( auto k : m_outKeys ) {
44  DEBUG_MSG << "adding output key " << k << endmsg;
46  std::make_unique<DataObjectHandle<DataObject>>( k, Gaudi::v1::DataHandle::Writer, this ) );
47  declareProperty( "dummy_out_" + std::to_string( i ), *( m_outputHandles.back() ) );
48  i++;
49  }
50 
51  return sc;
52 }
53 
54 //------------------------------------------------------------------------------
55 
56 StatusCode ViewTester::execute() // the execution of the algorithm
57 {
58  SmartIF<IScheduler> scheduler( serviceLocator()->service( "AvalancheSchedulerSvc" ) );
59  if ( !scheduler ) {
60  fatal() << "Unable to load AvalancheSchedulerSvc" << endmsg;
61  return StatusCode::FAILURE;
62  }
63 
64  const auto& context = getContext();
65 
66  // Report if currently running in a view
67  if ( !context.hasExtension<std::string>() )
68  info() << "Running in whole event context" << endmsg;
69  else
70  info() << "Running in view " << context.getExtension<std::string>() << endmsg;
71 
72  // If a node name is specified (and not already in view), do view scheduling
73  if ( !m_viewNodeName.empty() && !context.hasExtension<std::string>() ) {
74  if ( m_viewNumber > 0 ) {
75  // Make views
76  for ( unsigned int viewIndex = 0; viewIndex < m_viewNumber; ++viewIndex ) {
77  // Make event context for the view
78  auto viewContext = std::make_unique<EventContext>( context.evt(), context.slot() );
79  const std::string& viewName = viewContext->setExtension( m_baseViewName + std::to_string( viewIndex ) );
80 
81  StatusCode sc = scheduler->scheduleEventView( &context, m_viewNodeName, std::move( viewContext ) );
82  if ( sc.isSuccess() )
83  info() << "Attached view " << viewName << " to node " << m_viewNodeName.toString() << " for " << context
84  << endmsg;
85  else
86  error() << "Unable to attach view " << viewName << " to node " << m_viewNodeName.toString() << " for "
87  << context << endmsg;
88  }
89  } else {
90  // Disable the view node if there are no views
91  scheduler->scheduleEventView( &context, m_viewNodeName, nullptr );
92  }
93  }
94 
95  VERBOSE_MSG << "outputs number: " << m_outputHandles.size() << endmsg;
96  for ( auto& outputHandle : m_outputHandles ) {
97  if ( !outputHandle->isValid() ) continue;
98 
99  VERBOSE_MSG << "put to TS: " << outputHandle->objKey() << endmsg;
100  outputHandle->put( std::move( std::make_unique<DataObject>() ) );
101  }
102 
103  setFilterPassed( true );
104 
105  return StatusCode::SUCCESS;
106 }
107 
108 //------------------------------------------------------------------------------
109 
110 StatusCode ViewTester::finalize() // the finalization of the algorithm
111 {
112  return GaudiAlgorithm::finalize();
113 }
114 
115 //------------------------------------------------------------------------------
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:773
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:110
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:56
T move(T...args)
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Algorithm.cpp:816
#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