Skip to content

Commit

Permalink
Merge pull request #12963 from mantidproject/12776_multiperiod_event_…
Browse files Browse the repository at this point in the history
…loading

Extend LoadEventNexus For MultiPeriod Events
  • Loading branch information
martyngigg committed Jul 6, 2015
2 parents 4c7791f + 764f62c commit 6d59e1d
Show file tree
Hide file tree
Showing 21 changed files with 872 additions and 157 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/ExperimentInfo.h
Expand Up @@ -52,7 +52,7 @@ class MANTID_API_DLL ExperimentInfo {
virtual const std::string toString() const;

/// Instrument accessors
void setInstrument(const Geometry::Instrument_const_sptr &instr);
virtual void setInstrument(const Geometry::Instrument_const_sptr &instr);
/// Returns the parameterized instrument
virtual Geometry::Instrument_const_sptr getInstrument() const;

Expand Down
12 changes: 6 additions & 6 deletions Code/Mantid/Framework/API/inc/MantidAPI/MatrixWorkspace.h
Expand Up @@ -122,7 +122,7 @@ class MANTID_API_DLL MatrixWorkspace : public IMDWorkspace,
const bool ignoreMaskedDetectors = false) const;
//@}

void updateSpectraUsing(const SpectrumDetectorMapping &map);
virtual void updateSpectraUsing(const SpectrumDetectorMapping &map);
/// Build the default spectra mapping, most likely wanted after an instrument
/// update
void rebuildSpectraMapping(const bool includeMonitors = true);
Expand All @@ -131,10 +131,10 @@ class MANTID_API_DLL MatrixWorkspace : public IMDWorkspace,
spec2index_map getSpectrumToWorkspaceIndexMap() const;
detid2index_map
getDetectorIDToWorkspaceIndexMap(bool throwIfMultipleDets = false) const;
void
virtual void
getDetectorIDToWorkspaceIndexVector(std::vector<size_t> &out, detid_t &offset,
bool throwIfMultipleDets = false) const;
void getSpectrumToWorkspaceIndexVector(std::vector<size_t> &out,
virtual void getSpectrumToWorkspaceIndexVector(std::vector<size_t> &out,
specid_t &offset) const;
void getIndicesFromSpectra(const std::vector<specid_t> &spectraList,
std::vector<size_t> &indexList) const;
Expand Down Expand Up @@ -163,7 +163,7 @@ class MANTID_API_DLL MatrixWorkspace : public IMDWorkspace,
/// Gets MatrixWorkspace title (same as Run object run_title property)
virtual const std::string getTitle() const;

Kernel::DateAndTime getFirstPulseTime() const;
virtual Kernel::DateAndTime getFirstPulseTime() const;
Kernel::DateAndTime getLastPulseTime() const;

/// Returns the bin index for a given X value of a given workspace index
Expand Down Expand Up @@ -308,7 +308,7 @@ class MANTID_API_DLL MatrixWorkspace : public IMDWorkspace,
//----------------------------------------------------------------------

int axes() const;
Axis *getAxis(const std::size_t &axisIndex) const;
virtual Axis *getAxis(const std::size_t &axisIndex) const;
void replaceAxis(const std::size_t &axisIndex, Axis *const newAxis);

/// Returns true if the workspace contains data in histogram form (as opposed
Expand Down Expand Up @@ -342,7 +342,7 @@ class MANTID_API_DLL MatrixWorkspace : public IMDWorkspace,
const MaskList &maskedBins(const size_t &spectrumIndex) const;

// Methods handling the internal monitor workspace
void setMonitorWorkspace(const boost::shared_ptr<MatrixWorkspace> &monitorWS);
virtual void setMonitorWorkspace(const boost::shared_ptr<MatrixWorkspace> &monitorWS);
boost::shared_ptr<MatrixWorkspace> monitorWorkspace() const;

void saveInstrumentNexus(::NeXus::File *file) const;
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/DataHandling/CMakeLists.txt
Expand Up @@ -7,6 +7,7 @@ set ( SRC_FILES
src/CreateModeratorModel.cpp
src/CreateSampleShape.cpp
src/CreateSimulationWorkspace.cpp
src/DecoratorWorkspace.cpp
src/DefineGaugeVolume.cpp
src/DeleteTableRows.cpp
src/DetermineChunking.cpp
Expand Down Expand Up @@ -163,6 +164,7 @@ set ( INC_FILES
inc/MantidDataHandling/CreateModeratorModel.h
inc/MantidDataHandling/CreateSampleShape.h
inc/MantidDataHandling/CreateSimulationWorkspace.h
inc/MantidDataHandling/DecoratorWorkspace.h
inc/MantidDataHandling/DefineGaugeVolume.h
inc/MantidDataHandling/DeleteTableRows.h
inc/MantidDataHandling/DetermineChunking.h
Expand Down Expand Up @@ -318,6 +320,7 @@ set ( TEST_FILES
CreateModeratorModelTest.h
CreateSampleShapeTest.h
CreateSimulationWorkspaceTest.h
DecoratorWorkspaceTest.h
DefineGaugeVolumeTest.h
DeleteTableRowsTest.h
DetermineChunkingTest.h
Expand Down
@@ -0,0 +1,109 @@
#ifndef MANTID_DATAHANDLING_DECORATORWORKSPACE_H_
#define MANTID_DATAHANDLING_DECORATORWORKSPACE_H_

#include "MantidKernel/System.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataHandling/DllConfig.h"

#include <vector>
#include <boost/shared_ptr.hpp>
#include <memory>

namespace Mantid {
namespace DataHandling {

/** DecoratorWorkspace : Decorator pattern around a collection of EventWorspaces to give backward-forward compatibility
around performing operations on groups. Behave like an EventWorkspace with some overriden functionality and some additional new functionality.
Original purpose to support LoadEventNexus for the MultiPeriod cases.
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport DecoratorWorkspace : public Mantid::DataObjects::EventWorkspace {

private:

/// Vector of EventWorkspaces
std::vector<DataObjects::EventWorkspace_sptr> m_WsVec;
/// Create Empty EventWorkspaces
DataObjects::EventWorkspace_sptr createEmptyEventWorkspace() const;
/// private copy constructor. Not implemented.
DecoratorWorkspace(const DecoratorWorkspace &other);
/// Private copy assignment operator. Assignment not implemented.
DecoratorWorkspace &operator=(const DecoratorWorkspace &other);

public:

DecoratorWorkspace();
virtual ~DecoratorWorkspace();

/*-------------------------------------------------------
* DecoratorWorkspace specific methods
*-------------------------------------------------------*/
void setNPeriods(size_t nPeriods, std::unique_ptr<const Kernel::TimeSeriesProperty<int> >& periodLog);
void reserveEventListAt(size_t wi, size_t size);
size_t nPeriods() const;
DataObjects::EventWorkspace_sptr getSingleHeldWorkspace();
API::Workspace_sptr combinedWorkspace();
const DataObjects::EventList& getEventList(const size_t workspace_index, const size_t periodNumber) const;
virtual DataObjects::EventList& getEventList(const size_t workspace_index, const size_t periodNumber);
void setGeometryFlag(const int flag);
void setThickness(const float flag);
void setHeight(const float flag);
void setWidth(const float flag);

/*-------------------------------------------------------
* EventWorkspace overriden methods
*-------------------------------------------------------*/
Geometry::Instrument_const_sptr getInstrument() const;
const API::Run &run() const;
API::Run &mutableRun();
Mantid::API::ISpectrum* getSpectrum(const size_t index);
virtual const Mantid::API::ISpectrum *getSpectrum(const size_t index) const;
virtual Mantid::API::Axis* getAxis(const size_t& i) const;
size_t getNumberHistograms() const;
virtual const DataObjects::EventList& getEventList(const size_t workspace_index) const;

virtual DataObjects::EventList &getEventList(const std::size_t workspace_index);
void getSpectrumToWorkspaceIndexVector(std::vector<size_t>&out, Mantid::specid_t& offset) const;

void getDetectorIDToWorkspaceIndexVector(std::vector<size_t>&out, Mantid::specid_t& offset, bool dothrow) const;
Kernel::DateAndTime getFirstPulseTime() const;
void setAllX(Kernel::cow_ptr<MantidVec>& x);
size_t getNumberEvents() const;
void resizeTo(const size_t size);
void padSpectra(const std::vector<int32_t>& padding);
void setInstrument(const Geometry::Instrument_const_sptr& inst);
void setMonitorWorkspace(const boost::shared_ptr<API::MatrixWorkspace>& monitorWS);
void updateSpectraUsing(const API::SpectrumDetectorMapping& map);
DataObjects::EventList* getEventListPtr(size_t i);
void populateInstrumentParameters();
};

typedef boost::shared_ptr<DecoratorWorkspace> DecoratorWorkspace_sptr;
typedef std::unique_ptr<DecoratorWorkspace>DecoratorWorkspace_uptr;

} // namespace DataHandling
} // namespace Mantid

#endif /* MANTID_DATAHANDLING_DECORATORWORKSPACE_H_ */
Expand Up @@ -9,20 +9,29 @@
#include <nexus/NeXusFile.hpp>
#include <nexus/NeXusException.hpp>
#include "MantidDataObjects/Events.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include <memory>

namespace Mantid {

namespace DataHandling {

// Forward dec
class DecoratorWorkspace;

/** This class defines the pulse times for a specific bank.
* Since some instruments (ARCS, VULCAN) have multiple preprocessors,
* this means that some banks have different lists of pulse times.
*/
class BankPulseTimes {
public:

/// Starting number for assigning periods.
static const unsigned int FirstPeriod;

/// Constructor with NeXus::File
BankPulseTimes(::NeXus::File &file);
BankPulseTimes(::NeXus::File &file, const std::vector<int>& pNumbers);

/// Constructor with vector of DateAndTime
BankPulseTimes(const std::vector<Kernel::DateAndTime> &times);
Expand All @@ -41,6 +50,9 @@ class BankPulseTimes {

/// Array of the pulse times
Kernel::DateAndTime *pulseTimes;

/// Vector of period numbers corresponding to each pulse
std::vector<int> periodNumbers;
};

/** @class LoadEventNexus LoadEventNexus.h Nexus/LoadEventNexus.h
Expand Down Expand Up @@ -107,7 +119,7 @@ class DLLExport LoadEventNexus
static boost::shared_ptr<BankPulseTimes>
runLoadNexusLogs(const std::string &nexusfilename,
API::MatrixWorkspace_sptr localWorkspace, Algorithm &alg,
bool returnpulsetimes);
bool returnpulsetimes, int& size_t, std::unique_ptr<const Kernel::TimeSeriesProperty<int> >& periodLog);

static void loadEntryMetadata(const std::string &nexusfilename,
Mantid::API::MatrixWorkspace_sptr WS,
Expand All @@ -133,7 +145,7 @@ class DLLExport LoadEventNexus

static void
loadSampleDataISIScompatibility(::NeXus::File &file,
Mantid::API::MatrixWorkspace_sptr WS);
DecoratorWorkspace& WS);

/// method used to return instrument name for some old ISIS files where it is
/// not written properly within the instrument
Expand All @@ -144,7 +156,7 @@ class DLLExport LoadEventNexus
std::string m_filename;

/// The workspace being filled out
DataObjects::EventWorkspace_sptr WS;
boost::shared_ptr<DecoratorWorkspace> m_ws;

/// Filter by a minimum time-of-flight
double filter_tof_min;
Expand Down Expand Up @@ -196,7 +208,7 @@ class DLLExport LoadEventNexus

/// Vector where index = event_id; value = ptr to std::vector<TofEvent> in the
/// event list.
std::vector<EventVector_pt> eventVectors;
std::vector<std::vector<EventVector_pt> > eventVectors;

/// Mutex to protect eventVectors from each task
Poco::Mutex m_eventVectorMutex;
Expand Down Expand Up @@ -233,7 +245,7 @@ class DLLExport LoadEventNexus

/// Vector where index = event_id; value = ptr to std::vector<WeightedEvent>
/// in the event list.
std::vector<WeightedEventVector_pt> weightedEventVectors;
std::vector<std::vector<WeightedEventVector_pt> > weightedEventVectors;

private:
/// Intialisation code
Expand All @@ -245,7 +257,7 @@ class DLLExport LoadEventNexus
DataObjects::EventWorkspace_sptr createEmptyEventWorkspace();

/// Map detector IDs to event lists.
template <class T> void makeMapToEventLists(std::vector<T> &vectors);
template <class T> void makeMapToEventLists(std::vector<std::vector<T> > &vectors);

void createWorkspaceIndexMaps(const bool monitors, const std::vector<std::string> &bankNames);
void loadEvents(API::Progress *const prog, const bool monitors);
Expand Down Expand Up @@ -282,10 +294,6 @@ class DLLExport LoadEventNexus
/// Set the top entry field name
void setTopEntryName();

/// to re-use (copy) logs from data workspace to monitors, etc. workspace
void copyLogs(const DataObjects::EventWorkspace_sptr& from,
DataObjects::EventWorkspace_sptr& to);

/// to open the nexus file with specific exception handling/message
void safeOpenFile(const std::string fname);

Expand Down
Expand Up @@ -93,6 +93,8 @@ class DLLExport LoadNexusLogs : public API::Algorithm {
boost::shared_ptr<API::MatrixWorkspace> workspace) const;
void loadVetoPulses(::NeXus::File &file,
boost::shared_ptr<API::MatrixWorkspace> workspace) const;
void loadNPeriods(::NeXus::File &file,
boost::shared_ptr<API::MatrixWorkspace> workspace) const;

/// Create a time series property
Kernel::Property *createTimeSeries(::NeXus::File &file,
Expand Down

0 comments on commit 6d59e1d

Please sign in to comment.