Skip to content

Commit

Permalink
Merge pull request #749 from bzhang162/SIX-3.3.1
Browse files Browse the repository at this point in the history
Six 3.3.1
  • Loading branch information
dave-starinshak authored Sep 5, 2024
2 parents 41703fc + 9387984 commit 3e82dd3
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ template<typename T> class RowCol
T col{};

// Try to protect us from the unfortunate and probably
// unintendet case where row gets set and col doesnt, especially
// unintended case where row gets set and col doesn't, especially
// when doing scalar operations that might otherwise create
// ambiguities
RowCol() {} // = default; // error w/ICC and "const" member data
Expand Down
7 changes: 5 additions & 2 deletions six/modules/c++/cphd/include/cphd/CPHDWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ struct SIX_CPHD_API CPHDWriter final
void writeSupportData(io::OutputStream& stream,
const T* data_, const std::string& id)
{
const auto size = mMetadata.data.getSupportArrayById(id).size_bytes();
const auto &dataArray = mMetadata.data.getSupportArrayById(id);

const auto size = dataArray.size_bytes();
const auto data = sys::make_span<const std::byte>(data_, size);
writeSupportDataImpl(stream, data, mMetadata.data.getSupportArrayById(id).bytesPerElement);
writeSupportDataImpl(stream, data, getSupportDataBytesPerSwap(dataArray));
}
template <typename T>
void writeSupportData(const T* data, const std::string& id)
Expand All @@ -221,6 +223,7 @@ struct SIX_CPHD_API CPHDWriter final
* \param data A pointer to the start of the support array data block
*/
sys::Off_T getSupportBlockByteOffset(const Data::SupportArray&) const;
size_t getSupportDataBytesPerSwap(const Data::SupportArray& dataArray) const;
void writeSupportDataArray(io::SeekableOutputStream&, DataWriter&,
std::span<const std::byte>, const Data::SupportArray&);
void writeSupportDataArray(io::SeekableOutputStream&, std::span<const std::byte>, const Data::SupportArray&);
Expand Down
11 changes: 7 additions & 4 deletions six/modules/c++/cphd/include/cphd/SupportArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct SupportArrayParameter
* \param ySS_in Col coordinate (Y) sample spacing
*/
SupportArrayParameter(
const std::string& format, size_t id,
const std::string& format, const std::string& id,
double x0_in, double y0_in,
double xSS_in, double ySS_in);

Expand All @@ -83,13 +83,13 @@ struct SupportArrayParameter
}

//! Set unique identifier
void setIdentifier(size_t identifierIn)
void setIdentifier(const std::string& identifierIn)
{
identifier = identifierIn;
}

//! Get unique identifier
inline size_t getIdentifier() const
inline std::string getIdentifier() const
{
return identifier;
}
Expand All @@ -112,7 +112,7 @@ struct SupportArrayParameter
protected:
void initializeParams();
private:
size_t identifier;
std::string identifier;
};

/*!
Expand Down Expand Up @@ -229,6 +229,9 @@ struct SupportArray final
//! Get AGP support array by unique id
AdditionalSupportArray getAddedSupportArray(const std::string& key) const;

//!Get bytes per swap for suppor array data by unique id
size_t getSupportDataBytesPerSwap(const std::string& key, size_t bytesPerElement) const;

//! Vector of IAZ type arrays
std::vector<SupportArrayParameter> iazArray;

Expand Down
10 changes: 9 additions & 1 deletion six/modules/c++/cphd/include/cphd/SupportBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <mem/ScopedArray.h>
#include <mem/BufferView.h>

#include <cphd/SupportArray.h>
#include <cphd/Data.h>
#include <cphd/Utilities.h>
#include <cphd/Exports.h>
Expand All @@ -59,11 +60,13 @@ struct SIX_CPHD_API SupportBlock final
* \brief Constructor initializes book keeping information
*
* \param pathname Input CPHD pathname to initialize a file input stream
* \param supportArray SupportArray section for cphd::Metadata
* \param data Data section from CPHD
* \param startSupport CPHD header keyword "SUPPORT_BLOCK_BYTE_OFFSET"
* \param sizeSupport CPHD header keyword "SUPPORT_BLOCK_SIZE"
*/
SupportBlock(const std::string& pathname,
const mem::ScopedCopyablePtr<cphd::SupportArray> supportArray,
const cphd::Data& data,
int64_t startSupport,
int64_t sizeSupport);
Expand All @@ -74,16 +77,20 @@ struct SIX_CPHD_API SupportBlock final
* \brief Constructor initializes book keeping information
*
* \param inStream Input stream to an already opened CPHD file
* \param supportArray SupportArray section for cphd::Metadata
* \param data Data section from CPHD
* \param startSupport CPHD header keyword "SUPPORT_BLOCK_BYTE_OFFSET"
* \param sizeSupport CPHD header keyword "SUPPORT_BLOCK_SIZE"
*/
SupportBlock(std::shared_ptr<io::SeekableInputStream> inStream,
const mem::ScopedCopyablePtr<cphd::SupportArray> supportArray,
const cphd::Data& data,
int64_t startSupport,
int64_t sizeSupport);
SupportBlock(std::shared_ptr<io::SeekableInputStream> inStream,
const cphd::Data& data, const FileHeader&);
const mem::ScopedCopyablePtr<cphd::SupportArray> supportArray,
const cphd::Data& data,
const FileHeader&);

// Noncopyable
SupportBlock(const SupportBlock&) = delete;
Expand Down Expand Up @@ -154,6 +161,7 @@ struct SIX_CPHD_API SupportBlock final

private:
const std::shared_ptr<io::SeekableInputStream> mInStream;
const mem::ScopedCopyablePtr<cphd::SupportArray> mSupportArray;
cphd::Data mData;
const int64_t mSupportOffset; // offset in bytes to start of SupportBlock
const size_t mSupportSize; // total size in bytes of SupportBlock
Expand Down
5 changes: 4 additions & 1 deletion six/modules/c++/cphd/source/CPHDReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ cphd::CPHDReader::CPHDReader(std::shared_ptr<io::SeekableInputStream> inStream,
: mFileHeader(cphd::FileHeader::read(*inStream)),
mMetadata(fromXML(*inStream, schemaPaths_, logger, mFileHeader))
{
mSupportBlock = std::make_unique<SupportBlock>(inStream, mMetadata.data, mFileHeader);
mSupportBlock = std::make_unique<SupportBlock>(inStream,
mMetadata.supportArray,
mMetadata.data,
mFileHeader);

// Load the PVPBlock into memory
mPVPBlock = PVPBlock(mMetadata);
Expand Down
13 changes: 12 additions & 1 deletion six/modules/c++/cphd/source/CPHDWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,24 @@ sys::Off_T CPHDWriter::getSupportBlockByteOffset(const Data::SupportArray& dataA
const auto supportBlockByteOffset = mHeader.getSupportBlockByteOffset();
return supportBlockByteOffset + dataArray.arrayByteOffset;
}
size_t CPHDWriter::getSupportDataBytesPerSwap(const Data::SupportArray& dataArray) const
{
if(mMetadata.supportArray.get() == nullptr)
{
std::ostringstream oss;
oss << "mMetadata.supportArray was not populated";
throw except::Exception(Ctxt(oss.str()));
}

return mMetadata.supportArray->getSupportDataBytesPerSwap(dataArray.identifier,
dataArray.bytesPerElement);
}
void CPHDWriter::writeSupportDataArray(io::SeekableOutputStream& stream, DataWriter& dataWriter,
std::span<const std::byte> data, const Data::SupportArray& dataArray)
{
// Move inputstream head to offset of particular support array
stream.seek(getSupportBlockByteOffset(dataArray), io::SeekableOutputStream::START);
dataWriter(make_span(data, dataArray), dataArray.bytesPerElement);
dataWriter(make_span(data, dataArray), getSupportDataBytesPerSwap(dataArray));
}
void CPHDWriter::writeSupportDataArray(io::SeekableOutputStream& stream,
std::span<const std::byte> data, const Data::SupportArray& dataArray)
Expand Down
21 changes: 13 additions & 8 deletions six/modules/c++/cphd/source/CPHDXMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ std::unique_ptr<xml::lite::Document> CPHDXMLParser::toXML(
toXML(metadata.data, root);
toXML(metadata.channel, root);
toXML(metadata.pvp, root);
toXML(metadata.dwell, root);
toXML(metadata.referenceGeometry, root);

if (metadata.supportArray.get())
{
toXML(*(metadata.supportArray), root);
}

toXML(metadata.dwell, root);
toXML(metadata.referenceGeometry, root);

if (metadata.antenna.get())
{
toXML(*(metadata.antenna), root);
Expand Down Expand Up @@ -320,8 +322,11 @@ XMLElem CPHDXMLParser::toXML(const Data& data, XMLElem parent)
createString("Identifier", data.channels[ii].identifier, channelXML);
createInt("NumVectors", data.channels[ii].numVectors, channelXML);
createInt("NumSamples", data.channels[ii].numSamples, channelXML);
createInt("SignalArrayByteOffset", data.channels[ii].signalArrayByteOffset, channelXML);
createInt("PVPArrayByteOffset", data.channels[ii].pvpArrayByteOffset, channelXML);
std::string lTmpStr1 = std::to_string(data.channels[ii].signalArrayByteOffset);
std::string lTmpStr2 = std::to_string(data.channels[ii].pvpArrayByteOffset);
createString("SignalArrayByteOffset", lTmpStr1, channelXML);
createString("PVPArrayByteOffset", lTmpStr2, channelXML);

if(!six::Init::isUndefined(data.channels[ii].compressedSignalSize))
{
createInt("CompressedSignalSize", data.channels[ii].compressedSignalSize, channelXML);
Expand Down Expand Up @@ -581,13 +586,12 @@ void CPHDXMLParser::createSupportArray(const std::vector<SupportArrayParameter>&
for (auto&& param : supportArray)
{
XMLElem pXML = newElement(tag, &parent);
createInt("Identifier", param.getIdentifier(), pXML);
createString("Identifier", param.getIdentifier(), pXML);
createString("ElementFormat", param.elementFormat, pXML);
createDouble("X0", param.x0, pXML);
createDouble("Y0", param.y0, pXML);
createDouble("XSS", param.xSS, pXML);
createDouble("YSS", param.ySS, pXML);

}
}

Expand Down Expand Up @@ -1757,6 +1761,7 @@ void CPHDXMLParser::fromXML(const xml::lite::Element* antennaXML, Antenna& anten
XMLElem arrayXML = getFirstAndOnly(antPatternXMLVec[ii], "Array");
mCommon.parsePoly2D(getFirstAndOnly(arrayXML, "GainPoly"), antenna.antPattern[ii].array.gainPoly);
mCommon.parsePoly2D(getFirstAndOnly(arrayXML, "PhasePoly"), antenna.antPattern[ii].array.phasePoly);
std::ignore = six::parse(parser(), *arrayXML, antenna.antPattern[ii].array.antGPId);

// Parse Element
XMLElem elementXML = getFirstAndOnly(antPatternXMLVec[ii], "Element");
Expand Down Expand Up @@ -2413,8 +2418,8 @@ void CPHDXMLParser::parseSupportArrayParameter(const xml::lite::Element* paramXM
{
if(!additionalFlag)
{
size_t identifierVal;
parseUInt(getFirstAndOnly(paramXML, "Identifier"), identifierVal);
std::string identifierVal;
parseString(getFirstAndOnly(paramXML, "Identifier"), identifierVal);
param.setIdentifier(identifierVal);
}
parseString(getFirstAndOnly(paramXML, "ElementFormat"), param.elementFormat);
Expand Down
18 changes: 9 additions & 9 deletions six/modules/c++/cphd/source/FileHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ int64_t FileHeader::getPvpPadBytes() const
std::ostream& operator<< (std::ostream& os, const FileHeader& fh)
{
os << "FileHeader::\n"
<< " mVersion : " << to_string(fh.mVersion) << "\n"
<< " mXmlBlockSize : " << fh.mXmlBlockSize << "\n"
<< " mXmlBlockByteOffset : " << fh.mXmlBlockByteOffset << "\n"
<< " mSupportBlockSize : " << fh.mSupportBlockSize << "\n"
<< " mSupportBlockSize : " << fh.mSupportBlockByteOffset << "\n"
<< " mPvpBlockByteOffset : " << fh.mPvpBlockSize << "\n"
<< " mPvpBlockByteOffset : " << fh.mPvpBlockByteOffset << "\n"
<< " mSignalBlockSize : " << fh.mSignalBlockSize << "\n"
<< " mSignalBlockByteOffset : " << fh.mSignalBlockByteOffset << "\n"
<< " mVersion : " << to_string(fh.mVersion) << "\n"
<< " mXmlBlockSize : " << fh.mXmlBlockSize << "\n"
<< " mXmlBlockByteOffset : " << fh.mXmlBlockByteOffset << "\n"
<< " mSupportBlockSize : " << fh.mSupportBlockSize << "\n"
<< " mSupportBlockByteOffset : " << fh.mSupportBlockByteOffset << "\n"
<< " mPvpBlockSize : " << fh.mPvpBlockSize << "\n"
<< " mPvpBlockByteOffset : " << fh.mPvpBlockByteOffset << "\n"
<< " mSignalBlockSize : " << fh.mSignalBlockSize << "\n"
<< " mSignalBlockByteOffset : " << fh.mSignalBlockByteOffset << "\n"
<< " mClassification: " << fh.mClassification << "\n"
<< " mReleaseInfo : " << fh.mReleaseInfo << "\n";
return os;
Expand Down
102 changes: 96 additions & 6 deletions six/modules/c++/cphd/source/SupportArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ SupportArrayParameter::SupportArrayParameter() :
y0(six::Init::undefined<double>()),
xSS(six::Init::undefined<double>()),
ySS(six::Init::undefined<double>()),
identifier(six::Init::undefined<size_t>())
identifier(six::Init::undefined<std::string>())
{
}

SupportArrayParameter::SupportArrayParameter(
const std::string& format,
size_t id,
const std::string& id,
double x0_in,
double y0_in,
double xSS_in,
Expand Down Expand Up @@ -83,14 +83,32 @@ AdditionalSupportArray::AdditionalSupportArray(

static SupportArrayParameter getSupportArray(const std::vector<SupportArrayParameter>& params, const std::string& key)
{
size_t keyNum = str::toType<size_t>(key);
if (params.size() <= keyNum)
std::vector<int> validKeys;
for(size_t ii = 0; ii < params.size(); ++ii)
{
if (params[ii].getIdentifier()==key)
{
// found correct key. so add to validKeys
validKeys.push_back(ii);
}
}

if(validKeys.empty())
{
// if no matching key found, throw an exception
std::ostringstream oss;
oss << "SA_ID was not found " << (key);
throw except::Exception(Ctxt(oss));
throw except::Exception(Ctxt(oss.str()));
}
return params[keyNum];
if (validKeys.size()>1)
{
// if find repeated key, throw an exception
std::ostringstream oss;
oss << "Found multiple support arrays with same SA_ID: " << (key);
throw except::Exception(Ctxt(oss.str()));
}

return params[validKeys[0]];
}

SupportArrayParameter SupportArray::getIAZSupportArray(const std::string& key) const
Expand Down Expand Up @@ -119,6 +137,78 @@ AdditionalSupportArray SupportArray::getAddedSupportArray(const std::string& key
return addedSupportArray.find(key)->second;
}

size_t SupportArray::getSupportDataBytesPerSwap(const std::string& key,
size_t bytesPerElement) const
{
std::string elemFmt;
// Unfortunately, need to search each vector/map of support arrays
if(elemFmt.empty())
{
for(size_t ii = 0; ii < iazArray.size(); ++ii)
{
if (iazArray[ii].getIdentifier() == key)
{
// found correct id, so get element format
elemFmt = iazArray[ii].elementFormat;
break;
}
}
}

if(elemFmt.empty())
{
for(size_t ii = 0; ii < antGainPhase.size(); ++ii)
{
if (antGainPhase[ii].getIdentifier() == key)
{
// found correct id, so get element format
elemFmt = antGainPhase[ii].elementFormat;
break;
}
}
}

if(elemFmt.empty())
{
for(size_t ii = 0; ii < dwellTimeArray.size(); ++ii)
{
if (dwellTimeArray[ii].getIdentifier() == key)
{
// found correct id, so get element format
elemFmt = dwellTimeArray[ii].elementFormat;
break;
}
}
}

if(elemFmt.empty())
{
if (addedSupportArray.count(key) > 0)
{
// found correct id, so get element format
elemFmt = addedSupportArray.find(key)->second.elementFormat;
}
}

if(elemFmt.empty())
{
std::ostringstream oss;
oss << "SA_ID was not found" << (key);
throw except::Exception(Ctxt(oss.str()));
}

//Assuming homogeneous component types
//TODO: Test for validity of this assumption?
auto eqLoc = elemFmt.find("=");
auto numSwapsPerElement = str::split(elemFmt, ";").size();
if (elemFmt[eqLoc + 1] == 'C')
{
//Byteswap complex components individually too
numSwapsPerElement *= 2;
}
return bytesPerElement / numSwapsPerElement;
}

std::ostream& operator<< (std::ostream& os, const SupportArrayParameter& s)
{
if (!six::Init::isUndefined(s.getIdentifier()))
Expand Down
Loading

0 comments on commit 3e82dd3

Please sign in to comment.