Mantid
|
Defines a wrapper around a file whose internal structure can be accessed using the NeXus API. More...
#include <NexusDescriptor.h>
Public Types | |
enum | Version { Version4 , Version5 , AnyVersion } |
Enumerate HDF possible versions. More... | |
Public Member Functions | |
bool | classTypeExists (const std::string &classType) const |
Query if a given type exists somewhere in the file. More... | |
inline ::NeXus::File & | data () |
Access the open NeXus File object. More... | |
const std::string & | extension () const |
Access the file extension. More... | |
const std::string & | filename () const |
Access the filename. More... | |
const std::pair< std::string, std::string > & | firstEntryNameType () const |
Returns the name & type of the first entry in the file. More... | |
bool | hasRootAttr (const std::string &name) const |
Query if the given attribute exists on the root node. More... | |
NexusDescriptor ()=delete | |
Disable default constructor. More... | |
NexusDescriptor (const NexusDescriptor &)=delete | |
Disable copy operator. More... | |
NexusDescriptor (const std::string &filename, const bool init=true) | |
Constructor accepting a filename. More... | |
NexusDescriptor & | operator= (const NexusDescriptor &)=delete |
Disable assignment operator. More... | |
bool | pathExists (const std::string &path) const |
Query if a path exists. More... | |
std::string | pathOfType (const std::string &type) const |
return the path of a given type More... | |
bool | pathOfTypeExists (const std::string &path, const std::string &type) const |
Query if a path exists of a given type. More... | |
~NexusDescriptor () | |
Destructor. More... | |
Static Public Member Functions | |
static bool | isReadable (const std::string &filename, const Version version=AnyVersion) |
Returns true if the file is considered to store data in a hierarchy. More... | |
Static Public Attributes | |
static const unsigned char | HDF5Signature [8] = {137, 'H', 'D', 'F', '\r', '\n', '\032', '\n'} |
signature identifying a HDF5 file. More... | |
static size_t | HDF5SignatureSize = 8 |
Size of HDF5 signature. More... | |
static const unsigned char | HDFMagic [4] = {'\016', '\003', '\023', '\001'} |
HDF cookie that is stored in the first 4 bytes of the file. More... | |
static const size_t | HDFMagicSize = 4 |
Size of HDF magic number. More... | |
Private Member Functions | |
void | initialize (const std::string &filename) |
Initialize object with filename. More... | |
void | walkFile (::NeXus::File &file, const std::string &rootPath, const std::string &className, std::map< std::string, std::string > &pmap, int level) |
Walk the tree and cache the structure. More... | |
Private Attributes | |
std::string | m_extension |
Extension. More... | |
std::unique_ptr<::NeXus::File > | m_file |
Open NeXus handle. More... | |
std::string | m_filename |
Full filename. More... | |
std::pair< std::string, std::string > | m_firstEntryNameType |
First entry name/type. More... | |
std::map< std::string, std::string > | m_pathsToTypes |
Map of full path strings to types. Can check if path exists quickly. More... | |
std::unordered_set< std::string > | m_rootAttrs |
Root attributes. More... | |
Defines a wrapper around a file whose internal structure can be accessed using the NeXus API.
On construction the simple details about the layout of the file are cached for faster querying later.
Definition at line 31 of file NexusDescriptor.h.
Enumerate HDF possible versions.
Enumerator | |
---|---|
Version4 | |
Version5 | |
AnyVersion |
Definition at line 34 of file NexusDescriptor.h.
Mantid::Kernel::NexusDescriptor::NexusDescriptor | ( | const std::string & | filename, |
const bool | init = true |
||
) |
Constructor accepting a filename.
Constructs the wrapper.
filename | input filename |
init | true: expensive init including walking through the file, false: don't init |
filename | A string pointing to an existing file |
std::invalid_argument | if the file is not identified to be hierarchical. This currently involves simply checking for the signature if a HDF file at the start of the file |
Definition at line 111 of file NexusDescriptor.cpp.
References Mantid::DataHandling::exists(), filename(), and initialize().
|
default |
Destructor.
|
delete |
Disable default constructor.
|
delete |
Disable copy operator.
bool Mantid::Kernel::NexusDescriptor::classTypeExists | ( | const std::string & | classType | ) | const |
Query if a given type exists somewhere in the file.
classType | A string name giving a class type |
Definition at line 183 of file NexusDescriptor.cpp.
References m_pathsToTypes.
Referenced by Mantid::DataHandling::LoadTOFRawNexus::confidence(), and Mantid::DataHandling::LoadGeometry::isNexus().
|
inline |
Access the open NeXus File object.
Definition at line 82 of file NexusDescriptor.h.
Referenced by Mantid::DataHandling::LoadMuonNexus1::confidence(), Mantid::DataHandling::LoadMuonNexus2::confidence(), and Mantid::DataHandling::LoadNXcanSAS::confidence().
|
inline |
Access the file extension.
Defined as the string after and including the last period character
Definition at line 77 of file NexusDescriptor.h.
Referenced by Mantid::DataHandling::LoadEMUHdf::confidence(), Mantid::DataHandling::LoadNXcanSAS::confidence(), and Mantid::DataHandling::LoadPLN::confidence().
|
inline |
Access the filename.
Definition at line 71 of file NexusDescriptor.h.
Referenced by Mantid::DataHandling::LoadMcStas::confidence(), Mantid::DataHandling::LoadNXSPE::confidence(), initialize(), isReadable(), and NexusDescriptor().
const std::pair< std::string, std::string > & Mantid::Kernel::NexusDescriptor::firstEntryNameType | ( | ) | const |
Returns the name & type of the first entry in the file.
Definition at line 134 of file NexusDescriptor.cpp.
References m_firstEntryNameType.
Referenced by Mantid::DataHandling::LoadMcStas::confidence(), Mantid::DataHandling::LoadMuonNexus1::confidence(), and Mantid::DataHandling::LoadMuonNexus2::confidence().
bool Mantid::Kernel::NexusDescriptor::hasRootAttr | ( | const std::string & | name | ) | const |
Query if the given attribute exists on the root node.
name | The name of an attribute |
Definition at line 140 of file NexusDescriptor.cpp.
References m_rootAttrs.
|
private |
Initialize object with filename.
Creates the internal cached structure of the file as a tree of nodes.
Definition at line 199 of file NexusDescriptor.cpp.
References filename(), m_extension, m_file, m_filename, m_pathsToTypes, m_rootAttrs, and walkFile().
Referenced by NexusDescriptor().
|
static |
Returns true if the file is considered to store data in a hierarchy.
Checks for the HDF signatures and returns true if one of them is found.
filename | A string filename to check |
version | One of the NexusDescriptor::Version enumerations specifying the required version |
Definition at line 90 of file NexusDescriptor.cpp.
References filename().
Referenced by Mantid::API::FileLoaderRegistryImpl::canLoad(), Mantid::API::FileLoaderRegistryImpl::chooseLoader(), Mantid::DataHandling::LoadMuonNexus2::exec(), Mantid::DataHandling::UpdateInstrumentFromFile::exec(), Mantid::DataHandling::LoadGeometry::isNexus(), and Mantid::Kernel::NexusHDF5Descriptor::isReadable().
|
delete |
Disable assignment operator.
bool Mantid::Kernel::NexusDescriptor::pathExists | ( | const std::string & | path | ) | const |
Query if a path exists.
path | A string giving a path using UNIX-style path separators (/), e.g. /raw_data_1, /entry/bank1 |
Definition at line 147 of file NexusDescriptor.cpp.
References m_pathsToTypes.
Referenced by Mantid::DataHandling::LoadEMUHdf::confidence(), Mantid::DataHandling::LoadILLIndirect2::confidence(), Mantid::DataHandling::LoadILLSALSA::confidence(), Mantid::DataHandling::LoadILLSANS::confidence(), Mantid::DataHandling::LoadLLB::confidence(), Mantid::DataHandling::LoadMcStas::confidence(), Mantid::DataHandling::LoadMLZ::confidence(), Mantid::DataHandling::LoadMuonNexus1::confidence(), Mantid::DataHandling::LoadMuonNexus2::confidence(), Mantid::DataHandling::LoadNexusProcessed::confidence(), Mantid::DataHandling::LoadNexusProcessed2::confidence(), Mantid::DataHandling::LoadPLN::confidence(), Mantid::DataHandling::LoadSINQFocus::confidence(), and Mantid::DataHandling::LoadILLDiffraction::containsCalibratedData().
std::string Mantid::Kernel::NexusDescriptor::pathOfType | ( | const std::string & | type | ) | const |
return the path of a given type
type | A string specifying the required type |
Definition at line 170 of file NexusDescriptor.cpp.
References m_pathsToTypes.
bool Mantid::Kernel::NexusDescriptor::pathOfTypeExists | ( | const std::string & | path, |
const std::string & | type | ||
) | const |
Query if a path exists of a given type.
path | A string giving a path using UNIX-style path separators (/), e.g. /raw_data_1, /entry/bank1 |
type | A string specifying the required type |
Definition at line 157 of file NexusDescriptor.cpp.
References m_pathsToTypes.
Referenced by Mantid::DataHandling::LoadISISNexus2::confidence(), and Mantid::DataHandling::LoadTOFRawNexus::confidence().
|
private |
Walk the tree and cache the structure.
Cache the structure in the given maps.
file | An open NeXus File object |
rootPath | The current path that is open in the file |
className | The class of the current open path |
pmap | [Out] An output map filled with mappings of path->type |
level | An integer defining the current level in the file |
Definition at line 219 of file NexusDescriptor.cpp.
References m_firstEntryNameType, m_rootAttrs, and walkFile().
Referenced by initialize(), and walkFile().
|
static |
signature identifying a HDF5 file.
Definition at line 42 of file NexusDescriptor.h.
|
static |
Size of HDF5 signature.
Definition at line 40 of file NexusDescriptor.h.
|
static |
HDF cookie that is stored in the first 4 bytes of the file.
Definition at line 38 of file NexusDescriptor.h.
|
static |
Size of HDF magic number.
Definition at line 36 of file NexusDescriptor.h.
|
private |
|
private |
|
private |
|
private |
First entry name/type.
Definition at line 109 of file NexusDescriptor.h.
Referenced by firstEntryNameType(), and walkFile().
|
private |
Map of full path strings to types. Can check if path exists quickly.
Definition at line 113 of file NexusDescriptor.h.
Referenced by classTypeExists(), initialize(), pathExists(), pathOfType(), and pathOfTypeExists().
|
private |
Root attributes.
Definition at line 111 of file NexusDescriptor.h.
Referenced by hasRootAttr(), initialize(), and walkFile().