From 436eedeec3ccdd90b8d20ee2e1bac1dfb9bffffb Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Mon, 16 Sep 2024 15:02:27 -0400 Subject: [PATCH] Replace parameter and component tables with YAML This addresses issue #358 --- .../JANA/Components/JComponentSummary.cc | 15 +++- .../JANA/Components/JComponentSummary.h | 1 + src/libraries/JANA/JApplication.cc | 19 ++++-- src/libraries/JANA/JVersion.cc | 10 +-- .../JANA/Services/JParameterManager.cc | 68 +++++++++---------- 5 files changed, 68 insertions(+), 45 deletions(-) diff --git a/src/libraries/JANA/Components/JComponentSummary.cc b/src/libraries/JANA/Components/JComponentSummary.cc index 80277cefd..7476a6cc9 100644 --- a/src/libraries/JANA/Components/JComponentSummary.cc +++ b/src/libraries/JANA/Components/JComponentSummary.cc @@ -128,10 +128,23 @@ void PrintComponentTable(std::ostream& os, const JComponentSummary& cs) { os << comp_table; } +void PrintComponentYaml(std::ostream& os, const JComponentSummary& cs) { + os << "Component Summary" << std::endl; + + for (const auto* comp : cs.GetAllComponents()) { + os << std::endl; + os << " - base: " << "\"" << comp->GetBaseName() << "\"" << std::endl; + os << " type: " << "\"" << comp->GetTypeName() << "\"" << std::endl; + os << " prefix: " << "\"" << comp->GetPrefix() << "\"" << std::endl; + os << " level: " << "\"" << comp->GetLevel() << "\"" << std::endl; + os << " plugin: " << "\"" << comp->GetPluginName() << "\"" << std::endl; + } +} + std::ostream& operator<<(std::ostream& os, JComponentSummary const& cs) { - PrintComponentTable(os,cs); + PrintComponentYaml(os,cs); return os; } diff --git a/src/libraries/JANA/Components/JComponentSummary.h b/src/libraries/JANA/Components/JComponentSummary.h index 86c09a82b..d61d596e9 100644 --- a/src/libraries/JANA/Components/JComponentSummary.h +++ b/src/libraries/JANA/Components/JComponentSummary.h @@ -160,6 +160,7 @@ std::ostream& operator<<(std::ostream& os, const JComponentSummary& cs); std::ostream& operator<<(std::ostream& os, JComponentSummary::Collection const&); std::ostream& operator<<(std::ostream& os, JComponentSummary::Component const&); void PrintComponentTable(std::ostream& os, const JComponentSummary&); +void PrintComponentYaml(std::ostream& os, const JComponentSummary&); void PrintCollectionTable(std::ostream& os, const JComponentSummary&); inline bool operator==(const JComponentSummary::Collection& lhs, const JComponentSummary::Collection& rhs) { diff --git a/src/libraries/JANA/JApplication.cc b/src/libraries/JANA/JApplication.cc index 54649e645..0c67c998b 100644 --- a/src/libraries/JANA/JApplication.cc +++ b/src/libraries/JANA/JApplication.cc @@ -119,11 +119,20 @@ void JApplication::Initialize() { m_logger = m_params->GetLogger("jana"); m_logger.show_classname = false; - std::ostringstream oss; - oss << "Initializing..." << std::endl; - JVersion::PrintSplash(oss); - JVersion::PrintVersionDescription(oss); - LOG_WARN(m_logger) << oss.str() << LOG_END; + if (m_logger.level > JLogger::Level::INFO) { + std::ostringstream oss; + oss << "Initializing..." << std::endl << std::endl; + JVersion::PrintVersionDescription(oss); + LOG_WARN(m_logger) << oss.str() << LOG_END; + } + else { + std::ostringstream oss; + oss << "Initializing..." << std::endl; + JVersion::PrintSplash(oss); + JVersion::PrintVersionDescription(oss); + LOG_WARN(m_logger) << oss.str() << LOG_END; + + } // Set up wiring ProvideService(std::make_shared()); diff --git a/src/libraries/JANA/JVersion.cc b/src/libraries/JANA/JVersion.cc index c5482ef7e..97ec511af 100644 --- a/src/libraries/JANA/JVersion.cc +++ b/src/libraries/JANA/JVersion.cc @@ -31,7 +31,7 @@ void JVersion::PrintSplash(std::ostream& os) { void JVersion::PrintVersionDescription(std::ostream& os) { - os << "JANA2 version: " << JVersion::GetVersion() << " "; + os << " JANA2 version: " << JVersion::GetVersion() << " "; if (is_unknown) { os << " (unknown git status)"; } @@ -46,12 +46,12 @@ void JVersion::PrintVersionDescription(std::ostream& os) { } os << std::endl; if (!JVersion::is_unknown) { - os << "Commit hash: " << JVersion::GetCommitHash() << std::endl; - os << "Commit date: " << JVersion::GetCommitDate() << std::endl; + os << " Commit hash: " << JVersion::GetCommitHash() << std::endl; + os << " Commit date: " << JVersion::GetCommitDate() << std::endl; } - os << "Install prefix: " << JVersion::GetInstallDir() << std::endl; + os << " Install prefix: " << JVersion::GetInstallDir() << std::endl; if (JVersion::HasPodio() || JVersion::HasROOT() || JVersion::HasXerces()) { - os << "Optional deps: "; + os << " Optional deps: "; if (JVersion::HasPodio()) os << "Podio "; if (JVersion::HasROOT()) os << "ROOT "; if (JVersion::HasXerces()) os << "Xerces "; diff --git a/src/libraries/JANA/Services/JParameterManager.cc b/src/libraries/JANA/Services/JParameterManager.cc index 3ca41539f..8ed883bb5 100644 --- a/src/libraries/JANA/Services/JParameterManager.cc +++ b/src/libraries/JANA/Services/JParameterManager.cc @@ -144,15 +144,10 @@ void JParameterManager::PrintParameters(int verbosity, int strictness) { if ((strictness > 0) && (!param->IsDefault()) && (!param->IsUsed())) { strictness_violation = true; warnings_present = true; - if (strictness < 2) { - LOG_WARN(m_logger) << "Parameter '" << key << "' appears to be unused. Possible typo?" << LOG_END; - } - else { - LOG_FATAL(m_logger) << "Parameter '" << key << "' appears to be unused. Possible typo?" << LOG_END; - } + LOG_ERROR(m_logger) << "Parameter '" << key << "' appears to be unused. Possible typo?" << LOG_END; } if ((!param->IsDefault()) && (param->IsDeprecated())) { - LOG_WARN(m_logger) << "Parameter '" << key << "' has been deprecated and may no longer be supported in future releases." << LOG_END; + LOG_ERROR(m_logger) << "Parameter '" << key << "' has been deprecated and may no longer be supported in future releases." << LOG_END; warnings_present = true; } } @@ -196,38 +191,43 @@ void JParameterManager::PrintParameters(int verbosity, int strictness) { table.AddColumn("Default", JTablePrinter::Justify::Left, 25); table.AddColumn("Description", JTablePrinter::Justify::Left, 50); + std::ostringstream ss; for (JParameter* p: params_to_print) { - if (warnings_present) { - std::string warning; - if (p->IsDeprecated()) { - // If deprecated, it no longer matters whether it is advanced or not. If unused, won't show up here anyway. - warning = "Deprecated"; - } - else if (!p->IsUsed()) { - // Can't be both deprecated and unused, since JANA only finds out that it is deprecated by trying to use it - // Can't be both advanced and unused, since JANA only finds out that it is advanced by trying to use it - warning = "Unused"; - } - else if (p->IsAdvanced()) { - warning = "Advanced"; - } - table | p->GetKey() - | warning - | p->GetValue() - | p->GetDefault() - | p->GetDescription(); + ss << std::endl; + ss << " - key: \"" << p->GetKey() << "\"" << std::endl; + ss << " value: \"" << p->GetValue() << "\"" << std::endl; + ss << " default: \"" << p->GetDefault() << "\"" << std::endl; + if (!p->GetDescription().empty()) { + ss << " description: \""; + std::istringstream iss(p->GetDescription()); + std::string line; + bool is_first_line = true; + while (std::getline(iss, line)) { + if (!is_first_line) { + ss << std::endl << " " << line; + } + else { + ss << line; + } + is_first_line = false; + } + ss << "\"" << std::endl; + } + if (p->IsDeprecated()) { + ss << " warning: \"Deprecated\"" << std::endl; + // If deprecated, it no longer matters whether it is advanced or not. If unused, won't show up here anyway. } - else { - table | p->GetKey() - | p->GetValue() - | p->GetDefault() - | p->GetDescription(); + else if (!p->IsUsed()) { + // Can't be both deprecated and unused, since JANA only finds out that it is deprecated by trying to use it + // Can't be both advanced and unused, since JANA only finds out that it is advanced by trying to use it + ss << " warning: \"Unused\"" << std::endl; + } + else if (p->IsAdvanced()) { + ss << " warning: \"Advanced\"" << std::endl; } } - std::ostringstream ss; - table.Render(ss); - LOG_INFO(m_logger) << "Configuration Parameters\n" << ss.str() << LOG_END; + LOG_WARN(m_logger) << "Configuration Parameters\n" << ss.str() << LOG_END; // Now that we've printed the table, we can throw an exception if we are being super strict if (strictness_violation && strictness > 1) {