Mantid
Loading...
Searching...
No Matches
LoadGeometry.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 +
10
11namespace Mantid::DataHandling {
12
14bool LoadGeometry::isIDF(const std::string &filename) {
15 if (!filename.empty()) {
16 Mantid::Kernel::FileDescriptor descriptor(filename);
17 return descriptor.isXML();
18 }
19 return false;
20}
21
23bool LoadGeometry::isNexus(const std::string &filename) {
24 if (!filename.empty() && !Mantid::Kernel::FileDescriptor(filename).isAscii(filename)) {
25 Mantid::Kernel::NexusDescriptor descriptor(filename);
26 return descriptor.isReadable(filename) &&
27 (descriptor.classTypeExists("NXcylindrical_geometry") || descriptor.classTypeExists("NXoff_geometry") ||
28 descriptor.classTypeExists("NXtransformations"));
29 }
30 return false;
31}
32
33bool LoadGeometry::isNexus(const std::string &filename,
34 const std::map<std::string, std::set<std::string>> &allEntries) {
35 if (!filename.empty() && !Mantid::Kernel::FileDescriptor(filename).isAscii(filename)) {
36 Mantid::Kernel::NexusDescriptor descriptor(filename, false);
37 return descriptor.isReadable(filename) &&
38 (allEntries.count("NXcylindrical_geometry") == 1 || allEntries.count("NXoff_geometry") == 1 ||
39 allEntries.count("NXtransformations") == 1);
40 }
41 return false;
42}
43
45const std::vector<std::string> LoadGeometry::validExtensions() { return {".xml", ".nxs", ".hdf5"}; }
46
47} // namespace Mantid::DataHandling
Defines a wrapper around an open file.
static bool isAscii(const std::string &filename, const size_t nbytes=256)
Returns true if the file is considered ascii.
bool isXML() const
Returns true if the descriptor is looking at an XML file.
Defines a wrapper around a file whose internal structure can be accessed using the NeXus API.
bool classTypeExists(const std::string &classType) const
Query if a given type exists somewhere in the file.
static bool isReadable(const std::string &filename, const Version version=AnyVersion)
Returns true if the file is considered to store data in a hierarchy.
bool isIDF(const std::string &filename)
Determine if the Geometry file type is IDF.
const std::vector< std::string > validExtensions()
List allowed file extensions for geometry.
bool isNexus(const std::string &filename)
Determine if the Geometry file type is Nexus.