Exemple #1
0
/**
 * Copy all of the data (event lists) from the source workspace to this
 *workspace.
 *
 * @param source: EventWorkspace from which we are taking data.
 * @param sourceStartWorkspaceIndex: index in the workspace of source where we
 *start
 *          copying the data. This index will be 0 in the "this" workspace.
 *          Default: -1, meaning copy all.
 * @param sourceEndWorkspaceIndex: index in the workspace of source where we
 *stop.
 *          It is inclusive = source[sourceEndWorkspaceIndex[ WILL be copied.
 *          Default: -1, meaning copy all.
 *
 */
void EventWorkspace::copyDataFrom(const EventWorkspace &source,
                                  std::size_t sourceStartWorkspaceIndex,
                                  std::size_t sourceEndWorkspaceIndex) {
  // Start with nothing.
  this->clearData(); // properly de-allocates memory!

  // Copy the vector of EventLists
  EventListVector source_data = source.data;
  EventListVector::iterator it;
  EventListVector::iterator it_start = source_data.begin();
  EventListVector::iterator it_end = source_data.end();
  size_t source_data_size = source_data.size();

  // Do we copy only a range?
  if (sourceEndWorkspaceIndex == size_t(-1))
    sourceEndWorkspaceIndex = source_data_size - 1;
  if ((sourceStartWorkspaceIndex < source_data_size) &&
      (sourceEndWorkspaceIndex < source_data_size) &&
      (sourceEndWorkspaceIndex >= sourceStartWorkspaceIndex)) {
    it_start += sourceStartWorkspaceIndex;
    it_end = source_data.begin() + sourceEndWorkspaceIndex + 1;
  }

  for (it = it_start; it != it_end; ++it) {
    // Create a new event list, copying over the events
    EventList *newel = new EventList(**it);
    // Make sure to update the MRU to point to THIS event workspace.
    newel->setMRU(this->mru);
    this->data.push_back(newel);
  }
  // Save the number of vectors
  m_noVectors = this->data.size();

  this->clearMRU();
}