当前位置: 首页>>代码示例>>C++>>正文


C++ EventWorkspace_sptr::getOrAddEventList方法代码示例

本文整理汇总了C++中EventWorkspace_sptr::getOrAddEventList方法的典型用法代码示例。如果您正苦于以下问题:C++ EventWorkspace_sptr::getOrAddEventList方法的具体用法?C++ EventWorkspace_sptr::getOrAddEventList怎么用?C++ EventWorkspace_sptr::getOrAddEventList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EventWorkspace_sptr的用法示例。


在下文中一共展示了EventWorkspace_sptr::getOrAddEventList方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setupEventWorkspace

/** Set up an Event workspace
  * @param numentries :: number of log entries to output
  * @param times :: vector of Kernel::DateAndTime
  * @param values :: vector of log value in double
  */
void ExportTimeSeriesLog::setupEventWorkspace(int numentries,
                                              vector<DateAndTime> &times,
                                              vector<double> values) {
  Kernel::DateAndTime runstart(
      m_dataWS->run().getProperty("run_start")->value());

  // Get some stuff from the input workspace
  const size_t numberOfSpectra = 1;
  const int YLength = static_cast<int>(m_dataWS->blocksize());

  // Make a brand new EventWorkspace
  EventWorkspace_sptr outEventWS = boost::dynamic_pointer_cast<EventWorkspace>(
      API::WorkspaceFactory::Instance().create(
          "EventWorkspace", numberOfSpectra, YLength + 1, YLength));
  // Copy geometry over.
  API::WorkspaceFactory::Instance().initializeFromParent(m_dataWS, outEventWS,
                                                         false);

  m_outWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outEventWS);
  if (!m_outWS)
    throw runtime_error(
        "Output workspace cannot be casted to a MatrixWorkspace.");

  g_log.debug("[DBx336] An output workspace is generated.!");

  // Create the output event list (empty)
  EventList &outEL = outEventWS->getOrAddEventList(0);
  outEL.switchTo(WEIGHTED_NOTIME);

  // Allocate all the required memory
  outEL.reserve(numentries);
  outEL.clearDetectorIDs();

  for (size_t i = 0; i < static_cast<size_t>(numentries); i++) {
    Kernel::DateAndTime tnow = times[i];
    int64_t dt = tnow.totalNanoseconds() - runstart.totalNanoseconds();

    // convert to microseconds
    double dtmsec = static_cast<double>(dt) / 1000.0;
    outEL.addEventQuickly(WeightedEventNoTime(dtmsec, values[i], values[i]));
  }
  // Ensure thread-safety
  outEventWS->sortAll(TOF_SORT, NULL);

  // Now, create a default X-vector for histogramming, with just 2 bins.
  Kernel::cow_ptr<MantidVec> axis;
  MantidVec &xRef = axis.access();
  xRef.resize(2);
  std::vector<WeightedEventNoTime> &events = outEL.getWeightedEventsNoTime();
  xRef[0] = events.begin()->tof();
  xRef[1] = events.rbegin()->tof();

  // Set the binning axis using this.
  outEventWS->setX(0, axis);

  return;
}
开发者ID:DiegoMonserrat,项目名称:mantid,代码行数:62,代码来源:ExportTimeSeriesLog.cpp

示例2: exec

void CompressEvents::exec()
{
  // Get the input workspace
  EventWorkspace_sptr inputWS = getProperty("InputWorkspace");
  EventWorkspace_sptr outputWS = getProperty("OutputWorkspace");
  double tolerance = getProperty("Tolerance");

  // Some starting things
  bool inplace = (inputWS == outputWS);
  const int noSpectra = static_cast<int>(inputWS->getNumberHistograms());
  Progress prog(this,0.0,1.0, noSpectra*2);

  // Sort the input workspace in-place by TOF. This can be faster if there are few event lists.
  inputWS->sortAll(TOF_SORT, &prog);

  // Are we making a copy of the input workspace?
  if (!inplace)
  {
    //Make a brand new EventWorkspace
    outputWS = boost::dynamic_pointer_cast<EventWorkspace>(
        API::WorkspaceFactory::Instance().create("EventWorkspace", inputWS->getNumberHistograms(), 2, 1));
    //Copy geometry over.
    API::WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false);
    // We DONT copy the data though

    // Do we want to parallelize over event lists, or in each event list
    bool parallel_in_each = noSpectra < PARALLEL_GET_MAX_THREADS;
    //parallel_in_each = false;

    // Loop over the histograms (detector spectra)
    // Don't parallelize the loop if we are going to parallelize each event list.
    // cppcheck-suppress syntaxError
    PRAGMA_OMP( parallel for schedule(dynamic) if (!parallel_in_each) )
    for (int i = 0; i < noSpectra; ++i)
    {
      PARALLEL_START_INTERUPT_REGION
      //the loop variable i can't be signed because of OpenMp rules inforced in Linux. Using this signed type suppresses warnings below
      const size_t index = static_cast<size_t>(i);
      // The input event list
      EventList& input_el = inputWS->getEventList(index);
      // And on the output side
      EventList & output_el = outputWS->getOrAddEventList(index);
      // Copy other settings into output
      output_el.setX( input_el.ptrX() );

      // The EventList method does the work.
      input_el.compressEvents(tolerance, &output_el, parallel_in_each);

      prog.report("Compressing");
      PARALLEL_END_INTERUPT_REGION
    }
    PARALLEL_CHECK_INTERUPT_REGION

  }
开发者ID:trnielsen,项目名称:mantid,代码行数:54,代码来源:CompressEvents.cpp

示例3: execEvent

void GatherWorkspaces::execEvent() {

  // Every process in an MPI job must hit this next line or everything hangs!
  mpi::communicator included; // The communicator containing all processes
  // The root process needs to create a workspace of the appropriate size
  EventWorkspace_sptr outputWorkspace;
  if (included.rank() == 0) {
    g_log.debug() << "Total number of spectra is " << totalSpec << "\n";
    // Create the workspace for the output
    outputWorkspace = boost::dynamic_pointer_cast<EventWorkspace>(
        API::WorkspaceFactory::Instance().create("EventWorkspace", sumSpec,
                                                 numBins + hist, numBins));
    // Copy geometry over.
    API::WorkspaceFactory::Instance().initializeFromParent(
        eventW, outputWorkspace, true);
    setProperty("OutputWorkspace", outputWorkspace);
    ExperimentInfo_sptr inWS = inputWorkspace;
    outputWorkspace->copyExperimentInfoFrom(inWS.get());
  }

  for (size_t wi = 0; wi < totalSpec; wi++) {
    if (included.rank() == 0) {
      // How do we accumulate the data?
      std::string accum = this->getPropertyValue("AccumulationMethod");
      std::vector<Mantid::DataObjects::EventList> out_values;
      gather(included, eventW->getEventList(wi), out_values, 0);
      for (int i = 0; i < included.size(); i++) {
        size_t index = wi; // accum == "Add"
        if (accum == "Append")
          index = wi + i * totalSpec;
        outputWorkspace->dataX(index) = eventW->readX(wi);
        outputWorkspace->getOrAddEventList(index) += out_values[i];
        const ISpectrum *inSpec = eventW->getSpectrum(wi);
        ISpectrum *outSpec = outputWorkspace->getSpectrum(index);
        outSpec->clearDetectorIDs();
        outSpec->addDetectorIDs(inSpec->getDetectorIDs());
      }
    } else {
      gather(included, eventW->getEventList(wi), 0);
    }
  }
}
开发者ID:mkoennecke,项目名称:mantid,代码行数:42,代码来源:GatherWorkspaces.cpp

示例4: execEvent

/** Executes the algorithm
 *  @throw std::out_of_range If a property is set to an invalid value for the
 * input workspace
 */
void ExtractSpectra::execEvent() {
  m_histogram = m_inputWorkspace->isHistogramData();
  double minX_val = getProperty("XMin");
  double maxX_val = getProperty("XMax");
  if (isEmpty(minX_val))
    minX_val = eventW->getTofMin();
  if (isEmpty(maxX_val))
    maxX_val = eventW->getTofMax();

  // Check for common boundaries in input workspace
  m_commonBoundaries = WorkspaceHelpers::commonBoundaries(m_inputWorkspace);

  // Retrieve and validate the input properties
  this->checkProperties();
  cow_ptr<MantidVec> XValues_new;
  if (m_commonBoundaries) {
    const MantidVec &oldX =
        m_inputWorkspace->readX(m_workspaceIndexList.front());
    XValues_new.access().assign(oldX.begin() + m_minX, oldX.begin() + m_maxX);
  }
  size_t ntcnew = m_maxX - m_minX;

  if (ntcnew < 2) {
    // create new output X axis
    std::vector<double> rb_params;
    rb_params.push_back(minX_val);
    rb_params.push_back(maxX_val - minX_val);
    rb_params.push_back(maxX_val);
    ntcnew = VectorHelper::createAxisFromRebinParams(rb_params,
                                                     XValues_new.access());
  }

  // run inplace branch if appropriate
  MatrixWorkspace_sptr OutputWorkspace = this->getProperty("OutputWorkspace");
  bool inPlace = (OutputWorkspace == m_inputWorkspace);
  if (inPlace)
    g_log.debug("Cropping EventWorkspace in-place.");

  // Create the output workspace
  EventWorkspace_sptr outputWorkspace =
      boost::dynamic_pointer_cast<EventWorkspace>(
          API::WorkspaceFactory::Instance().create(
              "EventWorkspace", m_workspaceIndexList.size(), ntcnew,
              ntcnew - m_histogram));
  eventW->sortAll(TOF_SORT, nullptr);
  outputWorkspace->sortAll(TOF_SORT, nullptr);
  // Copy required stuff from it
  API::WorkspaceFactory::Instance().initializeFromParent(m_inputWorkspace,
                                                         outputWorkspace, true);

  Progress prog(this, 0.0, 1.0, 2 * m_workspaceIndexList.size());
  eventW->sortAll(Mantid::DataObjects::TOF_SORT, &prog);
  // Loop over the required workspace indices, copying in the desired bins
  PARALLEL_FOR2(m_inputWorkspace, outputWorkspace)
  for (int j = 0; j < static_cast<int>(m_workspaceIndexList.size()); ++j) {
    PARALLEL_START_INTERUPT_REGION
    auto i = m_workspaceIndexList[j];
    const EventList &el = eventW->getEventList(i);
    // The output event list
    EventList &outEL = outputWorkspace->getOrAddEventList(j);
    //    // left side of the crop - will erase 0 -> endLeft
    //    std::size_t endLeft;
    //    // right side of the crop - will erase endRight->numEvents+1
    //    std::size_t endRight;

    switch (el.getEventType()) {
    case TOF: {
      std::vector<TofEvent> moreevents;
      moreevents.reserve(el.getNumberEvents()); // assume all will make it
      copyEventsHelper(el.getEvents(), moreevents, minX_val, maxX_val);
      outEL += moreevents;
      break;
    }
    case WEIGHTED: {
      std::vector<WeightedEvent> moreevents;
      moreevents.reserve(el.getNumberEvents()); // assume all will make it
      copyEventsHelper(el.getWeightedEvents(), moreevents, minX_val, maxX_val);
      outEL += moreevents;
      break;
    }
    case WEIGHTED_NOTIME: {
      std::vector<WeightedEventNoTime> moreevents;
      moreevents.reserve(el.getNumberEvents()); // assume all will make it
      copyEventsHelper(el.getWeightedEventsNoTime(), moreevents, minX_val,
                       maxX_val);
      outEL += moreevents;
      break;
    }
    }
    outEL.setSortOrder(el.getSortType());

    // Copy spectrum number & detector IDs
    outEL.copyInfoFrom(el);

    bool hasDx = eventW->hasDx(i);

//.........这里部分代码省略.........
开发者ID:Mantid-Test-Account,项目名称:mantid,代码行数:101,代码来源:ExtractSpectra.cpp


注:本文中的EventWorkspace_sptr::getOrAddEventList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。