Commit 9a5d4d90 authored by Paal Kvamme's avatar Paal Kvamme
Browse files

Refactoring: Use WriteNowArgPack instead of discrete arguments.

parent 04517dc2
......@@ -201,6 +201,47 @@ struct WriteBrickArgPack
}
};
/**
* Argument package used by _writeWithRetry() which is at a lower level
* than _writeOneBrick() etc. and it got too awkward to use the
* one size fits all rule.
*
* There are new fields rawdata (replaces data) and brickstatus.
* Also the compressor is no longer needed as compression is now done.
*/
struct WriteNowArgPack
{
std::array<std::int64_t,3> brickpos;
std::int32_t lod;
std::int64_t fileoffset;
rawdata_t rawdata;
BrickStatus brickstatus;
WriteNowArgPack(const std::array<std::int64_t,3>& brickpos_in,
std::int32_t lod_in,
std::int64_t fileoffset_in,
const rawdata_t rawdata_in,
BrickStatus brickstatus_in)
: brickpos(brickpos_in)
, lod(lod_in)
, fileoffset(fileoffset_in)
, rawdata(rawdata_in)
, brickstatus(brickstatus_in)
{
}
std::string toString() const
{
std::stringstream ss;
ss << "pos=" << brickpos
<< ", lod=" << lod
<< ", size=" << rawdata.second;
if (fileoffset)
ss << ", fileoffset=" << std::hex << fileoffset << std::dec;
// TODO-Low: Symbolic names for enums
ss << ", brickstatus=" << (int)brickstatus;
return ss.str();
}
};
/**
* TODO-Low might want to fold this into LookupTable::LutInfo.
*
......@@ -1120,25 +1161,18 @@ ZgyInternalBulk::_setPaddingSamples(
* Would it help to refactor this function and its callers to operate on
* a list of bricks instead of one? Possibly but the added complexity
* might not be worth it.
*
* Args: brickpos, lod, fileoffset, rawdata, brickstatus.
*/
void
ZgyInternalBulk::_writeWithRetry(
rawdata_t rawdata,
BrickStatus brickstatus,
std::int64_t fileoffset,
const std::array<std::int64_t,3>& brickpos,
std::int32_t lod)
ZgyInternalBulk::_writeWithRetry(const WriteNowArgPack& args)
{
if (_logger(1))
_logger(1, std::stringstream()
<< "_writeWithRetry("
<< "pos=" << brickpos
<< ", fileoffset=" << std::hex
<< (fileoffset ? fileoffset : this->_file->xx_eof())
<< std::dec << ")\n");
_logger(1, "_writeWithRetry(" + args.toString() + ")\n");
std::int64_t fileoffset = args.fileoffset;
if (fileoffset) {
try {
this->_file->xx_write(rawdata.first.get(), fileoffset, rawdata.second, UsageHint::Data);
this->_file->xx_write(args.rawdata.first.get(), fileoffset, args.rawdata.second, UsageHint::Data);
}
catch (const OpenZGY::Errors::ZgySegmentIsClosed&) {
// The update mode doesn't need to be checked again here
......@@ -1154,10 +1188,10 @@ ZgyInternalBulk::_writeWithRetry(
_logger(1, std::stringstream()
<< "Allocating space at EOF: "
<< std::hex << fileoffset << std::dec << ")\n");
this->_file->xx_write(rawdata.first.get(), fileoffset, rawdata.second, UsageHint::Data);
this->_file->xx_write(args.rawdata.first.get(), fileoffset, args.rawdata.second, UsageHint::Data);
LookupTable::setBrickFilePosition
(brickpos[0], brickpos[1], brickpos[2], lod,
LookupTable::LutInfo(brickstatus, fileoffset, rawdata.second, 0),
(args.brickpos[0], args.brickpos[1], args.brickpos[2], args.lod,
LookupTable::LutInfo(args.brickstatus, fileoffset, args.rawdata.second, 0),
this->_metadata->ih().lodsizes(),
this->_metadata->ih().brickoffsets(),
&this->_get_metadata_rw()->blup().lup(),
......@@ -1191,6 +1225,8 @@ ZgyInternalBulk::_writeWithRetry(
* file offset is explicitly known the lower level write might not be
* thread safe. Also when serializing the order of bricks should be
* preserved. Otherwise performance on read might suffer.
*
* Args: brickpos, lod, data, compressor, fileoffset.
*/
void
ZgyInternalBulk::_writeOneNormalBrick(const WriteBrickArgPack& args)
......@@ -1249,7 +1285,8 @@ ZgyInternalBulk::_writeOneNormalBrick(const WriteBrickArgPack& args)
// It might be safer to unconditionally copy the data.
//data->byteswap();
}
_writeWithRetry(rawdata, brickstatus, args.fileoffset, args.brickpos, args.lod);
_writeWithRetry(WriteNowArgPack(args.brickpos, args.lod, args.fileoffset,
rawdata, brickstatus));
}
/**
......@@ -1258,6 +1295,8 @@ ZgyInternalBulk::_writeOneNormalBrick(const WriteBrickArgPack& args)
*
* The size stored in "data" is ignored. The constant applies to
* the whole brick. Also, args.fileoffset and args.compressor are N/A.
*
* Args: brickpos, lod, data, compressor(N/A), fileoffset(N/A).
*/
void
ZgyInternalBulk::_writeOneConstantBrick(const WriteBrickArgPack& args)
......@@ -1370,6 +1409,8 @@ ZgyInternalBulk::_mustLeakOldBrick(
* allowed while this is going on. Nor can there be a separate
* write request initiated by the user because (among other reasons)
* the bricks might overlap.
*
* Args: brickpos, lod, data, compressor, fileoffset.
*/
void
ZgyInternalBulk::_writeOneBrick(const WriteBrickArgPack& args_in)
......
......@@ -42,6 +42,7 @@ class DataBuffer;
struct IJK;
struct LutInfoEx;
struct WriteBrickArgPack;
struct WriteNowArgPack;
/**
* Read or write bulk data. The meta data needs to have been read
......@@ -178,12 +179,7 @@ private:
const std::array<std::int64_t,3>& used,
double missingvalue, const compressor_t& compressor);
void _writeWithRetry(
rawdata_t rawdata,
BrickStatus brickstatus,
std::int64_t fileoffset,
const std::array<std::int64_t,3>& brickpos,
std::int32_t lod);
void _writeWithRetry(const WriteNowArgPack& args);
void _writeOneNormalBrick(const WriteBrickArgPack& args);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment