Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor OriginalLabel class to remove inheritance from Blob #4309

Merged
merged 5 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions isis/src/base/apps/caminfo/caminfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ namespace Isis{

// Add the orginal label blob
if(ui.GetBoolean("ORIGINALLABEL") && incube->label()->hasObject("OriginalLabel")) {
OriginalLabel orig;
incube->read(orig);
OriginalLabel orig = incube->readOriginalLabel();
Pvl p = orig.ReturnLabels();
p.setName("OriginalLabel");
params.addObject(p);
Expand Down
1 change: 0 additions & 1 deletion isis/src/base/apps/demprep/demprep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "TProjection.h"
#include "SpecialPixel.h"
#include "LineManager.h"
#include "OriginalLabel.h"
#include "History.h"
#include "Table.h"
#include "Pvl.h"
Expand Down
9 changes: 4 additions & 5 deletions isis/src/base/apps/topds4/topds4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ namespace Isis {
// Add the original label (from an ingestion app) to the template engine data
// Wrap it in an OriginalLabel so existing elements don't get overwritten
if (cubeLabel.hasObject("OriginalLabel")) {
OriginalLabel origBlob;
icube->read(origBlob);
Pvl origLabel;
origLabel = origBlob.ReturnLabels();
dataSource["OriginalLabel"].update(pvlToJSON(origLabel));
OriginalLabel origLabel = icube->readOriginalLabel();
Pvl pvlOrigLabel;
pvlOrigLabel = origLabel.ReturnLabels();
dataSource["OriginalLabel"].update(pvlToJSON(pvlOrigLabel));
}
else if (cubeLabel.hasObject("OriginalXmlLabel")) {
OriginalXmlLabel origXmlBlob;
Expand Down
26 changes: 26 additions & 0 deletions isis/src/base/objs/Cube/Cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ find files of those names at the top level of this repository. **/
#include "IException.h"
#include "LineManager.h"
#include "Message.h"
#include "OriginalLabel.h"
#include "Preference.h"
#include "ProgramLauncher.h"
#include "Projection.h"
Expand Down Expand Up @@ -859,6 +860,22 @@ namespace Isis {
return footprint;
}

/**
* This method will read an OriginalLabel from a cube.
*/
OriginalLabel Cube::readOriginalLabel() const {
Blob origLabelBlob("IsisCube", "OriginalLabel");
try {
origLabelBlob.Read(fileName());
}
catch (IException &){
QString msg = "Unable to locate OriginalLabel in " + fileName();
throw IException(IException::User, msg, _FILEINFO_);
}
AustinSanders marked this conversation as resolved.
Show resolved Hide resolved
OriginalLabel origLabel(origLabelBlob);
return origLabel;
}

/**
* This method will write a blob of data (e.g. History, Table, etc)
* to the cube as specified by the contents of the Blob object.
Expand Down Expand Up @@ -929,6 +946,15 @@ namespace Isis {
}
}

/**
* This method will write an OriginalLabel object.
* to the cube as specified by the contents of the Blob object.
*
* @param Original label data to be written
*/
void Cube::write(OriginalLabel lab) {
write(*(lab.toBlob()));
}
Comment on lines +955 to +957
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this write method makes things easier but I don't know how necessary it is and that's something I have been going back and forth on. It'd be good for us to figure out exactly how we want to be writing these blobs back out. While the *(lab.toBlob()) is a little messy I don't think it's bad to have write(*(lab.toBlob())) all over the place rather than write(lab)


/**
* This method will write a buffer of data from the cube as specified by the
Expand Down
3 changes: 3 additions & 0 deletions isis/src/base/objs/Cube/Cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace Isis {
class Statistics;
class Histogram;
class History;
class OriginalLabel;
class ImagePolygon;

/**
Expand Down Expand Up @@ -250,9 +251,11 @@ namespace Isis {
void read(Blob &blob,
const std::vector<PvlKeyword> keywords = std::vector<PvlKeyword>()) const;
void read(Buffer &rbuf) const;
OriginalLabel readOriginalLabel() const;
History readHistory(const QString &name = "IsisCube") const;
ImagePolygon readFootprint() const;
void write(Blob &blob, bool overwrite=true);
void write(OriginalLabel lab);
void write(Buffer &wbuf);

void setBaseMultiplier(double base, double mult);
Expand Down
62 changes: 32 additions & 30 deletions isis/src/base/objs/OriginalLabel/OriginalLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,28 @@ namespace Isis {
/**
* Constructor for creating an original blob with a given name
*/
OriginalLabel::OriginalLabel() : Isis::Blob("IsisCube", "OriginalLabel") {
OriginalLabel::OriginalLabel() {
m_originalLabel.setTerminator("");
}


/**
* Constructor for creating an original label from a blob object.
*/
OriginalLabel::OriginalLabel(Isis::Blob &blob) {
fromBlob(blob);
}

/**
* Constructor for creating an original blob with a given name and file to
* read labels from.
*
* @param file File to read labels from
*/
OriginalLabel::OriginalLabel(const QString &file) :
Isis::Blob("IsisCube", "OriginalLabel") {
Blob::Read(file);
OriginalLabel::OriginalLabel(const QString &file){
Blob blob = Blob("IsisCube", "OriginalLabel");
blob.Read(file);
fromBlob(blob);
}

/**
Expand All @@ -37,35 +46,32 @@ namespace Isis {
*
* @param pvl Pvl containing labels of the source
*/
OriginalLabel::OriginalLabel(Pvl pvl) : Isis::Blob("IsisCube", "OriginalLabel") {
OriginalLabel::OriginalLabel(Pvl pvl){
m_originalLabel = pvl;
}

// Destructor
OriginalLabel::~OriginalLabel() {
}

/**
* Prepare labels for writing to the output cube.
*/
void OriginalLabel::WriteInit() {
ostringstream ostr;
if(p_nbytes > 0) ostr << std::endl;

// store labels
ostr << m_originalLabel;
string orglblStr = ostr.str();
int bytes = orglblStr.size();

// Copy label data to bytes variable
char *temp = p_buffer;
p_buffer = new char[p_nbytes+bytes];
if(temp != NULL) memcpy(p_buffer, temp, p_nbytes);
const char *ptr = orglblStr.c_str();
memcpy(&p_buffer[p_nbytes], (void *)ptr, bytes);
p_nbytes += bytes;
void OriginalLabel::fromBlob(Isis::Blob blob) {
Pvl pvl;
stringstream os;
char *buff = blob.getBuffer();
for(int i = 0; i < blob.Size(); i++){
os << buff[i];
}
os >> pvl;
m_originalLabel = pvl;
}

if(temp != NULL) delete [] temp;
Isis::Blob *OriginalLabel::toBlob() {
jessemapel marked this conversation as resolved.
Show resolved Hide resolved
std::stringstream sstream;
sstream << m_originalLabel;
string orglblStr = sstream.str();
Isis::Blob *blob = new Blob("IsisCube", "OriginalLabel");
blob->setData((char*)orglblStr.data(), orglblStr.length());
return blob;
}

/**
Expand All @@ -74,10 +80,6 @@ namespace Isis {
* @return (Isis::Pvl) original labels
*/
Pvl OriginalLabel::ReturnLabels() {
Pvl pvl;
stringstream os;
for(int i = 0; i < p_nbytes; i++) os << p_buffer[i];
os >> pvl;
return pvl;
return m_originalLabel;
}
}
6 changes: 4 additions & 2 deletions isis/src/base/objs/OriginalLabel/OriginalLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ namespace Isis {
* @history 2008-06-18 Steven Koechle - Fixed Documentation Errors
*
*/
class OriginalLabel : public Isis::Blob {
class OriginalLabel {
public:
OriginalLabel();
OriginalLabel(const QString &file);
OriginalLabel(Isis::Blob &blob);
OriginalLabel(Pvl pvl);
~OriginalLabel();

// Return the original labels
Pvl ReturnLabels();
Isis::Blob *toBlob();

protected:
// prepare data for writing
Expand All @@ -49,8 +51,8 @@ namespace Isis {
private:
// labels of original source
Pvl m_originalLabel;
void fromBlob(Isis::Blob blob);
};
};

#endif

2 changes: 1 addition & 1 deletion isis/src/base/objs/OriginalLabel/unitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main(int argc, char *argv[]) {
cout << p << endl;
Isis::OriginalLabel ol(p);

ol.Write("olTemp");
ol.toBlob()->Write("olTemp");

Isis::OriginalLabel ol2("olTemp");

Expand Down
3 changes: 1 addition & 2 deletions isis/src/base/objs/Process/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,7 @@ Isis::Cube *Process::SetOutputCubeStretch(const QString &parameter, const int ns
Isis::Pvl &inlab = *InputCubes[0]->label();
for(int i = 0; i < inlab.objects(); i++) {
if(inlab.object(i).isNamed("OriginalLabel")) {
Isis::OriginalLabel ol;
InputCubes[0]->read(ol);
Isis::OriginalLabel ol = InputCubes[0]->readOriginalLabel();
cube->write(ol);
}
}
Expand Down
2 changes: 0 additions & 2 deletions isis/src/galileo/apps/gllnims2isis/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ find files of those names at the top level of this repository. **/
#include "FileName.h"
#include "IException.h"
#include "iTime.h"
#include "OriginalLabel.h"
#include "Message.h"
#include "ProcessImportPds.h"
#include "ProcessByLine.h"
Expand Down Expand Up @@ -146,7 +145,6 @@ void importQubs(QString coreParamName, QString suffixParamName) {
}

// Create holder for original label
OriginalLabel origLabel(*pdsLabel);
//pdsLabel->write(fi.baseName()+".pvl");

//QFileInfo inputFileInfo(inFile.expanded());
Expand Down
3 changes: 1 addition & 2 deletions isis/src/lo/apps/lopdsgen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ void IsisMain() {
pdsLabel.addKeyword(productId);

// Translate the keywords from the original labels that go in this label
OriginalLabel origBlob;
iCube->read(origBlob);
OriginalLabel origBlob = iCube->readOriginalLabel();
Pvl origLabel;
PvlObject origLabelObj = origBlob.ReturnLabels();
origLabelObj.setName("OriginalLabelObject");
Expand Down
3 changes: 1 addition & 2 deletions isis/src/lro/apps/mrf2pds/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ void IsisMain() {
// Translate the keywords from the original EDR PDS label that go in
// this RDR PDS label for Level2 images only
if(bLevel2) {
OriginalLabel cOriginalBlob;
cInCube->read(cOriginalBlob);
OriginalLabel cOriginalBlob = cInCube->readOriginalLabel();
Pvl cOrigLabel;
PvlObject cOrigLabelObj = cOriginalBlob.ReturnLabels();
cOrigLabelObj.setName("OriginalLabelObject");
Expand Down
13 changes: 6 additions & 7 deletions isis/src/messenger/apps/mdis2pds/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,17 @@ void IsisMain() {

// Translate the keywords from the original EDR PDS label that go in
// this RDR PDS label
OriginalLabel origBlob;
incube->read(origBlob);
Pvl origLabel;
PvlObject origLabelObj = origBlob.ReturnLabels();
OriginalLabel origLabel = incube->readOriginalLabel();
Pvl pvlOrigLabel;
PvlObject origLabelObj = origLabel.ReturnLabels();
origLabelObj.setName("OriginalLabelObject");
origLabel.addObject(origLabelObj);
pvlOrigLabel.addObject(origLabelObj);

p.CheckStatus();

// Translates the ISIS labels along with the original EDR labels
origLabel.addObject(*(incube->label()));
PvlToPvlTranslationManager labels(origLabel,
pvlOrigLabel.addObject(*(incube->label()));
PvlToPvlTranslationManager labels(pvlOrigLabel,
"$ISISROOT/appdata/translations/MessengerMdisCdrLabel.trn");
labels.Auto(pdsLabel);

Expand Down
3 changes: 1 addition & 2 deletions isis/src/messenger/apps/mdisddr/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ void IsisMain() {
// output PDS file (required for 5 band IMAGE object).
Cube from;
from.open(input.expanded());
OriginalLabel origBlob;
from.read(origBlob);
OriginalLabel origBlob = from.readOriginalLabel();
Pvl origLabel;
PvlObject origLabelObj = origBlob.ReturnLabels();
origLabelObj.setName("OriginalLabelObject");
Expand Down
3 changes: 1 addition & 2 deletions isis/src/mro/apps/hicolormos/hicolormos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ void hicolormos(Cube *from1, Cube* from2, UserInterface &ui) {
mos += specialProcessingFlag;

//get the orginal label
OriginalLabel from1OrgLab;
from1OrgLab.Blob::Read(from1->fileName());
OriginalLabel from1OrgLab(from1->fileName());

Cube c;
c.open(ui.GetFileName("TO"), "rw");
Expand Down
9 changes: 3 additions & 6 deletions isis/src/mro/apps/hicubeit/hicubeit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,9 @@ namespace Isis {
}

// Concatenate all TDIs into one keyword
OriginalLabel redOrgLab;
redOrgLab.Blob::Read(redFile);
OriginalLabel irOrgLab;
irOrgLab.Blob::Read(irFile);
OriginalLabel bgOrgLab;
bgOrgLab.Blob::Read(bgFile);
OriginalLabel redOrgLab(redFile);
OriginalLabel irOrgLab(irFile);
OriginalLabel bgOrgLab(bgFile);

PvlGroup redGrp = redOrgLab.ReturnLabels().findGroup("INSTRUMENT_SETTING_PARAMETERS", Pvl::Traverse);
PvlGroup irGrp = irOrgLab.ReturnLabels().findGroup("INSTRUMENT_SETTING_PARAMETERS", Pvl::Traverse);
Expand Down
3 changes: 1 addition & 2 deletions isis/src/mro/apps/hideal2pds/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ void IsisMain() {
cubeLab.Auto(pdsLabel);

// get original label information
OriginalLabel origBlob;
inputCube->read(origBlob);
OriginalLabel origBlob = inputCube->readOriginalLabel();
Pvl origLabel;
PvlObject origLabelObj = origBlob.ReturnLabels();
origLabelObj.setName("OriginalLabelObject");
Expand Down
9 changes: 3 additions & 6 deletions isis/src/mro/apps/himos/himos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ namespace Isis {
QString startTime;
QString stopTime;
for(int i = 0; i < (int)clist.size(); i++) {
OriginalLabel origLab;
clist[i]->read(origLab);
OriginalLabel origLab = clist[i]->readOriginalLabel();
PvlGroup timegrp = origLab.ReturnLabels().findGroup("TIME_PARAMETERS", Pvl::Traverse);
if(i == 0) {
startClock = (QString)timegrp["SpacecraftClockStartCount"];
Expand Down Expand Up @@ -219,8 +218,7 @@ namespace Isis {
for(int i = 0; i < (int)clist.size(); i++) {
Pvl *clab = clist[i]->label();
PvlGroup cInst = clab->findGroup("Instrument", Pvl::Traverse);
OriginalLabel cOrgLab;
clist[i]->read(cOrgLab);
OriginalLabel cOrgLab = clist[i]->readOriginalLabel();
PvlGroup cGrp = cOrgLab.ReturnLabels().findGroup("INSTRUMENT_SETTING_PARAMETERS", Pvl::Traverse);
cpmmTdiFlag[(int)cInst["CpmmNumber"]] = (QString) cGrp["MRO:TDI"];
cpmmSummingFlag[(int)cInst["CpmmNumber"]] = (QString) cGrp["MRO:BINNING"];
Expand All @@ -236,8 +234,7 @@ namespace Isis {
}

// Get the blob of original labels from first image in list
OriginalLabel org;
clist[0]->read(org);
OriginalLabel org = clist[0]->readOriginalLabel();

//close all cubes
for(int i = 0; i < (int)clist.size(); i++) {
Expand Down
3 changes: 1 addition & 2 deletions isis/src/mro/apps/hirdrgen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ void IsisMain() {

// Translate the keywords from the original EDR PDS label that go in
// this RDR PDS label
OriginalLabel origBlob;
icube2->read(origBlob);
OriginalLabel origBlob = icube2->readOriginalLabel();
Pvl origLabel;
PvlObject origLabelObj = origBlob.ReturnLabels();
origLabelObj.setName("OriginalLabelObject");
Expand Down
Loading