Skip to content
Snippets Groups Projects
NexusHDF5Descriptor.h 2.58 KiB
Newer Older
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once

#include "MantidKernel/DllConfig.h"

#include <map>
#include <set>
#include <string>

namespace Mantid::Kernel {
class MANTID_KERNEL_DLL NexusHDF5Descriptor {

public:
  /**
   * Unique constructor
   * @param filename input HDF5 Nexus file name
   */
  NexusHDF5Descriptor(const std::string &filename);

  NexusHDF5Descriptor() = delete;

  /**
   * Using RAII components, no need to deallocate explicitly
   */
  ~NexusHDF5Descriptor() = default;

Peterson, Peter's avatar
Peterson, Peter committed
  /// Returns true if the file is considered to store data in a hierarchy
  static bool isReadable(const std::string &filename);

  /**
   * Returns a copy of the current file name
   * @return
   */
  std::string getFilename() const noexcept;

  /**
   * Returns a const reference of the internal map holding all entries in the
   * NeXus HDF5 file
   * @return map holding all entries by group class
   * <pre>
   *   key: group_class (e.g. NXentry, NXlog)
   *   value: set with absolute entry names for the group_class key
   *          (e.g. /entry/log)
   * </pre>
   */
  const std::map<std::string, std::set<std::string>> &getAllEntries() const
      noexcept;

William F Godoy's avatar
William F Godoy committed
  /**
   * Checks if a full-path entry exists for a particular groupClass in a Nexus
   * dataset
   * @param groupClass e.g. NxLog , Nexus entry attribute
   * @param entryName full path for an entry name /entry/NXlogs
   * @return true: entryName exists for a groupClass, otherwise false
   */
  bool isEntry(const std::string &entryName,
               const std::string &groupClass) const noexcept;

  /**
   * Checks if a full-path entry exists in a Nexus dataset
   * @param entryName full path for an entry name /entry/NXlogs
   * @return true: entryName exists, otherwise false
   */
  bool isEntry(const std::string &entryName) const noexcept;
William F Godoy's avatar
William F Godoy committed

private:
  /**
   * Sets m_allEntries, called in HDF5 constructor.
   * m_filename must be set
   */
  std::map<std::string, std::set<std::string>> initAllEntries();

  /** NeXus HDF5 file name */
  std::string m_filename;

  /**
   * All entries metadata
   * <pre>
   *   key: group_class (e.g. NXentry, NXlog)
   *   value: set with absolute entry names for the group_class key
   *          (e.g. /entry/log)
   * </pre>
   */
  const std::map<std::string, std::set<std::string>> m_allEntries;
} // namespace Mantid::Kernel