Skip to content

Commit

Permalink
Re #11828. The rest of MantidPlot and some framework.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed May 27, 2015
1 parent 4738a2f commit fd819e1
Show file tree
Hide file tree
Showing 46 changed files with 573 additions and 377 deletions.
37 changes: 22 additions & 15 deletions Code/Mantid/Framework/API/src/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,27 +1305,34 @@ bool Algorithm::processGroups() {
outputBaseName += ws->name();

// Set the property using the name of that workspace
Property *prop = dynamic_cast<Property *>(m_inputWorkspaceProps[iwp]);
alg->setPropertyValue(prop->name(), ws->name());
if (Property *prop = dynamic_cast<Property *>(m_inputWorkspaceProps[iwp])) {
alg->setPropertyValue(prop->name(), ws->name());
} else {
throw std::logic_error(
"Found a Workspace property which doesn't inherit from Property.");
}
} // not an empty (i.e. optional) input
} // for each InputWorkspace property

std::vector<std::string> outputWSNames(m_pureOutputWorkspaceProps.size());
// ---------- Set all the output workspaces ----------------------------
for (size_t owp = 0; owp < m_pureOutputWorkspaceProps.size(); owp++) {
Property *prop =
dynamic_cast<Property *>(m_pureOutputWorkspaceProps[owp]);

// Default name = "in1_in2_out"
std::string outName = outputBaseName + "_" + prop->value();
// Except if all inputs had similar names, then the name is "out_1"
if (m_groupsHaveSimilarNames)
outName = prop->value() + "_" + Strings::toString(entry + 1);

// Set in the output
alg->setPropertyValue(prop->name(), outName);

outputWSNames[owp] = outName;
if (Property *prop =
dynamic_cast<Property *>(m_pureOutputWorkspaceProps[owp])) {
// Default name = "in1_in2_out"
std::string outName = outputBaseName + "_" + prop->value();
// Except if all inputs had similar names, then the name is "out_1"
if (m_groupsHaveSimilarNames)
outName = prop->value() + "_" + Strings::toString(entry + 1);

// Set in the output
alg->setPropertyValue(prop->name(), outName);

outputWSNames[owp] = outName;
} else {
throw std::logic_error(
"Found a Workspace property which doesn't inherit from Property.");
}
} // for each OutputWorkspace property

// ------------ Execute the algo --------------
Expand Down
15 changes: 9 additions & 6 deletions Code/Mantid/Framework/Algorithms/src/ApplyDetailedBalance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ void ApplyDetailedBalance::exec() {
std::string Tstring = getProperty("Temperature");
double Temp;
try {
if (inputWS->run().hasProperty(Tstring))
Temp = (dynamic_cast<Kernel::TimeSeriesProperty<double> *>(
inputWS->run().getProperty(Tstring)))
->getStatistics()
.mean;
else
if (inputWS->run().hasProperty(Tstring)) {
if (auto log = dynamic_cast<Kernel::TimeSeriesProperty<double> *>(
inputWS->run().getProperty(Tstring)) ) {
Temp = log->getStatistics().mean;
} else {
throw std::invalid_argument(Tstring + " is not a double-valued log.");
}
} else {
Temp = boost::lexical_cast<double>(Tstring);
}
} catch (...) {
Tstring += " is not a valid log, nor is it a number";
throw std::invalid_argument(Tstring);
Expand Down
8 changes: 7 additions & 1 deletion Code/Mantid/Framework/Algorithms/src/ConvertSpectrumAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,13 @@ double ConvertSpectrumAxis::getEfixed(IDetector_const_sptr detector,
Kernel::Property *p = inputWS->run().getProperty("Ei");
Kernel::PropertyWithValue<double> *doublep =
dynamic_cast<Kernel::PropertyWithValue<double> *>(p);
efixed = (*doublep)();
if (doublep) {
efixed = (*doublep)();
} else {
efixed = 0.0;
g_log.warning() << "Efixed could not be found for detector "
<< detector->getID() << ", set to 0.0\n";
}
} else {
efixed = 0.0;
g_log.warning() << "Efixed could not be found for detector "
Expand Down
56 changes: 34 additions & 22 deletions Code/Mantid/Framework/Algorithms/src/EQSANSTofStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,23 @@ void EQSANSTofStructure::exec() {
high_tof_cut = getProperty("HighTOFCut");

// Calculate the frame width
double frequency = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData("frequency"))
->getStatistics()
.mean;
auto frequencyLog = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData("frequency"));
if (!frequencyLog) {
throw std::runtime_error("Frequency log not found.");
}
double frequency = frequencyLog->getStatistics().mean;
double tof_frame_width = 1.0e6 / frequency;

// Determine whether we need frame skipping or not by checking the chopper
// speed
bool frame_skipping = false;
const double chopper_speed = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData("Speed1"))
->getStatistics()
.mean;
auto chopper_speedLog = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData("Speed1"));
if (!chopper_speedLog) {
throw std::runtime_error("Chopper speed log not found.");
}
const double chopper_speed = chopper_speedLog->getStatistics().mean;
if (std::fabs(chopper_speed - frequency / 2.0) < 1.0)
frame_skipping = true;

Expand Down Expand Up @@ -114,8 +118,10 @@ EQSANSTofStructure::execEvent(Mantid::DataObjects::EventWorkspace_sptr inputWS,
// Get the nominal sample-to-detector distance (in mm)
Mantid::Kernel::Property *prop =
inputWS->run().getProperty("sample_detector_distance");
Mantid::Kernel::PropertyWithValue<double> *dp =
dynamic_cast<Mantid::Kernel::PropertyWithValue<double> *>(prop);
auto dp = dynamic_cast<Mantid::Kernel::PropertyWithValue<double> *>(prop);
if (!dp) {
throw std::runtime_error("sample_detector_distance log not found.");
}
const double SDD = *dp / 1000.0;

// Loop through the spectra and apply correction
Expand Down Expand Up @@ -204,10 +210,12 @@ double EQSANSTofStructure::getTofOffset(EventWorkspace_const_sptr inputWS,
double chopper_frameskip_srcpulse_wl_1[4] = {0, 0, 0, 0};

// Calculate the frame width
double frequency = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData("frequency"))
->getStatistics()
.mean;
auto frequencyLog = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData("frequency"));
if (!frequencyLog) {
throw std::runtime_error("Frequency log not found.");
}
double frequency = frequencyLog->getStatistics().mean;
double tof_frame_width = 1.0e6 / frequency;

double tmp_frame_width = tof_frame_width;
Expand All @@ -229,16 +237,20 @@ double EQSANSTofStructure::getTofOffset(EventWorkspace_const_sptr inputWS,
// Read chopper information
std::ostringstream phase_str;
phase_str << "Phase" << i + 1;
chopper_set_phase[i] = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData(phase_str.str()))
->getStatistics()
.mean;
auto log = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData(phase_str.str()));
if (!log) {
throw std::runtime_error("Phase log not found.");
}
chopper_set_phase[i] = log->getStatistics().mean;
std::ostringstream speed_str;
speed_str << "Speed" << i + 1;
chopper_speed[i] = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData(speed_str.str()))
->getStatistics()
.mean;
log = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData(speed_str.str()));
if (!log) {
throw std::runtime_error("Speed log not found.");
}
chopper_speed[i] = log->getStatistics().mean;

// Only process choppers with non-zero speed
if (chopper_speed[i] <= 0)
Expand Down
4 changes: 4 additions & 0 deletions Code/Mantid/Framework/Algorithms/src/FilterBadPulses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ void FilterBadPulses::exec() {
Kernel::TimeSeriesProperty<double> *pcharge_log =
dynamic_cast<Kernel::TimeSeriesProperty<double> *>(
runlogs.getLogData(LOG_CHARGE_NAME));
if (!pcharge_log) {
throw std::logic_error("Failed to find \"" + LOG_CHARGE_NAME +
"\" in sample logs");
}
Kernel::TimeSeriesPropertyStatistics stats = pcharge_log->getStatistics();

// check that the maximum value is greater than zero
Expand Down
6 changes: 5 additions & 1 deletion Code/Mantid/Framework/Algorithms/src/NormaliseByCurrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ double NormaliseByCurrent::extractCharge(
Property *chargeProperty = run.getLogData("proton_charge_by_period");
ArrayProperty<double> *chargePropertyArray =
dynamic_cast<ArrayProperty<double> *>(chargeProperty);
charge = chargePropertyArray->operator()()[periodNumber - 1];
if (chargePropertyArray) {
charge = chargePropertyArray->operator()()[periodNumber - 1];
} else {
throw std::runtime_error("Proton charge log not found.");
}
} else {
try {
charge = inputWS->run().getProtonCharge();
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/MDAlgorithms/src/MergeMDFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ void MergeMDFiles::exec() {
// pDiskBuffer = NULL;
MultipleFileProperty *multiFileProp =
dynamic_cast<MultipleFileProperty *>(getPointerToProperty("Filenames"));
if (!multiFileProp) {
throw std::logic_error("Filenames property must have MultipleFileProperty type.");
}
m_Filenames =
MultipleFileProperty::flattenFileNames(multiFileProp->operator()());
if (m_Filenames.size() == 0)
Expand Down
4 changes: 4 additions & 0 deletions Code/Mantid/Framework/MDAlgorithms/src/WeightedMeanMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ void WeightedMeanMD::execHistoHisto(
MDHistoWorkspaceIterator *rhs_it =
dynamic_cast<MDHistoWorkspaceIterator *>(operand->createIterator());

if (!lhs_it || !rhs_it) {
throw std::logic_error("Histo iterators have wrong type.");
}

do {
double lhs_s = lhs_it->getSignal();
double lhs_err = lhs_it->getError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,15 @@ void EQSANSDarkCurrentSubtraction::exec() {
// Normalize the dark current and data to counting time
double scaling_factor = 1.0;
if (inputWS->run().hasProperty("proton_charge")) {
Mantid::Kernel::Property *prop =
inputWS->run().getProperty("proton_charge");
Mantid::Kernel::TimeSeriesProperty<double> *dp =
dynamic_cast<Mantid::Kernel::TimeSeriesProperty<double> *>(prop);
auto dp = inputWS->run().getTimeSeriesProperty<double>("proton_charge");
double duration = dp->getStatistics().duration;

prop = darkWS->run().getProperty("proton_charge");
dp = dynamic_cast<Mantid::Kernel::TimeSeriesProperty<double> *>(prop);
dp = darkWS->run().getTimeSeriesProperty<double>("proton_charge");
double dark_duration = dp->getStatistics().duration;
scaling_factor = duration / dark_duration;
} else if (inputWS->run().hasProperty("timer")) {
Mantid::Kernel::Property *prop = inputWS->run().getProperty("timer");
Mantid::Kernel::PropertyWithValue<double> *dp =
dynamic_cast<Mantid::Kernel::PropertyWithValue<double> *>(prop);
double duration = *dp;

prop = darkWS->run().getProperty("timer");
dp = dynamic_cast<Mantid::Kernel::PropertyWithValue<double> *>(prop);
double dark_duration = *dp;
double duration = inputWS->run().getPropertyValueAsType<double>("timer");
double dark_duration = darkWS->run().getPropertyValueAsType<double>("timer");;
scaling_factor = duration / dark_duration;
} else {
output_message +=
Expand Down
5 changes: 1 addition & 4 deletions Code/Mantid/Framework/WorkflowAlgorithms/src/EQSANSLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,7 @@ void EQSANSLoad::exec() {
int run_number = 0;
std::string config_file = "";
if (dataWS->run().hasProperty("run_number")) {
Mantid::Kernel::Property *prop = dataWS->run().getProperty("run_number");
Mantid::Kernel::PropertyWithValue<std::string> *dp =
dynamic_cast<Mantid::Kernel::PropertyWithValue<std::string> *>(prop);
const std::string run_str = *dp;
const std::string run_str = dataWS->run().getPropertyValueAsType<std::string>("run_number");
Poco::NumberParser::tryParse(run_str, run_number);
// Find a proper config file
config_file = findConfigFile(run_number);
Expand Down
30 changes: 10 additions & 20 deletions Code/Mantid/Framework/WorkflowAlgorithms/src/EQSANSMonitorTOF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,15 @@ void EQSANSMonitorTOF::exec() {
double source_to_monitor = (monitor_z - source_z) * 1000.0;

// Calculate the frame width
double frequency = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData("frequency"))
->getStatistics()
.mean;
auto log = inputWS->run().getTimeSeriesProperty<double>("frequency");
double frequency = log->getStatistics().mean;
double tof_frame_width = 1.0e6 / frequency;

// Determine whether we need frame skipping or not by checking the chopper
// speed
bool frame_skipping = false;
const double chopper_speed = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData("Speed1"))
->getStatistics()
.mean;
log = inputWS->run().getTimeSeriesProperty<double>("Speed1");
const double chopper_speed = log->getStatistics().mean;
if (std::fabs(chopper_speed - frequency / 2.0) < 1.0)
frame_skipping = true;

Expand Down Expand Up @@ -211,10 +207,8 @@ double EQSANSMonitorTOF::getTofOffset(MatrixWorkspace_const_sptr inputWS,
double chopper_frameskip_srcpulse_wl_1[4] = {0, 0, 0, 0};

// Calculate the frame width
double frequency = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData("frequency"))
->getStatistics()
.mean;
auto log = inputWS->run().getTimeSeriesProperty<double>("frequency");
double frequency = log->getStatistics().mean;
double tof_frame_width = 1.0e6 / frequency;

double tmp_frame_width = tof_frame_width;
Expand All @@ -236,16 +230,12 @@ double EQSANSMonitorTOF::getTofOffset(MatrixWorkspace_const_sptr inputWS,
// Read chopper information
std::ostringstream phase_str;
phase_str << "Phase" << i + 1;
chopper_set_phase[i] = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData(phase_str.str()))
->getStatistics()
.mean;
log = inputWS->run().getTimeSeriesProperty<double>(phase_str.str());
chopper_set_phase[i] = log->getStatistics().mean;
std::ostringstream speed_str;
speed_str << "Speed" << i + 1;
chopper_speed[i] = dynamic_cast<TimeSeriesProperty<double> *>(
inputWS->run().getLogData(speed_str.str()))
->getStatistics()
.mean;
log = inputWS->run().getTimeSeriesProperty<double>(speed_str.str());
chopper_speed[i] = log->getStatistics().mean;

// Only process choppers with non-zero speed
if (chopper_speed[i] <= 0)
Expand Down
5 changes: 1 addition & 4 deletions Code/Mantid/Framework/WorkflowAlgorithms/src/EQSANSQ2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ void EQSANSQ2D::init() {
/// @param inputWS :: input workspace
/// @param pname :: name of the property to retrieve
double getRunProperty(MatrixWorkspace_sptr inputWS, const std::string &pname) {
Mantid::Kernel::Property *prop = inputWS->run().getProperty(pname);
Mantid::Kernel::PropertyWithValue<double> *dp =
dynamic_cast<Mantid::Kernel::PropertyWithValue<double> *>(prop);
return *dp;
return inputWS->run().getPropertyValueAsType<double>(pname);
}

/// Execute algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ double
HFIRDarkCurrentSubtraction::getCountingTime(MatrixWorkspace_sptr inputWS) {
// First, look whether we have the information in the log
if (inputWS->run().hasProperty("timer")) {
Mantid::Kernel::Property *prop = inputWS->run().getProperty("timer");
Mantid::Kernel::PropertyWithValue<double> *dp =
dynamic_cast<Mantid::Kernel::PropertyWithValue<double> *>(prop);
return *dp;
return inputWS->run().getPropertyValueAsType<double>("timer");
} else {
// If we don't have the information in the log, use the default timer
// spectrum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ void getDefaultBeamCenter(API::MatrixWorkspace_sptr dataWS, double &pixel_x,
}

double getSourceToSampleDistance(API::MatrixWorkspace_sptr dataWS) {
Mantid::Kernel::Property *prop =
dataWS->run().getProperty("number-of-guides");
Mantid::Kernel::PropertyWithValue<int> *dp =
dynamic_cast<Mantid::Kernel::PropertyWithValue<int> *>(prop);
const int nguides = *dp;
const int nguides = dataWS->run().getPropertyValueAsType<int>("number-of-guides");

std::vector<std::string> pars =
dataWS->getInstrument()->getStringParameter("aperture-distances");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ void HFIRSANSNormalise::exec() {

// Get the monitor or timer
boost::algorithm::to_lower(normalisation);
Mantid::Kernel::Property *prop = inputWS->run().getProperty(normalisation);
Mantid::Kernel::PropertyWithValue<double> *dp =
dynamic_cast<Mantid::Kernel::PropertyWithValue<double> *>(prop);
double norm_count = *dp;
double norm_count = inputWS->run().getPropertyValueAsType<double>(normalisation);

double factor;
if (boost::iequals(normalisation, "monitor")) {
Expand Down

0 comments on commit fd819e1

Please sign in to comment.