Skip to content

Commit 3e82dd3

Browse files
Merge pull request #749 from bzhang162/SIX-3.3.1
Six 3.3.1
2 parents 41703fc + 9387984 commit 3e82dd3

File tree

17 files changed

+255
-71
lines changed

17 files changed

+255
-71
lines changed

externals/coda-oss/modules/c++/types/include/types/RowCol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ template<typename T> class RowCol
6161
T col{};
6262

6363
// Try to protect us from the unfortunate and probably
64-
// unintendet case where row gets set and col doesnt, especially
64+
// unintended case where row gets set and col doesn't, especially
6565
// when doing scalar operations that might otherwise create
6666
// ambiguities
6767
RowCol() {} // = default; // error w/ICC and "const" member data

six/modules/c++/cphd/include/cphd/CPHDWriter.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,11 @@ struct SIX_CPHD_API CPHDWriter final
202202
void writeSupportData(io::OutputStream& stream,
203203
const T* data_, const std::string& id)
204204
{
205-
const auto size = mMetadata.data.getSupportArrayById(id).size_bytes();
205+
const auto &dataArray = mMetadata.data.getSupportArrayById(id);
206+
207+
const auto size = dataArray.size_bytes();
206208
const auto data = sys::make_span<const std::byte>(data_, size);
207-
writeSupportDataImpl(stream, data, mMetadata.data.getSupportArrayById(id).bytesPerElement);
209+
writeSupportDataImpl(stream, data, getSupportDataBytesPerSwap(dataArray));
208210
}
209211
template <typename T>
210212
void writeSupportData(const T* data, const std::string& id)
@@ -221,6 +223,7 @@ struct SIX_CPHD_API CPHDWriter final
221223
* \param data A pointer to the start of the support array data block
222224
*/
223225
sys::Off_T getSupportBlockByteOffset(const Data::SupportArray&) const;
226+
size_t getSupportDataBytesPerSwap(const Data::SupportArray& dataArray) const;
224227
void writeSupportDataArray(io::SeekableOutputStream&, DataWriter&,
225228
std::span<const std::byte>, const Data::SupportArray&);
226229
void writeSupportDataArray(io::SeekableOutputStream&, std::span<const std::byte>, const Data::SupportArray&);

six/modules/c++/cphd/include/cphd/SupportArray.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct SupportArrayParameter
6565
* \param ySS_in Col coordinate (Y) sample spacing
6666
*/
6767
SupportArrayParameter(
68-
const std::string& format, size_t id,
68+
const std::string& format, const std::string& id,
6969
double x0_in, double y0_in,
7070
double xSS_in, double ySS_in);
7171

@@ -83,13 +83,13 @@ struct SupportArrayParameter
8383
}
8484

8585
//! Set unique identifier
86-
void setIdentifier(size_t identifierIn)
86+
void setIdentifier(const std::string& identifierIn)
8787
{
8888
identifier = identifierIn;
8989
}
9090

9191
//! Get unique identifier
92-
inline size_t getIdentifier() const
92+
inline std::string getIdentifier() const
9393
{
9494
return identifier;
9595
}
@@ -112,7 +112,7 @@ struct SupportArrayParameter
112112
protected:
113113
void initializeParams();
114114
private:
115-
size_t identifier;
115+
std::string identifier;
116116
};
117117

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

232+
//!Get bytes per swap for suppor array data by unique id
233+
size_t getSupportDataBytesPerSwap(const std::string& key, size_t bytesPerElement) const;
234+
232235
//! Vector of IAZ type arrays
233236
std::vector<SupportArrayParameter> iazArray;
234237

six/modules/c++/cphd/include/cphd/SupportBlock.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <mem/ScopedArray.h>
3737
#include <mem/BufferView.h>
3838

39+
#include <cphd/SupportArray.h>
3940
#include <cphd/Data.h>
4041
#include <cphd/Utilities.h>
4142
#include <cphd/Exports.h>
@@ -59,11 +60,13 @@ struct SIX_CPHD_API SupportBlock final
5960
* \brief Constructor initializes book keeping information
6061
*
6162
* \param pathname Input CPHD pathname to initialize a file input stream
63+
* \param supportArray SupportArray section for cphd::Metadata
6264
* \param data Data section from CPHD
6365
* \param startSupport CPHD header keyword "SUPPORT_BLOCK_BYTE_OFFSET"
6466
* \param sizeSupport CPHD header keyword "SUPPORT_BLOCK_SIZE"
6567
*/
6668
SupportBlock(const std::string& pathname,
69+
const mem::ScopedCopyablePtr<cphd::SupportArray> supportArray,
6770
const cphd::Data& data,
6871
int64_t startSupport,
6972
int64_t sizeSupport);
@@ -74,16 +77,20 @@ struct SIX_CPHD_API SupportBlock final
7477
* \brief Constructor initializes book keeping information
7578
*
7679
* \param inStream Input stream to an already opened CPHD file
80+
* \param supportArray SupportArray section for cphd::Metadata
7781
* \param data Data section from CPHD
7882
* \param startSupport CPHD header keyword "SUPPORT_BLOCK_BYTE_OFFSET"
7983
* \param sizeSupport CPHD header keyword "SUPPORT_BLOCK_SIZE"
8084
*/
8185
SupportBlock(std::shared_ptr<io::SeekableInputStream> inStream,
86+
const mem::ScopedCopyablePtr<cphd::SupportArray> supportArray,
8287
const cphd::Data& data,
8388
int64_t startSupport,
8489
int64_t sizeSupport);
8590
SupportBlock(std::shared_ptr<io::SeekableInputStream> inStream,
86-
const cphd::Data& data, const FileHeader&);
91+
const mem::ScopedCopyablePtr<cphd::SupportArray> supportArray,
92+
const cphd::Data& data,
93+
const FileHeader&);
8794

8895
// Noncopyable
8996
SupportBlock(const SupportBlock&) = delete;
@@ -154,6 +161,7 @@ struct SIX_CPHD_API SupportBlock final
154161

155162
private:
156163
const std::shared_ptr<io::SeekableInputStream> mInStream;
164+
const mem::ScopedCopyablePtr<cphd::SupportArray> mSupportArray;
157165
cphd::Data mData;
158166
const int64_t mSupportOffset; // offset in bytes to start of SupportBlock
159167
const size_t mSupportSize; // total size in bytes of SupportBlock

six/modules/c++/cphd/source/CPHDReader.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ cphd::CPHDReader::CPHDReader(std::shared_ptr<io::SeekableInputStream> inStream,
7171
: mFileHeader(cphd::FileHeader::read(*inStream)),
7272
mMetadata(fromXML(*inStream, schemaPaths_, logger, mFileHeader))
7373
{
74-
mSupportBlock = std::make_unique<SupportBlock>(inStream, mMetadata.data, mFileHeader);
74+
mSupportBlock = std::make_unique<SupportBlock>(inStream,
75+
mMetadata.supportArray,
76+
mMetadata.data,
77+
mFileHeader);
7578

7679
// Load the PVPBlock into memory
7780
mPVPBlock = PVPBlock(mMetadata);

six/modules/c++/cphd/source/CPHDWriter.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,24 @@ sys::Off_T CPHDWriter::getSupportBlockByteOffset(const Data::SupportArray& dataA
162162
const auto supportBlockByteOffset = mHeader.getSupportBlockByteOffset();
163163
return supportBlockByteOffset + dataArray.arrayByteOffset;
164164
}
165+
size_t CPHDWriter::getSupportDataBytesPerSwap(const Data::SupportArray& dataArray) const
166+
{
167+
if(mMetadata.supportArray.get() == nullptr)
168+
{
169+
std::ostringstream oss;
170+
oss << "mMetadata.supportArray was not populated";
171+
throw except::Exception(Ctxt(oss.str()));
172+
}
165173

174+
return mMetadata.supportArray->getSupportDataBytesPerSwap(dataArray.identifier,
175+
dataArray.bytesPerElement);
176+
}
166177
void CPHDWriter::writeSupportDataArray(io::SeekableOutputStream& stream, DataWriter& dataWriter,
167178
std::span<const std::byte> data, const Data::SupportArray& dataArray)
168179
{
169180
// Move inputstream head to offset of particular support array
170181
stream.seek(getSupportBlockByteOffset(dataArray), io::SeekableOutputStream::START);
171-
dataWriter(make_span(data, dataArray), dataArray.bytesPerElement);
182+
dataWriter(make_span(data, dataArray), getSupportDataBytesPerSwap(dataArray));
172183
}
173184
void CPHDWriter::writeSupportDataArray(io::SeekableOutputStream& stream,
174185
std::span<const std::byte> data, const Data::SupportArray& dataArray)

six/modules/c++/cphd/source/CPHDXMLParser.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ std::unique_ptr<xml::lite::Document> CPHDXMLParser::toXML(
7979
toXML(metadata.data, root);
8080
toXML(metadata.channel, root);
8181
toXML(metadata.pvp, root);
82-
toXML(metadata.dwell, root);
83-
toXML(metadata.referenceGeometry, root);
8482

8583
if (metadata.supportArray.get())
8684
{
8785
toXML(*(metadata.supportArray), root);
8886
}
87+
88+
toXML(metadata.dwell, root);
89+
toXML(metadata.referenceGeometry, root);
90+
8991
if (metadata.antenna.get())
9092
{
9193
toXML(*(metadata.antenna), root);
@@ -320,8 +322,11 @@ XMLElem CPHDXMLParser::toXML(const Data& data, XMLElem parent)
320322
createString("Identifier", data.channels[ii].identifier, channelXML);
321323
createInt("NumVectors", data.channels[ii].numVectors, channelXML);
322324
createInt("NumSamples", data.channels[ii].numSamples, channelXML);
323-
createInt("SignalArrayByteOffset", data.channels[ii].signalArrayByteOffset, channelXML);
324-
createInt("PVPArrayByteOffset", data.channels[ii].pvpArrayByteOffset, channelXML);
325+
std::string lTmpStr1 = std::to_string(data.channels[ii].signalArrayByteOffset);
326+
std::string lTmpStr2 = std::to_string(data.channels[ii].pvpArrayByteOffset);
327+
createString("SignalArrayByteOffset", lTmpStr1, channelXML);
328+
createString("PVPArrayByteOffset", lTmpStr2, channelXML);
329+
325330
if(!six::Init::isUndefined(data.channels[ii].compressedSignalSize))
326331
{
327332
createInt("CompressedSignalSize", data.channels[ii].compressedSignalSize, channelXML);
@@ -581,13 +586,12 @@ void CPHDXMLParser::createSupportArray(const std::vector<SupportArrayParameter>&
581586
for (auto&& param : supportArray)
582587
{
583588
XMLElem pXML = newElement(tag, &parent);
584-
createInt("Identifier", param.getIdentifier(), pXML);
589+
createString("Identifier", param.getIdentifier(), pXML);
585590
createString("ElementFormat", param.elementFormat, pXML);
586591
createDouble("X0", param.x0, pXML);
587592
createDouble("Y0", param.y0, pXML);
588593
createDouble("XSS", param.xSS, pXML);
589594
createDouble("YSS", param.ySS, pXML);
590-
591595
}
592596
}
593597

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

17611766
// Parse Element
17621767
XMLElem elementXML = getFirstAndOnly(antPatternXMLVec[ii], "Element");
@@ -2413,8 +2418,8 @@ void CPHDXMLParser::parseSupportArrayParameter(const xml::lite::Element* paramXM
24132418
{
24142419
if(!additionalFlag)
24152420
{
2416-
size_t identifierVal;
2417-
parseUInt(getFirstAndOnly(paramXML, "Identifier"), identifierVal);
2421+
std::string identifierVal;
2422+
parseString(getFirstAndOnly(paramXML, "Identifier"), identifierVal);
24182423
param.setIdentifier(identifierVal);
24192424
}
24202425
parseString(getFirstAndOnly(paramXML, "ElementFormat"), param.elementFormat);

six/modules/c++/cphd/source/FileHeader.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,15 @@ int64_t FileHeader::getPvpPadBytes() const
303303
std::ostream& operator<< (std::ostream& os, const FileHeader& fh)
304304
{
305305
os << "FileHeader::\n"
306-
<< " mVersion : " << to_string(fh.mVersion) << "\n"
307-
<< " mXmlBlockSize : " << fh.mXmlBlockSize << "\n"
308-
<< " mXmlBlockByteOffset : " << fh.mXmlBlockByteOffset << "\n"
309-
<< " mSupportBlockSize : " << fh.mSupportBlockSize << "\n"
310-
<< " mSupportBlockSize : " << fh.mSupportBlockByteOffset << "\n"
311-
<< " mPvpBlockByteOffset : " << fh.mPvpBlockSize << "\n"
312-
<< " mPvpBlockByteOffset : " << fh.mPvpBlockByteOffset << "\n"
313-
<< " mSignalBlockSize : " << fh.mSignalBlockSize << "\n"
314-
<< " mSignalBlockByteOffset : " << fh.mSignalBlockByteOffset << "\n"
306+
<< " mVersion : " << to_string(fh.mVersion) << "\n"
307+
<< " mXmlBlockSize : " << fh.mXmlBlockSize << "\n"
308+
<< " mXmlBlockByteOffset : " << fh.mXmlBlockByteOffset << "\n"
309+
<< " mSupportBlockSize : " << fh.mSupportBlockSize << "\n"
310+
<< " mSupportBlockByteOffset : " << fh.mSupportBlockByteOffset << "\n"
311+
<< " mPvpBlockSize : " << fh.mPvpBlockSize << "\n"
312+
<< " mPvpBlockByteOffset : " << fh.mPvpBlockByteOffset << "\n"
313+
<< " mSignalBlockSize : " << fh.mSignalBlockSize << "\n"
314+
<< " mSignalBlockByteOffset : " << fh.mSignalBlockByteOffset << "\n"
315315
<< " mClassification: " << fh.mClassification << "\n"
316316
<< " mReleaseInfo : " << fh.mReleaseInfo << "\n";
317317
return os;

six/modules/c++/cphd/source/SupportArray.cpp

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ SupportArrayParameter::SupportArrayParameter() :
3333
y0(six::Init::undefined<double>()),
3434
xSS(six::Init::undefined<double>()),
3535
ySS(six::Init::undefined<double>()),
36-
identifier(six::Init::undefined<size_t>())
36+
identifier(six::Init::undefined<std::string>())
3737
{
3838
}
3939

4040
SupportArrayParameter::SupportArrayParameter(
4141
const std::string& format,
42-
size_t id,
42+
const std::string& id,
4343
double x0_in,
4444
double y0_in,
4545
double xSS_in,
@@ -83,14 +83,32 @@ AdditionalSupportArray::AdditionalSupportArray(
8383

8484
static SupportArrayParameter getSupportArray(const std::vector<SupportArrayParameter>& params, const std::string& key)
8585
{
86-
size_t keyNum = str::toType<size_t>(key);
87-
if (params.size() <= keyNum)
86+
std::vector<int> validKeys;
87+
for(size_t ii = 0; ii < params.size(); ++ii)
8888
{
89+
if (params[ii].getIdentifier()==key)
90+
{
91+
// found correct key. so add to validKeys
92+
validKeys.push_back(ii);
93+
}
94+
}
95+
96+
if(validKeys.empty())
97+
{
98+
// if no matching key found, throw an exception
8999
std::ostringstream oss;
90100
oss << "SA_ID was not found " << (key);
91-
throw except::Exception(Ctxt(oss));
101+
throw except::Exception(Ctxt(oss.str()));
92102
}
93-
return params[keyNum];
103+
if (validKeys.size()>1)
104+
{
105+
// if find repeated key, throw an exception
106+
std::ostringstream oss;
107+
oss << "Found multiple support arrays with same SA_ID: " << (key);
108+
throw except::Exception(Ctxt(oss.str()));
109+
}
110+
111+
return params[validKeys[0]];
94112
}
95113

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

140+
size_t SupportArray::getSupportDataBytesPerSwap(const std::string& key,
141+
size_t bytesPerElement) const
142+
{
143+
std::string elemFmt;
144+
// Unfortunately, need to search each vector/map of support arrays
145+
if(elemFmt.empty())
146+
{
147+
for(size_t ii = 0; ii < iazArray.size(); ++ii)
148+
{
149+
if (iazArray[ii].getIdentifier() == key)
150+
{
151+
// found correct id, so get element format
152+
elemFmt = iazArray[ii].elementFormat;
153+
break;
154+
}
155+
}
156+
}
157+
158+
if(elemFmt.empty())
159+
{
160+
for(size_t ii = 0; ii < antGainPhase.size(); ++ii)
161+
{
162+
if (antGainPhase[ii].getIdentifier() == key)
163+
{
164+
// found correct id, so get element format
165+
elemFmt = antGainPhase[ii].elementFormat;
166+
break;
167+
}
168+
}
169+
}
170+
171+
if(elemFmt.empty())
172+
{
173+
for(size_t ii = 0; ii < dwellTimeArray.size(); ++ii)
174+
{
175+
if (dwellTimeArray[ii].getIdentifier() == key)
176+
{
177+
// found correct id, so get element format
178+
elemFmt = dwellTimeArray[ii].elementFormat;
179+
break;
180+
}
181+
}
182+
}
183+
184+
if(elemFmt.empty())
185+
{
186+
if (addedSupportArray.count(key) > 0)
187+
{
188+
// found correct id, so get element format
189+
elemFmt = addedSupportArray.find(key)->second.elementFormat;
190+
}
191+
}
192+
193+
if(elemFmt.empty())
194+
{
195+
std::ostringstream oss;
196+
oss << "SA_ID was not found" << (key);
197+
throw except::Exception(Ctxt(oss.str()));
198+
}
199+
200+
//Assuming homogeneous component types
201+
//TODO: Test for validity of this assumption?
202+
auto eqLoc = elemFmt.find("=");
203+
auto numSwapsPerElement = str::split(elemFmt, ";").size();
204+
if (elemFmt[eqLoc + 1] == 'C')
205+
{
206+
//Byteswap complex components individually too
207+
numSwapsPerElement *= 2;
208+
}
209+
return bytesPerElement / numSwapsPerElement;
210+
}
211+
122212
std::ostream& operator<< (std::ostream& os, const SupportArrayParameter& s)
123213
{
124214
if (!six::Init::isUndefined(s.getIdentifier()))

0 commit comments

Comments
 (0)