Mantid
Loading...
Searching...
No Matches
BoxControllerNeXusIO.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2008 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
11#include "MantidDataObjects/DllConfig.h"
13#include <nexus/NeXusFile.hpp>
14
15#include <mutex>
16
17namespace Mantid {
18namespace DataObjects {
19
20//===============================================================================================
27class MANTID_DATAOBJECTS_DLL BoxControllerNeXusIO : public API::IBoxControllerIO {
28public:
30
32 bool isOpened() const override { return m_File.get() != nullptr; }
34 const std::string &getFileName() const override { return m_fileName; }
36 void copyFileTo(const std::string &destFilename) override;
37
39 size_t getDataChunk() const override { return m_dataChunk; }
40
41 bool openFile(const std::string &fileName, const std::string &mode) override;
42
43 void saveBlock(const std::vector<float> & /* DataBlock */, const uint64_t /*blockPosition*/) const override;
44 void loadBlock(std::vector<float> & /* Block */, const uint64_t /*blockPosition*/,
45 const size_t /*BlockSize*/) const override;
46 void saveBlock(const std::vector<double> & /* DataBlock */, const uint64_t /*blockPosition*/) const override;
47 void loadBlock(std::vector<double> & /* Block */, const uint64_t /*blockPosition*/,
48 const size_t /*BlockSize*/) const override;
49
50 void flushData() const override;
51 void closeFile() override;
52
53 ~BoxControllerNeXusIO() override;
54 // Auxiliary functions. Used to change default state of this object which is
55 // not fully supported. Should be replaced by some IBoxControllerIO factory
56 void setDataType(const size_t blockSize, const std::string &typeName) override;
57 void getDataType(size_t &CoordSize, std::string &typeName) const override;
58 //------------------------------------------------------------------------------------------------------------------------
59 // Auxiliary functions (non-virtual, used for testing)
60 int64_t getNDataColums() const { return m_BlockSize[1]; }
61 // get pointer to the Nexus file --> compatribility testing only.
62 ::NeXus::File *getFile() { return m_File.get(); }
63
77 enum class EventDataVersion : size_t { EDVLean = 2, EDVOriginal = 4, EDVGoniometer = 5 };
78
79 EventDataVersion getEventDataVersion() const { return m_EventDataVersion; }
80
81 void setEventDataVersion(const EventDataVersion &version);
82
87 void setEventDataVersion(const size_t &traitsCount);
88
93 int64_t dataEventCount(void) const;
94
107 template <typename FloatOrDouble>
108 void adjustEventDataBlock(std::vector<FloatOrDouble> &Block, const std::string &accessMode) const;
109
110private:
113 enum { DATA_CHUNK = 10000 };
114
118 std::string m_fileName;
120 std::unique_ptr<::NeXus::File> m_File;
128 //------
131 std::vector<int64_t> m_BlockStart;
134 std::vector<int64_t> m_BlockSize;
136 mutable std::mutex m_fileMutex;
137
138 // Mainly static information which may be split into different IO classes
139 // selected through chein of responsibility.
142 unsigned int m_CoordSize;
147 LeanEvent = 0, //< the event consisting of signal error and event coordinate
148 FatEvent = 1 //< the event having the same as lean event plus RunID and detID
151 } m_EventType;
152
154 std::string m_EventsVersion;
155
158
161 std::vector<std::string> m_EventsTypesSupported;
163 std::vector<std::string> m_EventsTypeHeaders;
164
166 static std::string g_EventGroupName;
168 static std::string g_DBDataName;
169
170 // helper functions:
171 // prepare to write event nexus data in current data version format
172 void CreateEventGroup();
173 void OpenAndCheckEventGroup();
174 void getDiskBufferFileData();
175 void prepareNxSToWrite_CurVersion();
176 void prepareNxSdata_CurVersion();
177 // get the event type from event name
178 static EventType TypeFromString(const std::vector<std::string> &typesSupported, const std::string &typeName);
184 doubleToFolat
186 } m_ReadConversion;
187
188 template <typename Type>
189 void saveGenericBlock(const std::vector<Type> &DataBlock, const uint64_t blockPosition) const;
190
199 template <typename Type>
200 void loadGenericBlock(std::vector<Type> &Block, const uint64_t blockPosition, const size_t nPoints) const;
201};
202} // namespace DataObjects
203} // namespace Mantid
This class is used by MDBox and MDGridBox in order to intelligently determine optimal behavior.
Definition: BoxController.h:33
The header describes interface to IO Operations perfomed by the box controller May be replaced by a b...
DataBlock: The DataBlock class holds information about a contiguous block of spectrum numbers.
Definition: DataBlock.h:26
The class responsible for saving events into nexus file using generic box controller interface Expect...
EventDataVersion
The version of the "event_data" Nexus dataset.
bool m_ReadOnly
identifier if the file open only for reading or is in read/write
std::vector< std::string > m_EventsTypeHeaders
data headers used for different events types
EventDataVersion m_EventDataVersion
"data_event" dataset version in the current Nexus file
CoordConversion
the enum, which suggests the way (currently)two possible data types are converted to each other
std::string m_fileName
full file name (with path) of the Nexis file responsible for the IO operations (as NeXus filename has...
std::unique_ptr<::NeXus::File > m_File
the file Handler responsible for Nexus IO operations;
std::vector< int64_t > m_BlockStart
the start of the current data block to read from.
size_t m_dataChunk
The size of the events block which can be written in the neXus array at once (continuous part of the ...
const std::string & getFileName() const override
get the full file name of the file used for IO operations
static std::string g_DBDataName
the group name to save disk buffer data
EventType
possible event types this class understands.
std::string m_EventsVersion
The version of the md events data block.
size_t getDataChunk() const override
Return the size of the NeXus data block used in NeXus data array.
static std::string g_EventGroupName
the name of the Nexus data group for saving the events
API::BoxController *const m_bc
shared pointer to the box controller, which is repsoponsible for this IO
unsigned int m_CoordSize
number of bytes in the event coordinates (coord_t length).
std::vector< std::string > m_EventsTypesSupported
the symbolic description of the event types currently supported by the class
std::vector< int64_t > m_BlockSize
the vector, which describes the event specific data size, namely how many column an event is composed...
std::mutex m_fileMutex
lock Nexus file operations as Nexus is not thread safe
Helper class which provides the Collimation Length for SANS instruments.