本文整理汇总了C++中IAlgorithm_sptr::executeAsChildAlg方法的典型用法代码示例。如果您正苦于以下问题:C++ IAlgorithm_sptr::executeAsChildAlg方法的具体用法?C++ IAlgorithm_sptr::executeAsChildAlg怎么用?C++ IAlgorithm_sptr::executeAsChildAlg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAlgorithm_sptr
的用法示例。
在下文中一共展示了IAlgorithm_sptr::executeAsChildAlg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: advanceProgress
/**
* Integrate each spectra to get the number of counts
* @param inputWS :: The workspace to integrate
* @param indexMin :: The lower bound of the spectra to integrate
* @param indexMax :: The upper bound of the spectra to integrate
* @param lower :: The lower bound
* @param upper :: The upper bound
* @param outputWorkspace2D :: set to true to output a workspace 2D even if the input is an EventWorkspace
* @returns A workspace containing the integrated counts
*/
MatrixWorkspace_sptr
DetectorDiagnostic::integrateSpectra(MatrixWorkspace_sptr inputWS,
const int indexMin, const int indexMax, const double lower, const double upper,
const bool outputWorkspace2D)
{
g_log.debug() << "Integrating input spectra.\n";
// If the input spectra only has one bin, assume it has been integrated already
// but we need to pass it to the algorithm so that a copy of the input workspace is
// actually created to use for further calculations
// get percentage completed estimates for now, t0 and when we've finished t1
double t0 = m_fracDone, t1 = advanceProgress(RTGetTotalCounts);
IAlgorithm_sptr childAlg = createChildAlgorithm("Integration", t0, t1 );
childAlg->setProperty( "InputWorkspace", inputWS );
childAlg->setProperty( "StartWorkspaceIndex", indexMin );
childAlg->setProperty( "EndWorkspaceIndex", indexMax );
// pass inputed values straight to this integration trusting the checking done there
childAlg->setProperty("RangeLower", lower );
childAlg->setProperty("RangeUpper", upper);
childAlg->setPropertyValue("IncludePartialBins", "1");
childAlg->executeAsChildAlg();
// Convert to 2D if desired, and if the input was an EventWorkspace.
MatrixWorkspace_sptr outputW = childAlg->getProperty("OutputWorkspace");
MatrixWorkspace_sptr finalOutputW = outputW;
if (outputWorkspace2D && boost::dynamic_pointer_cast<EventWorkspace>(outputW))
{
g_log.debug() << "Converting output Event Workspace into a Workspace2D." << std::endl;
childAlg = createChildAlgorithm("ConvertToMatrixWorkspace", t0, t1 );
childAlg->setProperty("InputWorkspace", outputW);
childAlg->executeAsChildAlg();
finalOutputW = childAlg->getProperty("OutputWorkspace");
}
return finalOutputW;
}
示例2: normaliseByIntegratedCount
/** Carries out a normalisation based on the integrated count of the monitor over a range
* @param inputWorkspace The input workspace
* @param outputWorkspace The result workspace
*/
void NormaliseToMonitor::normaliseByIntegratedCount(API::MatrixWorkspace_sptr inputWorkspace,
API::MatrixWorkspace_sptr& outputWorkspace)
{
// Add up all the bins so it's just effectively a single value with an error
IAlgorithm_sptr integrate = createChildAlgorithm("Integration");
integrate->setProperty<MatrixWorkspace_sptr>("InputWorkspace", m_monitor);
integrate->setProperty("RangeLower",m_integrationMin);
integrate->setProperty("RangeUpper",m_integrationMax);
integrate->setProperty<bool>("IncludePartialBins",getProperty("IncludePartialBins"));
integrate->executeAsChildAlg();
// Get back the result
m_monitor = integrate->getProperty("OutputWorkspace");
// Run the divide algorithm explicitly to enable progress reporting
IAlgorithm_sptr divide = createChildAlgorithm("Divide",0.0,1.0);
divide->setProperty<MatrixWorkspace_sptr>("LHSWorkspace", inputWorkspace);
divide->setProperty<MatrixWorkspace_sptr>("RHSWorkspace", m_monitor);
divide->setProperty<MatrixWorkspace_sptr>("OutputWorkspace", outputWorkspace);
divide->executeAsChildAlg();
// Get back the result
outputWorkspace = divide->getProperty("OutputWorkspace");
}
示例3: runMaskDetectors
/** Runs MaskDetectors as a child algorithm on the input workspace.
* @param inputWS The input workspace
* @param maskWS A masking workspace
*/
void StepScan::runMaskDetectors(MatrixWorkspace_sptr inputWS,
MatrixWorkspace_sptr maskWS) {
IAlgorithm_sptr maskingAlg = createChildAlgorithm("MaskDetectors");
maskingAlg->setProperty<MatrixWorkspace_sptr>("Workspace", inputWS);
maskingAlg->setProperty<MatrixWorkspace_sptr>("MaskedWorkspace", maskWS);
maskingAlg->executeAsChildAlg();
}
示例4: loadReference
/**
* It's assumed that both the flux reference files are simple Nexus
* files since they have to produced by hand by the instrument
* scientists. A simple Load algorithm should suffice.
*/
MatrixWorkspace_sptr SANSBeamFluxCorrection::loadReference() {
const std::string referenceFluxFile =
getPropertyValue("ReferenceFluxFilename");
Poco::Path path(referenceFluxFile);
const std::string entryName = "SANSBeamFluxCorrection_" + path.getBaseName();
std::string fluxRefWSName = "__beam_flux_reference_" + path.getBaseName();
// Load reference flux as needed
MatrixWorkspace_sptr fluxRefWS;
if (m_reductionManager->existsProperty(entryName)) {
fluxRefWS = m_reductionManager->getProperty(entryName);
fluxRefWSName = m_reductionManager->getPropertyValue(entryName);
m_output_message += " | Using flux reference " + referenceFluxFile + "\n";
} else {
IAlgorithm_sptr loadAlg = createChildAlgorithm("Load");
loadAlg->setProperty("Filename", referenceFluxFile);
loadAlg->executeAsChildAlg();
Workspace_sptr tmpWS = loadAlg->getProperty("OutputWorkspace");
fluxRefWS = boost::dynamic_pointer_cast<MatrixWorkspace>(tmpWS);
m_output_message +=
" | Loaded flux reference " + referenceFluxFile + "\n";
// Keep the reference data for later use
AnalysisDataService::Instance().addOrReplace(fluxRefWSName, fluxRefWS);
m_reductionManager->declareProperty(
new WorkspaceProperty<>(entryName, fluxRefWSName, Direction::InOut));
m_reductionManager->setPropertyValue(entryName, fluxRefWSName);
m_reductionManager->setProperty(entryName, fluxRefWS);
}
return fluxRefWS;
}
示例5: runtime_error
/** Uses Polynomial as a ChildAlgorithm to fit the log of the exponential curve
* expected for the transmission.
* @param[in] WS The single-spectrum workspace to fit
* @param[in] order The order of the polynomial from 2 to 6
* @param[out] coeficients of the polynomial. c[0] + c[1]x + c[2]x^2 + ...
*/
API::MatrixWorkspace_sptr
CalculateTransmission::fitPolynomial(API::MatrixWorkspace_sptr WS, int order,
std::vector<double> &coeficients) {
g_log.notice("Fitting the experimental transmission curve fitpolyno");
double start = m_done;
IAlgorithm_sptr childAlg = createChildAlgorithm("Fit", start, m_done = 0.9);
auto polyfit = API::FunctionFactory::Instance().createFunction("Polynomial");
polyfit->setAttributeValue("n", order);
polyfit->initialize();
childAlg->setProperty("Function", polyfit);
childAlg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", WS);
childAlg->setProperty("Minimizer", "Levenberg-MarquardtMD");
childAlg->setProperty("CreateOutput", true);
childAlg->setProperty("IgnoreInvalidData", true);
childAlg->executeAsChildAlg();
std::string fitStatus = childAlg->getProperty("OutputStatus");
if (fitStatus != "success") {
g_log.error("Unable to successfully fit the data: " + fitStatus);
throw std::runtime_error("Unable to successfully fit the data");
}
// Only get to here if successful
coeficients.resize(order + 1);
for (int i = 0; i <= order; i++) {
coeficients[i] = polyfit->getParameter(i);
}
return this->extractSpectra(childAlg->getProperty("OutputWorkspace"),
std::vector<size_t>(1, 1));
}
示例6: getInputWorkspace
/**
* This function gets the input workspace. In the case for a RebinnedOutput
* workspace, it must be cleaned before proceeding. Other workspaces are
* untouched.
* @return the input workspace, cleaned if necessary
*/
MatrixWorkspace_sptr Integration::getInputWorkspace() {
MatrixWorkspace_sptr temp = getProperty("InputWorkspace");
if (temp->id() == "RebinnedOutput") {
// Clean the input workspace in the RebinnedOutput case for nan's and
// 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);
alg->setProperty("InfinityError", 0.0);
alg->executeAsChildAlg();
temp = alg->getProperty("OutputWorkspace");
}
// To integrate point data it will be converted to histograms
if (!temp->isHistogramData()) {
auto alg = this->createChildAlgorithm("ConvertToHistogram");
alg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", temp);
std::string outName = "_" + temp->getName() + "_histogram";
alg->setProperty("OutputWorkspace", outName);
alg->executeAsChildAlg();
temp = alg->getProperty("OutputWorkspace");
temp->setDistribution(true);
}
return temp;
}
示例7: exec
/** Execute the algorithm.
*/
void ConvertDiffCal::exec() {
OffsetsWorkspace_const_sptr offsetsWS = getProperty("OffsetsWorkspace");
// initial setup of new style config
ITableWorkspace_sptr configWksp = boost::make_shared<TableWorkspace>();
configWksp->addColumn("int", "detid");
configWksp->addColumn("double", "difc");
configWksp->addColumn("double", "difa");
configWksp->addColumn("double", "tzero");
// create values in the table
const size_t numberOfSpectra = offsetsWS->getNumberHistograms();
Progress progress(this, 0.0, 1.0, numberOfSpectra);
for (size_t i = 0; i < numberOfSpectra; ++i) {
API::TableRow newrow = configWksp->appendRow();
newrow << static_cast<int>(getDetID(offsetsWS, i));
newrow << calculateDIFC(offsetsWS, i);
newrow << 0.; // difa
newrow << 0.; // tzero
progress.report();
}
// sort the results
IAlgorithm_sptr sortTable = createChildAlgorithm("SortTableWorkspace");
sortTable->setProperty("InputWorkspace", configWksp);
sortTable->setProperty("OutputWorkspace", configWksp);
sortTable->setPropertyValue("Columns", "detid");
sortTable->executeAsChildAlg();
// copy over the results
configWksp = sortTable->getProperty("OutputWorkspace");
setProperty("OutputWorkspace", configWksp);
}
示例8: exec
/** Executes the algorithm
*
* @throw Exception::FileError If the grouping file cannot be opened or read
*successfully
*/
void GetDetOffsetsMultiPeaks::exec() {
// Process input information
processProperties();
// Create information workspaces
createInformationWorkspaces();
// Calculate offset of each detector
calculateDetectorsOffsets();
// Return the output
setProperty("OutputWorkspace", m_outputW);
setProperty("NumberPeaksWorkspace", m_outputNP);
setProperty("MaskWorkspace", m_maskWS);
setProperty("FittedResolutionWorkspace", m_resolutionWS);
setProperty("SpectraFitInfoTableWorkspace", m_infoTableWS);
setProperty("PeaksOffsetTableWorkspace", m_peakOffsetTableWS);
// Also save to .cal file, if requested
std::string filename = getProperty("GroupingFileName");
if (!filename.empty()) {
progress(0.9, "Saving .cal file");
IAlgorithm_sptr childAlg = createChildAlgorithm("SaveCalFile");
childAlg->setProperty("OffsetsWorkspace", m_outputW);
childAlg->setProperty("MaskWorkspace", m_maskWS);
childAlg->setPropertyValue("Filename", filename);
childAlg->executeAsChildAlg();
}
// Make summary
progress(0.92, "Making summary");
makeFitSummary();
return;
}
示例9: extractMonitorSpectrum
/** Pulls the monitor spectrum out of a larger workspace
* @param WS :: The workspace containing the spectrum to extract
* @param index :: The index of the spectrum to extract
* @returns A workspace containing the single spectrum requested
*/
API::MatrixWorkspace_sptr NormaliseToMonitor::extractMonitorSpectrum(API::MatrixWorkspace_sptr WS, const std::size_t index)
{
IAlgorithm_sptr childAlg = createChildAlgorithm("ExtractSingleSpectrum");
childAlg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", WS);
childAlg->setProperty<int>("WorkspaceIndex", static_cast<int>(index));
childAlg->executeAsChildAlg();
MatrixWorkspace_sptr outWS = childAlg->getProperty("OutputWorkspace");
IAlgorithm_sptr alg = createChildAlgorithm("ConvertToMatrixWorkspace");
alg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", outWS);
alg->executeAsChildAlg();
outWS = alg->getProperty("OutputWorkspace");
// Only get to here if successful
return outWS;
}
示例10: runLoadNexusLogs
/** Load the logs from the input NeXus file.
*
* @param nexusFileName :: Name of the NeXus file to load logs from.
* @param localWorkspace :: MatrixWorkspace in which to put the logs.
* @param alg :: Handle of an algorithm for logging access.
* @return true if successful.
*/
bool AppendGeometryToSNSNexus::runLoadNexusLogs(
const std::string &nexusFileName, API::MatrixWorkspace_sptr localWorkspace,
Algorithm *alg) {
IAlgorithm_sptr loadLogs =
alg->createChildAlgorithm("LoadNexusLogs", 0, 1, true);
// Execute the Child Algorithm, catching errors without stopping.
bool executionSuccessful(true);
try {
alg->getLogger().information() << "Loading logs from the NeXus file..."
<< std::endl;
loadLogs->setPropertyValue("Filename", nexusFileName);
loadLogs->setProperty<MatrixWorkspace_sptr>("Workspace", localWorkspace);
loadLogs->executeAsChildAlg();
} catch (std::invalid_argument &e) {
alg->getLogger().information(
"Invalid argument to LoadNexusLogs Child Algorithm");
alg->getLogger().information(e.what());
executionSuccessful = false;
} catch (std::runtime_error &) {
alg->getLogger().information(
"Unable to successfully run runLoadNexusLogs Child Algorithm./n");
executionSuccessful = false;
}
return executionSuccessful;
}
示例11: string
/**
* Extracts multiple spectra from a Workspace2D into a new workspaces, using
*SumSpectra.
*
* @param ws :: The workspace containing the spectrum to extract
* @param indices :: The workspace index of the spectrum to extract
*
* @returns a Workspace2D containing the extracted spectrum
* @throws runtime_error if the ExtractSingleSpectrum algorithm fails during
*execution
*/
API::MatrixWorkspace_sptr
CalculateTransmission::extractSpectra(API::MatrixWorkspace_sptr ws,
const std::vector<size_t> &indices) {
// Compile a comma separated list of indices that we can pass to SumSpectra.
std::vector<std::string> indexStrings(indices.size());
// A bug in boost 1.53: https://svn.boost.org/trac/boost/ticket/7421
// means that lexical_cast cannot be used directly as the call is ambiguous
// so we need to define a function pointer that can resolve the overloaded
// lexical_cast function
typedef std::string (*from_size_t)(const size_t &);
std::transform(indices.begin(), indices.end(), indexStrings.begin(),
(from_size_t)boost::lexical_cast<std::string, size_t>);
const std::string commaIndexList = boost::algorithm::join(indexStrings, ",");
double start = m_done;
IAlgorithm_sptr childAlg =
createChildAlgorithm("SumSpectra", start, m_done += 0.1);
childAlg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", ws);
childAlg->setPropertyValue("ListOfWorkspaceIndices", commaIndexList);
childAlg->executeAsChildAlg();
// Only get to here if successful
return childAlg->getProperty("OutputWorkspace");
}
示例12: exec
/** Execute the algorithm.
*/
void TransformMD::exec() {
Mantid::API::IMDWorkspace_sptr inWS;
Mantid::API::IMDWorkspace_sptr outWS;
inWS = getProperty("InputWorkspace");
outWS = getProperty("OutputWorkspace");
if (boost::dynamic_pointer_cast<MatrixWorkspace>(inWS))
throw std::runtime_error("TransformMD can only transform a "
"MDHistoWorkspace or a MDEventWorkspace.");
if (outWS != inWS) {
// NOT in-place. So first we clone inWS into outWS
IAlgorithm_sptr clone =
this->createChildAlgorithm("CloneMDWorkspace", 0.0, 0.5, true);
clone->setProperty("InputWorkspace", inWS);
clone->executeAsChildAlg();
outWS = clone->getProperty("OutputWorkspace");
}
if (!outWS)
throw std::runtime_error("Invalid output workspace.");
size_t nd = outWS->getNumDims();
m_scaling = getProperty("Scaling");
m_offset = getProperty("Offset");
// Replicate single values
if (m_scaling.size() == 1)
m_scaling = std::vector<double>(nd, m_scaling[0]);
if (m_offset.size() == 1)
m_offset = std::vector<double>(nd, m_offset[0]);
// Check the size
if (m_scaling.size() != nd)
throw std::invalid_argument("Scaling argument must be either length 1 or "
"match the number of dimensions.");
if (m_offset.size() != nd)
throw std::invalid_argument("Offset argument must be either length 1 or "
"match the number of dimensions.");
// Transform the dimensions
outWS->transformDimensions(m_scaling, m_offset);
MDHistoWorkspace_sptr histo =
boost::dynamic_pointer_cast<MDHistoWorkspace>(outWS);
IMDEventWorkspace_sptr event =
boost::dynamic_pointer_cast<IMDEventWorkspace>(outWS);
if (histo) {
// Recalculate all the values since the dimensions changed.
histo->cacheValues();
} else if (event) {
// Call the method for this type of MDEventWorkspace.
CALL_MDEVENT_FUNCTION(this->doTransform, outWS);
}
this->setProperty("OutputWorkspace", outWS);
}
示例13: if
void StripVanadiumPeaks2::exec(){
// 1. Process input/output
API::MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
std::string outputWSName = getPropertyValue("OutputWorkspace");
int singleIndex = getProperty("WorkspaceIndex");
int param_fwhm = getProperty("FWHM");
int param_tolerance = getProperty("Tolerance");
bool singleSpectrum = !isEmpty(singleIndex);
// 2. Call StripPeaks
std::string peakpositions;
std::string unit = inputWS->getAxis(0)->unit()->unitID();
if (unit == "dSpacing")
{
peakpositions = "0.5044,0.5191,0.5350,0.5526,0.5936,0.6178,0.6453,0.6768,0.7134,0.7566,0.8089,0.8737,0.9571,1.0701,1.2356,1.5133,2.1401";
}
else if (unit == "MomentumTransfer")
{
g_log.error() << "Unit MomentumTransfer (Q-space) is NOT supported by StripVanadiumPeaks now.\n";
throw std::invalid_argument("Q-space is not supported");
// Comment out next line as it won't be reached.
//peakpositions = "2.9359, 4.1520, 5.0851, 5.8716, 6.5648, 7.1915, 7.7676, 8.3045, 8.8074, 9.2837, 9.7368, 10.1703, 10.5849, 11.3702, 11.7443, 12.1040, 12.4568";
} else {
g_log.error() << "Unit " << unit << " Is NOT supported by StripVanadiumPeaks, which only supports d-spacing" << std::endl;
throw std::invalid_argument("Not supported unit");
}
// Call StripPeak
double pro0 = 0.0;
double prof = 1.0;
bool sublog = true;
IAlgorithm_sptr stripPeaks = createChildAlgorithm("StripPeaks", pro0, prof, sublog);
stripPeaks->setProperty("InputWorkspace", inputWS);
stripPeaks->setPropertyValue("OutputWorkspace", outputWSName);
stripPeaks->setProperty("FWHM", param_fwhm);
stripPeaks->setProperty("Tolerance", param_tolerance);
stripPeaks->setPropertyValue("PeakPositions", peakpositions);
stripPeaks->setProperty<std::string>("BackgroundType", getProperty("BackgroundType"));
stripPeaks->setProperty<bool>("HighBackground", getProperty("HighBackground"));
if (singleSpectrum){
stripPeaks->setProperty("WorkspaceIndex", singleIndex);
}
stripPeaks->setProperty<double>("PeakPositionTolerance", getProperty("PeakPositionTolerance"));
stripPeaks->executeAsChildAlg();
// 3. Get and set output workspace
// API::MatrixWorkspace_sptr outputWS = AnalysisDataService::Instance().retrieveWS<API::MatrixWorkspace_sptr>(outputWSName);
// boost::shared_ptr<API::Workspace> outputWS = AnalysisDataService::Instance().retrieve(outputWSName);
API::MatrixWorkspace_sptr outputWS = stripPeaks->getProperty("OutputWorkspace");
this->setProperty("OutputWorkspace", outputWS);
return;
}
示例14: createChildAlgorithm
/** Calls the Rebin algorithm as a ChildAlgorithm.
* @param workspace The workspace to use as input to the Rebin algorithms
* @param params The rebin parameters
* @return A shared pointer to the output (rebinned) workspace
* @throw std::runtime_error If the Rebin algorithm fails
*/
API::MatrixWorkspace_sptr
MergeRuns::rebinInput(const API::MatrixWorkspace_sptr &workspace,
const std::vector<double> ¶ms) {
// Create a Rebin child algorithm
IAlgorithm_sptr rebin = createChildAlgorithm("Rebin");
rebin->setProperty("InputWorkspace", workspace);
rebin->setProperty("Params", params);
rebin->executeAsChildAlg();
return rebin->getProperty("OutputWorkspace");
}
示例15: extractMonitorSpectra
/**
* Pulls the monitor spectra out of a larger workspace
* @param ws
* @param workspaceIndexes The indexes of the spectra to extract
* @return A workspace containing the spectra requested
*/
MatrixWorkspace_sptr NormaliseToMonitor::extractMonitorSpectra(
const MatrixWorkspace_sptr &ws,
const std::vector<std::size_t> &workspaceIndexes) {
IAlgorithm_sptr childAlg = createChildAlgorithm("ExtractSpectra");
childAlg->setProperty<MatrixWorkspace_sptr>("InputWorkspace", ws);
childAlg->setProperty("WorkspaceIndexList", workspaceIndexes);
childAlg->executeAsChildAlg();
MatrixWorkspace_sptr outWS = childAlg->getProperty("OutputWorkspace");
return outWS;
}