Skip to content
Snippets Groups Projects
Unverified Commit 12cb32aa authored by williamfgc's avatar williamfgc Committed by GitHub
Browse files

Merge pull request #321 from williamfgc/declareio_xml

Solving issue #320 DeclareIO must be called at least once
parents 8e07ee4c 44180d05
No related branches found
No related tags found
No related merge requests found
......@@ -74,22 +74,48 @@ ADIOS::ADIOS(const bool debugMode, const std::string hostLanguage)
IO &ADIOS::DeclareIO(const std::string name)
{
if (m_DebugMode && m_IOs.count(name) == 1)
auto itIO = m_IOs.find(name);
if (itIO != m_IOs.end())
{
throw std::invalid_argument("ERROR: IO with name " + name +
" previously declared in config file or "
"with DeclareIO, name must be unique "
" , in call to DeclareIO\n");
IO &io = itIO->second;
if (!io.IsDeclared()) // exists from config xml
{
io.SetDeclared();
return io;
}
else
{
if (m_DebugMode)
{
throw std::invalid_argument(
"ERROR: IO with name " + name +
" previously declared with DeclareIO, name must be unique,"
" in call to DeclareIO\n");
}
}
}
auto ioPair = m_IOs.emplace(
name, IO(name, m_MPIComm, false, m_HostLanguage, m_DebugMode));
return ioPair.first->second;
IO &io = ioPair.first->second;
io.SetDeclared();
return io;
}
IO *ADIOS::InquireIO(const std::string name) noexcept
{
return InquireKey(name, m_IOs);
IO *io = InquireKey(name, m_IOs);
if (io != nullptr)
{
if (!io->IsDeclared())
{
io = nullptr;
}
}
return io;
}
Operator &ADIOS::DefineOperator(const std::string name, const std::string type,
......
......@@ -128,7 +128,11 @@ const DataMap &IO::GetAttributesDataMap() const noexcept
return m_Attributes;
}
bool IO::InConfigFile() const { return m_InConfigFile; };
bool IO::InConfigFile() const noexcept { return m_InConfigFile; };
void IO::SetDeclared() noexcept { m_IsDeclared = true; };
bool IO::IsDeclared() const noexcept { return m_IsDeclared; }
bool IO::RemoveVariable(const std::string &name) noexcept
{
......
......@@ -234,7 +234,17 @@ public:
* Check existence in config file passed to ADIOS class
* @return true: defined in config file
*/
bool InConfigFile() const;
bool InConfigFile() const noexcept;
/** Sets declared to true if IO exists in code created with ADIOS DeclareIO
*/
void SetDeclared() noexcept;
/**
* Check if declared in code
* @return true: created with ADIOS DeclareIO, false: dummy from config file
*/
bool IsDeclared() const noexcept;
/**
* Adds an operator defined by the ADIOS class. Could be a variable set
......@@ -275,6 +285,8 @@ private:
/** true: exist in config file (XML) */
const bool m_InConfigFile = false;
bool m_IsDeclared = false;
/** BPFileWriter engine default if unknown */
std::string m_EngineType;
......
......@@ -197,4 +197,4 @@ void InitXML(const std::string configXML, MPI_Comm mpiComm,
}
}
} // end namespace adios
} // end namespace adios2
......@@ -12,7 +12,6 @@
#define ADIOS2_HELPER_ADIOSXML_H_
/// \cond EXCLUDE_FROM_DOXYGEN
#include <adios2/core/Operator.h>
#include <map>
#include <memory> //std::shared_ptr
#include <string>
......@@ -20,6 +19,7 @@
/// \endcond
#include "adios2/core/IO.h"
#include "adios2/core/Operator.h"
namespace adios2
{
......@@ -37,6 +37,6 @@ void InitXML(const std::string configXML, MPI_Comm mpiComm,
const std::string hostLanguage, const bool debugMode,
std::map<std::string, std::shared_ptr<Operator>> &transforms,
std::map<std::string, IO> &ios);
}
} // end namespace adios2
#endif /* ADIOS2_HELPER_ADIOSXML_H_ */
......@@ -33,8 +33,11 @@ TEST_F(XMLConfigTest, TwoIOs)
adios2::ADIOS adios(configFile, adios2::DebugON);
#endif
// must be declared at least once
EXPECT_EQ(adios.InquireIO("Test IO 1"), nullptr);
EXPECT_NO_THROW({
adios2::IO &io = *adios.InquireIO("Test IO 1");
adios2::IO &io = adios.DeclareIO("Test IO 1");
const adios2::Params &params = io.GetParameters();
ASSERT_EQ(params.size(), 5);
EXPECT_THROW(params.at("DoesNotExist"), std::out_of_range);
......@@ -46,13 +49,21 @@ TEST_F(XMLConfigTest, TwoIOs)
adios2::Engine &engine =
io.Open("Test BP Writer 1", adios2::Mode::Write);
engine.Close();
EXPECT_NE(adios.InquireIO("Test IO 1"), nullptr);
});
EXPECT_EQ(adios.InquireIO("Test IO 2"), nullptr);
EXPECT_NO_THROW({
adios2::IO &io = *adios.InquireIO("Test IO 2");
adios2::IO &io = adios.DeclareIO("Test IO 2");
const adios2::Params &params = io.GetParameters();
ASSERT_EQ(params.size(), 0);
EXPECT_NE(adios.InquireIO("Test IO 2"), nullptr);
});
// double declaring
EXPECT_THROW(adios.DeclareIO("Test IO 1"), std::invalid_argument);
EXPECT_THROW(adios.DeclareIO("Test IO 2"), std::invalid_argument);
}
TEST_F(XMLConfigTest, TwoEnginesException)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment