Skip to content

Commit

Permalink
Merge pull request #67 from ManuelHu/misc-fixes
Browse files Browse the repository at this point in the history
Misc fixes
  • Loading branch information
gipert authored Apr 5, 2024
2 parents ffd717a + 40d35ae commit 3589d05
Show file tree
Hide file tree
Showing 24 changed files with 76 additions and 98 deletions.
4 changes: 2 additions & 2 deletions cmake/RMGConfig.hh.in
Original file line number Diff line number Diff line change
@@ -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_<DRIVER>
Expand Down
4 changes: 2 additions & 2 deletions include/RMGEventAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#ifndef _RMG_MANAGEMENT_EVENT_ACTION_HH_
#define _RMG_MANAGEMENT_EVENT_ACTION_HH_
#ifndef _RMG_EVENT_ACTION_HH_
#define _RMG_EVENT_ACTION_HH_

#include <memory>

Expand Down
4 changes: 2 additions & 2 deletions include/RMGGeneratorG4Gun.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#ifndef _RMGGENERATORG4GUN_HH_
#define _RMGGENERATORG4GUN_HH_
#ifndef _RMG_GENERATOR_G4GUN_HH_
#define _RMG_GENERATOR_G4GUN_HH_

#include <memory>

Expand Down
5 changes: 2 additions & 3 deletions include/RMGHardware.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#ifndef _RMG_MANAGEMENT_DETECTOR_CONSTRUCTION_HH_
#define _RMG_MANAGEMENT_DETECTOR_CONSTRUCTION_HH_
#ifndef _RMG_HARDWARE_HH_
#define _RMG_HARDWARE_HH_

#include <map>
#include <memory>
Expand Down Expand Up @@ -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<std::string, int> det) {
return fDetectorMetadata.at(det);
Expand Down
2 changes: 2 additions & 0 deletions include/RMGHardwareMessenger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class RMGHardwareMessenger : public G4UImessenger {

RMGHardware* fHardware;
G4UIcommand* fRegisterCmd;

void RegisterDetectorCmd(const std::string& parameters);
};

#endif
Expand Down
4 changes: 2 additions & 2 deletions include/RMGLog.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Modified by Luigi Pertoldi <[email protected]> in 2022

#ifndef _RMGLOG_HH_
#define _RMGLOG_HH_
#ifndef _RMG_LOG_HH_
#define _RMG_LOG_HH_

/**
* @class RMGLog
Expand Down
4 changes: 2 additions & 2 deletions include/RMGMasterGenerator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#ifndef _RMG_GENERATOR_PRIMARY_HH_
#define _RMG_GENERATOR_PRIMARY_HH_
#ifndef _RMG_MASTER_GENERATOR_HH_
#define _RMG_MASTER_GENERATOR_HH_

#include <memory>

Expand Down
4 changes: 2 additions & 2 deletions include/RMGPhysics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#ifndef _RMG_PROCESSES_LIST_HH_
#define _RMG_PROCESSES_LIST_HH_
#ifndef _RMG_PHYSICS_HH_
#define _RMG_PHYSICS_HH_

#include <map>
#include <memory>
Expand Down
4 changes: 2 additions & 2 deletions include/RMGRunAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#ifndef _RMG_MANAGEMENT_RUN_ACTION_HH_
#define _RMG_MANAGEMENT_RUN_ACTION_HH_
#ifndef _RMG_RUN_ACTION_HH_
#define _RMG_RUN_ACTION_HH_

#include <chrono>
#include <map>
Expand Down
4 changes: 2 additions & 2 deletions include/RMGStackingAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#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"

Expand Down
4 changes: 2 additions & 2 deletions include/RMGSteppingAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#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"

Expand Down
13 changes: 1 addition & 12 deletions include/RMGTools.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,7 @@
#ifndef _RMG_TOOLS_HH_
#define _RMG_TOOLS_HH_

#include <chrono>
#include <ctime>
#include <memory>
#include <utility>
#include <vector>

namespace RMGTools {

template<typename T> T ToEnum(std::string);

template<typename T> std::string GetCandidates();
} // namespace RMGTools
namespace RMGTools {} // namespace RMGTools

#include "RMGTools.icc"

Expand Down
4 changes: 2 additions & 2 deletions include/RMGTools.icc
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ namespace RMGTools {
}

template <typename T>
std::string GetCandidates() {
std::string GetCandidates(const char delim=' ') {
auto v = magic_enum::enum_names<T>();
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);
}
Expand Down
4 changes: 2 additions & 2 deletions include/RMGTrackingAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#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"

Expand Down
4 changes: 2 additions & 2 deletions include/RMGUserAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#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"

Expand Down
4 changes: 2 additions & 2 deletions include/RMGVGenerator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#ifndef _RMGVGENERATOR_HH_
#define _RMGVGENERATOR_HH_
#ifndef _RMG_V_GENERATOR_HH_
#define _RMG_V_GENERATOR_HH_

#include <memory>

Expand Down
4 changes: 2 additions & 2 deletions include/RMGVOutputScheme.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#ifndef _RMG_OUTPUT_SCHEME_HH_
#define _RMG_OUTPUT_SCHEME_HH_
#ifndef _RMG_V_OUTPUT_SCHEME_HH_
#define _RMG_V_OUTPUT_SCHEME_HH_

#include <map>
#include <string>
Expand Down
4 changes: 2 additions & 2 deletions include/RMGVVertexGenerator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#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
Expand Down
4 changes: 2 additions & 2 deletions include/RMGVertexFromFile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#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 <memory>
#include <string>
Expand Down
20 changes: 0 additions & 20 deletions src/RMGHardware.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<DetectorType>(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<G4GenericMessenger>(this, "/RMG/Geometry/",
Expand Down
53 changes: 35 additions & 18 deletions src/RMGHardwareMessenger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,55 @@

#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<RMGHardware::DetectorType>();
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<RMGHardware::DetectorType>().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);
}

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<RMGHardware::DetectorType>(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
5 changes: 0 additions & 5 deletions src/RMGManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,6 @@ void RMGManager::DefineCommands() {
fMessenger = std::make_unique<G4GenericMessenger>(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)
Expand Down
4 changes: 2 additions & 2 deletions src/RMGPhysics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<RMGPhysics::LowEnergyEMOption>())
.SetStates(G4State_PreInit, G4State_Idle);
.SetStates(G4State_PreInit);

fMessenger->DeclareMethod("EnableGammaAngularCorrelation", &RMGPhysics::SetUseGammaAngCorr)
.SetGuidance("")
Expand Down
8 changes: 2 additions & 6 deletions src/remage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<RMGLog::LogLevel>();
auto log_level_desc = fmt::format("Logging level {}", fmt::join(log_level_strings, "|"));
auto log_level_desc = "Logging level " + RMGTools::GetCandidates<RMGLog::LogLevel>('|');

app.add_flag("-q", quiet, "Print only warnings and errors");
app.add_flag("-v", verbosity, "Increase verbosity");
Expand Down

0 comments on commit 3589d05

Please sign in to comment.