Skip to content

Commit

Permalink
Merge pull request #2350 from bradking/io-storage
Browse files Browse the repository at this point in the history
core: Simplify IO variable and attribute storage
  • Loading branch information
Chuck Atkins authored Jun 29, 2020
2 parents 2852afe + 9f71ec6 commit 48dd42a
Show file tree
Hide file tree
Showing 24 changed files with 174 additions and 356 deletions.
14 changes: 7 additions & 7 deletions bindings/C/adios2/c/adios2_c_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ adios2_variable *adios2_inquire_variable(adios2_io *io, const char *name)
io, "for adios2_io, in call to adios2_inquire_variable");

adios2::core::IO &ioCpp = *reinterpret_cast<adios2::core::IO *>(io);
const auto &dataMap = ioCpp.GetVariablesDataMap();
const auto &dataMap = ioCpp.GetVariables();

auto itVariable = dataMap.find(name);
if (itVariable == dataMap.end()) // not found
Expand Down Expand Up @@ -292,7 +292,7 @@ adios2_error adios2_inquire_all_variables(adios2_variable ***variables,
io, "for adios2_io, in call to adios2_inquire_all_variables");

adios2::core::IO &ioCpp = *reinterpret_cast<adios2::core::IO *>(io);
const auto &dataMap = ioCpp.GetVariablesDataMap();
const auto &dataMap = ioCpp.GetVariables();

*size = dataMap.size();
adios2_variable **list =
Expand All @@ -308,7 +308,7 @@ adios2_error adios2_inquire_all_variables(adios2_variable ***variables,
for (auto &name : names)
{
auto it = dataMap.find(name);
const adios2::DataType type(it->second.first);
const adios2::DataType type(it->second->m_Type);
adios2::core::VariableBase *variable = nullptr;

if (type == adios2::DataType::Compound)
Expand Down Expand Up @@ -498,15 +498,15 @@ adios2_attribute *adios2_inquire_attribute(adios2_io *io, const char *name)
io, "for adios2_io, in call to adios2_inquire_attribute");

adios2::core::IO &ioCpp = *reinterpret_cast<adios2::core::IO *>(io);
const auto &dataMap = ioCpp.GetAttributesDataMap();
const auto &dataMap = ioCpp.GetAttributes();

auto itAttribute = dataMap.find(name);
if (itAttribute == dataMap.end()) // not found
{
return attribute;
}

const adios2::DataType type(itAttribute->second.first);
const adios2::DataType type(itAttribute->second->m_Type);
adios2::core::AttributeBase *attributeCpp = nullptr;

if (type == adios2::DataType::Compound)
Expand Down Expand Up @@ -551,7 +551,7 @@ adios2_error adios2_inquire_all_attributes(adios2_attribute ***attributes,
io, "for adios2_io, in call to adios2_inquire_all_attributes");

adios2::core::IO &ioCpp = *reinterpret_cast<adios2::core::IO *>(io);
const auto &dataMap = ioCpp.GetAttributesDataMap();
const auto &dataMap = ioCpp.GetAttributes();

*size = dataMap.size();
adios2_attribute **list =
Expand All @@ -567,7 +567,7 @@ adios2_error adios2_inquire_all_attributes(adios2_attribute ***attributes,
for (auto &name : names)
{
auto it = dataMap.find(name);
const adios2::DataType type(it->second.first);
const adios2::DataType type(it->second->m_Type);
adios2::core::AttributeBase *attribute = nullptr;

if (type == adios2::DataType::Compound)
Expand Down
4 changes: 3 additions & 1 deletion source/adios2/core/ADIOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ IO &ADIOS::DeclareIO(const std::string name)
}
}

auto ioPair = m_IOs.emplace(name, IO(*this, name, false, m_HostLanguage));
auto ioPair = m_IOs.emplace(
std::piecewise_construct, std::forward_as_tuple(name),
std::forward_as_tuple(*this, name, false, m_HostLanguage));
IO &io = ioPair.first->second;
io.SetDeclared();
return io;
Expand Down
6 changes: 0 additions & 6 deletions source/adios2/core/Attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ struct RequiresZeroPadding<long double> : std::true_type
if (RequiresZeroPadding<T>::value) \
std::memset(&m_DataSingleValue, 0, sizeof(m_DataSingleValue)); \
m_DataSingleValue = value; \
} \
\
template <> \
Params Attribute<T>::GetInfo() const noexcept \
{ \
return DoGetInfo(); \
}

ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_1ARG(declare_type)
Expand Down
4 changes: 1 addition & 3 deletions source/adios2/core/Attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ class Attribute : public AttributeBase

~Attribute<T>() = default;

Params GetInfo() const noexcept;

private:
Params DoGetInfo() const noexcept;
std::string DoGetInfoValue() const noexcept override;
};

} // end namespace core
Expand Down
14 changes: 5 additions & 9 deletions source/adios2/core/Attribute.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "Attribute.h"

#include "adios2/helper/adiosFunctions.h"
#include "adios2/helper/adiosType.h"

namespace adios2
Expand All @@ -22,21 +21,18 @@ namespace core
{

template <class T>
Params Attribute<T>::DoGetInfo() const noexcept
std::string Attribute<T>::DoGetInfoValue() const noexcept
{
Params info;
info["Type"] = ToString(m_Type);
info["Elements"] = std::to_string(m_Elements);

std::string value;
if (m_IsSingleValue)
{
info["Value"] = helper::ValueToString(m_DataSingleValue);
value = helper::ValueToString(m_DataSingleValue);
}
else
{
info["Value"] = "{ " + helper::VectorToCSV(m_DataArray) + " }";
value = "{ " + helper::VectorToCSV(m_DataArray) + " }";
}
return info;
return value;
}

} // end namespace core
Expand Down
9 changes: 9 additions & 0 deletions source/adios2/core/AttributeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,14 @@ AttributeBase::AttributeBase(const std::string &name, const DataType type,
{
}

Params AttributeBase::GetInfo() const noexcept
{
Params info;
info["Type"] = ToString(m_Type);
info["Elements"] = std::to_string(m_Elements);
info["Value"] = this->DoGetInfoValue();
return info;
}

} // end namespace core
} // end namespace adios2
5 changes: 5 additions & 0 deletions source/adios2/core/AttributeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class AttributeBase
const size_t elements);

virtual ~AttributeBase() = default;

Params GetInfo() const noexcept;

private:
virtual std::string DoGetInfoValue() const noexcept = 0;
};

} // end namespace core
Expand Down
Loading

0 comments on commit 48dd42a

Please sign in to comment.