@@ -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