MOAB: Mesh Oriented datABase  (version 5.3.0)
ReadDamsel.cpp
Go to the documentation of this file.
00001 /** MOAB Damsel file reader
00002  * For description of the Damsel-MOAB data model mapping, see WriteDamsel.cpp.
00003  *
00004  */
00005 
00006 #include "moab/ParallelComm.hpp"
00007 
00008 #include "ReadDamsel.hpp"
00009 
00010 #include <cassert>
00011 #include "moab/Interface.hpp"
00012 #include "moab/Core.hpp"
00013 #include "moab/Range.hpp"
00014 #include "moab/Error.hpp"
00015 #include "moab/ReadUtilIface.hpp"
00016 #include "moab/FileOptions.hpp"
00017 #include "MBTagConventions.hpp"
00018 #include "EntitySequence.hpp"
00019 #include "Internals.hpp"
00020 #include "DenseTag.hpp"
00021 
00022 namespace moab
00023 {
00024 
00025 ReaderIface* ReadDamsel::factory( Interface* iface )
00026 {
00027     return new ReadDamsel( iface );
00028 }
00029 
00030 ReadDamsel::ReadDamsel( Interface* impl )
00031     : mbImpl( impl ), readMeshIface( NULL ), nativeParallel( false ), myPcomm( NULL ), mGlobalIdTag( 0 ), dU()
00032 {
00033     init();
00034 }
00035 
00036 ReadDamsel::~ReadDamsel()
00037 {
00038     if( readMeshIface ) mbImpl->release_interface( readMeshIface );
00039 
00040     DMSLlib_finalize( dU.dmslLib );
00041 }
00042 
00043 ErrorCode ReadDamsel::init()
00044 {
00045     mbImpl->query_interface( readMeshIface );
00046     assert( readMeshIface );
00047 
00048     return MB_SUCCESS;
00049 }
00050 
00051 ErrorCode ReadDamsel::parse_options( const FileOptions& opts, bool& parallel )
00052 {
00053     // Handle parallel options
00054     bool use_mpio  = ( MB_SUCCESS == opts.get_null_option( "USE_MPIO" ) );
00055     ErrorCode rval = opts.match_option( "PARALLEL", "READ_PART" );
00056     parallel       = ( rval != MB_ENTITY_NOT_FOUND );
00057     nativeParallel = ( rval == MB_SUCCESS );
00058     if( use_mpio && !parallel )
00059     {
00060         MB_SET_ERR( MB_NOT_IMPLEMENTED, "'USE_MPIO' option specified w/out 'PARALLEL' option" );
00061     }
00062 
00063     return MB_SUCCESS;
00064 }
00065 
00066 // ASSUMPTIONS:
00067 // Partition collection is a *flat* collection of handles for entities and other collections that
00068 // will be represented on a part
00069 
00070 ErrorCode ReadDamsel::load_file( const char* filename, const EntityHandle* file_set, const FileOptions& opts,
00071                                  const ReaderIface::SubsetList* subset_list, const Tag* file_id_tag )
00072 {
00073     ErrorCode rval;
00074 
00075     rval = parse_options( opts, nativeParallel );
00076     if( MB_SUCCESS != rval ) return rval;
00077 
00078     // Initialize damsel
00079     dU.dmslLib = DMSLlib_init();
00080 
00081     // Create a damsel model
00082     dU.dmslModel =
00083         DMSLmodel_create( sizeof( EntityHandle ) == 8 ? DAMSEL_HANDLE_TYPE_HANDLE64 : DAMSEL_HANDLE_TYPE_HANDLE32 );
00084 
00085     // Model attach - need model id from make model, filename
00086 #ifdef MOAB_HAVE_MPI
00087     MPI_Comm comm = MPI_COMM_WORLD;
00088     if( nativeParallel ) { comm = myPcomm->proc_config().proc_comm(); }
00089 #endif
00090 
00091     damsel_err_t err;
00092     err = DMSLmodel_attach( dU.dmslModel, filename, comm, NULL );
00093     CHK_DMSL_ERR( err, "DMSLmodel_attach failed" );
00094     err = DMSLmodel_populate( dU.dmslModel );
00095     CHK_DMSL_ERR( err, "DMSLmodel_populate failed" );
00096 
00097     // STEP 0: GET COLLECTION, TAG, ENTITY INFOS FOR GLOBAL MODEL
00098     int num_containers = 0, num_tag_infos = 0, num_ent_infos = 0;
00099     DMSLmodel_get_tuple_count( dU.dmslModel, &num_containers, &num_tag_infos );
00100     num_ent_infos      = DMSLmodel_get_entity_count( dU.dmslModel );
00101     int num_coll_infos = DMSLmodel_get_collection_count( dU.dmslModel );
00102     CHK_DMSL_ERR( err, "DMSLmodel_get_collection_count failed" );
00103     if( -1 == num_containers || -1 == num_tag_infos || -1 == num_ent_infos )
00104         MB_SET_ERR( MB_FAILURE, "Bad count for containers/tags/ents" );
00105 
00106     std::vector< damsel_entity_buf_type > ent_infos( num_ent_infos );
00107     std::vector< damsel_collection_buf_type > coll_infos( num_coll_infos );
00108     std::vector< damsel_tag_buf_type > tag_infos( num_tag_infos );
00109     std::vector< damsel_container_buf_type > cont_infos( num_containers );
00110     err = DMSLmodel_get_entity_infos( dU.dmslModel, &ent_infos[0] );
00111     CHK_DMSL_ERR( err, "Failure getting entity infos" );
00112     err = DMSLmodel_get_collection_infos( dU.dmslModel, &coll_infos[0] );
00113     CHK_DMSL_ERR( err, "Failure getting collection infos" );
00114     err = DMSLmodel_get_tag_infos( dU.dmslModel, &tag_infos[0] );
00115     CHK_DMSL_ERR( err, "Failure getting tag infos" );
00116     err = DMSLmodel_get_container_infos( dU.dmslModel, &cont_infos[0] );
00117     CHK_DMSL_ERR( err, "Failure getting container infos" );
00118 
00119     // Create MOAB-side tags for all damsel tags except pre-defined ones
00120     rval = process_tags( tag_infos );MB_CHK_SET_ERR( rval, "Error processing tags" );
00121 
00122     /*
00123       if (nativeParallel) {
00124         // STEP 1: GET COLLECTION(S) REPRESENTING PARTITION:
00125         // Input: tag name, optionally value;
00126         // Output: container with file-side handles of collections satisfying those criteria
00127         // - Get all handles/values for tag
00128         // - Select handles matching criteria for tag value (will be collection handles)
00129         std::string partn_tag_name("PARALLEL_PARTITION");
00130         damsel_handle partn_tag = DMSLselect_tag_by_name(dU.dmslModel, partn_tag_name.c_str());
00131         // Get all the parts with that tag regardless of value
00132         damsel_container part_handles = DMSLselect_handles_with_values(dU.dmslModel, partn_tag);
00133 
00134         // STEP 2: GET HANDLES FOR TAGS WE NEED FOR THIS READER:
00135         // - "SET_CHARACTERISTIC"
00136         damsel_handle setchar_tag = DMSLselect_tag_by_name(dU.dmslModel, "SET_CHARACTERISTIC");
00137         // - "PARENT_LIST"
00138         //damsel_handle plist_tag = DMSLselect_tag_by_name(dU.dmslModel, "PARENT_LIST");
00139         // - "CHILD_LIST"
00140         //damsel_handle clist_tag = DMSLselect_tag_by_name(dU.dmslModel, "CHILD_LIST");
00141 
00142         // STEP 3: GET VALUES FOR "SET_CHARACTERISTIC" TAG ON PARTITION COLLECTIONS,
00143         //         GET VECTOR- OR SET-TYPE FLAGS FOR PARTITION COLLECTIONS
00144         // (gives tracking flag for moab)
00145         int num_handles = DMSLcontainer_count(part_handles);
00146         std::vector<unsigned> char_tagvals(num_handles);
00147         // Map the set chars
00148         err = DMSLmodel_map_tag(&char_tagvals[0], part_handles, &setchar_tag);CHK_DMSL_ERR(err,
00149       "Problem calling DMSLmodel_map_tag");
00150 
00151         // Execute the transfer
00152         err = DMSLmodel_transfer_sync(dU.dmslModel, DAMSEL_TRANSFER_TYPE_READ);CHK_DMSL_ERR(err,
00153       "Problem calling DMSLmodel_transfer_sync");
00154 
00155         // STEP 4: READ/PROCESS PARTITION COLLECTION(S)
00156         // Decide the handles I am responsible using round-robin for now
00157         // - GET TYPE, CONTENTS OF COLLECTION CONTENTS CONTAINER
00158         // - Allocate moab-side container (using count from container)
00159         // - MAP storage TO CONTAINER
00160         // - EXECUTE
00161         // ==> have list of all handles (entities + collections) represented on this proc
00162 
00163         int tmp_num = num_handles / proc_size, extra = num_handles % proc_size;
00164         if (extra) tmp_num++;
00165         int my_num_handles = tmp_num;
00166         if (proc_rank >= extra) my_num_handles--;
00167         int first_ind = std::min(proc_rank, extra) * tmp_num +
00168             std::max(proc_rank - extra, 0) * (tmp_num - 1);
00169 
00170         // - Create moab entity sets for partition collection(s)
00171         EntityHandle start_handle;
00172         rval = readMeshIface->create_entity_sets(my_num_handles, &char_tagvals[first_ind], 0,
00173       start_handle);MB_CHK_SET_ERR(rval, "Problem creating entity sets");
00174       }
00175       else {
00176     */
00177     // Initialize just by entity; each call to process_ent_info will:
00178     // a. Create moab-side representation to read into
00179     // b. Map those handles to damsel handles
00180     // c. Map coords / connectivity storage to damsel equivalent
00181     // d. For each tag, map moab storage to damsel storage
00182     std::vector< damsel_entity_buf_type >::iterator eiit;
00183 
00184     // Process verts info first
00185     for( eiit = ent_infos.begin(); eiit != ent_infos.end(); ++eiit )
00186     {
00187         if( ( *eiit ).entity_type == DAMSEL_ENTITY_TYPE_VERTEX )
00188         {
00189             rval = process_ent_info( *eiit );MB_CHK_ERR( rval );
00190         }
00191     }
00192 
00193     for( eiit = ent_infos.begin(); eiit != ent_infos.end(); ++eiit )
00194     {
00195         if( ( *eiit ).entity_type != DAMSEL_ENTITY_TYPE_VERTEX )
00196         {
00197             rval = process_ent_info( *eiit );MB_CHK_ERR( rval );
00198         }
00199     }
00200 
00201     /*
00202       }
00203 
00204       // Process collections
00205       rval = process_coll_infos(coll_infos);MB_CHK_ERR(rval);
00206 
00207       // STEP 5: Process into list of local info structs, each represents file-side struct and
00208       // portion of that struct
00209       // ASSUMPTION: Each local info struct represents single entity type & # vertices or collection
00210 
00211       // STEP 6: For each local info struct:
00212 
00213       // STEP 6b: READ CONTAINER INTO LOCAL BUFFER
00214       // STEP 6c: Create app representation of entities/vertices/collection, and damsel container
00215       for them,
00216       //    and MAP APP HANDLE CONTAINER TO DAMSEL CONTAINER
00217       // STEP 6d: Process vertices/entities/collection
00218       //    6d1: If vertices, continue
00219       //    6d2: If entities:
00220       //    - MAP LOCAL CONNECTIVITY REP'N TO DAMSEL (might be tag, don't know yet)
00221       //    6d3: If collection:
00222       //    - (everything in STEP 4 for this collection except for EXECUTE)
00223       //    - might need to filter out things not represented on this rank
00224       //    6d4: If sparse tag:
00225       //    - Create app-side representation of sparse tag
00226       //    - READ CONTAINER OF MODEL HANDLES INTO LOCAL BUFFER
00227       //    - Allocate app-side storage for tag values
00228       //    - MAP APP STORAGE TO MODEL TAG + (implicit?) CONTAINER
00229 
00230       // STEP 6e: Process dense tags for the local info struct; for each dense tag:
00231       //   - Get app tag handle for model tag handle
00232       //   - Get app storage for app tag handle + container
00233       //   - MAP APP STORAGE TO MODEL TAG + CONTAINER
00234 
00235       // STEP 7: EXECUTE
00236       //   - Assign all mapped data
00237       //   - Translate all damsel handles to app handles
00238       // uninit damsel
00239 
00240     */
00241 
00242     return MB_SUCCESS;
00243 }
00244 
00245 ErrorCode ReadDamsel::read_tag_values( const char* file_name, const char* tag_name, const FileOptions& opts,
00246                                        std::vector< int >& tag_values_out, const SubsetList* subset_list )
00247 {
00248     return MB_FAILURE;
00249 }
00250 
00251 ErrorCode ReadDamsel::process_tags( std::vector< damsel_tag_buf_type >& tag_infos )
00252 {
00253     Tag tagh;
00254     ErrorCode rval = MB_SUCCESS, tmp_rval;
00255     for( std::vector< damsel_tag_buf_type >::iterator tit = tag_infos.begin(); tit != tag_infos.end(); ++tit )
00256     {
00257         if( DamselUtil::dtom_data_type[( *tit ).tag_datatype] == MB_TYPE_OPAQUE )
00258         {
00259             std::cout << "Damsel reader encountered opaque tag." << std::endl;
00260             continue;
00261         }
00262 
00263         tmp_rval = mbImpl->tag_get_handle( ( *tit ).name, 1, DamselUtil::dtom_data_type[( *tit ).tag_datatype], tagh,
00264                                            MB_TAG_CREAT | MB_TAG_DENSE );
00265         if( MB_SUCCESS != tmp_rval )
00266             rval = tmp_rval;
00267         else
00268         {
00269             dU.tagMap.push_back( DamselUtil::tinfo( tagh, 0, MB_TAG_DENSE ) );
00270             // Also store predefined tags specially...
00271             if( !strncmp( ( *tit ).name, "mbdmsl_", 7 ) )
00272             {
00273                 // Predefined tag name, store the handle
00274                 if( !strcmp( ( *tit ).name, "mbdmsl_XCOORDS" ) )
00275                     dU.xcoordsTag = dU.tagMap.back();
00276                 else if( !strcmp( ( *tit ).name, "mbdmsl_YCOORDS" ) )
00277                 {
00278                     dU.ycoordsTag = dU.tagMap.back();
00279                 }
00280                 else if( !strcmp( ( *tit ).name, "mbdmsl_ZCOORDS" ) )
00281                 {
00282                     dU.zcoordsTag = dU.tagMap.back();
00283                 }
00284                 else if( !strcmp( ( *tit ).name, "mbdmsl_COLL_FLAGS" ) )
00285                 {
00286                     dU.collFlagsTag = dU.tagMap.back();
00287                 }
00288                 else if( !strcmp( ( *tit ).name, "mbdmsl_PARENTS" ) )
00289                 {
00290                     dU.parentsTag = dU.tagMap.back();
00291                 }
00292                 else if( !strcmp( ( *tit ).name, "mbdmsl_CHILDREN" ) )
00293                 {
00294                     dU.childrenTag = dU.tagMap.back();
00295                 }
00296                 else
00297                 {
00298                     rval = MB_FAILURE;
00299                     continue;
00300                 }
00301             }
00302         }
00303     }
00304 
00305     return rval;
00306 }
00307 
00308 ErrorCode ReadDamsel::process_ent_info( const damsel_entity_buf_type& einfo )
00309 {
00310     // Create this chunk of entities
00311     EntityHandle *connect, start_handle;
00312     ErrorCode rval;
00313     damsel_err_t err;
00314     damsel_container app_cont;
00315     Range these_ents;
00316 
00317     // Check that there's only one contiguous run of file-side handles, fail if there isn't
00318 #ifndef NDEBUG
00319     Range fside_handles;
00320     rval = DamselUtil::container_to_range( dU.dmslModel, const_cast< damsel_container& >( einfo.entity_container ),
00321                                            fside_handles );
00322     if( MB_SUCCESS != rval || fside_handles.size() != einfo.count || fside_handles.psize() != 1 ) return MB_FAILURE;
00323 #endif
00324 
00325     if( einfo.entity_type != DAMSEL_ENTITY_TYPE_VERTEX )
00326     {
00327         // Create the moab entities
00328         rval = readMeshIface->get_element_connect( einfo.count, einfo.vertices_per_entity,
00329                                                    DamselUtil::dtom_entity_type[einfo.entity_type], 0, start_handle,
00330                                                    connect );MB_CHK_ERR( rval );
00331         these_ents.insert( start_handle, start_handle + einfo.count - 1 );
00332 
00333         // Create an app-side sequence and map to file-side container
00334         app_cont = DMSLcontainer_create_sequence( dU.dmslModel, einfo.count, start_handle, 1 );
00335         err      = DMSLmodel_map_handles( app_cont, einfo.entity_container );
00336         CHK_DMSL_ERR( err, "Error returned mapping entity handles" );
00337 
00338         // Map connectivity
00339         assert( DMSLcontainer_count( einfo.vertex_container ) == (int)( einfo.vertices_per_entity * einfo.count ) );
00340         rval = get_contents( dU.dmslModel, einfo.vertex_container, connect );MB_CHK_SET_ERR( rval, "Error returned mapping connectivity" );
00341     }
00342     else
00343     {
00344         // Get the number of coordinate arrays
00345         int num_ctags             = 0;
00346         damsel_handle xcoord_dtag = DMSLselect_tag_by_name( dU.dmslModel, "mbdmsl_XCOORDS" );
00347         if( xcoord_dtag ) num_ctags++;
00348         damsel_handle ycoord_dtag = DMSLselect_tag_by_name( dU.dmslModel, "mbdmsl_YCOORDS" );
00349         if( ycoord_dtag ) num_ctags++;
00350         damsel_handle zcoord_dtag = DMSLselect_tag_by_name( dU.dmslModel, "mbdmsl_ZCOORDS" );
00351         if( zcoord_dtag ) num_ctags++;
00352 
00353         // Should have one vertex per entity
00354         assert( einfo.vertices_per_entity == 1 );
00355         std::vector< double* > coord_arrays;
00356         rval = readMeshIface->get_node_coords( num_ctags, einfo.count, 0, start_handle, coord_arrays );MB_CHK_ERR( rval );
00357 
00358         these_ents.insert( start_handle, start_handle + einfo.count - 1 );
00359 
00360         // Create an app-side sequence and map to file-side container
00361         app_cont = DMSLcontainer_create_sequence( dU.dmslModel, start_handle, einfo.count, 1 );
00362         err      = DMSLmodel_map_handles( app_cont, einfo.entity_container );
00363         CHK_DMSL_ERR( err, "Trouble mapping entity handles" );
00364 
00365         // Map the coords storage
00366         if( xcoord_dtag != 0 )
00367         {
00368             err = DMSLmodel_map_tag( coord_arrays[0], app_cont, (damsel_handle_ptr)&dU.xcoordsTag.mTagh );
00369             CHK_DMSL_ERR( err, "Trouble mapping x coordinate tag" );
00370         }
00371         if( ycoord_dtag != 0 )
00372         {
00373             err = DMSLmodel_map_tag( coord_arrays[1], app_cont, (damsel_handle_ptr)&dU.ycoordsTag.mTagh );
00374             CHK_DMSL_ERR( err, "Trouble mapping y coordinate tag" );
00375         }
00376         if( zcoord_dtag != 0 )
00377         {
00378             err = DMSLmodel_map_tag( coord_arrays[2], app_cont, (damsel_handle_ptr)&dU.zcoordsTag.mTagh );
00379             CHK_DMSL_ERR( err, "Trouble mapping z coordinate tag" );
00380         }
00381     }
00382 
00383     // Save mapping from moab entity to einfo
00384     dmHandleRMap.insert( DMSLcontainer_handle_at_position( einfo.entity_container, 0 ), start_handle, einfo.count );
00385 
00386     rval = process_entity_tags( einfo.tag_count, einfo.tag_handle_container, app_cont, these_ents );
00387 
00388     return rval;
00389 }
00390 
00391 ErrorCode ReadDamsel::process_entity_tags( int count, damsel_container tag_container, damsel_container app_cont,
00392                                            Range& these_ents )
00393 {
00394     // Process tags on these entities
00395     ErrorCode rval = MB_SUCCESS;
00396     for( int i = 0; i < count; i++ )
00397     {
00398         damsel_handle dtagh = DMSLcontainer_handle_at_position( tag_container, i );
00399 
00400         // Don't do conventional tags here
00401         std::vector< DamselUtil::tinfo >::iterator vit =
00402             std::find_if( dU.tagMap.begin(), dU.tagMap.end(), DamselUtil::DtagP< DamselUtil::tinfo >( dtagh ) );
00403 
00404         if( ( *vit ).tagType == MB_TAG_ANY )
00405             continue;
00406         else if( vit == dU.tagMap.end() )
00407             MB_SET_ERR( MB_FAILURE, "Failed to find tag" );
00408 
00409         Tag tagh = ( *vit ).mTagh;
00410         assert( tagh );
00411         void* tag_data;
00412         int ecount = these_ents.size();
00413         rval       = mbImpl->tag_iterate( tagh, these_ents.begin(), these_ents.end(), ecount, tag_data );MB_CHK_SET_ERR( rval, "Problem getting tag iterator" );
00414         assert( ecount == (int)these_ents.size() );
00415         damsel_err_t err = DMSLmodel_map_tag( tag_data, app_cont, (damsel_handle_ptr)&tagh );
00416         CHK_DMSL_ERR( err, "Problem calling DMSLmodel_map_tag" );
00417     }
00418 
00419     return rval;
00420 }
00421 
00422 ErrorCode ReadDamsel::get_contents( damsel_model m, damsel_container c, Range& ents )
00423 {
00424     EntityHandle eh;
00425     if( DMSLcontainer_get_type( c ) == DAMSEL_HANDLE_CONTAINER_TYPE_SEQUENCE )
00426     {
00427         damsel_handle start;
00428         size_t count, stride;
00429         damsel_err_t err = DMSLcontainer_sequence_get_contents( m, c, &start, &count, &stride );
00430         CHK_DMSL_ERR( err, "DMSLcontainer_sequence_get_contents" );
00431         if( stride == 1 )
00432         {
00433             while( count )
00434             {
00435                 // Get start in rangemap
00436                 RangeMap< damsel_handle, EntityHandle, 0 >::iterator beg = dmHandleRMap.lower_bound( start );
00437                 if( beg == dmHandleRMap.end() ) return MB_SUCCESS;
00438                 unsigned long diff = std::max( ( *beg ).begin - start, (damsel_handle)0 );
00439                 unsigned long num  = std::min( count - diff, ( size_t )( *beg ).count );
00440                 ents.insert( ( *beg ).begin + diff, ( *beg ).begin + diff + num - 1 );
00441                 count -= ( diff + num );
00442                 ++beg;
00443             }
00444         }
00445         else
00446         {
00447             for( int i = count - 1; i >= 0; i-- )
00448             {
00449                 if( dmHandleRMap.find( start + i, eh ) ) ents.insert( eh );
00450             }
00451         }
00452     }
00453     else if( DMSLcontainer_get_type( c ) == DAMSEL_HANDLE_CONTAINER_TYPE_VECTOR )
00454     {
00455         damsel_handle* handle_ptr;
00456         size_t count;
00457         damsel_err_t err = DMSLcontainer_vector_get_contents( m, c, &handle_ptr, &count );
00458         CHK_DMSL_ERR( err, "Trouble getting vector contents" );
00459         for( int i = count - 1; i >= 0; i-- )
00460         {
00461             if( dmHandleRMap.find( handle_ptr[i], eh ) ) ents.insert( eh );
00462         }
00463     }
00464     else if( DMSLcontainer_get_type( c ) == DAMSEL_HANDLE_CONTAINER_TYPE_TREE )
00465     {
00466         damsel_handle_ptr node_ptr = NULL;
00467         damsel_container cont      = NULL;
00468         while( DMSLcontainer_tree_get_contents( m, c, &node_ptr, &cont ) == DMSL_OK && cont )
00469         {
00470             ErrorCode rval = get_contents( m, c, ents );
00471             if( MB_SUCCESS != rval ) return rval;
00472         }
00473     }
00474 
00475     return MB_SUCCESS;
00476 }
00477 
00478 ErrorCode ReadDamsel::get_contents( damsel_model m, damsel_container c, EntityHandle* ents )
00479 {
00480     EntityHandle eh;
00481     int ind = 0;
00482 
00483     if( DMSLcontainer_get_type( c ) == DAMSEL_HANDLE_CONTAINER_TYPE_SEQUENCE )
00484     {
00485         damsel_handle start;
00486         size_t count, stride;
00487         damsel_err_t err = DMSLcontainer_sequence_get_contents( m, c, &start, &count, &stride );
00488         CHK_DMSL_ERR( err, "Problem calling DMSLcontainer_sequence_get_contents" );
00489         if( stride == 1 )
00490         {
00491             while( count )
00492             {
00493                 // Get start in rangemap
00494                 RangeMap< damsel_handle, EntityHandle, 0 >::iterator beg = dmHandleRMap.lower_bound( start );
00495                 if( beg == dmHandleRMap.end() ) return MB_SUCCESS;
00496                 unsigned int diff = std::max( ( *beg ).begin - start, (damsel_handle)0 );
00497                 unsigned int num  = std::min( count - diff, ( size_t )( *beg ).count );
00498                 for( EntityHandle hdl = ( *beg ).begin + diff; hdl <= (int)( *beg ).begin + diff + num - 1; hdl++ )
00499                     ents[ind++] = hdl;
00500                 count -= ( diff + num );
00501                 ++beg;
00502             }
00503         }
00504         else
00505         {
00506             for( int i = count - 1; i >= 0; i-- )
00507             {
00508                 if( dmHandleRMap.find( start + i, eh ) ) ents[i] = eh;
00509             }
00510         }
00511     }
00512     else if( DMSLcontainer_get_type( c ) == DAMSEL_HANDLE_CONTAINER_TYPE_VECTOR )
00513     {
00514         damsel_handle_ptr handle_ptr;
00515         size_t count;
00516         damsel_err_t err = DMSLcontainer_vector_get_contents( m, c, &handle_ptr, &count );
00517         CHK_DMSL_ERR( err, "Failed to get vector contents" );
00518         for( int i = count - 1; i >= 0; i-- )
00519         {
00520             if( dmHandleRMap.find( handle_ptr[i], eh ) ) ents[i] = eh;
00521         }
00522     }
00523     else if( DMSLcontainer_get_type( c ) == DAMSEL_HANDLE_CONTAINER_TYPE_TREE )
00524     {
00525         damsel_handle_ptr node_ptr = NULL;
00526         damsel_container cont      = NULL;
00527         while( DMSLcontainer_tree_get_contents( m, c, &node_ptr, &cont ) == DMSL_OK && cont )
00528         {
00529             ErrorCode rval = get_contents( m, cont, ents );
00530             if( MB_SUCCESS != rval ) return rval;
00531             unsigned int num = DMSLcontainer_count( cont );
00532             ents += num;
00533         }
00534     }
00535 
00536     return MB_SUCCESS;
00537 }
00538 
00539 /*
00540 ErrorCode ReadDamsel::process_coll_infos(std::vector<damsel_collection_buf_type> &coll_infos)
00541 {
00542   ErrorCode rval = MB_SUCCESS, tmp_rval;
00543   EntityHandle seth;
00544   std::vector<subrange> handle_subranges;
00545   for (std::vector<damsel_collection_buf_type>::iterator cit = coll_infos.begin(); cit !=
00546 coll_infos.end(); ++cit) {
00547     // Make the set
00548     tmp_rval = mbImpl->create_meshset(((*cit).type ==  DAMSEL_HANDLE_COLLECTION_TYPE_SET ?
00549 MESHSET_SET : MESHSET_ORDERED), seth); if (MB_SUCCESS != tmp_rval) rval = tmp_rval;
00550     // Make datastructures to pass things to process_entity_tags
00551     Range tmp_range(seth, seth);
00552     damsel_container ch = DMSLcontainer_create_sequence(dU.dmslModel, seth, 1, 1);
00553 
00554     // Get the tags on this set
00555     tmp_rval = process_entity_tags((*cit).tag_count, (*cit).tag_handle_container, ch, tmp_range);
00556     if (MB_SUCCESS != tmp_rval)
00557       rval = tmp_rval;
00558 
00559     // Process the set contents
00560     if ((*cit).type == DAMSEL_HANDLE_COLLECTION_TYPE_SET) {
00561       Range ents;
00562       tmp_rval = get_contents(dU.dmslModel, (*cit).contents, ents);
00563       if (MB_SUCCESS != tmp_rval)
00564         rval = tmp_rval;
00565       else if (!ents.empty()) {
00566         tmp_rval = mbImpl->add_entities(seth, ents);
00567         if (MB_SUCCESS != tmp_rval)
00568           rval = tmp_rval;
00569       }
00570     }
00571     else {
00572       std::vector<EntityHandle> ents(DMSLcontainer_count((*cit).contents));
00573       tmp_rval = get_contents(dU.dmslModel, (*cit).contents, &ents[0]);
00574       if (MB_SUCCESS != tmp_rval)
00575         rval = tmp_rval;
00576       else if (!ents.empty()) {
00577         tmp_rval = mbImpl->add_entities(seth, &ents[0], ents.size());
00578         if (MB_SUCCESS != tmp_rval)
00579           rval = tmp_rval;
00580       }
00581     }
00582 
00583     // Get the file handle for this collection, and map it to moab's set handle
00584     damsel_handle collh = (damsel_handle)(*((*cit).collection_handle));
00585     if (handle_subranges.empty() || seth != (*handle_subranges.rbegin()).seth + 1 ||
00586         collh != (*handle_subranges.rbegin()).collh + 1) {
00587       handle_subranges.push_back(subrange(collh, seth, 1));
00588     }
00589     else (*handle_subranges.rbegin()).count++;
00590   }
00591 
00592   for (std::vector<subrange>::iterator vit = handle_subranges.begin(); vit !=
00593 handle_subranges.end(); ++vit) dmHandleRMap.insert((*vit).collh, (*vit).seth, (*vit).count);
00594 
00595   return rval;
00596 }
00597 */
00598 
00599 }  // namespace moab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines