From 6eff5903cde141d5914f6f1492a86295a4496aa8 Mon Sep 17 00:00:00 2001 From: gwm17 Date: Thu, 14 Jul 2022 17:10:14 -0400 Subject: [PATCH] Switch to using YAML as our input config format, added yaml-cpp submodule --- .gitignore | 1 + .gitmodules | 3 +++ src/evb/CMakeLists.txt | 13 +++++++++--- src/evb/EVBApp.cpp | 47 +++++++++++++++++++++++++++++++++++++++--- vendor/yaml-cpp | 1 + 5 files changed, 59 insertions(+), 6 deletions(-) create mode 160000 vendor/yaml-cpp diff --git a/.gitignore b/.gitignore index 311cbc7..0ea703f 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ build/ *.sublime-project *.sublime-workspace *.make +*.yaml Makefile event_log.txt .DS_Store diff --git a/.gitmodules b/.gitmodules index 18a8e2a..9ff459d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "vendor/spdlog"] path = vendor/spdlog url = https://github.com/gabime/spdlog.git +[submodule "vendor/yaml-cpp"] + path = vendor/yaml-cpp + url = https://github.com/jbeder/yaml-cpp.git diff --git a/src/evb/CMakeLists.txt b/src/evb/CMakeLists.txt index 86b2cf8..610d6f2 100644 --- a/src/evb/CMakeLists.txt +++ b/src/evb/CMakeLists.txt @@ -1,6 +1,10 @@ add_library(EventBuilderCore STATIC) -target_include_directories(EventBuilderCore SYSTEM PUBLIC ../../vendor/spdlog/include ${ROOT_INCLUDE_DIRS} - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../ +target_include_directories(EventBuilderCore + SYSTEM PUBLIC ../../vendor/spdlog/include + ${ROOT_INCLUDE_DIRS} + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../ + ../../vendor/yaml-cpp/include ) target_precompile_headers(EventBuilderCore PRIVATE ../EventBuilder.h) @@ -34,6 +38,9 @@ target_sources(EventBuilderCore PRIVATE target_link_libraries(EventBuilderCore PUBLIC EVBDict ${ROOT_LIBRARIES} + yaml-cpp ) -set_target_properties(EventBuilderCore PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${EVB_LIBRARY_DIR}) \ No newline at end of file +set_target_properties(EventBuilderCore PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${EVB_LIBRARY_DIR}) + +target_compile_definitions(EventBuilderCore PRIVATE YAML_CPP_STATIC_DEFINE) \ No newline at end of file diff --git a/src/evb/EVBApp.cpp b/src/evb/EVBApp.cpp index f5dd5f0..5951a7a 100644 --- a/src/evb/EVBApp.cpp +++ b/src/evb/EVBApp.cpp @@ -9,6 +9,7 @@ #include "EVBApp.h" #include "CompassRun.h" #include "SlowSort.h" +#include "yaml-cpp/yaml.h" namespace EventBuilder { @@ -47,6 +48,33 @@ namespace EventBuilder { bool EVBApp::ReadConfigFile(const std::string& fullpath) { EVB_INFO("Reading in EVB configuration from file {0}...", fullpath); + + YAML::Node data; + try + { + data = YAML::LoadFile(fullpath); + } + catch(YAML::ParserException& e) + { + EVB_ERROR("Read of EVB config failed, unable to open input file!"); + return false; + } + + m_params.workspaceDir = data["WorkspaceDir"].as(); + m_params.scalerFile = data["ScalerFile"].as(); + m_params.timeShiftFile = data["TimeShiftFile"].as(); + m_params.slowCoincidenceWindow = data["SlowCoincidenceWindow(ps)"].as(); + m_params.runMin = data["MinRun"].as(); + m_params.runMax = data["MaxRun"].as(); + m_params.bufferSize = data["BufferSize(hits)"].as(); + + m_workspace.reset(new EVBWorkspace(m_params.workspaceDir)); + if(!m_workspace->IsValid()) + { + EVB_ERROR("Unable to process input configuration due to bad workspace."); + return false; + } + /* std::ifstream input(fullpath); if(!input.is_open()) { @@ -80,7 +108,7 @@ namespace EventBuilder { input>>junk>>m_params.bufferSize; input.close(); - + */ EVB_INFO("Successfully loaded EVB config."); return true; @@ -96,7 +124,20 @@ namespace EventBuilder { EVB_WARN("Failed to write to config to file {0}, unable to open file!", fullpath); return; } - + + YAML::Emitter yamlStream; + yamlStream << YAML::BeginMap; + yamlStream << YAML::Key << "WorkspaceDir" << YAML::Value << m_params.workspaceDir; + yamlStream << YAML::Key << "ScalerFile" << YAML::Value << m_params.scalerFile; + yamlStream << YAML::Key << "TimeShiftFile" << YAML::Value << m_params.timeShiftFile; + yamlStream << YAML::Key << "SlowCoincidenceWindow(ps)" << YAML::Value << m_params.slowCoincidenceWindow; + yamlStream << YAML::Key << "MinRun" << YAML::Value << m_params.runMin; + yamlStream << YAML::Key << "MaxRun" << YAML::Value << m_params.runMax; + yamlStream << YAML::Key << "BufferSize(hits)" << YAML::Value << m_params.bufferSize; + yamlStream << YAML::EndMap; + + output << yamlStream.c_str(); + /* output<<"-------Data Location----------"<