From 30d5b69b24ee9f6e0a746fa51659813223a331f0 Mon Sep 17 00:00:00 2001 From: Norbert Podhorszki Date: Tue, 30 Jul 2024 13:23:04 -0400 Subject: [PATCH] Fixes for building with and without support for Derived Variables --- bindings/Python/py11IO.cpp | 2 ++ bindings/Python/py11VariableDerived.cpp | 14 ++++++++++++++ bindings/Python/py11VariableDerived.h | 13 ++++++++++--- source/adios2/common/ADIOSTypes.h | 2 -- testing/adios2/python/CMakeLists.txt | 5 ++++- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/bindings/Python/py11IO.cpp b/bindings/Python/py11IO.cpp index fa9dc0de5b..0ace77d169 100644 --- a/bindings/Python/py11IO.cpp +++ b/bindings/Python/py11IO.cpp @@ -157,6 +157,8 @@ VariableDerived IO::DefineDerivedVariable(const std::string &name, const std::st adios2::py11::VariableDerived vd(dv); #else adios2::py11::VariableDerived vd; + throw std::invalid_argument("ERROR: Derived Variables are not supported in this adios2 build " + ", in call to DefineDerivedVariable\n"); #endif return vd; } diff --git a/bindings/Python/py11VariableDerived.cpp b/bindings/Python/py11VariableDerived.cpp index c9973e2853..f020e58813 100644 --- a/bindings/Python/py11VariableDerived.cpp +++ b/bindings/Python/py11VariableDerived.cpp @@ -14,6 +14,7 @@ namespace adios2 namespace py11 { +#ifdef ADIOS2_HAVE_DERIVED_VARIABLE VariableDerived::VariableDerived(core::VariableDerived *v) : m_VariableDerived(v) {} VariableDerived::operator bool() const noexcept @@ -33,5 +34,18 @@ DerivedVarType VariableDerived::Type() const return m_VariableDerived->GetDerivedType(); } +#else + +VariableDerived::operator bool() const noexcept { return false; } + +std::string VariableDerived::Name() const +{ + return "DerivedVariables are not supported in this ADIOS2 build"; +} + +DerivedVarType VariableDerived::Type() const { return DerivedVarType::ExpressionString; } + +#endif + } // end namespace py11 } // end namespace adios2 diff --git a/bindings/Python/py11VariableDerived.h b/bindings/Python/py11VariableDerived.h index 922e4a6088..7c84b439a6 100644 --- a/bindings/Python/py11VariableDerived.h +++ b/bindings/Python/py11VariableDerived.h @@ -9,7 +9,13 @@ #ifndef ADIOS2_BINDINGS_PYTHON_VARIABLEDERIVED_H_ #define ADIOS2_BINDINGS_PYTHON_VARIABLEDERIVED_H_ +#include "adios2/common/ADIOSConfig.h" + +#ifdef ADIOS2_HAVE_DERIVED_VARIABLE #include "adios2/core/VariableDerived.h" +#else +#include "adios2/common/ADIOSTypes.h" +#endif namespace adios2 { @@ -36,9 +42,10 @@ class VariableDerived DerivedVarType Type() const; private: - VariableDerived(core::VariableDerived *v); - - core::VariableDerived *m_VariableDerived = nullptr; +#ifdef ADIOS2_HAVE_DERIVED_VARIABLE + VariableDerived(adios2::core::VariableDerived *v); + adios2::core::VariableDerived *m_VariableDerived = nullptr; +#endif }; } // end namespace py11 diff --git a/source/adios2/common/ADIOSTypes.h b/source/adios2/common/ADIOSTypes.h index 0907831959..2df11670a8 100644 --- a/source/adios2/common/ADIOSTypes.h +++ b/source/adios2/common/ADIOSTypes.h @@ -33,7 +33,6 @@ namespace adios2 { -#ifdef ADIOS2_HAVE_DERIVED_VARIABLE /** Type of derived variables */ enum class DerivedVarType { @@ -41,7 +40,6 @@ enum class DerivedVarType ExpressionString, ///< Store only the expression string StoreData ///< Store data and metadata }; -#endif /** Memory space for the user provided buffers */ enum class MemorySpace diff --git a/testing/adios2/python/CMakeLists.txt b/testing/adios2/python/CMakeLists.txt index 370686cfeb..a52df04fba 100644 --- a/testing/adios2/python/CMakeLists.txt +++ b/testing/adios2/python/CMakeLists.txt @@ -20,7 +20,10 @@ python_add_test(NAME Api.Python.Variable SCRIPT TestVariable.py) python_add_test(NAME Api.Python.Attribute SCRIPT TestAttribute.py) python_add_test(NAME Api.Python.Stream SCRIPT TestStream.py) python_add_test(NAME Api.Python.FileReader SCRIPT TestFileReader.py) -python_add_test(NAME Api.Python.DerivedVariable SCRIPT TestDerivedVariable.py) + +if (ADIOS2_HAVE_Derived_Variable) + python_add_test(NAME Api.Python.DerivedVariable SCRIPT TestDerivedVariable.py) +endif() if(ADIOS2_HAVE_MPI) add_python_mpi_test(BPWriteReadString)