Skip to content

Commit

Permalink
Merge pull request #2465 from dmitry-ganyushin/hierarchical_reading
Browse files Browse the repository at this point in the history
Hierarchical reading implementation
  • Loading branch information
dmitry-ganyushin authored Sep 24, 2020
2 parents 57fd695 + 39a0f21 commit 346d251
Show file tree
Hide file tree
Showing 17 changed files with 827 additions and 3 deletions.
3 changes: 3 additions & 0 deletions bindings/CXX11/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ add_library(adios2_cxx11
adios2/cxx11/Types.tcc
adios2/cxx11/Variable.cpp
adios2/cxx11/fstream/ADIOS2fstream.cpp
adios2/cxx11/Group.cpp
adios2/cxx11/Group.tcc
)
set_property(TARGET adios2_cxx11 PROPERTY EXPORT_NAME cxx11)
set_property(TARGET adios2_cxx11 PROPERTY OUTPUT_NAME adios2${ADIOS2_LIBRARY_SUFFIX}_cxx11)
Expand Down Expand Up @@ -78,6 +80,7 @@ install(
FILES adios2/cxx11/ADIOS.h
adios2/cxx11/ADIOS.inl
adios2/cxx11/IO.h
adios2/cxx11/Group.h
adios2/cxx11/Variable.h
adios2/cxx11/Attribute.h
adios2/cxx11/Engine.h
Expand Down
1 change: 1 addition & 0 deletions bindings/CXX11/adios2.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ constexpr bool DebugOFF = false;
#include "adios2/cxx11/ADIOS.h"
#include "adios2/cxx11/Attribute.h"
#include "adios2/cxx11/Engine.h"
#include "adios2/cxx11/Group.h"
#include "adios2/cxx11/IO.h"
#include "adios2/cxx11/Operator.h"
#include "adios2/cxx11/Query.h"
Expand Down
75 changes: 75 additions & 0 deletions bindings/CXX11/adios2/cxx11/Group.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* Group.cpp :
*
* Created on: August 25, 2020
* Author: Dmitry Ganyushin [email protected]
*/

#include "Group.h"
#include "Group.tcc"
#include "adios2/core/Group.h"

namespace adios2
{
Group::Group(core::Group *group) : m_Group(group) {}

Group Group::OpenGroup(std::string group_name)
{
auto m = m_Group->OpenGroup(group_name);
return Group(m);
}
void Group::PrintTree()
{
m_Group->PrintTree();
return;
}

void Group::BuildTree()
{
m_Group->BuildTree();
return;
}
std::vector<std::string> Group::AvailableVariables()
{
return m_Group->AvailableVariables();
}
std::vector<std::string> Group::AvailableAttributes()
{
return m_Group->AvailableAttributes();
}
std::vector<std::string> Group::AvailableGroups()
{
return m_Group->AvailableGroups();
}

std::map<std::string, std::set<std::string>> &Group::getTreeMap()
{
return m_Group->getTreeMap();
}

std::string Group::InquirePath() { return m_Group->InquirePath(); }

void Group::setPath(std::string path) { m_Group->setPath(path); }
DataType Group::VariableType(const std::string &name) const
{
helper::CheckForNullptr(m_Group, "in call to IO::VariableType");
return m_Group->InquireVariableType(name);
}

DataType Group::AttributeType(const std::string &name) const
{
helper::CheckForNullptr(m_Group, "in call to IO::AttributeType");
return m_Group->InquireAttributeType(name);
}
Group::~Group(){};
// Explicit declaration of the public template methods
// Limits the types
#define declare_template_instantiation(T) \
template Variable<T> Group::InquireVariable<T>(const std::string &);

ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
} // end of namespace
146 changes: 146 additions & 0 deletions bindings/CXX11/adios2/cxx11/Group.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* Group.h :
*
* Created on: August 25, 2020
* Author: Dmitry Ganyushin [email protected]
*/
#ifndef ADIOS2_BINDINGS_CXX11_CXX11_GROUP_H_

#define ADIOS2_BINDINGS_CXX11_CXX11_GROUP_H_

#include "Attribute.h"
#include "Variable.h"
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#if ADIOS2_USE_MPI
#include <mpi.h>
#endif

#include "Group.h"
#include "adios2/common/ADIOSMacros.h"
#include "adios2/common/ADIOSTypes.h"

namespace adios2
{
class IO;

namespace core
{
class Group; // private implementation
}
class Group
{
friend class IO;

private:
Group(core::Group *group);
core::Group *m_Group = nullptr;

public:
~Group();
/**
* @brief Builds map that represents tree structure from m_Variable and
* m_Attributes from IO class
* @param
*/
void BuildTree();
/**
* @brief Prints map that represents tree structure
* @param
*/
void PrintTree();
/**
* @brief returns available groups on the path set
* @param
* @return vector of strings
*/
std::vector<std::string> AvailableGroups();
/**
* @brief returns available variables on the path set
* @param
* @return vector of strings
*/
std::vector<std::string> AvailableVariables();
/**
* @brief returns available attributes on the path set
* @param
* @return vector of strings
*/
std::vector<std::string> AvailableAttributes();
/**
* @brief returns the current path
* @param
* @return current path as a string
*/
std::string InquirePath();
/**
* @brief set the path, points to a particular node on the tree
* @param next possible path extension
*/
void setPath(std::string path);
/**
* @brief returns a new group object
* @param name of the group
* @return new group object
*/
Group OpenGroup(std::string group_name);
/**
* @brief returns a reference to the map representing the tree stucture
* @param delimiter symbol
*/
std::map<std::string, std::set<std::string>> &getTreeMap();
/**
* @brief Gets an existing variable of primitive type by name. A wrapper for
* the corresponding function of the IO class
* @param name of variable to be retrieved
* @return pointer to an existing variable in current IO, nullptr if not
* found
*/
template <class T>
Variable<T> InquireVariable(const std::string &name);
/**
* Gets an existing attribute of primitive type by name. A wrapper for
* the corresponding function of the IO class
* @param name of attribute to be retrieved
* @return pointer to an existing attribute in current IO, nullptr if not
* found
*/
template <class T>
Attribute<T> InquireAttribute(const std::string &name,
const std::string &variableName = "",
const std::string separator = "/");

/**
* Inspects variable type. This function can be used in conjunction with
* MACROS in an else if (type == adios2::GetType<T>() ) {} loop
* @param name unique variable name identifier in current IO
* @return type as in adios2::GetType<T>() (e.g. "double", "float"),
* empty std::string if variable not found
*/
DataType VariableType(const std::string &name) const;

/**
* Inspects attribute type. This function can be used in conjunction with
* MACROS in an else if (type == adios2::GetType<T>() ) {} loop
* @param name unique attribute name identifier in current IO
* @return type as in adios2::GetType<T>() (e.g. "double", "float"), empty
* std::string if attribute not found
*/
DataType AttributeType(const std::string &name) const;
};
// Explicit declaration of the public template methods
// Limits the types
#define declare_template_instantiation(T) \
extern template Variable<T> Group::InquireVariable<T>(const std::string &);
ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation

}
#endif // ADIOS2_BINDINGS_CXX11_CXX11_GROUP_H_
42 changes: 42 additions & 0 deletions bindings/CXX11/adios2/cxx11/Group.tcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* Group.tcc :
*
* Created on: August 25, 2020
* Author: Dmitry Ganyushin [email protected]
*/
#ifndef ADIOS2_BINDINGS_CXX11_CXX11_GROUP_TCC_
#define ADIOS2_BINDINGS_CXX11_CXX11_GROUP_TCC_

#include "Group.h"

#include "adios2/core/Group.h"

namespace adios2
{
template <class T>
Variable<T> Group::InquireVariable(const std::string &name)
{
helper::CheckForNullptr(m_Group, "for variable name " + name +
", in call to Group::InquireVariable");
return Variable<T>(
m_Group->InquireVariable<typename TypeInfo<T>::IOType>(name));
}

template <class T>
Attribute<T> Group::InquireAttribute(const std::string &name,
const std::string &variableName,
const std::string separator)
{
using IOType = typename TypeInfo<T>::IOType;
helper::CheckForNullptr(m_Group, "for attribute name " + name +
", in call to IO::InquireAttribute");
return Attribute<T>(
m_Group->InquireAttribute<IOType>(name, variableName, separator));
}

} // end namespace adios2

#endif /* ADIOS2_BINDINGS_CXX11_CXX11_GROUP_TCC_ */
5 changes: 4 additions & 1 deletion bindings/CXX11/adios2/cxx11/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ Engine IO::Open(const std::string &name, const Mode mode)
"for engine " + name + ", in call to IO::Open");
return Engine(&m_IO->Open(name, mode));
}

Group IO::GetGroup(const std::string &path, char delimiter)
{
return Group(&m_IO->GetGroup(path, delimiter));
};
void IO::FlushAll()
{
helper::CheckForNullptr(m_IO, "in call to IO::FlushAll");
Expand Down
9 changes: 8 additions & 1 deletion bindings/CXX11/adios2/cxx11/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

#include "Attribute.h"
#include "Engine.h"
#include "Group.h"
#include "Operator.h"
#include "Variable.h"

#if ADIOS2_USE_MPI
#include <mpi.h>
#endif
Expand Down Expand Up @@ -256,6 +256,13 @@ class IO
* @return engine object
*/
Engine Open(const std::string &name, const Mode mode);
/**
* Return a Group object for hierarchical reading.
* @param name starting path
* @param a delimiter to separate groups in a string representation
* @return Group object
*/
Group GetGroup(const std::string &path, char delimiter = '/');

#if ADIOS2_USE_MPI
/**
Expand Down
3 changes: 2 additions & 1 deletion bindings/CXX11/adios2/cxx11/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace adios2
// forward declare
class IO; // friend
class Engine; // friend

class Group; // friend
namespace core
{

Expand Down Expand Up @@ -131,6 +131,7 @@ class Variable

friend class IO;
friend class Engine;
friend class Group;

public:
/**
Expand Down
1 change: 1 addition & 0 deletions source/adios2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ add_library(adios2_core
core/Variable.cpp core/Variable.tcc
core/VariableBase.cpp
core/VariableCompound.cpp core/VariableCompound.tcc
core/Group.cpp core/Group.tcc

#operator callback
operator/callback/Signature1.cpp
Expand Down
Loading

0 comments on commit 346d251

Please sign in to comment.