Exemplo n.º 1
0
/**
  * 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;
  }
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
/** 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);
}