本文整理汇总了C++中api::IAlgorithm_sptr::setPropertyValue方法的典型用法代码示例。如果您正苦于以下问题:C++ IAlgorithm_sptr::setPropertyValue方法的具体用法?C++ IAlgorithm_sptr::setPropertyValue怎么用?C++ IAlgorithm_sptr::setPropertyValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api::IAlgorithm_sptr
的用法示例。
在下文中一共展示了IAlgorithm_sptr::setPropertyValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exec
/**
* Execute the algorithm.
*/
void FitResolutionConvolvedModel::exec() {
API::IAlgorithm_sptr fit = createFittingAlgorithm();
fit->setPropertyValue("Function", createFunctionString());
fit->setProperty("InputWorkspace", getPropertyValue(INPUT_WS_NAME));
fit->setProperty("DomainType",
"Simple"); // Parallel not quite giving correct answers
fit->setProperty("Minimizer", "Levenberg-MarquardtMD");
const int maxIter = niterations();
fit->setProperty("MaxIterations", maxIter);
fit->setProperty("CreateOutput", true);
fit->setPropertyValue("Output", getPropertyValue(SIMULATED_NAME));
try {
fit->execute();
} catch (std::exception &exc) {
throw std::runtime_error(
std::string("FitResolutionConvolvedModel - Error running Fit: ") +
exc.what());
}
// Pass on the relevant properties
IMDEventWorkspace_sptr simulatedData = fit->getProperty("OutputWorkspace");
this->setProperty(SIMULATED_NAME, simulatedData);
if (this->existsProperty(OUTPUT_PARS)) {
ITableWorkspace_sptr outputPars = fit->getProperty("OutputParameters");
setProperty(OUTPUT_PARS, outputPars);
}
if (this->existsProperty(OUTPUTCOV_MATRIX)) {
ITableWorkspace_sptr covarianceMatrix =
fit->getProperty("OutputNormalisedCovarianceMatrix");
setProperty(OUTPUTCOV_MATRIX, covarianceMatrix);
}
}
示例2: doSortHKL
/** Perform SortHKL on the output workspaces
*
* @param ws :: any PeaksWorkspace
* @param runName :: string to put in statistics table
*/
void StatisticsOfPeaksWorkspace::doSortHKL(Mantid::API::Workspace_sptr ws,
std::string runName) {
std::string pointGroup = getPropertyValue("PointGroup");
std::string latticeCentering = getPropertyValue("LatticeCentering");
std::string wkspName = getPropertyValue("OutputWorkspace");
std::string tableName = getPropertyValue("StatisticsTable");
API::IAlgorithm_sptr statsAlg = createChildAlgorithm("SortHKL");
statsAlg->setProperty("InputWorkspace", ws);
statsAlg->setPropertyValue("OutputWorkspace", wkspName);
statsAlg->setPropertyValue("StatisticsTable", tableName);
statsAlg->setProperty("PointGroup", pointGroup);
statsAlg->setProperty("LatticeCentering", latticeCentering);
statsAlg->setProperty("RowName", runName);
if (runName.compare("Overall") != 0)
statsAlg->setProperty("Append", true);
statsAlg->executeAsChildAlg();
PeaksWorkspace_sptr statsWksp = statsAlg->getProperty("OutputWorkspace");
ITableWorkspace_sptr tablews = statsAlg->getProperty("StatisticsTable");
if (runName.compare("Overall") == 0)
setProperty("OutputWorkspace", statsWksp);
setProperty("StatisticsTable", tablews);
}
示例3: convertUnitsToDSpacing
/// Run ConvertUnits as a sub-algorithm to convert to dSpacing
MatrixWorkspace_sptr DiffractionFocussing::convertUnitsToDSpacing(const API::MatrixWorkspace_sptr& workspace)
{
const std::string CONVERSION_UNIT = "dSpacing";
Unit_const_sptr xUnit = workspace->getAxis(0)->unit();
g_log.information() << "Converting units from "<< xUnit->label() << " to " << CONVERSION_UNIT<<".\n";
API::IAlgorithm_sptr childAlg = createSubAlgorithm("ConvertUnits", 0.34, 0.66);
childAlg->setProperty("InputWorkspace", workspace);
childAlg->setPropertyValue("Target",CONVERSION_UNIT);
childAlg->executeAsSubAlg();
return childAlg->getProperty("OutputWorkspace");
}
示例4: createChildAlgorithm
void LoadNexusMonitors2::runLoadLogs(const std::string filename,
API::MatrixWorkspace_sptr localWorkspace) {
// do the actual work
API::IAlgorithm_sptr loadLogs = createChildAlgorithm("LoadNexusLogs");
// Now execute the Child Algorithm. Catch and log any error, but don't stop.
try {
g_log.information() << "Loading logs from NeXus file..." << std::endl;
loadLogs->setPropertyValue("Filename", filename);
loadLogs->setProperty<API::MatrixWorkspace_sptr>("Workspace",
localWorkspace);
loadLogs->execute();
} catch (...) {
g_log.error() << "Error while loading Logs from Nexus. Some sample logs "
"may be missing." << std::endl;
}
}
示例5: createChildAlgorithm
/** Run the Child Algorithm LoadInstrument (as for LoadRaw)
* @param inst_name :: The name written in the Nexus file
* @param localWorkspace :: The workspace to insert the instrument into
*/
void LoadSpice2D::runLoadInstrument(
const std::string &inst_name,
DataObjects::Workspace2D_sptr localWorkspace) {
API::IAlgorithm_sptr loadInst = createChildAlgorithm("LoadInstrument");
// Now execute the Child Algorithm. Catch and log any error, but don't stop.
try {
loadInst->setPropertyValue("InstrumentName", inst_name);
loadInst->setProperty<API::MatrixWorkspace_sptr>("Workspace",
localWorkspace);
loadInst->setProperty("RewriteSpectraMap",
Mantid::Kernel::OptionalBool(true));
loadInst->execute();
} catch (std::invalid_argument &) {
g_log.information("Invalid argument to LoadInstrument Child Algorithm");
} catch (std::runtime_error &) {
g_log.information(
"Unable to successfully run LoadInstrument Child Algorithm");
}
}
示例6: exec
//.........这里部分代码省略.........
progTracker.complete();
ANSTO::EventAssigner eventAssigner(
roi, HISTO_BINS_Y, period, shift, tofMinBoundary, tofMaxBoundary,
timeMinBoundary, timeMaxBoundary, eventVectors);
loadEvents(prog, "loading neutron events", tarFile, eventAssigner);
Kernel::cow_ptr<MantidVec> axis;
MantidVec &xRef = axis.access();
xRef.resize(2, 0.0);
xRef[0] = std::max(
0.0,
floor(eventCounter.tofMin())); // just to make sure the bins hold it all
xRef[1] = eventCounter.tofMax() + 1;
eventWS->setAllX(axis);
// count total number of masked bins
size_t maskedBins = 0;
for (size_t i = 0; i != roi.size(); i++)
if (!roi[i])
maskedBins++;
if (maskedBins > 0) {
// create list of masked bins
std::vector<size_t> maskIndexList(maskedBins);
size_t maskIndex = 0;
for (size_t i = 0; i != roi.size(); i++)
if (!roi[i])
maskIndexList[maskIndex++] = i;
API::IAlgorithm_sptr maskingAlg = createChildAlgorithm("MaskDetectors");
maskingAlg->setProperty("Workspace", eventWS);
maskingAlg->setProperty("WorkspaceIndexList", maskIndexList);
maskingAlg->executeAsChildAlg();
}
// set log values
API::LogManager &logManager = eventWS->mutableRun();
logManager.addProperty("filename", filename);
logManager.addProperty("att_pos", static_cast<int>(instrumentInfo.att_pos));
logManager.addProperty("frame_count",
static_cast<int>(eventCounter.numFrames()));
logManager.addProperty("period", period);
// currently beam monitor counts are not available, instead number of frames
// times period is used
logManager.addProperty(
"bm_counts", static_cast<double>(eventCounter.numFrames()) * period /
1.0e6); // static_cast<double>(instrumentInfo.bm_counts)
// currently
Kernel::time_duration duration =
boost::posix_time::microseconds(static_cast<boost::int64_t>(
static_cast<double>(eventCounter.numFrames()) * period));
Kernel::DateAndTime start_time("2000-01-01T00:00:00");
Kernel::DateAndTime end_time(start_time + duration);
logManager.addProperty("start_time", start_time.toISO8601String());
logManager.addProperty("end_time", end_time.toISO8601String());
std::string time_str = start_time.toISO8601String();
AddSinglePointTimeSeriesProperty(logManager, time_str, "L1_chopper_value",
instrumentInfo.L1_chopper_value);
AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_det_value",
instrumentInfo.L2_det_value);
AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtainl_value",
instrumentInfo.L2_curtainl_value);
AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtainr_value",
instrumentInfo.L2_curtainr_value);
AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtainu_value",
instrumentInfo.L2_curtainu_value);
AddSinglePointTimeSeriesProperty(logManager, time_str, "L2_curtaind_value",
instrumentInfo.L2_curtaind_value);
AddSinglePointTimeSeriesProperty(logManager, time_str, "D_det_value",
instrumentInfo.D_det_value);
AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtainl_value",
instrumentInfo.D_curtainl_value);
AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtainr_value",
instrumentInfo.D_curtainr_value);
AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtainu_value",
instrumentInfo.D_curtainu_value);
AddSinglePointTimeSeriesProperty(logManager, time_str, "D_curtaind_value",
instrumentInfo.D_curtaind_value);
AddSinglePointTimeSeriesProperty(logManager, time_str, "curtain_rotation",
10.0);
API::IAlgorithm_sptr loadInstrumentAlg =
createChildAlgorithm("LoadInstrument");
loadInstrumentAlg->setProperty("Workspace", eventWS);
loadInstrumentAlg->setPropertyValue("InstrumentName", "BILBY");
loadInstrumentAlg->setProperty("RewriteSpectraMap",
Mantid::Kernel::OptionalBool(false));
loadInstrumentAlg->executeAsChildAlg();
setProperty("OutputWorkspace", eventWS);
}
示例7: exec
//.........这里部分代码省略.........
continue;
}
if (data.i < 0 && data.indx.empty())
{
g_log.warning() << "Zero spectra selected for fitting in workspace " << wsNames[i].name << '\n';
continue;
}
int j,jend;
if (data.i >= 0)
{
j = data.i;
jend = j + 1;
}
else
{// no need to check data.indx.empty()
j = data.indx.front();
jend = data.indx.back() + 1;
}
dProg /= abs(jend - j);
for(;j < jend;++j)
{
// Find the log value: it is either a log-file value or simply the workspace number
double logValue;
if (logName.empty())
{
API::Axis* axis = data.ws->getAxis(1);
logValue = (*axis)(j);
}
else if (logName != "SourceName")
{
Kernel::Property* prop = data.ws->run().getLogData(logName);
if (!prop)
{
throw std::invalid_argument("Log value "+logName+" does not exist");
}
TimeSeriesProperty<double>* logp =
dynamic_cast<TimeSeriesProperty<double>*>(prop);
logValue = logp->lastValue();
}
std::string resFun = fun;
std::vector<double> errors;
double chi2;
try
{
// Fit the function
API::IAlgorithm_sptr fit = createSubAlgorithm("Fit");
fit->initialize();
fit->setProperty("InputWorkspace",data.ws);
//fit->setPropertyValue("InputWorkspace",data.ws->getName());
fit->setProperty("WorkspaceIndex",j);
fit->setPropertyValue("Function",fun);
fit->setPropertyValue("StartX",getPropertyValue("StartX"));
fit->setPropertyValue("EndX",getPropertyValue("EndX"));
fit->setPropertyValue("Minimizer",getPropertyValue("Minimizer"));
fit->setPropertyValue("CostFunction",getPropertyValue("CostFunction"));
fit->execute();
resFun = fit->getPropertyValue("Function");
errors = fit->getProperty("Errors");
chi2 = fit->getProperty("OutputChi2overDoF");
}
catch(...)
{
g_log.error("Error in Fit subalgorithm");
throw;
}
if (sequential)
{
fun = resFun;
}
// Extract the fitted parameters and put them into the result table
TableRow row = result->appendRow();
if (isDataName)
{
row << wsNames[i].name;
}
else
{
row << logValue;
}
ifun = FunctionFactory::Instance().createInitialized(resFun);
for(size_t iPar=0;iPar<ifun->nParams();++iPar)
{
row << ifun->getParameter(iPar) << errors[iPar];
}
row << chi2;
delete ifun;
Prog += dProg;
progress(Prog);
interruption_point();
} // for(;j < jend;++j)
}
}
示例8: getWorkspace
/** Get a workspace identified by an InputData structure.
* @param data :: InputData with name and either spec or i fields defined.
* @return InputData structure with the ws field set if everything was OK.
*/
PlotPeakByLogValue::InputData PlotPeakByLogValue::getWorkspace(const InputData& data)
{
InputData out(data);
if (API::AnalysisDataService::Instance().doesExist(data.name))
{
DataObjects::Workspace2D_sptr ws = boost::dynamic_pointer_cast<DataObjects::Workspace2D>(
API::AnalysisDataService::Instance().retrieve(data.name));
if (ws)
{
out.ws = ws;
}
else
{
return data;
}
}
else
{
std::ifstream fil(data.name.c_str());
if (!fil)
{
g_log.warning() << "File "<<data.name<<" does not exist\n";
return data;
}
fil.close();
std::string::size_type i = data.name.find_last_of('.');
if (i == std::string::npos)
{
g_log.warning() << "Cannot open file "<<data.name<<"\n";
return data;
}
std::string ext = data.name.substr(i);
try
{
API::IAlgorithm_sptr load = createSubAlgorithm("Load");
load->initialize();
load->setPropertyValue("FileName",data.name);
load->execute();
if (load->isExecuted())
{
API::Workspace_sptr rws = load->getProperty("OutputWorkspace");
if (rws)
{
DataObjects::Workspace2D_sptr ws = boost::dynamic_pointer_cast<DataObjects::Workspace2D>(rws);
if (ws)
{
out.ws = ws;
}
else
{
API::WorkspaceGroup_sptr gws = boost::dynamic_pointer_cast<API::WorkspaceGroup>(rws);
if (gws)
{
std::vector<std::string> wsNames = gws->getNames();
std::string propName = "OUTPUTWORKSPACE_" + boost::lexical_cast<std::string>(data.period);
if (load->existsProperty(propName))
{
Workspace_sptr rws1 = load->getProperty(propName);
out.ws = boost::dynamic_pointer_cast<DataObjects::Workspace2D>(rws1);
}
}
}
}
}
}
catch(std::exception& e)
{
g_log.error(e.what());
return data;
}
}
if (!out.ws) return data;
API::Axis* axis = out.ws->getAxis(1);
if (axis->isSpectra())
{// spectra axis
if (out.spec < 0)
{
if (out.i >= 0)
{
out.spec = axis->spectraNo(out.i);
}
else
{// i < 0 && spec < 0 => use start and end
for(size_t i=0;i<axis->length();++i)
{
double s = double(axis->spectraNo(i));
if (s >= out.start && s <= out.end)
{
out.indx.push_back(static_cast<int>(i));
}
}
}
}
else
//.........这里部分代码省略.........
示例9: exec
void MaskBinsFromTable::exec()
{
MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
DataObjects::TableWorkspace_sptr paramWS = getProperty("MaskingInformation");
// 1. Check input table workspace and column order
g_log.debug() << "Lines of parameters workspace = " << paramWS->rowCount() << std::endl;
bool colname_specx = false;
if (!paramWS)
{
throw std::invalid_argument("Input table workspace is not accepted.");
}
else
{
std::vector<std::string> colnames = paramWS->getColumnNames();
// check colum name order
if (colnames.size() < 3)
{
g_log.error() << "Input MaskingInformation table workspace has fewer than 3 columns. " << colnames.size()
<< " columns indeed" << std::endl;
throw std::invalid_argument("MaskingInformation (TableWorkspace) has too few columns.");
}
if (colnames[0].compare("XMin") == 0)
{
// 1. Style XMin, XMax, SpectraList. Check rest
if (colnames[1].compare("XMax") != 0 || colnames[2].compare("SpectraList") != 0)
{
g_log.error() << "INput MaskingInformation table workspace has wrong column order. " << std::endl;
throw std::invalid_argument("MaskingInformation (TableWorkspace) has too few columns.");
}
}
else if (colnames[0].compare("SpectraList") == 0)
{
// 2. Style SpectraList, XMin, XMax
colname_specx = true;
if (colnames[1].compare("XMin") != 0 || colnames[2].compare("XMax") != 0)
{
g_log.error() << "INput MaskingInformation table workspace has wrong column order. " << std::endl;
throw std::invalid_argument("MaskingInformation (TableWorkspace) has too few columns.");
}
}
else
{
g_log.error() << "INput MaskingInformation table workspace has wrong column order. " << std::endl;
throw std::invalid_argument("MaskingInformation (TableWorkspace) has too few columns.");
}
}
// 2. Loop over all rows
bool firstloop = true;
API::MatrixWorkspace_sptr outputws = this->getProperty("OutputWorkspace");
for (size_t ib = 0; ib < paramWS->rowCount(); ++ib)
{
API::TableRow therow = paramWS->getRow(ib);
double xmin, xmax;
std::string speclist;
if (colname_specx)
{
therow >> speclist >> xmin >> xmax;
}
else
{
therow >> xmin >> xmax >> speclist;
}
g_log.debug() << "Row " << ib << " XMin = " << xmin << " XMax = " << xmax << " SpectraList = " << speclist << std::endl;
API::IAlgorithm_sptr maskbins = this->createChildAlgorithm("MaskBins", 0, 0.3, true);
maskbins->initialize();
if (firstloop)
{
maskbins->setProperty("InputWorkspace", inputWS);
firstloop = false;
}
else
{
maskbins->setProperty("InputWorkspace", outputws);
}
maskbins->setProperty("OutputWorkspace", outputws);
maskbins->setPropertyValue("SpectraList", speclist);
maskbins->setProperty("XMin", xmin);
maskbins->setProperty("XMax", xmax);
bool isexec = maskbins->execute();
if (!isexec)
{
g_log.error() << "MaskBins() is not executed for row " << ib << std::endl;
throw std::runtime_error("MaskBins() is not executed");
}
outputws = maskbins->getProperty("OutputWorkspace");
if (!outputws)
{
g_log.error() << "OutputWorkspace is not retrieved for row " << ib << ". " << std::endl;
throw std::runtime_error("OutputWorkspace is not got from MaskBins");
}
}
示例10: exec
/// Execute the algorithm
void SassenaFFT::exec()
{
const std::string gwsName = this->getPropertyValue("InputWorkspace");
API::WorkspaceGroup_sptr gws = this->getProperty("InputWorkspace");
const std::string ftqReName = gwsName + "_fqt.Re";
const std::string ftqImName = gwsName + "_fqt.Im";
// Make sure the intermediate structure factor is there
if(!gws->contains(ftqReName) )
{
const std::string errMessg = "workspace "+gwsName+" does not contain an intermediate structure factor";
this->g_log.error(errMessg);
throw Kernel::Exception::NotFoundError("group workspace does not contain",ftqReName);
}
// Retrieve the real and imaginary parts of the intermediate scattering function
DataObjects::Workspace2D_sptr fqtRe = boost::dynamic_pointer_cast<DataObjects::Workspace2D>( gws->getItem( ftqReName ) );
DataObjects::Workspace2D_sptr fqtIm = boost::dynamic_pointer_cast<DataObjects::Workspace2D>( gws->getItem( ftqImName ) );
// Calculate the FFT for all spectra, retaining only the real part since F(q,-t) = F*(q,t)
int part=3; // extract the real part of the transform, assuming I(Q,t) is real
const std::string sqwName = gwsName + "_sqw";
API::IAlgorithm_sptr fft = this->createChildAlgorithm("ExtractFFTSpectrum");
fft->setProperty<DataObjects::Workspace2D_sptr>("InputWorkspace", fqtRe);
if( !this->getProperty("FFTonlyRealPart") )
{
part=0; // extract the real part of the transform, assuming I(Q,t) is complex
fft->setProperty<DataObjects::Workspace2D_sptr>("InputImagWorkspace", fqtIm);
}
fft->setPropertyValue("OutputWorkspace", sqwName );
fft->setProperty<int>("FFTPart",part); // extract the real part
fft->executeAsChildAlg();
API::MatrixWorkspace_sptr sqw0 = fft->getProperty("OutputWorkspace");
DataObjects::Workspace2D_sptr sqw = boost::dynamic_pointer_cast<DataObjects::Workspace2D>( sqw0 );
API::AnalysisDataService::Instance().addOrReplace( sqwName, sqw );
// Transform the X-axis to appropriate dimensions
// We assume the units of the intermediate scattering function are in picoseconds
// The resulting frequency unit is in mili-eV, thus use m_ps2meV
API::IAlgorithm_sptr scaleX = this->createChildAlgorithm("ScaleX");
scaleX->setProperty<DataObjects::Workspace2D_sptr>("InputWorkspace",sqw);
scaleX->setProperty<double>("Factor", m_ps2meV);
scaleX->setProperty<DataObjects::Workspace2D_sptr>("OutputWorkspace", sqw);
scaleX->executeAsChildAlg();
//Do we apply the detailed balance condition exp(E/(2*kT)) ?
if( this->getProperty("DetailedBalance") )
{
double T = this->getProperty("Temp");
// The ExponentialCorrection algorithm assumes the form C0*exp(-C1*x). Note the explicit minus in the exponent
API::IAlgorithm_sptr ec = this->createChildAlgorithm("ExponentialCorrection");
ec->setProperty<DataObjects::Workspace2D_sptr>("InputWorkspace", sqw);
ec->setProperty<DataObjects::Workspace2D_sptr>("OutputWorkspace", sqw);
ec->setProperty<double>("C0",1.0);
ec->setProperty<double>("C1",-1.0/(2.0*T*m_T2ueV)); // Temperature in units of ueV
ec->setPropertyValue("Operation","Multiply");
ec->executeAsChildAlg();
}
// Set the Energy unit for the X-axis
sqw->getAxis(0)->unit() = Kernel::UnitFactory::Instance().create("DeltaE");
// Add to group workspace, except if we are replacing the workspace. In this case, the group workspace
// is already notified of the changes by the analysis data service.
if(!gws->contains(sqwName))
{
gws->add( sqwName );
}
else
{
this->g_log.information("Workspace "+sqwName+" replaced with new contents");
}
}