SaveISISNexus.h 4.57 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
#include "../../src/LoadRaw/isisraw2.h"
10
11
#include "MantidAPI/Algorithm.h"

12
13
#include <nexus/NeXusFile.hpp>

14
#include <climits>
15
#include <memory>
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace Mantid {
namespace DataHandling {
/**
The SaveISISNexus algorithm will convert a RAW file to a NeXus file.

Required Properties:
<UL>
<LI> InputFilename - The name of and path to the input RAW file </LI>
<LI> OutputFilename - The name of and path to the input NeXus file </LI>
</UL>

@author Roman Tolchenov, Tessella plc
@date 03/03/2011
*/
class DLLExport SaveISISNexus : public API::Algorithm {
public:
  /// Default constructor
  SaveISISNexus();
  /// Algorithm's name for identification overriding a virtual method
36
  const std::string name() const override { return "SaveISISNexus"; };
37
  /// Summary of algorithms purpose
38
  const std::string summary() const override {
39
40
41
42
43
    return "The SaveISISNexus algorithm will convert a RAW file to a NeXus "
           "file.";
  }

  /// Algorithm's version for identification overriding a virtual method
44
  int version() const override { return 1; };
Samuel Jones's avatar
Samuel Jones committed
45
  const std::vector<std::string> seeAlso() const override { return {"SaveNexusProcessed", "SaveNexus", "LoadNexus"}; }
46
  /// Algorithm's category for identification overriding a virtual method
47
  const std::string category() const override { return "DataHandling\\Nexus"; }
48
49
50

private:
  /// Overwrites Algorithm method.
51
  void init() override;
52
53

  /// Overwrites Algorithm method
54
  void exec() override;
55

56
  std::unique_ptr<ISISRAW2> m_isisRaw;
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  NXhandle handle;
  FILE *rawFile;
  std::vector<int> monitorData;
  /// <spectrum_index,monitor_index>. spectrum index is an index in any detector
  /// related array, not spectrum number
  std::map<int, int> monitor_index;
  int nper; ///< number of periods
  int nsp;  ///< number of spectra
  int ntc;  ///< number of time channels
  int nmon; ///< number of monitors
  int ndet; ///< number of detectors
  std::string start_time_str;
  std::vector<std::string> log_notes;

  NXlink counts_link;
  NXlink period_index_link;
  NXlink spectrum_index_link;
  NXlink time_of_flight_link;
  NXlink time_of_flight_raw_link;
  int *getMonitorData(int period, int imon);

  void saveInt(const char *name, void *data, int size = 1);
  void saveChar(const char *name, void *data, int size);
  void saveFloat(const char *name, void *data, int size);
  void saveIntOpen(const char *name, void *data, int size = 1);
  void saveCharOpen(const char *name, void *data, int size);
  void saveFloatOpen(const char *name, void *data, int size);
Samuel Jones's avatar
Samuel Jones committed
84
  int saveStringVectorOpen(const char *name, const std::vector<std::string> &str_vec, int max_str_size = -1);
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  void saveString(const char *name, const std::string &str);
  void saveStringOpen(const char *name, const std::string &str);
  inline void close() { NXclosedata(handle); }       ///< close an open dataset.
  inline void closegroup() { NXclosegroup(handle); } ///< close an open group.
  void putAttr(const char *name, const std::string &value);
  void putAttr(const char *name, char *value, int size);
  void putAttr(const char *name, int value, int size = 1);
  void toISO8601(std::string &str);

  template <typename T> friend class getWithoutMonitors;

  /// Write vms_compat
  void write_isis_vms_compat();
  /// Write monitors
  void write_monitors();
  /// Write single monitor
  void monitor_i(int i);
  /// Write instrument
  void instrument();
  /// Write instrument/detector_1
  void detector_1();
  /// Write instrument/moderator
  void moderator();
  /// Write instrument/dae
  void dae();
  /// Write instrument/source
  void source();
  /// Create a link to some of detector_1's data
  void make_detector_1_link();
  /// Write user
  void user();
  /// Write sample
  void sample();
  /// Write runlog
  void runlog();
  /// write one run log
Samuel Jones's avatar
Samuel Jones committed
121
  void write_runlog(const char *name, void *times, void *data, int type, int size, const std::string &units);
122
  /// write NXlog
Samuel Jones's avatar
Samuel Jones committed
123
  void write_logOpen(const char *name, void *times, void *data, int type, int size, const std::string &units);
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
  /// Write selog
  void selog();
  /// Write notes from LOG_STRUCT
  void logNotes();
  /// Write run cycle
  void run_cycle();
  void write_rpb();
  void write_spb();
  void write_vpb();

  /// The name and path of the input file
  std::string inputFilename;
};

} // namespace DataHandling
139
} // namespace Mantid