Commit 4f1fa389 authored by David Fairbrother's avatar David Fairbrother
Browse files

Fix missing assignment op / copy ctor

Fixes instances with missing assignment operator or copy constructor.
These are dangerous cases with dynamic memory as it's not obvious what
will happen, but the compiler will try anyway.

In many cases we can simply switch to unique_ptr or disable the copy
when it makes sense. But one or two cases required additional thought.

This fixes several memory leaks or sources of corruption if the fields
fall out of sync
parent c821b9f4
......@@ -48,7 +48,7 @@ public:
virtual ~ImplicitFunctionParameter() = default;
protected:
bool m_isValid;
bool m_isValid{false};
std::string parameterXMLTemplate(const std::string &valueXMLtext) const {
using namespace Poco::XML;
......
......@@ -28,20 +28,14 @@ public:
/// Constructor with vector of DateAndTime
BankPulseTimes(const std::vector<Mantid::Types::Core::DateAndTime> &times);
/// Destructor
~BankPulseTimes();
/// Equals
bool equals(size_t otherNumPulse, const std::string &otherStartTime);
/// String describing the start time
std::string startTime;
/// Size of the array of pulse times
size_t numPulses;
/// Array of the pulse times
Mantid::Types::Core::DateAndTime *pulseTimes;
std::vector<Mantid::Types::Core::DateAndTime> pulseTimes;
/// Vector of period numbers corresponding to each pulse
std::vector<int> periodNumbers;
......
......@@ -151,6 +151,10 @@ public:
FastReadOnlyFile(const char *filename);
~FastReadOnlyFile();
// Prevent copying of a file handle
FastReadOnlyFile(const FastReadOnlyFile &) = delete;
FastReadOnlyFile &operator=(FastReadOnlyFile) = delete;
// properties
void *handle() const;
......
......@@ -12,6 +12,7 @@
#include <nexus/NeXusFile.hpp>
#include <climits>
#include <memory>
namespace Mantid {
namespace DataHandling {
......@@ -52,7 +53,7 @@ private:
/// Overwrites Algorithm method
void exec() override;
ISISRAW2 m_isisRaw;
std::unique_ptr<ISISRAW2> m_isisRaw;
NXhandle handle;
FILE *rawFile;
std::vector<int> monitorData;
......
......@@ -39,32 +39,28 @@ BankPulseTimes::BankPulseTimes(::NeXus::File &file, const std::vector<int> &pNum
file.getData(seconds);
file.closeData();
// Now create the pulseTimes
numPulses = seconds.size();
if (numPulses == 0)
if (seconds.size() == 0)
throw std::runtime_error("event_time_zero field has no data!");
pulseTimes = new Mantid::Types::Core::DateAndTime[numPulses];
for (size_t i = 0; i < numPulses; i++)
pulseTimes[i] = start + seconds[i];
std::transform(seconds.cbegin(), seconds.cend(), std::back_inserter(pulseTimes),
[start](double seconds) { return start + seconds; });
} else if (heldTimeZeroType == ::NeXus::UINT64) {
std::vector<uint64_t> nanoseconds;
file.getData(nanoseconds);
file.closeData();
// Now create the pulseTimes
numPulses = nanoseconds.size();
if (numPulses == 0)
if (nanoseconds.size() == 0)
throw std::runtime_error("event_time_zero field has no data!");
pulseTimes = new Mantid::Types::Core::DateAndTime[numPulses];
for (size_t i = 0; i < numPulses; i++)
pulseTimes[i] = start + int64_t(nanoseconds[i]);
std::transform(nanoseconds.cbegin(), nanoseconds.cend(), std::back_inserter(pulseTimes),
[start](int64_t nanoseconds) { return start + nanoseconds; });
} else {
throw std::invalid_argument("Unsupported type for event_time_zero");
}
// Ensure that we always have a consistency between nPulses and
// periodNumbers containers
if (numPulses != pNumbers.size()) {
periodNumbers = std::vector<int>(numPulses, FirstPeriod);
if (pulseTimes.size() != pNumbers.size()) {
periodNumbers = std::vector<int>(pulseTimes.size(), FirstPeriod);
;
}
}
......@@ -75,19 +71,12 @@ BankPulseTimes::BankPulseTimes(::NeXus::File &file, const std::vector<int> &pNum
* @param times
*/
BankPulseTimes::BankPulseTimes(const std::vector<Mantid::Types::Core::DateAndTime> &times) {
numPulses = times.size();
pulseTimes = nullptr;
if (numPulses == 0)
if (times.size() == 0)
return;
pulseTimes = new Mantid::Types::Core::DateAndTime[numPulses];
periodNumbers = std::vector<int>(numPulses, FirstPeriod); // TODO we are fixing this at 1 period for all
for (size_t i = 0; i < numPulses; i++)
pulseTimes[i] = times[i];
}
//----------------------------------------------------------------------------------------------
/** Destructor */
BankPulseTimes::~BankPulseTimes() { delete[] this->pulseTimes; }
pulseTimes = times;
periodNumbers = std::vector<int>(pulseTimes.size(), FirstPeriod); // TODO we are fixing this at 1 period for all
}
//----------------------------------------------------------------------------------------------
/** Comparison. Is this bank's pulse times array the same as another one.
......@@ -99,5 +88,5 @@ BankPulseTimes::~BankPulseTimes() { delete[] this->pulseTimes; }
* reloaded.
*/
bool BankPulseTimes::equals(size_t otherNumPulse, const std::string &otherStartTime) {
return ((this->startTime == otherStartTime) && (this->numPulses == otherNumPulse));
return ((this->startTime == otherStartTime) && (this->pulseTimes.size() == otherNumPulse));
}
......@@ -154,7 +154,7 @@ void EventAssignerFixedWavelength::addEventImpl(size_t id, int64_t pulse, double
m_eventVectors[id]->emplace_back(m_wavelength);
}
// FastReadOnlyFile
// ISISRawOnlyFile
#ifdef _WIN32
FastReadOnlyFile::FastReadOnlyFile(const char *filename) {
m_handle = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
......
......@@ -55,7 +55,7 @@ void LoadBankFromDiskTask::loadPulseTimes(::NeXus::File &file) {
return;
}
std::string thisStartTime;
size_t thisNumPulses = 0;
size_t thispulseTimes = 0;
// If the offset is not present, use Unix epoch
if (!file.hasAttr("offset")) {
thisStartTime = "1970-01-01T00:00:00Z";
......@@ -66,13 +66,13 @@ void LoadBankFromDiskTask::loadPulseTimes(::NeXus::File &file) {
}
if (!file.getInfo().dims.empty())
thisNumPulses = file.getInfo().dims[0];
thispulseTimes = file.getInfo().dims[0];
file.closeData();
// Now, we look through existing ones to see if it is already loaded
// thisBankPulseTimes = NULL;
for (auto &bankPulseTime : m_loader.m_bankPulseTimes) {
if (bankPulseTime->equals(thisNumPulses, thisStartTime)) {
if (bankPulseTime->equals(thispulseTimes, thisStartTime)) {
thisBankPulseTimes = bankPulseTime;
return;
}
......@@ -131,7 +131,7 @@ void LoadBankFromDiskTask::prepareEventId(::NeXus::File &file, int64_t &start_ev
stop_event = dim0;
// Handle the time filtering by changing the start/end offsets.
for (size_t i = 0; i < thisBankPulseTimes->numPulses; i++) {
for (size_t i = 0; i < thisBankPulseTimes->pulseTimes.size(); i++) {
if (thisBankPulseTimes->pulseTimes[i] >= m_loader.alg->filter_time_start) {
start_event = static_cast<int64_t>(event_index[i]);
break; // stop looking
......@@ -150,7 +150,7 @@ void LoadBankFromDiskTask::prepareEventId(::NeXus::File &file, int64_t &start_ev
start_event = 0;
stop_event = dim0;
} else {
for (size_t i = 0; i < thisBankPulseTimes->numPulses; i++) {
for (size_t i = 0; i < thisBankPulseTimes->pulseTimes.size(); i++) {
if (thisBankPulseTimes->pulseTimes[i] > m_loader.alg->filter_time_stop) {
stop_event = event_index[i];
break;
......@@ -353,7 +353,7 @@ void LoadBankFromDiskTask::run() {
// The event_index should be the same length as the pulse times from DAS
// logs.
if (event_index.size() != thisBankPulseTimes->numPulses)
if (event_index.size() != thisBankPulseTimes->pulseTimes.size())
m_loader.alg->getLogger().warning() << "Bank " << entry_name
<< " has a mismatch between the number of event_index entries "
"and the number of pulse times in event_time_zero.\n";
......
......@@ -985,7 +985,7 @@ void LoadEventNexus::loadEvents(API::Progress *const prog, const bool monitors)
filter_time_start = Types::Core::DateAndTime::minimum();
filter_time_stop = Types::Core::DateAndTime::maximum();
if (m_allBanksPulseTimes->numPulses > 0) {
if (m_allBanksPulseTimes->pulseTimes.size() > 0) {
// If not specified, use the limits of doubles. Otherwise, convert from
// seconds to absolute PulseTime
if (filter_time_start_sec != EMPTY_DBL()) {
......
......@@ -353,6 +353,11 @@ public:
virtual ~ISISRAW();
explicit ISISRAW(ISISCRPT_STRUCT *crpt);
ISISRAW(ISISCRPT_STRUCT *crpt, bool doUpdateFromCRPT);
// Explicitly prevent copying with all the dynamic allocations
ISISRAW(const ISISRAW &) = delete;
ISISRAW &operator=(ISISRAW) = delete;
int updateFromCRPT();
virtual int ioRAW(FILE *file, bool from_file, bool read_data = true);
......
......@@ -104,12 +104,12 @@ void ProcessBankData::run() { // override {
// Default pulse time (if none are found)
const bool pulsetimesincreasing =
std::is_sorted(thisBankPulseTimes->pulseTimes, thisBankPulseTimes->pulseTimes + thisBankPulseTimes->numPulses);
std::is_sorted(thisBankPulseTimes->pulseTimes.cbegin(), thisBankPulseTimes->pulseTimes.cend());
if (!std::is_sorted(event_index->cbegin(), event_index->cend()))
throw std::runtime_error("Event index is not sorted");
// And there are this many pulses
const auto NUM_PULSES = thisBankPulseTimes->numPulses;
const auto NUM_PULSES = thisBankPulseTimes->pulseTimes.size();
prog->report(entry_name + ": filling events");
// Will we need to compress?
......
......@@ -28,6 +28,7 @@
#include <fstream>
#include <iterator>
#include <map>
#include <memory>
#include <sstream>
namespace Mantid::DataHandling {
......@@ -40,8 +41,9 @@ using namespace API;
/// Empty default constructor
SaveISISNexus::SaveISISNexus()
: Algorithm(), m_isisRaw(), handle(), rawFile(), nper(0), nsp(0), ntc(0), nmon(0), ndet(0), counts_link(),
period_index_link(), spectrum_index_link(), time_of_flight_link(), time_of_flight_raw_link() {}
: Algorithm(), m_isisRaw(std::make_unique<ISISRAW2>()), handle(), rawFile(), nper(0), nsp(0), ntc(0), nmon(0),
ndet(0), counts_link(), period_index_link(), spectrum_index_link(), time_of_flight_link(),
time_of_flight_raw_link() {}
/** Initialisation method.
*
......@@ -97,18 +99,18 @@ void SaveISISNexus::exec() {
// Retrieve the filename from the properties
inputFilename = getPropertyValue("InputFileName");
m_isisRaw = ISISRAW2();
m_isisRaw = std::make_unique<ISISRAW2>();
rawFile = fopen(inputFilename.c_str(), "rb");
if (rawFile == nullptr) {
throw Exception::FileError("Cannot open file ", inputFilename);
}
m_isisRaw.ioRAW(rawFile, true);
m_isisRaw->ioRAW(rawFile, true);
nper = m_isisRaw.t_nper; // number of periods
nsp = m_isisRaw.t_nsp1; // number of spectra
ntc = m_isisRaw.t_ntc1; // number of time channels
nmon = m_isisRaw.i_mon; // number of monitors
ndet = m_isisRaw.i_det; // number of detectors
nper = m_isisRaw->t_nper; // number of periods
nsp = m_isisRaw->t_nsp1; // number of spectra
ntc = m_isisRaw->t_ntc1; // number of time channels
nmon = m_isisRaw->i_mon; // number of monitors
ndet = m_isisRaw->i_det; // number of detectors
std::string outputFilename = getPropertyValue("OutputFileName");
......@@ -124,7 +126,7 @@ void SaveISISNexus::exec() {
write_isis_vms_compat();
saveString("beamline", " ");
flt = static_cast<float>(m_isisRaw.rpb.r_dur); // could be wrong
flt = static_cast<float>(m_isisRaw->rpb.r_dur); // could be wrong
saveFloatOpen("collection_time", &flt, 1);
putAttr("units", "second");
close();
......@@ -139,32 +141,32 @@ void SaveISISNexus::exec() {
putAttr("url", "http://svn.isis.rl.ac.uk/instruments/ISISTOFRAW/?version=1.0");
close();
flt = static_cast<float>(m_isisRaw.rpb.r_dur);
flt = static_cast<float>(m_isisRaw->rpb.r_dur);
saveFloatOpen("duration", &flt, 1);
putAttr("units", "second");
close();
start_time_str.assign(m_isisRaw.hdr.hd_date, m_isisRaw.hdr.hd_date + 12);
start_time_str.assign(m_isisRaw->hdr.hd_date, m_isisRaw->hdr.hd_date + 12);
toISO8601(start_time_str);
start_time_str += 'T';
start_time_str += std::string(m_isisRaw.hdr.hd_time, m_isisRaw.hdr.hd_time + 8);
start_time_str += std::string(m_isisRaw->hdr.hd_time, m_isisRaw->hdr.hd_time + 8);
saveCharOpen("start_time", &start_time_str[0], 19);
putAttr("units", "ISO8601");
close();
std::string str;
str.assign(m_isisRaw.rpb.r_enddate, m_isisRaw.rpb.r_enddate + 12);
str.assign(m_isisRaw->rpb.r_enddate, m_isisRaw->rpb.r_enddate + 12);
toISO8601(str);
str += 'T';
str += std::string(m_isisRaw.rpb.r_endtime, m_isisRaw.rpb.r_endtime + 8);
str += std::string(m_isisRaw->rpb.r_endtime, m_isisRaw->rpb.r_endtime + 8);
saveCharOpen("end_time", &str[0], 19);
putAttr("units", "ISO8601");
close();
saveChar("title", m_isisRaw.r_title, 80);
saveInt("good_frames", &m_isisRaw.rpb.r_goodfrm);
saveChar("title", m_isisRaw->r_title, 80);
saveInt("good_frames", &m_isisRaw->rpb.r_goodfrm);
std::string experiment_identifier = std::to_string(m_isisRaw.rpb.r_prop);
std::string experiment_identifier = std::to_string(m_isisRaw->rpb.r_prop);
saveChar("experiment_identifier", &experiment_identifier[0], static_cast<int>(experiment_identifier.size()));
int tmp_int(0);
saveInt("measurement_first_run", &tmp_int);
......@@ -173,27 +175,27 @@ void SaveISISNexus::exec() {
saveString("measurement_subid", " ");
saveString("measurement_type", " ");
saveCharOpen("name", &m_isisRaw.i_inst, 8);
putAttr("short_name", m_isisRaw.hdr.inst_abrv, 3);
saveCharOpen("name", &m_isisRaw->i_inst, 8);
putAttr("short_name", m_isisRaw->hdr.inst_abrv, 3);
close();
logNotes();
saveString("program_name", "isisicp");
saveFloatOpen("proton_charge", &m_isisRaw.rpb.r_gd_prtn_chrg, 1);
saveFloatOpen("proton_charge", &m_isisRaw->rpb.r_gd_prtn_chrg, 1);
putAttr("units", "uamp.hour");
close();
saveFloatOpen("proton_charge_raw", &m_isisRaw.rpb.r_tot_prtn_chrg, 1);
saveFloatOpen("proton_charge_raw", &m_isisRaw->rpb.r_tot_prtn_chrg, 1);
putAttr("units", "uamp.hour");
close();
saveInt("raw_frames", &m_isisRaw.rpb.r_rawfrm);
saveInt("raw_frames", &m_isisRaw->rpb.r_rawfrm);
run_cycle();
saveInt("run_number", &m_isisRaw.r_number);
saveInt("run_number", &m_isisRaw->r_number);
// script_name
// seci_config
......@@ -383,67 +385,67 @@ void SaveISISNexus::toISO8601(std::string &str) {
void SaveISISNexus::write_isis_vms_compat() {
NXmakegroup(handle, "isis_vms_compat", "IXvms");
NXopengroup(handle, "isis_vms_compat", "IXvms");
int ndet = m_isisRaw.i_det;
int nmon = m_isisRaw.i_mon;
int ndet = m_isisRaw->i_det;
int nmon = m_isisRaw->i_mon;
saveInt("ADD", &m_isisRaw.add, 9);
saveInt("CODE", m_isisRaw.code, ndet);
saveInt("CRAT", m_isisRaw.crat, ndet);
saveInt("ADD", &m_isisRaw->add, 9);
saveInt("CODE", m_isisRaw->code, ndet);
saveInt("CRAT", m_isisRaw->crat, ndet);
write_rpb();
write_spb();
write_vpb();
saveInt("DAEP", &m_isisRaw.daep, 64);
saveInt("DELT", m_isisRaw.delt, ndet);
saveInt("FORM", &m_isisRaw.data_format);
saveChar("HDR", &m_isisRaw.hdr, 80);
saveFloat("LEN2", m_isisRaw.len2, ndet);
saveInt("MDET", m_isisRaw.mdet, nmon);
saveInt("MODN", m_isisRaw.modn, ndet);
saveInt("MONP", m_isisRaw.monp, nmon);
saveInt("MPOS", m_isisRaw.mpos, ndet);
saveChar("NAME", m_isisRaw.i_inst, 8);
saveInt("DAEP", &m_isisRaw->daep, 64);
saveInt("DELT", m_isisRaw->delt, ndet);
saveInt("FORM", &m_isisRaw->data_format);
saveChar("HDR", &m_isisRaw->hdr, 80);
saveFloat("LEN2", m_isisRaw->len2, ndet);
saveInt("MDET", m_isisRaw->mdet, nmon);
saveInt("MODN", m_isisRaw->modn, ndet);
saveInt("MONP", m_isisRaw->monp, nmon);
saveInt("MPOS", m_isisRaw->mpos, ndet);
saveChar("NAME", m_isisRaw->i_inst, 8);
saveInt("NDET", &ndet);
saveInt("NFPP", &m_isisRaw.t_nfpp);
saveInt("NFPP", &m_isisRaw->t_nfpp);
saveInt("NMON", &nmon);
saveInt("NPER", &m_isisRaw.t_nper);
saveInt("NSER", &m_isisRaw.e_nse);
saveInt("NSP1", &m_isisRaw.t_nsp1);
saveInt("NTC1", &m_isisRaw.t_ntc1);
saveInt("NTRG", &m_isisRaw.t_ntrg);
saveInt("NUSE", &m_isisRaw.i_use);
saveInt("PMAP", &m_isisRaw.t_pmap, 256);
saveInt("PRE1", &m_isisRaw.t_pre1);
saveInt("RUN", &m_isisRaw.r_number);
saveInt("SPEC", m_isisRaw.spec, ndet);
saveInt("TCM1", &m_isisRaw.t_tcm1);
saveFloat("TCP1", m_isisRaw.t_tcp1, 20);
saveInt("TIMR", m_isisRaw.timr, ndet);
saveChar("TITL", m_isisRaw.r_title, 80);
saveFloat("TTHE", m_isisRaw.tthe, ndet);
saveInt("UDET", m_isisRaw.udet, ndet);
saveInt("ULEN", &m_isisRaw.u_len);
saveInt("NPER", &m_isisRaw->t_nper);
saveInt("NSER", &m_isisRaw->e_nse);
saveInt("NSP1", &m_isisRaw->t_nsp1);
saveInt("NTC1", &m_isisRaw->t_ntc1);
saveInt("NTRG", &m_isisRaw->t_ntrg);
saveInt("NUSE", &m_isisRaw->i_use);
saveInt("PMAP", &m_isisRaw->t_pmap, 256);
saveInt("PRE1", &m_isisRaw->t_pre1);
saveInt("RUN", &m_isisRaw->r_number);
saveInt("SPEC", m_isisRaw->spec, ndet);
saveInt("TCM1", &m_isisRaw->t_tcm1);
saveFloat("TCP1", m_isisRaw->t_tcp1, 20);
saveInt("TIMR", m_isisRaw->timr, ndet);
saveChar("TITL", m_isisRaw->r_title, 80);
saveFloat("TTHE", m_isisRaw->tthe, ndet);
saveInt("UDET", m_isisRaw->udet, ndet);
saveInt("ULEN", &m_isisRaw->u_len);
std::string user_info(160, ' ');
if (m_isisRaw.u_len > 0) {
std::copy(reinterpret_cast<char *>(&m_isisRaw.user), reinterpret_cast<char *>(&m_isisRaw.user) + m_isisRaw.u_len,
if (m_isisRaw->u_len > 0) {
std::copy(reinterpret_cast<char *>(&m_isisRaw->user), reinterpret_cast<char *>(&m_isisRaw->user) + m_isisRaw->u_len,
user_info.begin());
}
saveString("USER", user_info);
saveInt("VER1", &m_isisRaw.frmt_ver_no);
saveInt("VER2", &m_isisRaw.ver2);
saveInt("VER3", &m_isisRaw.ver3);
saveInt("VER4", &m_isisRaw.ver4);
saveInt("VER5", &m_isisRaw.ver5);
saveInt("VER6", &m_isisRaw.ver6);
saveInt("VER7", &m_isisRaw.ver7);
saveInt("VER8", &m_isisRaw.ver8);
saveInt("VER1", &m_isisRaw->frmt_ver_no);
saveInt("VER2", &m_isisRaw->ver2);
saveInt("VER3", &m_isisRaw->ver3);
saveInt("VER4", &m_isisRaw->ver4);
saveInt("VER5", &m_isisRaw->ver5);
saveInt("VER6", &m_isisRaw->ver6);
saveInt("VER7", &m_isisRaw->ver7);
saveInt("VER8", &m_isisRaw->ver8);
int tmp_int(0);
saveInt("VER9", &tmp_int);
int n = m_isisRaw.logsect.nlines;
int n = m_isisRaw->logsect.nlines;
log_notes.resize(n);
for (int i = 0; i < n; ++i) {
log_notes[i].assign(m_isisRaw.logsect.lines[i].data, m_isisRaw.logsect.lines[i].len);
log_notes[i].assign(m_isisRaw->logsect.lines[i].data, m_isisRaw->logsect.lines[i].len);
}
int ll = saveStringVectorOpen("NOTE", log_notes);
saveInt("NTNL", &n);
......@@ -455,8 +457,8 @@ void SaveISISNexus::write_isis_vms_compat() {
void SaveISISNexus::instrument() {
NXmakegroup(handle, "instrument", "NXinstrument");
NXopengroup(handle, "instrument", "NXinstrument");
saveCharOpen("name", &m_isisRaw.i_inst, 8);
putAttr("short_name", m_isisRaw.hdr.inst_abrv, 3);
saveCharOpen("name", &m_isisRaw->i_inst, 8);
putAttr("short_name", m_isisRaw->hdr.inst_abrv, 3);
close();
dae();
detector_1();
......@@ -470,7 +472,8 @@ void SaveISISNexus::detector_1() {
NXopengroup(handle, "detector_1", "NXdata");
for (int i = 0; i < nmon; ++i) {
auto si = int(std::distance(m_isisRaw.spec, std::find(m_isisRaw.spec, m_isisRaw.spec + nsp, m_isisRaw.mdet[i])));
auto si =
int(std::distance(m_isisRaw->spec, std::find(m_isisRaw->spec, m_isisRaw->spec + nsp, m_isisRaw->mdet[i])));
monitor_index[si] = i;
}
......@@ -489,15 +492,15 @@ void SaveISISNexus::detector_1() {
int index = 0;
for (int p = 0; p < nper; ++p) {
int ispec = 0;
m_isisRaw.skipData(rawFile, index++);
m_isisRaw->skipData(rawFile, index++);
for (int si = 0; si < nsp; ++si) {
if (monitor_index.find(si) != monitor_index.end()) {
m_isisRaw.readData(rawFile, index);
monitorData.insert(monitorData.end(), m_isisRaw.dat1 + 1, m_isisRaw.dat1 + ntc + 1);
m_isisRaw->readData(rawFile, index);
monitorData.insert(monitorData.end(), m_isisRaw->dat1 + 1, m_isisRaw->dat1 + ntc + 1);
} else {
m_isisRaw.readData(rawFile, index);
m_isisRaw->readData(rawFile, index);
int start[] = {p, ispec, 0};
NXputslab(handle, m_isisRaw.dat1 + 1, start, size);
NXputslab(handle, m_isisRaw->dat1 + 1, start, size);
++ispec;
}
++index;
......@@ -509,7 +512,7 @@ void SaveISISNexus::detector_1() {
NXmakelink(handle, &period_index_link);
std::vector<int> spec_minus_monitors(nsp - nmon);
std::generate(spec_minus_monitors.begin(), spec_minus_monitors.end(), getWithoutMonitors<int>(this, m_isisRaw.spec));
std::generate(spec_minus_monitors.begin(), spec_minus_monitors.end(), getWithoutMonitors<int>(this, m_isisRaw->spec));
saveIntOpen("spectrum_index", &spec_minus_monitors[0], nsp - nmon);
NXgetdataID(handle, &spectrum_index_link);
close();
......@@ -518,19 +521,19 @@ void SaveISISNexus::detector_1() {
NXmakelink(handle, &time_of_flight_raw_link);
std::vector<float> float_vec(ndet - nmon);
std::generate(float_vec.begin(), float_vec.end(), getWithoutMonitors<float>(this, m_isisRaw.delt));
std::generate(float_vec.begin(), float_vec.end(), getWithoutMonitors<float>(this, m_isisRaw->delt));
saveFloat("delt", &float_vec[0], ndet - nmon);
saveFloat("source_detector_distance", &m_isisRaw.ivpb.i_sddist, 1);
saveFloat("source_detector_distance", &m_isisRaw->ivpb.i_sddist, 1);
// using the same float_vec, size unchanged ndet-nmon
std::generate(float_vec.begin(), float_vec.end(), getWithoutMonitors<float>(this, m_isisRaw.len2));
std::generate(float_vec.begin(), float_vec.end(), getWithoutMonitors<float>(this, m_isisRaw->len2));
saveFloatOpen("distance", &float_vec[0], ndet - nmon);
putAttr("units", "metre");
close();
// using the same float_vec, size unchanged ndet-nmon
std::generate(float_vec.begin(), float_vec.end(), getWithoutMonitors<float>(this, m_isisRaw.tthe));
std::generate(float_vec.begin(), float_vec.end(), getWithoutMonitors<float>(this, m_isisRaw->tthe));
saveFloatOpen("polar_angle", &float_vec[0], ndet - nmon);
putAttr("units", "degree");
close();
......@@ -545,7 +548,7 @@ void SaveISISNexus::moderator() {
NXmakegroup(handle, "moderator", "NXmoderator");
NXopengroup(handle, "moderator", "NXmoderator");
float l1 = -m_isisRaw.ivpb.i_l1;
float l1 = -m_isisRaw->ivpb.i_l1;
saveFloatOpen("distance", &l1, 1);
putAttr("units", "metre");
......@@ -588,11 +591,11 @@ void SaveISISNexus::make_detector_1_link() {
* @param imon Monitor index (not its spectrum number)
*/
int *SaveISISNexus::getMonitorData(int period, int imon) {
return &monitorData[period * m_isisRaw.i_mon * m_isisRaw.t_ntc1 + imon * m_isisRaw.t_ntc1];
return &monitorData[period * m_isisRaw->i_mon * m_isisRaw->t_ntc1 + imon * m_isisRaw->t_ntc1];
}
void SaveISISNexus::write_monitors() {
int nmon = m_isisRaw.i_mon;
int nmon = m_isisRaw->i_mon;
for (int i = 0; i < nmon; ++i) {
monitor_i(i);
}
......@@ -603,8 +606,8 @@ void SaveISISNexus::write_monitors() {
* @param i Index of a monitor
*/
void SaveISISNexus::monitor_i(int i) {
int nper = m_isisRaw.t_nper; // number of periods
int ntc = m_isisRaw.t_ntc1; // number of time channels