diff --git a/cmake/RMGConfig.hh.in b/cmake/RMGConfig.hh.in index 3e55a62..80d3ea4 100644 --- a/cmake/RMGConfig.hh.in +++ b/cmake/RMGConfig.hh.in @@ -1,5 +1,5 @@ -#ifndef _RMGCONFIG_HH_ -#define _RMGCONFIG_HH_ +#ifndef _RMG_CONFIG_HH_ +#define _RMG_CONFIG_HH_ // other useful Geant4 exported variables: // G4VIS_USE_ diff --git a/include/RMGEventAction.hh b/include/RMGEventAction.hh index a47716d..7ada77d 100644 --- a/include/RMGEventAction.hh +++ b/include/RMGEventAction.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMG_MANAGEMENT_EVENT_ACTION_HH_ -#define _RMG_MANAGEMENT_EVENT_ACTION_HH_ +#ifndef _RMG_EVENT_ACTION_HH_ +#define _RMG_EVENT_ACTION_HH_ #include diff --git a/include/RMGGeneratorG4Gun.hh b/include/RMGGeneratorG4Gun.hh index ebd2fda..b306e44 100644 --- a/include/RMGGeneratorG4Gun.hh +++ b/include/RMGGeneratorG4Gun.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMGGENERATORG4GUN_HH_ -#define _RMGGENERATORG4GUN_HH_ +#ifndef _RMG_GENERATOR_G4GUN_HH_ +#define _RMG_GENERATOR_G4GUN_HH_ #include diff --git a/include/RMGHardware.hh b/include/RMGHardware.hh index f7cf45d..c9ac5a7 100644 --- a/include/RMGHardware.hh +++ b/include/RMGHardware.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMG_MANAGEMENT_DETECTOR_CONSTRUCTION_HH_ -#define _RMG_MANAGEMENT_DETECTOR_CONSTRUCTION_HH_ +#ifndef _RMG_HARDWARE_HH_ +#define _RMG_HARDWARE_HH_ #include #include @@ -57,7 +57,6 @@ class RMGHardware : public G4VUserDetectorConstruction { }; void RegisterDetector(DetectorType type, const std::string& pv_name, int uid, int copy_nr = 0); - void RegisterDetectorCmd(const std::string& parameters); inline const auto& GetDetectorMetadataMap() { return fDetectorMetadata; } inline const auto& GetDetectorMetadata(std::pair det) { return fDetectorMetadata.at(det); diff --git a/include/RMGHardwareMessenger.hh b/include/RMGHardwareMessenger.hh index cc0aa8c..e3ab068 100644 --- a/include/RMGHardwareMessenger.hh +++ b/include/RMGHardwareMessenger.hh @@ -32,6 +32,8 @@ class RMGHardwareMessenger : public G4UImessenger { RMGHardware* fHardware; G4UIcommand* fRegisterCmd; + + void RegisterDetectorCmd(const std::string& parameters); }; #endif diff --git a/include/RMGLog.hh b/include/RMGLog.hh index 13af842..66d6e7b 100644 --- a/include/RMGLog.hh +++ b/include/RMGLog.hh @@ -1,7 +1,7 @@ // Modified by Luigi Pertoldi in 2022 -#ifndef _RMGLOG_HH_ -#define _RMGLOG_HH_ +#ifndef _RMG_LOG_HH_ +#define _RMG_LOG_HH_ /** * @class RMGLog diff --git a/include/RMGMasterGenerator.hh b/include/RMGMasterGenerator.hh index cd5c7b9..6f023da 100644 --- a/include/RMGMasterGenerator.hh +++ b/include/RMGMasterGenerator.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMG_GENERATOR_PRIMARY_HH_ -#define _RMG_GENERATOR_PRIMARY_HH_ +#ifndef _RMG_MASTER_GENERATOR_HH_ +#define _RMG_MASTER_GENERATOR_HH_ #include diff --git a/include/RMGPhysics.hh b/include/RMGPhysics.hh index 598c44f..6490a05 100644 --- a/include/RMGPhysics.hh +++ b/include/RMGPhysics.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMG_PROCESSES_LIST_HH_ -#define _RMG_PROCESSES_LIST_HH_ +#ifndef _RMG_PHYSICS_HH_ +#define _RMG_PHYSICS_HH_ #include #include diff --git a/include/RMGRunAction.hh b/include/RMGRunAction.hh index 08600a2..622e675 100644 --- a/include/RMGRunAction.hh +++ b/include/RMGRunAction.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMG_MANAGEMENT_RUN_ACTION_HH_ -#define _RMG_MANAGEMENT_RUN_ACTION_HH_ +#ifndef _RMG_RUN_ACTION_HH_ +#define _RMG_RUN_ACTION_HH_ #include #include diff --git a/include/RMGStackingAction.hh b/include/RMGStackingAction.hh index 45dd497..ba3e139 100644 --- a/include/RMGStackingAction.hh +++ b/include/RMGStackingAction.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMG_MANAGEMENT_STACKING_ACTION_HH_ -#define _RMG_MANAGEMENT_STACKING_ACTION_HH_ +#ifndef _RMG_STACKING_ACTION_HH_ +#define _RMG_STACKING_ACTION_HH_ #include "G4UserStackingAction.hh" diff --git a/include/RMGSteppingAction.hh b/include/RMGSteppingAction.hh index 60e95bd..6847b37 100644 --- a/include/RMGSteppingAction.hh +++ b/include/RMGSteppingAction.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMG_MANAGEMENT_STEPPING_ACTION_HH_ -#define _RMG_MANAGEMENT_STEPPING_ACTION_HH_ +#ifndef _RMG_STEPPING_ACTION_HH_ +#define _RMG_STEPPING_ACTION_HH_ #include "G4UserSteppingAction.hh" diff --git a/include/RMGTools.hh b/include/RMGTools.hh index f87ab59..4ce75c5 100644 --- a/include/RMGTools.hh +++ b/include/RMGTools.hh @@ -16,18 +16,7 @@ #ifndef _RMG_TOOLS_HH_ #define _RMG_TOOLS_HH_ -#include -#include -#include -#include -#include - -namespace RMGTools { - - template T ToEnum(std::string); - - template std::string GetCandidates(); -} // namespace RMGTools +namespace RMGTools {} // namespace RMGTools #include "RMGTools.icc" diff --git a/include/RMGTools.icc b/include/RMGTools.icc index 5467ff5..3897b61 100644 --- a/include/RMGTools.icc +++ b/include/RMGTools.icc @@ -34,12 +34,12 @@ namespace RMGTools { } template - std::string GetCandidates() { + std::string GetCandidates(const char delim=' ') { auto v = magic_enum::enum_names(); std::string cand = ""; for (const auto& s : v) { auto name = s[0] == 'k' ? s.substr(1, std::string::npos) : s; - cand += std::string(name) + " "; + cand += std::string(name) + delim; } return cand.substr(0, cand.size()-1); } diff --git a/include/RMGTrackingAction.hh b/include/RMGTrackingAction.hh index 55f9656..a6ce9c3 100644 --- a/include/RMGTrackingAction.hh +++ b/include/RMGTrackingAction.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMG_MANAGEMENT_TRACKING_ACTION_HH_ -#define _RMG_MANAGEMENT_TRACKING_ACTION_HH_ +#ifndef _RMG_TRACKING_ACTION_HH_ +#define _RMG_TRACKING_ACTION_HH_ #include "G4UserTrackingAction.hh" diff --git a/include/RMGUserAction.hh b/include/RMGUserAction.hh index 01a9dbe..855d1d1 100644 --- a/include/RMGUserAction.hh +++ b/include/RMGUserAction.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMG_MANAGEMENT_USER_ACTION_HH_ -#define _RMG_MANAGEMENT_USER_ACTION_HH_ +#ifndef _RMG_USER_ACTION_HH_ +#define _RMG_USER_ACTION_HH_ #include "G4VUserActionInitialization.hh" diff --git a/include/RMGVGenerator.hh b/include/RMGVGenerator.hh index 672e8dc..3dcca4e 100644 --- a/include/RMGVGenerator.hh +++ b/include/RMGVGenerator.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMGVGENERATOR_HH_ -#define _RMGVGENERATOR_HH_ +#ifndef _RMG_V_GENERATOR_HH_ +#define _RMG_V_GENERATOR_HH_ #include diff --git a/include/RMGVOutputScheme.hh b/include/RMGVOutputScheme.hh index 67fc2ae..256bd40 100644 --- a/include/RMGVOutputScheme.hh +++ b/include/RMGVOutputScheme.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMG_OUTPUT_SCHEME_HH_ -#define _RMG_OUTPUT_SCHEME_HH_ +#ifndef _RMG_V_OUTPUT_SCHEME_HH_ +#define _RMG_V_OUTPUT_SCHEME_HH_ #include #include diff --git a/include/RMGVVertexGenerator.hh b/include/RMGVVertexGenerator.hh index 37fe6f2..c0211bd 100644 --- a/include/RMGVVertexGenerator.hh +++ b/include/RMGVVertexGenerator.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMG_GENERATOR_PRIMARY_POSITION_HH_ -#define _RMG_GENERATOR_PRIMARY_POSITION_HH_ +#ifndef _RMG_V_VERTEX_GENERARTOR_HH_ +#define _RMG_V_VERTEX_GENERARTOR_HH_ #include "RMGConfig.hh" #if RMG_HAS_BXDECAY0 diff --git a/include/RMGVertexFromFile.hh b/include/RMGVertexFromFile.hh index 42c0a4c..93c50a9 100644 --- a/include/RMGVertexFromFile.hh +++ b/include/RMGVertexFromFile.hh @@ -13,8 +13,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . -#ifndef _RMG_GENERATOR_FROM_FILE_HH_ -#define _RMG_GENERATOR_FROM_FILE_HH_ +#ifndef _RMG_VERTEX_FROM_FILE_HH_ +#define _RMG_VERTEX_FROM_FILE_HH_ #include #include diff --git a/src/RMGHardware.cc b/src/RMGHardware.cc index 5b01289..6370c7d 100644 --- a/src/RMGHardware.cc +++ b/src/RMGHardware.cc @@ -23,8 +23,6 @@ namespace fs = std::filesystem; #include "G4LogicalVolume.hh" #include "G4PhysicalVolumeStore.hh" #include "G4SDManager.hh" -#include "G4Tokenizer.hh" -#include "G4UIparameter.hh" #include "G4UserLimits.hh" #include "G4VPhysicalVolume.hh" @@ -187,24 +185,6 @@ void RMGHardware::RegisterDetector(DetectorType type, const std::string& pv_name } } -void RMGHardware::RegisterDetectorCmd(const std::string& parameters) { - G4Tokenizer next(parameters); - - auto type_str = next(); - auto type = magic_enum::enum_cast(type_str); - if (!type.has_value()) { - RMGLog::OutFormat(RMGLog::error, "Invalid detector type {} in command", type_str); - return; - } - auto pv_name = next(); - const int uid = std::stoi(next()); - int copy_nr = 0; - auto copy_nr_str = next(); - if (!copy_nr_str.empty()) copy_nr = std::stoi(copy_nr_str); - - this->RegisterDetector(type.value(), pv_name, uid, copy_nr); -} - void RMGHardware::DefineCommands() { fMessenger = std::make_unique(this, "/RMG/Geometry/", diff --git a/src/RMGHardwareMessenger.cc b/src/RMGHardwareMessenger.cc index 70c9258..8b65e5b 100644 --- a/src/RMGHardwareMessenger.cc +++ b/src/RMGHardwareMessenger.cc @@ -15,30 +15,33 @@ #include "RMGHardwareMessenger.hh" -#include "RMGHardware.hh" +#include "G4Tokenizer.hh" -#ifndef FMT_HEADER_ONLY -#define FMT_HEADER_ONLY -#endif -#include "fmt/core.h" -#include "magic_enum/magic_enum.hpp" +#include "RMGHardware.hh" +#include "RMGTools.hh" RMGHardwareMessenger::RMGHardwareMessenger(RMGHardware* hw) : fHardware(hw) { - auto detector_types = magic_enum::enum_names(); - auto options = fmt::format("{}", fmt::join(detector_types, "|")); - fRegisterCmd = new G4UIcommand("/RMG/Geometry/RegisterDetector", this); fRegisterCmd->SetGuidance("register a sensitive detector"); fRegisterCmd->SetGuidance("[usage] /RMG/Geometry/RegisterDetector T PV ID [C]"); - fRegisterCmd->SetGuidance(fmt::format(" T:(str) {}", options).c_str()); - fRegisterCmd->SetGuidance(" PV:(s) physvol"); - fRegisterCmd->SetGuidance(" ID:(int) unique detector id"); - fRegisterCmd->SetGuidance(" C:(int) copy nr (default 0)"); - fRegisterCmd->SetParameter(new G4UIparameter("type", 's', false)); - fRegisterCmd->SetParameter(new G4UIparameter("pv_name", 's', false)); - fRegisterCmd->SetParameter(new G4UIparameter("uid", 'i', false)); - fRegisterCmd->SetParameter(new G4UIparameter("copy_nr", 'i', true)); + auto p_type = new G4UIparameter("type", 's', false); + p_type->SetParameterCandidates(RMGTools::GetCandidates().c_str()); + p_type->SetGuidance("Detector type"); + fRegisterCmd->SetParameter(p_type); + + auto p_pv = new G4UIparameter("pv_name", 's', false); + p_pv->SetGuidance("Detector physical volume"); + fRegisterCmd->SetParameter(p_pv); + + auto p_uid = new G4UIparameter("uid", 'i', false); + p_uid->SetGuidance("unique detector id"); + fRegisterCmd->SetParameter(p_uid); + + auto p_copy = new G4UIparameter("copy_nr", 'i', true); + p_copy->SetGuidance("copy nr (default 0)"); + p_copy->SetDefaultValue("0"); + fRegisterCmd->SetParameter(p_copy); fRegisterCmd->AvailableForStates(G4State_PreInit); } @@ -46,7 +49,21 @@ RMGHardwareMessenger::RMGHardwareMessenger(RMGHardware* hw) : fHardware(hw) { RMGHardwareMessenger::~RMGHardwareMessenger() { delete fRegisterCmd; } void RMGHardwareMessenger::SetNewValue(G4UIcommand* command, G4String newValues) { - if (command == fRegisterCmd) fHardware->RegisterDetectorCmd(newValues); + if (command == fRegisterCmd) RegisterDetectorCmd(newValues); +} + +void RMGHardwareMessenger::RegisterDetectorCmd(const std::string& parameters) { + G4Tokenizer next(parameters); + + auto type_str = next(); + auto type = RMGTools::ToEnum(std::string(type_str), "detector type"); + auto pv_name = next(); + const int uid = std::stoi(next()); + int copy_nr = 0; + auto copy_nr_str = next(); + if (!copy_nr_str.empty()) copy_nr = std::stoi(copy_nr_str); + + fHardware->RegisterDetector(type, pv_name, uid, copy_nr); } // vim: tabstop=2 shiftwidth=2 expandtab diff --git a/src/RMGManager.cc b/src/RMGManager.cc index dfae677..47066db 100644 --- a/src/RMGManager.cc +++ b/src/RMGManager.cc @@ -259,11 +259,6 @@ void RMGManager::DefineCommands() { fMessenger = std::make_unique(this, "/RMG/Manager/", "General commands for controlling the application"); - fMessenger->DeclareMethod("Include", &RMGManager::IncludeMacroFile) - .SetGuidance("Include macro file") - .SetParameterName("filename", false) - .SetStates(G4State_PreInit, G4State_Idle); - fMessenger->DeclareMethod("Interactive", &RMGManager::SetInteractive) .SetGuidance("Enable interactive mode") .SetParameterName("flag", true) diff --git a/src/RMGPhysics.cc b/src/RMGPhysics.cc index 981f0af..9b98bf5 100644 --- a/src/RMGPhysics.cc +++ b/src/RMGPhysics.cc @@ -359,12 +359,12 @@ void RMGPhysics::DefineCommands() { fMessenger->DeclareProperty("OpticalPhysics", fConstructOptical) .SetGuidance("Add optical processes to the physics list") - .SetStates(G4State_PreInit, G4State_Idle); + .SetStates(G4State_PreInit); fMessenger->DeclareMethod("LowEnergyEMPhysics", &RMGPhysics::SetLowEnergyEMOptionString) .SetGuidance("Add low energy electromagnetic processes to the physics list") .SetCandidates(RMGTools::GetCandidates()) - .SetStates(G4State_PreInit, G4State_Idle); + .SetStates(G4State_PreInit); fMessenger->DeclareMethod("EnableGammaAngularCorrelation", &RMGPhysics::SetUseGammaAngCorr) .SetGuidance("") diff --git a/src/remage.cc b/src/remage.cc index 9ddbea9..bb1d3ea 100644 --- a/src/remage.cc +++ b/src/remage.cc @@ -19,11 +19,8 @@ #include "RMGHardware.hh" #include "RMGLog.hh" #include "RMGManager.hh" +#include "RMGTools.hh" -#ifndef FMT_HEADER_ONLY -#define FMT_HEADER_ONLY -#endif -#include "fmt/core.h" #include "magic_enum/magic_enum.hpp" namespace CLI { @@ -56,8 +53,7 @@ int main(int argc, char** argv) { std::string output; RMGLog::LogLevel loglevel = RMGLog::summary; - auto log_level_strings = magic_enum::enum_names(); - auto log_level_desc = fmt::format("Logging level {}", fmt::join(log_level_strings, "|")); + auto log_level_desc = "Logging level " + RMGTools::GetCandidates('|'); app.add_flag("-q", quiet, "Print only warnings and errors"); app.add_flag("-v", verbosity, "Increase verbosity");