Skip to content
Snippets Groups Projects
  • Nick Draper's avatar
    ef3ccb58
    Merge pull request #23693 from mantidproject/23488_update_file_headers · ef3ccb58
    Nick Draper authored
    Update copyright headers in all files
    
    Squashed commit of the following:
    
    * First version of a script to manage copyright statements
    
    re #23468
    
    * Neatened up script, added comments
    
    re #23488
    
    * move script to tools directory
    
    re #23488
    
    * small script changes and a couple of manual file changes
    
    re #23488
    
    * Minor chnage to whitespace detection in regex
    
    re #23488
    
    * Add an excluded directory
    
    re #23488
    
    * remove a repeasted copyright statement in a file
    
    re #23488
    
    * Don't comsume the comment end if it is on the same line
    
    re #23488
    
    * fix error in new copright parsing
    
    re #23488
    
    * remove double copyrifght entry
    
    re #23488
    
    * Improve handling of old copyrights at the start of comments
    
    re #23488
    
    * remove empty comments re #23488
    
    * exclude gsoapgenerated directories
    
    re #23488
    
    * Sort out greedy line matching re #23488
    
    * improve empty comment removal
    
    re #23488
    
    * improve false positives
    
    re #23488
    
    * impressive speedup by limiting regex matching length
    
    re #23488
    
    * remove evil invisible non ascii character
    
    Also upadte the copyright at the same time
    
    re #23488
    
    * resolve multiple copyrights in a single file
    
    re #23488
    
    * resolve an issue with new statement detection
    
    re #23488
    
    * another unprintable unicode character
    
    re #23488
    
    * pep updates and cmake the new copyright fit clang format
    
    re #23488
    
    * update already done new format headers
    
    re #23488
    
    * wrong type of bracket
    
    re #23488
    
    * Update class_maker and friends
    
    re #23488
    
    * Update all copyright statements
    
    re #23488
    
    * clang format re #23488
    
    * flake8 warnings re #23488
    
    * Flake8 warnings re #23488
    
    * Exclude .cmake.in and rb.in files
    
    re #23488
    
    * replace missing line re #23488
    
    * exclude .py.in files as they are flasely recognized as C++
    
    re #23488
    
    * another setp.py.in re #23488
    
    * another .py.in correction re #23488
    
    * Hopefully the last of the .py.in files re #23488
    
    * resolve utf-8 encoding of python files and changed ABINS checksum
    
    re #23488
    
    * updates to unit tests that reference line numbers
    
    re #23488
    
    * remaining unit test files and other fixes
    
    re #23488
    ef3ccb58
    History
    Merge pull request #23693 from mantidproject/23488_update_file_headers
    Nick Draper authored
    Update copyright headers in all files
    
    Squashed commit of the following:
    
    * First version of a script to manage copyright statements
    
    re #23468
    
    * Neatened up script, added comments
    
    re #23488
    
    * move script to tools directory
    
    re #23488
    
    * small script changes and a couple of manual file changes
    
    re #23488
    
    * Minor chnage to whitespace detection in regex
    
    re #23488
    
    * Add an excluded directory
    
    re #23488
    
    * remove a repeasted copyright statement in a file
    
    re #23488
    
    * Don't comsume the comment end if it is on the same line
    
    re #23488
    
    * fix error in new copright parsing
    
    re #23488
    
    * remove double copyrifght entry
    
    re #23488
    
    * Improve handling of old copyrights at the start of comments
    
    re #23488
    
    * remove empty comments re #23488
    
    * exclude gsoapgenerated directories
    
    re #23488
    
    * Sort out greedy line matching re #23488
    
    * improve empty comment removal
    
    re #23488
    
    * improve false positives
    
    re #23488
    
    * impressive speedup by limiting regex matching length
    
    re #23488
    
    * remove evil invisible non ascii character
    
    Also upadte the copyright at the same time
    
    re #23488
    
    * resolve multiple copyrights in a single file
    
    re #23488
    
    * resolve an issue with new statement detection
    
    re #23488
    
    * another unprintable unicode character
    
    re #23488
    
    * pep updates and cmake the new copyright fit clang format
    
    re #23488
    
    * update already done new format headers
    
    re #23488
    
    * wrong type of bracket
    
    re #23488
    
    * Update class_maker and friends
    
    re #23488
    
    * Update all copyright statements
    
    re #23488
    
    * clang format re #23488
    
    * flake8 warnings re #23488
    
    * Flake8 warnings re #23488
    
    * Exclude .cmake.in and rb.in files
    
    re #23488
    
    * replace missing line re #23488
    
    * exclude .py.in files as they are flasely recognized as C++
    
    re #23488
    
    * another setp.py.in re #23488
    
    * another .py.in correction re #23488
    
    * Hopefully the last of the .py.in files re #23488
    
    * resolve utf-8 encoding of python files and changed ABINS checksum
    
    re #23488
    
    * updates to unit tests that reference line numbers
    
    re #23488
    
    * remaining unit test files and other fixes
    
    re #23488
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
DataBlockComposite.h 6.04 KiB
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2016 ISIS Rutherford Appleton Laboratory UKRI,
//     NScD Oak Ridge National Laboratory, European Spallation Source
//     & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
#ifndef MANTID_DATAHANDLING_DATABLOCK_COMPOSITE_H_
#define MANTID_DATAHANDLING_DATABLOCK_COMPOSITE_H_

#include "MantidDataHandling/DataBlock.h"
#include "MantidDataHandling/DllConfig.h"

namespace Mantid {
namespace DataHandling {

/** DataBlockComposite: The DataBlockComposite handles a collection
    of DataBlocks. It represents a set of contiguous spectrum numbers
    which are to be consumed elsewhere.
*/
class DLLExport DataBlockComposite : public DataBlock {
public:
  int64_t getMinSpectrumID() const override;
  void setMinSpectrumID(int64_t) override;

  int64_t getMaxSpectrumID() const override;
  void setMaxSpectrumID(int64_t) override;

  size_t getNumberOfSpectra() const override;
  size_t getNumberOfChannels() const override;
  int getNumberOfPeriods() const override;

  std::unique_ptr<DataBlockGenerator> getGenerator() const override;

  bool operator==(const DataBlockComposite &other) const;

  // DataBlockComposite only mehtods
  void addDataBlock(DataBlock dataBlock);
  std::vector<DataBlock> getDataBlocks();
  DataBlockComposite operator+(const DataBlockComposite &other);
  void removeSpectra(DataBlockComposite &toRemove);
  void truncate(int64_t specMin, int64_t specMax);
  std::vector<int64_t> getAllSpectrumNumbers();
  bool isEmpty();

private:
  std::vector<DataBlock> m_dataBlocks;
};

/**
 * Populates a DataBlockComposite with DataBlocks which are extracted from a
 * indexable collection (array-type). Note that std::is_array does not
 * work on boost::shared_array which is one of the use cases. Hence this
 * function could get abused. Monitor spectra get their own data block
 * @param dataBlockComposite: the detector block composite which will get
 * populated
 * @param indexContainer: the container of indices
 * @param nArray: the number of array elements
 * @param numberOfPeriods: the number of periods
 * @param numberOfChannels: the number of channels
 * @param monitorSpectra: a collection of monitor spectrum numbers
 */
template <typename T>
void DLLExport populateDataBlockCompositeWithContainer(
    DataBlockComposite &dataBlockComposite, T &indexContainer, int64_t nArray,
    int numberOfPeriods, size_t numberOfChannels,
    std::vector<int64_t> monitorSpectra) {
  auto isMonitor = [&monitorSpectra](int64_t index) {
    return std::find(std::begin(monitorSpectra), std::end(monitorSpectra),
                     index) != std::end(monitorSpectra);
  };

  // Handles the case when an element is a monitor. It needs to crate a data
  // block
  // for potential specturm numbers before the monitor and a data block for
  // the
  // monitor itself
  struct HandleWhenElementIsMonitor {
    void
    operator()(Mantid::DataHandling::DataBlockComposite &dataBlockComposite,
               int numberOfPeriods, size_t numberOfChannels,
               int64_t previousValue, int64_t startValue) {
      if (previousValue - startValue > 0) {
        auto numberOfSpectra =
            previousValue - startValue; /* Should be from [start,
                                           previousValue -1]*/
        DataBlock dataBlock(numberOfPeriods, numberOfSpectra, numberOfChannels);
        dataBlock.setMinSpectrumID(startValue);
        dataBlock.setMaxSpectrumID(previousValue - 1);
        dataBlockComposite.addDataBlock(dataBlock);
      }

      // Save out the monitor
      DataBlock dataBlock(numberOfPeriods, 1, numberOfChannels);
      dataBlock.setMinSpectrumID(previousValue);
      dataBlock.setMaxSpectrumID(previousValue);
      dataBlockComposite.addDataBlock(dataBlock);
    }
  };

  // Handles the case when the element made a jump, ie there seems to
  // be a gap between neighbouring spetrum numbers. Then we need to
  // write out this range as a data block.
  struct HandleWhenElementMadeAJump {
    void
    operator()(Mantid::DataHandling::DataBlockComposite &dataBlockComposite,
               int numberOfPeriods, size_t numberOfChannels,
               int64_t previousValue, int64_t startValue) {
      auto numberOfSpectra = previousValue - startValue + 1;
      DataBlock dataBlock(numberOfPeriods, numberOfSpectra, numberOfChannels);
      dataBlock.setMinSpectrumID(startValue);
      dataBlock.setMaxSpectrumID(previousValue);
      dataBlockComposite.addDataBlock(dataBlock);
    }
  };

  HandleWhenElementIsMonitor handleWhenElementIsMonitor;
  HandleWhenElementMadeAJump handleWhenElementMadeAJump;

  auto startValue = indexContainer[0];
  auto previousValue = startValue;
  for (int64_t arrayIndex = 1; arrayIndex < nArray; ++arrayIndex) {
    // There are two ways to write data out. Either when we have a jump of
    // the indices or there is a monitor. In case of a monitor we also need
    // to clear the data that was potentially before the monitor.

    if (isMonitor(previousValue)) {
      handleWhenElementIsMonitor(dataBlockComposite, numberOfPeriods,
                                 numberOfChannels, previousValue, startValue);
      startValue = indexContainer[arrayIndex];
    } else if ((indexContainer[arrayIndex] - previousValue) != 1) {
      // We must have completed an interval, we create a DataBlock and add
      // it
      handleWhenElementMadeAJump(dataBlockComposite, numberOfPeriods,
                                 numberOfChannels, previousValue, startValue);
      startValue = indexContainer[arrayIndex];
    }

    // Set the previous value to the current value;
    previousValue = indexContainer[arrayIndex];
  }

  // The last interval would not have been added.
  if (isMonitor(previousValue)) {
    handleWhenElementIsMonitor(dataBlockComposite, numberOfPeriods,
                               numberOfChannels, previousValue, startValue);
  } else {
    handleWhenElementMadeAJump(dataBlockComposite, numberOfPeriods,
                               numberOfChannels, previousValue, startValue);
  }
}
} // namespace DataHandling
} // namespace Mantid
#endif