예제 #1
0
/** Execute the algorithm.
 */
void CreateEPP::exec() {
  API::MatrixWorkspace_sptr inputWS =
      getProperty(PropertyNames::INPUT_WORKSPACE);
  const auto &spectrumInfo = inputWS->spectrumInfo();
  API::ITableWorkspace_sptr outputWS =
      API::WorkspaceFactory::Instance().createTable("TableWorkspace");
  addEPPColumns(outputWS);
  const double sigma = getProperty(PropertyNames::SIGMA);
  const size_t spectraCount = spectrumInfo.size();
  outputWS->setRowCount(spectraCount);
  const auto l1 = spectrumInfo.l1();
  const double EFixed = inputWS->run().getPropertyAsSingleValue("Ei");
  for (size_t i = 0; i < spectraCount; ++i) {
    const auto l2 = spectrumInfo.l2(i);
    const auto elasticTOF = Kernel::UnitConversion::run(
        "Energy", "TOF", EFixed, l1, l2, 0, Kernel::DeltaEMode::Direct, EFixed);
    outputWS->getRef<int>(ColumnNames::WS_INDEX, i) = static_cast<int>(i);
    outputWS->getRef<double>(ColumnNames::PEAK_CENTRE, i) = elasticTOF;
    outputWS->getRef<double>(ColumnNames::PEAK_CENTRE_ERR, i) = 0;
    outputWS->getRef<double>(ColumnNames::SIGMA, i) = sigma;
    outputWS->getRef<double>(ColumnNames::SIGMA_ERR, i) = 0;
    double height = 0;
    try {
      const auto elasticIndex = inputWS->binIndexOf(elasticTOF, i);
      height = inputWS->y(i)[elasticIndex];
    } catch (std::out_of_range &) {
      std::ostringstream sout;
      sout << "EPP out of TOF range for workspace index " << i
           << ". Peak height set to zero.";
      g_log.warning() << sout.str();
    }
    outputWS->getRef<double>(ColumnNames::HEIGHT, i) = height;
    outputWS->getRef<double>(ColumnNames::CHI_SQUARED, i) = 1;
    outputWS->getRef<std::string>(ColumnNames::STATUS, i) = "success";
  }
  setProperty(PropertyNames::OUTPUT_WORKSPACE, outputWS);
}
예제 #2
0
/**
 * Load a table
 */
API::Workspace_sptr LoadNexusProcessed::loadTableEntry(NXEntry & entry)
{
  API::ITableWorkspace_sptr workspace;
  workspace = Mantid::API::WorkspaceFactory::Instance().createTable("TableWorkspace");

  NXData nx_tw = entry.openNXData("table_workspace");

  std::vector<double> values;

  bool hasNumberOfRowBeenSet = false;
  //int numberOfRows = 0;

  int columnNumber = 1;
  do
  {
    std::string str = "column_" + boost::lexical_cast<std::string>(columnNumber);

    NXInfo info = nx_tw.getDataSetInfo(str.c_str());
    if (info.stat == NX_ERROR)
    {
      break;
    }

    if ( info.type == NX_FLOAT64 )
    {
      NXDouble nxDouble = nx_tw.openNXDouble(str.c_str());
      std::string columnTitle = nxDouble.attributes("name");
      if (!columnTitle.empty())
      {
        workspace->addColumn("double", columnTitle);
        nxDouble.load();
        int length = nxDouble.dim0();
        if ( !hasNumberOfRowBeenSet )
        { 
          workspace->setRowCount(length);
          hasNumberOfRowBeenSet = true;
        }
        for (int i = 0; i < length; i++)
          workspace->cell<double>(i,columnNumber-1) = *(nxDouble() + i);
      }
    }
    else if ( info.type == NX_CHAR )
    {
      NXChar data = nx_tw.openNXChar(str.c_str());
      std::string columnTitle = data.attributes("name");
      if (!columnTitle.empty())
      {
        workspace->addColumn("str", columnTitle);
        int nRows = info.dims[0];
        if ( !hasNumberOfRowBeenSet )
        {
          workspace->setRowCount(nRows);
          hasNumberOfRowBeenSet = true;
        }
        int maxStr = info.dims[1];

        std::string fromCrap(maxStr,' ');

        data.load();
        for (int iR = 0; iR < nRows; iR++)
        {
          for (int i = 0; i < maxStr; i++)
            fromCrap[i] = *(data()+i+maxStr*iR);
          workspace->cell<std::string>(iR,columnNumber-1) = fromCrap;
        }
      }
    } 

    columnNumber++;
  
  } while ( 1 );

  return boost::static_pointer_cast<API::Workspace>(workspace);
}