Skip to content

Commit

Permalink
Tidyup/remove many usages of getName in algorithms.
Browse files Browse the repository at this point in the history
Use setProperty and workspace pointer for child algorithms and
getPropertyValue for other situations.
Refs #6187
  • Loading branch information
martyngigg committed Aug 6, 2013
1 parent f3a62bc commit 28e7156
Show file tree
Hide file tree
Showing 25 changed files with 55 additions and 76 deletions.
8 changes: 4 additions & 4 deletions Code/Mantid/Framework/API/src/Algorithm.cpp
Expand Up @@ -360,7 +360,7 @@ namespace Mantid
&& std::find(m_writeLockedWorkspaces.begin(), m_writeLockedWorkspaces.end(), ws) == m_writeLockedWorkspaces.end())
{
// Write-lock it if not already
g_log.debug() << "Write-locking " << ws->getName() << std::endl;
if(g_log.is(Logger::Priority::PRIO_DEBUG)) g_log.debug() << "Write-locking " << ws->name() << std::endl;
ws->getLock()->writeLock();
m_writeLockedWorkspaces.push_back(ws);
}
Expand All @@ -379,7 +379,7 @@ namespace Mantid
&& std::find(m_writeLockedWorkspaces.begin(), m_writeLockedWorkspaces.end(), ws) == m_writeLockedWorkspaces.end())
{
// Read-lock it if not already write-locked
g_log.debug() << "Read-locking " << ws->getName() << std::endl;
if(g_log.is(Logger::Priority::PRIO_DEBUG)) g_log.debug() << "Read-locking " << ws->name() << std::endl;
ws->getLock()->readLock();
m_readLockedWorkspaces.push_back(ws);
}
Expand All @@ -402,7 +402,7 @@ namespace Mantid
Workspace_sptr ws = m_writeLockedWorkspaces[i];
if (ws)
{
g_log.debug() << "Unlocking " << ws->getName() << std::endl;
if(g_log.is(Logger::Priority::PRIO_DEBUG)) g_log.debug() << "Unlocking " << ws->name() << std::endl;
ws->getLock()->unlock();
}
}
Expand All @@ -411,7 +411,7 @@ namespace Mantid
Workspace_sptr ws = m_readLockedWorkspaces[i];
if (ws)
{
g_log.debug() << "Unlocking " << ws->getName() << std::endl;
if(g_log.is(Logger::Priority::PRIO_DEBUG)) g_log.debug() << "Unlocking " << ws->name() << std::endl;
ws->getLock()->unlock();
}
}
Expand Down
14 changes: 0 additions & 14 deletions Code/Mantid/Framework/API/src/ITableWorkspace.cpp
Expand Up @@ -57,20 +57,6 @@ TableConstColumnHelper ITableWorkspace::getVector(const std::string& name) const
return TableConstColumnHelper(this,name);
}

/**
* If the workspace is the AnalysisDataService sends AfterReplaceNotification.
*/
void ITableWorkspace::modified()
{
if (!AnalysisDataService::Instance().doesExist(this->getName())) return;
Workspace_sptr ws = AnalysisDataService::Instance().retrieve(this->getName());
if (!ws) return;
ITableWorkspace_sptr tws = boost::dynamic_pointer_cast<ITableWorkspace>(ws);
if (!tws) return;
AnalysisDataService::Instance().notificationCenter.postNotification(
new Kernel::DataService<API::Workspace>::AfterReplaceNotification(this->getName(),tws));
}

/**
* Implement Workspace's virtual method to fill the info node with info
* descriding this table workspace.
Expand Down
1 change: 0 additions & 1 deletion Code/Mantid/Framework/Algorithms/src/AddPeak.cpp
Expand Up @@ -147,7 +147,6 @@ namespace Algorithms

peaksWS->addPeak(*peak);
delete peak;
//peaksWS->modified();
}


Expand Down
7 changes: 3 additions & 4 deletions Code/Mantid/Framework/Algorithms/src/FilterByTime2.cpp
Expand Up @@ -76,7 +76,7 @@ namespace Algorithms
}
else
{
g_log.debug() << "DB5244 InputWorkspace Name = " << inWS->getName() << std::endl;
g_log.debug() << "DB5244 InputWorkspace Name = " << this->getPropertyValue("InputWorkspace") << std::endl;
}

double starttime = this->getProperty("StartTime");
Expand Down Expand Up @@ -112,7 +112,7 @@ namespace Algorithms

API::Algorithm_sptr genfilter = createChildAlgorithm("GenerateEventsFilter", 0.0, 20.0, true, 1);
genfilter->initialize();
genfilter->setPropertyValue("InputWorkspace", inWS->getName());
genfilter->setProperty("InputWorkspace", inWS);
genfilter->setPropertyValue("OutputWorkspace", "FilterWS");
genfilter->setProperty("StartTime", start);
genfilter->setProperty("StopTime", stop);
Expand All @@ -132,7 +132,6 @@ namespace Algorithms
DataObjects::SplittersWorkspace_sptr filterWS = genfilter->getProperty("OutputWorkspace");
if (!filterWS)
{
g_log.error() << "Unable to retrieve generated SplittersWorkspace object from AnalysisDataService." << std::endl;
throw std::runtime_error("Unable to retrieve Splittersworkspace. ");
}
// AnalysisDataService::Instance().addOrReplace("FilterWS", filterWS);
Expand All @@ -142,7 +141,7 @@ namespace Algorithms

API::Algorithm_sptr filter = createChildAlgorithm("FilterEvents", 20.0, 100.0, true, 1);
filter->initialize();
filter->setPropertyValue("InputWorkspace", inWS->getName());
filter->setProperty("InputWorkspace", inWS);
filter->setPropertyValue("OutputWorkspaceBaseName", "ResultWS");
filter->setProperty("SplitterWorkspace", filterWS);
filter->setProperty("FilterByPulseTime", true);
Expand Down
Expand Up @@ -239,10 +239,11 @@ namespace Algorithms
// iii. percentage
Kernel::TimeSeriesProperty<double>* tlog = dynamic_cast<Kernel::TimeSeriesProperty<double>* >(
eventWS->run().getProperty(logname));
if (!tlog){
g_log.error() << "TimeSeriesProperty Log " << logname << " does not exist in workspace " <<
eventWS->getName() << std::endl;
throw std::invalid_argument("TimeSeriesProperty log cannot be found");
if (!tlog)
{
std::ostringstream msg;
msg << "TimeSeriesProperty Log " << logname << " does not exist in workspace " << eventWS->name() << std::endl;
throw std::invalid_argument(msg.str());
}

if (t0r < 0.0){
Expand Down Expand Up @@ -281,7 +282,6 @@ namespace Algorithms
this->processTimeLog(logname);
} else
{
g_log.error() << "Log name is not give!" << std::endl;
throw std::invalid_argument("Log name is not given!");
}

Expand All @@ -295,7 +295,6 @@ namespace Algorithms
filterEvents();

// 6. Set output
g_log.debug() << "Trying to set Output Workspace: " << outputWS->getName() << std::endl;
this->setProperty("OutputWorkspace", outputWS);
g_log.debug() << "Output Workspace is set!" << " Number of Events in Spectrum 0 = " << outputWS->getEventList(0).getNumberEvents() << std::endl;

Expand Down
Expand Up @@ -173,13 +173,11 @@ namespace Algorithms
{
std::stringstream errss;
errss << "GenerateEventsFilter does not get input workspace as an EventWorkspace.";
g_log.error(errss.str());
throw std::runtime_error(errss.str());
}
else
{
g_log.debug() << "DB9441 GenerateEventsFilter() Input Event WS = " << m_dataWS->getName()
<< ", Events = " << m_dataWS->getNumberEvents() << std::endl;
g_log.debug() << "DB9441 GenerateEventsFilter(), Events = " << m_dataWS->getNumberEvents() << std::endl;
}

Kernel::DateAndTime runstart = m_dataWS->run().startTime();
Expand Down
Expand Up @@ -115,8 +115,7 @@ namespace Algorithms
if (!log)
{
stringstream errmsg;
errmsg << "Property " << logname << " does not exit in sample of workspace " << m_dataWS->getName() << ".";
g_log.error(errmsg.str());
errmsg << "Log " << logname << " does not exist on input workspace";
throw std::invalid_argument(errmsg.str());
}
else
Expand All @@ -126,7 +125,6 @@ namespace Algorithms
{
stringstream errmsg;
errmsg << "Log " << logname << " is found, but is not a double type time series log";
g_log.error(errmsg.str());
throw std::invalid_argument(errmsg.str());
}
}
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Algorithms/src/IQTransform.cpp
Expand Up @@ -192,7 +192,7 @@ void IQTransform::subtractBackgroundValue(MantidVec& Y, const double value)
*/
API::MatrixWorkspace_sptr IQTransform::subtractBackgroundWS(API::MatrixWorkspace_sptr ws, API::MatrixWorkspace_sptr background)
{
g_log.debug() << "Subtracting the workspace " << background->getName() << " from the input workspace.\n";
if(g_log.is(Logger::Priority::PRIO_DEBUG)) g_log.debug() << "Subtracting the workspace " << background->name() << " from the input workspace.\n";
return ws - background;
}

Expand Down
2 changes: 0 additions & 2 deletions Code/Mantid/Framework/Algorithms/src/Integration.cpp
Expand Up @@ -262,8 +262,6 @@ MatrixWorkspace_const_sptr Integration::getInputWorkspace()
// inf's in order to treat the data correctly later.
IAlgorithm_sptr alg = this->createChildAlgorithm("ReplaceSpecialValues");
alg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", temp);
std::string outName = "_"+temp->getName()+"_clean";
alg->setProperty("OutputWorkspace", outName);
alg->setProperty("NaNValue", 0.0);
alg->setProperty("NaNError", 0.0);
alg->setProperty("InfinityValue", 0.0);
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Algorithms/src/Rebin.cpp
Expand Up @@ -183,7 +183,7 @@ namespace Mantid
else
{
//--------- Different output, OR you're inplace but not preserving Events --- create a Workspace2D -------
g_log.information() << "Creating a Workspace2D from the EventWorkspace " << eventInputWS->getName() << ".\n";
g_log.information() << "Creating a Workspace2D from the input EventWorkspace.\n";

//Create a Workspace2D
// This creates a new Workspace2D through a torturous route using the WorkspaceFactory.
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Algorithms/src/RenameWorkspace.cpp
Expand Up @@ -48,11 +48,11 @@ void RenameWorkspace::exec()
// Get the input workspace
Workspace_sptr inputWS = getProperty("InputWorkspace");
// get the workspace name
std::string inputwsName = inputWS->getName();
std::string inputwsName = getPropertyValue("InputWorkspace");
// get the output workspace name
std::string outputwsName = getPropertyValue("OutputWorkspace");

if (getPropertyValue("InputWorkspace") == getPropertyValue("OutputWorkspace"))
if (inputwsName == outputwsName)
{
throw std::invalid_argument("The input and output workspace names must be different");
}
Expand Down
3 changes: 1 addition & 2 deletions Code/Mantid/Framework/Crystal/src/MaskPeaksWorkspace.cpp
Expand Up @@ -172,8 +172,7 @@ namespace Mantid
// Mask bins
API::IAlgorithm_sptr maskbinstb = this->createChildAlgorithm("MaskBinsFromTable", 0.5, 1.0, true);
maskbinstb->initialize();
maskbinstb->setPropertyValue("InputWorkspace", inputW->getName());
maskbinstb->setPropertyValue("OutputWorkspace", inputW->getName());
maskbinstb->setProperty("InputWorkspace", inputW);
maskbinstb->setProperty("MaskingInformation", tablews);
maskbinstb->execute();

Expand Down
Expand Up @@ -124,7 +124,7 @@ FindDetectorsPar::exec()
return;
}else{
g_log.warning()<<" number of parameters in the file: "<<fileName<<" not equal to the number of histograms in the workspace"
<< inputWS->getName()<<std::endl;
<< this->getPropertyValue("InputWorkspace") <<std::endl;
g_log.warning()<<" calculating detector parameters algorithmically\n";
}

Expand Down
12 changes: 6 additions & 6 deletions Code/Mantid/Framework/DataHandling/src/Load.cpp
Expand Up @@ -428,7 +428,8 @@ namespace Mantid
for(; filenames != allFilenames.end(); ++filenames, ++wsName)
{
std::vector<std::string>::const_iterator filename = filenames->begin();
Workspace_sptr sumWS = loadFileToWs(*filename, *wsName);
const std::string & rootName = *wsName;
Workspace_sptr sumWS = loadFileToWs(*filename, rootName);

++filename;
for(; filename != filenames->end(); ++filename)
Expand All @@ -446,9 +447,8 @@ namespace Mantid
for( ; childWsName != childWsNames.end(); ++childWsName, ++count )
{
Workspace_sptr childWs = group->getItem(*childWsName);
const std::string childName = group->getName() + "_" + boost::lexical_cast<std::string>(count);
const std::string childName = rootName + "_" + boost::lexical_cast<std::string>(count);
API::AnalysisDataService::Instance().addOrReplace(childName, childWs);
//childWs->setName(group->getName() + "_" + boost::lexical_cast<std::string>(count));
}
}
// Add the sum to the list of loaded workspace names.
Expand All @@ -470,11 +470,11 @@ namespace Mantid
size_t count = 1;
for(auto childWsName = childWsNames.begin(); childWsName != childWsNames.end(); ++childWsName )
{
const std::string & childsName = *childWsName;
if( *childWsName == outputWsName )
{
Mantid::API::Workspace_sptr child = group->getItem(*childWsName);
//child->setName(child->getName() + "_" + boost::lexical_cast<std::string>(count));
const std::string childName = child->getName() + "_" + boost::lexical_cast<std::string>(count);
Mantid::API::Workspace_sptr child = group->getItem(childsName);
const std::string childName = childsName + "_" + boost::lexical_cast<std::string>(count);
API::AnalysisDataService::Instance().addOrReplace(childName, child);
count++;
}
Expand Down
20 changes: 10 additions & 10 deletions Code/Mantid/Framework/DataHandling/src/MergeLogs.cpp
Expand Up @@ -113,12 +113,8 @@ namespace DataHandling
bool launch1 = true;;
bool nocomparison = false;

std::cout << "Merging!!" << std::endl;

while (icont)
{
// std::cout << "index1 = " << index1 << ", index2 = " << index2 << ", launch1 = " << launch1 << ", nocomparison = " << nocomparison << std::endl;

// i. Determine which log to work on
if (!nocomparison){
if (times1[index1] < times2[index2]){
Expand Down Expand Up @@ -198,17 +194,21 @@ namespace DataHandling

// 1. Get property
Kernel::Property *prop = matrixWS->run().getLogData(logname);
if (!prop){
g_log.error() << "Unable to find log " << logname << " of workspace " << matrixWS->getName() << std::endl;
throw;
if (!prop)
{
std::ostringstream os;
os << "Unable to find log " << logname << " of workspace " << matrixWS->name() << std::endl;
throw std::invalid_argument(os.str());
}

// 2. Convert to TimeSeries

Kernel::TimeSeriesProperty<double> *timeprop = dynamic_cast<Kernel::TimeSeriesProperty<double>* >(prop);
if (!timeprop){
g_log.error() << "Property (log) " << logname << " is not of class TimeSeriesProperty!" << std::endl;
throw;
if (!timeprop)
{
std::ostringstream os;
os << "Property (log) " << logname << " is not of class TimeSeriesProperty!" << std::endl;
throw std::invalid_argument(os.str());
}

return timeprop;
Expand Down
5 changes: 3 additions & 2 deletions Code/Mantid/Framework/DataHandling/src/SaveNXSPE.cpp
Expand Up @@ -111,6 +111,7 @@ namespace Mantid

// Retrieve the input workspace
const MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace");
const std::string inputWSName = getPropertyValue("InputWorkspace");

// Do the full check for common binning
if (!WorkspaceHelpers::commonBoundaries(inputWS))
Expand All @@ -136,7 +137,7 @@ namespace Mantid
::NeXus::File nxFile(this->filename, NXACC_CREATE5);

// Make the top level entry (and open it)
nxFile.makeGroup(inputWS->getName(), "NXentry", true);
nxFile.makeGroup(inputWSName, "NXentry", true);

// Definition name and version
nxFile.writeData("definition", "NXSPE");
Expand Down Expand Up @@ -327,7 +328,7 @@ namespace Mantid
IAlgorithm_sptr spCalcDetPar = this->createChildAlgorithm("FindDetectorsPar", 0, 1, true, 1);

spCalcDetPar->initialize();
spCalcDetPar->setPropertyValue("InputWorkspace", inputWS->getName());
spCalcDetPar->setProperty("InputWorkspace", inputWS);
std::string parFileName = this->getPropertyValue("ParFile");
if(!(parFileName.empty()||parFileName=="not_used.par")){
spCalcDetPar->setPropertyValue("ParFile",parFileName);
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/SavePAR.cpp
Expand Up @@ -90,7 +90,7 @@ void SavePAR::exec() {
// execute the ChildAlgorithm to calculate the detector's parameters;
IAlgorithm_sptr spCalcDetPar = this->createChildAlgorithm("FindDetectorsPar", 0, 1, true, 1);
spCalcDetPar->initialize();
spCalcDetPar->setPropertyValue("InputWorkspace", inputWorkspace->getName());
spCalcDetPar->setProperty("InputWorkspace", inputWorkspace);
// calculate linear rather then angular detector's sizes;
spCalcDetPar->setPropertyValue("ReturnLinearRanges", "1");
// in test mode, request the ChildAlgortithm to create output workspace and add it to dataservice
Expand Down
3 changes: 1 addition & 2 deletions Code/Mantid/Framework/DataHandling/src/SavePHX.cpp
Expand Up @@ -82,15 +82,14 @@ void SavePHX::exec() {
std::ofstream outPHX_file(filename.c_str());

if (!outPHX_file) {
g_log.error("Failed to open (PHX) file:" + filename);
throw Kernel::Exception::FileError("Failed to open (PHX) file:",
filename);
}

// execute the ChildAlgorithm to calculate the detector's parameters;
IAlgorithm_sptr spCalcDetPar = this->createChildAlgorithm("FindDetectorsPar", 0, 1, true, 1);
spCalcDetPar->initialize();
spCalcDetPar->setPropertyValue("InputWorkspace", inputWorkspace->getName());
spCalcDetPar->setProperty("InputWorkspace", inputWorkspace);
spCalcDetPar->setPropertyValue("ReturnLinearRanges", "0");
// in test mode, request the ChildAlgortithm to create output workspace and add it to dataservice
if(!det_par_ws_name.empty()){
Expand Down
7 changes: 3 additions & 4 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMD.cpp
Expand Up @@ -675,11 +675,12 @@ DataObjects::TableWorkspace_const_sptr ConvertToMD::preprocessDetectorsPositions
DataObjects::TableWorkspace_sptr ConvertToMD::runPreprocessDetectorsToMDChildUpdatingMasks(Mantid::API::MatrixWorkspace_const_sptr InWS2D,
const std::string &OutWSName,const std::string &dEModeRequested,Kernel::DeltaEMode::Type &Emode)
{
UNUSED_ARG(OutWSName);
// prospective result
DataObjects::TableWorkspace_sptr TargTableWS;

// if input workspace does not exist in analysis data service, we have to add it there to work with the Child Algorithm
std::string InWSName = InWS2D->getName();
std::string InWSName = this->getPropertyValue("InputWorkspace");
if(!API::AnalysisDataService::Instance().doesExist(InWSName))
{
if(InWSName.empty())InWSName = "ImputMatrixWS";
Expand All @@ -690,11 +691,9 @@ DataObjects::TableWorkspace_sptr ConvertToMD::runPreprocessDetectorsToMDChildUp

Mantid::API::Algorithm_sptr childAlg = createChildAlgorithm("PreprocessDetectorsToMD",0.,1.);
if(!childAlg)throw(std::runtime_error("Can not create child ChildAlgorithm to preprocess detectors"));
childAlg->setProperty("InputWorkspace",InWSName);
childAlg->setProperty("OutputWorkspace",OutWSName);
childAlg->setProperty("InputWorkspace",InWS2D);
childAlg->setProperty("GetMaskState",true);
childAlg->setProperty("UpdateMasksInfo",true);
childAlg->setProperty("OutputWorkspace",OutWSName);

// check and get energy conversion mode to define additional ChildAlgorithm parameters
Emode = Kernel::DeltaEMode().fromString(dEModeRequested);
Expand Down
5 changes: 3 additions & 2 deletions Code/Mantid/Framework/MDAlgorithms/src/SlicingAlgorithm.cpp
Expand Up @@ -615,7 +615,7 @@ namespace MDAlgorithms
if (!m_inWS->getTransformToOriginal())
throw std::runtime_error("SlicingAlgorithm::createTransform(): Cannot propagate "
"a transformation. There is no transformation saved from "
+ m_inWS->getName() + " back to " + m_originalWS->getName() + ".");
+ m_inWS->name() + " back to " + m_originalWS->name() + ".");

// Fail if the MDHistoWorkspace was modified by binary operation
MDEvents::MDHistoWorkspace_sptr inHisto = boost::dynamic_pointer_cast<MDEvents::MDHistoWorkspace>(m_inWS);
Expand Down Expand Up @@ -643,7 +643,8 @@ namespace MDAlgorithms
}
}

g_log.notice() << "Performing " << this->name() << " on the original workspace, '" << m_originalWS->getName() << "'" << std::endl;
if(g_log.is(Logger::Priority::PRIO_DEBUG)) g_log.debug() << "Performing " << this->name() << " on the original workspace, '"
<< m_originalWS->name() << "'" << std::endl;
}

// Create the coordinate transformation
Expand Down

0 comments on commit 28e7156

Please sign in to comment.