/** Returns the deprecation message (if any) for deprecated algorithms. * * @param algName :: The name of the algorithm to execute. * @param version :: The version number (default=-1=highest version). * @return string, empty if algo is NOT deprecated. **/ std::string FrameworkManagerProxy::algorithmDeprecationMessage(const std::string& algName, int version) { std::string deprecMessage = ""; API::Algorithm_sptr alg = AlgorithmManager::Instance().createUnmanaged(algName, version); API::DeprecatedAlgorithm * depr = dynamic_cast<API::DeprecatedAlgorithm *>(alg.get()); if (depr) deprecMessage = depr->deprecationMsg(alg.get()); return deprecMessage; }
void GenericDataProcessorAlgorithm<Base>::copyProperty( API::Algorithm_sptr alg, const std::string &name) { if (!alg->existsProperty(name)) { std::stringstream msg; msg << "Algorithm \"" << alg->name() << "\" does not have property \"" << name << "\""; throw std::runtime_error(msg.str()); } auto prop = alg->getPointerToProperty(name); Base::declareProperty(std::unique_ptr<Property>(prop->clone()), prop->documentation()); }
/** * Load the instrument * @param instrName :: Instrument name */ void ISISLiveEventDataListener::loadInstrument(const std::string &instrName) { // try to load the instrument. if it doesn't load give a warning and carry on if (instrName.empty()) { g_log.warning() << "Unable to read instrument name from DAE." << std::endl; return; } const char *warningMessage = "Failed to load instrument "; try { g_log.notice() << "Loading instrument " << instrName << " ... " << std::endl; API::Algorithm_sptr alg = API::AlgorithmFactory::Instance().create("LoadInstrument", -1); alg->initialize(); alg->setPropertyValue("InstrumentName", instrName); alg->setProperty("Workspace", m_eventBuffer[0]); alg->setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(false)); alg->setChild(true); alg->execute(); // check if the instrument was loaded if (!alg->isExecuted()) { g_log.warning() << warningMessage << instrName << std::endl; } g_log.notice() << "Instrument loaded." << std::endl; } catch (std::exception &e) { g_log.warning() << warningMessage << instrName << std::endl; g_log.warning() << e.what() << instrName << std::endl; } }
/** Rebin output workspace */ void CountEventsInPulses::rebin(DataObjects::EventWorkspace_sptr outputWS) { const double xmin = outputWS->getTofMin(); const double xmax = outputWS->getTofMax(); if (xmax <= xmin) { std::stringstream ss; ss << "Tof_max " << xmax << " is less than Tof_min " << xmin; throw std::runtime_error(ss.str()); } std::stringstream ss; ss << xmin << ", " << mPulseLength << ", " << xmax; std::string binparam = ss.str(); g_log.debug() << "Binning parameter = " << binparam << std::endl; API::Algorithm_sptr rebin = this->createChildAlgorithm("Rebin", 0.8, 0.9, true); rebin->initialize(); rebin->setProperty("InputWorkspace", outputWS); rebin->setProperty("OutputWorkspace", outputWS); rebin->setProperty("Params", binparam); rebin->setProperty("PreserveEvents", true); bool success = rebin->execute(); if (!success) { g_log.warning() << "Rebin output event workspace failed! " << std::endl; } return; }
ResultType performBinaryOpWithDouble(const LHSType inputWS, const double value, const std::string &op, const std::string &name, bool inplace, bool reverse) { std::string algoName = op; // Create the single valued workspace first so that it is run as a top-level // algorithm // such that it's history can be recreated API::Algorithm_sptr alg = API::AlgorithmManager::Instance().createUnmanaged( "CreateSingleValuedWorkspace"); alg->setChild(false); alg->initialize(); alg->setProperty<double>("DataValue", value); const std::string tmp_name("__tmp_binary_operation_double"); alg->setPropertyValue("OutputWorkspace", tmp_name); alg->execute(); MatrixWorkspace_sptr singleValue; API::AnalysisDataServiceImpl &data_store = API::AnalysisDataService::Instance(); if (alg->isExecuted()) { singleValue = boost::dynamic_pointer_cast<API::MatrixWorkspace>( data_store.retrieve(tmp_name)); } else { throw std::runtime_error( "performBinaryOp: Error in execution of CreateSingleValuedWorkspace"); } // Call the function above with the signle-value workspace ResultType result = performBinaryOp<LHSType, MatrixWorkspace_sptr, ResultType>( inputWS, singleValue, algoName, name, inplace, reverse); // Delete the temporary data_store.remove(tmp_name); return result; }
/** Compress event */ DataObjects::EventWorkspace_sptr CountEventsInPulses::compressEvents(DataObjects::EventWorkspace_sptr inputws, double tolerance) { API::Algorithm_sptr alg = this->createChildAlgorithm("CompressEvents", 0.9, 1.0, true); alg->initialize(); alg->setProperty("InputWorkspace", inputws); alg->setProperty("OutputWorkspace", "TempWS"); alg->setProperty("Tolerance", tolerance); bool successful = alg->execute(); DataObjects::EventWorkspace_sptr outputws; if (!successful) { // Failed outputws = inputws; g_log.warning() << "CompressEvents() Failed!" << std::endl; } else { // Successful outputws = alg->getProperty("OutputWorkspace"); if (!outputws) { g_log.error() << "CompressEvents failed as the output is not a MatrixWorkspace. " << std::endl; throw std::runtime_error( "SumSpectra failed as the output is not a MatrixWorkspace."); } /* API::MatrixWorkspace_sptr testws = alg->getProperty("OutputWorkspace"); if (!testws) { g_log.error() << "CompressEvents failed as the output is not a MatrixWorkspace. " << std::endl; throw std::runtime_error("SumSpectra failed as the output is not a MatrixWorkspace."); } else { outputws = boost::dynamic_pointer_cast<DataObjects::EventWorkspace>(testws); } */ } return outputws; }
/** Executes the algorithm */ void FilterByTime2::exec() { DataObjects::EventWorkspace_const_sptr inWS = this->getProperty("InputWorkspace"); if (!inWS) { g_log.error() << "Input is not EventWorkspace" << std::endl; throw std::invalid_argument("Input is not EventWorksapce"); } else { g_log.debug() << "DB5244 InputWorkspace Name = " << inWS->getName() << std::endl; } double starttime = this->getProperty("StartTime"); double stoptime = this->getProperty("StopTime"); std::string absstarttime = this->getProperty("AbsoluteStartTime"); std::string absstoptime = this->getProperty("AbsoluteStopTime"); std::string start, stop; if ((absstarttime != "") && (absstoptime != "") && (starttime <= 0.0) && (stoptime <= 0.0)) { // Use the absolute string start = absstarttime; stop = absstoptime; } else if ((absstarttime != "" || absstoptime != "") && (starttime > 0.0 || stoptime > 0.0)) { throw std::invalid_argument( "It is not allowed to provide both absolute time and relative time."); } else { // Use second std::stringstream ss; ss << starttime; start = ss.str(); std::stringstream ss2; ss2 << stoptime; stop = ss2.str(); } // 1. Generate Filters g_log.debug() << "\nDB441: About to generate Filter. StartTime = " << starttime << " StopTime = " << stoptime << std::endl; API::Algorithm_sptr genfilter = createChildAlgorithm("GenerateEventsFilter", 0.0, 20.0, true, 1); genfilter->initialize(); genfilter->setPropertyValue("InputWorkspace", inWS->getName()); genfilter->setPropertyValue("OutputWorkspace", "FilterWS"); genfilter->setProperty("StartTime", start); genfilter->setProperty("StopTime", stop); genfilter->setProperty("UnitOfTime", "Seconds"); genfilter->setProperty("FastLog", false); bool sucgen = genfilter->execute(); if (!sucgen) { g_log.error() << "Unable to generate event filters" << std::endl; throw std::runtime_error("Unable to generate event filters"); } else { g_log.debug() << "Filters are generated. " << std::endl; } API::Workspace_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. "); } // 2. Filter events g_log.debug() << "\nAbout to filter events. " << "\n"; API::Algorithm_sptr filter = createChildAlgorithm("FilterEvents", 20.0, 100.0, true, 1); filter->initialize(); filter->setPropertyValue("InputWorkspace", inWS->getName()); filter->setPropertyValue("OutputWorkspaceBaseName", "ResultWS"); filter->setProperty("SplitterWorkspace", filterWS); filter->setProperty("FilterByPulseTime", true); bool sucfilt = filter->execute(); if (!sucfilt) { g_log.error() << "Unable to filter events" << std::endl; throw std::runtime_error("Unable to filter events"); } else { g_log.debug() << "Filter events is successful. " << std::endl; } DataObjects::EventWorkspace_sptr optws = filter->getProperty("OutputWorkspace_0"); this->setProperty("OutputWorkspace", optws); }