Skip to content

Commit 0c49ed0

Browse files
author
Martin D. Weinberg
committed
Deduplicate cache tags, oops
1 parent 5fc1198 commit 0c49ed0

2 files changed

Lines changed: 94 additions & 149 deletions

File tree

expui/BiorthBasis.cc

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,54 +1691,27 @@ namespace BasisClasses
16911691
//
16921692
HighFive::File file(cachename, HighFive::File::ReadOnly);
16931693

1694-
if (!file.hasAttribute("EmpModel")) {
1695-
// If the EmpModel attribute is missing, we have an old
1696-
// cache type. We will allow this for now to avoid breaking
1697-
// old caches, but we will trigger a cache build in the future
1698-
//
1699-
if (myid==0) {
1700-
std::cout << "---- Cylindrical: EmpModel attribute not found in cache file <" << cachename << ">. " << std::endl;
1701-
std::cout << "---- Cylindrical: this may indicate an old cache file created before EmpModel metadata was added. " << std::endl;
1702-
std::cout << "---- Cylindrical: we will continue...but consider remaking the cache to avoid confusion." << std::endl;
1703-
}
1704-
} else {
1705-
// Open existing EmpModel attribute and the the mtype string
1706-
//
1707-
auto read_attr = file.getAttribute("EmpModel");
1708-
1709-
std::string empmodel;
1710-
read_attr.read(empmodel);
1711-
1712-
// Check against the current mtype string. If they do not
1713-
// match, force cache recomputation to ensure consistency
1714-
// with the current mtype.
1715-
if (empmodel != mtype) {
1716-
if (myid==0) {
1717-
std::cout << "---- Cylindrical: EmpModel for cache file <"
1718-
<< cachename << "> is <"
1719-
<< empmodel << ">," << std::endl
1720-
<< "which does not match the requested EmpModel <"
1721-
<< mtype << ">" << std::endl
1722-
<< "---- Cylindrical: forcing cache recomputation"
1723-
<< std::endl;
1724-
}
1725-
// Force cache recomputation
1726-
cache_status = 0;
1727-
}
1728-
}
1729-
1730-
if (cache_status == 1) {
1694+
// mtype is already cached as "model" attribute in the HDF5
1695+
// cache file, so we do not need to write it here. We just
1696+
// need to write the DiskType and Python metadata (if
1697+
// applicable).
1698+
//
17311699

1732-
// Sanity: check that the DiskType attribute exists
1733-
//
1734-
if (!file.hasAttribute("DiskType")) {
1735-
if (myid==0) {
1700+
// Check that the DiskType for the cache matches the requested
1701+
// DiskType If the DiskType attribute is missing from the
1702+
// cache, this indicates thet the cache was created with an
1703+
// older versions of the code that did not include the
1704+
// DiskType attribute in the cache. We should trigger a cache
1705+
// recomputation in this case to be safe, but will let this
1706+
// pass for backward compatibility with older caches.
1707+
//
1708+
if (!file.hasAttribute("DiskType")) {
1709+
if (myid==0) {
17361710
std::cout << "---- Cylindrical: DiskType attribute not found in cache file <" << cachename << ">. " << std::endl
1737-
<< "---- This is a logic error since the DiskType attribute is required for cache creation" << std::endl
1738-
<< "---- We will trigger cache recomputation to be safe." << std::endl;
1739-
}
1740-
// Force cache recomputation
1741-
cache_status = 0;
1711+
<< "---- This indicates that the cache was created with an older version of the" << std::endl
1712+
<< "---- code that did not include the DiskType attribute in the cache. We" << std::endl
1713+
<< "---- suggest deleting the old cache file to prevent this warning and rebuild" << std::endl
1714+
<< "---- the cache, but we will continue..." << std::endl;
17421715
} else {
17431716
// Open existing DiskType attribute
17441717
//
@@ -1880,7 +1853,9 @@ namespace BasisClasses
18801853
}
18811854
}
18821855
}
1856+
// End: DeprojType and Python module consistency checks with cache
18831857
}
1858+
// End: DiskType and Python module consistency checks with cache
18841859
}
18851860
catch (const HighFive::Exception& err) {
18861861
if (myid==0) {
@@ -2033,12 +2008,11 @@ namespace BasisClasses
20332008
//
20342009
HighFive::File file(cachename, HighFive::File::ReadWrite);
20352010

2036-
file.createAttribute("EmpModel", mtype);
2037-
2038-
std::cout << "---- Cylindrical: writing EmpModel <"
2039-
<< EmpCylSL::EmpModelLabs.at(EmpCylSL::mtype)
2040-
<< "> to cache file <" << cachename << ">" << std::endl;
2041-
2011+
// mtype is already cached as "model" attribute in the HDF5
2012+
// cache file, so we do not need to write it here. We just
2013+
// need to write the DiskType and Python metadata (if
2014+
// applicable).
2015+
//
20422016
file.createAttribute("DiskType", dtype);
20432017

20442018
std::cout << "---- Cylindrical: writing DiskType <" << dtype

src/Cylinder.cc

Lines changed: 68 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,125 +2069,92 @@ bool Cylinder::checkMetaData()
20692069
//
20702070
HighFive::File file(cachename, HighFive::File::ReadOnly);
20712071

2072-
// Sanity: check that the EmpModel attribute exists
2072+
// Sanity: check that the DiskType attribute exists
20732073
//
2074-
if (!file.hasAttribute("EmpModel")) {
2074+
if (!file.hasAttribute("DiskType")) {
20752075
if (myid==0) {
2076-
std::cout << "---- Cylinder:checkDtype: EmpModel attribute not found in cache file <" << cachename << ">" << std::endl
2076+
std::cout << "---- Cylinder:checkMetaData: DiskType attribute not found in cache file <" << cachename << ">" << std::endl
20772077
<< "---- This may indicate an old cache file created before EmpModel metadata was added" << std::endl
20782078
<< "---- We will continue...but consider remaking the cache to avoid confusion" << std::endl;
20792079
}
2080-
} else {
2081-
// Check that the EmpModel attribute matches the current empirical model
2080+
}
2081+
else {
2082+
// Open existing DiskType attribute
20822083
//
2083-
auto read_attr = file.getAttribute("EmpModel");
2084-
2085-
std::string loaded_mtype;
2086-
read_attr.read(loaded_mtype);
2087-
2088-
if (loaded_mtype != mtype) {
2084+
auto read_attr = file.getAttribute("DiskType");
2085+
2086+
std::string loaded_dtype;
2087+
read_attr.read(loaded_dtype);
2088+
2089+
// Map the loaded dtype string to a DiskType enum value
2090+
//
2091+
DiskType disktype = dtlookup.at(loaded_dtype);
2092+
2093+
if (disktype != DTYPE) {
20892094
if (myid==0) {
2090-
std::cout << "---- Cylinder::checkDtype: EmpModel for cache file <"
2091-
<< cachename << "> is <" << loaded_mtype << ">,"
2092-
<< " which does not match the requested empirical model <"
2093-
<< mtype << ">" << std::endl
2094-
<< "---- Cylindrical: forcing cache recomputation"
2095+
std::cout << "---- Cylinder::checkMetaData: DiskType for cache file <"
2096+
<< cachename << "> is <"
2097+
<< loaded_dtype << ">," << std::endl
2098+
<< "which does not match the requested DiskType <"
2099+
<< dtype << ">" << std::endl
2100+
<< "---- Cylinder::checkMetaData: forcing cache recomputation"
20952101
<< std::endl;
20962102
}
20972103
// Force cache recomputation
20982104
cache_status = false;
20992105
}
2100-
else {
2101-
2102-
if (!file.hasAttribute("DiskType")) {
2106+
else if (disktype == DiskType::python) {
2107+
// Sanity check: if DiskType is python, then the
2108+
// pythonDiskType attribute must exist
2109+
//
2110+
if (!file.hasAttribute("pythonDiskType")) {
21032111
if (myid==0) {
2104-
std::cout << "---- Cylinder:checkDtype: DiskType attribute not found in cache file <" << cachename << ">" << std::endl
2105-
<< "---- Cylinder:checkDtype: this may indicate a logic error. Forcing cache recomputation." << std::endl;
2112+
std::cout << "---- Cylinder::checkMetaData: pythonDiskType attribute not found in cache file <" << cachename << ">. " << std::endl;
2113+
std::cout << "---- Cylinder::checkMetaData: this may indicate a logic error. Forcing cache recomputation." << std::endl;
21062114
}
21072115
// Force cache recomputation
21082116
cache_status = false;
2109-
}
2110-
else {
2111-
// Open existing DiskType attribute
2112-
//
2113-
auto read_attr = file.getAttribute("DiskType");
2114-
2115-
std::string loaded_dtype;
2116-
read_attr.read(loaded_dtype);
2117-
2118-
// Map the loaded dtype string to a DiskType enum value
2119-
//
2120-
DiskType disktype = dtlookup.at(loaded_dtype);
2121-
2122-
if (disktype != DTYPE) {
2123-
if (myid==0) {
2124-
std::cout << "---- Cylinder::checkDtype: DiskType for cache file <"
2125-
<< cachename << "> is <"
2126-
<< loaded_dtype << ">," << std::endl
2127-
<< "which does not match the requested DiskType <"
2128-
<< dtype << ">" << std::endl
2129-
<< "---- Cylindrical: forcing cache recomputation"
2130-
<< std::endl;
2131-
}
2132-
// Force cache recomputation
2133-
cache_status = false;
2134-
}
2135-
else if (disktype == DiskType::python) {
2136-
// Sanity check: if DiskType is python, then the
2137-
// pythonDiskType attribute must exist
2138-
//
2139-
if (!file.hasAttribute("pythonDiskType")) {
2140-
if (myid==0) {
2141-
std::cout << "---- Cylinder::checkDtype: pythonDiskType attribute not found in cache file <" << cachename << ">. " << std::endl;
2142-
std::cout << "---- Cylindier:checkDtype: this may indicate a logic error. Forcing cache recomputation." << std::endl;
2143-
}
2144-
// Force cache recomputation
2145-
cache_status = false;
2146-
} else {
2147-
auto read_attr = file.getAttribute("pythonDiskType");
2117+
} else {
2118+
auto read_attr = file.getAttribute("pythonDiskType");
21482119

2149-
// Get the pyname attribute
2150-
std::vector<std::string> pyinfo;
2151-
read_attr.read(pyinfo);
2120+
// Get the pyname attribute
2121+
std::vector<std::string> pyinfo;
2122+
read_attr.read(pyinfo);
21522123

2153-
std::string current_md5;
2124+
std::string current_md5;
21542125

2155-
// Get the md5sum for requested Python module source file
2156-
try {
2157-
current_md5 = QuickDigest5::fileToHash(pyname);
2158-
} catch (const std::runtime_error& e) {
2159-
if (myid==0)
2160-
std::cerr << "Cylinder::CheckDtype error: "
2161-
<< e.what() << std::endl;
2162-
}
2126+
// Get the md5sum for requested Python module source file
2127+
try {
2128+
current_md5 = QuickDigest5::fileToHash(pyname);
2129+
} catch (const std::runtime_error& e) {
2130+
if (myid==0)
2131+
std::cerr << "Cylinder::checkMetaData error: "
2132+
<< e.what() << std::endl;
2133+
}
21632134

2164-
// Check that the md5sums match for the current Python
2165-
// module source files and the loaded Python module used to
2166-
// create the cache. If they do not match, force cache
2167-
// recomputation to ensure consistency with the current
2168-
// Python module.
2169-
//
2170-
if (current_md5 != pyinfo[1]) {
2171-
if (myid==0) {
2172-
std::cout << "---- Cylinder::checkDtype: Python module for disk density has changed since cache creation." << std::endl
2173-
<< "---- Current module: <" << pyname << ">, md5sum: " << current_md5 << std::endl
2174-
<< "---- Loaded module: <" << pyinfo[0] << ">, md5sum: " << pyinfo[1] << std::endl
2175-
<< "---- Cylindrical: forcing cache recomputation to ensure consistency" << std::endl;
2176-
}
2177-
cache_status = false;
2178-
}
2135+
// Check that the md5sums match for the current Python
2136+
// module source files and the loaded Python module used to
2137+
// create the cache. If they do not match, force cache
2138+
// recomputation to ensure consistency with the current
2139+
// Python module.
2140+
//
2141+
if (current_md5 != pyinfo[1]) {
2142+
if (myid==0) {
2143+
std::cout << "---- Cylinder::checkMetaData: Python module for disk density has changed since cache creation." << std::endl
2144+
<< "---- Current module: <" << pyname << ">, md5sum: " << current_md5 << std::endl
2145+
<< "---- Loaded module: <" << pyinfo[0] << ">, md5sum: " << pyinfo[1] << std::endl
2146+
<< "---- Cylinder:checkMetaData: forcing cache recomputation to ensure consistency" << std::endl;
21792147
}
2180-
// End: have Python disk type, check md5 hashes
2148+
cache_status = false;
21812149
}
2182-
// End: Python disk type check
21832150
}
2184-
// End: DiskType attribute check
2185-
2186-
// Could add deprojection checks here in the future
2151+
// End: have Python disk type, check md5 hashes
21872152
}
2188-
// End: DiskType attribute check
2153+
// End: Python disk type check
2154+
2155+
// Could add deprojection checks here in the future
21892156
}
2190-
// End: EmpModel attribute check
2157+
// End: DiskType attribute check
21912158

21922159
return cache_status;
21932160
}
@@ -2199,7 +2166,11 @@ void Cylinder::saveMetaData()
21992166
if (myid) return;
22002167

22012168
std::string dtype = dtstring.at(DTYPE);
2202-
2169+
2170+
// mtype is already cached as "model" attribute in the HDF5 cache
2171+
// file, so we do not need to write it here. We just need to write
2172+
// the DiskType and Python metadata (if applicable).
2173+
//
22032174
try {
22042175
// Reopen the cache file for writing the Python metadata
22052176
//
@@ -2223,7 +2194,7 @@ void Cylinder::saveMetaData()
22232194
file.createAttribute("pythonDiskType", pyinfo);
22242195

22252196
} catch (const std::runtime_error& e) {
2226-
std::cerr << "Cylinder::saveDtype error: " << e.what() << std::endl;
2197+
std::cerr << "Cylinder::saveMetaData error: " << e.what() << std::endl;
22272198
std::cerr << "Can not write the md5 hash to HDF5" << std::endl;
22282199
}
22292200
}
@@ -2232,7 +2203,7 @@ void Cylinder::saveMetaData()
22322203

22332204
} catch (const HighFive::Exception& err) {
22342205
std::cerr << err.what() << std::endl;
2235-
std::cerr << "Cylinder::saveDtype: error writing metadata to cache file <"
2206+
std::cerr << "Cylinder::saveMetaData: error writing metadata to cache file <"
22362207
<< cachename << std::endl;
22372208
}
22382209
}

0 commit comments

Comments
 (0)