Changeset 17288


Ignore:
Timestamp:
10/21/13 13:27:01 (11 years ago)
Author:
lyard
Message:
Bugfix to be able to reuse the same zofits object to write more than one file
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/mcore/zofits.h

    r17285 r17288  
    182182            SetInt(  "ZSHRINK",  1,               "Catalog shrink factor");
    183183
    184             fCatalogSize      = 0;
     184            fCatalogSize   = 0;
     185            fRealRowWidth  = 0;
     186            fCatalogOffset = 0;
     187            fCatalogSize   = 0;
     188            fCheckOffset   = 0;
     189
     190            fRealColumns.clear();
    185191            fCatalog.clear();
     192            fCatalogSum.reset();
    186193            fRawSum.reset();
    187194        }
     
    286293                std::rethrow_exception(fThreadsException);
    287294#endif
     295
    288296            //copy current row to pool or rows waiting for compression
    289297            char* target_location = fSmartBuffer.get() + fRealRowWidth*(fTable.num_rows%fNumRowsPerTile);
     
    362370
    363371        /// Shrinks a catalog that is too long to fit into the reserved space at the beginning of the file.
    364         void ShrinkCatalog()
     372        const uint32_t ShrinkCatalog()
    365373        {
    366374            //add empty row to get either the target number of rows, or a multiple of the allowed size
     
    370378            //did we write more rows than what the catalog could host ?
    371379            if (fCatalogSize <= fNumTiles) // nothing to do
    372                 return;
     380                return 1;
    373381
    374382            //always exact as extra rows were added just above
     
    409417            SetInt("ZTILELEN", fNumRowsPerTile);
    410418            SetInt("ZSHRINK",  shrink_factor);
     419
     420            return shrink_factor;
    411421        }
    412422
     
    457467            }
    458468
    459             ShrinkCatalog();
     469            const uint32_t shrink_factor = ShrinkCatalog();
    460470
    461471            //update header keywords
     
    471481            SetInt("NAXIS1", total_catalog_width);
    472482            SetInt("NAXIS2", total_num_tiles_written);
    473             SetStr("RAWSUM", std::to_string(fRawSum.val()));
     483            SetStr("RAWSUM", std::to_string((long long int)(fRawSum.val())));
    474484
    475485            const float compression_ratio = (float)(fRealRowWidth*fTable.num_rows)/(float)heap_size;
     
    489499
    490500            std::ofstream::close();
     501
     502            fSmartBuffer = std::shared_ptr<char>();
     503
     504            //restore the number of rows per tile in case the catalog has been shrinked
     505            if (shrink_factor != 1)
     506                fNumRowsPerTile /= shrink_factor;
    491507
    492508            if ((checksm+fDataSum).valid())
     
    530546            fRealColumns.emplace_back(col, comp);
    531547
    532             SetStr("ZFORM"+std::to_string(fRealColumns.size()), std::to_string(cnt)+typechar, "format of "+name+" "+CommentFromType(typechar));
    533             SetStr("ZCTYP"+std::to_string(fRealColumns.size()), "FACT", "Compression type: FACT");
     548            SetStr("ZFORM"+std::to_string((long long int)(fRealColumns.size())), std::to_string((long long int)(cnt))+typechar, "format of "+name+" "+CommentFromType(typechar));
     549            SetStr("ZCTYP"+std::to_string((long long int)(fRealColumns.size())), "FACT", "Compression type: FACT");
    534550
    535551            return true;
Note: See TracChangeset for help on using the changeset viewer.