[MOAB-dev] r3511 - MOAB/trunk

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Fri Jan 29 13:46:09 CST 2010


Author: kraftche
Date: 2010-01-29 13:46:09 -0600 (Fri, 29 Jan 2010)
New Revision: 3511

Modified:
   MOAB/trunk/MBCore.cpp
   MOAB/trunk/MBCore.hpp
Log:
Improve cleanup of failed attempts to read a file:

o In addition to deleting all entities created during the aborted file
  read, also delete all new tags created during the read.

o When trying every reader until one succeeds, clean up after each
  failed read attempt, rather than once if all read attempts fail.



Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp	2010-01-29 17:36:52 UTC (rev 3510)
+++ MOAB/trunk/MBCore.cpp	2010-01-29 19:46:09 UTC (rev 3511)
@@ -404,6 +404,27 @@
   return rval;
 }
 
+void MBCore::clean_up_failed_read( const MBRange& initial_ents,
+                                   std::vector<MBTag> initial_tags )
+{
+  MBRange new_ents;
+  get_entities_by_handle( 0, new_ents );
+  new_ents = subtract( new_ents, initial_ents );
+  delete_entities( new_ents );
+
+  std::vector<MBTag> all_tags, new_tags;
+  tag_get_tags( all_tags );
+  std::sort( initial_tags.begin(), initial_tags.end() );
+  std::sort( all_tags.begin(), all_tags.end() );
+  std::set_difference( all_tags.begin(), all_tags.end(),
+                       initial_tags.begin(), initial_tags.end(),
+                       std::back_inserter( new_tags ) );
+  while (!new_tags.empty()) {
+    tag_delete( new_tags.back() );
+    new_tags.pop_back();
+  }
+}
+
 MBErrorCode MBCore::serial_load_file( const char* file_name,
                                       const MBEntityHandle* file_set,
                                       const FileOptions& opts,
@@ -422,6 +443,11 @@
   rval = get_entities_by_handle( 0, initial_ents );
   if (MB_SUCCESS != rval)
     return rval;
+    
+  std::vector<MBTag> initial_tags;
+  rval = tag_get_tags( initial_tags );
+  if (MB_SUCCESS != rval)
+    return rval;
 
     // otherwise try using the file extension to select a reader
   MBReaderIface* reader = set->get_file_extension_reader( file_name );
@@ -443,17 +469,18 @@
         delete reader;
         if (MB_SUCCESS == rval)
           break;
+        clean_up_failed_read( initial_ents, initial_tags );
       }
     }
   }
   
-  MBRange new_ents;
-  get_entities_by_handle( 0, new_ents );
-  new_ents = subtract( new_ents, initial_ents );
   if (MB_SUCCESS != rval) {
-    delete_entities( new_ents );
+    clean_up_failed_read( initial_ents, initial_tags );
   }
   else if (file_set) {
+    MBRange new_ents;
+    get_entities_by_handle( 0, new_ents );
+    new_ents = subtract( new_ents, initial_ents );
     rval = add_entities( *file_set, new_ents );
   }
   

Modified: MOAB/trunk/MBCore.hpp
===================================================================
--- MOAB/trunk/MBCore.hpp	2010-01-29 17:36:52 UTC (rev 3510)
+++ MOAB/trunk/MBCore.hpp	2010-01-29 19:46:09 UTC (rev 3511)
@@ -1165,6 +1165,14 @@
     //! return the entity set representing the whole mesh
   MBEntityHandle get_root_set();
   
+  
+    //!\brief Clean up after a file reader returns failure.
+    //!
+    //! Delete all entities not contained in initial_entities
+    //! and all tags not contained in initial_tags.
+  void clean_up_failed_read( const MBRange& initial_entities,
+                             std::vector<MBTag> initial_tags );
+  
     // other interfaces for MB
   MBWriteUtil* mMBWriteUtil;
   MBReadUtil* mMBReadUtil;



More information about the moab-dev mailing list