MuonNexusReader.h 4.58 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8
9
10

#include "MantidAPI/Algorithm.h"
#include "MantidDataObjects/Workspace2D.h"
11
#include <boost/date_time/posix_time/posix_time.hpp>
12
13
#include <climits>
#include <nexus/NeXusFile.hpp>
14

15
16
// class MuonNexusReader - based on ISISRAW this class implements a simple
// reader for Nexus Muon data files.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class DLLExport MuonNexusReader {
  /** @class MuonNexusReader MuonNexusReader.h

  MuunNexusReader opens a Nexus file and reads certain fields expected for a
  ISIS Muon
      data file (old format). These values are stored for access via
  LoadMuonNexus.

  Required Properties:
  <UL>
  <LI> Filename - The name of and path to the input Nexus file </LI>
  </UL>

  @author Ronald Fowler, based on ISISRAW.
  @date 14/08/2008
  */
private:
34
35
36
37
38
39
  std::string nexus_instrument_name;            ///< name read from nexus file
  std::string nexus_samplename;                 ///< sample name read from Nexus
  int nexusLogCount;                            ///< number of NXlog sections read from file
  std::vector<bool> logType;                    ///< true if i'th log is numeric
  std::vector<std::string> logNames;            ///< stores name read from file
  std::vector<std::string> m_periodInformation; /// stores the information of the periods
40
  void openFirstNXentry(NeXus::File &handle);
Samuel Jones's avatar
Samuel Jones committed
41
42
43
44
45
  bool readMuonLogData(NeXus::File &handle);             ///< method to read the fields of open NXlog section
  std::vector<std::vector<float>> logValues,             ///< array of values for i'th NXlog section
      logTimes;                                          ///< arrys of times for i'th NXlog section
  std::vector<std::vector<std::string>> logStringValues; ///< array of string values for i'th NXlog section
  std::string startTime;                                 ///< string startTime which must be read from Nexus
46
  /// file to base all NXlog times on
Samuel Jones's avatar
Samuel Jones committed
47
48
  std::time_t startTime_time_t;                            ///< startTime in time_t format
  std::time_t to_time_t(const boost::posix_time::ptime &t) ///< convert posix time to time_t
49
50
51
52
53
54
  {
    /**
    Take the input Posix time, subtract the unix epoch, and return the seconds
    as a std::time_t value.
    @param t :: time of interest as ptime
    @return :: time_t value of t
55
    */
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    if (t == boost::posix_time::neg_infin)
      return 0;
    else if (t == boost::posix_time::pos_infin)
      return LONG_MAX;
    boost::posix_time::ptime start(boost::gregorian::date(1970, 1, 1));
    return (t - start).total_seconds();
  }

public:
  /// Default constructor
  MuonNexusReader();
  /// Destructor
  ~MuonNexusReader();

  void readFromFile(const std::string &filename); ///< read histogram data
  void readLogData(const std::string &filename);  ///< read log data
72
73
  void getTimeChannels(float *timebnds,
                       const int &nbnds) const; ///< get time bin boundaries
Lamar Moore's avatar
Lamar Moore committed
74
                                                /// return sample name
75
  std::string getSampleName() const { return nexus_samplename; };
Samuel Jones's avatar
Samuel Jones committed
76
  int numberOfLogs() const;                  ///< Number of NXlog sections read from file
77
78
  int getLogLength(const int i) const;       ///< Lenght of i'th log
  std::string getLogName(const int i) const; ///< Name of i'th log
Samuel Jones's avatar
Samuel Jones committed
79
  void getLogValues(const int &logNumber, const int &logSequence, std::time_t &logTime,
80
                    double &value); ///< get logSequence pair of logNumber log
Samuel Jones's avatar
Samuel Jones committed
81
82
83
  void getLogStringValues(const int &logNumber, const int &logSequence, std::time_t &logTime,
                          std::string &value); ///< get logSequence pair of logNumber string log
  bool logTypeNumeric(const int i) const;      ///< true if i'th log is of numeric type
84
85
86
87
88
  // following ISISRAW.h
  int t_nsp1; ///< number of spectra in time regime 1
  int t_ntc1; ///< number of time channels in time regime 1
  int t_nper; ///< number of periods in file (=1 at present)
  // for nexus histogram data
89
90
91
92
93
  float *corrected_times;                         ///< temp store for corrected times
  int *counts;                                    ///< temp store of histogram data
  int *detectorGroupings;                         ///< detector grouping info
  int numDetectors;                               ///< detector count
  std::string getInstrumentName() const;          ///< return instrument name
94
  std::vector<std::string> getPeriodInfo() const; /// Return period information
95
};