Skip to content
Snippets Groups Projects
Commit e8287692 authored by Vakhtang Tsulaia's avatar Vakhtang Tsulaia
Browse files

Merge branch 'module_component' into 'main'

make EventLoop Module into an AsgComponent plus minor code cleanup

See merge request atlas/athena!69470
parents 06a3a9cc d5f5f68d
No related branches found
No related tags found
No related merge requests found
Showing
with 141 additions and 162 deletions
......@@ -36,6 +36,8 @@ namespace EL
public:
using Module::Module;
virtual StatusCode firstInitialize (ModuleData& data) override;
};
}
......
......@@ -40,21 +40,15 @@ namespace EL
//
public:
virtual ::StatusCode onInitialize (ModuleData& data) override;
public:
virtual ::StatusCode onFinalize (ModuleData& data) override;
public:
virtual ::StatusCode onCloseInputFile (ModuleData& data) override;
public:
virtual ::StatusCode onNewInputFile (ModuleData& data) override;
public:
virtual ::StatusCode onFileExecute (ModuleData& data) override;
using Module::Module;
virtual ::StatusCode onExecute (ModuleData& data) override;
virtual StatusCode onInitialize (ModuleData& data) override;
virtual StatusCode onFinalize (ModuleData& data) override;
virtual StatusCode onCloseInputFile (ModuleData& data) override;
virtual StatusCode onNewInputFile (ModuleData& data) override;
virtual StatusCode onFileExecute (ModuleData& data) override;
virtual StatusCode onExecute (ModuleData& data) override;
......
......@@ -31,7 +31,9 @@ namespace EL
public:
virtual ::StatusCode firstInitialize (ModuleData& data) override;
using Module::Module;
virtual StatusCode firstInitialize (ModuleData& data) override;
};
}
}
......
......@@ -28,6 +28,8 @@ namespace EL
public:
using Module::Module;
BatchSample *sample = nullptr;
BatchSegment *segment = nullptr;
std::optional<uint64_t> maxEvents;
......
......@@ -26,6 +26,8 @@ namespace EL
public:
using Module::Module;
std::vector<std::string> fileList;
std::optional<uint64_t> skipEvents;
std::optional<uint64_t> maxEvents;
......
......@@ -27,7 +27,10 @@ namespace EL
//
public:
virtual ::StatusCode postFinalize (ModuleData& data) override;
using Module::Module;
virtual StatusCode postFinalize (ModuleData& data) override;
};
}
}
......
......@@ -31,7 +31,7 @@ namespace EL
std::string preloader;
FactoryPreloadModule (const std::string& val_preloader);
using Module::Module;
StatusCode onInitialize (ModuleData& data) override;
};
......
......@@ -30,16 +30,14 @@ namespace EL
//
public:
virtual ~FileExecutedModule () noexcept;
public:
virtual ::StatusCode onInitialize (ModuleData& data) override;
using Module::Module;
public:
virtual ::StatusCode onFileExecute (ModuleData& data) override;
virtual ~FileExecutedModule () noexcept;
public:
virtual ::StatusCode postFinalize (ModuleData& data) override;
virtual StatusCode onInitialize (ModuleData& data) override;
virtual StatusCode onFileExecute (ModuleData& data) override;
virtual StatusCode postFinalize (ModuleData& data) override;
......
......@@ -31,9 +31,12 @@ namespace EL
unsigned m_eventsProcessed = 0;
public:
virtual ::StatusCode onNewInputFile (ModuleData& data) override;
virtual ::StatusCode onExecute (ModuleData& data) override;
virtual ::StatusCode postFileClose (ModuleData& data) override;
using Module::Module;
virtual StatusCode onNewInputFile (ModuleData& data) override;
virtual StatusCode onExecute (ModuleData& data) override;
virtual StatusCode postFileClose (ModuleData& data) override;
virtual void reportInputFailure (ModuleData& data) override;
};
}
......
......@@ -28,13 +28,12 @@ namespace EL
//
public:
virtual ::StatusCode postFirstEvent (ModuleData& data) override;
public:
virtual ::StatusCode onWorkerEnd (ModuleData& data) override;
using Module::Module;
public:
virtual ::StatusCode postFinalize (ModuleData& data) override;
virtual StatusCode postFirstEvent (ModuleData& data) override;
virtual StatusCode onWorkerEnd (ModuleData& data) override;
virtual StatusCode postFinalize (ModuleData& data) override;
......
......@@ -32,13 +32,13 @@ namespace EL
/// test job with this module enabled to ensure it runs and doesn't break
/// the output.
class MemoryMonitorModule final : public Module, public asg::AsgMessaging
class MemoryMonitorModule final : public Module
{
/// Public Members
/// ==============
public:
MemoryMonitorModule (const std::string& name);
using Module::Module;
virtual StatusCode firstInitialize (ModuleData& data) override;
virtual StatusCode onInitialize (ModuleData& data) override;
......
......@@ -9,81 +9,78 @@
#ifndef EVENT_LOOP__MODULE_H
#define EVENT_LOOP__MODULE_H
#include <EventLoop/Global.h>
#include <AsgMessaging/StatusCode.h>
#include <AsgTools/AsgComponent.h>
#include <AsgTools/PropertyWrapper.h>
namespace EL
{
namespace Detail
{
class IInputModuleActions;
struct ModuleData;
/// \brief the base class for EventLoop instrumentation module
/// @brief the base class for EventLoop instrumentation module
///
/// These are **internal** modules for EventLoop that allow to
/// factor out non-core functionalities into separate modules.
/// The goal here is a separation of concern, allowing to
/// implement these modules to be defined without having to worry
/// about the internals of EventLoop, and conversely to allow
/// implementing the core functionality of EventLoop without
/// having the code interwoven with a lot auxilliary code.
/// factor out non-core functionalities into separate modules. The
/// goal here is a separation of concern, allowing to implement
/// these modules without having to worry about the internals of
/// EventLoop, and conversely to allow implementing the core
/// functionality of EventLoop without having the code interwoven
/// with a lot auxilliary code.
///
/// \warn The module interface is not considered stable and it can
/// @warn The module interface is not considered stable and it can
/// change without warning from one release to the next. This
/// interface is really meant to be completely internal and users
/// are not meant to mess with it.
///
/// \warn While I currently do not stream modules, the possibility
/// is anticipated and all modules ought to be written as if they
/// were to be streamed one day.
class Module
class Module : public asg::AsgComponent
{
/// \brief standard (virtual) destructor
/// Public/Virtual Members
/// ======================
public:
virtual ~Module () noexcept = default;
/// @brief inherited constructors
using AsgComponent::AsgComponent;
/// \brief action at the the very beginning of the worker job
/// @brief action at the the very beginning of the worker job
///
/// This gets called as early as possible in the worker
/// initialization. Essentially all that should happen before
/// this is to load all the modules. The main purpose is to
/// start any benchmarks that are meant to capture the
/// initialization process as well.
public:
virtual ::StatusCode firstInitialize (ModuleData& data);
virtual StatusCode firstInitialize (ModuleData& data);
/// \brief action before opening the first file in the worker
/// @brief action before opening the first file in the worker
/// job
///
/// This is mostly meant to allow loading the dictionaries
/// before any files and associated information is loaded.
public:
virtual ::StatusCode preFileInitialize (ModuleData& data);
virtual StatusCode preFileInitialize (ModuleData& data);
/// \brief action just before algorithms are initialized
/// @brief action just before algorithms are initialized
///
/// This is typically used for any setup that this module needs
/// to do.
public:
virtual ::StatusCode onInitialize (ModuleData& data);
virtual StatusCode onInitialize (ModuleData& data);
/// \brief process all input files
/// @brief process all input files
///
/// This deviates slightly from the usual pattern for module functions in
/// that I pass in the possible actions as an argument. See @ref
/// IInputModuleActions for details.
public:
virtual StatusCode processInputs (ModuleData& data, IInputModuleActions& actions);
/// \brief action after processing first event
/// @brief action after processing first event
///
/// This is mostly meant to set up benchmarks that record
/// per-event performance. While a lot of initialization
......@@ -91,76 +88,65 @@ namespace EL
/// initialization that happens on the first event, so when
/// recording per-event performance the first event is sort of
/// "special" and may need to be omitted.
public:
virtual ::StatusCode postFirstEvent (ModuleData& data);
virtual StatusCode postFirstEvent (ModuleData& data);
/// \brief actions after opening a new input file
public:
virtual ::StatusCode onNewInputFile (ModuleData& data);
/// @brief actions after opening a new input file
virtual StatusCode onNewInputFile (ModuleData& data);
/// \brief actions before closing an input file
public:
virtual ::StatusCode onCloseInputFile (ModuleData& data);
/// @brief actions before closing an input file
virtual StatusCode onCloseInputFile (ModuleData& data);
/// \brief actions after `CloseInputFile` is called on the
/// @brief actions after `CloseInputFile` is called on the
/// algorithms
///
/// Right now that is only used to disconnect the `TEvent`
/// object from the input file.
public:
virtual ::StatusCode postCloseInputFile (ModuleData& data);
virtual StatusCode postCloseInputFile (ModuleData& data);
/// \brief actions just before `fileExecute` is called on
/// @brief actions just before `fileExecute` is called on
/// algorithms
public:
virtual ::StatusCode onFileExecute (ModuleData& data);
virtual StatusCode onFileExecute (ModuleData& data);
/// \brief actions just before `execute` is called on
/// @brief actions just before `execute` is called on
/// algorithms
///
/// For now that is mostly used to point input modules to the
/// right event
public:
virtual ::StatusCode onExecute (ModuleData& data);
virtual StatusCode onExecute (ModuleData& data);
/// \brief actions just before algorithms are finalized
public:
virtual ::StatusCode onFinalize (ModuleData& data);
/// @brief actions just before algorithms are finalized
virtual StatusCode onFinalize (ModuleData& data);
/// \brief actions after algorithms have been finalized
/// @brief actions after algorithms have been finalized
///
/// This is usually used to calculate some job summary
/// information that is to be stored it in the histogram output
/// file.
public:
virtual ::StatusCode postFinalize (ModuleData& data);
virtual StatusCode postFinalize (ModuleData& data);
/// \brief action at the end of the worker job
/// @brief action at the end of the worker job
///
/// This is mostly meant/used to print job summary statements at
/// the very end of worker job, and actually have them show up
/// at or at least near the end of any log file.
public:
virtual ::StatusCode onWorkerEnd (ModuleData& data);
virtual StatusCode onWorkerEnd (ModuleData& data);
/// \brief action at of the worker job
///
/// Executed just right before worker exit successfully
/// at this stage all outputs have been created
public:
virtual ::StatusCode postFileClose(ModuleData& data);
/// @brief action at end of the worker job
///
/// Executed just right before worker exit successfully
/// at this stage all outputs have been created
virtual StatusCode postFileClose(ModuleData& data);
/// \brief report that we failed to open our input file
public:
/// @brief report that we failed to open our input file
virtual void reportInputFailure (ModuleData& data);
};
}
......
......@@ -23,8 +23,12 @@ namespace EL
//
// public interfacce
//
public:
virtual ::StatusCode postFileClose (ModuleData& data) override;
using Module::Module;
virtual StatusCode postFileClose (ModuleData& data) override;
};
}
}
......
......@@ -28,16 +28,13 @@ namespace EL
//
public:
virtual ::StatusCode firstInitialize (ModuleData& data) override;
public:
virtual ::StatusCode onFileExecute (ModuleData& data) override;
public:
virtual ::StatusCode postFinalize (ModuleData& data) override;
using Module::Module;
public:
virtual ::StatusCode onWorkerEnd (ModuleData& data) override;
virtual StatusCode firstInitialize (ModuleData& data) override;
virtual StatusCode onFileExecute (ModuleData& data) override;
virtual StatusCode postFinalize (ModuleData& data) override;
virtual StatusCode onWorkerEnd (ModuleData& data) override;
//
// private interface
......
......@@ -34,15 +34,15 @@ namespace EL
// public interface
//
public:
/// effects: standard constructor.
/// guarantee: no-fail
public:
TEventModule ();
TEventModule (const std::string& name);
/// effects: standard destructor.
/// guarantee: no-fail
public:
~TEventModule ();
......@@ -52,19 +52,12 @@ namespace EL
//
public:
virtual ::StatusCode onInitialize (ModuleData& data) override;
public:
virtual ::StatusCode postFinalize (ModuleData& data) override;
public:
virtual ::StatusCode onNewInputFile (ModuleData& data) override;
public:
virtual ::StatusCode postCloseInputFile (ModuleData& data) override;
public:
virtual ::StatusCode onExecute (ModuleData& data) override;
virtual StatusCode onInitialize (ModuleData& data) override;
virtual StatusCode postFinalize (ModuleData& data) override;
virtual StatusCode onNewInputFile (ModuleData& data) override;
virtual StatusCode postCloseInputFile (ModuleData& data) override;
virtual StatusCode onExecute (ModuleData& data) override;
......
......@@ -27,10 +27,11 @@ namespace EL
//
public:
virtual ::StatusCode onNewInputFile (ModuleData& data) override;
public:
virtual ::StatusCode onCloseInputFile (ModuleData& data) override;
using Module::Module;
virtual StatusCode onNewInputFile (ModuleData& data) override;
virtual StatusCode onCloseInputFile (ModuleData& data) override;
};
}
}
......
......@@ -23,6 +23,8 @@ namespace EL
{
public:
using Module::Module;
virtual StatusCode onInitialize (ModuleData& data) override;
};
}
......
......@@ -12,7 +12,6 @@
#include <EventLoop/AlgorithmMemoryModule.h>
#include <EventLoop/MessageCheck.h>
#include <EventLoop/ModuleData.h>
#include <EventLoop/AlgorithmMemoryWrapper.h>
#include <TSystem.h>
......@@ -28,7 +27,6 @@ namespace EL
StatusCode AlgorithmMemoryModule ::
firstInitialize (ModuleData& data)
{
using namespace msgEventLoop;
::ProcInfo_t pinfo;
if (gSystem->GetProcInfo (&pinfo) != 0) {
ANA_MSG_ERROR ("Could not get memory usage information");
......
......@@ -32,10 +32,9 @@ namespace EL
{
namespace
{
template<typename F> ::StatusCode
forAllAlgorithms (ModuleData& data, const char *funcName, F&& func)
template<typename F> StatusCode
forAllAlgorithms (MsgStream& msg, ModuleData& data, const char *funcName, F&& func)
{
using namespace msgEventLoop;
for (AlgorithmData& alg : data.m_algs)
{
try
......@@ -43,13 +42,13 @@ namespace EL
typedef typename std::decay<decltype(func(alg))>::type scType__;
if (!::asg::CheckHelper<scType__>::isSuccess (func (alg)))
{
ANA_MSG_ERROR ("executing " << funcName << " on algorithm " << alg->getName());
msg << MSG::ERROR << "executing " << funcName << " on algorithm " << alg->getName() << endmsg;
return StatusCode::FAILURE;
}
} catch (...)
{
report_exception (std::current_exception());
ANA_MSG_ERROR ("executing " << funcName << " on algorithm " << alg->getName());
msg << MSG::ERROR << "executing " << funcName << " on algorithm " << alg->getName() << endmsg;
return StatusCode::FAILURE;
}
}
......@@ -59,14 +58,13 @@ namespace EL
::StatusCode AlgorithmStateModule ::
StatusCode AlgorithmStateModule ::
onInitialize (ModuleData& data)
{
using namespace msgEventLoop;
if (m_initialized)
{
ANA_MSG_ERROR ("getting second initialize call");
return ::StatusCode::FAILURE;
return StatusCode::FAILURE;
}
m_initialized = true;
AlgorithmWorkerData workerData;
......@@ -75,72 +73,67 @@ namespace EL
workerData.m_filterWorker = data.m_worker;
workerData.m_wk = data.m_worker;
workerData.m_evtStore = data.m_evtStore;
return forAllAlgorithms (data, "initialize", [&] (AlgorithmData& alg) {
return forAllAlgorithms (msg(), data, "initialize", [&] (AlgorithmData& alg) {
return alg->initialize (workerData);});
}
::StatusCode AlgorithmStateModule ::
StatusCode AlgorithmStateModule ::
onFinalize (ModuleData& data)
{
using namespace msgEventLoop;
if (!m_initialized)
return ::StatusCode::SUCCESS;
if (forAllAlgorithms (data, "finalize", [&] (AlgorithmData& alg) {
return StatusCode::SUCCESS;
if (forAllAlgorithms (msg(), data, "finalize", [&] (AlgorithmData& alg) {
return alg->finalize ();}).isFailure())
return StatusCode::FAILURE;
return ::StatusCode::SUCCESS;
return StatusCode::SUCCESS;
}
::StatusCode AlgorithmStateModule ::
StatusCode AlgorithmStateModule ::
onCloseInputFile (ModuleData& data)
{
using namespace msgEventLoop;
return forAllAlgorithms (data, "endInputFile", [&] (AlgorithmData& alg) {
return forAllAlgorithms (msg(), data, "endInputFile", [&] (AlgorithmData& alg) {
return alg->endInputFile ();});
}
::StatusCode AlgorithmStateModule ::
StatusCode AlgorithmStateModule ::
onNewInputFile (ModuleData& data)
{
using namespace msgEventLoop;
if (!m_initialized)
{
ANA_MSG_ERROR ("algorithms have not been initialized yet");
return ::StatusCode::FAILURE;
return StatusCode::FAILURE;
}
if (data.m_inputTree == nullptr ||
data.m_inputTree->GetEntries() == 0)
return ::StatusCode::SUCCESS;
return StatusCode::SUCCESS;
if (forAllAlgorithms (data, "changeInput", [&] (AlgorithmData& alg) {
if (forAllAlgorithms (msg(), data, "changeInput", [&] (AlgorithmData& alg) {
return alg->beginInputFile ();}).isFailure())
return ::StatusCode::FAILURE;
return ::StatusCode::SUCCESS;
return StatusCode::FAILURE;
return StatusCode::SUCCESS;
}
::StatusCode AlgorithmStateModule ::
StatusCode AlgorithmStateModule ::
onFileExecute (ModuleData& data)
{
using namespace msgEventLoop;
return forAllAlgorithms (data, "fileExecute", [&] (AlgorithmData& alg) {
return forAllAlgorithms (msg(), data, "fileExecute", [&] (AlgorithmData& alg) {
return alg->fileExecute ();});
}
::StatusCode AlgorithmStateModule ::
StatusCode AlgorithmStateModule ::
onExecute (ModuleData& data)
{
using namespace msgEventLoop;
RCU_CHANGE_INVARIANT (this);
data.m_skipEvent = false;
......@@ -154,20 +147,20 @@ namespace EL
if (iter->m_algorithm->execute() == StatusCode::FAILURE)
{
ANA_MSG_ERROR ("while calling execute() on algorithm " << iter->m_algorithm->getName());
return ::StatusCode::FAILURE;
return StatusCode::FAILURE;
}
if (data.m_skipEvent)
{
iter->m_skipCount += 1;
return ::StatusCode::SUCCESS;
return StatusCode::SUCCESS;
}
}
} catch (...)
{
Detail::report_exception (std::current_exception());
ANA_MSG_ERROR ("while calling execute() on algorithm " << iter->m_algorithm->getName());
return ::StatusCode::FAILURE;
return StatusCode::FAILURE;
}
/// rationale: this will make sure that the post-processing runs
......@@ -180,17 +173,17 @@ namespace EL
if (jter->m_algorithm->postExecute() == StatusCode::FAILURE)
{
ANA_MSG_ERROR ("while calling postExecute() on algorithm " << iter->m_algorithm->getName());
return ::StatusCode::FAILURE;
return StatusCode::FAILURE;
}
}
} catch (...)
{
Detail::report_exception (std::current_exception());
ANA_MSG_ERROR ("while calling postExecute() on algorithm " << iter->m_algorithm->getName());
return ::StatusCode::FAILURE;
return StatusCode::FAILURE;
}
return ::StatusCode::SUCCESS;
return StatusCode::SUCCESS;
}
}
}
......@@ -23,12 +23,12 @@ namespace EL
{
namespace Detail
{
::StatusCode AlgorithmTimerModule ::
StatusCode AlgorithmTimerModule ::
firstInitialize (ModuleData& data)
{
for (auto& alg : data.m_algs)
alg.m_algorithm = std::make_unique<AlgorithmTimerWrapper>(std::move (alg.m_algorithm));
return ::StatusCode::SUCCESS;
return StatusCode::SUCCESS;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment