13#include <Poco/Thread.h>
16#include <nexus/NeXusFile.hpp>
42 std::initializer_list<std::string> exts = {
".nxs"};
45 "The name of the Nexus file to write.");
48 "The name of the Nexus file to load (optional).\n"
49 "Must have been written by NexusTester algorithm.");
51 declareProperty(
"ChunkSize", 10,
"Chunk size for writing/loading, in kb of data");
56 "Clear the linux disk cache before loading.\n"
57 "Only works on linux AND you need to run MantidPlot in sudo mode (!).");
59 std::vector<std::string> types{
"Zeros",
"Incrementing Numbers",
"Random Numbers"};
60 declareProperty(
"FakeData",
"Incrementing Numbers", std::make_shared<StringListValidator>(types),
61 "For writing: type of fake data to generate.");
63 declareProperty(
"CompressionFactor", 0.0,
"The size of the file divided by the the size of the data on disk.",
81 throw std::invalid_argument(
"ChunkSize must be > 0");
83 throw std::invalid_argument(
"NumChunks must be > 0");
86 size_t chunkSize = ChunkSizeKb * 1024 /
sizeof(uint32_t);
88 auto fakeData = std::vector<uint32_t>(chunkSize);
89 if (FakeDataType ==
"Zeros") {
90 for (
size_t i = 0; i < chunkSize; i++)
92 }
else if (FakeDataType ==
"Incrementing Numbers") {
93 for (
size_t i = 0; i < chunkSize; i++)
94 fakeData[i] = uint32_t(i);
95 }
else if (FakeDataType ==
"Random Numbers") {
96 for (
size_t i = 0; i < chunkSize; i++)
100 std::vector<int64_t> dims;
101 dims.emplace_back(int64_t(chunkSize) * NumChunks);
102 std::vector<int64_t> chunkDims;
103 chunkDims.emplace_back(int64_t(chunkSize));
106 double dataSizeMB = double(chunkSize * NumChunks *
sizeof(uint32_t)) / (1024. * 1024.);
107 g_log.
notice() <<
"Data size is " << dataSizeMB <<
" MB\n";
110 if (!SaveFilename.empty()) {
111 ::NeXus::File file(SaveFilename, NXACC_CREATE5);
112 file.makeGroup(
"FakeDataGroup",
"NXdata",
true);
113 file.makeCompData(
"FakeData", ::NeXus::UINT32, dims, Compress ? ::NeXus::LZW : ::NeXus::NONE, chunkDims,
true);
114 Progress prog(
this, 0.0, 1.0, NumChunks);
116 for (
int i = 0; i < NumChunks; i++) {
117 std::vector<int64_t> startDims;
118 startDims.emplace_back(i * int64_t(chunkSize));
119 file.putSlab(fakeData.data(), startDims, chunkDims);
124 double MBperSec = dataSizeMB / seconds;
125 g_log.
notice() << tim <<
" to save the file = " << MBperSec <<
" MB/sec\n";
130 Poco::File info(SaveFilename.empty() ? LoadFilename : SaveFilename);
131 double fileSizeMB = double(info.getSize()) / (1024. * 1024.);
132 g_log.
notice() <<
"File size is " << fileSizeMB <<
" MB\n";
134 double CompressionFactor = fileSizeMB / dataSizeMB;
135 this->
setProperty(
"CompressionFactor", CompressionFactor);
137 bool ClearDiskCache = this->
getProperty(
"ClearDiskCache");
138 if (ClearDiskCache) {
140 if (system(
"sync ; echo 3 > /proc/sys/vm/drop_caches") != 0)
142 Poco::Thread::sleep(100);
146 if (!LoadFilename.empty()) {
147 ::NeXus::File file(LoadFilename, NXACC_READ);
149 NXsetcache(HDFCacheSize);
150 file.openGroup(
"FakeDataGroup",
"NXdata");
151 Progress prog(
this, 0.0, 1.0, NumChunks);
154 for (
int i = 0; i < NumChunks; i++) {
155 file.openData(
"FakeData");
156 std::vector<int64_t> startDims;
157 startDims.emplace_back(i * int64_t(chunkSize));
158 file.getSlab(fakeData.data(), startDims, chunkDims);
166 double MBperSec = dataSizeMB / seconds;
168 g_log.
notice() << tim <<
" to load the file = " << MBperSec <<
" MB/sec (data), " << MBperSec * CompressionFactor
169 <<
" MB/sec (file)\n";
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
@ OptionalSave
to specify a file to write to but an empty string is
@ OptionalLoad
to specify a file to read but the file doesn't have to exist
Helper class for reporting progress from algorithms.
NexusTester : debugging/performance testing algorithm for nexus file loading and saving.
const std::string category() const override
Algorithm's category for identification.
void exec() override
Execute the algorithm.
int version() const override
Algorithm's version for identification.
void init() override
Initialize the algorithm's properties.
CPUTimer : Timer that uses the CPU time, rather than wall-clock time to measure execution time.
float elapsedWallClock(bool doReset=true)
Calculate the elapsed wall-clock time, reseting the timer if specified.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
void information(const std::string &msg)
Logs at information level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
@ Output
An output workspace.