void StartLiveDataDialog::accept()
{
  // Now manually set the StartTime property as there's a computation needed
  DateAndTime startTime = DateAndTime::getCurrentTime() - ui.dateTimeEdit->value()*60.0;
  m_algorithm->setPropertyValue("StartTime",startTime.toISO8601String());

  AlgorithmDialog::accept(); // accept executes the algorithm
}
/**
 * Shift the times in a log of a string property
 * @param logEntry :: the string property
 * @param timeShift :: the time shift.
 */
void ChangeTimeZero::shiftTimeOfLogForStringProperty(
    PropertyWithValue<std::string> *logEntry, double timeShift) const {
  // Parse the log entry and replace all ISO8601 strings with an adjusted value
  auto value = logEntry->value();
  if (checkForDateTime(value)) {
    DateAndTime dateTime(value);
    DateAndTime shiftedTime = dateTime + timeShift;
    logEntry->setValue(shiftedTime.toISO8601String());
  }
}
Beispiel #3
0
 void saveTimeVector(::NeXus::File * file, TimeSeriesProperty<NumT> * prop)
 {
   std::vector<DateAndTime> times = prop->timesAsVector();
   DateAndTime start = times[0];
   std::vector<double> timeSec(times.size());
   for (size_t i=0; i<times.size(); i++)
     timeSec[i] = double(times[i].totalNanoseconds() - start.totalNanoseconds()) * 1e-9;
   file->writeData("time", timeSec);
   file->openData("time");
   file->putAttr("start", start.toISO8601String() );
   file->closeData();
 }
Beispiel #4
0
/** Execute the algorithm.
 */
void LoadLiveData::exec() {
  // The full, post-processed output workspace
  m_outputWS = this->getProperty("OutputWorkspace");

  // Validate inputs
  if (this->hasPostProcessing()) {
    if (this->getPropertyValue("AccumulationWorkspace").empty())
      throw std::invalid_argument("Must specify the AccumulationWorkspace "
                                  "parameter if using PostProcessing.");

    // The accumulated but not post-processed output workspace
    m_accumWS = this->getProperty("AccumulationWorkspace");
  } else {
    // No post-processing, so the accumulation and output are the same
    m_accumWS = m_outputWS;
  }

  // Get or create the live listener
  ILiveListener_sptr listener = this->getLiveListener();

  // Do we need to reset the data?
  bool dataReset = listener->dataReset();

  // The listener returns a MatrixWorkspace containing the chunk of live data.
  Workspace_sptr chunkWS;
  bool dataNotYetGiven = true;
  while (dataNotYetGiven) {
    try {
      chunkWS = listener->extractData();
      dataNotYetGiven = false;
    } catch (Exception::NotYet &ex) {
      g_log.warning() << "The " << listener->name()
                      << " is not ready to return data: " << ex.what() << "\n";
      g_log.warning()
          << "Trying again in 10 seconds - cancel the algorithm to stop.\n";
      const int tenSeconds = 40;
      for (int i = 0; i < tenSeconds; ++i) {
        Poco::Thread::sleep(10000 / tenSeconds); // 250 ms
        this->interruption_point();
      }
    }
  }

  // TODO: Have the ILiveListener tell me exactly the time stamp
  DateAndTime lastTimeStamp = DateAndTime::getCurrentTime();
  this->setPropertyValue("LastTimeStamp", lastTimeStamp.toISO8601String());

  // Now we process the chunk
  Workspace_sptr processed = this->processChunk(chunkWS);

  bool PreserveEvents = this->getProperty("PreserveEvents");
  EventWorkspace_sptr processedEvent =
      boost::dynamic_pointer_cast<EventWorkspace>(processed);
  if (!PreserveEvents && processedEvent) {
    // Convert the monitor workspace, if there is one and it's necessary
    MatrixWorkspace_sptr monitorWS = processedEvent->monitorWorkspace();
    auto monitorEventWS =
        boost::dynamic_pointer_cast<EventWorkspace>(monitorWS);
    if (monitorEventWS) {
      auto monAlg = this->createChildAlgorithm("ConvertToMatrixWorkspace");
      monAlg->setProperty("InputWorkspace", monitorEventWS);
      monAlg->executeAsChildAlg();
      if (!monAlg->isExecuted())
        g_log.error(
            "Failed to convert monitors from events to histogram form.");
      monitorWS = monAlg->getProperty("OutputWorkspace");
    }

    // Now do the main workspace
    Algorithm_sptr alg = this->createChildAlgorithm("ConvertToMatrixWorkspace");
    alg->setProperty("InputWorkspace", processedEvent);
    std::string outputName = "__anonymous_livedata_convert_" +
                             this->getPropertyValue("OutputWorkspace");
    alg->setPropertyValue("OutputWorkspace", outputName);
    alg->execute();
    if (!alg->isExecuted())
      throw std::runtime_error("Error when calling ConvertToMatrixWorkspace "
                               "(since PreserveEvents=False). See log.");
    // Replace the "processed" workspace with the converted one.
    MatrixWorkspace_sptr temp = alg->getProperty("OutputWorkspace");
    if (monitorWS)
      temp->setMonitorWorkspace(monitorWS); // Set back the monitor workspace
    processed = temp;
  }

  // How do we accumulate the data?
  std::string accum = this->getPropertyValue("AccumulationMethod");

  // If the AccumulationWorkspace does not exist, we always replace the
  // AccumulationWorkspace.
  // Also, if the listener said we are resetting the data, then we clear out the
  // old.
  if (!m_accumWS || dataReset)
    accum = "Replace";

  g_log.notice() << "Performing the " << accum << " operation.\n";

  // Perform the accumulation and set the AccumulationWorkspace workspace
  if (accum == "Replace")
    this->replaceChunk(processed);
  else if (accum == "Append")
    this->appendChunk(processed);
  else
    // Default to Add.
    this->addChunk(processed);

  // At this point, m_accumWS is set.

  if (this->hasPostProcessing()) {
    // ----------- Run post-processing -------------
    this->runPostProcessing();
    // Set both output workspaces
    this->setProperty("AccumulationWorkspace", m_accumWS);
    this->setProperty("OutputWorkspace", m_outputWS);
    doSortEvents(m_outputWS);
  } else {
    // ----------- No post-processing -------------
    m_outputWS = m_accumWS;
    // We DO NOT set AccumulationWorkspace.
    this->setProperty("OutputWorkspace", m_outputWS);
  }

  // Output group requires some additional handling
  WorkspaceGroup_sptr out_gws =
      boost::dynamic_pointer_cast<WorkspaceGroup>(m_outputWS);
  if (out_gws) {
    size_t n = static_cast<size_t>(out_gws->getNumberOfEntries());
    for (size_t i = 0; i < n; ++i) {
      auto ws = out_gws->getItem(i);
      std::string itemName = ws->name();
      std::string wsName =
          getPropertyValue("OutputWorkspace") + "_" + std::to_string(i + 1);
      if (wsName != itemName) {
        if (AnalysisDataService::Instance().doesExist(itemName)) {
          // replace the temporary name with the proper one
          AnalysisDataService::Instance().rename(itemName, wsName);
        }
      } else {
        // touch the workspace in the ADS to issue a notification to update the
        // GUI
        AnalysisDataService::Instance().addOrReplace(itemName, ws);
      }
    }
  }
}
Beispiel #5
0
/** Circumvent a bug in IPython 1.1, which chokes on nanosecond precision
 * datetimes.
 *  Adding a space to the string returned by the C++ method avoids it being
 * given
 *  the special treatment that leads to the problem.
 */
std::string ISO8601StringPlusSpace(DateAndTime &self) {
  return self.toISO8601String() + " ";
}