Ejemplo n.º 1
0
/** Execute the algorithm.
*/
void ConvertToYSpace::exec() {
  retrieveInputs();
  createOutputWorkspace();

  const int64_t nhist = static_cast<int64_t>(m_inputWS->getNumberHistograms());
  const int64_t nreports = nhist;
  auto progress = boost::make_shared<Progress>(this, 0.0, 1.0, nreports);

  PARALLEL_FOR2(m_inputWS, m_outputWS)
  for (int64_t i = 0; i < nhist; ++i) {
    PARALLEL_START_INTERUPT_REGION

    if (!convert(i)) {

      g_log.warning("No detector defined for index=" +
                    boost::lexical_cast<std::string>(i) +
                    ". Zeroing spectrum.");
      m_outputWS->maskWorkspaceIndex(i);
    }

    PARALLEL_END_INTERUPT_REGION
  }
  PARALLEL_CHECK_INTERUPT_REGION

  setProperty("OutputWorkspace", m_outputWS);
}
/**
 * Create the output workspace group.
 * @param baseName :: The base name for the output workspace. Suffix "Workspace"
 * will be added to it.
 * @param function :: A function to calculate the values. Must be of the
 * MultiDomainFunction type.
 * @param domain :: Domain created earlier with this creator (unused)
 * @param values :: Values created earlier with this creator (unused)
 * @param outputWorkspacePropertyName :: Name for the property to hold the
 * output workspace. If
 *    empty the property won't be created.
 * @return A shared pointer to the created workspace.
 */
boost::shared_ptr<API::Workspace> MultiDomainCreator::createOutputWorkspace(
    const std::string &baseName, API::IFunction_sptr function,
    boost::shared_ptr<API::FunctionDomain> domain,
    boost::shared_ptr<API::FunctionValues> values,
    const std::string &outputWorkspacePropertyName) {
  UNUSED_ARG(domain);
  UNUSED_ARG(values);

  auto mdFunction =
      boost::dynamic_pointer_cast<API::MultiDomainFunction>(function);
  if (!mdFunction) {
    throw std::runtime_error("A MultiDomainFunction is expected to be used "
                             "with MultiDomainCreator.");
  }

  // split the function into independent parts
  std::vector<API::IFunction_sptr> functions =
      mdFunction->createEquivalentFunctions();
  // there must be as many parts as there are domains
  if (functions.size() != m_creators.size()) {
    throw std::runtime_error("Number of functions and domains don't match");
  }

  API::WorkspaceGroup_sptr outWS =
      API::WorkspaceGroup_sptr(new API::WorkspaceGroup());

  for (size_t i = 0; i < functions.size(); ++i) {
    std::string localName =
        baseName + "Workspace_" + boost::lexical_cast<std::string>(i);
    auto fun = functions[i];
    auto creator = m_creators[i];
    boost::shared_ptr<API::FunctionDomain> localDomain;
    boost::shared_ptr<API::FunctionValues> localValues;
    fun->setUpForFit();
    creator->createDomain(localDomain, localValues);
    creator->initFunction(fun);
    auto ws = creator->createOutputWorkspace(localName, fun, localDomain,
                                             localValues, "");
    API::AnalysisDataService::Instance().addOrReplace(localName, ws);
    outWS->addWorkspace(ws);
  }

  if (!outputWorkspacePropertyName.empty()) {
    declareProperty(
        new API::WorkspaceProperty<API::WorkspaceGroup>(
            outputWorkspacePropertyName, "", Kernel::Direction::Output),
        "Name of the output Workspace holding resulting simulated spectrum");
    m_manager->setPropertyValue(outputWorkspacePropertyName,
                                baseName + "Workspaces");
    m_manager->setProperty(outputWorkspacePropertyName, outWS);
  }

  return outWS;
}
Ejemplo n.º 3
0
/** Execute the algorithm
 * Procedure:
 * 1. check all the inputs
 * 2. create an EventWorkspace object
 * 3. process events
 * 4. set out output
 */
void LoadEventPreNexus2::exec() {
  g_log.information("Executing LoadEventPreNexus Ver 2.0");

  // Process input properties
  // a. Check 'chunk' properties are valid, if set
  const int chunks = getProperty("TotalChunks");
  if (!isEmpty(chunks) && int(getProperty("ChunkNumber")) > chunks) {
    throw std::out_of_range("ChunkNumber cannot be larger than TotalChunks");
  }

  prog = make_unique<Progress>(this, 0.0, 1.0, 100);

  // b. what spectra (pixel ID's) to load
  this->spectra_list = this->getProperty(PID_PARAM);

  // c. the event file is needed in case the pulseid fileanme is empty
  string event_filename = this->getPropertyValue(EVENT_PARAM);
  string pulseid_filename = this->getPropertyValue(PULSEID_PARAM);
  bool throwError = true;
  if (pulseid_filename.empty()) {
    pulseid_filename = generatePulseidName(event_filename);
    if (!pulseid_filename.empty()) {
      if (Poco::File(pulseid_filename).exists()) {
        this->g_log.information()
            << "Found pulseid file " << pulseid_filename << '\n';
        throwError = false;
      } else {
        pulseid_filename = "";
      }
    }
  }

  processInvestigationInputs();

  // Read input files
  prog->report("Loading Pulse ID file");
  this->readPulseidFile(pulseid_filename, throwError);
  prog->report("Loading Event File");
  this->openEventFile(event_filename);

  // Correct event indexes mased by veto flag
  unmaskVetoEventIndex();

  // Optinally output event number / pulse file
  std::string diswsname = getPropertyValue("EventNumberWorkspace");
  if (!diswsname.empty()) {
    MatrixWorkspace_sptr disws = generateEventDistribtionWorkspace();
    setProperty("EventNumberWorkspace", disws);
  }

  // Create otuput Workspace
  prog->report("Creating output workspace");
  createOutputWorkspace(event_filename);

  // Process the events into pixels
  procEvents(localWorkspace);

  // Set output
  this->setProperty<IEventWorkspace_sptr>(OUT_PARAM, localWorkspace);

  // Fast frequency sample environment data
  this->processImbedLogs();

} // exec()