Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend LoadEventNexus For MultiPeriod Events #12963

Merged
merged 23 commits into from Jul 6, 2015
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
51037a0
refs #12776. Update LoadNexusLogs
OwenArnold Jun 16, 2015
7a392fb
refs #12776. Rename ws-member
OwenArnold Jun 16, 2015
6afcbee
refs #12776. Make single use explicit.
OwenArnold Jun 22, 2015
c69981f
refs #12776. Read N Periods.
OwenArnold Jun 22, 2015
9587a19
refs #12776. Add loop setters.
OwenArnold Jun 23, 2015
90f1983
refs #12776. Move to single vector of workspaces.
OwenArnold Jun 23, 2015
35601a1
refs #12776. Load Frame-Period number info.
OwenArnold Jun 25, 2015
bf62c2d
refs #12776. Direct events to correct workspace based on period.
OwenArnold Jun 25, 2015
c32a26e
refs #12776. EventWorkspace -> Workspace as OutputWorkspace property.
OwenArnold Jun 26, 2015
21d369c
refs #12776. Stop mp event monitor loading.
OwenArnold Jun 26, 2015
d4b28cd
refs #12776. Write multiperiod group workspace.
OwenArnold Jun 26, 2015
801a489
refs #12776. Write individual period logs.
OwenArnold Jun 29, 2015
b8c7f43
refs #12776. Refactor and fix warnings.
OwenArnold Jun 29, 2015
5a6dc80
refs #12776. Actually add the files.
OwenArnold Jun 29, 2015
8d58f5a
refs #12776 fix build errors.
OwenArnold Jun 30, 2015
b4393c9
refs #12776 remove override keyword.
OwenArnold Jun 30, 2015
9ff1e34
Merge branch 'master' of github.com:mantidproject/mantid into 12776_m…
OwenArnold Jul 1, 2015
c071ac5
refs #12776 Disable copy and assignment.
OwenArnold Jul 1, 2015
4224944
refs #12776 Disable copy and assignment again.
OwenArnold Jul 1, 2015
90ffa66
refs #12776. Handle where periodnumber is 0
OwenArnold Jul 2, 2015
d13203b
refs #12776. Set sample info
OwenArnold Jul 3, 2015
8a1ca5f
refs #12776. Copy goniometer across
OwenArnold Jul 3, 2015
764f62c
refs #12776. Code review changes.
OwenArnold Jul 6, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -117,7 +117,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 @@ -126,10 +126,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 @@ -158,7 +158,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 @@ -303,7 +303,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 @@ -337,7 +337,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 * const 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