diff --git a/CMakeLists.txt b/CMakeLists.txt
index 284f985..068cf84 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,190 +1,196 @@
# Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
################################################################################
# This file is part of NUISANCE.
#
# NUISANCE is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# NUISANCE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NUISANCE. If not, see .
################################################################################
cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
project(NUISANCE)
include(ExternalProject)
enable_language(Fortran)
set (NUISANCE_VERSION_MAJOR 1)
set (NUISANCE_VERSION_MINOR 0)
set (NUISANCE_VERSION_REVISION 0)
set (NUISANCE_VERSION_STRING "v${NUISANCE_VERSION_MAJOR}r${NUISANCE_VERSION_MINOR}")
if(${NUISANCE_VERSION_REVISION} STRGREATER "0")
set (NUISANCE_VERSION_STRING "${NUISANCE_VERSION_STRING}p${NUISANCE_VERSION_REVISION}")
endif()
#Set this to TRUE to enable build debugging messages
set(BUILD_DEBUG_MSGS TRUE)
include(${CMAKE_SOURCE_DIR}/cmake/cmessage.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/cacheVariables.cmake)
cmessage(STATUS "CMAKE_INSTALL_PREFIX: \"${CMAKE_INSTALL_PREFIX}\"")
cmessage(STATUS "CMAKE_BUILD_TYPE: \"${CMAKE_BUILD_TYPE}\"")
################################################################################
# Check Dependencies
################################################################################
################################## ROOT ######################################
include(${CMAKE_SOURCE_DIR}/cmake/ROOTSetup.cmake)
################################# HEPMC ######################################
include(${CMAKE_SOURCE_DIR}/cmake/HepMC.cmake)
############################ Reweight Engines ################################
include(${CMAKE_SOURCE_DIR}/cmake/ReweightEnginesSetup.cmake)
############################ Other Generators ################################
include(${CMAKE_SOURCE_DIR}/cmake/GiBUUSetup.cmake)
if(USE_NUANCE)
LIST(APPEND EXTRA_CXX_FLAGS -D__NUANCE_ENABLED__)
endif()
################################# Pythia6/8 ####################################
include(${CMAKE_SOURCE_DIR}/cmake/pythia6Setup.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/pythia8Setup.cmake)
################################# gperftools ###################################
include(${CMAKE_SOURCE_DIR}/cmake/gperfSetup.cmake)
if(NOT NOTEST)
enable_testing()
endif()
SET(GENERATOR_SUPPORT)
foreach(gen NEUT;NuWro;GENIE;GiBUU;NUANCE)
if(USE_${gen})
SET(GENERATOR_SUPPORT "${GENERATOR_SUPPORT}${gen} ")
endif()
endforeach(gen)
cmessage(STATUS "Generator Input Support: ${GENERATOR_SUPPORT}")
set(MINCODE
Routines
FCN)
set(CORE
MCStudies
Genie
FitBase
+ Config
+ Logger
+ Statistical
InputHandler
Splines
- Reweight
+ Reweight
Utils
#Devel
Smearceptance
)
LIST(APPEND ALLEXPERIMENTS
ANL
ArgoNeuT
BEBC
BNL
Electron
FNAL
GGM
K2K
MINERvA
MiniBooNE
SciBooNE
T2K)
foreach(exp ${ALLEXPERIMENTS})
if(NOT NO_${exp})
LIST(APPEND EXPERIMENTS_TO_BUILD ${exp})
else()
LIST(REVERSE EXTRA_CXX_FLAGS)
LIST(APPEND EXTRA_CXX_FLAGS -D__NO_${exp}__)
LIST(REVERSE EXTRA_CXX_FLAGS)
endif()
endforeach()
################################## COMPILER ####################################
include(${CMAKE_SOURCE_DIR}/cmake/c++CompilerSetup.cmake)
################################### doxygen ###################################
include(${CMAKE_SOURCE_DIR}/cmake/docsSetup.cmake)
################################################################################
set(MINIMUM_INCLUDE_DIRECTORIES)
LIST(APPEND MINIMUM_INCLUDE_DIRECTORIES
${RWENGINE_INCLUDE_DIRECTORIES}
${CMAKE_SOURCE_DIR}/src/FitBase
${CMAKE_SOURCE_DIR}/src/Reweight
${CMAKE_SOURCE_DIR}/src/InputHandler
+ ${CMAKE_SOURCE_DIR}/src/Config
+ ${CMAKE_SOURCE_DIR}/src/Logger
+ ${CMAKE_SOURCE_DIR}/src/Statistical
${CMAKE_SOURCE_DIR}/src/Splines
${CMAKE_SOURCE_DIR}/src/Utils
${CMAKE_SOURCE_DIR}/src/Genie)
cmessage(DEBUG "Base include directories: ${MINIMUM_INCLUDE_DIRECTORIES}")
set(EXP_INCLUDE_DIRECTORIES)
foreach(edir ${EXPERIMENTS_TO_BUILD})
LIST(APPEND EXP_INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/src/${edir})
endforeach()
cmessage(DEBUG "Included experiments: ${EXP_INCLUDE_DIRECTORIES}")
foreach(mdir ${MINCODE})
cmessage (DEBUG "Configuring directory: src/${mdir}")
add_subdirectory(src/${mdir})
endforeach()
foreach(edir ${EXPERIMENTS_TO_BUILD})
cmessage (DEBUG "Configuring directory: src/${edir}")
add_subdirectory(src/${edir})
endforeach()
foreach(cdir ${CORE})
cmessage (DEBUG "Configuring directory: src/${cdir}")
add_subdirectory(src/${cdir})
endforeach()
cmessage(DEBUG "Module targets: ${MODULETargets}")
add_subdirectory(app)
add_subdirectory(src/Tests)
configure_file(cmake/setup.sh.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/setup.sh" @ONLY)
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/setup.sh" DESTINATION
${CMAKE_INSTALL_PREFIX})
install(PROGRAMS
"${PROJECT_SOURCE_DIR}/scripts/nuiscardgen" DESTINATION
bin)
install(PROGRAMS
"${PROJECT_SOURCE_DIR}/scripts/nuissamples" DESTINATION
bin)
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index 878957e..e4e2350 100644
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -1,201 +1,217 @@
# Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
################################################################################
# This file is part of NUISANCE.
#
# NUISANCE is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# NUISANCE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NUISANCE. If not, see .
################################################################################
set(TARGETS_TO_BUILD)
if(USE_MINIMIZER)
add_executable(nuismin nuismin.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuismin)
target_link_libraries(nuismin ${MODULETargets})
target_link_libraries(nuismin ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(nuismin ${ROOT_LIBS})
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(nuismin PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
add_executable(nuissplines nuissplines.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuissplines)
target_link_libraries(nuissplines ${MODULETargets})
target_link_libraries(nuissplines ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(nuissplines ${ROOT_LIBS})
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(nuissplines PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
endif()
include_directories(${RWENGINE_INCLUDE_DIRECTORIES})
include_directories(${CMAKE_SOURCE_DIR}/src/Routines)
include_directories(${CMAKE_SOURCE_DIR}/src/InputHandler)
include_directories(${CMAKE_SOURCE_DIR}/src/Genie)
include_directories(${CMAKE_SOURCE_DIR}/src/FitBase)
include_directories(${CMAKE_SOURCE_DIR}/src/Utils)
+include_directories(${CMAKE_SOURCE_DIR}/src/Config)
+include_directories(${CMAKE_SOURCE_DIR}/src/Logger)
+include_directories(${CMAKE_SOURCE_DIR}/src/Statistical)
include_directories(${CMAKE_SOURCE_DIR}/src/Splines)
include_directories(${CMAKE_SOURCE_DIR}/src/Reweight)
include_directories(${CMAKE_SOURCE_DIR}/src/FCN)
include_directories(${CMAKE_SOURCE_DIR}/src/MCStudies)
include_directories(${CMAKE_SOURCE_DIR}/src/Smearceptance)
include_directories(${EXP_INCLUDE_DIRECTORIES})
if (USE_NuWro AND NOT NUWRO_BUILT_FROM_FILE)
add_executable(nuwro_nuisance nuwro_NUISANCE.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuwro_nuisance)
target_link_libraries(nuwro_nuisance ${MODULETargets})
target_link_libraries(nuwro_nuisance ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(nuwro_nuisance ${ROOT_LIBS})
include_directories(${CMAKE_SOURCE_DIR}/src/FitBase)
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(nuwro_nuisance PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
endif()
if (USE_NEUT)
add_executable(neut_nuisance neut_NUISANCE.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};neut_nuisance)
target_link_libraries(neut_nuisance ${MODULETargets})
target_link_libraries(neut_nuisance ${CMAKE_DEPENDLIB_FLAGS})
target_link_libraries(neut_nuisance ${ROOT_LIBS})
include_directories(${CMAKE_SOURCE_DIR}/src/FitBase)
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(neut_nuisance PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
endif()
if (BUILD_GEVGEN)
add_executable(gevgen_nuisance gEvGen_NUISANCE.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};gevgen_nuisance)
target_link_libraries(gevgen_nuisance ${MODULETargets})
target_link_libraries(gevgen_nuisance ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(gevgen_nuisance ${ROOT_LIBS})
include_directories(${CMAKE_SOURCE_DIR}/src/FitBase)
include_directories(${GENIE_INCLUDES}/Apps)
include_directories(${GENIE_INCLUDES}/FluxDrivers)
include_directories(${GENIE_INCLUDES}/EVGDrivers)
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(gevgen_nuisance PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
add_executable(gevgen_nuisance_mixed gEvGen_NUISANCE_MIXED.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};gevgen_nuisance_mixed)
target_link_libraries(gevgen_nuisance_mixed ${MODULETargets})
target_link_libraries(gevgen_nuisance_mixed ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(gevgen_nuisance_mixed ${ROOT_LIBS})
include_directories(${CMAKE_SOURCE_DIR}/src/FitBase)
include_directories(${GENIE_INCLUDES}/Apps)
include_directories(${GENIE_INCLUDES}/FluxDrivers)
include_directories(${GENIE_INCLUDES}/EVGDrivers)
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(gevgen_nuisance_mixed PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
endif()
if (USE_GiBUU)
add_executable(DumpGiBUUEvents DumpGiBUUEvents.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};DumpGiBUUEvents)
target_link_libraries(DumpGiBUUEvents ${MODULETargets})
target_link_libraries(DumpGiBUUEvents ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(DumpGiBUUEvents ${ROOT_LIBS})
include_directories(${CMAKE_SOURCE_DIR}/src/FitBase)
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(DumpGiBUUEvents PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
endif()
add_executable(nuiscomp nuiscomp.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuiscomp)
target_link_libraries(nuiscomp ${MODULETargets})
target_link_libraries(nuiscomp ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(nuiscomp ${ROOT_LIBS})
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(nuiscomp PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
add_executable(nuisflat nuisflat.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuisflat)
target_link_libraries(nuisflat ${MODULETargets})
target_link_libraries(nuisflat ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(nuisflat ${ROOT_LIBS})
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(nuisflat PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
add_executable(nuissmear nuissmear.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuissmear)
target_link_libraries(nuissmear ${MODULETargets})
target_link_libraries(nuissmear ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(nuissmear ${ROOT_LIBS})
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(nuissmear PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
add_executable(nuissyst nuissyst.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuissyst)
target_link_libraries(nuissyst ${MODULETargets})
target_link_libraries(nuissyst ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(nuissyst ${ROOT_LIBS})
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(nuissyst PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
add_executable(nuisbayes nuisbayes.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};nuisbayes)
target_link_libraries(nuisbayes ${MODULETargets})
target_link_libraries(nuisbayes ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(nuisbayes ${ROOT_LIBS})
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(nuisbayes PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
if(USE_GENIE)
add_executable(PrepareGENIE PrepareGENIE.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};PrepareGENIE)
target_link_libraries(PrepareGENIE ${MODULETargets})
target_link_libraries(PrepareGENIE ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(PrepareGENIE ${ROOT_LIBS})
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(PrepareGENIE PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
endif()
if(USE_NEUT)
add_executable(PrepareNEUT PrepareNEUT.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};PrepareNEUT)
target_link_libraries(PrepareNEUT ${MODULETargets})
target_link_libraries(PrepareNEUT ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(PrepareNEUT ${ROOT_LIBS})
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(PrepareNEUT PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
endif()
# PREPARE NUWRO
# Commented out for the time being until it is finished..
if(USE_NuWro)
add_executable(PrepareNuwro PrepareNuwroEvents.cxx)
set(TARGETS_TO_BUILD ${TARGETS_TO_BUILD};PrepareNuwro)
target_link_libraries(PrepareNuwro ${MODULETargets})
target_link_libraries(PrepareNuwro ${CMAKE_DEPENDLIB_FLAGS})
# target_link_libraries(PrepareNuwro ${ROOT_LIBS})
if(NOT "${CMAKE_LINK_FLAGS}" STREQUAL "")
set_target_properties(PrepareNuwro PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
endif()
endif()
install(TARGETS ${TARGETS_TO_BUILD} DESTINATION bin)
+
+#add_executable(DumpROOTClassesFromVector DumpROOTClassesFromVector.cxx)
+# #Strip out -lNuWro_event1
+# string(REPLACE "-lNuWro_event1" "" NWEVSTRIPPED_CDF ${CMAKE_DEPENDLIB_FLAGS})
+# cmessage(DEBUG "Attempted to strip out nuwro library: \"${CMAKE_DEPENDLIB_FLAGS}\" -> \"${NWEVSTRIPPED_CDF}\"")
+# add_executable(PrepareNEUT PrepareNEUT.cxx)
+# target_link_libraries(DumpROOTClassesFromVector ${MODULETargets})
+# target_link_libraries(DumpROOTClassesFromVector ${NWEVSTRIPPED_CDF})
+# if(NOT CMAKE_LINK_FLAGS STREQUAL "")
+# set_target_properties(DumpROOTClassesFromVector PROPERTIES LINK_FLAGS ${CMAKE_LINK_FLAGS})
+# endif()
+#install(TARGETS DumpROOTClassesFromVector DESTINATION bin)
+
diff --git a/src/Utils/DumpROOTClassesFromVector.cxx b/app/DumpROOTClassesFromVector.cxx
similarity index 100%
rename from src/Utils/DumpROOTClassesFromVector.cxx
rename to app/DumpROOTClassesFromVector.cxx
diff --git a/src/FitBase/CMakeLists.txt b/src/Config/CMakeLists.txt
similarity index 73%
copy from src/FitBase/CMakeLists.txt
copy to src/Config/CMakeLists.txt
index 543bcb2..7577b9d 100644
--- a/src/FitBase/CMakeLists.txt
+++ b/src/Config/CMakeLists.txt
@@ -1,72 +1,52 @@
# Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
################################################################################
# This file is part of NUISANCE.
#
# NUISANCE is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# NUISANCE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NUISANCE. If not, see .
################################################################################
-set(IMPLFILES
-ParamPull.cxx
-EventManager.cxx
-Measurement1D.cxx
-Measurement2D.cxx
-JointMeas1D.cxx
-MeasurementBase.cxx
-TemplateMeas1D.cxx
-SampleSettings.cxx
-MeasurementVariableBox.cxx
-MeasurementVariableBox2D.cxx
-MeasurementVariableBox1D.cxx
-CustomVariableBoxes.h
+set(HEADERFILES
+NuisConfig.h
+NuisKey.h
)
-set(HEADERFILES
-ParamPull.h
-JointMeas1D.h
-Measurement2D.h
-EventManager.h
-MeasurementBase.h
-Measurement1D.h
-TemplateMeas1D.h
-SampleSettings.h
-MeasurementVariableBox.h
-MeasurementVariableBox2D.h
-MeasurementVariableBox1D.h
-CustomVariableBoxes.h
+set(IMPLFILES
+NuisConfig.cxx
+NuisKey.cxx
)
-set(LIBNAME FitBase)
+set(LIBNAME Config)
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
add_library(${LIBNAME} STATIC ${IMPLFILES})
else(CMAKE_BUILD_TYPE MATCHES RELEASE)
add_library(${LIBNAME} SHARED ${IMPLFILES})
endif()
include_directories(${MINIMUM_INCLUDE_DIRECTORIES})
-cmessage(DEBUG "FitBase includes: ${MINIMUM_INCLUDE_DIRECTORIES}")
set_target_properties(${LIBNAME} PROPERTIES VERSION
"${NUISANCE_VERSION_MAJOR}.${NUISANCE_VERSION_MINOR}.${NUISANCE_VERSION_REVISION}")
+
#set_target_properties(${LIBNAME} PROPERTIES LINK_FLAGS ${ROOT_LD_FLAGS})
if(DEFINED PROJECTWIDE_EXTRA_DEPENDENCIES)
add_dependencies(${LIBNAME} ${PROJECTWIDE_EXTRA_DEPENDENCIES})
endif()
install(TARGETS ${LIBNAME} DESTINATION lib)
#Can uncomment this to install the headers... but is it really neccessary?
-install(FILES ${HEADERFILES} DESTINATION include)
+#install(FILES ${HEADERFILES} DESTINATION include)
set(MODULETargets ${MODULETargets} ${LIBNAME} PARENT_SCOPE)
diff --git a/src/Utils/NuisConfig.cxx b/src/Config/NuisConfig.cxx
similarity index 99%
rename from src/Utils/NuisConfig.cxx
rename to src/Config/NuisConfig.cxx
index a9f4e80..f015dc6 100644
--- a/src/Utils/NuisConfig.cxx
+++ b/src/Config/NuisConfig.cxx
@@ -1,788 +1,783 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see .
*******************************************************************************/
#include "NuisConfig.h"
#include "TXMLEngine.h"
#include "GeneralUtils.h"
#include "FitLogger.h"
-#include "GeneralUtils.h"
namespace Config {
-nuisconfig& Get() { return nuisconfig::GetConfig(); };
+nuisconfig& Get() {
+ return nuisconfig::GetConfig();
+};
std::string GetPar(std::string name) {
return Get().GetConfig(name);
}
int GetParI(std::string name) {
return Get().GetConfigI(name);
}
bool GetParB(std::string name) {
return Get().GetConfigB(name);
}
+float GetParF(std::string name) {
+ return Get().GetConfigF(name);
+}
double GetParD(std::string name) {
return Get().GetConfigD(name);
}
void SetPar(std::string name, std::string val) {
Get().SetConfig(name, val);
}
void SetPar(std::string name, bool val) {
Get().SetConfig(name, val);
}
void SetPar(std::string name, int val) {
Get().SetConfig(name, val);
}
void SetPar(std::string name, float val) {
Get().SetConfig(name, val);
}
void SetPar(std::string name, double val) {
Get().SetConfig(name, val);
}
+
}
+namespace FitPar {
+ std::string GetDataBase() { return GeneralUtils::GetTopLevelDir() + "/data/"; };
+ nuisconfig& Config() { return Config::Get(); };
+}
nuisconfig* nuisconfig::m_nuisconfigInstance = NULL;
nuisconfig& nuisconfig::GetConfig(void) {
if (!m_nuisconfigInstance) m_nuisconfigInstance = new nuisconfig;
return *m_nuisconfigInstance;
};
// Main Class Definition
nuisconfig::nuisconfig() {
// Load default Parameters
std::string filename = (GeneralUtils::GetTopLevelDir() +
"/parameters/config.xml");
std::cout << "[ NUISANCE ]: Loading DEFAULT settings from : " << filename;
// Create XML Engine
fXML = new TXMLEngine;
fXML->SetSkipComments(true);
// Load in documents
fXMLDocs.push_back(fXML->ParseFile(filename.c_str(), 1000000));
if (!fXMLDocs[0]) {
THROW("Cannot Read Parameters File!");
}
// Setup Main XML Node to be the first file read
fMainNode = fXML->DocGetRootElement(fXMLDocs[0]);
// Print result
std::cout << " -> DONE." << std::endl;
}
nuisconfig::~nuisconfig() {
// Should really delete XML objects here but we don't
}
void nuisconfig::LoadSettings(std::string filename, std::string state) {
// Open file and see if its XML
std::cout << "[ NUISANCE ]: Trying to parse file : " << filename;
StopTalking();
XMLDocPointer_t readdoc = fXML->ParseFile(filename.c_str(), 1000000);
StartTalking();
// If it is parse it as a nice XML config file
if (readdoc) {
std::cout << " -> Found XML file." << std::endl;
LoadXMLSettings(filename, state);
// Otherwise its an old simple card file
} else {
std::cout << " -> Assuming its a simple card file." << std::endl;
LoadCardSettings(filename, state);
}
}
void nuisconfig::LoadXMLSettings(std::string filename, std::string state = "") {
std::cout << "[ NUISANCE ]: Loading XML settings from : " << filename;
// Add new file to xml docs list
fXMLDocs.push_back(fXML->ParseFile(filename.c_str(), 1000000));
// Get New Doc ROOT
int nxml = fXMLDocs.size();
XMLNodePointer_t newdocroot = fXML->DocGetRootElement(fXMLDocs[nxml - 1]);
// Loop over children and add
XMLNodePointer_t child = fXML->GetChild(newdocroot);
// // Here we manually load all the children from the card file into our root node
if (!child){
THROW("CANNOT Find child inside settings file!");
}
while (child != 0) {
// SPECIAL CONFIG CASE
// If its a config node, then remove previous attributes, overriding old value
if (!std::string(fXML->GetNodeName(child)).compare("config")) {
// Loop over attribues
XMLAttrPointer_t attr1 = fXML->GetFirstAttr(child);
while (attr1 != 0) {
// If a valid attribute name is given then compare
if (!GetConfigS(fXML->GetAttrName(attr1)).empty()) {
// Get full list of present configs
std::vector confignodes = GetNodes("config");
// Loop over present configs and compare
for (size_t i = 0; i < confignodes.size(); i++) {
// If we already have this config, free the old attribute
if (fXML->HasAttr(confignodes[i], fXML->GetAttrName(attr1))) {
fXML->FreeAttr(confignodes[i], fXML->GetAttrName(attr1));
break;
}
}
}
// Move onto next config attribute
attr1 = fXML->GetNextAttr(attr1);
}
}
// Add this child to the main config list
fXML->AddChild(fMainNode, child);
// Get Next Child
child = fXML->GetNext(child);
}
std::cout << " -> DONE." << std::endl;
}
void nuisconfig::LoadCardSettings(std::string filename, std::string state) {
std::cout << "[ NUISANCE ]: Loading simple config from : " << filename;
// Build XML Config from the card file by parsing each line
std::vector cardlines =
GeneralUtils::ParseFileToStr(filename, "\n");
int linecount = 0;
// Loop over all input lines
for (std::vector::iterator iter = cardlines.begin();
iter != cardlines.end(); iter++) {
std::string line = (*iter);
linecount++;
// Skip Comments
if (line.empty()) continue;
if (line.c_str()[0] == '#') continue;
// Parse whitespace
std::vector strvct = GeneralUtils::ParseToStr(line, " ");
if (strvct.empty()) continue;
// Get Identifier
std::string id = strvct[0];
// Build backwards compatible xml configs
// Sample structure
if (!id.compare("sample")) {
CreateSampleNodeFromLine(line);
}
// Any parameter structure
if (id.find("_parameter") != std::string::npos) {
CreateParameterNodeFromLine(line);
}
// Any covar structure
if (!id.compare("covar") || !id.compare("pull") || !id.compare("throw")) {
CreatePullNodeFromLine(line);
}
// Any config structure
if (!id.compare("config")) {
CreateOldConfigNodeFromLine(line);
}
}
std::cout << " -> DONE." << std::endl;
}
XMLNodePointer_t nuisconfig::CreateSampleNodeFromLine(const std::string line) {
// Create new node entry
XMLNodePointer_t samplenode = CreateNode("sample");
// Parse line
std::vector strvct = GeneralUtils::ParseToStr(line, " ");
// Add line elements to the node
// name input type norm
if (strvct.size() > 1) Set(samplenode, "name", strvct[1]);
if (strvct.size() > 2) Set(samplenode, "input", strvct[2]);
if (strvct.size() > 3) Set(samplenode, "type", strvct[3]);
if (strvct.size() > 4) Set(samplenode, "norm", strvct[4]);
return samplenode;
}
XMLNodePointer_t nuisconfig::CreateParameterNodeFromLine(const std::string line) {
// Create new node entry
XMLNodePointer_t parnode = CreateNode("parameter");
// Parse line
std::vector strvct = GeneralUtils::ParseToStr(line, " ");
// Add line elements to the node
// type name nominal [low] [high] [step] state
if (strvct.size() > 0) Set(parnode, "type", strvct[0]);
if (strvct.size() > 1) Set(parnode, "name", strvct[1]);
if (strvct.size() > 2) Set(parnode, "nominal", strvct[2]);
// If free structure
if (strvct.size() == 7) {
Set(parnode, "low", strvct[3]);
Set(parnode, "high", strvct[4]);
Set(parnode, "step", strvct[5]);
Set(parnode, "state", strvct[6]);
// Fixed param structure
} else if (strvct.size() == 3) {
Set(parnode, "state", "FIX");
} else if (strvct.size() == 4) {
Set(parnode, "state", strvct[3]);
}
return parnode;
}
XMLNodePointer_t nuisconfig::CreatePullNodeFromLine(const std::string line) {
// Create new node entry
XMLNodePointer_t parnode = CreateNode("covar");
// Parse line
std::vector strvct = GeneralUtils::ParseToStr(line, " ");
// Add line elements to the node
// name input type
if (strvct.size() > 1) Set(parnode, "name", strvct[1]);
if (strvct.size() > 2) Set(parnode, "input", strvct[2]);
if (strvct.size() > 3) Set(parnode, "type", strvct[3]);
return parnode;
}
XMLNodePointer_t nuisconfig::CreateOldConfigNodeFromLine(const std::string line) {
// Create new node entry
XMLNodePointer_t confignode = CreateNode("config");
// Parse line
std::vector strvct = GeneralUtils::ParseToStr(line, " ");
// Add line elements to the node
// name value
if (strvct.size() > 2) Set(confignode, strvct[1], strvct[2]);
return confignode;
}
void nuisconfig::FinaliseSettings(std::string name) {
std::cout << "[ NUISANCE ]: Finalising run settings";
WriteSettings(name);
// Save full config to file
RemoveEmptyNodes();
RemoveIdenticalNodes();
std::cout << " -> DONE." << std::endl;
}
void nuisconfig::WriteSettings(std::string outputname) {
// Create a New XML Doc
XMLDocPointer_t newxmldoc = fXML->NewDoc();
fXML->DocSetRootElement(newxmldoc, fMainNode);
// Save document to file
if (GetConfigB("SaveParsedXMLFile")) {
fXML->SaveDoc(newxmldoc, outputname.c_str());
}
}
-
-
-
-
-
XMLNodePointer_t nuisconfig::CreateNode(std::string name) {
return fXML->NewChild(fMainNode, 0, name.c_str());
}
XMLNodePointer_t nuisconfig::CreateNode(XMLNodePointer_t node, std::string name) {
return fXML->NewChild(node, 0, name.c_str());
}
XMLNodePointer_t nuisconfig::GetNode(XMLNodePointer_t node, std::string type) {
/// Loop over all children
XMLNodePointer_t child = fXML->GetChild(node);
while (child != 0) {
/// Get nodes for given type (if type empty return all)
if (std::string(fXML->GetNodeName(child)) == type.c_str() or type.empty()) {
return child;
}
// Next child
child = fXML->GetNext(child);
}
// Child not found
return 0;
}
void nuisconfig::RemoveEmptyNodes() {
std::vector nodelist = Config::Get().GetNodes();
for (size_t i = 0; i < nodelist.size(); i++) {
if (fXML->IsEmptyNode(nodelist[i])) {
RemoveNode(nodelist[i]);
}
}
}
void nuisconfig::RemoveIdenticalNodes() {
std::vector removed;
// Loop over all nodes and check for identical nodes
std::vector nodelist = Config::Get().GetNodes();
for (size_t i = 0; i < nodelist.size(); i++) {
for (size_t j = 0; j < nodelist.size(); j++) {
XMLNodePointer_t node1 = nodelist[i];
XMLNodePointer_t node2 = nodelist[j];
// Check node already removed.
if (std::find(removed.begin(), removed.end(), node1) != removed.end())
continue;
if (std::find(removed.begin(), removed.end(), node2) != removed.end())
continue;
if (i == j) continue;
// Check matching
if (!MatchingNodes(node1, node2)) continue;
if (std::string(fXML->GetNodeName(node1)).compare("config") and
fXML->IsEmptyNode(node1)) {
// Matching so print out warning
std::cout << "Matching nodes given! Removing node1!" << std::endl
<< "Node 1" << std::endl;
PrintNode(node1);
std::cout << "Node 2" << std::endl;
PrintNode(node2);
}
// Remove node
removed.push_back(node1);
}
}
// Now go through and remove this node.
for (size_t i = 0; i < removed.size(); i++) {
RemoveNode(removed.at(i));
}
return;
}
void nuisconfig::RemoveNode(XMLNodePointer_t node) {
fXML->FreeAllAttr(node);
fXML->CleanNode(node);
fXML->FreeNode(node);
fXML->UnlinkNode(node);
}
void nuisconfig::PrintNode(XMLNodePointer_t node) {
// Print Node Name
std::cout << fXML->GetNodeName(node) << std::endl;
// Loop and print all attributes
XMLAttrPointer_t attr = fXML->GetFirstAttr(node);
while (attr != 0) {
std::cout << " -> " << fXML->GetAttrName(attr) << " : "
<< fXML->GetAttrValue(attr) << std::endl;
attr = fXML->GetNextAttr(attr);
}
}
bool nuisconfig::MatchingNodes(XMLNodePointer_t node1, XMLNodePointer_t node2) {
bool matching = true;
XMLAttrPointer_t attr = fXML->GetFirstAttr(node1);
while (attr != 0) {
if (GetS(node2, fXML->GetAttrName(attr)) != fXML->GetAttrValue(attr))
matching = false;
attr = fXML->GetNextAttr(attr);
}
return matching;
}
XMLNodePointer_t nuisconfig::GetNode(std::string type) {
return GetNode(fMainNode, type);
}
std::vector nuisconfig::GetNodes(XMLNodePointer_t node,
std::string type) {
// Create new vector for nodes
std::vector nodelist;
/// Loop over all children
XMLNodePointer_t child = fXML->GetChild(node);
while (child != 0) {
/// Get nodes for given type (if type empty return all)
if (std::string(fXML->GetNodeName(child)) == type.c_str() or type.empty()) {
nodelist.push_back(child);
}
// Next child
child = fXML->GetNext(child);
}
// return list
return nodelist;
}
std::vector nuisconfig::GetNodes(std::string type) {
return GetNodes(fMainNode, type);
}
void nuisconfig::Set(XMLNodePointer_t node, std::string name, std::string val) {
// Remove and re-add attribute
if (fXML->HasAttr(node, name.c_str())) {
fXML->FreeAttr(node, name.c_str());
}
fXML->NewAttr(node, 0, name.c_str(), val.c_str());
}
void nuisconfig::Set(XMLNodePointer_t node, std::string name, bool val) {
Set(node, name, GeneralUtils::BoolToStr(val));
}
void nuisconfig::Set(XMLNodePointer_t node, std::string name, int val) {
Set(node, name, GeneralUtils::IntToStr(val));
}
void nuisconfig::Set(XMLNodePointer_t node, std::string name, float val) {
Set(node, name, GeneralUtils::DblToStr(val));
}
void nuisconfig::Set(XMLNodePointer_t node, std::string name, double val) {
Set(node, name, GeneralUtils::DblToStr(val));
}
void nuisconfig::SetS(XMLNodePointer_t node, std::string name, std::string val) {
Set(node, name, val);
}
void nuisconfig::SetB(XMLNodePointer_t node, std::string name, bool val) {
Set(node, name, GeneralUtils::BoolToStr(val));
}
void nuisconfig::SetI(XMLNodePointer_t node, std::string name, int val) {
Set(node, name, GeneralUtils::IntToStr(val));
}
void nuisconfig::SetF(XMLNodePointer_t node, std::string name, float val) {
Set(node, name, GeneralUtils::DblToStr(val));
}
void nuisconfig::SetD(XMLNodePointer_t node, std::string name, double val) {
Set(node, name, GeneralUtils::DblToStr(val));
}
bool nuisconfig::Has(XMLNodePointer_t node, std::string name) {
// If node empty return empty
if (node == 0) return false;
// Search attributes
XMLAttrPointer_t attr = fXML->GetFirstAttr(node);
bool found = false;
// Loop over all attributes
while (attr != 0) {
// Find value of correct name
if (std::string(fXML->GetAttrName(attr)) == name.c_str()) {
found = true;
break;
}
// Next Attribute
attr = fXML->GetNextAttr(attr);
}
return found;
}
std::string nuisconfig::Get(XMLNodePointer_t node, std::string name) {
// If node empty return empty
if (node == 0) return "";
// Get Attribute from child with name
XMLAttrPointer_t attr = fXML->GetFirstAttr(node);
std::string temp = "";
// Loop over all attributes
while (attr != 0) {
// If valid match then save
if (std::string(fXML->GetAttrName(attr)) == name.c_str()) {
temp = fXML->GetAttrValue(attr);
}
// Next Attribute
attr = fXML->GetNextAttr(attr);
}
return temp;
}
std::string nuisconfig::GetS(XMLNodePointer_t node, std::string name) {
return Get(node, name);
}
bool nuisconfig::GetB(XMLNodePointer_t node, std::string name) {
std::string tempattr = Get(node, name);
return GeneralUtils::StrToBool(tempattr);
}
int nuisconfig::GetI(XMLNodePointer_t node, std::string name) {
std::string tempattr = Get(node, name);
return GeneralUtils::StrToInt(tempattr);
}
float nuisconfig::GetF(XMLNodePointer_t node, std::string name) {
std::string tempattr = Get(node, name);
return GeneralUtils::StrToDbl(tempattr);
}
double nuisconfig::GetD(XMLNodePointer_t node, std::string name) {
std::string tempattr = Get(node, name);
return GeneralUtils::StrToDbl(tempattr);
}
std::vector nuisconfig::GetVS(XMLNodePointer_t node,
std::string name,
const char* del) {
std::string tempattr = Get(node, name);
return GeneralUtils::ParseToStr(tempattr, del);
}
// std::vector nuisconfig::GetVB(XMLNodePointer_t node,
// std::string name,
// const char* del) {
// std::string tempattr = Get(node, name);
// return GeneralUtils::ParseToBool(tempattr, del);
// }
std::vector nuisconfig::GetVI(XMLNodePointer_t node,
std::string name,
const char* del) {
std::string tempattr = Get(node, name);
return GeneralUtils::ParseToInt(tempattr, del);
}
// std::vector nuisconfig::GetVF(XMLNodePointer_t node,
// std::string name,
// const char* del) {
// std::string tempattr = Get(node, name);
// return GeneralUtils::ParseToDouble(tempattr, del);
// }
std::vector nuisconfig::GetVD(XMLNodePointer_t node,
std::string name,
const char* del) {
std::string tempattr = Get(node, name);
return GeneralUtils::ParseToDbl(tempattr, del);
}
std::vector nuisconfig::GetAllKeysForNode(XMLNodePointer_t node) {
bool matching = true;
XMLAttrPointer_t attr = fXML->GetFirstAttr(node);
std::vector keys;
while (attr != 0) {
if (!std::string(fXML->GetAttrName(attr)).empty()) {
keys.push_back(std::string(fXML->GetAttrName(attr)));
}
attr = fXML->GetNextAttr(attr);
}
return keys;
}
XMLNodePointer_t nuisconfig::GetConfigNode(std::string name) {
// Loop over children and look for name
XMLNodePointer_t child = fXML->GetChild(fMainNode);
while (child != 0) {
// Select only config parameters
if (!std::string(fXML->GetNodeName(child)).compare("config")) {
// Loop over config attributes and search for name
XMLAttrPointer_t attr = fXML->GetFirstAttr(child);
while (attr != 0) {
// Save name value
if (std::string(fXML->GetAttrName(attr)) == name.c_str()) {
return child;
}
// Get Next Attribute
attr = fXML->GetNextAttr(attr);
}
}
// Next Child
child = fXML->GetNext(child);
}
return 0;
}
void nuisconfig::SetConfig(std::string name, std::string val) {
XMLNodePointer_t node = GetConfigNode(name);
if (!node) node = CreateNode("config");
Set(node, name, val);
}
void nuisconfig::SetConfig(std::string name, bool val) {
XMLNodePointer_t node = GetConfigNode(name);
if (!node) node = CreateNode("config");
Set(node, name, val);
}
void nuisconfig::SetConfig(std::string name, int val) {
XMLNodePointer_t node = GetConfigNode(name);
if (!node) node = CreateNode("config");
Set(node, name, val);
}
void nuisconfig::SetConfig(std::string name, float val) {
XMLNodePointer_t node = GetConfigNode(name);
if (!node) node = CreateNode("config");
Set(node, name, val);
}
void nuisconfig::SetConfig(std::string name, double val) {
XMLNodePointer_t node = GetConfigNode(name);
if (!node) node = CreateNode("config");
Set(node, name, val);
}
void nuisconfig::OverrideConfig(std::string conf) {
std::vector opts = GeneralUtils::ParseToStr(conf, "=");
SetConfig(opts[0], opts[1]);
}
std::string nuisconfig::GetConfig(std::string name) {
XMLNodePointer_t node = GetConfigNode(name);
if (!node) return "";
XMLAttrPointer_t attr = fXML->GetFirstAttr(node);
std::string temp = "";
// Loop config attributes
while (attr != 0) {
// Find match
if (std::string(fXML->GetAttrName(attr)) == name.c_str()) {
temp = fXML->GetAttrValue(attr);
}
// Get Next Attribute
attr = fXML->GetNextAttr(attr);
}
return temp;
}
std::string nuisconfig::GetConfigS(const std::string name) {
return GetConfig(name);
}
bool nuisconfig::GetConfigB(const std::string name) {
std::string pars = GetConfig(name);
return GeneralUtils::StrToBool(pars);
}
int nuisconfig::GetConfigI(const std::string name) {
std::string pars = GetConfig(name);
return GeneralUtils::StrToInt(pars);
}
float nuisconfig::GetConfigF(const std::string name) {
std::string pars = GetConfig(name);
return GeneralUtils::StrToDbl(pars);
}
double nuisconfig::GetConfigD(const std::string name) {
std::string pars = GetConfig(name);
return GeneralUtils::StrToDbl(pars);
}
std::string nuisconfig::GetParDIR(std::string parName) {
std::string outstr = this->GetParS(parName);
// Make replacements in the string
const int nfiletypes = 2;
const std::string filetypes[nfiletypes] = {"@data", "@nuisance"};
std::string filerepl[nfiletypes] = { FitPar::GetDataBase(),
FitPar::GetDataBase() + "/../"
};
for (int i = 0; i < nfiletypes; i++) {
std::string findstring = filetypes[i];
std::string replstring = filerepl[i];
if (outstr.find(findstring) != std::string::npos) {
outstr.replace(outstr.find(findstring), findstring.size(), filerepl[i]);
break;
}
}
return outstr;
};
-
-
-
-namespace FitPar {
- std::string GetDataBase() { return GeneralUtils::GetTopLevelDir() + "/data/"; };
- nuisconfig& Config() { return Config::Get(); };
-}
-
-
diff --git a/src/Utils/NuisConfig.h b/src/Config/NuisConfig.h
similarity index 71%
rename from src/Utils/NuisConfig.h
rename to src/Config/NuisConfig.h
index bd2cf9b..1d93029 100644
--- a/src/Utils/NuisConfig.h
+++ b/src/Config/NuisConfig.h
@@ -1,202 +1,184 @@
// Copyright 2016 L. Pickering, P Stowell, R. Terri, C. Wilkinson, C. Wret
/*******************************************************************************
* This file is part of NUISANCE.
*
* NUISANCE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NUISANCE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NUISANCE. If not, see .
*******************************************************************************/
#ifndef NUISCONFIG_H_SEEN
#define NUISCONFIG_H_SEEN
#include
#include