1511 if (!conf.DoParse(argc, argv,
printHelp))
1515 string fileNameIn =
"";
1516 string fileNameOut =
"";
1517 string drsFileName =
"";
1518 uint32_t numRowsPerTile = 100;
1519 bool displayText=
true;
1522 if (conf.Get<
bool>(
"quiet")) displayText =
false;
1523 const vector<string> inputFileNameVec = conf.Vec<
string>(
"inputFile");
1524 if (inputFileNameVec.size() != 1)
1527 if (inputFileNameVec.size() == 0) cout <<
"no";
1528 else cout << inputFileNameVec.size();
1529 cout <<
" input file(s) given. Expected one. Aborting. Input:" << endl;;
1530 for (
unsigned int i=0;
i<inputFileNameVec.size();
i++)
1531 cout << inputFileNameVec[
i] << endl;
1536 fileNameIn = inputFileNameVec[0];
1539 if (conf.Has(
"drs")) drsFileName = conf.Get<
string>(
"drs");
1542 bool verifyDataPlease =
false;
1543 if (conf.Has(
"verify")) verifyDataPlease = conf.Get<
bool>(
"verify");
1547 if (conf.Has(
"output"))
1548 fileNameOut = conf.Get<
string>(
"output");
1551 size_t pos = fileNameIn.find(
".fits.fz");
1552 if (pos == string::npos)
1554 cout <<
"ERROR: input file does not seems ot be fits. Aborting." << endl;
1557 fileNameOut = fileNameIn.substr(0, pos) +
".fits";
1562 const vector<string> columnsCompression = conf.Vec<
string>(
"compression");
1565 vector<std::pair<string, string>> compressions;
1566 for (
unsigned int i=0;
i<columnsCompression.size();
i++)
1568 size_t pos = columnsCompression[
i].find_first_of(
"=");
1569 if (pos == string::npos)
1571 cout <<
"ERROR: Something wrong occured while parsing " << columnsCompression[
i] <<
". Aborting." << endl;
1574 string comp = columnsCompression[
i].substr(pos+1);
1575 if (comp !=
"UNCOMPRESSED" && comp !=
"AMPLITUDE" && comp !=
"HUFFMAN" &&
1576 comp !=
"SMOOTHMAN" && comp !=
"INT_WAVELET")
1578 cout <<
"Unkown compression scheme requested (" << comp <<
"). Aborting." << endl;
1581 compressions.push_back(make_pair(columnsCompression[
i].substr(0, pos), comp));
1585 if (conf.Has(
"rowPerTile")) numRowsPerTile = conf.Get<
unsigned int>(
"rowPerTile");
1593 factfits inFile(fileNameIn,
"",
"Events",
false);
1595 if (!inFile.IsCompressedFITS())
1597 cout <<
"ERROR: input file is NOT a compressed fits. Cannot be decompressed: Aborting." << endl;
1602 uint32_t originalNumRows = inFile.GetNumRows();
1603 uint32_t numTiles = (originalNumRows%numRowsPerTile) ? (originalNumRows/numRowsPerTile)+1 : originalNumRows/numRowsPerTile;
1607 unsigned int numThreads = 1;
1608 if (conf.Has(
"threads"))
1610 numThreads = conf.Get<
unsigned int>(
"threads");
1619 if (drsFileName !=
"")
1623 drsFile =
new factfits(drsFileName);
1627 cout <<
"Error: could not open " << drsFileName <<
" for calibration" << endl;
1635 cout <<
"**********************" << endl;
1636 cout <<
"Will decompress from : " << fileNameIn << endl;
1637 cout <<
"to : " << fileNameOut << endl;
1638 cout <<
"**********************" << endl;
1647 uint32_t rowWidth = inFile.GetUInt(
"ZNAXIS1");
1648 char*
buffer =
new char[rowWidth + 12];
1649 memset(buffer, 0, 4);
1656 cout <<
"Input file has " << columns.size() <<
" columns and " << inFile.GetNumRows() <<
" rows" << endl;
1662 vector<void*> readPointers;
1663 vector<int32_t> readOffsets;
1664 vector<int32_t> readElemSize;
1665 vector<int32_t> readNumElems;
1667 string tableName = inFile.GetStr(
"EXTNAME");
1674 ofits reconstructedFile;
1677 string reconstructedName = fileNameOut;
1678 reconstructedFile.
open(reconstructedName.c_str(),
false);
1681 string origChecksumStr;
1692 for (fits::Table::Keys::const_iterator it=header2.begin(); it!= header2.end(); it++)
1694 string k = it->first;
1695 if (k ==
"XTENSION" || k ==
"BITPIX" || k ==
"PCOUNT" || k ==
"GCOUNT" ||
1696 k ==
"TFIELDS" || k ==
"ZTABLE" || k ==
"ZNAXIS1" || k ==
"ZNAXIS2" ||
1697 k ==
"ZHEAPPTR" || k ==
"ZPCOUNT" || k ==
"ZTILELEN" || k ==
"THEAP" ||
1698 k ==
"CHECKSUM" || k ==
"DATASUM" || k ==
"FCTCPVER" || k ==
"ZHEAP")
1705 reconstructedFile.
SetKeyComment(
"CHECKSUM", it->second.comment);
1706 origChecksumStr = it->second.value;
1716 reconstructedFile.
SetKeyComment(
"DATASUM", it->second.comment);
1717 origDatasum = it->second.value;
1723 tableName = it->second.value;
1734 if (k ==
"TFORM" || k ==
"NAXIS" || k ==
"ZCTYP" )
1739 if (k ==
"ZFORM" || k ==
"ZTYPE")
1741 string tmpKey = it->second.fitsString;
1743 reconstructedFile.SetKeyFromFitsString(tmpKey);
1747 reconstructedFile.SetKeyFromFitsString(it->second.fitsString);
1750 if (tableName ==
"")
1752 cout <<
"Error: table name from file " << fileNameOut <<
" could not be found. Aborting" << endl;
1757 for (uint32_t numCol=1; numCol<10000; numCol++)
1761 if (!inFile.HasKey(
"TTYPE"+str.str()))
break;
1763 string ttype = inFile.GetStr(
"TTYPE"+str.str());
1764 string tform = inFile.GetStr(
"ZFORM"+str.str());
1765 char type = tform[tform.size()-1];
1766 string number = tform.substr(0, tform.size()-1);
1767 int numElems = atoi(number.c_str());
1769 if (number ==
"") numElems=1;
1771 reconstructedFile.
AddColumn(numElems, type, ttype,
"",
"",
false);
1781 readPointers.clear();
1782 readOffsets.clear();
1783 readElemSize.clear();
1784 readNumElems.clear();
1785 for (fits::Table::Columns::const_iterator it=columns.begin(); it!= columns.end(); it++)
1787 readPointers.push_back(inFile.SetPtrAddress(it->first));
1788 readOffsets.push_back(it->second.offset);
1789 readElemSize.push_back(it->second.size);
1790 readNumElems.push_back(it->second.num);
1795 while (i<=inFile.GetNumRows() && inFile.GetNextRow())
1798 for (fits::Table::Columns::const_iterator it=columns.begin(); it!= columns.end();it++)
1800 memcpy(&buffer[readOffsets[count]], readPointers[count], readElemSize[count]*readNumElems[count]);
1803 if (displayText) cout <<
"\r Row " << i << flush;
1804 reconstructedFile.
WriteRow(buffer, rowWidth);
1805 if (!reconstructedFile.good())
1807 cout <<
"ERROR: no space left on device (probably)" << endl;
1813 if (displayText) cout << endl;
1818 if (!inFile.IsFileOk())
1819 cout <<
"ERROR: file checksums seems wrong" << endl;
1821 if (!reconstructedFile.
close())
1823 cout <<
"ERROR: disk probably full..." <<endl;
1828 std::pair<string, int> origChecksum = make_pair(origChecksumStr, atoi(origDatasum.c_str()));
1829 std::pair<string, int> newChecksum = reconstructedFile.
GetChecksumData();
1832 if (origChecksum.second != newChecksum.second)
1834 cout <<
"ERROR: datasums are NOT identical: " << (uint32_t)(origChecksum.second) <<
" vs " << (uint32_t)(newChecksum.second) << endl;
1837 if (origChecksum.first != newChecksum.first)
1839 cout <<
"WARNING: checksums are NOT Identical: " << origChecksum.first <<
" vs " << newChecksum.first << endl;
1843 if (
true) cout <<
"Ok" << endl;
std::vector< Column > SortedColumns
std::map< std::string, Column > Columns
std::pair< std::string, int > GetChecksumData()
bool SetKeyComment(const std::string &key, const std::string &comment)
virtual bool AddColumn(uint32_t cnt, char typechar, const std::string &name, const std::string &unit, const std::string &comment="", bool addHeaderKeys=true)
void setupConfiguration(Configuration &conf)
virtual void open(const char *filename, bool addEXTNAMEKey=true)
std::map< std::string, Entry > Keys
Commandline parsing, resource file parsing and database access.
virtual bool WriteTableHeader(const char *name="DATA")
virtual bool WriteRow(const void *ptr, size_t cnt, bool byte_swap=true)