@@ -2069,6 +2069,8 @@ void Cylinder::writeCovarH5Params(HighFive::File& file)
20692069
20702070bool Cylinder::checkDtype ()
20712071{
2072+ // All processes must check the dtype metadata to ensure consistency
2073+ //
20722074 bool cache_status = true ;
20732075
20742076 // Open the cache file for reading the Python metadata
@@ -2079,82 +2081,104 @@ bool Cylinder::checkDtype()
20792081 //
20802082 if (!file.hasAttribute (" DiskType" )) {
20812083 if (myid==0 ) {
2082- std::cout << " ---- Cylinder:checkDtype: DiskType attribute not found in cache file <" << cachename << " >. " << std::endl
2083- << " ---- This may indicate an old cache file created before DiskType metadata was added. " << std::endl
2084- << " ---- We will continue...but consider remaking the cache to avoid confusion. " << std::endl;
2084+ std::cout << " ---- Cylinder:checkDtype: DiskType attribute not found in cache file <" << cachename << " >" << std::endl
2085+ << " ---- This may indicate an old cache file created before DiskType metadata was added" << std::endl
2086+ << " ---- We will continue...but consider remaking the cache to avoid confusion" << std::endl;
20852087 }
20862088 } else {
2087- // Open existing DiskType attribute
2089+ // Check for existence of DiskType attribute
20882090 //
2089- auto read_attr = file.getAttribute (" DiskType" );
2091+ if (!file.hasAttribute (" DiskType" )) {
2092+ if (myid==0 ) {
2093+ std::cout << " ---- Cylinder::checkDtype: DiskType attribute not found in cache file <" << cachename << " >" << std::endl
2094+ << " ---- This may indicate an old cache file created before DiskType metadata was added" << std::endl
2095+ << " ---- We will continue...but consider remaking the cache to avoid confusion" << std::endl;
2096+ }
2097+ } else {
2098+ // Open existing DiskType attribute
2099+ //
2100+ auto read_attr = file.getAttribute (" DiskType" );
20902101
2091- std::string loaded_dtype;
2092- read_attr.read (loaded_dtype);
2102+ std::string loaded_dtype;
2103+ read_attr.read (loaded_dtype);
20932104
2094- DiskType disktype = dtlookup.at (loaded_dtype);
2105+ // Map the loaded dtype string to a DiskType enum value
2106+ //
2107+ DiskType disktype = dtlookup.at (loaded_dtype);
20952108
2096- if (disktype != DTYPE ) {
2097- if (myid==0 ) {
2098- std::cout << " ---- Cylinder::checkDtype: DiskType for cache file <"
2099- << cachename << " > is <"
2100- << loaded_dtype << " >," << std::endl
2101- << " which does not match the requested DiskType <"
2102- << dtype << " >" << std::endl
2103- << " ---- Cylindrical: forcing cache recomputation"
2104- << std::endl;
2105- }
2106- // Force cache recomputation
2107- cache_status = false ;
2108- }
2109- else if (disktype == DiskType::python) {
2110- // Sanity check: if DiskType is python, then the pythonDiskType
2111- // attribute must exist
2112- if (!file.hasAttribute (" pythonDiskType" )) {
2109+ if (disktype != DTYPE ) {
21132110 if (myid==0 ) {
2114- std::cout << " ---- Cylinder::checkDtype: pythonDiskType attribute not found in cache file <" << cachename << " >. " << std::endl;
2115- std::cout << " ---- Cylindier:checkDtype: this may indicate a logic error. Forcing cache recomputation." << std::endl;
2111+ std::cout << " ---- Cylinder::checkDtype: DiskType for cache file <"
2112+ << cachename << " > is <"
2113+ << loaded_dtype << " >," << std::endl
2114+ << " which does not match the requested DiskType <"
2115+ << dtype << " >" << std::endl
2116+ << " ---- Cylindrical: forcing cache recomputation"
2117+ << std::endl;
21162118 }
21172119 // Force cache recomputation
2118- cache_status = false ;
2120+ cache_status = false ;
21192121 }
2120- auto read_attr = file.getAttribute (" pythonDiskType" );
2121-
2122- // Get the pyname attribute
2123- std::vector<std::string> pyinfo;
2124- read_attr.read (pyinfo);
2122+ else if (disktype == DiskType::python) {
2123+ // Sanity check: if DiskType is python, then the
2124+ // pythonDiskType attribute must exist
2125+ //
2126+ if (!file.hasAttribute (" pythonDiskType" )) {
2127+ if (myid==0 ) {
2128+ std::cout << " ---- Cylinder::checkDtype: pythonDiskType attribute not found in cache file <" << cachename << " >. " << std::endl;
2129+ std::cout << " ---- Cylindier:checkDtype: this may indicate a logic error. Forcing cache recomputation." << std::endl;
2130+ }
2131+ // Force cache recomputation
2132+ cache_status = false ;
2133+ } else {
2134+ auto read_attr = file.getAttribute (" pythonDiskType" );
2135+
2136+ // Get the pyname attribute
2137+ std::vector<std::string> pyinfo;
2138+ read_attr.read (pyinfo);
21252139
2126- std::string current_md5;
2127-
2128- // Get the md5sum for requested Python module source file
2129- try {
2130- current_md5 = QuickDigest5::fileToHash (pyname);
2131- } catch (const std::runtime_error& e) {
2132- if (myid==0 )
2133- std::cerr << " Error: " << e.what () << std::endl;
2134- }
2140+ std::string current_md5;
21352141
2136- // Check that the md5sums match for the current Python module
2137- // source files and the loaded Python module used to create the
2138- // cache. If they do not match, force cache recomputation to
2139- // ensure consistency with the current Python module.
2140- if (current_md5 != pyinfo[1 ]) {
2141- if (myid==0 ) {
2142- std::cout << " ---- Cylinder::checkDtype: Python module for disk density has changed since cache creation." << std::endl
2143- << " ---- Current module: <" << pyname << " >, md5sum: " << current_md5 << std::endl
2144- << " ---- Loaded module: <" << pyinfo[0 ] << " >, md5sum: " << pyinfo[1 ] << std::endl
2145- << " ---- Cylindrical: forcing cache recomputation to ensure consistency" << std::endl;
2142+ // Get the md5sum for requested Python module source file
2143+ try {
2144+ current_md5 = QuickDigest5::fileToHash (pyname);
2145+ } catch (const std::runtime_error& e) {
2146+ if (myid==0 )
2147+ std::cerr << " Cylinder::CheckDtype error: "
2148+ << e.what () << std::endl;
2149+ }
2150+
2151+ // Check that the md5sums match for the current Python
2152+ // module source files and the loaded Python module used to
2153+ // create the cache. If they do not match, force cache
2154+ // recomputation to ensure consistency with the current
2155+ // Python module.
2156+ //
2157+ if (current_md5 != pyinfo[1 ]) {
2158+ if (myid==0 ) {
2159+ std::cout << " ---- Cylinder::checkDtype: Python module for disk density has changed since cache creation." << std::endl
2160+ << " ---- Current module: <" << pyname << " >, md5sum: " << current_md5 << std::endl
2161+ << " ---- Loaded module: <" << pyinfo[0 ] << " >, md5sum: " << pyinfo[1 ] << std::endl
2162+ << " ---- Cylindrical: forcing cache recomputation to ensure consistency" << std::endl;
2163+ }
2164+ cache_status = false ;
2165+ }
21462166 }
2147- cache_status = false ;
2167+ // End: have Python disk type, check md5 hashes
21482168 }
2169+ // End: Python disk type check
21492170 }
2171+ // End: DiskType attribute exists, check value
21502172 }
2173+ // End: DiskType attribute check
21512174
21522175 return cache_status;
21532176}
21542177
21552178void Cylinder::saveDtype ()
21562179{
21572180 // Only one process must write the dtype metadata
2181+ //
21582182 if (myid) return ;
21592183
21602184 std::string dtype = dtstring.at (DTYPE );
@@ -2168,7 +2192,7 @@ void Cylinder::saveDtype()
21682192 //
21692193 file.createAttribute (" DiskType" , dtype);
21702194
2171- // Write the md5sum for the Python module source file, if Python
2195+ // Write the md5sum for the Python module source file if Python
21722196 // disk type is used. This will allow us to check for consistency
21732197 // between the Python module used to create the cache and the
21742198 // current Python module, and force cache recomputation if they do
@@ -2186,6 +2210,9 @@ void Cylinder::saveDtype()
21862210 std::cerr << " Can not write the md5 hash to HDF5" << std::endl;
21872211 }
21882212 }
2213+
2214+ // Deprojection metadata could be added here
2215+
21892216 } catch (const HighFive::Exception& err) {
21902217 std::cerr << err.what () << std::endl;
21912218 std::cerr << " Cylinder::saveDtype: error writing metadata to cache file <"
0 commit comments