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