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"
12#include "MantidNexus/NexusFile.h"
13
14#include <mutex>
15
16namespace Mantid {
17namespace DataObjects {
18
19//===============================================================================================
26class MANTID_DATAOBJECTS_DLL BoxControllerNeXusIO : public API::IBoxControllerIO {
27public:
29
31 bool isOpened() const override { return m_File.get() != nullptr; }
33 const std::string &getFileName() const override { return m_fileName; }
35 void copyFileTo(const std::string &destFilename) override;
36
38 size_t getDataChunk() const override { return m_dataChunk; }
39
40 bool openFile(const std::string &fileName, const std::string &mode) override;
41
42 void saveBlock(const std::vector<float> & /* DataBlock */, const uint64_t /*blockPosition*/) const override;
43 void loadBlock(std::vector<float> & /* Block */, const uint64_t /*blockPosition*/,
44 const size_t /*BlockSize*/) const override;
45 void saveBlock(const std::vector<double> & /* DataBlock */, const uint64_t /*blockPosition*/) const override;
46 void loadBlock(std::vector<double> & /* Block */, const uint64_t /*blockPosition*/,
47 const size_t /*BlockSize*/) const override;
48
49 void flushData() const override;
50 void closeFile() override;
51
52 ~BoxControllerNeXusIO() override;
53 // Auxiliary functions. Used to change default state of this object which is
54 // not fully supported. Should be replaced by some IBoxControllerIO factory
55 void setDataType(const size_t blockSize, const std::string &typeName) override;
56 void getDataType(size_t &CoordSize, std::string &typeName) const override;
57 //------------------------------------------------------------------------------------------------------------------------
58 // Auxiliary functions (non-virtual, used for testing)
59 int64_t getNDataColums() const { return m_BlockSize[1]; }
60 // get pointer to the Nexus file --> compatribility testing only.
61 Nexus::File *getFile() { return m_File.get(); }
62
76 enum class EventDataVersion : size_t { EDVLean = 2, EDVOriginal = 4, EDVGoniometer = 5 };
77
78 EventDataVersion getEventDataVersion() const { return m_EventDataVersion; }
79
80 void setEventDataVersion(const EventDataVersion &version);
81
86 void setEventDataVersion(const size_t &traitsCount);
87
92 uint64_t dataEventCount(void) const;
93
106 template <typename FloatOrDouble>
107 void adjustEventDataBlock(std::vector<FloatOrDouble> &Block, const std::string &accessMode) const;
108
109private:
112 enum { DATA_CHUNK = 10000 };
113
117 std::string m_fileName;
119 std::unique_ptr<Nexus::File> m_File;
127 //------
135 mutable std::mutex m_fileMutex;
136
137 // Mainly static information which may be split into different IO classes
138 // selected through chein of responsibility.
141 unsigned int m_CoordSize;
146 LeanEvent = 0, //< the event consisting of signal error and event coordinate
147 FatEvent = 1 //< the event having the same as lean event plus RunID and detID
150 } m_EventType;
151
153 std::string m_EventsVersion;
154
157
160 std::vector<std::string> m_EventsTypesSupported;
162 std::vector<std::string> m_EventsTypeHeaders;
163
165 static std::string g_EventGroupName;
167 static std::string g_DBDataName;
168
169 // helper functions:
170 // prepare to write event nexus data in current data version format
171 void CreateEventGroup();
172 void OpenAndCheckEventGroup();
173 void getDiskBufferFileData();
174 void prepareNxSToWrite_CurVersion();
175 void prepareNxSdata_CurVersion();
176 // get the event type from event name
177 static EventType TypeFromString(const std::vector<std::string> &typesSupported, const std::string &typeName);
183 doubleToFolat
185 } m_ReadConversion;
186
187 template <typename Type>
188 void saveGenericBlock(const std::vector<Type> &DataBlock, const uint64_t blockPosition) const;
189
191 template <typename Type>
192 void loadGenericBlock(std::vector<Type> &Block, const uint64_t blockPosition, const size_t nPoints) const;
193};
194} // namespace DataObjects
195} // namespace Mantid
This class is used by MDBox and MDGridBox in order to intelligently determine optimal behavior.
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:28
The class responsible for saving events into nexus file using generic box controller interface Expect...
Nexus::DimVector m_BlockSize
the vector, which describes the event specific data size, namely how many column an event is composed...
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...
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.
Nexus::DimVector m_BlockStart
the start of the current data block to read from.
std::string m_EventsVersion
The version of the md events data block.
std::unique_ptr< Nexus::File > m_File
the file Handler responsible for Nexus IO operations;
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::mutex m_fileMutex
lock Nexus file operations as Nexus is not thread safe
std::vector< dimsize_t > DimVector
Helper class which provides the Collimation Length for SANS instruments.