Advanced Computing Platform for Theoretical Physics

Commit b1f90170 authored by Yu-Chen Ding's avatar Yu-Chen Ding
Browse files

fix dlclose(); add crmc.param logic

parent 5eb23d35
......@@ -146,6 +146,9 @@ SET (CRMC_HEADERS
${CMAKE_BINARY_DIR}/src/CRMCconfig.h
${CMAKE_BINARY_DIR}/src/CRMCinterface.h)
include(GNUInstallDirs)
SET(CRMC_PARAM_DEFAULT ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SYSCONFDIR}/crmc.param)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
......
......@@ -3,6 +3,8 @@
#define CRMC_VERSION_MAJOR @CRMC_VERSION_MAJOR@
#define CRMC_VERSION_MINOR @CRMC_VERSION_MINOR@
#define CRMC_PARAM_DEFAULT "@CRMC_PARAM_DEFAULT@"
#cmakedefine CRMC_STATIC
#cmakedefine CRMC_EPOS
......
......@@ -229,7 +229,7 @@ void CRMCoptions::ParseOptions(int argc, char **argv)
else
{
fOutputMode = eNone;
OutputPolicyNone::dlname = om;
OutputPolicyNone::dl_filename = om;
}
// check if either sqrt(s) or the momenta option was used
......@@ -286,6 +286,10 @@ void CRMCoptions::ParseOptions(int argc, char **argv)
fParamFileName = config.getValue();
fParamFileName += ' '; // space needed at the end for Fortran command "index". "trim"
// needs f90 therefore not used here
} else {
if (!std::ifstream("crmc.param")) {
fParamFileName = CRMC_PARAM_DEFAULT " ";
}
}
if (out.isSet())
......
......@@ -16,13 +16,13 @@
using namespace std;
std::string OutputPolicyNone::dlname = "";
std::string OutputPolicyNone::dl_filename = "";
typedef decltype(OutputPolicyNone::pAfterburner) (*_factory_t)(void);
void OutputPolicyNone::InitOutput(const CRMCoptions& cfg) {
pAfterburner.reset();
if (!dlname.empty()) {
void* dl_handle = dlopen(dlname.c_str(), RTLD_NOW);
if (!dl_filename.empty()) {
void* dl_handle = dlopen(dl_filename.c_str(), RTLD_NOW);
if (!dl_handle) {
throw std::runtime_error(
std::string("cannot load dynamic object: ") + dlerror());
......@@ -32,10 +32,9 @@ void OutputPolicyNone::InitOutput(const CRMCoptions& cfg) {
dlclose(dl_handle);
throw std::runtime_error("symbol '" __CRMC_AFTERBURNER_STRING
"' not found in dynamic objcet '" +
dlname + "'");
dl_filename + "'");
}
pAfterburner = factory();
dlclose(dl_handle);
pAfterburner->InitOutput(cfg);
}
}
......@@ -49,9 +48,14 @@ void OutputPolicyNone::FillEvent(const CRMCoptions& cfg, const int nEvent) {
void OutputPolicyNone::CloseOutput(const CRMCoptions& cfg) {
if (pAfterburner) {
pAfterburner->CloseOutput(cfg);
pAfterburner.reset();
} else if (cfg.fCSMode) {
PrintCrossSections(cfg);
}
if (dl_handle) {
dlclose(dl_handle);
dl_handle = nullptr;
}
}
void OutputPolicyNone::PrintCrossSections(const CRMCoptions& cfg) {
......
......@@ -7,7 +7,7 @@
class CRMCoptions;
// new dynamic policy is inserted into original class OutputPolicyNone,
// in this way we expect minimum code conflicts in future updates
// in this way we expect minimum code conflicts in future upstream updates
class OutputPolicyAfterburner {
public:
......@@ -17,9 +17,9 @@ class OutputPolicyAfterburner {
};
class OutputPolicyNone {
public:
static std::string dlname;
static std::string dl_filename;
void* dl_handle = nullptr;
std::unique_ptr<OutputPolicyAfterburner> pAfterburner = nullptr;
void InitOutput(const CRMCoptions& cfg);
......
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