Skip to content

Commit

Permalink
remove old logging macros
Browse files Browse the repository at this point in the history
  • Loading branch information
ahoopes committed Apr 3, 2020
1 parent 65d465d commit 2e31025
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 50 deletions.
4 changes: 2 additions & 2 deletions include/argparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class ArgumentParser {
template <typename T>
T retrieve(const String& name) {
String unstripped = unstrip(name);
if (index.count(unstripped) == 0) logFatal(1) << "'" << unstripped << "' is not a known argument";
if (index.count(unstripped) == 0) fs::fatal() << "'" << unstripped << "' is not a known argument";
size_t N = index[unstripped];
T retrieved{};
// try to cast the arguments
Expand All @@ -232,7 +232,7 @@ class ArgumentParser {
fulltype = "std::vector<" + arguments[N].typeName() + ">";
sentence_starter = "These inputs are";
}
logFatal(1) << "invalid cast of argument '" << name << "'. " << sentence_starter << " of type '"
fs::fatal() << "invalid cast of argument '" << name << "'. " << sentence_starter << " of type '"
<< arguments[N].typeName() << "' and should be retrieved via " << term::dim()
<< "retrieve<" << fulltype << ">(\"" << name << "\")" << term::reset() << ". "
<< "To change the expected type, modify the call to "
Expand Down
4 changes: 0 additions & 4 deletions include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ namespace fs {

}

// temporary definitions
#define logWarning fs::warning()
#define logFatal(ret) fs::fatal(ret)

// old c-style error functions
void ErrorExit(int ecode, const char *fmt, ...);
void ErrorPrintf(int ecode, const char *fmt, ...);
Expand Down
2 changes: 1 addition & 1 deletion mri_refine_seg/mri_refine_seg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ int main(int argc, char **argv) {
// load input
std::string segname = parser.retrieve<std::string>("in");
MRI *seg = MRIread(segname.c_str());
if (!seg) logFatal(1) << "could not read input volume " << segname;
if (!seg) fs::fatal() << "could not read input volume " << segname;
MRI *orig_seg = MRIcopy(seg, NULL);

// allocate buffer for label mask (used for efficient cluster-finding)
Expand Down
24 changes: 12 additions & 12 deletions mri_seg_overlap/mri_seg_overlap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ int main(int argc, char **argv)

std::string seg1_fname = parser.retrieve<std::string>("seg1");
MRI *seg1 = MRIread(seg1_fname.c_str());
if (!seg1) logFatal(1) << "could not read input volume " << seg1;
if (!seg1) fs::fatal() << "could not read input volume " << seg1;

std::string seg2_fname = parser.retrieve<std::string>("seg2");
MRI *seg2 = MRIread(seg2_fname.c_str());
if (!seg2) logFatal(1) << "could not read input volume " << seg2;
if (!seg2) fs::fatal() << "could not read input volume " << seg2;

// check input dimensions
if (MRIdimMismatch(seg1, seg2, 0)) logFatal(1) << "input volumes must have matching dimensions";
if (seg1->nframes != seg2->nframes) logFatal(1) << "input volumes must have the same number of frames";
if (MRIdimMismatch(seg1, seg2, 0)) fs::fatal() << "input volumes must have matching dimensions";
if (seg1->nframes != seg2->nframes) fs::fatal() << "input volumes must have the same number of frames";

// ------ retrieve user options ------

Expand All @@ -86,7 +86,7 @@ int main(int argc, char **argv)
for (auto const &str : parser.retrieve<std::vector<std::string>>("measures")) {
if (str == "dice") measures.push_back(OverlapMeasure("dice", &computeDice));
else if (str == "jaccard") measures.push_back(OverlapMeasure("jaccard", &computeJaccard));
else logFatal(1) << "unknown measure '" << str << "'... options are: dice, jaccard";
else fs::fatal() << "unknown measure '" << str << "'... options are: dice, jaccard";
}
} else {
// by default, only report dice scores
Expand All @@ -95,11 +95,11 @@ int main(int argc, char **argv)

// a few sanity checks on the user input
if (parser.exists("labelfile") && parser.exists("labels")) {
logFatal(1) << "can't use both the --labels and --labelfile options together";
fs::fatal() << "can't use both the --labels and --labelfile options together";
} else if (parser.exists("names") && !parser.exists("labels")) {
logFatal(1) << "the --names option must be used along with the --labels option";
fs::fatal() << "the --names option must be used along with the --labels option";
} else if (parser.exists("seg") && (parser.exists("labelfile") || parser.exists("labels"))) {
logFatal(1) << "can't specify --seg in addition to a custom label list";
fs::fatal() << "can't specify --seg in addition to a custom label list";
}

// check if user wants to ignore label names
Expand All @@ -116,15 +116,15 @@ int main(int argc, char **argv)
// user provided custom label names as well
std::vector<std::string> names = parser.retrieve<std::vector<std::string>>("names");
if (names.size() != labels.size()) {
logFatal(1) << "number of label names (" << labelnames.size() << ") must match "
fs::fatal() << "number of label names (" << labelnames.size() << ") must match "
"the number of specified labels (" << labels.size() << ")";
}
for (unsigned int i = 0 ; i < labels.size() ; i++) labelnames[labels[i]] = names[i];
}
} else if (parser.exists("labelfile")) {
// user specified labels via a file - assume lookup-table format
LookupTable lut(parser.retrieve<std::string>("labelfile"));
if (lut.empty()) logFatal(1) << "provided label file contains no valid labels";
if (lut.empty()) fs::fatal() << "provided label file contains no valid labels";
labels = lut.labels();
if (lut.hasNameInfo()) for (int i : labels) labelnames[i] = lut[i].name;
} else if (parser.exists("seg")) {
Expand Down Expand Up @@ -190,13 +190,13 @@ int main(int argc, char **argv)
}

// sanity check to make sure the label list isn't empty
if (labels.empty()) logFatal(1) << "no matching labels to report on";
if (labels.empty()) fs::fatal() << "no matching labels to report on";

// determine default label names (if not already known) via FreeSurferColorLUT
if (reportNames && labelnames.empty()) {
LookupTable lut(std::string(std::getenv("FREESURFER_HOME")) + "/FreeSurferColorLUT.txt");
if (lut.empty()) {
logWarning << "can't load default FreeSurferColorLUT - is FREESURFER_HOME set?";
fs::warning() << "can't load default FreeSurferColorLUT - is FREESURFER_HOME set?";
reportNames = false;
} else if (lut.hasNameInfo()) {
for (int l : labels) labelnames[l] = lut[l].name;
Expand Down
4 changes: 2 additions & 2 deletions mris_annot_diff/mris_annot_diff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ int main(int argc, char *argv[])

// compare lengths
int length = annot1.size();
if (length != annot2.size()) logFatal(1) << "annotation sizes (" << length << " and " << annot2.size() << ") do not match";
if (length != annot2.size()) fs::fatal() << "annotation sizes (" << length << " and " << annot2.size() << ") do not match";

// diff labels
int ndiffs = 0;
for (int i = 0; i < length; i++) {
if (annot1[i] != annot2[i]) ndiffs++;
}

if (ndiffs > 0) logFatal(1) << "found " << ndiffs << " differences between annotations";
if (ndiffs > 0) fs::fatal() << "found " << ndiffs << " differences between annotations";
exit(0);
}
8 changes: 4 additions & 4 deletions mris_defects_pointset/mris_defects_pointset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ int main(int argc, char **argv)
std::string surfpath = parser.retrieve<std::string>("surf");
std::cout << "Reading in surface " << surfpath << std::endl;
MRIS *surf = MRISread(surfpath.c_str());
if (!surf) logFatal(1) << "could not read surface";
if (!surf) fs::fatal() << "could not read surface";

// load defect overlay
std::string defectpath = parser.retrieve<std::string>("defects");
std::cout << "Reading in defect segmentation " << defectpath << std::endl;
MRI *overlay = MRIread(defectpath.c_str());
if (!overlay) logFatal(1) << "could not read defect segmentation";
if (!overlay) fs::fatal() << "could not read defect segmentation";

if (overlay->width != surf->nvertices) {
logFatal(1) << "error: defect overlay (" << overlay->width << " points) "
fs::fatal() << "error: defect overlay (" << overlay->width << " points) "
<< "does not match surface (" << surf->nvertices << " vertices)";
}

Expand All @@ -61,7 +61,7 @@ int main(int argc, char **argv)
std::string labelpath = parser.retrieve<std::string>("label");
std::cout << "Reading in label " << labelpath << std::endl;
LABEL *label = LabelRead(NULL, labelpath.c_str());
if (!label) logFatal(1) << "could not read label";
if (!label) fs::fatal() << "could not read label";
// set values outside of the label to 0
MRI *tmp = MRISlabel2Mask(surf, label, NULL);
for (int v = 0 ; v < surf->nvertices ; v++) {
Expand Down
4 changes: 2 additions & 2 deletions mris_resample/mris_resample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ IoParams::parse(int ac, char** av)

annotation = false;

if (strAnnotationOut.empty() && !strAnnotationIn.empty()) logFatal(1) << "missing --annot_out flag";
if (!strAnnotationOut.empty() && strAnnotationIn.empty()) logFatal(1) << "missing --annot_in flag";
if (strAnnotationOut.empty() && !strAnnotationIn.empty()) fs::fatal() << "missing --annot_out flag";
if (!strAnnotationOut.empty() && strAnnotationIn.empty()) fs::fatal() << "missing --annot_in flag";

if (!strAnnotationOut.empty() && !strAnnotationIn.empty()) {
annotation = true;
Expand Down
2 changes: 1 addition & 1 deletion utils/annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int print_annotation_colortable(FILE *fp)
std::vector<int> readAnnotationIntoVector(const std::string& filename)
{
FILE *file = fopen(filename.c_str(), "r");
if (!file) logFatal(1) << "could not open " << filename;
if (!file) fs::fatal() << "could not open " << filename;

std::map<int,int> annotmap;
int num = freadInt(file);
Expand Down
38 changes: 19 additions & 19 deletions utils/argparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
static std::string verifyOption(const std::string& name)
{
if (name.empty())
logFatal(1) << "invalid argument configuration. Argument names must not be empty";
fs::fatal() << "invalid argument configuration. Argument names must not be empty";
if ((name.size() == 2 && name[0] != '-') || name.size() == 3)
logFatal(1) << "invalid argument configuration for '" << name << "'. Short names must begin with '-'";
fs::fatal() << "invalid argument configuration for '" << name << "'. Short names must begin with '-'";
if (name.size() > 3 && (name[0] != '-' || name[1] != '-'))
logFatal(1) << "invalid argument configuration for '" << name << "'. Multi-character names must begin with '--'";
fs::fatal() << "invalid argument configuration for '" << name << "'. Multi-character names must begin with '--'";
return name;
}

Expand Down Expand Up @@ -101,11 +101,11 @@ ArgumentParser::Argument::Argument(const ArgumentParser::String& _short_name, co

// check for illogical option flags
if ((min_args == 0) && (argtype != ArgType::Bool)) {
logFatal(1) << "invalid argument configuration for '" << canonicalName() << "'. "
fs::fatal() << "invalid argument configuration for '" << canonicalName() << "'. "
<< "Option flags that accept no input must be of type ArgType::Bool";
}
if ((min_args == 0) && required) {
logFatal(1) << "invalid argument configuration for '" << canonicalName() << "'. "
fs::fatal() << "invalid argument configuration for '" << canonicalName() << "'. "
<< "Required flags must accept at least one input";
}
}
Expand All @@ -115,11 +115,11 @@ ArgumentParser::Argument::Argument(const ArgumentParser::String& _short_name, co
void ArgumentParser::Argument::validate()
{
if (positional && consumed < min_args)
logFatal(2) << "not enough positional arguments supplied";
fs::fatal(2) << "not enough positional arguments supplied";
if (fixed && fixed_nargs != consumed)
logFatal(2) << "not enough inputs passed to option '" << canonicalName() << "' (expected " << fixed_nargs << ")";
fs::fatal(2) << "not enough inputs passed to option '" << canonicalName() << "' (expected " << fixed_nargs << ")";
if (!fixed && variable_nargs == '+' && consumed < 1)
logFatal(2) << "option '" << canonicalName() << "' requires at least one input";
fs::fatal(2) << "option '" << canonicalName() << "' requires at least one input";
}


Expand Down Expand Up @@ -216,7 +216,7 @@ void ArgumentParser::parse(size_t ac, char** av)
if (index.count(future) == 0) args_following++;
}
if (arguments[index[element]].min_args > args_following) {
logFatal(2) << "not enough inputs supplied to '" << element << "'";
fs::fatal(2) << "not enough inputs supplied to '" << element << "'";
}
}
}
Expand All @@ -238,7 +238,7 @@ void ArgumentParser::parse(size_t ac, char** av)
// if so, let's get the next set of positional arguments
posidx++;
if (posidx >= positionals.size()) {
logFatal(2) << "unexpected argument '" << element << "'";
fs::fatal(2) << "unexpected argument '" << element << "'";
} else {
active = positionals[posidx];
}
Expand Down Expand Up @@ -284,7 +284,7 @@ void ArgumentParser::parse(size_t ac, char** av)
}
}
} catch (...) {
logFatal(2) << "input '" << element << "' cannot be converted to expected type (" << active.typeName() << ")";
fs::fatal(2) << "input '" << element << "' cannot be converted to expected type (" << active.typeName() << ")";
}
variables[N].exists = true;
active.consumed++;
Expand Down Expand Up @@ -327,7 +327,7 @@ void ArgumentParser::parse(size_t ac, char** av)
for (ArgumentVector::const_iterator it = arguments.begin(); it != arguments.end(); ++it) {
Argument arg = *it;
if (arg.required && !exists(arg.canonicalName())) {
logFatal(2) << "missing required input '" << arg.canonicalName() << "'";
fs::fatal(2) << "missing required input '" << arg.canonicalName() << "'";
}
}
}
Expand All @@ -351,7 +351,7 @@ bool ArgumentParser::exists(const String& name)
{
// first check if name is a valid argument key
String unstripped = unstrip(name);
if (index.count(unstripped) == 0) logFatal(1) << "'" << unstripped << "' is not a known argument";
if (index.count(unstripped) == 0) fs::fatal() << "'" << unstripped << "' is not a known argument";
return variables[index[unstripped]].exists;
}

Expand All @@ -369,31 +369,31 @@ void ArgumentParser::insertArgument(const ArgumentParser::Argument& arg)
case ArgType::Float : variables.push_back(float(0)); break;
case ArgType::Bool : variables.push_back(false); break;
case ArgType::String : variables.push_back(String()); break;
default : logFatal(1) << "unknown argument type for '" << arg.canonicalName() << "'";
default : fs::fatal() << "unknown argument type for '" << arg.canonicalName() << "'";
}
} else {
switch(arg.argtype) {
case ArgType::Int : variables.push_back(IntVector()); break;
case ArgType::Float : variables.push_back(FloatVector()); break;
case ArgType::Bool : variables.push_back(std::vector<bool>()); break;
case ArgType::String : variables.push_back(StringVector()); break;
default : logFatal(1) << "unknown argument type for '" << arg.canonicalName() << "'";
default : fs::fatal() << "unknown argument type for '" << arg.canonicalName() << "'";
}
}

// make sure name doesn't already exist
for (IndexMap::iterator it = index.begin(); it != index.end(); it++) {
String stripped = strip(it->first);
if (stripped == strip(arg.short_name) || stripped == strip(arg.name)) {
logFatal(1) << "invalid argument configuration. '" << arg.canonicalName() << "' is used twice";
fs::fatal() << "invalid argument configuration. '" << arg.canonicalName() << "' is used twice";
}
}

// make sure there are no illogical combinations of arguments with a variable number of inputs
if (!arg.fixed) {
if (arg.positional) {
if (variable_positional) {
logFatal(1) << "invalid argument configuration for '" << arg.canonicalName() << "'. "
fs::fatal() << "invalid argument configuration for '" << arg.canonicalName() << "'. "
<< "Two positional arguments cannot both have a variable amount of inputs, "
<< "as this could lead to an undefined boundary between the two";
}
Expand All @@ -402,7 +402,7 @@ void ArgumentParser::insertArgument(const ArgumentParser::Argument& arg)
variable_flag = true;
}
if (variable_positional && variable_flag) {
logFatal(1) << "invalid argument configuration for '" << arg.canonicalName() << "'. "
fs::fatal() << "invalid argument configuration for '" << arg.canonicalName() << "'. "
<< "A positional argument and flagged argument cannot both have a variable "
<< "amount of inputs, as this could lead to an undefined boundary between the two";
}
Expand All @@ -411,4 +411,4 @@ void ArgumentParser::insertArgument(const ArgumentParser::Argument& arg)
// add argument name to the index
if (!arg.short_name.empty()) index[arg.short_name] = N;
if (!arg.name.empty()) index[arg.name] = N;
}
}
6 changes: 3 additions & 3 deletions utils/mri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ extern int errno;
MRI::Shape::Shape(const std::vector<int>& shape) {
// validate dimensions
int dims = shape.size();
if ((dims != 3) && (dims != 4)) logFatal(1) << "volume must be 3D or 4D (provided shape has " << dims << " dimensions)";
if ((dims != 3) && (dims != 4)) fs::fatal() << "volume must be 3D or 4D (provided shape has " << dims << " dimensions)";

// validate size
for (auto const & len : shape) {
if (len <= 0) logFatal(1) << "volume size must be greater than 0 in every dimension";
if (len <= 0) fs::fatal() << "volume size must be greater than 0 in every dimension";
}

width = shape[0];
Expand Down Expand Up @@ -150,7 +150,7 @@ MRI::MRI(Shape volshape, int dtype, bool alloc) : shape(volshape), type(dtype)

// set data type
bytes_per_vox = MRIsizeof(type);
if (bytes_per_vox < 1) logFatal(1) << "unsupported MRI data type: " << type;
if (bytes_per_vox < 1) fs::fatal() << "unsupported MRI data type: " << type;
vox_per_row = width;
vox_per_slice = vox_per_row * height;
vox_per_vol = vox_per_slice * depth;
Expand Down

0 comments on commit 2e31025

Please sign in to comment.