Commit 40ac7826 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Rest of the code: Algorithm -> Module.

parent c39edf0e
Pipeline #358630 passed with stages
in 8 minutes and 5 seconds
# For every algorithm, build a separate library to be loaded by corryvreckan core
# For every module, build a separate library to be loaded by corryvreckan core
MACRO(corryvreckan_enable_default val)
# Get the name of the algorithm
GET_FILENAME_COMPONENT(_corryvreckan_algorithm_dir ${CMAKE_CURRENT_SOURCE_DIR} NAME)
# Get the name of the module
GET_FILENAME_COMPONENT(_corryvreckan_module_dir ${CMAKE_CURRENT_SOURCE_DIR} NAME)
# Build all algorithms by default if not specified otherwise
OPTION(BUILD_${_corryvreckan_algorithm_dir} "Build algorithm in directory ${_corryvreckan_algorithm_dir}?" ${val})
# Build all modules by default if not specified otherwise
OPTION(BUILD_${_corryvreckan_module_dir} "Build module in directory ${_corryvreckan_module_dir}?" ${val})
ENDMACRO()
# Common algorithm definitions
MACRO(corryvreckan_algorithm name)
# Get the name of the algorithm
GET_FILENAME_COMPONENT(_corryvreckan_algorithm_dir ${CMAKE_CURRENT_SOURCE_DIR} NAME)
# Common module definitions
MACRO(corryvreckan_module name)
# Get the name of the module
GET_FILENAME_COMPONENT(_corryvreckan_module_dir ${CMAKE_CURRENT_SOURCE_DIR} NAME)
# Build all algorithms by default if not specified otherwise
OPTION(BUILD_${_corryvreckan_algorithm_dir} "Build algorithm in directory ${_corryvreckan_algorithm_dir}?" ON)
# Build all modules by default if not specified otherwise
OPTION(BUILD_${_corryvreckan_module_dir} "Build module in directory ${_corryvreckan_module_dir}?" ON)
# Quit the file if not building this file or all algorithms
IF(NOT (BUILD_${_corryvreckan_algorithm_dir} OR BUILD_ALL_ALGORITHMS))
# Quit the file if not building this file or all modules
IF(NOT (BUILD_${_corryvreckan_module_dir} OR BUILD_ALL_MODULES))
RETURN()
ENDIF()
# Put message
MESSAGE( STATUS "Building algorithm: " ${_corryvreckan_algorithm_dir} )
MESSAGE( STATUS "Building module: " ${_corryvreckan_module_dir} )
# Prepend with the algorithm prefix to create the name of the algorithm
SET(${name} "CorryvreckanAlgorithm${_corryvreckan_algorithm_dir}")
# Prepend with the module prefix to create the name of the module
SET(${name} "CorryvreckanModule${_corryvreckan_module_dir}")
# Save the algorithm library for prelinking in the executable (NOTE: see exec folder)
SET(CORRYVRECKAN_ALGORITHM_LIBRARIES ${CORRYVRECKAN_ALGORITHM_LIBRARIES} ${${name}} CACHE INTERNAL "Algorithm libraries")
# Save the module library for prelinking in the executable (NOTE: see exec folder)
SET(CORRYVRECKAN_MODULE_LIBRARIES ${CORRYVRECKAN_MODULE_LIBRARIES} ${${name}} CACHE INTERNAL "Module libraries")
# Set default algorithm class name
SET(_corryvreckan_algorithm_class "${_corryvreckan_algorithm_dir}")
# Set default module class name
SET(_corryvreckan_module_class "${_corryvreckan_module_dir}")
# Find if alternative algorithm class name is passed or we can use the default
# Find if alternative module class name is passed or we can use the default
SET (extra_macro_args ${ARGN})
LIST(LENGTH extra_macro_args num_extra_args)
IF (${num_extra_args} GREATER 0)
MESSAGE (AUTHOR_WARNING "Provided non-standard algorithm class name! Naming it ${_corryvreckan_algorithm_class} is recommended")
LIST(GET extra_macro_args 0 _corryvreckan_algorithm_class)
MESSAGE (AUTHOR_WARNING "Provided non-standard module class name! Naming it ${_corryvreckan_module_class} is recommended")
LIST(GET extra_macro_args 0 _corryvreckan_module_class)
ENDIF ()
# check if main header file is defined
IF(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_corryvreckan_algorithm_class}.h")
MESSAGE(FATAL_ERROR "Header file ${_corryvreckan_algorithm_class}.h does not exist, cannot build algorithm! \
IF(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_corryvreckan_module_class}.h")
MESSAGE(FATAL_ERROR "Header file ${_corryvreckan_module_class}.h does not exist, cannot build module! \
Create the header or provide the alternative class name as first argument")
ENDIF()
......@@ -53,15 +53,15 @@ Create the header or provide the alternative class name as first argument")
TARGET_INCLUDE_DIRECTORIES(${${name}} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
# Set the special header flags and add the special dynamic implementation file
TARGET_COMPILE_DEFINITIONS(${${name}} PRIVATE CORRYVRECKAN_ALGORITHM_NAME=${_corryvreckan_algorithm_class})
TARGET_COMPILE_DEFINITIONS(${${name}} PRIVATE CORRYVRECKAN_ALGORITHM_HEADER="${_corryvreckan_algorithm_class}.h")
TARGET_COMPILE_DEFINITIONS(${${name}} PRIVATE CORRYVRECKAN_MODULE_NAME=${_corryvreckan_module_class})
TARGET_COMPILE_DEFINITIONS(${${name}} PRIVATE CORRYVRECKAN_MODULE_HEADER="${_corryvreckan_module_class}.h")
TARGET_SOURCES(${${name}} PRIVATE "${PROJECT_SOURCE_DIR}/src/core/algorithm/dynamic_algorithm_impl.cpp")
SET_PROPERTY(SOURCE "${PROJECT_SOURCE_DIR}/src/core/algorithm/dynamic_algorithm_impl.cpp" APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${_corryvreckan_algorithm_class}.h")
TARGET_SOURCES(${${name}} PRIVATE "${PROJECT_SOURCE_DIR}/src/core/module/dynamic_module_impl.cpp")
SET_PROPERTY(SOURCE "${PROJECT_SOURCE_DIR}/src/core/module/dynamic_module_impl.cpp" APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${_corryvreckan_module_class}.h")
ENDMACRO()
# Add sources to the algorithm
MACRO(corryvreckan_algorithm_sources name)
# Add sources to the module
MACRO(corryvreckan_module_sources name)
# Get the list of sources
SET(_list_var "${ARGN}")
LIST(REMOVE_ITEM _list_var ${name})
......@@ -76,8 +76,8 @@ MACRO(corryvreckan_algorithm_sources name)
TARGET_LINK_LIBRARIES(${name} ${CORRYVRECKAN_LIBRARIES} ${CORRYVRECKAN_DEPS_LIBRARIES})
ENDMACRO()
# Provide default install target for the algorithm
MACRO(corryvreckan_algorithm_install name)
# Provide default install target for the module
MACRO(corryvreckan_module_install name)
INSTALL(TARGETS ${name}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
......
#!/bin/bash
# Ask for the name of the new algorithm
read -p "Name of the new algorithm: " NEWALGORITHM
# Copy the GenericAlgorithm and replace the name with the new algorithm name
echo "Creating folder src/algorithms/${NEWALGORITHM}"
mkdir ../src/algorithms/${NEWALGORITHM}
echo "Creating ${NEWALGORITHM}.cpp"
cp ../src/algorithms/GenericAlgorithm/GenericAlgorithm.cpp ../src/algorithms/${NEWALGORITHM}/${NEWALGORITHM}.cpp
echo "Creating ${NEWALGORITHM}.h"
cp ../src/algorithms/GenericAlgorithm/GenericAlgorithm.h ../src/algorithms/${NEWALGORITHM}/${NEWALGORITHM}.h
echo "Creating supplimentory files"
cp ../src/algorithms/GenericAlgorithm/CMakeLists.txt ../src/algorithms/${NEWALGORITHM}/CMakeLists.txt
cp ../src/algorithms/README_template.md ../src/algorithms/${NEWALGORITHM}/README.md
# Check mac or linux platform
platform=`uname`
if [ "$platform" == "Darwin" ]
then
sed -i "" s/"GenericAlgorithm"/"${NEWALGORITHM}"/g ../src/algorithms/${NEWALGORITHM}/${NEWALGORITHM}.cpp
sed -i "" s/"GenericAlgorithm"/"${NEWALGORITHM}"/g ../src/algorithms/${NEWALGORITHM}/${NEWALGORITHM}.h
sed -i "" s/"GenericAlgorithm"/"${NEWALGORITHM}"/g ../src/algorithms/${NEWALGORITHM}/CMakeLists.txt
else
sed -i s/"GenericAlgorithm"/"${NEWALGORITHM}"/g ../src/algorithms/${NEWALGORITHM}/${NEWALGORITHM}.cpp
sed -i s/"GenericAlgorithm"/"${NEWALGORITHM}"/g ../src/algorithms/${NEWALGORITHM}/${NEWALGORITHM}.h
sed -i s/"GenericAlgorithm"/"${NEWALGORITHM}"/g ../src/algorithms/${NEWALGORITHM}/CMakeLists.txt
fi
#!/bin/bash
# Ask for the name of the new module
read -p "Name of the new module: " NEWMODULE
# Copy the GenericAlgorithm and replace the name with the new module name
echo "Creating folder src/modules/${NEWMODULE}"
mkdir ../src/modules/${NEWMODULE}
echo "Creating ${NEWMODULE}.cpp"
cp ../src/modules/GenericAlgorithm/GenericAlgorithm.cpp ../src/modules/${NEWMODULE}/${NEWMODULE}.cpp
echo "Creating ${NEWMODULE}.h"
cp ../src/modules/GenericAlgorithm/GenericAlgorithm.h ../src/modules/${NEWMODULE}/${NEWMODULE}.h
echo "Creating supplimentory files"
cp ../src/modules/GenericAlgorithm/CMakeLists.txt ../src/modules/${NEWMODULE}/CMakeLists.txt
cp ../src/modules/README_template.md ../src/modules/${NEWMODULE}/README.md
# Check mac or linux platform
platform=`uname`
if [ "$platform" == "Darwin" ]
then
sed -i "" s/"GenericAlgorithm"/"${NEWMODULE}"/g ../src/modules/${NEWMODULE}/${NEWMODULE}.cpp
sed -i "" s/"GenericAlgorithm"/"${NEWMODULE}"/g ../src/modules/${NEWMODULE}/${NEWMODULE}.h
sed -i "" s/"GenericAlgorithm"/"${NEWMODULE}"/g ../src/modules/${NEWMODULE}/CMakeLists.txt
else
sed -i s/"GenericAlgorithm"/"${NEWMODULE}"/g ../src/modules/${NEWMODULE}/${NEWMODULE}.cpp
sed -i s/"GenericAlgorithm"/"${NEWMODULE}"/g ../src/modules/${NEWMODULE}/${NEWMODULE}.h
sed -i s/"GenericAlgorithm"/"${NEWMODULE}"/g ../src/modules/${NEWMODULE}/CMakeLists.txt
fi
......@@ -7,15 +7,15 @@
// Local include files
#include "Analysis.h"
#include "algorithm/exceptions.h"
#include "module/exceptions.h"
#include "utils/log.h"
#include <dlfcn.h>
#include <fstream>
#include <iomanip>
#define CORRYVRECKAN_ALGORITHM_PREFIX "libCorryvreckanAlgorithm"
#define CORRYVRECKAN_GENERATOR_FUNCTION "corryvreckan_algorithm_generator"
#define CORRYVRECKAN_MODULE_PREFIX "libCorryvreckanModule"
#define CORRYVRECKAN_GENERATOR_FUNCTION "corryvreckan_module_generator"
using namespace corryvreckan;
......@@ -92,7 +92,7 @@ void Analysis::load() {
add_units();
load_detectors();
load_algorithms();
load_modules();
}
void Analysis::load_detectors() {
......@@ -131,7 +131,7 @@ void Analysis::load_detectors() {
});
}
void Analysis::load_algorithms() {
void Analysis::load_modules() {
std::vector<Configuration> configs = conf_mgr_->getConfigurations();
// Create histogram output file
......@@ -142,14 +142,14 @@ void Analysis::load_algorithms() {
throw RuntimeError("Cannot create main ROOT file " + histogramFile);
}
LOG(DEBUG) << "Start loading algorithms, have " << configs.size() << " configurations.";
LOG(DEBUG) << "Start loading modules, have " << configs.size() << " configurations.";
// Loop through all non-global configurations
for(auto& config : configs) {
// Load library for each module. Libraries are named (by convention + CMAKE)
// libAllpixModule Name.suffix
std::string lib_name =
std::string(CORRYVRECKAN_ALGORITHM_PREFIX).append(config.getName()).append(SHARED_LIBRARY_SUFFIX);
LOG_PROGRESS(STATUS, "LOAD_LOOP") << "Loading algorithm " << config.getName();
std::string(CORRYVRECKAN_MODULE_PREFIX).append(config.getName()).append(SHARED_LIBRARY_SUFFIX);
LOG_PROGRESS(STATUS, "LOAD_LOOP") << "Loading module " << config.getName();
void* lib = nullptr;
bool load_error = false;
......@@ -226,7 +226,7 @@ void Analysis::load_algorithms() {
<< std::endl
<< "- Recompile the library " << problem_lib << " with tls-model=global-dynamic";
} else if(lib_error != nullptr && std::strstr(lib_error, "cannot open shared object file") != nullptr &&
problem_lib.find(CORRYVRECKAN_ALGORITHM_PREFIX) == std::string::npos) {
problem_lib.find(CORRYVRECKAN_MODULE_PREFIX) == std::string::npos) {
LOG(ERROR) << "Library could not be loaded: one of its dependencies is missing" << std::endl
<< "The name of the missing library is " << problem_lib << std::endl
<< "Please make sure the library is properly initialized and try "
......@@ -252,44 +252,44 @@ void Analysis::load_algorithms() {
std::string global_dir = gSystem->pwd();
config.set<std::string>("_global_dir", global_dir);
// Merge the global configuration into the algorithms config:
// Merge the global configuration into the modules config:
config.merge(global_config);
// Create the algorithms from the library
m_algorithms.emplace_back(create_algorithm(loaded_libraries_[lib_name], config));
// Create the modules from the library
m_modules.emplace_back(create_module(loaded_libraries_[lib_name], config));
}
LOG(STATUS) << "Loaded " << configs.size() << " modules";
}
Algorithm* Analysis::create_algorithm(void* library, Configuration config) {
LOG(TRACE) << "Creating algorithm " << config.getName() << ", using generator \"" << CORRYVRECKAN_GENERATOR_FUNCTION
Module* Analysis::create_module(void* library, Configuration config) {
LOG(TRACE) << "Creating module " << config.getName() << ", using generator \"" << CORRYVRECKAN_GENERATOR_FUNCTION
<< "\"";
// Make the vector to return
std::string algorithm_name = config.getName();
std::string module_name = config.getName();
// Get the generator function for this module
void* generator = dlsym(library, CORRYVRECKAN_GENERATOR_FUNCTION);
// If the generator function was not found, throw an error
if(generator == nullptr) {
LOG(ERROR) << "Algorithm library is invalid or outdated: required "
LOG(ERROR) << "Module library is invalid or outdated: required "
"interface function not found!";
throw corryvreckan::RuntimeError("Error instantiating algorithm from " + config.getName());
throw corryvreckan::RuntimeError("Error instantiating module from " + config.getName());
}
// Convert to correct generator function
auto algorithm_generator = reinterpret_cast<Algorithm* (*)(Configuration, std::vector<Detector*>)>(generator); // NOLINT
auto module_generator = reinterpret_cast<Module* (*)(Configuration, std::vector<Detector*>)>(generator); // NOLINT
// Figure out which detectors should run on this algorithm:
std::vector<Detector*> algorithm_det;
// Figure out which detectors should run on this module:
std::vector<Detector*> module_det;
if(!config.has("detectors")) {
algorithm_det = detectors;
module_det = detectors;
} else {
std::vector<std::string> det_list = config.getArray<std::string>("detectors");
for(auto& d : detectors) {
if(std::find(det_list.begin(), det_list.end(), d->name()) != det_list.end()) {
algorithm_det.push_back(d);
module_det.push_back(d);
}
}
}
......@@ -298,10 +298,10 @@ Algorithm* Analysis::create_algorithm(void* library, Configuration config) {
if(config.has("masked")) {
std::vector<std::string> mask_list = config.getArray<std::string>("masked");
for(auto it = algorithm_det.begin(); it != algorithm_det.end();) {
for(auto it = module_det.begin(); it != module_det.end();) {
// Remove detectors which are masked:
if(std::find(mask_list.begin(), mask_list.end(), (*it)->name()) != mask_list.end()) {
it = algorithm_det.erase(it);
it = module_det.erase(it);
} else {
it++;
}
......@@ -314,18 +314,18 @@ Algorithm* Analysis::create_algorithm(void* library, Configuration config) {
section_name += config.getName();
Log::setSection(section_name);
// Set module specific log settings
auto old_settings = set_algorithm_before(config.getName(), config);
// Build algorithm
Algorithm* algorithm = algorithm_generator(config, algorithm_det);
auto old_settings = set_module_before(config.getName(), config);
// Build module
Module* module = module_generator(config, module_det);
// Reset log
Log::setSection(old_section_name);
set_algorithm_after(old_settings);
set_module_after(old_settings);
// Return the algorithm to the analysis
return algorithm;
// Return the module to the analysis
return module;
}
// Run the analysis loop - this initialises, runs and finalises all algorithms
// Run the analysis loop - this initialises, runs and finalises all modules
void Analysis::run() {
// Check if we have an event or track limit:
......@@ -333,7 +333,7 @@ void Analysis::run() {
int number_of_tracks = global_config.get<int>("number_of_tracks", -1);
float run_time = global_config.get<float>("run_time", Units::convert(-1.0, "s"));
// Loop over all events, running each algorithm on each "event"
// Loop over all events, running each module on each "event"
LOG(STATUS) << "========================| Event loop |========================";
m_events = 1;
int events_prev = 1;
......@@ -357,24 +357,24 @@ void Analysis::run() {
if(number_of_tracks > -1 && m_tracks >= number_of_tracks)
break;
// Run all algorithms
for(auto& algorithm : m_algorithms) {
// Run all modules
for(auto& module : m_modules) {
// Set run module section header
std::string old_section_name = Log::getSection();
std::string section_name = "R:";
section_name += algorithm->getName();
section_name += module->getName();
Log::setSection(section_name);
// Set module specific settings
auto old_settings = set_algorithm_before(algorithm->getName(), algorithm->getConfig());
auto old_settings = set_module_before(module->getName(), module->getConfig());
// Change to the output file directory
m_directory->cd(algorithm->getName().c_str());
// Run the algorithms with timing enabled
algorithm->getStopwatch()->Start(false);
StatusCode check = algorithm->run(m_clipboard);
algorithm->getStopwatch()->Stop();
m_directory->cd(module->getName().c_str());
// Run the modules with timing enabled
module->getStopwatch()->Start(false);
StatusCode check = module->run(m_clipboard);
module->getStopwatch()->Stop();
// Reset logging
Log::setSection(old_section_name);
set_algorithm_after(old_settings);
set_module_after(old_settings);
if(check == NoData) {
noData = true;
skipped++;
......@@ -407,7 +407,7 @@ void Analysis::run() {
// Clear objects from this iteration from the clipboard
m_clipboard->clear();
// Check if any of the algorithms return a value saying it should stop
// Check if any of the modules return a value saying it should stop
if(!run)
break;
// Increment event number
......@@ -429,54 +429,54 @@ void Analysis::terminate() {
m_terminate = true;
}
// Initalise all algorithms
// Initalise all modules
void Analysis::initialiseAll() {
// Loop over all algorithms and initialise them
LOG(STATUS) << "=================| Initialising algorithms |==================";
for(auto& algorithm : m_algorithms) {
// Loop over all modules and initialise them
LOG(STATUS) << "=================| Initialising modules |==================";
for(auto& module : m_modules) {
// Set init module section header
std::string old_section_name = Log::getSection();
std::string section_name = "I:";
section_name += algorithm->getName();
section_name += module->getName();
Log::setSection(section_name);
// Set module specific settings
auto old_settings = set_algorithm_before(algorithm->getName(), algorithm->getConfig());
auto old_settings = set_module_before(module->getName(), module->getConfig());
// Make a new folder in the output file
m_directory->cd();
m_directory->mkdir(algorithm->getName().c_str());
m_directory->cd(algorithm->getName().c_str());
LOG(INFO) << "Initialising \"" << algorithm->getName() << "\"";
// Initialise the algorithm
algorithm->initialise();
m_directory->mkdir(module->getName().c_str());
m_directory->cd(module->getName().c_str());
LOG(INFO) << "Initialising \"" << module->getName() << "\"";
// Initialise the module
module->initialise();
// Reset logging
Log::setSection(old_section_name);
set_algorithm_after(old_settings);
set_module_after(old_settings);
}
}
// Finalise all algorithms
// Finalise all modules
void Analysis::finaliseAll() {
// Loop over all algorithms and finalise them
LOG(STATUS) << "===================| Finalising algorithms |===================";
for(auto& algorithm : m_algorithms) {
// Loop over all modules and finalise them
LOG(STATUS) << "===================| Finalising modules |===================";
for(auto& module : m_modules) {
// Set init module section header
std::string old_section_name = Log::getSection();
std::string section_name = "F:";
section_name += algorithm->getName();
section_name += module->getName();
Log::setSection(section_name);
// Set module specific settings
auto old_settings = set_algorithm_before(algorithm->getName(), algorithm->getConfig());
auto old_settings = set_module_before(module->getName(), module->getConfig());
// Change to the output file directory
m_directory->cd(algorithm->getName().c_str());
// Finalise the algorithm
algorithm->finalise();
m_directory->cd(module->getName().c_str());
// Finalise the module
module->finalise();
// Reset logging
Log::setSection(old_section_name);
set_algorithm_after(old_settings);
set_module_after(old_settings);
}
// Write the output histogram file
......@@ -506,19 +506,19 @@ void Analysis::finaliseAll() {
timing();
}
// Display timing statistics for each algorithm, over all events and per event
// Display timing statistics for each module, over all events and per event
void Analysis::timing() {
LOG(STATUS) << "===============| Wall-clock timing (seconds) |================";
for(auto& algorithm : m_algorithms) {
LOG(STATUS) << std::setw(25) << algorithm->getName() << " -- " << std::fixed << std::setprecision(5)
<< algorithm->getStopwatch()->RealTime() << " = " << std::setprecision(9)
<< algorithm->getStopwatch()->RealTime() / m_events << " s/evt";
for(auto& module : m_modules) {
LOG(STATUS) << std::setw(25) << module->getName() << " -- " << std::fixed << std::setprecision(5)
<< module->getStopwatch()->RealTime() << " = " << std::setprecision(9)
<< module->getStopwatch()->RealTime() / m_events << " s/evt";
}
LOG(STATUS) << "==============================================================";
}
// Helper functions to set the module specific log settings if necessary
std::tuple<LogLevel, LogFormat> Analysis::set_algorithm_before(const std::string&, const Configuration& config) {
std::tuple<LogLevel, LogFormat> Analysis::set_module_before(const std::string&, const Configuration& config) {
// Set new log level if necessary
LogLevel prev_level = Log::getReportingLevel();
if(config.has("log_level")) {
......@@ -553,7 +553,7 @@ std::tuple<LogLevel, LogFormat> Analysis::set_algorithm_before(const std::string
return std::make_tuple(prev_level, prev_format);
}
void Analysis::set_algorithm_after(std::tuple<LogLevel, LogFormat> prev) {
void Analysis::set_module_after(std::tuple<LogLevel, LogFormat> prev) {
// Reset the previous log level
LogLevel cur_level = Log::getReportingLevel();
LogLevel old_level = std::get<0>(prev);
......
......@@ -11,18 +11,18 @@
#include "Clipboard.h"
#include "Detector.h"
#include "algorithm/Algorithm.h"
#include "config/ConfigManager.hpp"
#include "config/Configuration.hpp"
#include "module/Module.hpp"
//-------------------------------------------------------------------------------
// The analysis class is the core class which allows the event processing to
// run. It basically contains a vector of algorithms, each of which is
// run. It basically contains a vector of modules, each of which is
// initialised,
// run on each event and finalised. It does not define what an event is, merely
// runs each algorithm sequentially and passes the clipboard between them
// runs each module sequentially and passes the clipboard between them
// (erasing
// it at the end of each run sequence). When an algorithm returns a 0, the event
// it at the end of each run sequence). When an module returns a 0, the event
// processing will stop.
//-------------------------------------------------------------------------------
......@@ -55,7 +55,7 @@ namespace corryvreckan {
private:
void load_detectors();
void load_algorithms();
void load_modules();
void add_units();
// Log file if specified
......@@ -66,15 +66,15 @@ namespace corryvreckan {
int m_events;
int m_tracks;
std::vector<Algorithm*> m_algorithms;
std::vector<Module*> m_modules;
std::map<std::string, void*> loaded_libraries_;
std::atomic<bool> m_terminate;
std::unique_ptr<corryvreckan::ConfigManager> conf_mgr_;
Algorithm* create_algorithm(void* library, corryvreckan::Configuration config);
std::tuple<LogLevel, LogFormat> set_algorithm_before(const std::string&, const Configuration& config);
void set_algorithm_after(std::tuple<LogLevel, LogFormat> prev);
Module* create_module(void* library, corryvreckan::Configuration config);
std::tuple<LogLevel, LogFormat> set_module_before(const std::string&, const Configuration& config);
void set_module_after(std::tuple<LogLevel, LogFormat> prev);
};
} // namespace corryvreckan
#endif // ANALYSIS_H
......@@ -10,7 +10,7 @@
#include "utils/log.h"
//-------------------------------------------------------------------------------
// The Clipboard class is used to transfer information between algorithms during
// The Clipboard class is used to transfer information between modules during
// the event processing. Any object inheriting from TestBeamObject can be placed
// on the clipboard, and retrieved by its name. At the end of each event, the
// clipboard is wiped clean.
......
#ifndef ALGORITHM_H
#define ALGORITHM_H 1
#ifndef MODULE_H
#define MODULE_H 1
// Include files
#include <string>
......@@ -10,14 +10,14 @@
#include "exceptions.h"
//-------------------------------------------------------------------------------
// The algorithm class is the base class that all user algorithms are built on.
// The module class is the base class that all user modules are built on.
// It
// allows the analysis class to hold algorithms of different types, without
// allows the analysis class to hold modules of different types, without
// knowing
// what they are, and provides the functions initialise, run and finalise. It
// also
// gives some basic tools like the "tcout" replacement for "cout" (appending the
// algorithm name) and the stopwatch for timing measurements.
// module name) and the stopwatch for timing measurements.
//-------------------------------------------------------------------------------
namespace corryvreckan {
......@@ -28,15 +28,15 @@ namespace corryvreckan {
Failure,
};
/** Base class for all algorithms
* @defgroup Algorithms Algorithms
/** Base class for all modules
* @defgroup Modules Modules
*/
class Algorithm {
class Module {
public:
// Constructors and destructors
Algorithm() {}
Algorithm(Configuration config, std::vector<Detector*> detectors) {
Module() {}
Module(Configuration config, std::vector<Detector*> detectors) {
m_name = config.getName();
m_config = config;
m_detectors = detectors;
......@@ -46,13 +46,13 @@ namespace corryvreckan {
for(auto& d : m_detectors) {
det << d->name() << ", ";
}
LOG(TRACE) << "Algorithm determined to run on detectors: " << det.str();
LOG(TRACE) << "Module determined to run on detectors: " << det.str();
}
}