Example #1
0
/** Executes the algorithm. Reading in Log entries from the Nexus file
 *
 *  @throw Mantid::Kernel::Exception::FileError  Thrown if file is not recognised to be a Nexus datafile
 *  @throw std::runtime_error Thrown with Workspace problems
 */
void LoadMuonLog::exec()
{
  // Retrieve the filename from the properties and perform some initial checks on the filename

  m_filename = getPropertyValue("Filename");

  MuonNexusReader nxload;
  if ( nxload.readLogData(m_filename) != 0 )
  {
    g_log.error("In LoadMuonLog: " + m_filename + " can not be opened.");
    throw Exception::FileError("File does not exist:" , m_filename);
  }

  // Get the input workspace and retrieve sample from workspace.
  // the log data will be loaded into the Sample container of the workspace
  // Also set the sample name at this point, as part of the sample related log data.

  const MatrixWorkspace_sptr localWorkspace = getProperty("Workspace");
  localWorkspace->mutableSample().setName(nxload.getSampleName());

  // Attempt to load the content of each NXlog section into the Sample object
  // Assumes that MuonNexusReader has read all log data
  // Two cases of double or string data allowed
 Progress prog(this,0.0,1.0,nxload.numberOfLogs());
  for (int i = 0; i < nxload.numberOfLogs(); i++)
  {
    std::string logName=nxload.getLogName(i);
    TimeSeriesProperty<double> *l_PropertyDouble = new TimeSeriesProperty<double>(logName);
    TimeSeriesProperty<std::string> *l_PropertyString = new TimeSeriesProperty<std::string>(logName);
    std::vector<double> logTimes;

    // Read log file into Property which is then stored in Sample object
    if(!nxload.logTypeNumeric(i))
    {
       std::string logValue;
       std::time_t logTime;
       for( int j=0;j<nxload.getLogLength(i);j++)
       {
          nxload.getLogStringValues(i,j,logTime,logValue);
          l_PropertyString->addValue(logTime, logValue);
       }
    }
    else
    {
       double logValue;
       std::time_t logTime;
       for( int j=0;j<nxload.getLogLength(i);j++)
       {
          nxload.getLogValues(i,j,logTime,logValue);
          l_PropertyDouble->addValue(logTime, logValue);
       }
    }

    // store Property in Sample object and delete unused object
    if ( nxload.logTypeNumeric(i) )
    {
      localWorkspace->mutableRun().addLogData(l_PropertyDouble);
      delete l_PropertyString;
    }
    else
    {
      localWorkspace->mutableRun().addLogData(l_PropertyString);
      delete l_PropertyDouble;
    }
    prog.report();
  } // end for


  // operation was a success and ended normally
  return;
}