DamarisVar: avoid stringstream member

This commit is contained in:
Arne Morten Kvarving 2024-01-30 09:25:18 +01:00
parent 3f842cd67f
commit cfd5af89b0
2 changed files with 36 additions and 37 deletions

View File

@ -22,6 +22,7 @@
#include <opm/common/ErrorMacros.hpp> #include <opm/common/ErrorMacros.hpp>
#include <Damaris.h> #include <Damaris.h>
#include <fmt/format.h>
#include <cassert> #include <cassert>
#include <sstream> #include <sstream>
@ -130,7 +131,7 @@ DamarisVar<T>::~DamarisVar()
template<class T> template<class T>
void DamarisVar<T>::printError() const void DamarisVar<T>::printError() const
{ {
OPM_THROW(std::runtime_error, dam_err_sstr_.str()); OPM_THROW(std::runtime_error, dam_err_str_);
} }
template<class T> template<class T>
@ -159,9 +160,9 @@ void DamarisVar<T>::setDamarisParameter(const std::vector<int>& paramSizeVal)
dam_err_ = damaris_parameter_set(param_names_[varnum].c_str(), &paramSizeVal[varnum], sizeof(int)); dam_err_ = damaris_parameter_set(param_names_[varnum].c_str(), &paramSizeVal[varnum], sizeof(int));
if (dam_err_ != DAMARIS_OK) { if (dam_err_ != DAMARIS_OK) {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar : damaris_parameter_set(\"" dam_err_str_ += fmt::format(" ERROR rank = {}: class DamarisVar : damaris_parameter_set(\"{}\""
<< param_names_[varnum] << "\", paramSizeVal, sizeof(int)); Damaris error = " ", paramSizeVal, sizeof(int)); Damaris error = {}\n",
<< damaris_error_string(dam_err_) << std::endl; rank_, param_names_[varnum], damaris_error_string(dam_err_));
resbool = false; resbool = false;
has_error_ = true; has_error_ = true;
} }
@ -175,10 +176,9 @@ void DamarisVar<T>::setDamarisParameter(const std::vector<int>& paramSizeVal)
if (total_size > 0) { if (total_size > 0) {
current_size_ = total_size; current_size_ = total_size;
} else { } else {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar::getDataStoreBlockSize() " dam_err_str_ += fmt::format(" ERROR rank = {}: class DamarisVar::getDataStoreBlockSize() "
<< "The total size of the variable is 0 - please check " "The total size of the variable is 0 - please check "
"input paramSizeVal array." "input paramSizeVal array.\n", rank_);
<< std::endl;
has_error_ = true; has_error_ = true;
} }
@ -197,9 +197,9 @@ void DamarisVar<T>::setDamarisPosition(const std::vector<int64_t>& positionsVals
} }
dam_err_ = damaris_set_position(variable_name_.c_str(), positionsVals.data()); dam_err_ = damaris_set_position(variable_name_.c_str(), positionsVals.data());
if (dam_err_ != DAMARIS_OK) { if (dam_err_ != DAMARIS_OK) {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar : damaris_set_position(\"" dam_err_str_ += fmt::format(" ERROR rank = {}: class DamarisVar : damaris_set_position(\"{}\""
<< variable_name_ ", positionsVals); Damaris error = {}\n",
<< "\", positionsVals); Damaris error = " << damaris_error_string(dam_err_) << std::endl; rank_, variable_name_, damaris_error_string(dam_err_));
has_error_ = true; has_error_ = true;
} }
@ -215,18 +215,17 @@ void DamarisVar<T>::setPointersToDamarisShmem()
// Allocate memory in the shared memory section... // Allocate memory in the shared memory section...
dam_err_ = damaris_alloc(variable_name_.c_str(), (void**)&data_ptr_); dam_err_ = damaris_alloc(variable_name_.c_str(), (void**)&data_ptr_);
if (dam_err_ != DAMARIS_OK) { if (dam_err_ != DAMARIS_OK) {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar : damaris_alloc(\"" dam_err_str_ += fmt::format(" ERROR rank = {}: class DamarisVar : damaris_alloc(\"{}\""
<< variable_name_ << "\", (void **) &ret_ptr)" ", (void **) &ret_ptr), Damaris error = {}\n",
<< ", Damaris error = " << damaris_error_string(dam_err_) << std::endl; rank_, variable_name_, damaris_error_string(dam_err_));
has_error_ = true; has_error_ = true;
} }
} else { } else {
dam_err_ = -1; dam_err_ = -1;
dam_err_sstr_ << " ERROR rank =" << rank_ dam_err_str_ += fmt::format(" ERROR rank = {}: class DamarisVar : "
<< " : class DamarisVar : setDamarisParameter() should be " "setDamarisParameter() should be "
"called first so as to define the size of the memory " "called first to define the size of the memory "
"block required for variable : " "block required for variable: {}\n", rank_, variable_name_);
<< variable_name_ << std::endl;
has_error_ = true; has_error_ = true;
} }
@ -241,9 +240,9 @@ void DamarisVar<T>::commitVariableDamarisShmem()
// Signal to Damaris we are done writing data for this iteration // Signal to Damaris we are done writing data for this iteration
dam_err_ = damaris_commit(variable_name_.c_str()); dam_err_ = damaris_commit(variable_name_.c_str());
if (dam_err_ != DAMARIS_OK) { if (dam_err_ != DAMARIS_OK) {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar : damaris_commit(\"" dam_err_str_ += fmt::format(" ERROR rank = {}: class DamarisVar : damaris_commit(\"{}\")"
<< variable_name_ << "\")" ", Damaris error = {}\n",
<< ", Damaris error = " << damaris_error_string(dam_err_) << std::endl; rank_, variable_name_, damaris_error_string(dam_err_));
has_error_ = true; has_error_ = true;
} }
} }
@ -254,9 +253,9 @@ void DamarisVar<T>::clearVariableDamarisShmem()
// Signal to Damaris it has complete charge of the memory area // Signal to Damaris it has complete charge of the memory area
dam_err_ = damaris_clear(variable_name_.c_str()); dam_err_ = damaris_clear(variable_name_.c_str());
if (dam_err_ != DAMARIS_OK) { if (dam_err_ != DAMARIS_OK) {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : class DamarisVar : damaris_clear(\"" << variable_name_ dam_err_str_ += fmt::format(" ERROR rank = {}: class DamarisVar : damaris_clear(\"{}\")"
<< "\")" ", Damaris error = {}\n",
<< ", Damaris error = " << damaris_error_string(dam_err_) << std::endl; rank_, variable_name_, damaris_error_string(dam_err_));
has_error_ = true; has_error_ = true;
} }
data_ptr_ = nullptr; data_ptr_ = nullptr;
@ -270,8 +269,9 @@ bool DamarisVar<T>::TestType(const std::string& variable_name)
DAMARIS_TYPE_STR vartype; DAMARIS_TYPE_STR vartype;
dam_err_ = damaris_get_type(variable_name.c_str(), &vartype); dam_err_ = damaris_get_type(variable_name.c_str(), &vartype);
if (dam_err_ != DAMARIS_OK) { if (dam_err_ != DAMARIS_OK) {
dam_err_sstr_ << " ERROR rankDamarisVar::DamarisVar () damaris_get_type(\"" << variable_name_ dam_err_str_ = fmt::format(" ERROR rank = {}: DamarisVar::DamarisVar () damaris_get_type(\"{}\""
<< "\", vartype); Damaris error = " << damaris_error_string(dam_err_) << std::endl; ", vartype); Damaris error = {}\n",
rank_, variable_name_, damaris_error_string(dam_err_));
has_error_ = true; has_error_ = true;
return false; return false;
} }
@ -349,13 +349,13 @@ bool DamarisVar<T>::TestType(const std::string& variable_name)
resbool = false; resbool = false;
} }
} else if (vartype == DAMARIS_TYPE_UNDEFINED) { } else if (vartype == DAMARIS_TYPE_UNDEFINED) {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : DamarisVar::DamarisVar():: \"" << variable_name dam_err_str_ += fmt::format(" ERROR rank = {}: DamarisVar::DamarisVar():: \"{}\""
<< "\" has type DAMARIS_TYPE_UNDEFINED" << std::endl; " has type DAMARIS_TYPE_UNDEFINED\n", rank_, variable_name);
has_error_ = true; has_error_ = true;
resbool = false; resbool = false;
} else { } else {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : DamarisVar::DamarisVar():: \"" << variable_name dam_err_str_ += fmt::format(" ERROR rank = {}: DamarisVar::DamarisVar():: \"{}\""
<< "\" is not of available type " << std::endl; " is not of available type\n", rank_, variable_name);
has_error_ = true; has_error_ = true;
resbool = false; resbool = false;
} }
@ -368,9 +368,10 @@ void DamarisVar<T>::formatTypeError(const std::string& var_name,
const std::string& type_name1, const std::string& type_name1,
const std::string& type_name2) const std::string& type_name2)
{ {
dam_err_sstr_ << " ERROR rank =" << rank_ << " : DamarisVar::DamarisVar () variable_name_: \"" << var_name dam_err_str_ += fmt::format(" ERROR rank = {}: DamarisVar::DamarisVar() variable_name: \"{}\""
<< "\" The template type of Type of DamarisVar<T> in the code: " << type_name1 " The template type of Type of DamarisVar<T> in the code: {}"
<< " does not match type in XML:" << type_name2 << std::endl; " does not match type in XML: {}\n",
rank_, var_name, type_name1, type_name2);
has_error_ = true; has_error_ = true;
} }

View File

@ -21,7 +21,6 @@
#define DAMARISVAR_HPP #define DAMARISVAR_HPP
#include <cstddef> #include <cstddef>
#include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
@ -132,8 +131,7 @@ namespace DamarisOutput
int dam_err_; //!< Set to != DAMARIS_OK if a Damaris error was returned by a int dam_err_; //!< Set to != DAMARIS_OK if a Damaris error was returned by a
//!< Damaris API function call //!< Damaris API function call
bool has_error_; bool has_error_;
std::ostringstream dam_err_sstr_; //!< Use dam_err_sstr.str() to return an std::string dam_err_str_; //!< Error string describing detected error
//!< error string describing detected error
DamarisVarXMLAttributes xml_attributes_; //!< The extra elements that need to be part of a Damaris DamarisVarXMLAttributes xml_attributes_; //!< The extra elements that need to be part of a Damaris
//!< <variable> type. They are simple string values that //!< <variable> type. They are simple string values that
//!< may reference other XML elements (and could be //!< may reference other XML elements (and could be