Commit 0d74801b authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Module types: rename UNIQUE->GLOBAL, add new type DUT

parent 8c7042d7
......@@ -60,12 +60,12 @@ Create the header or provide the alternative class name as first argument")
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()
# Put this at the start of every unique module
MACRO(corryvreckan_unique_module name)
# Put this at the start of every global module
MACRO(corryvreckan_global_module name)
_corryvreckan_module_define_common(${name} ${ARGN})
# Set the unique flag to true
TARGET_COMPILE_DEFINITIONS(${${name}} PRIVATE CORRYVRECKAN_MODULE_UNIQUE=1)
TARGET_COMPILE_DEFINITIONS(${${name}} PRIVATE CORRYVRECKAN_MODULE_GLOBAL=1)
ENDMACRO()
# Put this at the start of every detector module
......@@ -73,7 +73,17 @@ MACRO(corryvreckan_detector_module name)
_corryvreckan_module_define_common(${name} ${ARGN})
# Set the unique flag to false
TARGET_COMPILE_DEFINITIONS(${${name}} PRIVATE CORRYVRECKAN_MODULE_UNIQUE=0)
TARGET_COMPILE_DEFINITIONS(${${name}} PRIVATE CORRYVRECKAN_MODULE_GLOBAL=0)
TARGET_COMPILE_DEFINITIONS(${${name}} PRIVATE CORRYVRECKAN_MODULE_DUT=0)
ENDMACRO()
# Put this at the start of every detector module
MACRO(corryvreckan_dut_module name)
_corryvreckan_module_define_common(${name} ${ARGN})
# Set the unique flag to false
TARGET_COMPILE_DEFINITIONS(${${name}} PRIVATE CORRYVRECKAN_MODULE_GLOBAL=0)
TARGET_COMPILE_DEFINITIONS(${${name}} PRIVATE CORRYVRECKAN_MODULE_DUT=1)
ENDMACRO()
# Add sources to the module
......
......@@ -25,7 +25,8 @@
#define CORRYVRECKAN_MODULE_PREFIX "libCorryvreckanModule"
#define CORRYVRECKAN_GENERATOR_FUNCTION "corryvreckan_module_generator"
#define CORRYVRECKAN_UNIQUE_FUNCTION "corryvreckan_module_is_unique"
#define CORRYVRECKAN_GLOBAL_FUNCTION "corryvreckan_module_is_global"
#define CORRYVRECKAN_DUT_FUNCTION "corryvreckan_module_is_dut"
using namespace corryvreckan;
......@@ -273,15 +274,25 @@ void Analysis::load_modules() {
loaded_libraries_[lib_name] = lib;
// Check if this module is produced once, or once per detector
bool unique = true;
void* uniqueFunction = dlsym(loaded_libraries_[lib_name], CORRYVRECKAN_UNIQUE_FUNCTION);
bool global = true;
bool dut_only = false;
void* globalFunction = dlsym(loaded_libraries_[lib_name], CORRYVRECKAN_GLOBAL_FUNCTION);
void* dutFunction = dlsym(loaded_libraries_[lib_name], CORRYVRECKAN_DUT_FUNCTION);
// If the unique function was not found, throw an error
if(uniqueFunction == nullptr) {
// If the global function was not found, throw an error
if(globalFunction == nullptr) {
LOG(ERROR) << "Module library is invalid or outdated: required interface function not found!";
throw corryvreckan::DynamicLibraryError(config.getName());
} else {
unique = reinterpret_cast<bool (*)()>(uniqueFunction)(); // NOLINT
global = reinterpret_cast<bool (*)()>(globalFunction)(); // NOLINT
}
// If the DUT function was not found, throw an error
if(dutFunction == nullptr) {
LOG(ERROR) << "Module library is invalid or outdated: required interface function not found!";
throw corryvreckan::DynamicLibraryError(config.getName());
} else {
dut_only = reinterpret_cast<bool (*)()>(dutFunction)(); // NOLINT
}
// Apply the module specific options to the module configuration
......@@ -295,10 +306,10 @@ void Analysis::load_modules() {
config.merge(global_config);
// Create the modules from the library
if(unique) {
if(global) {
m_modules.emplace_back(create_unique_module(loaded_libraries_[lib_name], config));
} else {
auto modules = create_detector_modules(loaded_libraries_[lib_name], config);
auto modules = create_detector_modules(loaded_libraries_[lib_name], config, dut_only);
for(const auto& mod : modules) {
m_modules.push_back(mod);
}
......@@ -368,7 +379,7 @@ Module* Analysis::create_unique_module(void* library, Configuration config) {
return module;
}
std::vector<Module*> Analysis::create_detector_modules(void* library, Configuration config) {
std::vector<Module*> Analysis::create_detector_modules(void* library, Configuration config, bool dut_only) {
LOG(TRACE) << "Creating instantiations for module " << config.getName() << ", using generator \""
<< CORRYVRECKAN_GENERATOR_FUNCTION << "\"";
......@@ -417,6 +428,12 @@ std::vector<Module*> Analysis::create_detector_modules(void* library, Configurat
for(const auto& detector : module_det) {
// Set the identifier for this module:
config.setName(module_base_name + "_" + detector->name());
// If this should only be instantiated for DUTs, skip otherwise:
if(dut_only && !detector->isDUT()) {
LOG(TRACE) << "Skipping instantiation \"" << config.getName() << "\", detector is no DUT";
continue;
}
LOG(TRACE) << "Creating instantiation \"" << config.getName() << "\"";
// Set the log section header
......
......@@ -78,7 +78,7 @@ namespace corryvreckan {
std::unique_ptr<corryvreckan::ConfigManager> conf_mgr_;
Module* create_unique_module(void* library, corryvreckan::Configuration config);
std::vector<Module*> create_detector_modules(void* library, Configuration config);
std::vector<Module*> create_detector_modules(void* library, Configuration config, bool dut_only);
std::tuple<LogLevel, LogFormat> set_module_before(const std::string&, const Configuration& config);
void set_module_after(std::tuple<LogLevel, LogFormat> prev);
......
......@@ -6,7 +6,7 @@
* Needs the following names to be defined by the build system
* - CORRYVRECKAN_MODULE_NAME: name of the module
* - CORRYVRECKAN_MODULE_HEADER: name of the header defining the module
* - CORRYVRECKAN_MODULE_UNIQUE: true if the module is unique, false otherwise
* - CORRYVRECKAN_MODULE_GLOBAL: true if the module is unique, false otherwise
*
* @copyright Copyright (c) 2017 CERN and the Allpix Squared authors.
* This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md".
......@@ -34,9 +34,16 @@ namespace corryvreckan {
*
* Used by the ModuleManager to determine if it should instantiate a single module or modules per detector instead.
*/
bool corryvreckan_module_is_unique();
bool corryvreckan_module_is_global();
#if CORRYVRECKAN_MODULE_UNIQUE || defined(DOXYGEN)
/**
* @brief Returns the type of the Module it is linked to
*
* Used by the ModuleManager to determine if it should instantiate a modules per detector or only per DUT.
*/
bool corryvreckan_module_is_dut();
#if CORRYVRECKAN_MODULE_GLOBAL || defined(DOXYGEN)
/**
* @brief Instantiates an unique module
* @param config Configuration for this module
......@@ -52,10 +59,13 @@ namespace corryvreckan {
return static_cast<Module*>(module);
}
// Returns that is a unique module
bool corryvreckan_module_is_unique() { return true; }
bool corryvreckan_module_is_global() { return true; }
// Globale modules cannot be DUT modules
bool corryvreckan_module_is_dut() { return false; }
#endif
#if !CORRYVRECKAN_MODULE_UNIQUE || defined(DOXYGEN)
#if(!CORRYVRECKAN_MODULE_GLOBAL && !CORRYVRECKAN_MODULE_DUT) || defined(DOXYGEN)
/**
* @brief Instantiates a detector module
* @param config Configuration for this module
......@@ -72,7 +82,31 @@ namespace corryvreckan {
}
// Returns that is a detector module
bool corryvreckan_module_is_unique() { return false; }
bool corryvreckan_module_is_global() { return false; }
// Return that this module is a generic detector module
bool corryvreckan_module_is_dut() { return false; }
#endif
#if(!CORRYVRECKAN_MODULE_GLOBAL && CORRYVRECKAN_MODULE_DUT) || defined(DOXYGEN)
/**
* @brief Instantiates a DUT module
* @param config Configuration for this module
* @param detector Pointer to the Detector object this module is bound to
* @return Instantiation of the module
*
* Internal method for the dynamic loading in the central Analysis class. Forwards the supplied arguments to the
* constructor and returns an instantiation
*/
Module* corryvreckan_module_generator(Configuration config, Detector* detector);
Module* corryvreckan_module_generator(Configuration config, Detector* detector) {
auto module = new CORRYVRECKAN_MODULE_NAME(std::move(config), std::move(detector)); // NOLINT
return static_cast<Module*>(module);
}
// Returns that is a detector module
bool corryvreckan_module_is_global() { return false; }
// Return that this module is a generic detector module
bool corryvreckan_module_is_dut() { return true; }
#endif
}
} // namespace corryvreckan
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
CORRYVRECKAN_ENABLE_DEFAULT(OFF)
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
# Peary and its CLICpix2 component is required for data decoding:
FIND_PACKAGE(Peary REQUIRED COMPONENTS CLICpix2)
......
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_DUT_MODULE(MODULE_NAME)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
......@@ -7,8 +7,7 @@
using namespace corryvreckan;
DUTAnalysis::DUTAnalysis(Configuration config, std::vector<Detector*> detectors)
: Module(std::move(config), std::move(detectors)) {
DUTAnalysis::DUTAnalysis(Configuration config, Detector* detector) : Module(std::move(config), std::move(detector)) {
m_digitalPowerPulsing = m_config.get<bool>("digitalPowerPulsing", false);
m_useMCtruth = m_config.get<bool>("useMCtruth", false);
chi2ndofCut = m_config.get<double>("chi2ndofCut", 3.);
......
......@@ -14,7 +14,8 @@ namespace corryvreckan {
public:
// Constructors and destructors
DUTAnalysis(Configuration config, std::vector<Detector*> detectors);
DUTAnalysis(Configuration config, Detector* detector);
~DUTAnalysis() {}
// Functions
......@@ -22,6 +23,7 @@ namespace corryvreckan {
StatusCode run(Clipboard* clipboard);
void finalise();
private:
// Histograms
TH1F* tracksVersusTime;
TH1F* associatedTracksVersusTime;
......
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
CORRYVRECKAN_ENABLE_DEFAULT(OFF)
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
FIND_PACKAGE(EUDAQ QUIET)
IF(NOT EUDAQ_FOUND)
......
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_UNIQUE_MODULE(MODULE_NAME)
CORRYVRECKAN_GLOBAL_MODULE(MODULE_NAME)
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment