Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r7 (7f57a304)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Gaudi::Examples::QueueingApplication Class Reference
Inheritance diagram for Gaudi::Examples::QueueingApplication:
Collaboration diagram for Gaudi::Examples::QueueingApplication:

Private Member Functions

int run () override
 Implement the application main logic: More...
 
 Application (Options opts)
 Construct and configure the application from the provided options. More...
 

Additional Inherited Members

- Public Types inherited from Gaudi.Application
using Options = std::map< std::string, std::string >
 
using Factory = Gaudi::PluginService::Factory< Application(Options)>
 
- Public Member Functions inherited from Gaudi.Application
def __init__ (self, opts, appType="Gaudi::Application")
 
def create (cls, appType, opts)
 
def run (self)
 
def __del__ (self)
 
 Application (Options opts)
 Construct and configure the application from the provided options. More...
 
virtual ~Application ()
 
int run (std::function< int(SmartIF< IStateful > &)> action)
 Run a user provided implementation of the application main logic. More...
 
- Static Public Member Functions inherited from Gaudi.Application
static Factory::ReturnType create (std::string_view type, Options opts)
 Factory function to instantiate a derived class via GaudiPluginService. More...
 
- Protected Attributes inherited from Gaudi.Application
SmartIF< IStatefulapp
 Handle to the ApplicationMgr instance. More...
 

Detailed Description

Definition at line 48 of file QueueingApplication.cpp.

Member Function Documentation

◆ Application()

Gaudi.Application::Application
private

Construct and configure the application from the provided options.

Definition at line 33 of file Application.cpp.

52  {
53  // # Prepare the application
54  // - instantiate
56  GAUDI_ASSERT_THROW_NAME( app, "failure instantiating ApplicationMgr", "Gaudi::Application" );
57 
58  // - main configuration
59  consumeOptions( app.as<IProperty>(), options );
60  // - start minimal services
61  GAUDI_ASSERT_THROW_NAME( app->configure(), "failure creating basic services", "Gaudi::Application" );
62 
63  consumeOptions( SmartIF<IMessageSvc>{ app }.as<IProperty>(), options );
64 
65  // - prepare job configuration
66  {
67  auto sloc = app.as<ISvcLocator>();
68  auto& jos = sloc->getOptsSvc();
69  for ( const auto& [name, value] : options ) jos.set( name, value );
70  }
71 }

◆ run()

int Gaudi::Examples::QueueingApplication::run ( )
inlineoverrideprivatevirtual

Implement the application main logic:

  • prepare for processing (initialize + start)
  • loop over events
  • terminate (stop + finalize)

Reimplemented from Gaudi.Application.

Definition at line 53 of file QueueingApplication.cpp.

53  {
54  // - parameters for the job
55  const std::size_t n_of_batches = 2;
56  const std::size_t evts_in_batch = 5;
57 
58  // - get ready to process events
59  app->initialize().ignore();
60 
61  // - this MsgStream is useful to have uniform printout
62  MsgStream log( app.as<IMessageSvc>(), "<main>" );
63 
64  // we print the parameters here so that they appear close to the Capacity in the log
65  log << MSG::INFO << " n_of_batches: " << n_of_batches << endmsg;
66  log << MSG::INFO << " evts_in_batch: " << evts_in_batch << endmsg;
67 
68  app->start().ignore(); // this starts the QueueingEventLoopMgr processing thread
69 
70  // - main processing loop
71  {
72  // - get the IQueueingEventProcessor interface of the application
74 
75  // - processing state informations
76  // - events ready to be processed
78  // - count of events enqueued
79  std::size_t evt_count = 0;
80 
81  // - loop over input batches
82  for ( std::size_t batch = 1; batch <= n_of_batches; ++batch ) {
83  // - prepare the batch
84  log << MSG::INFO << "prepare batch of events n. " << batch << endmsg;
85  if ( batch == 2 ) {
86  log << MSG::INFO << " (pretend we need time so that the processing thread drains the input queue)"
87  << endmsg;
88  sleep_for( 4s );
89  log << MSG::INFO << " (all events in the queue should have been processed by now)" << endmsg;
90  }
91  for ( std::size_t i = 0; i < evts_in_batch; ++i ) {
92  // - create a new EventContext for each event in the batch
93  auto ctx = qep->createEventContext();
94  // ... here you can do something with the context ... like setting I/O related stuff
95  // - declare the event as ready to be enqueued
96  ready.push( std::move( ctx ) );
97  }
98 
99  // - once the batch is ready we can push all events, relying on the push to block if needed
100  log << MSG::INFO << "looping over the batch" << endmsg;
101  while ( !ready.empty() ) {
102  ++evt_count;
103  log << MSG::INFO << "- pushing event " << evt_count << " (" << ready.front() << ")..." << endmsg;
104  qep->push( std::move( ready.front() ) ); // this blocks if the system is full
105  ready.pop();
106  log << MSG::INFO << " ... event " << evt_count << " pushed" << endmsg;
107 
108  // - for each push we try a pop, to avoid that the output queue gets too big
109  log << MSG::INFO << "- checking for completed events" << endmsg;
110  if ( auto result = qep->pop() ) { // this never blocks, but evaulates to false if there was nothing to pop
111  // - if an event completed, we can do something (e.g. I/O)
112  auto&& [sc, ctx] = std::move( *result );
113  log << MSG::INFO << " " << ctx << " -> " << sc << endmsg;
114  }
115  }
116  }
117  log << MSG::INFO << "no more inputs: let's drain the output queue" << endmsg;
118  while ( !qep->empty() ) {
119  if ( auto result = qep->pop() ) {
120  auto&& [sc, ctx] = std::move( *result );
121  log << MSG::INFO << " " << ctx << " -> " << sc << endmsg;
122  } else {
123  sleep_for( 10ms );
124  }
125  }
126 
127  // - nothing else to do on the events
128  log << MSG::INFO << "all done" << endmsg;
129  }
130 
131  // - terminate the application
132  app->stop().ignore(); // this stops the QueueingEventLoopMgr processing thread
133  app->finalize().ignore();
134 
135  // - get and propagate the return code the ApplicationMgr whishes to expose
136  return getAppReturnCode( app.as<IProperty>() );
137  }

The documentation for this class was generated from the following file:
std::this_thread::sleep_for
T sleep_for(T... args)
Gaudi::createApplicationMgr
GAUDI_API IAppMgrUI * createApplicationMgr(const std::string &dllname, const std::string &factname)
IMessageSvc
Definition: IMessageSvc.h:47
Gaudi.Configuration.log
log
Definition: Configuration.py:28
std::move
T move(T... args)
MSG::INFO
@ INFO
Definition: IMessageSvc.h:25
gaudirun.s
string s
Definition: gaudirun.py:346
ISvcLocator
Definition: ISvcLocator.h:46
Gaudi::getAppReturnCode
int getAppReturnCode(const SmartIF< IProperty > &appmgr)
Get the application (current) return code.
Definition: AppReturnCode.h:79
GAUDI_ASSERT_THROW_NAME
#define GAUDI_ASSERT_THROW_NAME(cond, msg, name)
Definition: Application.cpp:25
std::queue
STL class.
ISvcLocator::getOptsSvc
Gaudi::Interfaces::IOptionsSvc & getOptsSvc()
Direct access to Gaudi::Interfaces::IOptionsSvc implementation.
Definition: ISvcLocator.cpp:19
std::queue::front
T front(T... args)
Gaudi::Units::ms
constexpr double ms
Definition: SystemOfUnits.h:154
IProperty
Definition: IProperty.h:33
TimingHistograms.name
name
Definition: TimingHistograms.py:25
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:588
std::queue::pop
T pop(T... args)
SmartIF< IMessageSvc >
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
MsgStream
Definition: MsgStream.h:34
SmartIF::as
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Definition: SmartIF.h:117
std::queue::empty
T empty(T... args)
std::queue::push
T push(T... args)
std::size_t
Gaudi.Application::app
SmartIF< IStateful > app
Handle to the ApplicationMgr instance.
Definition: Application.h:50
gaudirun.options
options
Definition: gaudirun.py:313