Switch to using YAML as our input config format, added yaml-cpp submodule

This commit is contained in:
Gordon McCann 2022-07-14 17:10:14 -04:00
parent b57c1d4f21
commit 6eff5903cd
5 changed files with 59 additions and 6 deletions

1
.gitignore vendored
View File

@ -16,6 +16,7 @@ build/
*.sublime-project *.sublime-project
*.sublime-workspace *.sublime-workspace
*.make *.make
*.yaml
Makefile Makefile
event_log.txt event_log.txt
.DS_Store .DS_Store

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "vendor/spdlog"] [submodule "vendor/spdlog"]
path = vendor/spdlog path = vendor/spdlog
url = https://github.com/gabime/spdlog.git url = https://github.com/gabime/spdlog.git
[submodule "vendor/yaml-cpp"]
path = vendor/yaml-cpp
url = https://github.com/jbeder/yaml-cpp.git

View File

@ -1,6 +1,10 @@
add_library(EventBuilderCore STATIC) add_library(EventBuilderCore STATIC)
target_include_directories(EventBuilderCore SYSTEM PUBLIC ../../vendor/spdlog/include ${ROOT_INCLUDE_DIRS} target_include_directories(EventBuilderCore
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../ 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) target_precompile_headers(EventBuilderCore PRIVATE ../EventBuilder.h)
@ -34,6 +38,9 @@ target_sources(EventBuilderCore PRIVATE
target_link_libraries(EventBuilderCore PUBLIC target_link_libraries(EventBuilderCore PUBLIC
EVBDict EVBDict
${ROOT_LIBRARIES} ${ROOT_LIBRARIES}
yaml-cpp
) )
set_target_properties(EventBuilderCore PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${EVB_LIBRARY_DIR}) set_target_properties(EventBuilderCore PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${EVB_LIBRARY_DIR})
target_compile_definitions(EventBuilderCore PRIVATE YAML_CPP_STATIC_DEFINE)

View File

@ -9,6 +9,7 @@
#include "EVBApp.h" #include "EVBApp.h"
#include "CompassRun.h" #include "CompassRun.h"
#include "SlowSort.h" #include "SlowSort.h"
#include "yaml-cpp/yaml.h"
namespace EventBuilder { namespace EventBuilder {
@ -47,6 +48,33 @@ namespace EventBuilder {
bool EVBApp::ReadConfigFile(const std::string& fullpath) bool EVBApp::ReadConfigFile(const std::string& fullpath)
{ {
EVB_INFO("Reading in EVB configuration from file {0}...", 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<std::string>();
m_params.scalerFile = data["ScalerFile"].as<std::string>();
m_params.timeShiftFile = data["TimeShiftFile"].as<std::string>();
m_params.slowCoincidenceWindow = data["SlowCoincidenceWindow(ps)"].as<double>();
m_params.runMin = data["MinRun"].as<int>();
m_params.runMax = data["MaxRun"].as<int>();
m_params.bufferSize = data["BufferSize(hits)"].as<size_t>();
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); std::ifstream input(fullpath);
if(!input.is_open()) if(!input.is_open())
{ {
@ -80,7 +108,7 @@ namespace EventBuilder {
input>>junk>>m_params.bufferSize; input>>junk>>m_params.bufferSize;
input.close(); input.close();
*/
EVB_INFO("Successfully loaded EVB config."); EVB_INFO("Successfully loaded EVB config.");
return true; return true;
@ -96,7 +124,20 @@ namespace EventBuilder {
EVB_WARN("Failed to write to config to file {0}, unable to open file!", fullpath); EVB_WARN("Failed to write to config to file {0}, unable to open file!", fullpath);
return; 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----------"<<std::endl; output<<"-------Data Location----------"<<std::endl;
output<<"WorkspaceDirectory: "<<m_params.workspaceDir<<std::endl; output<<"WorkspaceDirectory: "<<m_params.workspaceDir<<std::endl;
output<<"-------------------------------"<<std::endl; output<<"-------------------------------"<<std::endl;
@ -112,7 +153,7 @@ namespace EventBuilder {
output<<"MaxRun: "<<m_params.runMax<<std::endl; output<<"MaxRun: "<<m_params.runMax<<std::endl;
output<<"BufferSize: "<<m_params.bufferSize<<std::endl; output<<"BufferSize: "<<m_params.bufferSize<<std::endl;
output<<"-------------------------------"<<std::endl; output<<"-------------------------------"<<std::endl;
*/
output.close(); output.close();
EVB_INFO("Successfully wrote config to file."); EVB_INFO("Successfully wrote config to file.");

1
vendor/yaml-cpp vendored Submodule

@ -0,0 +1 @@
Subproject commit c73ee34704c512ebe915b283645aefa9f424a22f