Skip to content
Snippets Groups Projects
Commit 80b29304 authored by Annika Vauth's avatar Annika Vauth
Browse files

allow excluding passive detectors from modules - analogous to aux detectors

parent 345dae47
No related branches found
No related tags found
No related merge requests found
Showing
with 90 additions and 20 deletions
......@@ -86,6 +86,11 @@ MACRO(corryvreckan_exclude_aux name)
TARGET_COMPILE_DEFINITIONS(${name} PRIVATE CORRYVRECKAN_EXCLUDE_AUX=1)
ENDMACRO()
# Select whether to exclude passive detectors or not
MACRO(corryvreckan_exclude_pass name)
TARGET_COMPILE_DEFINITIONS(${name} PRIVATE CORRYVRECKAN_EXCLUDE_PASS=1)
ENDMACRO()
# Append list of possible detector types as compile definition
MACRO(corryvreckan_detector_type name)
SET(extra_macro_args ${ARGN})
......
......@@ -93,7 +93,7 @@ CORRYVRECKAN_DETECTOR_TYPE(${MODULE_NAME} "Timepix3" "CLICpix2")
\end{minted}
The module will then only be instantiated for detectors of one of the given types. This is particularly useful for event loader modules which read a very specific file format.
\item For detector modules, auxiliary detectors can be excluded from being instantiated by adding \parameter{CORRYVRECKAN_EXCLUDE_AUX(MODULE_NAME)} below the definition of the module type.
\item For detector modules, auxiliary detectors can be excluded from being instantiated by adding \parameter{CORRYVRECKAN_EXCLUDE_AUX(MODULE_NAME)} below the definition of the module type. Passive detectors can be excluded from being instantiated by adding \parameter{CORRYVRECKAN_EXCLUDE_PASS(MODULE_NAME)} below the definition of the module type.
\item The following lines should contain the logic to load possible dependencies of the module (below is an example to load Geant4).
Only ROOT is automatically included and linked to the module.
\item A line with \texttt{\textbf{CORRYVRECKAN\_MODULE\_SOURCES(\$\{MODULE\_NAME\} \textit{sources})}} defines the module source files. Here, \texttt{sources} should be replaced by a list of all source files relevant to this module.
......
......@@ -31,6 +31,18 @@ if [ "$type" == 2 ]; then
done
fi
# If type is detector, ask if pass should be excluded:
exclude_pass=0
if [ "$type" == 2 ]; then
echo -e "Should passive detectors be excluded from this module?\n"
select yn in "yes" "nope"; do
case $yn in
yes ) exclude_pass=1; break;;
nope ) exclude_pass=0; break;;
esac
done
fi
echo "Creating directory and files..."
echo
......@@ -109,6 +121,12 @@ if [ "$type" != 1 ]; then
eval $command
fi
# Add pass exclusion for detector module if selected:
if [ "$exclude_pass" == 1 ]; then
command="sed $opt '/_DETECTOR_/ a CORRYVRECKAN_EXCLUDE_PASS(\${MODULE_NAME})' $MODDIR/$MODNAME/CMakeLists.txt"
eval $command
fi
# Change header file
command="sed ${opt} \
-e 's/param detectors.*/param detector Pointer to the detector for this module instance/g' \
......
......@@ -32,6 +32,7 @@
#define CORRYVRECKAN_GLOBAL_FUNCTION "corryvreckan_module_is_global"
#define CORRYVRECKAN_DUT_FUNCTION "corryvreckan_module_is_dut"
#define CORRYVRECKAN_AUX_FUNCTION "corryvreckan_module_exclude_aux"
#define CORRYVRECKAN_PASS_FUNCTION "corryvreckan_module_exclude_pass"
#define CORRYVRECKAN_TYPE_FUNCTION "corryvreckan_detector_types"
using namespace corryvreckan;
......@@ -227,10 +228,12 @@ void ModuleManager::load_modules() {
void* globalFunction = dlsym(loaded_libraries_[lib_name], CORRYVRECKAN_GLOBAL_FUNCTION);
void* dutFunction = dlsym(loaded_libraries_[lib_name], CORRYVRECKAN_DUT_FUNCTION);
void* auxFunction = dlsym(loaded_libraries_[lib_name], CORRYVRECKAN_AUX_FUNCTION);
void* passFunction = dlsym(loaded_libraries_[lib_name], CORRYVRECKAN_PASS_FUNCTION);
void* typeFunction = dlsym(loaded_libraries_[lib_name], CORRYVRECKAN_TYPE_FUNCTION);
// If the global function was not found, throw an error
if(globalFunction == nullptr || dutFunction == nullptr || auxFunction == nullptr || typeFunction == nullptr) {
if(globalFunction == nullptr || dutFunction == nullptr || auxFunction == nullptr || passFunction == nullptr ||
typeFunction == nullptr) {
LOG(ERROR) << "Module library is invalid or outdated: required interface function not found!";
throw corryvreckan::DynamicLibraryError(config.getName());
}
......@@ -238,6 +241,7 @@ void ModuleManager::load_modules() {
bool global = reinterpret_cast<bool (*)()>(globalFunction)(); // NOLINT
bool dut_only = reinterpret_cast<bool (*)()>(dutFunction)(); // NOLINT
bool exclude_aux = reinterpret_cast<bool (*)()>(auxFunction)(); // NOLINT
bool exclude_pass = reinterpret_cast<bool (*)()>(passFunction)(); // NOLINT
char* type_tokens = reinterpret_cast<char* (*)()>(typeFunction)(); // NOLINT
std::vector<std::string> types = get_type_vector(type_tokens);
......@@ -251,7 +255,8 @@ void ModuleManager::load_modules() {
if(global) {
mod_list.emplace_back(create_unique_module(loaded_libraries_[lib_name], config));
} else {
mod_list = create_detector_modules(loaded_libraries_[lib_name], config, dut_only, exclude_aux, types);
mod_list =
create_detector_modules(loaded_libraries_[lib_name], config, dut_only, exclude_aux, exclude_pass, types);
}
// Loop through all created instantiations
......@@ -394,8 +399,12 @@ std::pair<ModuleIdentifier, Module*> ModuleManager::create_unique_module(void* l
return std::make_pair(identifier, module);
}
std::vector<std::pair<ModuleIdentifier, Module*>> ModuleManager::create_detector_modules(
void* library, Configuration& config, bool dut_only, bool exclude_aux, std::vector<std::string> types) {
std::vector<std::pair<ModuleIdentifier, Module*>> ModuleManager::create_detector_modules(void* library,
Configuration& config,
bool dut_only,
bool exclude_aux,
bool exclude_pass,
std::vector<std::string> types) {
LOG(TRACE) << "Creating instantiations for module " << config.getName() << ", using generator \""
<< CORRYVRECKAN_GENERATOR_FUNCTION << "\"";
......@@ -499,6 +508,11 @@ std::vector<std::pair<ModuleIdentifier, Module*>> ModuleManager::create_detector
continue;
}
if(exclude_pass && detector->isPassive()) {
LOG(TRACE) << "Skipping instantiation \"" << identifier.getUniqueName() << "\", detector is passive";
continue;
}
// Do not instantiate module if detector type is not mentioned as supported:
auto detectortype = detector->getType();
std::transform(detectortype.begin(), detectortype.end(), detectortype.begin(), ::tolower);
......
......@@ -120,11 +120,16 @@ namespace corryvreckan {
* @param config Configuration of the module
* @param dut_only Boolean signaling whether should be instantiated only for DUT detectors
* @param exclude_aux Boolean to exclude instantiations for auxliary detectors
* @param exclude_pass Boolean to exclude instantiations for passive detectors
* @param types List of detector type restrictions imposed by the module itself
* @return A list of all created detector modules and their identifiers
*/
std::vector<std::pair<ModuleIdentifier, Module*>> create_detector_modules(
void* library, Configuration& config, bool dut_only, bool exclude_aux, std::vector<std::string> types);
std::vector<std::pair<ModuleIdentifier, Module*>> create_detector_modules(void* library,
Configuration& config,
bool dut_only,
bool exclude_aux,
bool exclude_pass,
std::vector<std::string> types);
using IdentifierToModuleMap = std::map<ModuleIdentifier, ModuleList::iterator>;
......
......@@ -54,6 +54,13 @@ namespace corryvreckan {
*/
bool corryvreckan_module_exclude_aux();
/**
* @brief Returns if the linked module should be excluded for PASS detectors
*
* Used by the ModuleManager to determine if it should instantiate a modules for passive detectors
*/
bool corryvreckan_module_exclude_pass();
/**
* @brief Returns a list of detector types this module can run on
*
......@@ -141,5 +148,13 @@ namespace corryvreckan {
// Return that this module should not exclude aux detectors
bool corryvreckan_module_exclude_aux() { return false; }
#endif
#if(!CORRYVRECKAN_MODULE_GLOBAL && defined(CORRYVRECKAN_EXCLUDE_PASS)) || defined(DOXYGEN)
// Return that this module should not be instantiated for pass detectors
bool corryvreckan_module_exclude_pass() { return true; }
#else
// Return that this module should not exclude pass detectors
bool corryvreckan_module_exclude_pass() { return false; }
#endif
}
} // namespace corryvreckan
# SPDX-FileCopyrightText: 2017-2022 CERN and the Corryvreckan authors
# SPDX-FileCopyrightText: 2017-2023 CERN and the Corryvreckan authors
# SPDX-License-Identifier: MIT
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
CORRYVRECKAN_DETECTOR_TYPE(${MODULE_NAME} "FASTPIX")
CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
CORRYVRECKAN_EXCLUDE_PASS(${MODULE_NAME})
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# SPDX-FileCopyrightText: 2017-2022 CERN and the Corryvreckan authors
# SPDX-FileCopyrightText: 2017-2023 CERN and the Corryvreckan authors
# SPDX-License-Identifier: MIT
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DUT_MODULE(MODULE_NAME)
CORRYVRECKAN_DETECTOR_TYPE(${MODULE_NAME} "ATLASpix")
CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
CORRYVRECKAN_EXCLUDE_PASS(${MODULE_NAME})
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# SPDX-FileCopyrightText: 2017-2022 CERN and the Corryvreckan authors
# SPDX-FileCopyrightText: 2017-2023 CERN and the Corryvreckan authors
# SPDX-License-Identifier: MIT
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
CORRYVRECKAN_DETECTOR_TYPE(${MODULE_NAME} "FASTPIX")
CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
CORRYVRECKAN_EXCLUDE_PASS(${MODULE_NAME})
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# SPDX-FileCopyrightText: 2017-2022 CERN and the Corryvreckan authors
# SPDX-FileCopyrightText: 2017-2023 CERN and the Corryvreckan authors
# SPDX-License-Identifier: MIT
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
CORRYVRECKAN_EXCLUDE_PASS(${MODULE_NAME})
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# SPDX-FileCopyrightText: 2017-2022 CERN and the Corryvreckan authors
# SPDX-FileCopyrightText: 2017-2023 CERN and the Corryvreckan authors
# SPDX-License-Identifier: MIT
CORRYVRECKAN_ENABLE_DEFAULT(ON)
......@@ -6,6 +6,7 @@ CORRYVRECKAN_ENABLE_DEFAULT(ON)
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
CORRYVRECKAN_EXCLUDE_PASS(${MODULE_NAME})
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# SPDX-FileCopyrightText: 2017-2022 CERN and the Corryvreckan authors
# SPDX-FileCopyrightText: 2017-2023 CERN and the Corryvreckan authors
# SPDX-License-Identifier: MIT
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
CORRYVRECKAN_EXCLUDE_PASS(${MODULE_NAME})
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# SPDX-FileCopyrightText: 2017-2022 CERN and the Corryvreckan authors
# SPDX-FileCopyrightText: 2017-2023 CERN and the Corryvreckan authors
# SPDX-License-Identifier: MIT
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
CORRYVRECKAN_EXCLUDE_PASS(${MODULE_NAME})
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# SPDX-FileCopyrightText: 2017-2022 CERN and the Corryvreckan authors
# SPDX-FileCopyrightText: 2017-2023 CERN and the Corryvreckan authors
# SPDX-License-Identifier: MIT
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
CORRYVRECKAN_EXCLUDE_PASS(${MODULE_NAME})
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# SPDX-FileCopyrightText: 2017-2022 CERN and the Corryvreckan authors
# SPDX-FileCopyrightText: 2017-2023 CERN and the Corryvreckan authors
# SPDX-License-Identifier: MIT
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
CORRYVRECKAN_EXCLUDE_PASS(${MODULE_NAME})
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# SPDX-FileCopyrightText: 2017-2022 CERN and the Corryvreckan authors
# SPDX-FileCopyrightText: 2017-2023 CERN and the Corryvreckan authors
# SPDX-License-Identifier: MIT
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
CORRYVRECKAN_DETECTOR_TYPE(${MODULE_NAME} "FASTPIX")
CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
CORRYVRECKAN_EXCLUDE_PASS(${MODULE_NAME})
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# SPDX-FileCopyrightText: 2017-2022 CERN and the Corryvreckan authors
# SPDX-FileCopyrightText: 2017-2023 CERN and the Corryvreckan authors
# SPDX-License-Identifier: MIT
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
CORRYVRECKAN_EXCLUDE_PASS(${MODULE_NAME})
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# SPDX-FileCopyrightText: 2017-2022 CERN and the Corryvreckan authors
# SPDX-FileCopyrightText: 2017-2023 CERN and the Corryvreckan authors
# SPDX-License-Identifier: MIT
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
CORRYVRECKAN_DETECTOR_TYPE(${MODULE_NAME} "Timepix3")
CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
CORRYVRECKAN_EXCLUDE_PASS(${MODULE_NAME})
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
# SPDX-FileCopyrightText: 2017-2022 CERN and the Corryvreckan authors
# SPDX-FileCopyrightText: 2017-2023 CERN and the Corryvreckan authors
# SPDX-License-Identifier: MIT
# Define module and return the generated name as MODULE_NAME
CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
CORRYVRECKAN_EXCLUDE_PASS(${MODULE_NAME})
# Add source files to library
CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
......
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