Skip to content

Commit

Permalink
Fixing #5 : make it possible to open readonly files, and adding test-…
Browse files Browse the repository at this point in the history
…case for it
  • Loading branch information
aroffringa committed Nov 11, 2017
1 parent 380344d commit b957139
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
17 changes: 11 additions & 6 deletions dyscostman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void DyscoStMan::readHeader()
}
}

void DyscoStMan::initializeRowsPerBlock(size_t rowsPerBlock, size_t antennaCount)
void DyscoStMan::initializeRowsPerBlock(size_t rowsPerBlock, size_t antennaCount, bool writeToHeader)
{
if(areOffsetsInitialized() && (rowsPerBlock != _rowsPerBlock || antennaCount != _antennaCount))
throw DyscoStManError("initializeRowsPerBlock() called with two different values; something is wrong");
Expand All @@ -273,15 +273,20 @@ void DyscoStMan::initializeRowsPerBlock(size_t rowsPerBlock, size_t antennaCount

col->InitializeAfterNRowsPerBlockIsKnown();
}
writeHeader();
if(writeToHeader)
writeHeader();
}

void DyscoStMan::open(casacore::uInt nRow, casacore::AipsIO&)
{
_nRow = nRow;
_fStream.reset(new std::fstream(fileName().c_str()));
_fStream.reset(new std::fstream(fileName().c_str(), std::ios_base::in | std::ios_base::out));
if(_fStream->fail())
throw DyscoStManError("I/O error: could not open file '" + fileName() + "', which should be an existing file");
{
_fStream.reset(new std::fstream(fileName().c_str(), std::ios_base::in));
if(_fStream->fail())
throw DyscoStManError("I/O error: could not open file '" + fileName() + "', which should be an existing file");
}

readHeader();

Expand Down Expand Up @@ -352,14 +357,14 @@ void DyscoStMan::prepare()
if(wghtCol != 0)
wghtCol->SetBitsPerSymbol(_weightBitCount);
}
col->Prepare( _distribution, _normalization, _studentTNu, _distributionTruncation);
col->Prepare(_distribution, _normalization, _studentTNu, _distributionTruncation);
}

// In case this is a new measurement set, we do not know the rowsPerBlock yet
// If this measurement set is opened, we do know it, and we have to call
// initializeRowsPerBlock() to let the columns know this value.
if(areOffsetsInitialized())
initializeRowsPerBlock(_rowsPerBlock, _antennaCount);
initializeRowsPerBlock(_rowsPerBlock, _antennaCount, false);
}

void DyscoStMan::reopenRW()
Expand Down
2 changes: 1 addition & 1 deletion dyscostman.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class DyscoStMan : public casacore::DataManager
* @param rowsPerBlock Number of measurement set rows in one time block.
* @param antennaCount Highest antenna index+1 used in a time block.
*/
void initializeRowsPerBlock(size_t rowsPerBlock, size_t antennaCount);
void initializeRowsPerBlock(size_t rowsPerBlock, size_t antennaCount, bool writeToHeader);

private:
friend class DyscoStManColumn;
Expand Down
2 changes: 1 addition & 1 deletion dyscostmancol.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ inline bool DyscoStManColumn::areOffsetsInitialized() const

inline void DyscoStManColumn::initializeRowsPerBlock(size_t rowsPerBlock, size_t antennaCount)
{
_storageManager->initializeRowsPerBlock(rowsPerBlock, antennaCount);
_storageManager->initializeRowsPerBlock(rowsPerBlock, antennaCount, true);
}

} // end of namespace
Expand Down
22 changes: 22 additions & 0 deletions tests/testdyscostman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,26 @@ BOOST_AUTO_TEST_CASE( read_past_end )
}
}

BOOST_AUTO_TEST_CASE( readonly )
{
size_t nAnt = 3;
TestTableFixture fixture(nAnt);

boost::filesystem::directory_iterator end_itr;

for (boost::filesystem::directory_iterator itr("TestTable/"); itr != end_itr; ++itr)
{
if (boost::filesystem::is_regular_file(itr->path())) {
boost::filesystem::permissions(itr->path(),
boost::filesystem::others_read|boost::filesystem::owner_read);
}
}
casacore::Table table("TestTable");
casacore::ArrayColumn<casacore::Complex> dataCol(table, "DATA");
for(size_t i=0; i!=table.nrow(); ++i)
{
BOOST_CHECK_CLOSE_FRACTION((*dataCol(i).cbegin()).real(), float(i), 1e-4);
}
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit b957139

Please sign in to comment.