Nonlocal: Raw -> Smart Pointers. Improved config of standalone dump_nonlocal_field.
This commit is contained in:
parent
fb8ca28ea3
commit
2eec7bd182
30
src/external/Nonlocal/PNL_PippardFitter.cpp
vendored
30
src/external/Nonlocal/PNL_PippardFitter.cpp
vendored
@ -31,6 +31,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include <TSAXParser.h>
|
||||
#include <TMath.h>
|
||||
@ -52,14 +53,14 @@ PNL_PippardFitterGlobal::PNL_PippardFitterGlobal()
|
||||
{
|
||||
// read XML startup file
|
||||
char startup_path_name[128];
|
||||
TSAXParser *saxParser = new TSAXParser();
|
||||
PNL_StartupHandler *fStartupHandler = new PNL_StartupHandler();
|
||||
std::unique_ptr<TSAXParser> saxParser = std::make_unique<TSAXParser>();
|
||||
fStartupHandler = std::make_unique<PNL_StartupHandler>();
|
||||
strcpy(startup_path_name, fStartupHandler->GetStartupFilePath().Data());
|
||||
saxParser->ConnectToHandler("PNL_StartupHandler", fStartupHandler);
|
||||
saxParser->ConnectToHandler("PNL_StartupHandler", fStartupHandler.get());
|
||||
//Int_t status = saxParser->ParseFile(startup_path_name);
|
||||
// parsing the file as above seems to lead to problems in certain environments;
|
||||
// use the parseXmlFile function instead (see PUserFcnBase.cpp for the definition)
|
||||
Int_t status = parseXmlFile(saxParser, startup_path_name);
|
||||
Int_t status = parseXmlFile(saxParser.get(), startup_path_name);
|
||||
// check for parse errors
|
||||
if (status) { // error
|
||||
std::cout << std::endl << ">> PNL_PippardFitterGlobal::PNL_PippardFitterGlobal: **WARNING** Reading/parsing nonlocal_startup.xml failed.";
|
||||
@ -67,14 +68,8 @@ PNL_PippardFitterGlobal::PNL_PippardFitterGlobal()
|
||||
fValid = false;
|
||||
}
|
||||
|
||||
// clean up
|
||||
if (saxParser) {
|
||||
delete saxParser;
|
||||
saxParser = 0;
|
||||
}
|
||||
|
||||
// check if everything went fine with the startup handler
|
||||
if (!fStartupHandler->IsValid()) {
|
||||
if (!fStartupHandler->IsValid() && fValid) {
|
||||
std::cout << std::endl << ">> PNL_PippardFitterGlobal::PNL_PippardFitterGlobal **PANIC ERROR**";
|
||||
std::cout << std::endl << ">> startup handler too unhappy. Will terminate unfriendly, sorry.";
|
||||
std::cout << std::endl;
|
||||
@ -84,13 +79,15 @@ PNL_PippardFitterGlobal::PNL_PippardFitterGlobal()
|
||||
fFourierPoints = fStartupHandler->GetFourierPoints();
|
||||
|
||||
// load all the TRIM.SP rge-files
|
||||
fRgeHandler = new PRgeHandler("./nonlocal_startup.xml");
|
||||
if (fValid) {
|
||||
fRgeHandler = std::make_unique<PRgeHandler>("./nonlocal_startup.xml");
|
||||
if (!fRgeHandler->IsValid()) {
|
||||
std::cout << std::endl << ">> PNL_PippardFitterGlobal::PNL_PippardFitterGlobal **PANIC ERROR**";
|
||||
std::cout << std::endl << ">> rge data handler too unhappy. Will terminate unfriendly, sorry.";
|
||||
std::cout << std::endl;
|
||||
fValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
fPlanPresent = false;
|
||||
fFieldq = 0;
|
||||
@ -124,15 +121,6 @@ PNL_PippardFitterGlobal::~PNL_PippardFitterGlobal()
|
||||
fftw_free(fFieldq);
|
||||
fFieldB = 0;
|
||||
}
|
||||
|
||||
if (fRgeHandler) {
|
||||
delete fRgeHandler;
|
||||
fRgeHandler = 0;
|
||||
}
|
||||
if (fStartupHandler) {
|
||||
delete fStartupHandler;
|
||||
fStartupHandler = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
6
src/external/Nonlocal/PNL_PippardFitter.h
vendored
6
src/external/Nonlocal/PNL_PippardFitter.h
vendored
@ -36,6 +36,8 @@
|
||||
//#endif
|
||||
#include <fftw3.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "PMusr.h"
|
||||
#include "PUserFcnBase.h"
|
||||
#include "PNL_StartupHandler.h"
|
||||
@ -57,8 +59,8 @@ class PNL_PippardFitterGlobal
|
||||
private:
|
||||
Bool_t fValid{true};
|
||||
|
||||
PNL_StartupHandler *fStartupHandler{nullptr};
|
||||
PRgeHandler *fRgeHandler{nullptr};
|
||||
std::unique_ptr<PNL_StartupHandler> fStartupHandler;
|
||||
std::unique_ptr<PRgeHandler> fRgeHandler;
|
||||
|
||||
mutable std::vector<Double_t> fPreviousParam;
|
||||
|
||||
|
4
src/external/Nonlocal/cmake/dnlf_config.h.in
vendored
4
src/external/Nonlocal/cmake/dnlf_config.h.in
vendored
@ -2,3 +2,7 @@
|
||||
|
||||
#define PROJECT_VERSION "@PROJECT_VERSION@"
|
||||
|
||||
#define GIT_BRANCH "@GIT_BRANCH@"
|
||||
#define GIT_CURRENT_SHA1 @GIT_CURRENT_SHA1@
|
||||
|
||||
#define ROOT_VERSION_USED "@ROOT_VERSION_USED@"
|
||||
|
55
src/external/Nonlocal/prog/CMakeLists.txt
vendored
55
src/external/Nonlocal/prog/CMakeLists.txt
vendored
@ -1,23 +1,64 @@
|
||||
#--- dump_nonlocal_field ------------------------------------------------------
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
project(dump_nonlocal_field VERSION 1.0.0 LANGUAGES C CXX)
|
||||
|
||||
#--- check for git ------------------------------------------------------------
|
||||
find_package(Git REQUIRED)
|
||||
|
||||
#--- check for ROOT -----------------------------------------------------------
|
||||
find_package(ROOT 6.18 REQUIRED COMPONENTS Gui MathMore Minuit2 XMLParser)
|
||||
if (ROOT_mathmore_FOUND)
|
||||
execute_process(COMMAND root-config --bindir OUTPUT_VARIABLE ROOT_BINDIR)
|
||||
string(STRIP ${ROOT_BINDIR} ROOT_BINDIR)
|
||||
execute_process(COMMAND root-config --version OUTPUT_VARIABLE ROOT_VERSION_USED)
|
||||
string(STRIP ${ROOT_VERSION_USED} ROOT_VERSION_USED)
|
||||
execute_process(COMMAND root-config --incdir OUTPUT_VARIABLE ROOT_INC)
|
||||
string(STRIP ${ROOT_INC} ROOT_INC)
|
||||
message("-- Found ROOT: ${ROOT_BINDIR} (found version: ${ROOT_VERSION})")
|
||||
#---Define useful ROOT functions and macros (e.g. ROOT_GENERATE_DICTIONARY)
|
||||
include(${ROOT_USE_FILE})
|
||||
endif (ROOT_mathmore_FOUND)
|
||||
|
||||
#--- check for boost ----------------------------------------------------------
|
||||
find_package(Boost REQUIRED
|
||||
COMPONENTS
|
||||
system
|
||||
filesystem
|
||||
)
|
||||
message(STATUS "Boost libs: ${Boost_LIBRARIES}")
|
||||
|
||||
#--- check for fftw3 ----------------------------------------------------------
|
||||
#find_package(FFTW3 REQUIRED)
|
||||
|
||||
# Get the current working branch
|
||||
execute_process(
|
||||
COMMAND git rev-parse --abbrev-ref HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_BRANCH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
# Get the latest abbreviated commit hash of the working branch
|
||||
execute_process(
|
||||
COMMAND git log -1 --pretty="%h, %ci"
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_CURRENT_SHA1
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
|
||||
#--- feed dnlf_config.h -----------------------------------------
|
||||
set(HAVE_DNLF_CONFIG_H 1 CACHE INTERNAL "dnlf_config.h is available")
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/dnlf_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/dnlf_config.h)
|
||||
|
||||
#--- start create git-revision.h ----------------------------------------------
|
||||
if (IS_GIT_REPO)
|
||||
set(HAVE_GIT_REV_H "-DHAVE_GIT_REV_H")
|
||||
else (IS_GIT_REPO)
|
||||
set(HAVE_GIT_REV_H "")
|
||||
endif (IS_GIT_REPO)
|
||||
|
||||
add_executable(dump_nonlocal_field dump_nonlocal_field.cpp)
|
||||
target_compile_options(dump_nonlocal_field BEFORE PRIVATE "-DHAVE_CONFIG_H" "-DHAVE_DNLF_CONFIG_H" "${HAVE_GIT_REV_H}")
|
||||
target_include_directories(dump_nonlocal_field
|
||||
BEFORE PRIVATE
|
||||
$<BUILD_INTERFACE:${Boost_INCLUDE_DIR}>
|
||||
$<BUILD_INTERFACE:${ROOT_INC}>
|
||||
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
|
||||
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/src>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
|
||||
|
@ -38,15 +38,9 @@
|
||||
|
||||
#include "PNL_PippardFitter.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
#ifdef HAVE_DNLF_CONFIG_H
|
||||
#include "dnlf_config.h"
|
||||
#endif
|
||||
#ifdef HAVE_GIT_REV_H
|
||||
#include "git-revision.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
@ -202,18 +196,10 @@ int main(int argc, char* argv[])
|
||||
if (argv[i][0] != '-') { // must be the msr-file name
|
||||
msrFileName = argv[i];
|
||||
} else if (!strcmp(argv[i], "--version")) {
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#ifdef HAVE_GIT_REV_H
|
||||
std::cout << std::endl << "dump_nonlocal_field version: " << PROJECT_VERSION << " (" << PACKAGE_VERSION << "), git-branch: " << GIT_BRANCH << ", git-rev: " << GIT_CURRENT_SHA1 << " (" << BUILD_TYPE << "), ROOT version: " << ROOT_VERSION_USED << std::endl << std::endl;
|
||||
#ifdef HAVE_DNLF_CONFIG_H
|
||||
std::cout << std::endl << "dump_nonlocal_field version: " << PROJECT_VERSION << ", git-branch: " << GIT_BRANCH << ", git-rev: " << GIT_CURRENT_SHA1 << ", ROOT version: " << ROOT_VERSION_USED << std::endl << std::endl;
|
||||
#else
|
||||
std::cout << std::endl << "dump_nonlocal_field version: " << PROJECT_VERSION << " (" << PACKAGE_VERSION << "/" << BUILD_TYPE << "), ROOT version: " << ROOT_VERSION_USED << std::endl << std::endl;
|
||||
#endif
|
||||
#else
|
||||
#ifdef HAVE_GIT_REV_H
|
||||
std::cout << std::endl << "dump_nonlocal_field git-branch: " << GIT_BRANCH << ", git-rev: " << GIT_CURRENT_SHA1 << std::endl << std::endl;
|
||||
#else
|
||||
std::cout << std::endl << "dump_nonlocal_field version: unknown" << std::endl << std::endl;
|
||||
#endif
|
||||
std::cout << std::endl << "dump_nonlocal_field version: " << PROJECT_VERSION << ", ROOT version: " << ROOT_VERSION_USED << std::endl << std::endl;
|
||||
#endif
|
||||
return 0;
|
||||
} else if (!strcmp(argv[i], "--help")) {
|
||||
@ -260,14 +246,17 @@ int main(int argc, char* argv[])
|
||||
|
||||
// calculate field and write it to file
|
||||
PNL_PippardFitterGlobal pip;
|
||||
if (pip.IsValid())
|
||||
pip.CalculateField(param);
|
||||
else
|
||||
return -3;
|
||||
|
||||
std::ofstream fout(outFileName.c_str(), std::ofstream::out);
|
||||
if (!fout.is_open()) {
|
||||
std::cout << std::endl;
|
||||
std::cerr << "**ERROR** can not write to file '" << outFileName << "'." << std::endl;
|
||||
std::cout << std::endl;
|
||||
return -3;
|
||||
return -4;
|
||||
}
|
||||
// write header
|
||||
fout << "% z (nm), field (G)" << std::endl;
|
||||
|
Loading…
x
Reference in New Issue
Block a user