Mantid
Loading...
Searching...
No Matches
NexusTestHelper.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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/*********************************************************************************
8 * PLEASE READ THIS!!!!!!!
9 *
10 * This file MAY NOT be modified to use anything from a package other than
11 *Kernel.
12 *********************************************************************************/
15#include <Poco/File.h>
16#include <memory>
17
18#if defined(_MSC_VER)
19#pragma warning(push, 0)
20#endif
21#include <nexus/NeXusFile.hpp>
22#if defined(_MSC_VER)
23#pragma warning(pop)
24#endif
25
26//----------------------------------------------------------------------------------------------
29NexusTestHelper::NexusTestHelper(bool deleteFile) : file(nullptr), deleteFile(deleteFile) {}
30
31//----------------------------------------------------------------------------------------------
36 if (!file)
37 return;
38 file->close();
39 if (deleteFile) {
40 if (Poco::File(filename).exists())
41 Poco::File(filename).remove();
42 }
43}
44
45//----------------------------------------------------------------------------------------------
49void NexusTestHelper::createFile(const std::string &barefilename) {
50 filename = (Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory") + barefilename);
51 if (Poco::File(filename).exists())
52 Poco::File(filename).remove();
53 file = std::make_unique<::NeXus::File>(filename, NXACC_CREATE5);
54 file->makeGroup("test_entry", "NXentry", true);
55}
56
57//----------------------------------------------------------------------------------------------
60 if (!file)
61 throw std::runtime_error("NexusTestHelper: you must call createFile() before reopenFile().");
62 file->close();
63 file = std::make_unique<::NeXus::File>(filename, NXACC_READ);
64 file->openGroup("test_entry", "NXentry");
65}
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
void reopenFile()
Close the newly created file and re-open it for reading back.
bool deleteFile
Do you delete when finished?
virtual ~NexusTestHelper()
Destructor.
NexusTestHelper(bool deleteFile=true)
structor.
void createFile(const std::string &barefilename)
Creates a NXS file with an entry, for use in a test.
std::unique_ptr<::NeXus::File > file
Nexus file handle.
std::string filename
Created filename (full path)