@@ -58,6 +58,13 @@ namespace openPMD
58
58
throw std::runtime_error ((TEXT)); \
59
59
}
60
60
61
+ namespace JSONDefaults
62
+ {
63
+ using const_str = char const *const ;
64
+ constexpr const_str openpmd_internal = " __openPMD_internal" ;
65
+ constexpr const_str IOMode = " IO_mode" ;
66
+ } // namespace JSONDefaults
67
+
61
68
namespace
62
69
{
63
70
struct DefaultValue
@@ -166,6 +173,7 @@ JSONIOHandlerImpl::JSONIOHandlerImpl(
166
173
" Invalid value: '" + mode +
167
174
" ' (accepted values are 'dataset' and 'template'." );
168
175
}
176
+ m_modeWasManuallySpecified = true ;
169
177
}
170
178
auto shadow = jsonConfig.invertShadow ();
171
179
if (shadow.size () > 0 )
@@ -1580,6 +1588,55 @@ std::shared_ptr<nlohmann::json> JSONIOHandlerImpl::obtainJsonContents(File file)
1580
1588
break ;
1581
1589
}
1582
1590
VERIFY (fh->good (), " [JSON] Failed reading from a file." );
1591
+ if (res->contains (JSONDefaults::openpmd_internal))
1592
+ {
1593
+ auto const &openpmd_internal = res->at (JSONDefaults::openpmd_internal);
1594
+ if (openpmd_internal.contains (JSONDefaults::IOMode))
1595
+ {
1596
+ auto modeOption = openPMD::json::asLowerCaseStringDynamic (
1597
+ openpmd_internal.at (JSONDefaults::IOMode));
1598
+ if (!modeOption.has_value ())
1599
+ {
1600
+ std::cerr
1601
+ << " [JSON/TOML backend] Warning: Invalid value of "
1602
+ " non-string type at internal meta table for entry '"
1603
+ << JSONDefaults::IOMode << " '. Will ignore and continue."
1604
+ << std::endl;
1605
+ }
1606
+ else if (modeOption.value () == " dataset" )
1607
+ {
1608
+ if (m_modeWasManuallySpecified && m_mode == IOMode::Template)
1609
+ {
1610
+ std::cerr
1611
+ << " [JSON/TOML backend] Warning: IO Mode was manually "
1612
+ " specified as 'Template', but opened file is in "
1613
+ " 'Dataset' mode. Will continue with dataset mode."
1614
+ << std::endl;
1615
+ }
1616
+ m_mode = IOMode::Dataset;
1617
+ }
1618
+ else if (modeOption.value () == " template" )
1619
+ {
1620
+ if (m_modeWasManuallySpecified && m_mode == IOMode::Dataset)
1621
+ {
1622
+ std::cerr
1623
+ << " [JSON/TOML backend] Warning: IO Mode was manually "
1624
+ " specified as 'Dataset', but opened file is in "
1625
+ " 'Template' mode. Will continue with template mode."
1626
+ << std::endl;
1627
+ }
1628
+ m_mode = IOMode::Template;
1629
+ }
1630
+ else
1631
+ {
1632
+ std::cerr << " [JSON/TOML backend] Warning: Invalid value '"
1633
+ << modeOption.value ()
1634
+ << " ' at internal meta table for entry '"
1635
+ << JSONDefaults::IOMode
1636
+ << " '. Will ignore and continue." << std::endl;
1637
+ }
1638
+ }
1639
+ }
1583
1640
m_jsonVals.emplace (file, res);
1584
1641
return res;
1585
1642
}
@@ -1608,8 +1665,12 @@ void JSONIOHandlerImpl::putJsonContents(
1608
1665
{
1609
1666
case IOMode::Dataset:
1610
1667
(*it->second )[" platform_byte_widths" ] = platformSpecifics ();
1668
+ (*it->second )[JSONDefaults::openpmd_internal]
1669
+ [JSONDefaults::IOMode] = " dataset" ;
1611
1670
break ;
1612
1671
case IOMode::Template:
1672
+ (*it->second )[JSONDefaults::openpmd_internal]
1673
+ [JSONDefaults::IOMode] = " template" ;
1613
1674
break ;
1614
1675
}
1615
1676
0 commit comments