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