Changeset 17225
- Timestamp:
- 10/16/13 19:20:53 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/zofits.h
r17221 r17225 7 7 8 8 #include "ofits.h" 9 #include "zfits.h" 9 10 #include "Queue.h" 10 11 #include "MemoryManager.h" 11 12 12 #include "FITS.h"13 14 13 #ifdef USE_BOOST_THREADS 15 14 #include <boost/thread.hpp> 16 15 #endif 17 18 using namespace FITS;19 16 20 17 #ifndef __MARS__ … … 24 21 using namespace std; 25 22 #endif 23 26 24 27 25 class zofits : public ofits … … 61 59 { 62 60 InitMemberVariables(numTiles, rowPerTile, maxUsableMem); 63 SetNum WorkingThreads(fNumQueues);61 SetNumThreads(fgNumQueues); 64 62 } 65 63 … … 72 70 { 73 71 InitMemberVariables(numTiles, rowPerTile, maxUsableMem); 74 SetNum WorkingThreads(fNumQueues);72 SetNumThreads(fgNumQueues); 75 73 } 76 74 … … 206 204 } 207 205 208 bool WriteRow(const void* ptr, size_t cnt, bool byte_swap=true)206 bool WriteRow(const void* ptr, size_t cnt, bool = true) 209 207 { 210 208 if (cnt != fRealRowWidth) … … 497 495 bool AddColumn(uint32_t cnt, char typechar, const string& name, const string& unit, const string& comment="", bool addHeaderKeys=true) 498 496 { 499 BlockHeaderWriter head; 500 return AddColumn(cnt, typechar, name, unit, head, comment, addHeaderKeys); 501 } 502 503 bool AddColumn(const string& compressionScheme, uint32_t cnt, char typechar, const string& name, const string& unit, const string& comment="", bool addHeaderKeys=true) 504 { 505 BlockHeaderWriter head(compressionScheme); 506 return AddColumn(cnt, typechar, name, unit, head, comment, addHeaderKeys); 507 } 508 bool AddColumn(uint32_t cnt, char typechar, const string& name, const string& unit, const BlockHeaderWriter& header, const string& comment="", bool addHeaderKeys=true) 497 return AddColumn(kFactRaw, cnt, typechar, name, unit, comment, addHeaderKeys); 498 } 499 500 bool AddColumn(const FITS::Compression &comp, uint32_t cnt, char typechar, const string& name, const string& unit, const string& comment="", bool addHeaderKeys=true) 509 501 { 510 502 if (!ofits::AddColumn(1, 'Q', name, unit, comment, addHeaderKeys)) … … 522 514 fRealRowWidth += size*cnt; 523 515 524 fRealColumns.emplace_back(CompressedColumn(col, header));516 fRealColumns.emplace_back(CompressedColumn(col, comp)); 525 517 526 518 ostringstream strKey, strVal, strCom; … … 541 533 } 542 534 543 bool AddColumnShort(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="") 544 { return AddColumn(compressionScheme, cnt, 'I', name, unit, comment); } 545 bool AddColumnInt(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="") 546 { return AddColumn(compressionScheme, cnt, 'J', name, unit, comment); } 547 bool AddColumnLong(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="") 548 { return AddColumn(compressionScheme, cnt, 'K', name, unit, comment); } 549 bool AddColumnFloat(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="") 550 { return AddColumn(compressionScheme, cnt, 'E', name, unit, comment); } 551 bool AddColumnDouble(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="") 552 { return AddColumn(compressionScheme, cnt, 'D', name, unit, comment); } 553 bool AddColumnChar(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="") 554 { return AddColumn(compressionScheme, cnt, 'A', name, unit, comment); } 555 bool AddColumnByte(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="") 556 { return AddColumn(compressionScheme, cnt, 'B', name, unit, comment); } 557 bool AddColumnBool(const string& compressionScheme, uint32_t cnt, const string &name, const string &unit="", const string &comment="") 558 { return AddColumn(compressionScheme, cnt, 'L', name, unit, comment); } 559 560 static void SetNumThreads(int32_t num) { fNumQueues = num;} 561 static int32_t GetNumThreads() { return fNumQueues;} 562 protected: 563 564 bool SetNumWorkingThreads(int32_t num) 535 static void SetDefaultNumThreads(int32_t num) { fgNumQueues = num;} 536 static int32_t GetDefaultNumThreads() { return fgNumQueues;} 537 538 int32_t GetNumThreads() { return fNumQueues;} 539 bool SetNumThreads(int32_t num) 565 540 { 566 541 if (is_open()) … … 619 594 return true; 620 595 } 596 597 protected: 621 598 622 599 bool reallocateBuffers() … … 738 715 if (fRealColumns[i].col.num == 0) continue; 739 716 740 BlockHeaderWriter& head = fRealColumns[i].block_head;717 Compression& head = fRealColumns[i].block_head; 741 718 742 719 //set the default byte telling if uncompressed the compressed Flag … … 744 721 745 722 //skip header data 746 compressedOffset += head. SizeOnDisk();747 748 for (uint32_t j=0;j<head. NumProcs();j++)//sequence.size(); j++)723 compressedOffset += head.getSizeOnDisk(); 724 725 for (uint32_t j=0;j<head.getNumProcs();j++)//sequence.size(); j++) 749 726 { 750 switch (head. Proc(j))727 switch (head.getProc(j)) 751 728 { 752 729 case kFactRaw: … … 757 734 break; 758 735 case kFactHuffman16: 759 if (head. Ordering() == kOrderByCol)760 compressedOffset += compressHUFFMAN (dest + compressedOffset, src + offset, thisRoundNumRows, fRealColumns[i].col.size, fRealColumns[i].col.num);736 if (head.getOrdering() == kOrderByCol) 737 compressedOffset += compressHUFFMAN16(dest + compressedOffset, src + offset, thisRoundNumRows, fRealColumns[i].col.size, fRealColumns[i].col.num); 761 738 else 762 compressedOffset += compressHUFFMAN (dest + compressedOffset, src + offset, fRealColumns[i].col.num, fRealColumns[i].col.size, thisRoundNumRows);739 compressedOffset += compressHUFFMAN16(dest + compressedOffset, src + offset, fRealColumns[i].col.num, fRealColumns[i].col.size, thisRoundNumRows); 763 740 break; 764 default:765 {766 ostringstream str;767 str << "Unkown compression sequence entry: " << head.Proc(j);768 #ifdef __EXCEPTIONS769 throw runtime_error(str.str());770 #else771 gLog << ___err___ << "ERROR - " << str.str();772 return 0;773 #endif774 }775 741 } 776 742 } 777 743 778 744 //check if compressed size is larger than uncompressed 779 if ((head. Proc(0) != kFactRaw) && (compressedOffset - previousOffset > fRealColumns[i].col.size*fRealColumns[i].col.num*thisRoundNumRows+head.SizeOnDisk()))// && two)745 if ((head.getProc(0) != kFactRaw) && (compressedOffset - previousOffset > fRealColumns[i].col.size*fRealColumns[i].col.num*thisRoundNumRows+head.getSizeOnDisk()))// && two) 780 746 {//if so set flag and redo it uncompressed 781 747 cout << "Redoing uncompressed ! " << endl; 782 748 //de-smooth ! 783 if (head. Proc(0) == kFactSmoothing)749 if (head.getProc(0) == kFactSmoothing) 784 750 UnApplySMOOTHING(src+offset, fRealColumns[i].col.num*thisRoundNumRows); 785 751 786 BlockHeaderWriter he; 787 compressedOffset = previousOffset + he.SizeOnDisk(); 752 Compression he; 753 754 compressedOffset = previousOffset + he.getSizeOnDisk(); 788 755 compressedOffset += compressUNCOMPRESSED(dest + compressedOffset, src + offset, thisRoundNumRows*fRealColumns[i].col.size*fRealColumns[i].col.num); 756 789 757 he.SetBlockSize(compressedOffset - previousOffset); 790 he.Write(dest+previousOffset); 758 he.Memcpy(dest+previousOffset); 759 791 760 offset += thisRoundNumRows*fRealColumns[i].col.size*fRealColumns[i].col.num; 761 792 762 fCatalog[currentCatalogRow][i].first = compressedOffset - fCatalog[currentCatalogRow][i].second; 793 763 continue; … … 795 765 796 766 head.SetBlockSize(compressedOffset - previousOffset); 797 head. Write(dest + previousOffset);767 head.Memcpy(dest + previousOffset); 798 768 799 769 offset += thisRoundNumRows*fRealColumns[i].col.size*fRealColumns[i].col.num; … … 814 784 for (uint32_t i=0;i<fRealColumns.size();i++) 815 785 { 816 switch (fRealColumns[i].block_head. Ordering())786 switch (fRealColumns[i].block_head.getOrdering()) 817 787 { 818 788 case kOrderByRow: … … 832 802 } 833 803 break; 834 default:835 {836 ostringstream str;837 str << "Unkown column ordering: " << fRealColumns[i].block_head.Ordering();838 #ifdef __EXCEPTIONS839 throw runtime_error(str.str());840 #else841 gLog << ___err___ << "ERROR - " << str.str();842 return;843 #endif844 }845 804 }; 846 805 } … … 854 813 } 855 814 856 uint32_t compressHUFFMAN (char* dest, const char* src, uint32_t numRows, uint32_t sizeOfElems, uint32_t numRowElems)815 uint32_t compressHUFFMAN16(char* dest, const char* src, uint32_t numRows, uint32_t sizeOfElems, uint32_t numRowElems) 857 816 { 858 817 string huffmanOutput; … … 865 824 { 866 825 #ifdef __EXCEPTIONS 867 throw runtime_error(" Fatal ERROR: HUFMANN can only encode short or longer types");826 throw runtime_error("HUFMANN16 can only encode columns with 16-bit or longer types"); 868 827 #else 869 gLog << ___err___ << "ERROR - Fatal ERROR: HUFMANN can only encode short or longer types";828 gLog << ___err___ << "ERROR - HUFMANN16 can only encode columns with 16-bit or longer types"; 870 829 return 0; 871 830 #endif … … 920 879 921 880 //thread related stuff 922 static int32_t fNumQueues; ///< The number of threads that will be used to compress 881 static int32_t fgNumQueues; ///< The number of threads that will be used to compress 882 int32_t fNumQueues; ///< The number of threads that will be used to compress 923 883 924 884 int32_t fLatestWrittenTile; … … 949 909 struct CompressedColumn 950 910 { 951 CompressedColumn(const Table::Column& c, const BlockHeaderWriter& h) : col(c),952 911 CompressedColumn(const Table::Column& c, const Compression& h) : col(c), 912 block_head(h) 953 913 {} 954 914 Table::Column col; 955 BlockHeaderWriterblock_head;915 Compression block_head; 956 916 }; 957 917 vector<CompressedColumn> fRealColumns; … … 959 919 }; 960 920 961 int32_t zofits::f NumQueues = 0;921 int32_t zofits::fgNumQueues = 0; 962 922 963 923 #ifndef __MARS__ 964 924 }; //namespace std 965 925 #endif 966 967 #ifdef crappy_example_usage968 zofits zofitsfile(123456, 100);969 zofitsfile.SetNumWorkingThreads(numThreads);970 zofitsfile.open((fileNameOut).c_str());971 std::zofits::BlockHeader zoheader(0, kOrderByRow, 2);972 vector<uint16_t> smoothmanProcessings(2);973 smoothmanProcessings[0] = kFactSmoothing;974 smoothmanProcessings[1] = kFactHuffman16;975 976 zofitsfile.AddColumn(sortedColumns[i].num,977 sortedColumns[i].type,978 colName,979 "");980 981 zofitsfile.AddColumn(sortedColumns[i].num,982 sortedColumns[i].type,983 colName,984 "",985 zoheader,986 smoothmanProcessings);987 988 zofitsfile.SetStr("ZCHKSUM", i->second.value, i->second.comment);989 zofitsfile.SetDrsCalibration(drsCalibFloat);990 zofitsfile.WriteTableHeader(tableName.c_str());991 zofitsfile.WriteRow(buffer, rowWidth);992 zofitsfile.close();993 994 #endif
Note:
See TracChangeset
for help on using the changeset viewer.