From c7945ec3c4b806067b13f1aaddeed0471c69b6c4 Mon Sep 17 00:00:00 2001
From: Annika Vauth <annika.vauth@uni-hamburg.de>
Date: Wed, 1 Mar 2023 10:28:14 +0100
Subject: [PATCH] reverse logic to make excluding passive the default unless
 INCLUDE_PASSIVE is specified

---
 cmake/corryvreckan.cmake                          |  6 +++---
 doc/usermanual/chapters/development.tex           |  2 +-
 etc/addModule.sh                                  |  8 ++++----
 src/core/module/ModuleManager.cpp                 | 10 +++++-----
 src/core/module/ModuleManager.hpp                 |  4 ++--
 src/core/module/dynamic_module_impl.cpp           | 14 +++++++-------
 src/modules/AnalysisFASTPIX/CMakeLists.txt        |  1 -
 src/modules/AnalysisTimingATLASpix/CMakeLists.txt |  1 -
 src/modules/AnalysisTimingFASTPIX/CMakeLists.txt  |  1 -
 src/modules/Clustering4D/CMakeLists.txt           |  1 -
 src/modules/ClusteringAnalog/CMakeLists.txt       |  1 -
 src/modules/ClusteringSpatial/CMakeLists.txt      |  1 -
 src/modules/Correlations/CMakeLists.txt           |  1 -
 src/modules/EtaCalculation/CMakeLists.txt         |  1 -
 src/modules/EtaCorrection/CMakeLists.txt          |  1 -
 src/modules/EventLoaderFASTPIX/CMakeLists.txt     |  1 -
 src/modules/MaskCreator/CMakeLists.txt            |  1 -
 src/modules/MaskCreatorTimepix3/CMakeLists.txt    |  1 -
 src/modules/Prealignment/CMakeLists.txt           |  1 -
 19 files changed, 22 insertions(+), 35 deletions(-)

diff --git a/cmake/corryvreckan.cmake b/cmake/corryvreckan.cmake
index e0df3599e..206331ca4 100644
--- a/cmake/corryvreckan.cmake
+++ b/cmake/corryvreckan.cmake
@@ -86,9 +86,9 @@ 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_passive name)
-    TARGET_COMPILE_DEFINITIONS(${name} PRIVATE CORRYVRECKAN_EXCLUDE_PASSIVE=1)
+# Select whether to include passive detectors or not
+MACRO(corryvreckan_include_passive name)
+    TARGET_COMPILE_DEFINITIONS(${name} PRIVATE CORRYVRECKAN_INCLUDE_PASSIVE=0)
 ENDMACRO()
 
 # Append list of possible detector types as compile definition
diff --git a/doc/usermanual/chapters/development.tex b/doc/usermanual/chapters/development.tex
index 5967a759d..8752b8dc8 100644
--- a/doc/usermanual/chapters/development.tex
+++ b/doc/usermanual/chapters/development.tex
@@ -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. Passive detectors can be excluded from being instantiated by adding \parameter{CORRYVRECKAN_EXCLUDE_PASSIVE(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 will be excluded from being instantiated, unless the \parameter{CORRYVRECKAN_INCLUDE_PASSIVE(MODULE_NAME)} is added 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.
diff --git a/etc/addModule.sh b/etc/addModule.sh
index 2cfd6bff4..c895f4d6b 100755
--- a/etc/addModule.sh
+++ b/etc/addModule.sh
@@ -32,7 +32,7 @@ if [ "$type" == 2 ]; then
 fi
 
 # If type is detector, ask if pass should be excluded:
-exclude_pass=0
+exclude_pass=1
 if [ "$type" == 2 ]; then
     echo -e "Should passive detectors be excluded from this module?\n"
     select yn in "yes" "nope"; do
@@ -121,9 +121,9 @@ 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_PASSIVE(\${MODULE_NAME})' $MODDIR/$MODNAME/CMakeLists.txt"
+    # Add inclusion of passive detectors for detector module if selected:
+    if [ "$exclude_pass" == 0  ]; then
+        command="sed $opt '/_DETECTOR_/ a CORRYVRECKAN_INCLUDE_PASSIVE(\${MODULE_NAME})' $MODDIR/$MODNAME/CMakeLists.txt"
         eval $command
     fi
 
diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp
index 414632c90..15ce537c7 100644
--- a/src/core/module/ModuleManager.cpp
+++ b/src/core/module/ModuleManager.cpp
@@ -32,7 +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_passive"
+#define CORRYVRECKAN_PASS_FUNCTION "corryvreckan_module_include_passive"
 #define CORRYVRECKAN_TYPE_FUNCTION "corryvreckan_detector_types"
 
 using namespace corryvreckan;
@@ -241,7 +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
+        bool include_pass = reinterpret_cast<bool (*)()>(passFunction)();  // NOLINT
         char* type_tokens = reinterpret_cast<char* (*)()>(typeFunction)(); // NOLINT
 
         std::vector<std::string> types = get_type_vector(type_tokens);
@@ -256,7 +256,7 @@ void ModuleManager::load_modules() {
             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, exclude_pass, types);
+                create_detector_modules(loaded_libraries_[lib_name], config, dut_only, exclude_aux, include_pass, types);
         }
 
         // Loop through all created instantiations
@@ -403,7 +403,7 @@ std::vector<std::pair<ModuleIdentifier, Module*>> ModuleManager::create_detector
                                                                                          Configuration& config,
                                                                                          bool dut_only,
                                                                                          bool exclude_aux,
-                                                                                         bool exclude_pass,
+                                                                                         bool include_pass,
                                                                                          std::vector<std::string> types) {
     LOG(TRACE) << "Creating instantiations for module " << config.getName() << ", using generator \""
                << CORRYVRECKAN_GENERATOR_FUNCTION << "\"";
@@ -508,7 +508,7 @@ std::vector<std::pair<ModuleIdentifier, Module*>> ModuleManager::create_detector
             continue;
         }
 
-        if(exclude_pass && detector->isPassive()) {
+        if(!include_pass && detector->isPassive()) {
             LOG(TRACE) << "Skipping instantiation \"" << identifier.getUniqueName() << "\", detector is passive";
             continue;
         }
diff --git a/src/core/module/ModuleManager.hpp b/src/core/module/ModuleManager.hpp
index 428ecf68a..c6d953e72 100644
--- a/src/core/module/ModuleManager.hpp
+++ b/src/core/module/ModuleManager.hpp
@@ -120,7 +120,7 @@ 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 include_pass Boolean to include 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
          */
@@ -128,7 +128,7 @@ namespace corryvreckan {
                                                                                   Configuration& config,
                                                                                   bool dut_only,
                                                                                   bool exclude_aux,
-                                                                                  bool exclude_pass,
+                                                                                  bool include_pass,
                                                                                   std::vector<std::string> types);
 
         using IdentifierToModuleMap = std::map<ModuleIdentifier, ModuleList::iterator>;
diff --git a/src/core/module/dynamic_module_impl.cpp b/src/core/module/dynamic_module_impl.cpp
index 1ee630237..cc1323bc9 100644
--- a/src/core/module/dynamic_module_impl.cpp
+++ b/src/core/module/dynamic_module_impl.cpp
@@ -55,11 +55,11 @@ namespace corryvreckan {
     bool corryvreckan_module_exclude_aux();
 
     /**
-     * @brief Returns if the linked module should be excluded for PASS detectors
+     * @brief Returns if the linked module should be included for PASSIVE detectors
      *
      * Used by the ModuleManager to determine if it should instantiate a modules for passive detectors
      */
-    bool corryvreckan_module_exclude_passive();
+    bool corryvreckan_module_include_passive();
 
     /**
      * @brief Returns a list of detector types this module can run on
@@ -149,12 +149,12 @@ namespace corryvreckan {
     bool corryvreckan_module_exclude_aux() { return false; }
 #endif
 
-#if(!CORRYVRECKAN_MODULE_GLOBAL && defined(CORRYVRECKAN_EXCLUDE_PASSIVE)) || defined(DOXYGEN)
-    // Return that this module should not be instantiated for pass detectors
-    bool corryvreckan_module_exclude_passive() { return true; }
+#if(!CORRYVRECKAN_MODULE_GLOBAL && defined(CORRYVRECKAN_INCLUDE_PASSIVE)) || defined(DOXYGEN)
+    // Return that this module should be instantiated for passive detectors
+    bool corryvreckan_module_include_passive() { return true; }
 #else
-    // Return that this module should not exclude pass detectors
-    bool corryvreckan_module_exclude_passive() { return false; }
+    // Return that this module should exclude passive detectors
+    bool corryvreckan_module_include_passive() { return false; }
 #endif
     }
 } // namespace corryvreckan
diff --git a/src/modules/AnalysisFASTPIX/CMakeLists.txt b/src/modules/AnalysisFASTPIX/CMakeLists.txt
index 34a27778a..f1b796134 100644
--- a/src/modules/AnalysisFASTPIX/CMakeLists.txt
+++ b/src/modules/AnalysisFASTPIX/CMakeLists.txt
@@ -5,7 +5,6 @@
 CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
 CORRYVRECKAN_DETECTOR_TYPE(${MODULE_NAME} "FASTPIX")
 CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
-CORRYVRECKAN_EXCLUDE_PASSIVE(${MODULE_NAME})
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
diff --git a/src/modules/AnalysisTimingATLASpix/CMakeLists.txt b/src/modules/AnalysisTimingATLASpix/CMakeLists.txt
index 4ec319f4e..2010b0d6c 100644
--- a/src/modules/AnalysisTimingATLASpix/CMakeLists.txt
+++ b/src/modules/AnalysisTimingATLASpix/CMakeLists.txt
@@ -5,7 +5,6 @@
 CORRYVRECKAN_DUT_MODULE(MODULE_NAME)
 CORRYVRECKAN_DETECTOR_TYPE(${MODULE_NAME} "ATLASpix")
 CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
-CORRYVRECKAN_EXCLUDE_PASSIVE(${MODULE_NAME})
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
diff --git a/src/modules/AnalysisTimingFASTPIX/CMakeLists.txt b/src/modules/AnalysisTimingFASTPIX/CMakeLists.txt
index 24d4b4510..a9ef3b8a3 100644
--- a/src/modules/AnalysisTimingFASTPIX/CMakeLists.txt
+++ b/src/modules/AnalysisTimingFASTPIX/CMakeLists.txt
@@ -5,7 +5,6 @@
 CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
 CORRYVRECKAN_DETECTOR_TYPE(${MODULE_NAME} "FASTPIX")
 CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
-CORRYVRECKAN_EXCLUDE_PASSIVE(${MODULE_NAME})
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
diff --git a/src/modules/Clustering4D/CMakeLists.txt b/src/modules/Clustering4D/CMakeLists.txt
index 62574fdd7..3d5229dee 100644
--- a/src/modules/Clustering4D/CMakeLists.txt
+++ b/src/modules/Clustering4D/CMakeLists.txt
@@ -4,7 +4,6 @@
 # Define module and return the generated name as MODULE_NAME
 CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
 CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
-CORRYVRECKAN_EXCLUDE_PASSIVE(${MODULE_NAME})
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
diff --git a/src/modules/ClusteringAnalog/CMakeLists.txt b/src/modules/ClusteringAnalog/CMakeLists.txt
index 254db70ac..48022c3f8 100644
--- a/src/modules/ClusteringAnalog/CMakeLists.txt
+++ b/src/modules/ClusteringAnalog/CMakeLists.txt
@@ -6,7 +6,6 @@ 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_PASSIVE(${MODULE_NAME})
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
diff --git a/src/modules/ClusteringSpatial/CMakeLists.txt b/src/modules/ClusteringSpatial/CMakeLists.txt
index a38b8cbac..7c4a55b51 100644
--- a/src/modules/ClusteringSpatial/CMakeLists.txt
+++ b/src/modules/ClusteringSpatial/CMakeLists.txt
@@ -4,7 +4,6 @@
 # Define module and return the generated name as MODULE_NAME
 CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
 CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
-CORRYVRECKAN_EXCLUDE_PASSIVE(${MODULE_NAME})
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
diff --git a/src/modules/Correlations/CMakeLists.txt b/src/modules/Correlations/CMakeLists.txt
index 3e9dbf27d..79b36af9f 100644
--- a/src/modules/Correlations/CMakeLists.txt
+++ b/src/modules/Correlations/CMakeLists.txt
@@ -4,7 +4,6 @@
 # Define module and return the generated name as MODULE_NAME
 CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
 CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
-CORRYVRECKAN_EXCLUDE_PASSIVE(${MODULE_NAME})
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
diff --git a/src/modules/EtaCalculation/CMakeLists.txt b/src/modules/EtaCalculation/CMakeLists.txt
index ba2f81ee1..962964b4c 100644
--- a/src/modules/EtaCalculation/CMakeLists.txt
+++ b/src/modules/EtaCalculation/CMakeLists.txt
@@ -4,7 +4,6 @@
 # Define module and return the generated name as MODULE_NAME
 CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
 CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
-CORRYVRECKAN_EXCLUDE_PASSIVE(${MODULE_NAME})
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
diff --git a/src/modules/EtaCorrection/CMakeLists.txt b/src/modules/EtaCorrection/CMakeLists.txt
index 4bf1b8f44..25f6753a0 100644
--- a/src/modules/EtaCorrection/CMakeLists.txt
+++ b/src/modules/EtaCorrection/CMakeLists.txt
@@ -4,7 +4,6 @@
 # Define module and return the generated name as MODULE_NAME
 CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
 CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
-CORRYVRECKAN_EXCLUDE_PASSIVE(${MODULE_NAME})
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
diff --git a/src/modules/EventLoaderFASTPIX/CMakeLists.txt b/src/modules/EventLoaderFASTPIX/CMakeLists.txt
index 4c9a08a4a..054302a08 100644
--- a/src/modules/EventLoaderFASTPIX/CMakeLists.txt
+++ b/src/modules/EventLoaderFASTPIX/CMakeLists.txt
@@ -5,7 +5,6 @@
 CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
 CORRYVRECKAN_DETECTOR_TYPE(${MODULE_NAME} "FASTPIX")
 CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
-CORRYVRECKAN_EXCLUDE_PASSIVE(${MODULE_NAME})
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
diff --git a/src/modules/MaskCreator/CMakeLists.txt b/src/modules/MaskCreator/CMakeLists.txt
index c85da6568..521b7ab37 100644
--- a/src/modules/MaskCreator/CMakeLists.txt
+++ b/src/modules/MaskCreator/CMakeLists.txt
@@ -4,7 +4,6 @@
 # Define module and return the generated name as MODULE_NAME
 CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
 CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
-CORRYVRECKAN_EXCLUDE_PASSIVE(${MODULE_NAME})
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
diff --git a/src/modules/MaskCreatorTimepix3/CMakeLists.txt b/src/modules/MaskCreatorTimepix3/CMakeLists.txt
index bdbbfd742..f5392ac60 100644
--- a/src/modules/MaskCreatorTimepix3/CMakeLists.txt
+++ b/src/modules/MaskCreatorTimepix3/CMakeLists.txt
@@ -5,7 +5,6 @@
 CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
 CORRYVRECKAN_DETECTOR_TYPE(${MODULE_NAME} "Timepix3")
 CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
-CORRYVRECKAN_EXCLUDE_PASSIVE(${MODULE_NAME})
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
diff --git a/src/modules/Prealignment/CMakeLists.txt b/src/modules/Prealignment/CMakeLists.txt
index 8447340c8..7d278deef 100644
--- a/src/modules/Prealignment/CMakeLists.txt
+++ b/src/modules/Prealignment/CMakeLists.txt
@@ -4,7 +4,6 @@
 # Define module and return the generated name as MODULE_NAME
 CORRYVRECKAN_DETECTOR_MODULE(MODULE_NAME)
 CORRYVRECKAN_EXCLUDE_AUX(${MODULE_NAME})
-CORRYVRECKAN_EXCLUDE_PASSIVE(${MODULE_NAME})
 
 # Add source files to library
 CORRYVRECKAN_MODULE_SOURCES(${MODULE_NAME}
-- 
GitLab