Mantid
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
Mantid::Kernel::NexusDescriptor Class Reference

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...
 
NexusDescriptoroperator= (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...
 

Detailed Description

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.

Member Enumeration Documentation

◆ Version

Enumerate HDF possible versions.

Enumerator
Version4 
Version5 
AnyVersion 

Definition at line 34 of file NexusDescriptor.h.

Constructor & Destructor Documentation

◆ NexusDescriptor() [1/3]

Mantid::Kernel::NexusDescriptor::NexusDescriptor ( const std::string &  filename,
const bool  init = true 
)

Constructor accepting a filename.

Constructs the wrapper.

Parameters
filenameinput filename
inittrue: expensive init including walking through the file, false: don't init
filenameA string pointing to an existing file
Exceptions
std::invalid_argumentif 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().

◆ ~NexusDescriptor()

Mantid::Kernel::NexusDescriptor::~NexusDescriptor ( )
default

Destructor.

◆ NexusDescriptor() [2/3]

Mantid::Kernel::NexusDescriptor::NexusDescriptor ( )
delete

Disable default constructor.

◆ NexusDescriptor() [3/3]

Mantid::Kernel::NexusDescriptor::NexusDescriptor ( const NexusDescriptor )
delete

Disable copy operator.

Member Function Documentation

◆ classTypeExists()

bool Mantid::Kernel::NexusDescriptor::classTypeExists ( const std::string &  classType) const

Query if a given type exists somewhere in the file.

Parameters
classTypeA string name giving a class type
Returns
True if the type exists in the file, false otherwise

Definition at line 183 of file NexusDescriptor.cpp.

References m_pathsToTypes.

Referenced by Mantid::DataHandling::LoadTOFRawNexus::confidence(), and Mantid::DataHandling::LoadGeometry::isNexus().

◆ data()

inline ::NeXus::File & Mantid::Kernel::NexusDescriptor::data ( )
inline

Access the open NeXus File object.

Returns
A reference to 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().

◆ extension()

const std::string & Mantid::Kernel::NexusDescriptor::extension ( ) const
inline

Access the file extension.

Defined as the string after and including the last period character

Returns
A reference to a const string containing the file extension

Definition at line 77 of file NexusDescriptor.h.

Referenced by Mantid::DataHandling::LoadEMUHdf::confidence(), Mantid::DataHandling::LoadNXcanSAS::confidence(), and Mantid::DataHandling::LoadPLN::confidence().

◆ filename()

const std::string & Mantid::Kernel::NexusDescriptor::filename ( ) const
inline

Access the filename.

Returns
A reference to a const string containing the filename

Definition at line 71 of file NexusDescriptor.h.

Referenced by Mantid::DataHandling::LoadMcStas::confidence(), Mantid::DataHandling::LoadNXSPE::confidence(), initialize(), isReadable(), and NexusDescriptor().

◆ firstEntryNameType()

const std::pair< std::string, std::string > & Mantid::Kernel::NexusDescriptor::firstEntryNameType ( ) const

◆ hasRootAttr()

bool Mantid::Kernel::NexusDescriptor::hasRootAttr ( const std::string &  name) const

Query if the given attribute exists on the root node.

Parameters
nameThe name of an attribute
Returns
True if the attribute exists, false otherwise

Definition at line 140 of file NexusDescriptor.cpp.

References m_rootAttrs.

◆ initialize()

void Mantid::Kernel::NexusDescriptor::initialize ( const std::string &  filename)
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().

◆ isReadable()

bool Mantid::Kernel::NexusDescriptor::isReadable ( const std::string &  filename,
const Version  version = AnyVersion 
)
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.

Parameters
filenameA string filename to check
versionOne of the NexusDescriptor::Version enumerations specifying the required version
Returns
True if the file is considered hierarchical, false otherwise

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().

◆ operator=()

NexusDescriptor & Mantid::Kernel::NexusDescriptor::operator= ( const NexusDescriptor )
delete

Disable assignment operator.

◆ pathExists()

bool Mantid::Kernel::NexusDescriptor::pathExists ( const std::string &  path) const

◆ pathOfType()

std::string Mantid::Kernel::NexusDescriptor::pathOfType ( const std::string &  type) const

return the path of a given type

Parameters
typeA string specifying the required type
Returns
path A string giving a path using UNIX-style path separators (/), e.g. /raw_data_1, /entry/bank1

Definition at line 170 of file NexusDescriptor.cpp.

References m_pathsToTypes.

◆ pathOfTypeExists()

bool Mantid::Kernel::NexusDescriptor::pathOfTypeExists ( const std::string &  path,
const std::string &  type 
) const

Query if a path exists of a given type.

Parameters
pathA string giving a path using UNIX-style path separators (/), e.g. /raw_data_1, /entry/bank1
typeA string specifying the required type
Returns
True if the path exists in the file, false otherwise

Definition at line 157 of file NexusDescriptor.cpp.

References m_pathsToTypes.

Referenced by Mantid::DataHandling::LoadISISNexus2::confidence(), and Mantid::DataHandling::LoadTOFRawNexus::confidence().

◆ walkFile()

void Mantid::Kernel::NexusDescriptor::walkFile ( ::NeXus::File &  file,
const std::string &  rootPath,
const std::string &  className,
std::map< std::string, std::string > &  pmap,
int  level 
)
private

Walk the tree and cache the structure.

Cache the structure in the given maps.

Parameters
fileAn open NeXus File object
rootPathThe current path that is open in the file
classNameThe class of the current open path
pmap[Out] An output map filled with mappings of path->type
levelAn 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().

Member Data Documentation

◆ HDF5Signature

const unsigned char Mantid::Kernel::NexusDescriptor::HDF5Signature = {137, 'H', 'D', 'F', '\r', '\n', '\032', '\n'}
static

signature identifying a HDF5 file.

Definition at line 42 of file NexusDescriptor.h.

◆ HDF5SignatureSize

size_t Mantid::Kernel::NexusDescriptor::HDF5SignatureSize = 8
static

Size of HDF5 signature.

Definition at line 40 of file NexusDescriptor.h.

◆ HDFMagic

const unsigned char Mantid::Kernel::NexusDescriptor::HDFMagic = {'\016', '\003', '\023', '\001'}
static

HDF cookie that is stored in the first 4 bytes of the file.

Definition at line 38 of file NexusDescriptor.h.

◆ HDFMagicSize

const size_t Mantid::Kernel::NexusDescriptor::HDFMagicSize = 4
static

Size of HDF magic number.

Definition at line 36 of file NexusDescriptor.h.

◆ m_extension

std::string Mantid::Kernel::NexusDescriptor::m_extension
private

Extension.

Definition at line 107 of file NexusDescriptor.h.

Referenced by initialize().

◆ m_file

std::unique_ptr<::NeXus::File> Mantid::Kernel::NexusDescriptor::m_file
private

Open NeXus handle.

Definition at line 116 of file NexusDescriptor.h.

Referenced by initialize().

◆ m_filename

std::string Mantid::Kernel::NexusDescriptor::m_filename
private

Full filename.

Definition at line 105 of file NexusDescriptor.h.

Referenced by initialize().

◆ m_firstEntryNameType

std::pair<std::string, std::string> Mantid::Kernel::NexusDescriptor::m_firstEntryNameType
private

First entry name/type.

Definition at line 109 of file NexusDescriptor.h.

Referenced by firstEntryNameType(), and walkFile().

◆ m_pathsToTypes

std::map<std::string, std::string> Mantid::Kernel::NexusDescriptor::m_pathsToTypes
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().

◆ m_rootAttrs

std::unordered_set<std::string> Mantid::Kernel::NexusDescriptor::m_rootAttrs
private

Root attributes.

Definition at line 111 of file NexusDescriptor.h.

Referenced by hasRootAttr(), initialize(), and walkFile().


The documentation for this class was generated from the following files: