The Gaudi Framework  v30r3 (a5ef0a68)
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  for ( uint i = 0; i < m_inputHandles.size(); ++i ) delete m_inputHandles[i];
25 
26  for ( uint i = 0; i < m_outputHandles.size(); ++i ) delete m_outputHandles[i];
27 }
28 
30 {
31  auto sc = GaudiAlgorithm::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  declareProperty( "dummy_out_" + std::to_string( i ), *( m_outputHandles.back() ) );
53  i++;
54  }
55 
56  return sc;
57 }
58 
59 //------------------------------------------------------------------------------
60 
61 StatusCode ViewTester::execute() // the execution of the algorithm
62 {
63  SmartIF<IScheduler> scheduler( serviceLocator()->service( "AvalancheSchedulerSvc" ) );
64  if ( !scheduler ) {
65  fatal() << "Unable to load AvalancheSchedulerSvc" << endmsg;
66  return StatusCode::FAILURE;
67  }
68 
69  // Report if currently running in a view
70  std::string const* contextName = getContext().getExtension<std::string>();
71  if ( contextName == nullptr ) {
72  info() << "Running in whole event context" << endmsg;
73  } else {
74  info() << "Running in view " << *contextName << endmsg;
75  }
76 
77  // If a node name is specified (and not already in view), do view scheduling
78  if ( m_viewNodeName != "" && contextName == nullptr ) {
79  if ( m_viewNumber > 0 ) {
80  // Make views
81  for ( unsigned int viewIndex = 0; viewIndex < m_viewNumber; ++viewIndex ) {
82  // Make event context for the view
83  EventContext* viewContext = new EventContext( getContext().evt(), getContext().slot() );
84  std::string viewName = m_baseViewName + std::to_string( viewIndex );
85  viewContext->setExtension<std::string>( viewName );
86 
87  StatusCode sc = scheduler->scheduleEventView( &getContext(), m_viewNodeName, viewContext );
88  if ( sc.isSuccess() ) {
89  info() << "Attached " << viewName << " to node " << m_viewNodeName.toString() << endmsg;
90  } else {
91  error() << "Unable to attach " << viewName << " to node " << m_viewNodeName.toString() << endmsg;
92  }
93  }
94  } else {
95  // Disable the view node if there are no views
96  scheduler->scheduleEventView( &getContext(), m_viewNodeName, 0 );
97  }
98  }
99 
100  VERBOSE_MSG << "outputs number: " << m_outputHandles.size() << endmsg;
101  for ( auto& outputHandle : m_outputHandles ) {
102  if ( !outputHandle->isValid() ) continue;
103 
104  VERBOSE_MSG << "put to TS: " << outputHandle->objKey() << endmsg;
105  outputHandle->put( new DataObject() );
106  }
107 
108  setFilterPassed( true );
109 
110  return StatusCode::SUCCESS;
111 }
112 
113 //------------------------------------------------------------------------------
114 
115 StatusCode ViewTester::finalize() // the finalization of the algorithm
116 {
117  return GaudiAlgorithm::finalize();
118 }
119 
120 //------------------------------------------------------------------------------
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:791
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
std::vector< DataObjectHandle< DataObject > * > m_outputHandles
Definition: ViewTester.h:46
StatusCode initialize() override
standard initialization method
T to_string(T...args)
StatusCode initialize() override
Its initialization.
Definition: ViewTester.cpp:29
StatusCode finalize() override
the finalization of the algorithm
Definition: ViewTester.cpp:115
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
Gaudi::Property< std::string > m_baseViewName
Definition: ViewTester.h:49
STL class.
#define DECLARE_COMPONENT(type)
#define DEBUG_MSG
Definition: ViewTester.cpp:7
Gaudi::Property< std::string > m_viewNodeName
Definition: ViewTester.h:52
T push_back(T...args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
std::vector< DataObjectHandle< DataObject > * > m_inputHandles
Definition: ViewTester.h:45
Gaudi::Property< std::vector< std::string > > m_inpKeys
Definition: ViewTester.h:43
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:436
The useful base class for data processing algorithms.
T * getExtension()
Definition: EventContext.h:81
Gaudi::Property< std::vector< std::string > > m_outKeys
Definition: ViewTester.h:44
StatusCode execute() override
the execution of the algorithm
Definition: ViewTester.cpp:61
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Algorithm.cpp:834
#define VERBOSE_MSG
Definition: ViewTester.cpp:10
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
void setExtension(const T &t)
Definition: EventContext.h:75
T size(T...args)
ViewTester()
the default constructor is disabled
virtual StatusCode scheduleEventView(EventContext const *sourceContext, std::string const &nodeName, EventContext *viewContext)=0
Method to inform the scheduler about event views.
T back(T...args)
virtual ~ViewTester()
virtual & protected desctrustor
Definition: ViewTester.cpp:22
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
Definition: Algorithm.h:370
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:231
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
evt
Definition: IOTest.py:96
Gaudi::Property< unsigned int > m_viewNumber
Definition: ViewTester.h:51