Changeset 17779 for trunk/Mars


Ignore:
Timestamp:
05/05/14 09:50:53 (11 years ago)
Author:
tbretz
Message:
Use COmmentFromType and SizeFromType from FITS namespace; try using sysconf if std::thread::hardware_concurrency fails; added a fix in reallocateBuffer which could cause a buffer overrun; open must be called in the ocnstructor after the variables have been initialized
File:
1 edited

Legend:

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

    r17766 r17779  
    88 *      Author: lyard
    99 */
    10 
    1110#include "ofits.h"
    1211#include "huffman.h"
     
    1615#ifdef HAVE_BOOST_THREAD
    1716#include <boost/thread.hpp>
     17#else
     18#include <unistd.h>
    1819#endif
    1920
     
    8990public:
    9091        /// static setter for the default number of threads to use. -1 means all available physical cores
    91         static uint32_t DefaultNumThreads(const uint32_t &_n=-2) { static uint32_t n=0; if (int32_t(_n)>=-1) n=_n; return n; }
     92        static uint32_t DefaultNumThreads(const uint32_t &_n=-2) { static uint32_t n=0; if (int32_t(_n)>-2) n=_n; return n; }
    9293        static uint32_t DefaultMaxMemory(const uint32_t &_n=0) { static uint32_t n=1000000; if (_n>0) n=_n; return n; }
    9394        static uint32_t DefaultMaxNumTiles(const uint32_t &_n=0) { static uint32_t n=1000; if (_n>0) n=_n; return n; }
     
    119120            fWriteToDiskQueue(std::bind(&zofits::WriteBufferToDisk, this, std::placeholders::_1), false)
    120121        {
    121             open(fname);
    122122            InitMemberVariables(numTiles, rowPerTile, size_t(maxUsableMem)*1000);
    123123            SetNumThreads(DefaultNumThreads());
     124            open(fname);
    124125        }
    125126
     
    131132            fWriteToDiskQueue(std::bind(&zofits::WriteBufferToDisk, this, std::placeholders::_1), false)
    132133        {
    133             open(fname);
    134134            InitMemberVariables(numTiles, rowPerTile, size_t(maxUsableMem)*1000);
    135135            SetNumThreads(DefaultNumThreads());
     136            open(fname);
    136137        }
    137138
     
    576577                return false;
    577578
    578             const size_t size = SizeFromType(typechar);
     579            const size_t size = FITS::SizeFromType(typechar);
    579580
    580581            Table::Column col;
     
    589590            fRealColumns.emplace_back(col, comp);
    590591
    591             SetStr("ZFORM"+std::to_string((long long int)(fRealColumns.size())), std::to_string((long long int)(cnt))+typechar, "format of "+name+" "+CommentFromType(typechar));
     592            SetStr("ZFORM"+std::to_string((long long int)(fRealColumns.size())), std::to_string((long long int)(cnt))+typechar, "format of "+name+" "+FITS::CommentFromType(typechar));
    592593            SetStr("ZCTYP"+std::to_string((long long int)(fRealColumns.size())), "FACT", "Compression type: FACT");
    593594
     
    614615#else
    615616            unsigned int num_available_cores = std::thread::hardware_concurrency();
     617            if (num_available_cores == 0)
     618                num_available_cores = sysconf(_SC_NPROCESSORS_ONLN);
    616619#endif
    617620            // could not detect number of available cores from system properties...
     
    637640        void reallocateBuffers()
    638641        {
    639             const size_t chunk_size = fRealRowWidth*fNumRowsPerTile + fRealColumns.size()*sizeof(FITS::BlockHeader) + sizeof(FITS::TileHeader) + 8; //+8 for checksuming;
     642            size_t total_block_head_size = 0;
     643            for (auto it=fRealColumns.begin(); it!=fRealColumns.end(); it++)
     644                total_block_head_size += it->block_head.getSizeOnDisk();
     645
     646            const size_t chunk_size = fRealRowWidth*fNumRowsPerTile + total_block_head_size + sizeof(FITS::TileHeader) + 8; //+8 for checksuming;
    640647            fMemPool.setChunkSize(chunk_size);
    641 
    642648            fSmartBuffer = fMemPool.malloc();
    643649            fRawSumBuffer.resize(fRealRowWidth + 4-fRealRowWidth%4); //for checksuming
Note: See TracChangeset for help on using the changeset viewer.