Ignore:
Timestamp:
10/18/13 17:52:38 (11 years ago)
Author:
tbretz
Message:
Hopefully finished removing the std namespace from the headers.
File:
1 edited

Legend:

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

    r17263 r17264  
    1010
    1111#include "ofits.h"
    12 #include "zfits.h"
     12#include "huffman.h"
    1313#include "Queue.h"
    1414#include "MemoryManager.h"
     
    1616#ifdef USE_BOOST_THREADS
    1717#include <boost/thread.hpp>
    18 #endif
    19 
    20 #ifndef __MARS__
    21 namespace std
    22 {
    2318#endif
    2419
     
    3934        struct CatalogEntry
    4035        {
    41             CatalogEntry(int64_t f=0, int64_t s=0) : first(f), second(s) {};
     36            CatalogEntry(int64_t f=0, int64_t s=0) : first(f), second(s) { }
    4237            int64_t first;   ///< Size of this column in the tile
    4338            int64_t second;  ///< offset of this column in the tile, from the start of the heap area
    4439        } __attribute__((__packed__));
    4540
    46         typedef vector<CatalogEntry> CatalogRow;
    47         typedef list<CatalogRow>     CatalogType;
     41        typedef std::vector<CatalogEntry> CatalogRow;
     42        typedef std::list<CatalogRow>     CatalogType;
    4843
    4944
     
    5954            WriteTarget(const WriteTarget &t, uint32_t sz) : tile_num(t.tile_num), size(sz), data(t.data) { }
    6055
    61             uint32_t         tile_num; ///< Tile index of the data (to make sure that they are written in the correct order)
    62             uint32_t         size;     ///< Size to write
    63             shared_ptr<char> data;     ///< Memory block to write
     56            uint32_t              tile_num; ///< Tile index of the data (to make sure that they are written in the correct order)
     57            uint32_t              size;     ///< Size to write
     58            std::shared_ptr<char> data;     ///< Memory block to write
    6459        };
    6560
     
    7166            {}
    7267
    73             CatalogRow&      catalog_entry;   ///< Reference to the catalog entry to deal with
    74             shared_ptr<char> src;             ///< Original data
    75             shared_ptr<char> transposed_src;  ///< Transposed data
    76             WriteTarget      target;          ///< Compressed data
    77             uint32_t         num_rows;        ///< Number of rows to compress
     68            CatalogRow&           catalog_entry;   ///< Reference to the catalog entry to deal with
     69            std::shared_ptr<char> src;             ///< Original data
     70            std::shared_ptr<char> transposed_src;  ///< Transposed data
     71            WriteTarget           target;          ///< Compressed data
     72            uint32_t              num_rows;        ///< Number of rows to compress
    7873         };
    7974
     
    9287               uint32_t rowPerTile  = DefaultNumRowsPerTile(),
    9388               uint32_t maxUsableMem= DefaultMaxMemory()) : ofits(),
    94                                                         fMemPool(0, maxUsableMem*1000),
    95                                                         fWriteToDiskQueue(bind(&zofits::WriteBufferToDisk, this, placeholders::_1), false)
     89            fMemPool(0, maxUsableMem*1000),
     90            fWriteToDiskQueue(std::bind(&zofits::WriteBufferToDisk, this, std::placeholders::_1), false)
    9691        {
    9792            InitMemberVariables(numTiles, rowPerTile, maxUsableMem*1000);
     
    107102               uint32_t rowPerTile  = DefaultNumRowsPerTile(),
    108103               uint32_t maxUsableMem= DefaultMaxMemory()) : ofits(fname),
    109                                                         fMemPool(0, maxUsableMem*1000),
    110                                                         fWriteToDiskQueue(bind(&zofits::WriteBufferToDisk, this, placeholders::_1), false)
     104                   fMemPool(0, maxUsableMem*1000),
     105                   fWriteToDiskQueue(std::bind(&zofits::WriteBufferToDisk, this, std::placeholders::_1), false)
    111106        {
    112107            InitMemberVariables(numTiles, rowPerTile, maxUsableMem*1000);
     
    132127            fMaxUsableMem = maxUsableMem;
    133128#ifdef __EXCEPTIONS
    134             fThreadsException = exception_ptr();
     129            fThreadsException = std::exception_ptr();
    135130#endif
    136131            fErrno = 0;
     
    208203
    209204            // swap the catalog bytes before writing
    210             vector<char> swapped_catalog(total_catalog_size);
     205            std::vector<char> swapped_catalog(total_catalog_size);
    211206
    212207            uint32_t shift = 0;
     
    272267            {
    273268#ifdef __EXCEPTIONS
    274                 throw runtime_error("Wrong size of row given to WriteRow");
     269                throw std::runtime_error("Wrong size of row given to WriteRow");
    275270#else
    276                 gLog << ___err___ << "ERROR - Wrong size of row given to WriteRow" << endl;
     271                gLog << ___err___ << "ERROR - Wrong size of row given to WriteRow" << std::endl;
    277272                return false;
    278273#endif
     
    282277            //check if something hapenned while the compression threads were working
    283278            //if so, re-throw the exception that was generated
    284             if (fThreadsException != exception_ptr())
    285                 rethrow_exception(fThreadsException);
     279            if (fThreadsException != std::exception_ptr())
     280                std::rethrow_exception(fThreadsException);
    286281#endif
    287282            //copy current row to pool or rows waiting for compression
     
    331326                const WriteTarget write_target(compress_target.target, size_to_write);
    332327                if (!WriteBufferToDisk(write_target))
    333                     throw runtime_error("Unexpected tile number mismatch in WriteBufferToDisk in the main thread.");
     328                    throw std::runtime_error("Unexpected tile number mismatch in WriteBufferToDisk in the main thread.");
    334329
    335330                // The correct 'errno' is set, because it is the main thread.
     
    339334            //if all queues are empty, use queue 0
    340335            uint32_t min_index     = 0;
    341             uint32_t min_size      = numeric_limits<uint32_t>::max();
     336            uint32_t min_size      = std::numeric_limits<uint32_t>::max();
    342337            uint32_t current_index = 0;
    343338
     
    353348
    354349            if (!fCompressionQueues[min_index].emplace(compress_target))
    355                 throw runtime_error("The compression queues are not started. Did you close the file before writing this row?");
     350                throw std::runtime_error("The compression queues are not started. Did you close the file before writing this row?");
    356351
    357352            errno = fErrno;
     
    448443            //check if something hapenned while the compression threads were working
    449444            //if so, re-throw the exception that was generated
    450             if (fThreadsException != exception_ptr())
    451                 rethrow_exception(fThreadsException);
     445            if (fThreadsException != std::exception_ptr())
     446                std::rethrow_exception(fThreadsException);
    452447#endif
    453448
     
    467462                const WriteTarget write_target(compress_target.target, size_to_write);
    468463                if (!WriteBufferToDisk(write_target))
    469                     throw runtime_error("Tile number mismatch in WriteBufferToDisk writing the last tile.");
     464                    throw std::runtime_error("Tile number mismatch in WriteBufferToDisk writing the last tile.");
    470465            }
    471466
     
    502497            SetInt("NAXIS1", total_catalog_width);
    503498            SetInt("NAXIS2", total_num_tiles_written);
    504             SetStr("RAWSUM", to_string(fRawSum.val()));
     499            SetStr("RAWSUM", std::to_string(fRawSum.val()));
    505500
    506501            const float compression_ratio = (float)(fRealRowWidth*fTable.num_rows)/(float)heap_size;
     
    519514            const Checksum checksm = UpdateHeaderChecksum();
    520515
    521             ofstream::close();
     516            std::ofstream::close();
    522517
    523518            if ((checksm+fDataSum).valid())
    524519                return true;
    525520
    526             ostringstream sout;
     521            std::ostringstream sout;
    527522            sout << "Checksum (" << std::hex << checksm.val() << ") invalid.";
    528523#ifdef __EXCEPTIONS
    529             throw runtime_error(sout.str());
     524            throw std::runtime_error(sout.str());
    530525#else
    531             gLog << ___err___ << "ERROR - " << sout.str() << endl;
     526            gLog << ___err___ << "ERROR - " << sout.str() << std::endl;
    532527            return false;
    533528#endif
     
    535530
    536531        /// Overload of the ofits method. Just calls the zofits specific one with default, uncompressed options for this column
    537         bool AddColumn(uint32_t cnt, char typechar, const string& name, const string& unit, const string& comment="", bool addHeaderKeys=true)
     532        bool AddColumn(uint32_t cnt, char typechar, const std::string& name, const std::string& unit,
     533                       const std::string& comment="", bool addHeaderKeys=true)
    538534        {
    539535            return AddColumn(FITS::kFactRaw, cnt, typechar, name, unit, comment, addHeaderKeys);
     
    541537
    542538        /// Overload of the simplified compressed version
    543         bool AddColumn(const FITS::Compression &comp, uint32_t cnt, char typechar, const string& name, const string& unit, const string& comment="", bool addHeaderKeys=true)
     539        bool AddColumn(const FITS::Compression &comp, uint32_t cnt, char typechar, const std::string& name,
     540                       const std::string& unit, const std::string& comment="", bool addHeaderKeys=true)
    544541        {
    545542            if (!ofits::AddColumn(1, 'Q', name, unit, comment, addHeaderKeys))
     
    559556            fRealColumns.emplace_back(col, comp);
    560557
    561             SetStr("ZFORM"+to_string(fRealColumns.size()), to_string(cnt)+typechar, "format of "+name+" "+CommentFromType(typechar));
    562             SetStr("ZCTYP"+to_string(fRealColumns.size()), "FACT", "Compression type: FACT");
     558            SetStr("ZFORM"+std::to_string(fRealColumns.size()), std::to_string(cnt)+typechar, "format of "+name+" "+CommentFromType(typechar));
     559            SetStr("ZCTYP"+std::to_string(fRealColumns.size()), "FACT", "Compression type: FACT");
    563560
    564561            return true;
     
    572569            {
    573570#ifdef __EXCEPTIONS
    574                 throw runtime_error("File must be closed before changing the number of compression threads");
     571                throw std::runtime_error("File must be closed before changing the number of compression threads");
    575572#else
    576                 gLog << ___err___ << "ERROR - File must be closed before changing the number of compression threads" << endl;
     573                gLog << ___err___ << "ERROR - File must be closed before changing the number of compression threads" << std::endl;
    577574#endif
    578575                return false;
     
    583580            unsigned int num_available_cores = boost::thread::hardware_concurrency();
    584581#else
    585             unsigned int num_available_cores = thread::hardware_concurrency();
     582            unsigned int num_available_cores = std::thread::hardware_concurrency();
    586583#endif
    587584            // could not detect number of available cores from system properties...
     
    595592            if (fCompressionQueues.size() != uint32_t(num))
    596593            {
    597                 fCompressionQueues.resize(num, Queue<CompressionTarget>(bind(&zofits::CompressBuffer, this, placeholders::_1), false));
     594                fCompressionQueues.resize(num, Queue<CompressionTarget>(std::bind(&zofits::CompressBuffer, this, std::placeholders::_1), false));
    598595                fNumQueues = num;
    599596            }
     
    664661//            for (uint32_t i=0;i<thisRoundNumRows;i++)
    665662//            {
    666 //                char* target_location = target.src.get()->get() + fRealRowWidth*i;
     663//                char* target_location = target.src.get() + fRealRowWidth*i;
    667664//                cout << "Target Location there...." << hex << static_cast<void*>(target_location) << endl;
    668665//                DrsOffsetCalibrate(target_location);
     
    682679            catch (...)
    683680            {
    684                 fThreadsException = current_exception();
     681                fThreadsException = std::current_exception();
    685682                if (fNumQueues == 0)
    686                     rethrow_exception(fThreadsException);
     683                    std::rethrow_exception(fThreadsException);
    687684            }
    688685#endif
     
    720717            catch (...)
    721718            {
    722                 fThreadsException = current_exception();
     719                fThreadsException = std::current_exception();
    723720                if (fNumQueues == 0)
    724                     rethrow_exception(fThreadsException);
     721                    std::rethrow_exception(fThreadsException);
    725722            }
    726723#endif
     
    871868        uint32_t compressHUFFMAN16(char* dest, const char* src, uint32_t numRows, uint32_t sizeOfElems, uint32_t numRowElems)
    872869        {
    873             string huffmanOutput;
     870            std::string huffmanOutput;
    874871            uint32_t previousHuffmanSize = 0;
    875872
     
    881878            {
    882879#ifdef __EXCEPTIONS
    883                 throw runtime_error("HUFMANN16 can only encode columns with 16-bit or longer types");
     880                throw std::runtime_error("HUFMANN16 can only encode columns with 16-bit or longer types");
    884881#else
    885                 gLog << ___err___ << "ERROR - HUFMANN16 can only encode columns with 16-bit or longer types" << endl;
     882                gLog << ___err___ << "ERROR - HUFMANN16 can only encode columns with 16-bit or longer types" << std::endl;
    886883                return 0;
    887884#endif
     
    942939        int32_t         fLatestWrittenTile; ///< Index of the last tile written to disk (for correct ordering while using several threads)
    943940
    944         vector<Queue<CompressionTarget>>          fCompressionQueues;  ///< Processing queues (=threads)
     941        std::vector<Queue<CompressionTarget>>          fCompressionQueues;  ///< Processing queues (=threads)
    945942        Queue<WriteTarget, QueueMin<WriteTarget>> fWriteToDiskQueue;   ///< Writing queue (=thread)
    946943
     
    967964            FITS::Compression block_head;  ///< the compression data associated with that column
    968965        };
    969         vector<CompressedColumn> fRealColumns;     ///< Vector hosting the columns of the file
    970         uint32_t                 fRealRowWidth;    ///< Width in bytes of one uncompressed row
    971         shared_ptr<char>         fSmartBuffer;     ///< Smart pointer to the buffer where the incoming rows are written
    972         vector<char>             fRawSumBuffer;    ///< buffer used for checksuming the incoming data, before compression
    973 
    974 #ifdef __EXCEPTIONS
    975         exception_ptr     fThreadsException; ///< exception pointer to store exceptions coming from the threads
    976 #endif
    977         int               fErrno;            ///< propagate errno to main thread
    978 
    979 
     966        std::vector<CompressedColumn> fRealColumns;     ///< Vector hosting the columns of the file
     967        uint32_t                      fRealRowWidth;    ///< Width in bytes of one uncompressed row
     968        std::shared_ptr<char>         fSmartBuffer;     ///< Smart pointer to the buffer where the incoming rows are written
     969        std::vector<char>             fRawSumBuffer;    ///< buffer used for checksuming the incoming data, before compression
     970
     971#ifdef __EXCEPTIONS
     972        std::exception_ptr fThreadsException; ///< exception pointer to store exceptions coming from the threads
     973#endif
     974        int                fErrno;            ///< propagate errno to main thread
    980975};
    981976
    982 #ifndef __MARS__
    983 }; //namespace std
    984 #endif
    985 
    986 #endif
     977#endif
Note: See TracChangeset for help on using the changeset viewer.