From a0336a1739c76bf2dbbe123d1a79a153b7beb98d Mon Sep 17 00:00:00 2001 From: Martyn Gigg <martyn.gigg@stfc.ac.uk> Date: Mon, 26 Jul 2010 07:22:06 +0000 Subject: [PATCH] Converted all uses of the logs on the Sample class to use the new Run class. Also cleared some warnings. Re #1416 --- .../API/inc/MantidAPI/MatrixWorkspace.h | 14 +- Code/Mantid/API/inc/MantidAPI/Run.h | 23 + Code/Mantid/API/inc/MantidAPI/Sample.h | 35 +- Code/Mantid/API/src/MatrixWorkspace.cpp | 25 +- Code/Mantid/API/src/Run.cpp | 4 +- Code/Mantid/API/src/Sample.cpp | 59 +- Code/Mantid/API/src/WorkspaceFactory.cpp | 1 + Code/Mantid/API/test/MatrixWorkspaceTest.h | 18 +- Code/Mantid/API/test/WorkspaceFactoryTest.h | 26 +- Code/Mantid/API/test/WorkspacePropertyTest.h | 40 +- .../inc/MantidAlgorithms/BinaryOperation.h | 6 +- .../MantidAlgorithms/CheckWorkspacesMatch.h | 2 + .../Algorithms/inc/MantidAlgorithms/Plus.h | 4 +- Code/Mantid/Algorithms/src/AddSampleLog.cpp | 6 +- .../Mantid/Algorithms/src/BinaryOperation.cpp | 2 +- .../Algorithms/src/CheckWorkspacesMatch.cpp | 52 +- Code/Mantid/Algorithms/src/GetEi2.cpp | 29 +- .../Algorithms/src/MedianDetectorTest.cpp | 14 +- .../Algorithms/src/NormaliseByCurrent.cpp | 12 +- .../src/PlotAsymmetryByLogValue.cpp | 6 +- Code/Mantid/Algorithms/src/Plus.cpp | 10 +- .../Mantid/Algorithms/test/AddSampleLogTest.h | 33 +- .../test/CheckWorkspacesMatchTest.h | 8 +- .../Algorithms/test/NormaliseByCurrentTest.h | 2 +- Code/Mantid/Algorithms/test/PlusTest.h | 29 + .../CurveFitting/src/PlotPeakByLogValue.cpp | 2 +- .../test/PlotPeakByLogValueTest.h | 2 +- .../inc/MantidDataHandling/LoadLog.h | 124 +- .../inc/MantidDataHandling/LoadRawHelper.h | 186 +- Code/Mantid/DataHandling/src/LoadCanSAS1D.cpp | 5 +- Code/Mantid/DataHandling/src/LoadDAE.cpp | 2 +- .../DataHandling/src/LoadEventPreNeXus.cpp | 6 +- Code/Mantid/DataHandling/src/LoadLog.cpp | 23 +- Code/Mantid/DataHandling/src/LoadRaw.cpp | 7 +- Code/Mantid/DataHandling/src/LoadRaw2.cpp | 37 +- Code/Mantid/DataHandling/src/LoadRaw3.cpp | 32 +- Code/Mantid/DataHandling/src/LoadRawBin0.cpp | 15 +- .../Mantid/DataHandling/src/LoadRawHelper.cpp | 1669 +++++++++-------- .../DataHandling/src/LoadRawSpectrum0.cpp | 14 +- Code/Mantid/DataHandling/src/SaveCanSAS1D.cpp | 24 +- .../DataHandling/test/LoadCanSAS1dTest.h | 2 +- Code/Mantid/DataHandling/test/LoadDAETest.h | 8 +- Code/Mantid/DataHandling/test/LoadLogTest.h | 28 +- Code/Mantid/DataHandling/test/LoadRaw2Test.h | 21 +- Code/Mantid/DataHandling/test/LoadRaw3Test.h | 42 +- .../DataHandling/test/LoadRawBin0Test.h | 16 +- .../DataHandling/test/LoadRawSpectrum0Test.h | 15 +- Code/Mantid/DataHandling/test/LoadRawTest.h | 10 +- .../test/ManagedRawFileWorkspace2DTest.h | 4 +- .../DataHandling/test/SaveCanSAS1dTest.h | 11 +- .../inc/MantidDataObjects/EventWorkspace.h | 4 +- .../inc/MantidDataObjects/Workspace1D.h | 2 +- .../inc/MantidDataObjects/Workspace2D.h | 2 +- .../MantidDataObjects/WorkspaceSingleValue.h | 2 +- .../Mantid/DataObjects/src/EventWorkspace.cpp | 4 +- Code/Mantid/DataObjects/src/Workspace2D.cpp | 2 +- .../Geometry/inc/MantidGeometry/IComponent.h | 2 +- .../inc/MantidGeometry/Instrument/Component.h | 2 +- .../MantidGeometry/Instrument/DetectorGroup.h | 2 +- .../Instrument/ParametrizedComponent.h | 2 +- .../Geometry/src/Instrument/Component.cpp | 2 +- .../src/Instrument/ParametrizedComponent.cpp | 2 +- .../Kernel/inc/MantidKernel/ConfigService.h | 2 +- .../Mantid/Kernel/inc/MantidKernel/Property.h | 2 +- .../inc/MantidKernel/PropertyWithValue.h | 2 +- Code/Mantid/Kernel/src/ConfigService.cpp | 2 +- Code/Mantid/Kernel/src/Property.cpp | 1 + Code/Mantid/Kernel/src/SupportBasic.cpp | 4 +- .../Nexus/inc/MantidNexus/LoadISISNexus2.h | 3 +- .../Nexus/inc/MantidNexus/LoadSNSNexus.h | 1 - .../Nexus/inc/MantidNexus/NexusFileIO.h | 33 +- .../Nexus/inc/MantidNexus/NexusFileWriter.h | 94 - Code/Mantid/Nexus/src/LoadISISNexus.cpp | 14 +- Code/Mantid/Nexus/src/LoadISISNexus2.cpp | 34 +- Code/Mantid/Nexus/src/LoadMuonLog.cpp | 5 +- Code/Mantid/Nexus/src/LoadMuonNexus.cpp | 12 +- Code/Mantid/Nexus/src/LoadMuonNexus2.cpp | 8 +- Code/Mantid/Nexus/src/LoadNexusProcessed.cpp | 5 +- Code/Mantid/Nexus/src/LoadSNSNexus.cpp | 10 +- Code/Mantid/Nexus/src/NexusFileIO.cpp | 540 +----- Code/Mantid/Nexus/src/NexusFileWriter.cpp | 457 ----- Code/Mantid/Nexus/src/SaveNexusProcessed.cpp | 10 +- Code/Mantid/Nexus/test/LoadISISNexusTest.h | 16 +- Code/Mantid/Nexus/test/LoadMuonLogTest.h | 7 +- Code/Mantid/Nexus/test/LoadMuonNexus2Test.h | 6 +- Code/Mantid/Nexus/test/LoadMuonNexusTest.h | 2 +- .../Nexus/test/LoadNexusProcessedTest.h | 2 +- .../Nexus/test/LoadRSaveNLoadNcspTest.h | 8 +- Code/Mantid/Nexus/test/LoadSNSNexusTest.h | 12 +- .../Nexus/test/SaveNexusProcessedTest.h | 2 +- Code/Mantid/PythonAPI/src/api_exports.cpp | 28 +- Code/Mantid/build.sh | 31 +- Code/RPM_Kit/mantid.spec.template | 3 + .../src/PlotAsymmetryByLogValueDialog.cpp | 4 +- .../qtiplot/src/Mantid/FitPropertyBrowser.cpp | 2 +- .../src/Mantid/MantidSampleLogDialog.cpp | 2 +- Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp | 6 +- .../src/Mantid/SequentialFitDialog.cpp | 2 +- 98 files changed, 1595 insertions(+), 2570 deletions(-) delete mode 100644 Code/Mantid/Nexus/inc/MantidNexus/NexusFileWriter.h delete mode 100644 Code/Mantid/Nexus/src/NexusFileWriter.cpp diff --git a/Code/Mantid/API/inc/MantidAPI/MatrixWorkspace.h b/Code/Mantid/API/inc/MantidAPI/MatrixWorkspace.h index 8b7726eee22..a73dbb63b5c 100644 --- a/Code/Mantid/API/inc/MantidAPI/MatrixWorkspace.h +++ b/Code/Mantid/API/inc/MantidAPI/MatrixWorkspace.h @@ -8,6 +8,7 @@ #include "MantidAPI/WorkspaceHistory.h" #include "MantidAPI/Instrument.h" #include "MantidAPI/Sample.h" +#include "MantidAPI/Run.h" #include "MantidAPI/WorkspaceIterator.h" #include "MantidAPI/Axis.h" #include "MantidGeometry/Instrument/ParameterMap.h" @@ -82,6 +83,11 @@ public: const Sample& sample() const; Sample& mutableSample(); + /// Run details object access + const Run & run() const; + /// Writable version of the run object + Run& mutableRun(); + /// Get a detector object (Detector or DetectorGroup) for the given spectrum index Geometry::IDetector_sptr getDetector(const int index) const; double detectorTwoTheta(Geometry::IDetector_const_sptr det) const; @@ -102,7 +108,7 @@ public: /// Returns the size of each block of data returned by the dataY accessors virtual int blocksize() const = 0; /// Returns the number of histograms in the workspace - virtual const int getNumberHistograms() const = 0; + virtual int getNumberHistograms() const = 0; /// Returns the bin index for a given X value of a given workspace index size_t binIndexOf(const double xValue, const int index = 0) const; @@ -138,12 +144,12 @@ public: virtual void setX(const int index, const Kernel::cow_ptr<MantidVec>& X) = 0; //---------------------------------------------------------------------- - const int axes() const; + int axes() const; Axis* const getAxis(const int& axisIndex) const; void replaceAxis(const int& axisIndex, Axis* const newAxis); /// Returns true if the workspace contains data in histogram form (as opposed to point-like) - virtual const bool isHistogramData() const; + virtual bool isHistogramData() const; std::string YUnit() const; void setYUnit(const std::string& newUnit); @@ -185,6 +191,8 @@ private: Kernel::cow_ptr<SpectraDetectorMap> m_spectramap; /// The information on the sample environment Kernel::cow_ptr<Sample> m_sample; + /// The run information + Kernel::cow_ptr<Run> m_run; /// The unit for the data values (e.g. Counts) std::string m_YUnit; diff --git a/Code/Mantid/API/inc/MantidAPI/Run.h b/Code/Mantid/API/inc/MantidAPI/Run.h index e140648ff42..a19816f6250 100644 --- a/Code/Mantid/API/inc/MantidAPI/Run.h +++ b/Code/Mantid/API/inc/MantidAPI/Run.h @@ -49,6 +49,8 @@ namespace Mantid /// Add data to the object in the form of a property void addProperty(Kernel::Property *prop); + /// Does the property exist on the object + bool hasProperty(const std::string & name) const { return Kernel::PropertyManager::existsProperty(name); } // Expose some of the PropertyManager publicly using Kernel::PropertyManager::removeProperty; @@ -61,6 +63,27 @@ namespace Mantid void setProtonCharge( const double charge); /// Get the proton charge double getProtonCharge() const; + /** + * Add a log entry + * @parma p A pointer to the property containing the log entry + */ + void addLogData( Kernel::Property *p ) { addProperty(p); } + /** + * Access a single log entry + * @param name The name of the log entry to retrieve + * @returns A pointer to a property containing the log entry + */ + Kernel::Property* getLogData( const std::string &name ) const { return getProperty(name); } + /** + * Access all log entries + * @returns A list of all of the log entries + */ + const std::vector< Kernel::Property* >& getLogData() const {return getProperties(); } + /** + * Remove a named log entry + * @param name The name of the entry to remove + */ + void removeLogData(const std::string &name) { return removeProperty(name); } //@} private: diff --git a/Code/Mantid/API/inc/MantidAPI/Sample.h b/Code/Mantid/API/inc/MantidAPI/Sample.h index d1b3c10e05f..192845244bc 100644 --- a/Code/Mantid/API/inc/MantidAPI/Sample.h +++ b/Code/Mantid/API/inc/MantidAPI/Sample.h @@ -4,7 +4,6 @@ //---------------------------------------------------------------------- // Includes //---------------------------------------------------------------------- -#include "MantidKernel/PropertyManager.h" #include "MantidGeometry/Objects/Object.h" namespace Mantid @@ -41,47 +40,45 @@ namespace API class DLLExport Sample { public: + /// Default constructor Sample(); + /// Virtual destructor virtual ~Sample(); + /// Set the name of the sample void setName( const std::string &name ); + /// Returns the name of the sample const std::string& getName() const; - - void addLogData( Kernel::Property *p ); - Kernel::Property* getLogData( const std::string &name ) const; - const std::vector< Kernel::Property* >& getLogData() const; - void removeLogData(const std::string &name); - - void setProtonCharge( const double &charge); - const double& getProtonCharge() const; - + /// Set the geometrical shape of the sample void setShapeObject(const Geometry::Object & sample_shape); + /// Returns the geometrical shape of the sample const Geometry::Object& getShapeObject() const; + /// Sets the geometry flag void setGeometryFlag(int geom_id); + /// Returns the geometry flag int getGeometryFlag() const; - + /// Sets the thickness void setThickness(double thick); + /// Returns the thickness double getThickness() const; - + /// Sets the height void setHeight(double height); + /// Returns the height double getHeight() const; - + /// Sets the width void setWidth(double width); + /// Returns the width double getWidth() const; - ///// copy constructor. + /// Copy constructor. Sample(const Sample& copy); - ///// copy assignment operator. + /// Copy assignment operator. const Sample& operator=(const Sample& rhs); private: /// The name for the sample std::string m_name; - /// Stores the information read in from the logfiles. - Kernel::PropertyManager m_manager; - /// The good proton charge for this run in uA.hour - double m_protonCharge; /// The sample shape object Geometry::Object m_sample_shape; /// The sample geometry flag diff --git a/Code/Mantid/API/src/MatrixWorkspace.cpp b/Code/Mantid/API/src/MatrixWorkspace.cpp index 21540b2e1ae..06b580b2f71 100644 --- a/Code/Mantid/API/src/MatrixWorkspace.cpp +++ b/Code/Mantid/API/src/MatrixWorkspace.cpp @@ -19,7 +19,7 @@ Kernel::Logger& MatrixWorkspace::g_log = Kernel::Logger::get("MatrixWorkspace"); /// Default constructor MatrixWorkspace::MatrixWorkspace() : Workspace(), m_axes(), m_isInitialized(false), - sptr_instrument(new Instrument), m_spectramap(), m_sample(), + sptr_instrument(new Instrument), m_spectramap(), m_sample(), m_run(), m_YUnit(), m_YUnitLabel(), m_isDistribution(false), m_parmap(), m_masks() {} @@ -127,6 +127,23 @@ Sample& MatrixWorkspace::mutableSample() return m_sample.access(); } +/** Get a constant reference to the Run object associated with this workspace. + */ +const Run& MatrixWorkspace::run() const +{ + return *m_run; +} + +/** Get a reference to the Run object associated with this workspace. + * This non-const method will copy the Run object if it is shared between + * more than one workspace, and the reference returned will be to the copy. + * Can ONLY be taken by reference! + */ +Run& MatrixWorkspace::mutableRun() +{ + return m_run.access(); +} + /** Get the effective detector for the given spectrum * @param index The workspace index for which the detector is required * @return A single detector object representing the detector(s) contributing @@ -214,7 +231,7 @@ const Geometry::ParameterMap& MatrixWorkspace::constInstrumentParameters() const } /// The number of axes which this workspace has -const int MatrixWorkspace::axes() const +int MatrixWorkspace::axes() const { return static_cast<int>(m_axes.size()); } @@ -265,7 +282,7 @@ void MatrixWorkspace::replaceAxis(const int& axisIndex, Axis* const newAxis) } /// Returns true if the workspace contains data in histogram form, false if it's point-like -const bool MatrixWorkspace::isHistogramData() const +bool MatrixWorkspace::isHistogramData() const { return ( readX(0).size()==readY(0).size() ? false : true ); } @@ -396,7 +413,7 @@ void MatrixWorkspace::populateInstrumentParameters() // Get the data in the logfiles associated with the raw data - const std::vector<Kernel::Property*>& logfileProp = sample().getLogData(); + const std::vector<Kernel::Property*>& logfileProp = run().getLogData(); // Get pointer to parameter map that we may add parameters to and information about diff --git a/Code/Mantid/API/src/Run.cpp b/Code/Mantid/API/src/Run.cpp index 2f4955f23f6..d4a22ddca9a 100644 --- a/Code/Mantid/API/src/Run.cpp +++ b/Code/Mantid/API/src/Run.cpp @@ -14,7 +14,7 @@ namespace Mantid /** * Default constructor */ - Run::Run() : PropertyManager(), m_protonChargeName("proton-charge") + Run::Run() : PropertyManager(), m_protonChargeName("proton_charge_tot") { } @@ -40,7 +40,7 @@ namespace Mantid */ void Run::setProtonCharge(const double charge) { - if( !existsProperty(m_protonChargeName) ) + if( !hasProperty(m_protonChargeName) ) { addProperty(new Kernel::PropertyWithValue<double>(m_protonChargeName, charge)); } diff --git a/Code/Mantid/API/src/Sample.cpp b/Code/Mantid/API/src/Sample.cpp index 9f821f80963..70e889a4abb 100644 --- a/Code/Mantid/API/src/Sample.cpp +++ b/Code/Mantid/API/src/Sample.cpp @@ -10,7 +10,7 @@ namespace API /// Constructor Sample::Sample() : - m_name(), m_manager(), m_protonCharge(0.0), m_sample_shape(), m_geom_id(0), m_thick(0.0), + m_name(), m_sample_shape(), m_geom_id(0), m_thick(0.0), m_height(0.0), m_width(0.0) { } @@ -19,8 +19,7 @@ Sample::Sample() : * @param copy const reference to the sample object */ Sample::Sample(const Sample& copy) : - m_name(copy.m_name), m_manager(copy.m_manager), m_protonCharge(copy.m_protonCharge), - m_sample_shape(copy.m_sample_shape), m_geom_id(copy.m_geom_id), + m_name(copy.m_name), m_sample_shape(copy.m_sample_shape), m_geom_id(copy.m_geom_id), m_thick(copy.m_thick), m_height(copy.m_height), m_width(copy.m_width) { } @@ -32,8 +31,6 @@ Sample::Sample(const Sample& copy) : { if (this == &rhs) return *this; m_name = rhs.m_name; - m_manager = rhs.m_manager; - m_protonCharge = rhs.m_protonCharge; m_sample_shape = rhs.m_sample_shape; m_geom_id = rhs.m_geom_id; m_thick = rhs.m_thick; @@ -63,48 +60,6 @@ const std::string& Sample::getName() const return m_name; } -/** Add a set of data as read in from a log file. - * Note that the sample takes over ownership of the data, so the user should not delete it. - * @param p A pointer to the property (typically a TimeSeriesProperty) containing the data. - */ -void Sample::addLogData( Kernel::Property *p ) -{ - m_manager.declareProperty(p); -} - -/** Retrieve a particular dataset - * @param name The name of the dataset (as contained in the original property object) - * @return A pointer to the property containing the dataset - */ -Kernel::Property* Sample::getLogData( const std::string &name ) const -{ - return m_manager.getProperty(name); -} - -/** Retrieve the full set of log properties - * @return A vector of pointers to the property objects - */ -const std::vector<Kernel::Property*>& Sample::getLogData() const -{ - return m_manager.getProperties(); -} - -/** Set the good proton charge total for this run - * @param charge The proton charge in uA.hour - */ -void Sample::setProtonCharge( const double &charge) -{ - m_protonCharge = charge; -} - -/** Retrieve the total good proton charge delivered in this run - * @return The proton charge in uA.hour - */ -const double& Sample::getProtonCharge() const -{ - return m_protonCharge; -} - /** * Set the object that describes the sample shape * @param sample_shape The shape object @@ -197,13 +152,5 @@ double Sample::getWidth() const return m_width; } -/**Deletes a log data item - * @param name The name of the item to delete - */ -void Sample::removeLogData(const std::string &name) -{ - m_manager.removeProperty(name); } - -} // namespace API -} // namespace Mantid +} diff --git a/Code/Mantid/API/src/WorkspaceFactory.cpp b/Code/Mantid/API/src/WorkspaceFactory.cpp index c164a50760e..cb823a34fd4 100644 --- a/Code/Mantid/API/src/WorkspaceFactory.cpp +++ b/Code/Mantid/API/src/WorkspaceFactory.cpp @@ -87,6 +87,7 @@ void WorkspaceFactoryImpl::initializeFromParent(const MatrixWorkspace_const_sptr child->setInstrument(parent->getInstrument()); // This call also copies the parameter map child->m_spectramap = parent->m_spectramap; child->m_sample = parent->m_sample; + child->m_run = parent->m_run; child->setYUnit(parent->m_YUnit); child->setYUnitLabel(parent->m_YUnitLabel); child->isDistribution(parent->isDistribution()); diff --git a/Code/Mantid/API/test/MatrixWorkspaceTest.h b/Code/Mantid/API/test/MatrixWorkspaceTest.h index d58040032d0..d9f2e8fa998 100644 --- a/Code/Mantid/API/test/MatrixWorkspaceTest.h +++ b/Code/Mantid/API/test/MatrixWorkspaceTest.h @@ -20,7 +20,7 @@ public: virtual ~WorkspaceTester() {} // Empty overrides of virtual methods - virtual const int getNumberHistograms() const { return 1;} + virtual int getNumberHistograms() const { return 1;} const std::string id() const {return "WorkspaceTester";} void init(const int& i, const int& j, const int& k) { @@ -31,14 +31,14 @@ public: } int size() const {return vec.size();} int blocksize() const {return vec.size();} - MantidVec& dataX(int const index) {return vec;} - MantidVec& dataY(int const index) {return vec;} - MantidVec& dataE(int const index) {return vec;} - const MantidVec& dataX(int const index) const {return vec;} - const MantidVec& dataY(int const index) const {return vec;} - const MantidVec& dataE(int const index) const {return vec;} - Kernel::cow_ptr<MantidVec> refX(const int index) const {return Kernel::cow_ptr<MantidVec>();} - void setX(const int index, const Kernel::cow_ptr<MantidVec>& X) {} + MantidVec& dataX(int const ) {return vec;} + MantidVec& dataY(int const ) {return vec;} + MantidVec& dataE(int const ) {return vec;} + const MantidVec& dataX(int const) const {return vec;} + const MantidVec& dataY(int const) const {return vec;} + const MantidVec& dataE(int const) const {return vec;} + Kernel::cow_ptr<MantidVec> refX(const int) const {return Kernel::cow_ptr<MantidVec>();} + void setX(const int, const Kernel::cow_ptr<MantidVec>&) {} private: MantidVec vec; diff --git a/Code/Mantid/API/test/WorkspaceFactoryTest.h b/Code/Mantid/API/test/WorkspaceFactoryTest.h index b72896caf94..9a2a1ba9161 100644 --- a/Code/Mantid/API/test/WorkspaceFactoryTest.h +++ b/Code/Mantid/API/test/WorkspaceFactoryTest.h @@ -20,7 +20,7 @@ class WorkspaceFactoryTest : public CxxTest::TestSuite class WorkspaceTest: public MatrixWorkspace { public: - virtual const int getNumberHistograms() const { return 1;} + virtual int getNumberHistograms() const { return 1;} WorkspaceTest() : data(MantidVec(1,1)) {} // static std::string WSTYPE; @@ -28,21 +28,21 @@ class WorkspaceFactoryTest : public CxxTest::TestSuite //section required to support iteration virtual int size() const {return 1000000;} virtual int blocksize() const {return 10000;} - virtual MantidVec& dataX(int const index) {return data;} + virtual MantidVec& dataX(int const) {return data;} ///Returns the y data - virtual MantidVec& dataY(int const index) {return data;} + virtual MantidVec& dataY(int const) {return data;} ///Returns the error data - virtual MantidVec& dataE(int const index) {return data;} + virtual MantidVec& dataE(int const) {return data;} - virtual const MantidVec& dataX(int const index)const {return data;} + virtual const MantidVec& dataX(int const)const {return data;} ///Returns the y data - virtual const MantidVec& dataY(int const index)const {return data;} + virtual const MantidVec& dataY(int const)const {return data;} ///Returns the error data - virtual const MantidVec& dataE(int const index)const {return data;} - cow_ptr<MantidVec> refX(const int index) const {return cow_ptr<MantidVec>();} - void setX(const int index, const cow_ptr<MantidVec>& X) {} + virtual const MantidVec& dataE(int const)const {return data;} + cow_ptr<MantidVec> refX(const int) const {return cow_ptr<MantidVec>();} + void setX(const int, const cow_ptr<MantidVec>& ) {} - virtual void init(const int &NVectors, const int &XLength, const int &YLength){}; + virtual void init(const int &, const int &, const int &){}; private: MantidVec data; @@ -52,7 +52,7 @@ class WorkspaceFactoryTest : public CxxTest::TestSuite class Workspace1DTest: public WorkspaceTest { public: - const int getNumberHistograms() const { return 1;} + int getNumberHistograms() const { return 1;} // static std::string WSTYPE; const std::string id() const {return "Workspace1DTest";} }; @@ -62,7 +62,7 @@ class WorkspaceFactoryTest : public CxxTest::TestSuite public: // static std::string WSTYPE; const std::string id() const {return "Workspace2DTest";} - const int getNumberHistograms() const { return 2;} + int getNumberHistograms() const { return 2;} void init(const int &NVectors, const int &XLength, const int &YLength) { @@ -78,7 +78,7 @@ class WorkspaceFactoryTest : public CxxTest::TestSuite public: // static std::string WSTYPE; const std::string id() const {return "ManagedWorkspace2D";} - const int getNumberHistograms() const { return 2;} + int getNumberHistograms() const { return 2;} }; class NotInFactory : public WorkspaceTest diff --git a/Code/Mantid/API/test/WorkspacePropertyTest.h b/Code/Mantid/API/test/WorkspacePropertyTest.h index d3f9d3f4b82..b693ba5e029 100644 --- a/Code/Mantid/API/test/WorkspacePropertyTest.h +++ b/Code/Mantid/API/test/WorkspacePropertyTest.h @@ -18,26 +18,26 @@ class WorkspacePropertyTest : public CxxTest::TestSuite class WorkspaceTest: public MatrixWorkspace { public: - virtual const int getNumberHistograms() const { return 1;} + virtual int getNumberHistograms() const { return 1;} const std::string id() const {return "WorkspacePropTest";} //section required to support iteration virtual int size() const {return 0;} virtual int blocksize() const {return 1000000;} - virtual MantidVec& dataX(int const index) {return data;} + virtual MantidVec& dataX(int const) {return data;} ///Returns the y data - virtual MantidVec& dataY(int const index) {return data;} + virtual MantidVec& dataY(int const) {return data;} ///Returns the error data - virtual MantidVec& dataE(int const index) {return data;} + virtual MantidVec& dataE(int const) {return data;} - virtual const MantidVec& dataX(int const index)const {return data;} + virtual const MantidVec& dataX(int const)const {return data;} ///Returns the y data - virtual const MantidVec& dataY(int const index)const {return data;} + virtual const MantidVec& dataY(int const )const {return data;} ///Returns the error data - virtual const MantidVec& dataE(int const index)const {return data;} - cow_ptr<MantidVec> refX(const int index) const {return cow_ptr<MantidVec>();} - void setX(const int index, const cow_ptr<MantidVec>& X) {} - virtual void init(const int &NVectors, const int &XLength, const int &YLength){}; + virtual const MantidVec& dataE(int const)const {return data;} + cow_ptr<MantidVec> refX(const int) const {return cow_ptr<MantidVec>();} + void setX(const int, const cow_ptr<MantidVec>&) {} + virtual void init(const int &, const int &, const int &){}; private: MantidVec data; @@ -48,26 +48,26 @@ class WorkspacePropertyTest : public CxxTest::TestSuite class WorkspaceTest2 : public MatrixWorkspace { public: - virtual const int getNumberHistograms() const { return 1;} + virtual int getNumberHistograms() const { return 1;} const std::string id() const {return "WorkspacePropTest";} //section required to support iteration virtual int size() const {return 0;} virtual int blocksize() const {return 1000000;} - virtual MantidVec& dataX(int const index) {return data;} + virtual MantidVec& dataX(int const) {return data;} ///Returns the y data - virtual MantidVec& dataY(int const index) {return data;} + virtual MantidVec& dataY(int const) {return data;} ///Returns the error data - virtual MantidVec& dataE(int const index) {return data;} + virtual MantidVec& dataE(int const) {return data;} - virtual const MantidVec& dataX(int const index)const {return data;} + virtual const MantidVec& dataX(int const)const {return data;} ///Returns the y data - virtual const MantidVec& dataY(int const index)const {return data;} + virtual const MantidVec& dataY(int const)const {return data;} ///Returns the error data - virtual const MantidVec& dataE(int const index)const {return data;} - cow_ptr<MantidVec> refX(const int index) const {return cow_ptr<MantidVec>();} - void setX(const int index, const cow_ptr<MantidVec>& X) {} - virtual void init(const int &NVectors, const int &XLength, const int &YLength){}; + virtual const MantidVec& dataE(int const)const {return data;} + cow_ptr<MantidVec> refX(const int) const {return cow_ptr<MantidVec>();} + void setX(const int, const cow_ptr<MantidVec>&) {} + virtual void init(const int &, const int &, const int &){}; private: MantidVec data; diff --git a/Code/Mantid/Algorithms/inc/MantidAlgorithms/BinaryOperation.h b/Code/Mantid/Algorithms/inc/MantidAlgorithms/BinaryOperation.h index a626b0f6787..3833d78d73c 100644 --- a/Code/Mantid/Algorithms/inc/MantidAlgorithms/BinaryOperation.h +++ b/Code/Mantid/Algorithms/inc/MantidAlgorithms/BinaryOperation.h @@ -7,7 +7,7 @@ #include "MantidAPI/PairedGroupAlgorithm.h" #include "MantidAPI/Workspace.h" #include "MantidAPI/WorkspaceGroup.h" -#include "MantidAPI/Sample.h" +#include "MantidAPI/Run.h" namespace Mantid { @@ -108,13 +108,13 @@ namespace Mantid */ virtual void setOutputUnits(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs,API::MatrixWorkspace_sptr out) {} - /** Only overridden by operations that affect the properties of the sample (e.g. Plus + /** Only overridden by operations that affect the properties of the run (e.g. Plus * where the proton currents (charges) are added). Otherwise it does nothing. * @param lhs one of the workspaces to operate on * @param rhs the other workspace * @param ans the output workspace */ - virtual void operateOnSample(const API::Sample& lhs, const API::Sample& rhs, API::Sample& ans) const {}; + virtual void operateOnRun(const API::Run& lhs, const API::Run& rhs, API::Run& ans) const {}; private: void doSingleValue(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs,API::MatrixWorkspace_sptr out); diff --git a/Code/Mantid/Algorithms/inc/MantidAlgorithms/CheckWorkspacesMatch.h b/Code/Mantid/Algorithms/inc/MantidAlgorithms/CheckWorkspacesMatch.h index fdb1e5df0b4..b5d66ac292e 100644 --- a/Code/Mantid/Algorithms/inc/MantidAlgorithms/CheckWorkspacesMatch.h +++ b/Code/Mantid/Algorithms/inc/MantidAlgorithms/CheckWorkspacesMatch.h @@ -30,6 +30,7 @@ namespace Algorithms <LI> CheckSpectraMap - Whether to check that the spectra-detector maps match (default: true) </LI> <LI> CheckInstrument - Whether to check that the instruments match (default: true) </LI> <LI> CheckMasking - Whether to check that the bin masking matches (default: true) </LI> + <LI> CheckSample - Whether to check that the sample object mathces (default: false) </LI> </UL> Output Properties: @@ -87,6 +88,7 @@ private: bool checkInstrument(API::MatrixWorkspace_const_sptr ws1, API::MatrixWorkspace_const_sptr ws2); bool checkMasking(API::MatrixWorkspace_const_sptr ws1, API::MatrixWorkspace_const_sptr ws2); bool checkSample(const API::Sample& sample1, const API::Sample& sample2); + bool checkRunProperties(const API::Run& run1, const API::Run& run2); std::string result; ///< the result string }; diff --git a/Code/Mantid/Algorithms/inc/MantidAlgorithms/Plus.h b/Code/Mantid/Algorithms/inc/MantidAlgorithms/Plus.h index cbc216c8994..dbc61d98862 100644 --- a/Code/Mantid/Algorithms/inc/MantidAlgorithms/Plus.h +++ b/Code/Mantid/Algorithms/inc/MantidAlgorithms/Plus.h @@ -5,7 +5,7 @@ // Includes //---------------------------------------------------------------------- #include "MantidAlgorithms/CommutativeBinaryOperation.h" -#include "MantidAPI/Sample.h" +#include "MantidAPI/Run.h" namespace Mantid { @@ -64,7 +64,7 @@ namespace Mantid void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE, const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut); bool checkCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const; - void operateOnSample(const API::Sample& lhs, const API::Sample& rhs, API::Sample & ans) const; + void operateOnRun(const API::Run& lhs, const API::Run& rhs, API::Run & ans) const; }; } // namespace Algorithm diff --git a/Code/Mantid/Algorithms/src/AddSampleLog.cpp b/Code/Mantid/Algorithms/src/AddSampleLog.cpp index 7aab14aea3c..7e9b68fe86b 100644 --- a/Code/Mantid/Algorithms/src/AddSampleLog.cpp +++ b/Code/Mantid/Algorithms/src/AddSampleLog.cpp @@ -30,14 +30,14 @@ void AddSampleLog::exec() { // A pointer to the workspace to add a log to MatrixWorkspace_sptr wSpace = getProperty("Workspace"); - // we're going to edit the workspaces sample so get a non-const reference to it - Sample &theSample = wSpace->mutableSample(); + // we're going to edit the workspaces run details so get a non-const reference to it + Run &theRun = wSpace->mutableRun(); // get the data that the user wants to add std::string propName = getProperty("LogName"); std::string propValue = getProperty("LogText"); - theSample.addLogData(new PropertyWithValue<std::string>(propName, propValue)); + theRun.addLogData(new PropertyWithValue<std::string>(propName, propValue)); setProperty("Workspace", wSpace); } diff --git a/Code/Mantid/Algorithms/src/BinaryOperation.cpp b/Code/Mantid/Algorithms/src/BinaryOperation.cpp index 773296b7b49..5f368e0f3c8 100644 --- a/Code/Mantid/Algorithms/src/BinaryOperation.cpp +++ b/Code/Mantid/Algorithms/src/BinaryOperation.cpp @@ -67,7 +67,7 @@ namespace Mantid } // only overridden for some operations (plus and minus at the time of writing) - operateOnSample(lhs->sample(), rhs->sample(), out_work->mutableSample()); + operateOnRun(lhs->run(), rhs->run(), out_work->mutableRun()); // Initialise the progress reporting object m_progress = new Progress(this,0.0,1.0,lhs->getNumberHistograms()); diff --git a/Code/Mantid/Algorithms/src/CheckWorkspacesMatch.cpp b/Code/Mantid/Algorithms/src/CheckWorkspacesMatch.cpp index 0f097672dc3..acf24eb5b85 100644 --- a/Code/Mantid/Algorithms/src/CheckWorkspacesMatch.cpp +++ b/Code/Mantid/Algorithms/src/CheckWorkspacesMatch.cpp @@ -64,8 +64,12 @@ void CheckWorkspacesMatch::doComparison() if ( static_cast<bool>(getProperty("CheckSpectraMap")) && ! checkSpectraMap(ws1->spectraMap(),ws2->spectraMap()) ) return; if ( static_cast<bool>(getProperty("CheckInstrument")) && ! checkInstrument(ws1,ws2) ) return; if ( static_cast<bool>(getProperty("CheckMasking")) && ! checkMasking(ws1,ws2) ) return; - if ( static_cast<bool>(getProperty("CheckSample")) && ! checkSample( ws1->sample(), ws2->sample() ) ) return; - + if ( static_cast<bool>(getProperty("CheckSample")) ) + { + if( !checkSample(ws1->sample(), ws2->sample()) ) return; + if( !checkRunProperties(ws1->run(), ws2->run()) ) return; + } + return; } @@ -298,17 +302,47 @@ bool CheckWorkspacesMatch::checkSample(const API::Sample& sample1, const API::Sa result = "Sample name mismatch"; return false; } + // N.B. Sample shape properties are not currently written out to nexus processed files, so omit here - if ( sample1.getProtonCharge() != sample2.getProtonCharge() ) + // All OK if here + return true; +} + +/// Checks that the Run matches +/// @param run1 the first run object +/// @param run2 the second run object +/// @retval true The sample matches +/// @retval false The samples does not match + +bool CheckWorkspacesMatch::checkRunProperties(const API::Run& run1, const API::Run& run2) +{ + double run1Charge(-1.0); + try + { + run1Charge = run1.getProtonCharge(); + } + catch(Exception::NotFoundError&) + { + } + double run2Charge(-1.0); + try + { + run2Charge = run2.getProtonCharge(); + } + catch(Exception::NotFoundError&) + { + } + + if ( run1Charge != run2Charge ) { - g_log.debug() << "WS1 proton charge: " << sample1.getProtonCharge() << "\n"; - g_log.debug() << "WS2 proton charge: " << sample2.getProtonCharge() << "\n"; + g_log.debug() << "WS1 proton charge: " << run1Charge << "\n"; + g_log.debug() << "WS2 proton charge: " << run2Charge << "\n"; result = "Proton charge mismatch"; return false; } - const std::vector<Kernel::Property*>& ws1logs = sample1.getLogData(); - const std::vector<Kernel::Property*>& ws2logs = sample2.getLogData(); + const std::vector<Kernel::Property*>& ws1logs = run1.getLogData(); + const std::vector<Kernel::Property*>& ws2logs = run2.getLogData(); // Check that the number of separate logs is the same if ( ws1logs.size() != ws2logs.size() ) { @@ -339,10 +373,6 @@ bool CheckWorkspacesMatch::checkSample(const API::Sample& sample1, const API::Sa return false; } } - - // N.B. Sample shape properties are not currently written out to nexus processed files, so omit here - - // All OK if here return true; } diff --git a/Code/Mantid/Algorithms/src/GetEi2.cpp b/Code/Mantid/Algorithms/src/GetEi2.cpp index e8a6efea8b0..dada5b69cff 100644 --- a/Code/Mantid/Algorithms/src/GetEi2.cpp +++ b/Code/Mantid/Algorithms/src/GetEi2.cpp @@ -11,19 +11,17 @@ #include <algorithm> #include <sstream> -namespace Mantid -{ - namespace Algorithms - { - // Register the algorithm into the algorithm factory - DECLARE_ALGORITHM(GetEi2) - } -} - using namespace Mantid::Kernel; using namespace Mantid::API; using namespace Mantid::Geometry; -using namespace Mantid::Algorithms; + +namespace Mantid +{ +namespace Algorithms +{ + + // Register the algorithm into the algorithm factory + DECLARE_ALGORITHM(GetEi2) /** * Default contructor @@ -252,7 +250,7 @@ MatrixWorkspace_sptr GetEi2::extractSpectrum(int ws_index, const double start, c * @param peak_e An output vector containing just the E values of the peak data * @returns The width of the peak at half height */ -double GetEi2::calculatePeakWidthAtHalfHeight(MatrixWorkspace_sptr data_ws, const double prominence, +double GetEi2::calculatePeakWidthAtHalfHeight(API::MatrixWorkspace_sptr data_ws, const double prominence, std::vector<double> & peak_x, std::vector<double> & peak_y, std::vector<double> & peak_e) const { // First create a temporary vector of bin_centre values to work with @@ -452,7 +450,7 @@ double GetEi2::calculatePeakWidthAtHalfHeight(MatrixWorkspace_sptr data_ws, cons * @param prominence The factor over the background by which a peak is to be considered a "real" peak * @return The calculated first moment */ -double GetEi2::calculateFirstMoment(MatrixWorkspace_sptr monitor_ws, const double prominence) +double GetEi2::calculateFirstMoment(API::MatrixWorkspace_sptr monitor_ws, const double prominence) { std::vector<double> peak_x, peak_y, peak_e; calculatePeakWidthAtHalfHeight(monitor_ws, prominence, peak_x, peak_y, peak_e); @@ -477,7 +475,7 @@ double GetEi2::calculateFirstMoment(MatrixWorkspace_sptr monitor_ws, const doubl * @param end The maximum value for the new bin range * @returns The rebinned workspace */ -MatrixWorkspace_sptr GetEi2::rebin(MatrixWorkspace_sptr monitor_ws, const double first, const double width, const double end) +API::MatrixWorkspace_sptr GetEi2::rebin(API::MatrixWorkspace_sptr monitor_ws, const double first, const double width, const double end) { IAlgorithm_sptr childAlg = createSubAlgorithm("Rebin"); childAlg->setProperty("InputWorkspace", monitor_ws); @@ -614,5 +612,8 @@ void GetEi2::integrate(double & integral_val, double &integral_err, const Mantid void GetEi2::storeEi(const double ei) const { Property *incident_energy = new PropertyWithValue<double>("Ei",ei,Direction::Input); - m_input_ws->mutableSample().addLogData(incident_energy); + m_input_ws->mutableRun().addLogData(incident_energy); +} + +} } diff --git a/Code/Mantid/Algorithms/src/MedianDetectorTest.cpp b/Code/Mantid/Algorithms/src/MedianDetectorTest.cpp index 3c2195a2cd3..cef871cf779 100644 --- a/Code/Mantid/Algorithms/src/MedianDetectorTest.cpp +++ b/Code/Mantid/Algorithms/src/MedianDetectorTest.cpp @@ -169,7 +169,7 @@ void MedianDetectorTest::retrieveProperties() * @param lastSpec the index number of the last histogram to analyse * @return A pointer to the workspace (or an empty pointer) */ -MatrixWorkspace_sptr MedianDetectorTest::getSolidAngles(int firstSpec, int lastSpec ) +API::MatrixWorkspace_sptr MedianDetectorTest::getSolidAngles(int firstSpec, int lastSpec ) { g_log.information("Calculating soild angles"); // get percentage completed estimates for now, t0 and when we've finished t1 @@ -209,7 +209,7 @@ MatrixWorkspace_sptr MedianDetectorTest::getSolidAngles(int firstSpec, int lastS * @param lastSpec the index number of the last histogram to analyse * @return Each histogram in the workspace has a single bin containing the sum of the bins in the input workspace */ -MatrixWorkspace_sptr MedianDetectorTest::getTotalCounts(int firstSpec, int lastSpec ) +API::MatrixWorkspace_sptr MedianDetectorTest::getTotalCounts(int firstSpec, int lastSpec) { g_log.information() << "Integrating input workspace" << std::endl; // get percentage completed estimates for now, t0 and when we've finished t1 @@ -248,7 +248,7 @@ MatrixWorkspace_sptr MedianDetectorTest::getTotalCounts(int firstSpec, int lastS * @throw invalid_argument if the ConvertToDistribution validation on the input workspace fails (a workspace that is already a distribution is acceptable) * @throw runtime_error if there is an during the execution of ConvertToDistribution */ -MatrixWorkspace_sptr MedianDetectorTest::getRate(MatrixWorkspace_sptr counts) +API::MatrixWorkspace_sptr MedianDetectorTest::getRate(API::MatrixWorkspace_sptr counts) { g_log.information("Calculating time averaged count rates"); // get percentage completed estimates for now, t0 and when we've finished t1 @@ -294,7 +294,7 @@ MatrixWorkspace_sptr MedianDetectorTest::getRate(MatrixWorkspace_sptr counts) * @return The median value of the histograms in the workspace that was passed to it * @throw out_of_range if a value is incountered that is unbelievibly high or negative */ -double MedianDetectorTest::getMedian(MatrixWorkspace_sptr input) +double MedianDetectorTest::getMedian(API::MatrixWorkspace_sptr input) { g_log.information("Calculating the median count rate of the spectra"); @@ -392,7 +392,7 @@ double MedianDetectorTest::getMedian(MatrixWorkspace_sptr input) * @param filename write the list of spectra numbers for failed detectors to a file with this name * @return An array that of the index numbers of the histograms that fail */ -void MedianDetectorTest::FindDetects(MatrixWorkspace_sptr responses, const double baseNum, std::vector<int> &specNums, const std::string &filename) +void MedianDetectorTest::FindDetects(API::MatrixWorkspace_sptr responses, const double baseNum, std::vector<int> &specNums, const std::string &filename) { g_log.information("Applying the criteria to find failing detectors"); @@ -552,7 +552,7 @@ void MedianDetectorTest::writeFile(const std::string &fname, const std::set<int> /** * Write a list of indices to a file - * @param The file stream + * @param file The file stream * @param indices A set of indices to write * @param totalLines The total number of lines that will be written to the file * @param convertToSpectraNo If true, the index will be converted to a spectra number first @@ -607,7 +607,7 @@ void MedianDetectorTest::writeListToFile(std::ofstream & file, const std::set<in * @param high The number of spectra counting high * @param alreadyMasked The number of spectra already masked when tested. */ -void MedianDetectorTest::logFinds(std::vector<int>::size_type missing, std::vector<int>::size_type low, std::vector<int>::size_type high, int alreadyMasked) +void MedianDetectorTest::logFinds(size_t missing, size_t low, size_t high, int alreadyMasked) { if ( missing > 0 ) { diff --git a/Code/Mantid/Algorithms/src/NormaliseByCurrent.cpp b/Code/Mantid/Algorithms/src/NormaliseByCurrent.cpp index 604b491ae5c..85afd87c80c 100644 --- a/Code/Mantid/Algorithms/src/NormaliseByCurrent.cpp +++ b/Code/Mantid/Algorithms/src/NormaliseByCurrent.cpp @@ -37,11 +37,15 @@ void NormaliseByCurrent::exec() MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace"); // Get the good proton charge and check it's valid - double charge = inputWS->sample().getProtonCharge(); - if ( charge < 1.0E-6 ) + double charge(-1.0); + try { - g_log.error() << "The proton charge is not set to a valid value. Charge = " << charge << std::endl; - throw std::out_of_range("The proton charge is not set to a valid value"); + charge = inputWS->run().getProtonCharge(); + } + catch(Exception::NotFoundError &) + { + g_log.error() << "The proton charge is not set for the run attached to this worksapce\n"; + throw; } g_log.information() << "Normalisation current: " << charge << " uamps" << std::endl; diff --git a/Code/Mantid/Algorithms/src/PlotAsymmetryByLogValue.cpp b/Code/Mantid/Algorithms/src/PlotAsymmetryByLogValue.cpp index 2d7239bfe96..319a96f840b 100644 --- a/Code/Mantid/Algorithms/src/PlotAsymmetryByLogValue.cpp +++ b/Code/Mantid/Algorithms/src/PlotAsymmetryByLogValue.cpp @@ -150,7 +150,7 @@ namespace Mantid { ws_red = boost::dynamic_pointer_cast<DataObjects::Workspace2D>(tmp); TimeSeriesProperty<double>* logp = - dynamic_cast<TimeSeriesProperty<double>*>(ws_red->sample().getLogData(logName)); + dynamic_cast<TimeSeriesProperty<double>*>(ws_red->run().getLogData(logName)); double Y,E; calcIntAsymmetry(ws_red,Y,E); outWS->dataY(0)[i-is] = Y; @@ -170,7 +170,7 @@ namespace Mantid { ws_red = loadNexus->getProperty(wsProp); TimeSeriesProperty<double>* logp = - dynamic_cast<TimeSeriesProperty<double>*>(ws_red->sample().getLogData(logName)); + dynamic_cast<TimeSeriesProperty<double>*>(ws_red->run().getLogData(logName)); double Y,E; calcIntAsymmetry(ws_red,Y,E); outWS->dataY(0)[i-is] = Y; @@ -196,7 +196,7 @@ namespace Mantid if (!ws_red || !ws_green) throw std::invalid_argument("Red or green period is out of range"); TimeSeriesProperty<double>* logp = - dynamic_cast<TimeSeriesProperty<double>*>(ws_red->sample().getLogData(logName)); + dynamic_cast<TimeSeriesProperty<double>*>(ws_red->run().getLogData(logName)); double Y,E; calcIntAsymmetry(ws_red,ws_green,Y,E); outWS->dataY(0)[i-is] = Y; diff --git a/Code/Mantid/Algorithms/src/Plus.cpp b/Code/Mantid/Algorithms/src/Plus.cpp index 62573e45dab..038054ffa0e 100644 --- a/Code/Mantid/Algorithms/src/Plus.cpp +++ b/Code/Mantid/Algorithms/src/Plus.cpp @@ -57,9 +57,15 @@ namespace Mantid * @param rhs the other workspace sample to be summed * @param ans the sample in the output workspace */ - void Plus::operateOnSample(const Sample& lhs, const Sample& rhs, Sample& ans) const + void Plus::operateOnRun(const Run& lhs, const Run& rhs, Run& ans) const { - ans.setProtonCharge( lhs.getProtonCharge() + rhs.getProtonCharge() ); + try + { + ans.setProtonCharge( lhs.getProtonCharge() + rhs.getProtonCharge() ); + } + catch(Exception::NotFoundError &) + { + } } } diff --git a/Code/Mantid/Algorithms/test/AddSampleLogTest.h b/Code/Mantid/Algorithms/test/AddSampleLogTest.h index 713e6990df0..503bad75331 100644 --- a/Code/Mantid/Algorithms/test/AddSampleLogTest.h +++ b/Code/Mantid/Algorithms/test/AddSampleLogTest.h @@ -17,29 +17,29 @@ class AddSampleLogTest : public CxxTest::TestSuite { public: - void testInsertion2D() - { - ExecuteAlgorithm(WorkspaceCreationHelper::Create2DWorkspace(10,10)); - } + void testInsertion2D() + { + ExecuteAlgorithm(WorkspaceCreationHelper::Create2DWorkspace(10,10)); + } void testInsertionEvent() - { - ExecuteAlgorithm(WorkspaceCreationHelper::CreateEventWorkspace(10,10)); - } + { + ExecuteAlgorithm(WorkspaceCreationHelper::CreateEventWorkspace(10,10)); + } void ExecuteAlgorithm(MatrixWorkspace_sptr testWS) - { + { //add the workspace to the ADS AnalysisDataService::Instance().add("AddSampleLogTest_Temporary", testWS); //execute algorithm - AddSampleLog alg; - TS_ASSERT_THROWS_NOTHING(alg.initialize()); - TS_ASSERT( alg.isInitialized() ) + AddSampleLog alg; + TS_ASSERT_THROWS_NOTHING(alg.initialize()); + TS_ASSERT( alg.isInitialized() ) alg.setPropertyValue("Workspace", "AddSampleLogTest_Temporary"); - alg.setPropertyValue("LogName", "my name"); - alg.setPropertyValue("LogText", "my data"); + alg.setPropertyValue("LogName", "my name"); + alg.setPropertyValue("LogText", "my data"); TS_ASSERT_THROWS_NOTHING(alg.execute()) TS_ASSERT( alg.isExecuted() ) @@ -47,16 +47,15 @@ public: //check output MatrixWorkspace_sptr output = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve(alg.getProperty("Workspace"))); - Sample wSpaceSam = output->sample(); - PropertyWithValue<std::string> *testProp = - dynamic_cast<PropertyWithValue<std::string>*>(wSpaceSam.getLogData("my name")); + const Run& wSpaceRun = output->run(); + PropertyWithValue<std::string> *testProp = dynamic_cast<PropertyWithValue<std::string>*>(wSpaceRun.getLogData("my name")); TS_ASSERT(testProp) TS_ASSERT_EQUALS(testProp->value(), "my data") //cleanup AnalysisDataService::Instance().remove(output->getName()); - } + } diff --git a/Code/Mantid/Algorithms/test/CheckWorkspacesMatchTest.h b/Code/Mantid/Algorithms/test/CheckWorkspacesMatchTest.h index c3a44820c19..90119c52b4b 100644 --- a/Code/Mantid/Algorithms/test/CheckWorkspacesMatchTest.h +++ b/Code/Mantid/Algorithms/test/CheckWorkspacesMatchTest.h @@ -262,7 +262,7 @@ public: checker.setProperty("CheckSample",true); Mantid::API::MatrixWorkspace_sptr ws2 = WorkspaceCreationHelper::Create2DWorkspace123(2,2); - ws2->mutableSample().setProtonCharge(99.99); + ws2->mutableRun().setProtonCharge(99.99); TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace1",ws1) ) TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace2",ws2) ) @@ -277,7 +277,7 @@ public: checker.setProperty("CheckSample",true); Mantid::API::MatrixWorkspace_sptr ws2 = WorkspaceCreationHelper::Create2DWorkspace123(2,2); - ws2->mutableSample().addLogData(new Mantid::Kernel::PropertyWithValue<int>("Prop1",99)); + ws2->mutableRun().addLogData(new Mantid::Kernel::PropertyWithValue<int>("Prop1",99)); TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace1",ws1) ) TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace2",ws2) ) @@ -286,7 +286,7 @@ public: TS_ASSERT_EQUALS( checker.getPropertyValue("Result"), "Different numbers of logs" ) Mantid::API::MatrixWorkspace_sptr ws3 = WorkspaceCreationHelper::Create2DWorkspace123(2,2); - ws3->mutableSample().addLogData(new Mantid::Kernel::PropertyWithValue<int>("Prop2",99)); + ws3->mutableRun().addLogData(new Mantid::Kernel::PropertyWithValue<int>("Prop2",99)); TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace1",ws2) ) TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace2",ws3) ) @@ -295,7 +295,7 @@ public: TS_ASSERT_EQUALS( checker.getPropertyValue("Result"), "Log name mismatch" ) Mantid::API::MatrixWorkspace_sptr ws4 = WorkspaceCreationHelper::Create2DWorkspace123(2,2); - ws4->mutableSample().addLogData(new Mantid::Kernel::PropertyWithValue<int>("Prop1",100)); + ws4->mutableRun().addLogData(new Mantid::Kernel::PropertyWithValue<int>("Prop1",100)); TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace1",ws2) ) TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace2",ws4) ) diff --git a/Code/Mantid/Algorithms/test/NormaliseByCurrentTest.h b/Code/Mantid/Algorithms/test/NormaliseByCurrentTest.h index 97f09ae1657..2ff0a3525ef 100644 --- a/Code/Mantid/Algorithms/test/NormaliseByCurrentTest.h +++ b/Code/Mantid/Algorithms/test/NormaliseByCurrentTest.h @@ -56,7 +56,7 @@ public: TS_ASSERT( ! norm.isExecuted() ) // Now set the charge MatrixWorkspace_sptr input = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve("normIn")); - input->mutableSample().setProtonCharge(2.0); + input->mutableRun().setProtonCharge(2.0); input->getAxis(0)->unit() = Mantid::Kernel::UnitFactory::Instance().create("TOF"); input->setYUnit("Counts"); diff --git a/Code/Mantid/Algorithms/test/PlusTest.h b/Code/Mantid/Algorithms/test/PlusTest.h index 613a0195f5f..98285c05ca7 100644 --- a/Code/Mantid/Algorithms/test/PlusTest.h +++ b/Code/Mantid/Algorithms/test/PlusTest.h @@ -391,6 +391,35 @@ public: TS_ASSERT_EQUALS(a->readY(0)[0],10); TS_ASSERT_EQUALS(a,b); } + + void testRunAddition() + { + MatrixWorkspace_sptr a = WorkspaceCreationHelper::CreateWorkspaceSingleValue(3); + a->mutableRun().setProtonCharge(10.); + MatrixWorkspace_sptr b = WorkspaceCreationHelper::CreateWorkspaceSingleValue(2); + b->mutableRun().setProtonCharge(5.); + + AnalysisDataService::Instance().add("a", a); + AnalysisDataService::Instance().add("b", b); + + Plus alg; + alg.initialize(); + TS_ASSERT_THROWS_NOTHING( + alg.setPropertyValue("LHSWorkspace","a"); + alg.setPropertyValue("RHSWorkspace","b"); + alg.setPropertyValue("OutputWorkspace","c"); + ) + alg.execute(); + + MatrixWorkspace_sptr work_out1; + TS_ASSERT_THROWS_NOTHING(work_out1 = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve("c"))); + + TS_ASSERT_DELTA(work_out1->run().getProtonCharge(), 15.0, 1e-8); + + AnalysisDataService::Instance().remove("a"); + AnalysisDataService::Instance().remove("b"); + AnalysisDataService::Instance().remove("c"); + } private: diff --git a/Code/Mantid/CurveFitting/src/PlotPeakByLogValue.cpp b/Code/Mantid/CurveFitting/src/PlotPeakByLogValue.cpp index 3d05899a5c9..5992b899de2 100644 --- a/Code/Mantid/CurveFitting/src/PlotPeakByLogValue.cpp +++ b/Code/Mantid/CurveFitting/src/PlotPeakByLogValue.cpp @@ -117,7 +117,7 @@ namespace Mantid double logValue; if (!logName.empty()) { - Kernel::Property* prop = data.ws->sample().getLogData(logName); + Kernel::Property* prop = data.ws->run().getLogData(logName); if (!prop) { throw std::invalid_argument("Log value "+logName+" does not exist"); diff --git a/Code/Mantid/CurveFitting/test/PlotPeakByLogValueTest.h b/Code/Mantid/CurveFitting/test/PlotPeakByLogValueTest.h index 61613a670fc..fcee4fbf39c 100644 --- a/Code/Mantid/CurveFitting/test/PlotPeakByLogValueTest.h +++ b/Code/Mantid/CurveFitting/test/PlotPeakByLogValueTest.h @@ -202,7 +202,7 @@ private: //addNoise(ws,0.01); Kernel::TimeSeriesProperty<double>* logd = new Kernel::TimeSeriesProperty<double>("var"); logd->addValue("2007-11-01T18:18:53",1+iWS*0.3); - ws->mutableSample().addLogData(logd); + ws->mutableRun().addLogData(logd); std::ostringstream wsName; wsName << "PlotPeakGroup_" << iWS ; AnalysisDataService::Instance().add(wsName.str(),ws); diff --git a/Code/Mantid/DataHandling/inc/MantidDataHandling/LoadLog.h b/Code/Mantid/DataHandling/inc/MantidDataHandling/LoadLog.h index c1b10e80ec8..5302ab3a017 100644 --- a/Code/Mantid/DataHandling/inc/MantidDataHandling/LoadLog.h +++ b/Code/Mantid/DataHandling/inc/MantidDataHandling/LoadLog.h @@ -8,60 +8,61 @@ namespace Mantid { - + namespace DataHandling { /** @class LoadLog LoadLog.h DataHandling/LoadLog.h - Load ISIS log file(s). Assumes that a log file originates from a - PC (not VMS) environment, i.e. the log files to be loaded are assumed - to have the extension .txt. Its filename is assumed to starts with the raw data - file identifier followed by the character '_', and a log file is assumed to have a - format of two columns, where the first column consists of data-time strings of the - ISO 8601 form and the second column consists of either numbers or strings that may - contain spaces. - - The algoritm requires an input filename. If this filename is the name of a - raw datafile the algorithm will attempt to read in all the log files associated - with that log file. Otherwise it will assume the filename specified is the - filename of a specific log file. - - LoadLog is an algorithm and as such inherits from the Algorithm class, - via DataHandlingCommand, and overrides the init() & exec() methods. - LoadLog is intended to be used as a child algorithm of - other Loadxxx algorithms, rather than being used directly. - - Required Properties: - <UL> - <LI> Filename - The filename (including its full or relative path) of either an ISIS log file - or an ISIS raw file. If a raw file is specified all log files associated with that raw file - are loaded into the specified workspace. The file extension must either be .raw or .s when - specifying a raw file, and at least 10 characters long. </LI> - <LI> Workspace - The workspace to which the log data is appended </LI> - </UL> - - @author Anders Markvardsen, ISIS, RAL - @date 26/09/2007 - - Copyright © 2007-8 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory - - 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://svn.mantidproject.org/mantid/trunk/Code/Mantid>. - Code Documentation is available at: <http://doxygen.mantidproject.org> + Load ISIS log file(s). Assumes that a log file originates from a + PC (not VMS) environment, i.e. the log files to be loaded are assumed + to have the extension .txt. Its filename is assumed to starts with the raw data + file identifier followed by the character '_', and a log file is assumed to have a + format of two columns, where the first column consists of data-time strings of the + ISO 8601 form and the second column consists of either numbers or strings that may + contain spaces. + + The algoritm requires an input filename. If this filename is the name of a + raw datafile the algorithm will attempt to read in all the log files associated + with that log file. Otherwise it will assume the filename specified is the + filename of a specific log file. + + LoadLog is an algorithm and as such inherits from the Algorithm class, + via DataHandlingCommand, and overrides the init() & exec() methods. + LoadLog is intended to be used as a child algorithm of + other Loadxxx algorithms, rather than being used directly. + + Required Properties: + <UL> + <LI> Filename - The filename (including its full or relative path) of either an ISIS log file + or an ISIS raw file. If a raw file is specified all log files associated with that raw file + are loaded into the specified workspace. The file extension must either be .raw or .s when + specifying a raw file, and at least 10 characters long. </LI> + <LI> Workspace - The workspace to which the log data is appended </LI> + </UL> + + @author Anders Markvardsen, ISIS, RAL + @date 26/09/2007 + + Copyright © 2007-8 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + + + 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://svn.mantidproject.org/mantid/trunk/Code/Mantid>. + Code Documentation is available at: <http://doxygen.mantidproject.org> */ class DLLExport LoadLog : public API::Algorithm { @@ -79,7 +80,7 @@ namespace Mantid virtual const std::string category() const { return "DataHandling\\Logs";} /// this method returns data periods property and useful for loading log data for multi period files - const boost::shared_ptr<Kernel::Property> getPeriodsProperty() const {return m_periods;} + const boost::shared_ptr<Kernel::Property> getPeriodsProperty() const {return m_periods;} private: @@ -110,20 +111,19 @@ namespace Mantid /// Return the name of the three column log file for associated with the specified file. Empty string if one doesn't exist std::string getThreeColumnName() const; - /// create timeseries property from .log file and adds taht to sample object - std::set<std::string> createthreecolumnFileLogProperty(const std::string& logfile, - API::Sample& sample); - - /// if a file with the second column(block column) name in .log file exists - /// in the raw file directory - bool blockcolumnFileExists(const std::string& fileName); + /// create timeseries property from .log file and adds taht to sample object + std::set<std::string> createthreecolumnFileLogProperty(const std::string& logfile, API::Run& run); + + /// if a file with the second column(block column) name in .log file exists + /// in the raw file directory + bool blockcolumnFileExists(const std::string& fileName); /// if alternate data stream named checksum exists for the raw file bool adsExists(); - /// returns the list of log files from ADS checksum - std::set<std::string> getLogfilenamesfromADS(); + /// returns the list of log files from ADS checksum + std::set<std::string> getLogfilenamesfromADS(); - /// TimeSeriesProperty<int> containing data periods. Created by LogParser - boost::shared_ptr<Kernel::Property> m_periods; + /// TimeSeriesProperty<int> containing data periods. Created by LogParser + boost::shared_ptr<Kernel::Property> m_periods; }; } // namespace DataHandling diff --git a/Code/Mantid/DataHandling/inc/MantidDataHandling/LoadRawHelper.h b/Code/Mantid/DataHandling/inc/MantidDataHandling/LoadRawHelper.h index 667885ea76d..7f323062c37 100644 --- a/Code/Mantid/DataHandling/inc/MantidDataHandling/LoadRawHelper.h +++ b/Code/Mantid/DataHandling/inc/MantidDataHandling/LoadRawHelper.h @@ -6,7 +6,7 @@ //---------------------------------------------------------------------- #include "MantidAPI/Algorithm.h" #include "MantidDataObjects/Workspace2D.h" -#include "MantidAPI/Sample.h" +#include "MantidAPI/Run.h" #include <climits> //---------------------------------------------------------------------- @@ -20,134 +20,134 @@ namespace Mantid { /** @class LoadRawHelper DataHandling/LoadRawHelper.h - Helper class for LoadRaw algorithms. + Helper class for LoadRaw algorithms. - @author Sofia Antony, ISIS,RAL - @date 14/04/2010 + @author Sofia Antony, ISIS,RAL + @date 14/04/2010 - Copyright © 2007-9 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + Copyright © 2007-9 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory - This file is part of Mantid. + 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 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. + 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/>. + 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://svn.mantidproject.org/mantid/trunk/Code/Mantid>. - Code Documentation is available at: <http://doxygen.mantidproject.org> + File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>. + Code Documentation is available at: <http://doxygen.mantidproject.org> */ - class DLLExport LoadRawHelper: public API::Algorithm + class DLLExport LoadRawHelper: public API::Algorithm { public: /// Default constructor - LoadRawHelper(); + LoadRawHelper(); /// Destructor ~LoadRawHelper(); - protected: - /// Overwrites Algorithm method. + protected: + /// Overwrites Algorithm method. void init(); - ///Opens Raw File - FILE* openRawFile(const std::string & fileName); - ///checks the file is an ascii file - bool isAscii(FILE* file) const; + ///Opens Raw File + FILE* openRawFile(const std::string & fileName); + ///checks the file is an ascii file + bool isAscii(FILE* file) const; /// Reads title from the isisraw class - void readTitle(FILE* file,std::string & title); + void readTitle(FILE* file,std::string & title); /// reads workspace parameters like number of histograms,size of vectors etc - void readworkspaceParameters(int &numberOfSpectra,int & numberOfPeriods,int& lengthIn,int& noTimeRegimes ); + void readworkspaceParameters(int &numberOfSpectra,int & numberOfPeriods,int& lengthIn,int& noTimeRegimes ); - /// skips histrogram data from raw file. - void skipData(FILE* file,int hist); - - ///calls isisRaw ioraw - void ioRaw(FILE* file,bool from_file ); - - /// reads data - bool readData(FILE* file,int histToRead); - - ///creates shared pointer to workspace from parent workspace - DataObjects::Workspace2D_sptr createWorkspace(DataObjects::Workspace2D_sptr ws_sptr, - int nVectors=-1,int xLengthIn=-1,int yLengthIn=-1); - - /// overloaded method to create shared pointer to workspace + /// skips histrogram data from raw file. + void skipData(FILE* file,int hist); + + ///calls isisRaw ioraw + void ioRaw(FILE* file,bool from_file ); + + /// reads data + bool readData(FILE* file,int histToRead); + + ///creates shared pointer to workspace from parent workspace + DataObjects::Workspace2D_sptr createWorkspace(DataObjects::Workspace2D_sptr ws_sptr, + int nVectors=-1,int xLengthIn=-1,int yLengthIn=-1); + + /// overloaded method to create shared pointer to workspace DataObjects::Workspace2D_sptr createWorkspace(int nVectors,int xlengthIn,int ylengthIn,const std::string& title); - ///creates monitor workspace - void createMonitorWorkspace(DataObjects::Workspace2D_sptr& monws_sptr, - DataObjects::Workspace2D_sptr& ws_sptr,API::WorkspaceGroup_sptr& mongrp_sptr, - const int mwsSpecs,const int nwsSpecs,const int numberOfPeriods,const int lenthIn,std::string title); + ///creates monitor workspace + void createMonitorWorkspace(DataObjects::Workspace2D_sptr& monws_sptr, + DataObjects::Workspace2D_sptr& ws_sptr,API::WorkspaceGroup_sptr& mongrp_sptr, + const int mwsSpecs,const int nwsSpecs,const int numberOfPeriods,const int lenthIn,std::string title); - /// creates shared pointer to group workspace + /// creates shared pointer to group workspace API::WorkspaceGroup_sptr createGroupWorkspace(); - //Constructs the time channel (X) vector(s) - std::vector<boost::shared_ptr<MantidVec> > getTimeChannels(const int& regimes, + //Constructs the time channel (X) vector(s) + std::vector<boost::shared_ptr<MantidVec> > getTimeChannels(const int& regimes, const int& lengthIn); - /// loadinstrument sub algorithm + /// loadinstrument sub algorithm void runLoadInstrument(const std::string& fileName,DataObjects::Workspace2D_sptr); - /// loadinstrumentfromraw algorithm + /// loadinstrumentfromraw algorithm void runLoadInstrumentFromRaw(const std::string& fileName,DataObjects::Workspace2D_sptr); - /// loadinstrumentfromraw sub algorithm + /// loadinstrumentfromraw sub algorithm void runLoadMappingTable(const std::string& fileName,DataObjects::Workspace2D_sptr); - /// load log algorithm + /// load log algorithm void runLoadLog(const std::string& fileName,DataObjects::Workspace2D_sptr,int period=1); - ///gets the monitor spectrum list from the workspace + ///gets the monitor spectrum list from the workspace void getmonitorSpectrumList(DataObjects::Workspace2D_sptr localWorkspace,std::vector<int>& monitorSpecList); /// sets the workspace property void setWorkspaceProperty(const std::string & propertyName,const std::string& title, - API::WorkspaceGroup_sptr grpws_sptr,DataObjects::Workspace2D_sptr ws_sptr,int numberOfPeriods,bool bMonitor); + API::WorkspaceGroup_sptr grpws_sptr,DataObjects::Workspace2D_sptr ws_sptr,int numberOfPeriods,bool bMonitor); /// overloaded method to set the workspace property void setWorkspaceProperty(DataObjects::Workspace2D_sptr ws_sptr,API::WorkspaceGroup_sptr grpws_sptr,const int period,bool bmonitors); /// This method sets the raw file data to workspace vectors void setWorkspaceData(DataObjects::Workspace2D_sptr newWorkspace,const std::vector<boost::shared_ptr<MantidVec> >& - timeChannelsVec,int wsIndex,int nspecNum,int noTimeRegimes,int lengthIn,int binStart); - - /// creates time series property showing times when when a particular period was active. + timeChannelsVec,int wsIndex,int nspecNum,int noTimeRegimes,int lengthIn,int binStart); + + /// creates time series property showing times when when a particular period was active. Kernel::Property* createPeriodLog(int period)const; /// ISISRAW class instance which does raw file reading. Shared pointer to prevent memory leak when an exception is thrown. boost::shared_ptr<ISISRAW2> isisRaw; - /// get proton charge from raw file - float getProtonCharge()const ; - /// set proton charge - void setProtonCharge(API::Sample& sample); - /// Stores the run number in the sample's logs - void setRunNumber(API::Sample& sample); - - /// number of time regimes - int getNumberofTimeRegimes(); - /// resets the isisraw shared pointer - void reset(); - - ///sets optional properties like spec_min,spec_max etc - void setOptionalProperties(const int& spec_min,const int& spec_max,const std::vector<int>& spec_list); - /// Validates the optional 'spectra to read' properties, if they have been set - void checkOptionalProperties(); - /// calculate workspace size - int calculateWorkspaceSize(); - /// calculate workspace sizes if separate or exclude monitors are selected - void calculateWorkspacesizes(const std::vector<int>& monitorSpecList, - int& normalwsSpecs, int& monitorwsSpecs); - /// load the specra - void loadSpectra(FILE* file,const int& period, const int& m_total_specs, - DataObjects::Workspace2D_sptr ws_sptr,std::vector<boost::shared_ptr<MantidVec> >); - /// Has the spectrum_list property been set? + /// get proton charge from raw file + float getProtonCharge()const ; + /// set proton charge + void setProtonCharge(API::Run& run); + /// Stores the run number in the sample's logs + void setRunNumber(API::Run& run); + + /// number of time regimes + int getNumberofTimeRegimes(); + /// resets the isisraw shared pointer + void reset(); + + ///sets optional properties like spec_min,spec_max etc + void setOptionalProperties(const int& spec_min,const int& spec_max,const std::vector<int>& spec_list); + /// Validates the optional 'spectra to read' properties, if they have been set + void checkOptionalProperties(); + /// calculate workspace size + int calculateWorkspaceSize(); + /// calculate workspace sizes if separate or exclude monitors are selected + void calculateWorkspacesizes(const std::vector<int>& monitorSpecList, + int& normalwsSpecs, int& monitorwsSpecs); + /// load the specra + void loadSpectra(FILE* file,const int& period, const int& m_total_specs, + DataObjects::Workspace2D_sptr ws_sptr,std::vector<boost::shared_ptr<MantidVec> >); + /// Has the spectrum_list property been set? bool m_list; /// Have the spectrum_min/max properties been set? bool m_interval; @@ -162,17 +162,17 @@ namespace Mantid /// Overwrites Algorithm method void exec(); - - /// Allowed values for the cache property + + /// Allowed values for the cache property std::vector<std::string> m_cache_options; /// A map for storing the time regime for each spectrum std::map<int,int> m_specTimeRegimes; /// The current value of the progress counter double m_prog; - - /// number of spectra - int m_numberOfSpectra; + + /// number of spectra + int m_numberOfSpectra; /// a vector holding the indexes of monitors std::vector<int> m_monitordetectorList; @@ -180,15 +180,15 @@ namespace Mantid /// TimeSeriesProperty<int> containing data periods. boost::shared_ptr<Kernel::Property> m_perioids; - /// A flag int value to indicate that the value wasn't set by users + /// A flag int value to indicate that the value wasn't set by users static const int unSetInt = INT_MAX-15; - /// boolean for list spectra options + /// boolean for list spectra options bool m_bmspeclist; - ///the total nuumber of spectra - int m_total_specs; - + ///the total nuumber of spectra + int m_total_specs; + }; } // namespace DataHandling diff --git a/Code/Mantid/DataHandling/src/LoadCanSAS1D.cpp b/Code/Mantid/DataHandling/src/LoadCanSAS1D.cpp index 0b54b587d99..91174f4853b 100644 --- a/Code/Mantid/DataHandling/src/LoadCanSAS1D.cpp +++ b/Code/Mantid/DataHandling/src/LoadCanSAS1D.cpp @@ -222,9 +222,8 @@ void LoadCanSAS1D::createRunNumLog(const Poco::XML::Element * const sasEntry, co throwException(runText, elemName, fileName); - API::Sample &sam = wSpace->mutableSample(); - sam.addLogData( - new PropertyWithValue<std::string>("run_number", runText->innerText())); + API::Run &run = wSpace->mutableRun(); + run.addLogData(new PropertyWithValue<std::string>("run_number", runText->innerText())); } } diff --git a/Code/Mantid/DataHandling/src/LoadDAE.cpp b/Code/Mantid/DataHandling/src/LoadDAE.cpp index d5c7c386e2f..b7ea541d980 100644 --- a/Code/Mantid/DataHandling/src/LoadDAE.cpp +++ b/Code/Mantid/DataHandling/src/LoadDAE.cpp @@ -367,7 +367,7 @@ namespace Mantid runLoadInstrument(localWorkspace, iName); //runLoadLog(localWorkspace ); // Set the total proton charge for this run - localWorkspace->mutableSample().setProtonCharge(m_proton_charge); + localWorkspace->mutableRun().setProtonCharge(m_proton_charge); } if(m_numberOfPeriods>1) { diff --git a/Code/Mantid/DataHandling/src/LoadEventPreNeXus.cpp b/Code/Mantid/DataHandling/src/LoadEventPreNeXus.cpp index c65fd2edb88..57e1fbba92a 100644 --- a/Code/Mantid/DataHandling/src/LoadEventPreNeXus.cpp +++ b/Code/Mantid/DataHandling/src/LoadEventPreNeXus.cpp @@ -585,15 +585,15 @@ void LoadEventPreNeXus::setProtonCharge(DataObjects::EventWorkspace_sptr & works { if (this->proton_charge.empty()) // nothing to do return; - Sample& sample = workspace->mutableSample(); - sample.setProtonCharge(this->proton_charge_tot); + Run& run = workspace->mutableRun(); + run.setProtonCharge(this->proton_charge_tot); TimeSeriesProperty<double>* log = new TimeSeriesProperty<double>("ProtonCharge"); size_t num = this->proton_charge.size(); for (size_t i = 0; i < num; i++) log->addValue(to_time_t(this->pulsetimes[i]), this->proton_charge[i]); /// TODO set the units for the log - sample.addLogData(log); + run.addLogData(log); } //----------------------------------------------------------------------------- diff --git a/Code/Mantid/DataHandling/src/LoadLog.cpp b/Code/Mantid/DataHandling/src/LoadLog.cpp index d1298e2ad62..899f62a68a5 100644 --- a/Code/Mantid/DataHandling/src/LoadLog.cpp +++ b/Code/Mantid/DataHandling/src/LoadLog.cpp @@ -97,8 +97,8 @@ void LoadLog::exec() throw Exception::FileError("Filename is a directory:" , m_filename); } - // Get the input workspace and retrieve sample from workspace. - // the log file(s) will be loaded into the Sample container of the workspace + // Get the input workspace and retrieve run from workspace. + // the log file(s) will be loaded into the run object of the workspace const MatrixWorkspace_sptr localWorkspace = getProperty("Workspace"); // If m_filename is the filename of a raw datafile then search for potential log files @@ -173,7 +173,7 @@ void LoadLog::exec() std::string threecolumnLogfile = getThreeColumnName(); if( !threecolumnLogfile.empty() ) { - std::set<std::string> blockFileNameList=createthreecolumnFileLogProperty(threecolumnLogfile,localWorkspace->mutableSample()); + std::set<std::string> blockFileNameList=createthreecolumnFileLogProperty(threecolumnLogfile,localWorkspace->mutableRun()); //remove the file name from potential logfiles list if it's there in the .log file. std::set<std::string>::const_iterator itr; for(itr=blockFileNameList.begin();itr!=blockFileNameList.end();++itr) @@ -202,8 +202,8 @@ void LoadLog::exec() // Add mantid-created logs m_periods=parser.getPeriodsProperty(); - localWorkspace->mutableSample().addLogData(parser.createAllPeriodsLog()); - localWorkspace->mutableSample().addLogData(parser.createRunningLog()); + localWorkspace->mutableRun().addLogData(parser.createAllPeriodsLog()); + localWorkspace->mutableRun().addLogData(parser.createRunningLog()); // Extract the common part of log file names (the workspace name) std::string ws_name = Poco::Path(m_filename).getFileName(); @@ -265,7 +265,7 @@ void LoadLog::exec() Property* log = parser.createLogProperty(*logs_itr,stringToLower(log_name)); if (log) { - localWorkspace->mutableSample().addLogData(log); + localWorkspace->mutableRun().addLogData(log); } } catch(std::exception&) @@ -403,12 +403,12 @@ std::set<std::string> LoadLog::getLogfilenamesfromADS() return logfilesList; } -/** This method reads the.log file and creates timeseries property and sets that to the sample object +/** This method reads the.log file and creates timeseries property and sets that to the run object * @param logfile three column log(.log) file name. - * @param sample sample object + * @param run The run information object * @returns list of logfiles which exists as blockname in the .log file */ -std::set<std::string> LoadLog::createthreecolumnFileLogProperty(const std::string& logfile,API::Sample& sample) +std::set<std::string> LoadLog::createthreecolumnFileLogProperty(const std::string& logfile,API::Run& run) { std::set<std::string> blockFileNameList; std::string sdata,str; @@ -505,12 +505,13 @@ std::set<std::string> LoadLog::createthreecolumnFileLogProperty(const std::strin { std::map<std::string,Kernel::TimeSeriesProperty<double>*>::const_iterator itr=dMap.begin(); for(;itr!=dMap.end();++itr) - {sample.addLogData(itr->second); + { + run.addLogData(itr->second); } std::map<std::string,Kernel::TimeSeriesProperty<std::string>*>::const_iterator sitr=sMap.begin(); for(;sitr!=sMap.end();++sitr) { - sample.addLogData(sitr->second); + run.addLogData(sitr->second); } } catch(std::invalid_argument &e) diff --git a/Code/Mantid/DataHandling/src/LoadRaw.cpp b/Code/Mantid/DataHandling/src/LoadRaw.cpp index a3c31a51ff8..12bb8cf753a 100644 --- a/Code/Mantid/DataHandling/src/LoadRaw.cpp +++ b/Code/Mantid/DataHandling/src/LoadRaw.cpp @@ -176,12 +176,11 @@ namespace Mantid runLoadInstrument(localWorkspace ); runLoadMappingTable(localWorkspace ); runLoadLog(localWorkspace ); - Property* log=createPeriodLog(1); - if(log)localWorkspace->mutableSample().addLogData(log); + Property* log=createPeriodLog(1); + if(log)localWorkspace->mutableRun().addLogData(log); // Set the total proton charge for this run // (not sure how this works for multi_period files) - // localWorkspace->getSample()->setProtonCharge(iraw.rpb.r_gd_prtn_chrg); - localWorkspace->mutableSample().setProtonCharge(iraw.rpb.r_gd_prtn_chrg); + localWorkspace->mutableRun().setProtonCharge(iraw.rpb.r_gd_prtn_chrg); } else // We are working on a higher period of a multiperiod raw file { diff --git a/Code/Mantid/DataHandling/src/LoadRaw2.cpp b/Code/Mantid/DataHandling/src/LoadRaw2.cpp index 0f98b84c14d..e24563dcb68 100644 --- a/Code/Mantid/DataHandling/src/LoadRaw2.cpp +++ b/Code/Mantid/DataHandling/src/LoadRaw2.cpp @@ -165,9 +165,12 @@ namespace Mantid runLoadInstrument(localWorkspace ); runLoadMappingTable(localWorkspace ); runLoadLog(localWorkspace ); - Property* log=createPeriodLog(1); - if(log)localWorkspace->mutableSample().addLogData(log); - localWorkspace->mutableSample().setProtonCharge(isisRaw->rpb.r_gd_prtn_chrg); + Property* log=createPeriodLog(1); + if(log) + { + localWorkspace->mutableRun().addLogData(log); + } + localWorkspace->mutableRun().setProtonCharge(isisRaw->rpb.r_gd_prtn_chrg); for (int i = 0; i < m_numberOfSpectra; ++i) localWorkspace->getAxis(1)->spectraNo(i)= i+1; localWorkspace->populateInstrumentParameters(); @@ -244,11 +247,14 @@ namespace Mantid runLoadInstrument(localWorkspace ); runLoadMappingTable(localWorkspace ); runLoadLog(localWorkspace ); - Property* log=createPeriodLog(period+1); - if(log)localWorkspace->mutableSample().addLogData(log); + Property* log=createPeriodLog(period+1); + if(log) + { + localWorkspace->mutableRun().addLogData(log); + } // Set the total proton charge for this run // (not sure how this works for multi_period files) - localWorkspace->mutableSample().setProtonCharge(isisRaw->rpb.r_gd_prtn_chrg); + localWorkspace->mutableRun().setProtonCharge(isisRaw->rpb.r_gd_prtn_chrg); } else // We are working on a higher period of a multiperiod raw file { @@ -262,14 +268,17 @@ namespace Mantid declareProperty(new WorkspaceProperty<DataObjects::Workspace2D>(outputWorkspace,WSName,Direction::Output)); g_log.information() << "Workspace " << WSName << " created. \n"; - //remove previous period data - std::stringstream index; - index << (period); - std::string prevPeriod="PERIOD "+index.str(); - localWorkspace->mutableSample().removeLogData(prevPeriod); - //add current period data - Property* log=createPeriodLog(period+1); - if(log)localWorkspace->mutableSample().addLogData(log); + //remove previous period data + std::stringstream index; + index << (period); + std::string prevPeriod="PERIOD "+index.str(); + localWorkspace->mutableRun().removeLogData(prevPeriod); + //add current period data + Property* log=createPeriodLog(period+1); + if(log) + { + localWorkspace->mutableRun().addLogData(log); + } } // check if values stored in logfiles should be used to define parameters of the instrument diff --git a/Code/Mantid/DataHandling/src/LoadRaw3.cpp b/Code/Mantid/DataHandling/src/LoadRaw3.cpp index ff1db2a32c8..ca81e324749 100644 --- a/Code/Mantid/DataHandling/src/LoadRaw3.cpp +++ b/Code/Mantid/DataHandling/src/LoadRaw3.cpp @@ -138,17 +138,16 @@ void LoadRaw3::exec() // Only run the sub-algorithms once runLoadInstrument(m_filename,localWorkspace); runLoadMappingTable(m_filename,localWorkspace); - Sample& sample = localWorkspace->mutableSample(); + Run& run = localWorkspace->mutableRun(); if (bLoadlogFiles) { runLoadLog(m_filename,localWorkspace); Property* log = createPeriodLog(1); - if (log) sample.addLogData(log); + if (log) run.addLogData(log); } // Set the total proton charge for this run - setProtonCharge(sample); - - setRunNumber(sample); + setProtonCharge(run); + setRunNumber(run); // populate instrument parameters g_log.debug("Populating the instrument parameters..."); @@ -225,19 +224,19 @@ void LoadRaw3::exec() //std::string prevPeriod="PERIOD "+suffix.str(); if(localWorkspace) { - Sample& sampleObj = localWorkspace->mutableSample(); - sampleObj.removeLogData(prevPeriod.str()); + Run& runObj = localWorkspace->mutableRun(); + runObj.removeLogData(prevPeriod.str()); //add current period data Property* log = createPeriodLog(period+1); - if (log) sampleObj.addLogData(log); + if (log) runObj.addLogData(log); } if(monitorWorkspace) { - Sample& sampleObj = monitorWorkspace->mutableSample(); - sampleObj.removeLogData(prevPeriod.str()); + Run& runObj = monitorWorkspace->mutableRun(); + runObj.removeLogData(prevPeriod.str()); //add current period data Property* log = createPeriodLog(period+1); - if (log) sampleObj.addLogData(log); + if (log) runObj.addLogData(log); } }//end of if loop for loadlogfiles if (bseparateMonitors) @@ -563,9 +562,12 @@ void LoadRaw3::goManagedRaw(bool bincludeMonitors, bool bexcludeMonitors, bool b { runLoadLog(fileName,localWorkspace); Property* log=createPeriodLog(1); - if(log)localWorkspace->mutableSample().addLogData(log); + if(log) + { + localWorkspace->mutableRun().addLogData(log); + } } - setProtonCharge(localWorkspace->mutableSample()); + setProtonCharge(localWorkspace->mutableRun()); m_prog = 0.7; progress(m_prog); @@ -592,8 +594,8 @@ void LoadRaw3::goManagedRaw(bool bincludeMonitors, bool bexcludeMonitors, bool b * @param fileName raw file name */ void LoadRaw3::separateOrexcludeMonitors(DataObjects::Workspace2D_sptr localWorkspace, - bool binclude,bool bexclude,bool bseparate, - int m_numberOfSpectra,const std::string &fileName) + bool binclude,bool bexclude,bool bseparate, + int m_numberOfSpectra,const std::string &fileName) { std::vector<int> monitorSpecList; diff --git a/Code/Mantid/DataHandling/src/LoadRawBin0.cpp b/Code/Mantid/DataHandling/src/LoadRawBin0.cpp index a3a38561939..297ba789017 100644 --- a/Code/Mantid/DataHandling/src/LoadRawBin0.cpp +++ b/Code/Mantid/DataHandling/src/LoadRawBin0.cpp @@ -109,15 +109,15 @@ void LoadRawBin0::exec() // Create the 2D workspace for the output xlength and ylength is one DataObjects::Workspace2D_sptr localWorkspace = createWorkspace(m_total_specs, 1,1,title); - Sample& sample = localWorkspace->mutableSample(); + Run& run = localWorkspace->mutableRun(); if (bLoadlogFiles) { runLoadLog(m_filename,localWorkspace); Property* log = createPeriodLog(1); - if (log) sample.addLogData(log); + if (log) run.addLogData(log); } // Set the total proton charge for this run - setProtonCharge(sample); + setProtonCharge(run); WorkspaceGroup_sptr ws_grp = createGroupWorkspace(); setWorkspaceProperty("OutputWorkspace", title, ws_grp, localWorkspace,m_numberOfPeriods, false); @@ -134,11 +134,14 @@ void LoadRawBin0::exec() //remove previous period data std::stringstream prevPeriod; prevPeriod << "PERIOD " << (period); - Sample& sampleObj = localWorkspace->mutableSample(); - sampleObj.removeLogData(prevPeriod.str()); + Run& runObj = localWorkspace->mutableRun(); + runObj.removeLogData(prevPeriod.str()); //add current period data Property* log = createPeriodLog(period+1); - if (log) sampleObj.addLogData(log); + if (log) + { + runObj.addLogData(log); + } } } diff --git a/Code/Mantid/DataHandling/src/LoadRawHelper.cpp b/Code/Mantid/DataHandling/src/LoadRawHelper.cpp index 887a6bfc79f..fdcab7ce154 100644 --- a/Code/Mantid/DataHandling/src/LoadRawHelper.cpp +++ b/Code/Mantid/DataHandling/src/LoadRawHelper.cpp @@ -23,900 +23,903 @@ namespace Mantid { -namespace DataHandling -{ + namespace DataHandling + { -using namespace Kernel; -using namespace API; + using namespace Kernel; + using namespace API; -/// Constructor -LoadRawHelper::LoadRawHelper() : - Algorithm(),isisRaw(new ISISRAW2), - m_list(false),m_spec_list(),m_spec_min(0), - m_spec_max(unSetInt),m_specTimeRegimes(),m_bmspeclist(false) -{ -} + /// Constructor + LoadRawHelper::LoadRawHelper() : + Algorithm(),isisRaw(new ISISRAW2), + m_list(false),m_spec_list(),m_spec_min(0), + m_spec_max(unSetInt),m_specTimeRegimes(),m_bmspeclist(false) + { + } -LoadRawHelper::~LoadRawHelper() -{ -} + LoadRawHelper::~LoadRawHelper() + { + } -/// Initialisation method. -void LoadRawHelper::init() -{ - std::vector<std::string> exts; - exts.push_back(".raw"); - exts.push_back(".s*"); - exts.push_back(".add"); - declareProperty(new FileProperty("Filename", "", FileProperty::Load, exts), - "The name of the RAW file to read, including its full or relative\n" - "path. (N.B. case sensitive if running on Linux)."); - - declareProperty(new WorkspaceProperty<Workspace> ("OutputWorkspace", "", Direction::Output), - "The name of the workspace that will be created, filled with the\n" - "read-in data and stored in the Analysis Data Service. If the input\n" - "RAW file contains multiple periods higher periods will be stored in\n" - "separate workspaces called OutputWorkspace_PeriodNo."); + /// Initialisation method. + void LoadRawHelper::init() + { + std::vector<std::string> exts; + exts.push_back(".raw"); + exts.push_back(".s*"); + exts.push_back(".add"); + declareProperty(new FileProperty("Filename", "", FileProperty::Load, exts), + "The name of the RAW file to read, including its full or relative\n" + "path. (N.B. case sensitive if running on Linux)."); + + declareProperty(new WorkspaceProperty<Workspace> ("OutputWorkspace", "", Direction::Output), + "The name of the workspace that will be created, filled with the\n" + "read-in data and stored in the Analysis Data Service. If the input\n" + "RAW file contains multiple periods higher periods will be stored in\n" + "separate workspaces called OutputWorkspace_PeriodNo."); - m_cache_options.push_back("If Slow"); - m_cache_options.push_back("Always"); - m_cache_options.push_back("Never"); - declareProperty("Cache", "If Slow", new ListValidator(m_cache_options)); + m_cache_options.push_back("If Slow"); + m_cache_options.push_back("Always"); + m_cache_options.push_back("Never"); + declareProperty("Cache", "If Slow", new ListValidator(m_cache_options)); - declareProperty("LoadLogFiles", true, " Boolean option to load or skip log files."); + declareProperty("LoadLogFiles", true, " Boolean option to load or skip log files."); -} -/**opens the raw file and returns the file pointer - *@param fileName - name of the raw file - *@return file pointer -*/ -FILE* LoadRawHelper::openRawFile(const std::string & fileName) -{ - FILE* file = fopen(fileName.c_str(), "rb"); - if (file == NULL) - { - g_log.error("Unable to open file " + fileName); - throw Exception::FileError("Unable to open File:", fileName); - } - return file; - -} -/**reads in HDR_STRUCT struct from isisRaw class and creates workspace title - *@param file - pointer to the raw file - *@param title workspace title -*/ -void LoadRawHelper::readTitle(FILE* file,std::string & title) -{ - //isisRaw->ioRAW(file, true); - ioRaw(file,true ); - // This reads in the HDR_STRUCT run, user, title, date & time fields - std::string header(isisRaw->hdr.hd_run, 69); - // Insert some spaces to tidy the string up a bit - header.insert(5, " "); - header.insert(26, " "); - header.insert(51, " "); - title=header; - g_log.information("*** Run title: " + title + " ***"); -} -/**skips the histogram from raw file - *@param file - pointer to the raw file - *@param hist - postion in the file to skip -*/ -void LoadRawHelper::skipData(FILE* file,int hist) -{ - isisRaw->skipData(file, hist); -} -/// calls isisRaw ioRaw. -/// @param file the file pointer -/// @param from_file unknown -void LoadRawHelper::ioRaw(FILE* file,bool from_file ) -{ - isisRaw->ioRAW(file, from_file); -} -int LoadRawHelper::getNumberofTimeRegimes() -{ - return isisRaw->daep.n_tr_shift; -} + } + /**opens the raw file and returns the file pointer + *@param fileName - name of the raw file + *@return file pointer + */ + FILE* LoadRawHelper::openRawFile(const std::string & fileName) + { + FILE* file = fopen(fileName.c_str(), "rb"); + if (file == NULL) + { + g_log.error("Unable to open file " + fileName); + throw Exception::FileError("Unable to open File:", fileName); + } + return file; -void LoadRawHelper::reset() -{ - isisRaw.reset(); -} - -/**reads the histogram from raw file - *@param file - pointer to the raw file - *@param hist - postion in the file to read -*/ -bool LoadRawHelper::readData(FILE* file,int hist) -{ - return isisRaw->readData(file, hist); -} + } + /**reads in HDR_STRUCT struct from isisRaw class and creates workspace title + *@param file - pointer to the raw file + *@param title workspace title + */ + void LoadRawHelper::readTitle(FILE* file,std::string & title) + { + //isisRaw->ioRAW(file, true); + ioRaw(file,true ); + // This reads in the HDR_STRUCT run, user, title, date & time fields + std::string header(isisRaw->hdr.hd_run, 69); + // Insert some spaces to tidy the string up a bit + header.insert(5, " "); + header.insert(26, " "); + header.insert(51, " "); + title=header; + g_log.information("*** Run title: " + title + " ***"); + } + /**skips the histogram from raw file + *@param file - pointer to the raw file + *@param hist - postion in the file to skip + */ + void LoadRawHelper::skipData(FILE* file,int hist) + { + isisRaw->skipData(file, hist); + } + /// calls isisRaw ioRaw. + /// @param file the file pointer + /// @param from_file unknown + void LoadRawHelper::ioRaw(FILE* file,bool from_file ) + { + isisRaw->ioRAW(file, from_file); + } + int LoadRawHelper::getNumberofTimeRegimes() + { + return isisRaw->daep.n_tr_shift; + } -float LoadRawHelper::getProtonCharge()const -{ - return isisRaw->rpb.r_gd_prtn_chrg; -} + void LoadRawHelper::reset() + { + isisRaw.reset(); + } -void LoadRawHelper::setProtonCharge(API::Sample& sample) -{ - //isisRaw->rpb.r_gd_prtn_chrg; - sample.setProtonCharge(getProtonCharge()); -} -/** Stores the run number in the sample's logs -* @param sample the workspace's sample -*/ -void LoadRawHelper::setRunNumber(API::Sample& sample) -{ - std::string run = boost::lexical_cast<std::string>(isisRaw->r_number); - sample.addLogData( new PropertyWithValue<std::string>("run_number", run) ); -} -/**reads workspace dimensions,number of periods etc from raw data - *@param numberOfSpectra number of spectrums - *@param numberOfPeriods number of periods - *@param lengthIn size of workspace vectors - *@param noTimeRegimes number of time regime. - -*/ -void LoadRawHelper::readworkspaceParameters(int& numberOfSpectra,int& numberOfPeriods,int& lengthIn,int & noTimeRegimes ) -{ - // Read in the number of spectra in the RAW file - m_numberOfSpectra=numberOfSpectra = isisRaw->t_nsp1; - // Read the number of periods in this file - numberOfPeriods = isisRaw->t_nper; - // Read the number of time channels (i.e. bins) from the RAW file - const int channelsPerSpectrum = isisRaw->t_ntc1; - // Read in the time bin boundaries - lengthIn = channelsPerSpectrum + 1; - // Now check whether there is more than one time regime in use - noTimeRegimes = isisRaw->daep.n_tr_shift; -} -/**This method creates shared pointer to a workspace - *@param ws_sptr shared pointer to the parent workspace - *@param nVectors number of histograms in the workspace - *@param xLengthIn size of workspace X vector - *@param yLengthIn size of workspace Y vector -*/ -DataObjects::Workspace2D_sptr LoadRawHelper::createWorkspace(DataObjects::Workspace2D_sptr ws_sptr, - int nVectors,int xLengthIn,int yLengthIn) -{ - DataObjects::Workspace2D_sptr empty; - if(!ws_sptr)return empty; - DataObjects::Workspace2D_sptr workspace = boost::dynamic_pointer_cast<DataObjects::Workspace2D> - (WorkspaceFactory::Instance().create(ws_sptr,nVectors,xLengthIn,yLengthIn)); - return workspace; -} - -/** This method creates pointer to workspace - * @param nVectors The number of vectors/histograms in the workspace - * @param xlengthIn The number of X data points/bin boundaries in each vector - * @param ylengthIn The number of Y data points/bin boundaries in each vector - * @param title title of the workspace - * @return Workspace2D_sptr shared pointer to the workspace - */ -DataObjects::Workspace2D_sptr LoadRawHelper::createWorkspace(int nVectors, int xlengthIn,int ylengthIn,const std::string& title) -{ - DataObjects::Workspace2D_sptr workspace; - if(nVectors>0) - { - workspace =boost::dynamic_pointer_cast<DataObjects::Workspace2D>(WorkspaceFactory::Instance().create( - "Workspace2D", nVectors, xlengthIn, ylengthIn)); - // Set the units - workspace->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); - workspace->setYUnit("Counts"); - workspace->setTitle(title); + /**reads the histogram from raw file + *@param file - pointer to the raw file + *@param hist - postion in the file to read + */ + bool LoadRawHelper::readData(FILE* file,int hist) + { + return isisRaw->readData(file, hist); + } - } - return workspace; -} - -/**creates monitor workspace - *@param monws_sptr shared pointer to monitor workspace - *@param normalws_sptr shared pointer to output workspace - *@param mongrp_sptr shared pointer to monitor group workspace - *@param mwsSpecs number of spectra in the monitor workspace - *@param nwsSpecs number of spectra in the output workspace - *@param numberOfPeriods total number of periods from raw file - *@param lengthIn size of workspace vectors - *@param title title of the workspace - -*/ -void LoadRawHelper::createMonitorWorkspace(DataObjects::Workspace2D_sptr& monws_sptr,DataObjects::Workspace2D_sptr& normalws_sptr, - WorkspaceGroup_sptr& mongrp_sptr,const int mwsSpecs,const int nwsSpecs, - const int numberOfPeriods,const int lengthIn,const std::string title) -{ - try - { - //create monitor group workspace - mongrp_sptr = createGroupWorkspace(); //create workspace - // create monitor workspace - if(mwsSpecs>0) - { - if(normalws_sptr) - { - monws_sptr=createWorkspace(normalws_sptr,mwsSpecs,lengthIn,lengthIn-1); - - } - else - { - monws_sptr=createWorkspace(mwsSpecs,lengthIn,lengthIn-1,title); - } - } - if(!monws_sptr) return ; - - std::string wsName= getPropertyValue("OutputWorkspace"); - // if the normal output workspace size>0 then set the workspace as "MonitorWorkspace" - // otherwise set the workspace as "OutputWorkspace" - if (nwsSpecs> 0) - { - std::string monitorwsName = wsName + "_Monitors"; - declareProperty(new WorkspaceProperty<Workspace> ("MonitorWorkspace", monitorwsName, - Direction::Output)); - setWorkspaceProperty("MonitorWorkspace", title, mongrp_sptr, monws_sptr,numberOfPeriods, true); - } - else - { - //if only monitors range selected - //then set the monitor workspace as the outputworkspace - setWorkspaceProperty("OutputWorkspace", title, mongrp_sptr, monws_sptr,numberOfPeriods, false); - //normalws_sptr = monws_sptr; - } + float LoadRawHelper::getProtonCharge()const + { + return isisRaw->rpb.r_gd_prtn_chrg; + } + + /** + * Set the proton charge on the run object + * @param run The run object + */ + void LoadRawHelper::setProtonCharge(API::Run& run) + { + run.setProtonCharge(getProtonCharge()); + } + /** Stores the run number in the run logs + * @param run the workspace's run object + */ + void LoadRawHelper::setRunNumber(API::Run& run) + { + std::string run_num = boost::lexical_cast<std::string>(isisRaw->r_number); + run.addLogData( new PropertyWithValue<std::string>("run_number", run_num) ); + } + /**reads workspace dimensions,number of periods etc from raw data + *@param numberOfSpectra number of spectrums + *@param numberOfPeriods number of periods + *@param lengthIn size of workspace vectors + *@param noTimeRegimes number of time regime. + + */ + void LoadRawHelper::readworkspaceParameters(int& numberOfSpectra,int& numberOfPeriods,int& lengthIn,int & noTimeRegimes ) + { + // Read in the number of spectra in the RAW file + m_numberOfSpectra=numberOfSpectra = isisRaw->t_nsp1; + // Read the number of periods in this file + numberOfPeriods = isisRaw->t_nper; + // Read the number of time channels (i.e. bins) from the RAW file + const int channelsPerSpectrum = isisRaw->t_ntc1; + // Read in the time bin boundaries + lengthIn = channelsPerSpectrum + 1; + // Now check whether there is more than one time regime in use + noTimeRegimes = isisRaw->daep.n_tr_shift; + } + /**This method creates shared pointer to a workspace + *@param ws_sptr shared pointer to the parent workspace + *@param nVectors number of histograms in the workspace + *@param xLengthIn size of workspace X vector + *@param yLengthIn size of workspace Y vector + */ + DataObjects::Workspace2D_sptr LoadRawHelper::createWorkspace(DataObjects::Workspace2D_sptr ws_sptr, + int nVectors,int xLengthIn,int yLengthIn) + { + DataObjects::Workspace2D_sptr empty; + if(!ws_sptr)return empty; + DataObjects::Workspace2D_sptr workspace = boost::dynamic_pointer_cast<DataObjects::Workspace2D> + (WorkspaceFactory::Instance().create(ws_sptr,nVectors,xLengthIn,yLengthIn)); + return workspace; + } - } - catch(std::out_of_range& ) + /** This method creates pointer to workspace + * @param nVectors The number of vectors/histograms in the workspace + * @param xlengthIn The number of X data points/bin boundaries in each vector + * @param ylengthIn The number of Y data points/bin boundaries in each vector + * @param title title of the workspace + * @return Workspace2D_sptr shared pointer to the workspace + */ + DataObjects::Workspace2D_sptr LoadRawHelper::createWorkspace(int nVectors, int xlengthIn,int ylengthIn,const std::string& title) + { + DataObjects::Workspace2D_sptr workspace; + if(nVectors>0) + { + workspace =boost::dynamic_pointer_cast<DataObjects::Workspace2D>(WorkspaceFactory::Instance().create( + "Workspace2D", nVectors, xlengthIn, ylengthIn)); + // Set the units + workspace->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); + workspace->setYUnit("Counts"); + workspace->setTitle(title); + + } + return workspace; + } + + /**creates monitor workspace + *@param monws_sptr shared pointer to monitor workspace + *@param normalws_sptr shared pointer to output workspace + *@param mongrp_sptr shared pointer to monitor group workspace + *@param mwsSpecs number of spectra in the monitor workspace + *@param nwsSpecs number of spectra in the output workspace + *@param numberOfPeriods total number of periods from raw file + *@param lengthIn size of workspace vectors + *@param title title of the workspace + + */ + void LoadRawHelper::createMonitorWorkspace(DataObjects::Workspace2D_sptr& monws_sptr,DataObjects::Workspace2D_sptr& normalws_sptr, + WorkspaceGroup_sptr& mongrp_sptr,const int mwsSpecs,const int nwsSpecs, + const int numberOfPeriods,const int lengthIn,const std::string title) + { + try + { + //create monitor group workspace + mongrp_sptr = createGroupWorkspace(); //create workspace + // create monitor workspace + if(mwsSpecs>0) { - g_log.debug()<<"Error in creating monitor workspace"<<std::endl; + if(normalws_sptr) + { + monws_sptr=createWorkspace(normalws_sptr,mwsSpecs,lengthIn,lengthIn-1); + + } + else + { + monws_sptr=createWorkspace(mwsSpecs,lengthIn,lengthIn-1,title); + } } - catch(std::runtime_error& ) - { - g_log.debug()<<"Error in creating monitor workspace"<<std::endl; + if(!monws_sptr) return ; + + std::string wsName= getPropertyValue("OutputWorkspace"); + // if the normal output workspace size>0 then set the workspace as "MonitorWorkspace" + // otherwise set the workspace as "OutputWorkspace" + if (nwsSpecs> 0) + { + std::string monitorwsName = wsName + "_Monitors"; + declareProperty(new WorkspaceProperty<Workspace> ("MonitorWorkspace", monitorwsName, + Direction::Output)); + setWorkspaceProperty("MonitorWorkspace", title, mongrp_sptr, monws_sptr,numberOfPeriods, true); + } + else + { + //if only monitors range selected + //then set the monitor workspace as the outputworkspace + setWorkspaceProperty("OutputWorkspace", title, mongrp_sptr, monws_sptr,numberOfPeriods, false); + //normalws_sptr = monws_sptr; } -} - -/** Executes the algorithm. Reading in the file and creating and populating - * the output workspace - * - * @throw Exception::FileError If the RAW file cannot be found/opened - * @throw std::invalid_argument If the optional properties are set to invalid values - */ -void LoadRawHelper::exec() -{ -} + } + catch(std::out_of_range& ) + { + g_log.debug()<<"Error in creating monitor workspace"<<std::endl; + } + catch(std::runtime_error& ) + { + g_log.debug()<<"Error in creating monitor workspace"<<std::endl; + } + } -/** Creates a TimeSeriesProperty<bool> showing times when a particular period was active. - * @param period The data period - */ -Kernel::Property* LoadRawHelper::createPeriodLog(int period)const -{ - Kernel::TimeSeriesProperty<int>* periods = dynamic_cast< Kernel::TimeSeriesProperty<int>* >(m_perioids.get()); - if(!periods) return 0; - std::ostringstream ostr; - ostr<<period; - Kernel::TimeSeriesProperty<bool>* p = new Kernel::TimeSeriesProperty<bool> ("period "+ostr.str()); - std::map<Kernel::dateAndTime, int> pMap = periods->valueAsMap(); - std::map<Kernel::dateAndTime, int>::const_iterator it = pMap.begin(); - if (it->second != period) - p->addValue(it->first,false); - for(;it!=pMap.end();it++) - p->addValue(it->first, (it->second == period) ); - - return p; -} - -/** sets the workspace properties - * @param ws_sptr shared pointer to workspace - * @param grpws_sptr shared pointer to group workspace - * @param period period number - * @param bmonitors boolean flag to name the workspaces - */ -void LoadRawHelper::setWorkspaceProperty(DataObjects::Workspace2D_sptr ws_sptr, WorkspaceGroup_sptr grpws_sptr, - const int period, bool bmonitors) -{ - if(!ws_sptr) return; - if(!grpws_sptr) return; - std::string wsName; - std::string outws; - std::string outputWorkspace; - std::string localWSName = getProperty("OutputWorkspace"); - std::stringstream suffix; - suffix << (period + 1); - if (bmonitors) - { - wsName = localWSName + "_Monitors" + "_" + suffix.str(); - outputWorkspace = "MonitorWorkspace"; - } - else - { - wsName = localWSName + "_" + suffix.str(); - outputWorkspace = "OutputWorkspace"; - } - outws = outputWorkspace + "_" + suffix.str(); - declareProperty(new WorkspaceProperty<DataObjects::Workspace2D> (outws, wsName, Direction::Output)); - grpws_sptr->add(wsName); - setProperty(outws, boost::dynamic_pointer_cast<DataObjects::Workspace2D>(ws_sptr)); -} - -/** This method sets the workspace property - * @param propertyName property name for the workspace - * @param title title of the workspace - * @param grpws_sptr shared pointer to group workspace - * @param ws_sptr shared pointer to workspace - * @param numberOfPeriods numer periods in the raw file - * @param bMonitor to identify the workspace is an output workspace or monitor workspace - */ -void LoadRawHelper::setWorkspaceProperty(const std::string& propertyName, const std::string& title, - WorkspaceGroup_sptr grpws_sptr, DataObjects::Workspace2D_sptr ws_sptr,int numberOfPeriods, bool bMonitor) -{ - Property *ws = getProperty("OutputWorkspace"); - std::string wsName = ws->value(); - if (bMonitor) - wsName += "_Monitors"; - if(!ws_sptr)return; - ws_sptr->setTitle(title); - ws_sptr->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); - if (numberOfPeriods > 1) - { - grpws_sptr->add(wsName); - setProperty(propertyName, boost::dynamic_pointer_cast<Workspace>(grpws_sptr)); - } - else - { - setProperty(propertyName, boost::dynamic_pointer_cast<Workspace>(ws_sptr)); - } -} - -/** This method sets the raw file data to workspace vectors - * @param newWorkspace shared pointer to the workspace - * @param timeChannelsVec vector holding the X data - * @param wsIndex variable used for indexing the ouputworkspace - * @param nspecNum spectrum number - * @param noTimeRegimes regime no. - * @param lengthIn length of the workspace - * @param binStart start of bin - */ -void LoadRawHelper::setWorkspaceData(DataObjects::Workspace2D_sptr newWorkspace, const std::vector< - boost::shared_ptr<MantidVec> >& timeChannelsVec, int wsIndex, int nspecNum, int noTimeRegimes,int lengthIn,int binStart) -{ - if(!newWorkspace)return; - typedef double (*uf)(double); - uf dblSqrt = std::sqrt; - // But note that the last (overflow) bin is kept - MantidVec& Y = newWorkspace->dataY(wsIndex); - Y.assign(isisRaw->dat1 + binStart, isisRaw->dat1 + lengthIn); - // Fill the vector for the errors, containing sqrt(count) - MantidVec& E = newWorkspace->dataE(wsIndex); - std::transform(Y.begin(), Y.end(), E.begin(), dblSqrt); - - newWorkspace->getAxis(1)->spectraNo(wsIndex) = nspecNum; - //for loadrawbin0 - if(binStart==0) - { - newWorkspace->setX(wsIndex, timeChannelsVec[0]); - return ; - } - //for loadrawspectrum 0 - if(nspecNum==0) - { - newWorkspace->setX(wsIndex, timeChannelsVec[0]); - return ; - } - // Set the X vector pointer and spectrum number - if (noTimeRegimes < 2) - newWorkspace->setX(wsIndex, timeChannelsVec[0]); - else - { - - // Use std::vector::at just incase spectrum missing from spec array - newWorkspace->setX(wsIndex, timeChannelsVec.at(m_specTimeRegimes[nspecNum] - 1)); - } - -} - -/** This method returns the monitor spectrum list - * @param localWorkspace shared pointer to workspace - * @param monitorSpecList a list holding the spectrum indexes of the monitors - */ -void LoadRawHelper::getmonitorSpectrumList(DataObjects::Workspace2D_sptr localWorkspace, - std::vector<int>& monitorSpecList) -{ - if (!m_monitordetectorList.empty()) - { - const SpectraDetectorMap& specdetMap = localWorkspace->spectraMap(); - //get the monitor spectrum list from SpectraDetectorMap - std::vector<int> specList = specdetMap.getSpectra(m_monitordetectorList); - // remove duplicates by calling sort & unique algorithms - sort(specList.begin(), specList.end(), std::less<int>()); - std::vector<int>::iterator uEnd; - uEnd = unique(specList.begin(), specList.end()); - std::vector<int> newVec; - newVec.assign(specList.begin(), uEnd); - //remove if zeroes are there in the Spectra list - std::vector<int>::iterator itr; - itr = find(newVec.begin(), newVec.end(), 0); - if (itr != newVec.end()) - newVec.erase(itr); - monitorSpecList.assign(newVec.begin(), newVec.end()); - } - else{ - g_log.error() << "monitor detector id list is empty for the selected workspace" << std::endl; - } -} - - -/** This method creates pointer to group workspace - * @return WorkspaceGroup_sptr shared pointer to the workspace - */ -WorkspaceGroup_sptr LoadRawHelper::createGroupWorkspace() -{ - WorkspaceGroup_sptr workspacegrp(new WorkspaceGroup); - return workspacegrp; -} - -/** - * Check if a file is a text file - * @param file The file pointer - * @returns true if the file an ascii text file, false otherwise - */ -bool LoadRawHelper::isAscii(FILE* file) const -{ - char data[256]; - int n = fread(data, 1, sizeof(data), file); - char *pend = &data[n]; - fseek(file,0,SEEK_SET); - /* - * Call it a binary file if we find a non-ascii character in the - * first 256 bytes of the file. - */ - for( char *p = data; p < pend; ++p ) - { - unsigned long ch = (unsigned long)*p; - if( !(ch <= 0x7F) ) + /** Executes the algorithm. Reading in the file and creating and populating + * the output workspace + * + * @throw Exception::FileError If the RAW file cannot be found/opened + * @throw std::invalid_argument If the optional properties are set to invalid values + */ + void LoadRawHelper::exec() { - return false; } - - } - return true; -} + /** Creates a TimeSeriesProperty<bool> showing times when a particular period was active. + * @param period The data period + */ + Kernel::Property* LoadRawHelper::createPeriodLog(int period)const + { + Kernel::TimeSeriesProperty<int>* periods = dynamic_cast< Kernel::TimeSeriesProperty<int>* >(m_perioids.get()); + if(!periods) return 0; + std::ostringstream ostr; + ostr<<period; + Kernel::TimeSeriesProperty<bool>* p = new Kernel::TimeSeriesProperty<bool> ("period "+ostr.str()); + std::map<Kernel::dateAndTime, int> pMap = periods->valueAsMap(); + std::map<Kernel::dateAndTime, int>::const_iterator it = pMap.begin(); + if (it->second != period) + p->addValue(it->first,false); + for(;it!=pMap.end();it++) + p->addValue(it->first, (it->second == period) ); + + return p; + } -/** Constructs the time channel (X) vector(s) - * @param regimes The number of time regimes (if 1 regime, will actually contain 0) - * @param lengthIn The number of time channels - * @return The vector(s) containing the time channel boundaries, in a vector of shared ptrs - */ -std::vector<boost::shared_ptr<MantidVec> > LoadRawHelper::getTimeChannels(const int& regimes, - const int& lengthIn) -{ - float* const timeChannels = new float[lengthIn]; - isisRaw->getTimeChannels(timeChannels, lengthIn); + /** sets the workspace properties + * @param ws_sptr shared pointer to workspace + * @param grpws_sptr shared pointer to group workspace + * @param period period number + * @param bmonitors boolean flag to name the workspaces + */ + void LoadRawHelper::setWorkspaceProperty(DataObjects::Workspace2D_sptr ws_sptr, WorkspaceGroup_sptr grpws_sptr, + const int period, bool bmonitors) + { + if(!ws_sptr) return; + if(!grpws_sptr) return; + std::string wsName; + std::string outws; + std::string outputWorkspace; + std::string localWSName = getProperty("OutputWorkspace"); + std::stringstream suffix; + suffix << (period + 1); + if (bmonitors) + { + wsName = localWSName + "_Monitors" + "_" + suffix.str(); + outputWorkspace = "MonitorWorkspace"; + } + else + { + wsName = localWSName + "_" + suffix.str(); + outputWorkspace = "OutputWorkspace"; + } + outws = outputWorkspace + "_" + suffix.str(); + declareProperty(new WorkspaceProperty<DataObjects::Workspace2D> (outws, wsName, Direction::Output)); + grpws_sptr->add(wsName); + setProperty(outws, boost::dynamic_pointer_cast<DataObjects::Workspace2D>(ws_sptr)); + } - std::vector<boost::shared_ptr<MantidVec> > timeChannelsVec; - if (regimes >= 2) - { - g_log.debug() << "Raw file contains " << regimes << " time regimes\n"; - // If more than 1 regime, create a timeChannelsVec for each regime - for (int i = 0; i < regimes; ++i) - { - // Create a vector with the 'base' time channels - boost::shared_ptr<MantidVec> channelsVec(new MantidVec(timeChannels, timeChannels + lengthIn)); - const double shift = isisRaw->daep.tr_shift[i]; - g_log.debug() << "Time regime " << i + 1 << " shifted by " << shift << " microseconds\n"; - // Add on the shift for this vector - std::transform(channelsVec->begin(), channelsVec->end(), channelsVec->begin(), std::bind2nd( - std::plus<double>(), shift)); - timeChannelsVec.push_back(channelsVec); - } - // In this case, also need to populate the map of spectrum-regime correspondence - const int ndet = isisRaw->i_det; - std::map<int, int>::iterator hint = m_specTimeRegimes.begin(); - for (int j = 0; j < ndet; ++j) - { - // No checking for consistency here - that all detectors for given spectrum - // are declared to use same time regime. Will just use first encountered - hint = m_specTimeRegimes.insert(hint, std::make_pair(isisRaw->spec[j], isisRaw->timr[j])); - } - } - else // Just need one in this case - { - boost::shared_ptr<MantidVec> channelsVec(new MantidVec(timeChannels, timeChannels + lengthIn)); - timeChannelsVec.push_back(channelsVec); - } - // Done with the timeChannels C array so clean up - delete[] timeChannels; - return timeChannelsVec; -} - -/// Run the sub-algorithm LoadInstrument (or LoadInstrumentFromRaw) -/// @param fileName the raw file filename -/// @param localWorkspace The workspace to load the instrument for -void LoadRawHelper::runLoadInstrument(const std::string& fileName,DataObjects::Workspace2D_sptr localWorkspace) -{ - g_log.debug("Loading the instrument definition..."); - progress(m_prog, "Loading the instrument geometry..."); - // Determine the search directory for XML instrument definition files (IDFs) - std::string directoryName = Kernel::ConfigService::Instance().getString( - "instrumentDefinition.directory"); - if (directoryName.empty()) - { - // This is the assumed deployment directory for IDFs, where we need to be relative to the - // directory of the executable, not the current working directory. - directoryName = Poco::Path(Mantid::Kernel::ConfigService::Instance().getBaseDir()).resolve( - "../Instrument").toString(); - } - - std::string instrumentID = isisRaw->i_inst; // get the instrument name - size_t i = instrumentID.find_first_of(' '); // cut trailing spaces - if (i != std::string::npos) - instrumentID.erase(i); - - // force ID to upper case - std::transform(instrumentID.begin(), instrumentID.end(), instrumentID.begin(), toupper); - std::string fullPathIDF = directoryName + "/" + instrumentID + "_Definition.xml"; - - IAlgorithm_sptr loadInst= createSubAlgorithm("LoadInstrument"); - - // Now execute the sub-algorithm. Catch and log any error, but don't stop. - bool executionSuccessful(true); - try - { - loadInst->setPropertyValue("Filename", fullPathIDF); - loadInst->setProperty<MatrixWorkspace_sptr> ("Workspace", localWorkspace); - loadInst->execute(); - } catch (std::invalid_argument&) - { - g_log.information("Invalid argument to LoadInstrument sub-algorithm"); - executionSuccessful = false; - } catch (std::runtime_error&) - { - g_log.information("Unable to successfully run LoadInstrument sub-algorithm"); - executionSuccessful = false; - } + /** This method sets the workspace property + * @param propertyName property name for the workspace + * @param title title of the workspace + * @param grpws_sptr shared pointer to group workspace + * @param ws_sptr shared pointer to workspace + * @param numberOfPeriods numer periods in the raw file + * @param bMonitor to identify the workspace is an output workspace or monitor workspace + */ + void LoadRawHelper::setWorkspaceProperty(const std::string& propertyName, const std::string& title, + WorkspaceGroup_sptr grpws_sptr, DataObjects::Workspace2D_sptr ws_sptr,int numberOfPeriods, bool bMonitor) + { + Property *ws = getProperty("OutputWorkspace"); + std::string wsName = ws->value(); + if (bMonitor) + wsName += "_Monitors"; + if(!ws_sptr)return; + ws_sptr->setTitle(title); + ws_sptr->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); + if (numberOfPeriods > 1) + { + grpws_sptr->add(wsName); + setProperty(propertyName, boost::dynamic_pointer_cast<Workspace>(grpws_sptr)); + } + else + { + setProperty(propertyName, boost::dynamic_pointer_cast<Workspace>(ws_sptr)); + } + } - // If loading instrument definition file fails, run LoadInstrumentFromRaw instead - if (!executionSuccessful) - { - g_log.information() << "Instrument definition file " - << fullPathIDF << " not found. Attempt to load information about \n" - << "the instrument from raw data file.\n"; - runLoadInstrumentFromRaw(fileName,localWorkspace); - } - else - { - m_monitordetectorList = loadInst->getProperty("MonitorList"); - std::vector<int>::const_iterator itr; - for (itr = m_monitordetectorList.begin(); itr != m_monitordetectorList.end(); ++itr) + /** This method sets the raw file data to workspace vectors + * @param newWorkspace shared pointer to the workspace + * @param timeChannelsVec vector holding the X data + * @param wsIndex variable used for indexing the ouputworkspace + * @param nspecNum spectrum number + * @param noTimeRegimes regime no. + * @param lengthIn length of the workspace + * @param binStart start of bin + */ + void LoadRawHelper::setWorkspaceData(DataObjects::Workspace2D_sptr newWorkspace, const std::vector< + boost::shared_ptr<MantidVec> >& timeChannelsVec, int wsIndex, int nspecNum, int noTimeRegimes,int lengthIn,int binStart) { - g_log.debug() << "Monitor detector id is " << (*itr) << std::endl; + if(!newWorkspace)return; + typedef double (*uf)(double); + uf dblSqrt = std::sqrt; + // But note that the last (overflow) bin is kept + MantidVec& Y = newWorkspace->dataY(wsIndex); + Y.assign(isisRaw->dat1 + binStart, isisRaw->dat1 + lengthIn); + // Fill the vector for the errors, containing sqrt(count) + MantidVec& E = newWorkspace->dataE(wsIndex); + std::transform(Y.begin(), Y.end(), E.begin(), dblSqrt); + + newWorkspace->getAxis(1)->spectraNo(wsIndex) = nspecNum; + //for loadrawbin0 + if(binStart==0) + { + newWorkspace->setX(wsIndex, timeChannelsVec[0]); + return ; + } + //for loadrawspectrum 0 + if(nspecNum==0) + { + newWorkspace->setX(wsIndex, timeChannelsVec[0]); + return ; + } + // Set the X vector pointer and spectrum number + if (noTimeRegimes < 2) + newWorkspace->setX(wsIndex, timeChannelsVec[0]); + else + { + + // Use std::vector::at just incase spectrum missing from spec array + newWorkspace->setX(wsIndex, timeChannelsVec.at(m_specTimeRegimes[nspecNum] - 1)); + } + } - } -} -/// Run LoadInstrumentFromRaw as a sub-algorithm (only if loading from instrument definition file fails) -/// @param fileName the raw file filename -/// @param localWorkspace The workspace to load the instrument for -void LoadRawHelper::runLoadInstrumentFromRaw(const std::string& fileName,DataObjects::Workspace2D_sptr localWorkspace) -{ - IAlgorithm_sptr loadInst = createSubAlgorithm("LoadInstrumentFromRaw"); - loadInst->setPropertyValue("Filename", fileName); - // Set the workspace property to be the same one filled above - loadInst->setProperty<MatrixWorkspace_sptr> ("Workspace", localWorkspace); + /** This method returns the monitor spectrum list + * @param localWorkspace shared pointer to workspace + * @param monitorSpecList a list holding the spectrum indexes of the monitors + */ + void LoadRawHelper::getmonitorSpectrumList(DataObjects::Workspace2D_sptr localWorkspace, + std::vector<int>& monitorSpecList) + { + if (!m_monitordetectorList.empty()) + { + const SpectraDetectorMap& specdetMap = localWorkspace->spectraMap(); + //get the monitor spectrum list from SpectraDetectorMap + std::vector<int> specList = specdetMap.getSpectra(m_monitordetectorList); + // remove duplicates by calling sort & unique algorithms + sort(specList.begin(), specList.end(), std::less<int>()); + std::vector<int>::iterator uEnd; + uEnd = unique(specList.begin(), specList.end()); + std::vector<int> newVec; + newVec.assign(specList.begin(), uEnd); + //remove if zeroes are there in the Spectra list + std::vector<int>::iterator itr; + itr = find(newVec.begin(), newVec.end(), 0); + if (itr != newVec.end()) + newVec.erase(itr); + monitorSpecList.assign(newVec.begin(), newVec.end()); + } + else{ + g_log.error() << "monitor detector id list is empty for the selected workspace" << std::endl; + } + } - // Now execute the sub-algorithm. Catch and log any error, but don't stop. - try - { - loadInst->execute(); - } catch (std::runtime_error&) - { - g_log.error("Unable to successfully run LoadInstrumentFromRaw sub-algorithm"); - } - m_monitordetectorList = loadInst->getProperty("MonitorList"); - std::vector<int>::const_iterator itr; - for (itr = m_monitordetectorList.begin(); itr != m_monitordetectorList.end(); ++itr) - { - g_log.debug() << "Monitor dtector id is " << (*itr) << std::endl; - - } - if (!loadInst->isExecuted()) - { - g_log.error("No instrument definition loaded"); - } -} - -/// Run the LoadMappingTable sub-algorithm to fill the SpectraToDetectorMap -/// @param fileName the raw file filename -/// @param localWorkspace The workspace to load the mapping table for -void LoadRawHelper::runLoadMappingTable(const std::string& fileName,DataObjects::Workspace2D_sptr localWorkspace) -{ - g_log.debug("Loading the spectra-detector mapping..."); - progress(m_prog, "Loading the spectra-detector mapping..."); - // Now determine the spectra to detector map calling sub-algorithm LoadMappingTable - // There is a small penalty in re-opening the raw file but nothing major. - IAlgorithm_sptr loadmap = createSubAlgorithm("LoadMappingTable"); - loadmap->setPropertyValue("Filename",fileName); - loadmap->setProperty<MatrixWorkspace_sptr> ("Workspace", localWorkspace); - try - { - loadmap->execute(); - } catch (std::runtime_error&) - { - g_log.error("Unable to successfully execute LoadMappingTable sub-algorithm"); - } - if (!loadmap->isExecuted()) - { - g_log.error("LoadMappingTable sub-algorithm is not executed"); - } + /** This method creates pointer to group workspace + * @return WorkspaceGroup_sptr shared pointer to the workspace + */ + WorkspaceGroup_sptr LoadRawHelper::createGroupWorkspace() + { + WorkspaceGroup_sptr workspacegrp(new WorkspaceGroup); + return workspacegrp; + } -} + /** + * Check if a file is a text file + * @param file The file pointer + * @returns true if the file an ascii text file, false otherwise + */ + bool LoadRawHelper::isAscii(FILE* file) const + { + char data[256]; + int n = fread(data, 1, sizeof(data), file); + char *pend = &data[n]; + fseek(file,0,SEEK_SET); + /* + * Call it a binary file if we find a non-ascii character in the + * first 256 bytes of the file. + */ + for( char *p = data; p < pend; ++p ) + { + unsigned long ch = (unsigned long)*p; + if( !(ch <= 0x7F) ) + { + return false; + } + + } + return true; + } -/// Run the LoadLog sub-algorithm -/// @param fileName the raw file filename -/// @param localWorkspace The workspace to load the logs for -/// @param period The period number that the workspace holds -void LoadRawHelper::runLoadLog(const std::string& fileName,DataObjects::Workspace2D_sptr localWorkspace, int period) -{ - g_log.debug("Loading the log files..."); - progress(m_prog, "Reading log files..."); - IAlgorithm_sptr loadLog = createSubAlgorithm("LoadLog"); - // Pass through the same input filename - loadLog->setPropertyValue("Filename", fileName); - // Set the workspace property to be the same one filled above - loadLog->setProperty<MatrixWorkspace_sptr> ("Workspace", localWorkspace); - - // Now execute the sub-algorithm. Catch and log any error, but don't stop. - try - { - loadLog->execute(); - } catch (std::exception&) - { - g_log.error("Unable to successfully run LoadLog sub-algorithm"); - } - if (!loadLog->isExecuted()) - { - g_log.error("Unable to successfully run LoadLog sub-algorithm"); - } - LoadLog* plog=dynamic_cast<LoadLog*>(loadLog.get()); - if(plog) m_perioids=plog->getPeriodsProperty(); -} - -///sets optional properties for the loadraw algorithm -/// @param spec_min The minimum spectra number -/// @param spec_max The maximum spectra number -/// @param spec_list The list of Spectra to be included -void LoadRawHelper::setOptionalProperties(const int& spec_min,const int& spec_max,const std::vector<int>& spec_list) -{ - m_spec_min=spec_min; - m_spec_max=spec_max; - m_spec_list.assign(spec_list.begin(),spec_list.end()); -} -/// Validates the optional 'spectra to read' properties, if they have been set -void LoadRawHelper::checkOptionalProperties() -{ - //read in the settings passed to the algorithm - /*m_spec_list = getProperty("SpectrumList"); - m_spec_max = getProperty("SpectrumMax"); - m_spec_min = getProperty("SpectrumMin");*/ - - m_list = !m_spec_list.empty(); - m_bmspeclist = !m_spec_list.empty(); - m_interval = (m_spec_max != unSetInt) || (m_spec_min != 1); - if (m_spec_max == unSetInt) - m_spec_max = 1; - // Check validity of spectra list property, if set - if (m_list) - { - m_list = true; - if (m_spec_list.size() == 0) + /** Constructs the time channel (X) vector(s) + * @param regimes The number of time regimes (if 1 regime, will actually contain 0) + * @param lengthIn The number of time channels + * @return The vector(s) containing the time channel boundaries, in a vector of shared ptrs + */ + std::vector<boost::shared_ptr<MantidVec> > LoadRawHelper::getTimeChannels(const int& regimes, + const int& lengthIn) { - m_list = false; + float* const timeChannels = new float[lengthIn]; + isisRaw->getTimeChannels(timeChannels, lengthIn); + + std::vector<boost::shared_ptr<MantidVec> > timeChannelsVec; + if (regimes >= 2) + { + g_log.debug() << "Raw file contains " << regimes << " time regimes\n"; + // If more than 1 regime, create a timeChannelsVec for each regime + for (int i = 0; i < regimes; ++i) + { + // Create a vector with the 'base' time channels + boost::shared_ptr<MantidVec> channelsVec(new MantidVec(timeChannels, timeChannels + lengthIn)); + const double shift = isisRaw->daep.tr_shift[i]; + g_log.debug() << "Time regime " << i + 1 << " shifted by " << shift << " microseconds\n"; + // Add on the shift for this vector + std::transform(channelsVec->begin(), channelsVec->end(), channelsVec->begin(), std::bind2nd( + std::plus<double>(), shift)); + timeChannelsVec.push_back(channelsVec); + } + // In this case, also need to populate the map of spectrum-regime correspondence + const int ndet = isisRaw->i_det; + std::map<int, int>::iterator hint = m_specTimeRegimes.begin(); + for (int j = 0; j < ndet; ++j) + { + // No checking for consistency here - that all detectors for given spectrum + // are declared to use same time regime. Will just use first encountered + hint = m_specTimeRegimes.insert(hint, std::make_pair(isisRaw->spec[j], isisRaw->timr[j])); + } + } + else // Just need one in this case + { + boost::shared_ptr<MantidVec> channelsVec(new MantidVec(timeChannels, timeChannels + lengthIn)); + timeChannelsVec.push_back(channelsVec); + } + // Done with the timeChannels C array so clean up + delete[] timeChannels; + return timeChannelsVec; } - else + + /// Run the sub-algorithm LoadInstrument (or LoadInstrumentFromRaw) + /// @param fileName the raw file filename + /// @param localWorkspace The workspace to load the instrument for + void LoadRawHelper::runLoadInstrument(const std::string& fileName,DataObjects::Workspace2D_sptr localWorkspace) { - const int minlist = *min_element(m_spec_list.begin(), m_spec_list.end()); - const int maxlist = *max_element(m_spec_list.begin(), m_spec_list.end()); - if (maxlist >m_numberOfSpectra || minlist <= 0) + g_log.debug("Loading the instrument definition..."); + progress(m_prog, "Loading the instrument geometry..."); + // Determine the search directory for XML instrument definition files (IDFs) + std::string directoryName = Kernel::ConfigService::Instance().getString( + "instrumentDefinition.directory"); + if (directoryName.empty()) + { + // This is the assumed deployment directory for IDFs, where we need to be relative to the + // directory of the executable, not the current working directory. + directoryName = Poco::Path(Mantid::Kernel::ConfigService::Instance().getBaseDir()).resolve( + "../Instrument").toString(); + } + + std::string instrumentID = isisRaw->i_inst; // get the instrument name + size_t i = instrumentID.find_first_of(' '); // cut trailing spaces + if (i != std::string::npos) + instrumentID.erase(i); + + // force ID to upper case + std::transform(instrumentID.begin(), instrumentID.end(), instrumentID.begin(), toupper); + std::string fullPathIDF = directoryName + "/" + instrumentID + "_Definition.xml"; + + IAlgorithm_sptr loadInst= createSubAlgorithm("LoadInstrument"); + + // Now execute the sub-algorithm. Catch and log any error, but don't stop. + bool executionSuccessful(true); + try + { + loadInst->setPropertyValue("Filename", fullPathIDF); + loadInst->setProperty<MatrixWorkspace_sptr> ("Workspace", localWorkspace); + loadInst->execute(); + } catch (std::invalid_argument&) + { + g_log.information("Invalid argument to LoadInstrument sub-algorithm"); + executionSuccessful = false; + } catch (std::runtime_error&) + { + g_log.information("Unable to successfully run LoadInstrument sub-algorithm"); + executionSuccessful = false; + } + + // If loading instrument definition file fails, run LoadInstrumentFromRaw instead + if (!executionSuccessful) + { + g_log.information() << "Instrument definition file " + << fullPathIDF << " not found. Attempt to load information about \n" + << "the instrument from raw data file.\n"; + runLoadInstrumentFromRaw(fileName,localWorkspace); + } + else { - g_log.error("Invalid list of spectra"); - throw std::invalid_argument("Inconsistent properties defined"); + m_monitordetectorList = loadInst->getProperty("MonitorList"); + std::vector<int>::const_iterator itr; + for (itr = m_monitordetectorList.begin(); itr != m_monitordetectorList.end(); ++itr) + { + g_log.debug() << "Monitor detector id is " << (*itr) << std::endl; + } } } - } - // Check validity of spectra range, if set - if (m_interval) - { - m_interval = true; - //m_spec_min = getProperty("SpectrumMin"); - if (m_spec_min != 1 && m_spec_max == 1) - m_spec_max = m_numberOfSpectra; - if (m_spec_max < m_spec_min || m_spec_max >m_numberOfSpectra) + + /// Run LoadInstrumentFromRaw as a sub-algorithm (only if loading from instrument definition file fails) + /// @param fileName the raw file filename + /// @param localWorkspace The workspace to load the instrument for + void LoadRawHelper::runLoadInstrumentFromRaw(const std::string& fileName,DataObjects::Workspace2D_sptr localWorkspace) { - g_log.error("Invalid Spectrum min/max properties"); - throw std::invalid_argument("Inconsistent properties defined"); + IAlgorithm_sptr loadInst = createSubAlgorithm("LoadInstrumentFromRaw"); + loadInst->setPropertyValue("Filename", fileName); + // Set the workspace property to be the same one filled above + loadInst->setProperty<MatrixWorkspace_sptr> ("Workspace", localWorkspace); + + // Now execute the sub-algorithm. Catch and log any error, but don't stop. + try + { + loadInst->execute(); + } catch (std::runtime_error&) + { + g_log.error("Unable to successfully run LoadInstrumentFromRaw sub-algorithm"); + } + m_monitordetectorList = loadInst->getProperty("MonitorList"); + std::vector<int>::const_iterator itr; + for (itr = m_monitordetectorList.begin(); itr != m_monitordetectorList.end(); ++itr) + { + g_log.debug() << "Monitor dtector id is " << (*itr) << std::endl; + + } + if (!loadInst->isExecuted()) + { + g_log.error("No instrument definition loaded"); + } } - } -} -/// Calculates the total number of spectra in the workspace, given the input properties -int LoadRawHelper::calculateWorkspaceSize() -{ - int total_specs(0); - if (m_interval || m_list) - { - if (m_interval) + /// Run the LoadMappingTable sub-algorithm to fill the SpectraToDetectorMap + /// @param fileName the raw file filename + /// @param localWorkspace The workspace to load the mapping table for + void LoadRawHelper::runLoadMappingTable(const std::string& fileName,DataObjects::Workspace2D_sptr localWorkspace) { - if (m_spec_min != 1 && m_spec_max == 1) - m_spec_max = m_numberOfSpectra; + g_log.debug("Loading the spectra-detector mapping..."); + progress(m_prog, "Loading the spectra-detector mapping..."); + // Now determine the spectra to detector map calling sub-algorithm LoadMappingTable + // There is a small penalty in re-opening the raw file but nothing major. + IAlgorithm_sptr loadmap = createSubAlgorithm("LoadMappingTable"); + loadmap->setPropertyValue("Filename",fileName); + loadmap->setProperty<MatrixWorkspace_sptr> ("Workspace", localWorkspace); + try + { + loadmap->execute(); + } catch (std::runtime_error&) + { + g_log.error("Unable to successfully execute LoadMappingTable sub-algorithm"); + } + + if (!loadmap->isExecuted()) + { + g_log.error("LoadMappingTable sub-algorithm is not executed"); + } - m_total_specs=total_specs = (m_spec_max - m_spec_min + 1); - m_spec_max += 1; } - else - total_specs = 0; - if (m_list) + /// Run the LoadLog sub-algorithm + /// @param fileName the raw file filename + /// @param localWorkspace The workspace to load the logs for + /// @param period The period number that the workspace holds + void LoadRawHelper::runLoadLog(const std::string& fileName,DataObjects::Workspace2D_sptr localWorkspace, int period) { - if (m_interval) + g_log.debug("Loading the log files..."); + progress(m_prog, "Reading log files..."); + IAlgorithm_sptr loadLog = createSubAlgorithm("LoadLog"); + // Pass through the same input filename + loadLog->setPropertyValue("Filename", fileName); + // Set the workspace property to be the same one filled above + loadLog->setProperty<MatrixWorkspace_sptr> ("Workspace", localWorkspace); + + // Now execute the sub-algorithm. Catch and log any error, but don't stop. + try { - for (std::vector<int>::iterator it = m_spec_list.begin(); it != m_spec_list.end();) - if (*it >= m_spec_min && *it < m_spec_max) - { - it = m_spec_list.erase(it); - } - else - it++; + loadLog->execute(); + } catch (std::exception&) + { + g_log.error("Unable to successfully run LoadLog sub-algorithm"); } - if (m_spec_list.size() == 0) - m_list = false; - total_specs += m_spec_list.size(); - m_total_specs=total_specs; + if (!loadLog->isExecuted()) + { + g_log.error("Unable to successfully run LoadLog sub-algorithm"); + } + LoadLog* plog=dynamic_cast<LoadLog*>(loadLog.get()); + if(plog) m_perioids=plog->getPeriodsProperty(); } - } - else - { - total_specs = m_numberOfSpectra; - m_total_specs=total_specs; - // In this case want all the spectra, but zeroth spectrum is garbage so go from 1 to NSP1 - m_spec_min = 1; - m_spec_max = m_numberOfSpectra + 1; - } - return total_specs; -} - -/// calculate workspace sizes. -/// @param monitorSpecList the vector of the monitor spectra -/// @param normalwsSpecs the spectra for the detector workspace -/// @param monitorwsSpecs the spectra for the monitor workspace -void LoadRawHelper::calculateWorkspacesizes(const std::vector<int>& monitorSpecList, - int& normalwsSpecs, int & monitorwsSpecs) -{ - if (!m_interval && !m_bmspeclist) - { - normalwsSpecs = m_total_specs - monitorSpecList.size(); - monitorwsSpecs = monitorSpecList.size(); - g_log.debug() << "normalwsSpecs when m_interval & m_bmspeclist are false is " << normalwsSpecs - << " monitorwsSpecs is " << monitorwsSpecs << std::endl; - } - else if (m_interval || m_bmspeclist) - { - int msize = 0; - if (m_interval) + + ///sets optional properties for the loadraw algorithm + /// @param spec_min The minimum spectra number + /// @param spec_max The maximum spectra number + /// @param spec_list The list of Spectra to be included + void LoadRawHelper::setOptionalProperties(const int& spec_min,const int& spec_max,const std::vector<int>& spec_list) + { + m_spec_min=spec_min; + m_spec_max=spec_max; + m_spec_list.assign(spec_list.begin(),spec_list.end()); + } + + /// Validates the optional 'spectra to read' properties, if they have been set + void LoadRawHelper::checkOptionalProperties() { - std::vector<int>::const_iterator itr1; - for (itr1 = monitorSpecList.begin(); itr1 != monitorSpecList.end(); ++itr1) + //read in the settings passed to the algorithm + /*m_spec_list = getProperty("SpectrumList"); + m_spec_max = getProperty("SpectrumMax"); + m_spec_min = getProperty("SpectrumMin");*/ + + m_list = !m_spec_list.empty(); + m_bmspeclist = !m_spec_list.empty(); + m_interval = (m_spec_max != unSetInt) || (m_spec_min != 1); + if (m_spec_max == unSetInt) + m_spec_max = 1; + // Check validity of spectra list property, if set + if (m_list) + { + m_list = true; + if (m_spec_list.size() == 0) + { + m_list = false; + } + else + { + const int minlist = *min_element(m_spec_list.begin(), m_spec_list.end()); + const int maxlist = *max_element(m_spec_list.begin(), m_spec_list.end()); + if (maxlist >m_numberOfSpectra || minlist <= 0) + { + g_log.error("Invalid list of spectra"); + throw std::invalid_argument("Inconsistent properties defined"); + } + } + } + // Check validity of spectra range, if set + if (m_interval) { - if (*itr1 >= m_spec_min && *itr1 < m_spec_max) - ++msize; + m_interval = true; + //m_spec_min = getProperty("SpectrumMin"); + if (m_spec_min != 1 && m_spec_max == 1) + m_spec_max = m_numberOfSpectra; + if (m_spec_max < m_spec_min || m_spec_max >m_numberOfSpectra) + { + g_log.error("Invalid Spectrum min/max properties"); + throw std::invalid_argument("Inconsistent properties defined"); + } + } - monitorwsSpecs = msize; - normalwsSpecs = m_total_specs - monitorwsSpecs; - g_log.debug() << "normalwsSpecs when m_interval true is " << normalwsSpecs - << " monitorwsSpecs is " << monitorwsSpecs << std::endl; } - if (m_bmspeclist) + /// Calculates the total number of spectra in the workspace, given the input properties + int LoadRawHelper::calculateWorkspaceSize() { - if (m_interval) + int total_specs(0); + if (m_interval || m_list) { - std::vector<int>::iterator itr; - for (itr = m_spec_list.begin(); itr != m_spec_list.end();) - { //if the m_spec_list elements are in the range between m_spec_min & m_spec_max - if (*itr >= m_spec_min && *itr < m_spec_max) - itr = m_spec_list.erase(itr); - else - ++itr; - } - if (m_spec_list.size() == 0) - { - g_log.debug() << "normalwsSpecs is " << normalwsSpecs << " monitorwsSpecs is " - << monitorwsSpecs << std::endl; - } - else - { //at this point there are monitors in the list which are not in the min& max range - // so find those monitors count and calculate the workspace specs - std::vector<int>::const_iterator itr; - std::vector<int>::const_iterator monitr; - int monCounter = 0; - for (itr = m_spec_list.begin(); itr != m_spec_list.end(); ++itr) - { - monitr = find(monitorSpecList.begin(), monitorSpecList.end(), *itr); - if (monitr != monitorSpecList.end()) - ++monCounter; - } - monitorwsSpecs += monCounter; - normalwsSpecs = m_total_specs - monitorwsSpecs; - g_log.debug() << "normalwsSpecs is " << normalwsSpecs << " monitorwsSpecs is " - << monitorwsSpecs << std::endl; - } - }//end if loop for m_interval + if (m_interval) + { + if (m_spec_min != 1 && m_spec_max == 1) + m_spec_max = m_numberOfSpectra; + + m_total_specs=total_specs = (m_spec_max - m_spec_min + 1); + m_spec_max += 1; + } + else + total_specs = 0; + + if (m_list) + { + if (m_interval) + { + for (std::vector<int>::iterator it = m_spec_list.begin(); it != m_spec_list.end();) + if (*it >= m_spec_min && *it < m_spec_max) + { + it = m_spec_list.erase(it); + } + else + it++; + } + if (m_spec_list.size() == 0) + m_list = false; + total_specs += m_spec_list.size(); + m_total_specs=total_specs; + + } + } else - { //if only List true - int mSize = 0; - std::vector<int>::const_iterator itr; - std::vector<int>::const_iterator monitr; - for (itr = m_spec_list.begin(); itr != m_spec_list.end(); ++itr) - { - monitr = find(monitorSpecList.begin(), monitorSpecList.end(), *itr); - if (monitr != monitorSpecList.end()) - { - ++mSize; - } - } - monitorwsSpecs = mSize; - normalwsSpecs = m_total_specs - monitorwsSpecs; - - } - }//end of if loop for m_bmspeclist - } - -} - -void LoadRawHelper::loadSpectra(FILE* file,const int& period,const int& total_specs, - DataObjects::Workspace2D_sptr ws_sptr,std::vector<boost::shared_ptr<MantidVec> > timeChannelsVec) -{ - int histCurrent = -1; - int wsIndex=0; - int numberOfPeriods=isisRaw->t_nper; - int histTotal = total_specs * numberOfPeriods; - int noTimeRegimes=getNumberofTimeRegimes(); - int lengthIn = isisRaw->t_ntc1+1; - - //loop through spectra - for (int i = 1; i <= m_numberOfSpectra; ++i) + { + total_specs = m_numberOfSpectra; + m_total_specs=total_specs; + // In this case want all the spectra, but zeroth spectrum is garbage so go from 1 to NSP1 + m_spec_min = 1; + m_spec_max = m_numberOfSpectra + 1; + } + return total_specs; + } + + /// calculate workspace sizes. + /// @param monitorSpecList the vector of the monitor spectra + /// @param normalwsSpecs the spectra for the detector workspace + /// @param monitorwsSpecs the spectra for the monitor workspace + void LoadRawHelper::calculateWorkspacesizes(const std::vector<int>& monitorSpecList, + int& normalwsSpecs, int & monitorwsSpecs) + { + if (!m_interval && !m_bmspeclist) + { + normalwsSpecs = m_total_specs - monitorSpecList.size(); + monitorwsSpecs = monitorSpecList.size(); + g_log.debug() << "normalwsSpecs when m_interval & m_bmspeclist are false is " << normalwsSpecs + << " monitorwsSpecs is " << monitorwsSpecs << std::endl; + } + else if (m_interval || m_bmspeclist) + { + int msize = 0; + if (m_interval) { - int histToRead = i + period * (m_numberOfSpectra + 1); - if ((i >= m_spec_min && i < m_spec_max) || (m_list && find(m_spec_list.begin(), m_spec_list.end(), - i) != m_spec_list.end())) - { - progress(m_prog, "Reading raw file data..."); - - //read spectrum from raw file - readData(file, histToRead); - //set worksapce data - setWorkspaceData(ws_sptr, timeChannelsVec, wsIndex, i,noTimeRegimes,lengthIn,1); - ++wsIndex; - - if (numberOfPeriods == 1) - { - if (++histCurrent % 100 == 0) - { - m_prog = double(histCurrent) / histTotal; - } - interruption_point(); - } - - } - else - { - skipData(file, histToRead); - } + std::vector<int>::const_iterator itr1; + for (itr1 = monitorSpecList.begin(); itr1 != monitorSpecList.end(); ++itr1) + { + if (*itr1 >= m_spec_min && *itr1 < m_spec_max) + ++msize; + } + monitorwsSpecs = msize; + normalwsSpecs = m_total_specs - monitorwsSpecs; + g_log.debug() << "normalwsSpecs when m_interval true is " << normalwsSpecs + << " monitorwsSpecs is " << monitorwsSpecs << std::endl; } + if (m_bmspeclist) + { + if (m_interval) + { + std::vector<int>::iterator itr; + for (itr = m_spec_list.begin(); itr != m_spec_list.end();) + { //if the m_spec_list elements are in the range between m_spec_min & m_spec_max + if (*itr >= m_spec_min && *itr < m_spec_max) + itr = m_spec_list.erase(itr); + else + ++itr; + } + if (m_spec_list.size() == 0) + { + g_log.debug() << "normalwsSpecs is " << normalwsSpecs << " monitorwsSpecs is " + << monitorwsSpecs << std::endl; + } + else + { //at this point there are monitors in the list which are not in the min& max range + // so find those monitors count and calculate the workspace specs + std::vector<int>::const_iterator itr; + std::vector<int>::const_iterator monitr; + int monCounter = 0; + for (itr = m_spec_list.begin(); itr != m_spec_list.end(); ++itr) + { + monitr = find(monitorSpecList.begin(), monitorSpecList.end(), *itr); + if (monitr != monitorSpecList.end()) + ++monCounter; + } + monitorwsSpecs += monCounter; + normalwsSpecs = m_total_specs - monitorwsSpecs; + g_log.debug() << "normalwsSpecs is " << normalwsSpecs << " monitorwsSpecs is " + << monitorwsSpecs << std::endl; + } + }//end if loop for m_interval + else + { //if only List true + int mSize = 0; + std::vector<int>::const_iterator itr; + std::vector<int>::const_iterator monitr; + for (itr = m_spec_list.begin(); itr != m_spec_list.end(); ++itr) + { + monitr = find(monitorSpecList.begin(), monitorSpecList.end(), *itr); + if (monitr != monitorSpecList.end()) + { + ++mSize; + } + } + monitorwsSpecs = mSize; + normalwsSpecs = m_total_specs - monitorwsSpecs; + + } + }//end of if loop for m_bmspeclist + } + + } -} + void LoadRawHelper::loadSpectra(FILE* file,const int& period,const int& total_specs, + DataObjects::Workspace2D_sptr ws_sptr,std::vector<boost::shared_ptr<MantidVec> > timeChannelsVec) + { + int histCurrent = -1; + int wsIndex=0; + int numberOfPeriods=isisRaw->t_nper; + int histTotal = total_specs * numberOfPeriods; + int noTimeRegimes=getNumberofTimeRegimes(); + int lengthIn = isisRaw->t_ntc1+1; + + //loop through spectra + for (int i = 1; i <= m_numberOfSpectra; ++i) + { + int histToRead = i + period * (m_numberOfSpectra + 1); + if ((i >= m_spec_min && i < m_spec_max) || (m_list && find(m_spec_list.begin(), m_spec_list.end(), + i) != m_spec_list.end())) + { + progress(m_prog, "Reading raw file data..."); + + //read spectrum from raw file + readData(file, histToRead); + //set worksapce data + setWorkspaceData(ws_sptr, timeChannelsVec, wsIndex, i,noTimeRegimes,lengthIn,1); + ++wsIndex; + + if (numberOfPeriods == 1) + { + if (++histCurrent % 100 == 0) + { + m_prog = double(histCurrent) / histTotal; + } + interruption_point(); + } + + } + else + { + skipData(file, histToRead); + } + } + + } -} // namespace DataHandling + } // namespace DataHandling } // namespace Mantid diff --git a/Code/Mantid/DataHandling/src/LoadRawSpectrum0.cpp b/Code/Mantid/DataHandling/src/LoadRawSpectrum0.cpp index 8de305715c4..356e8f9d3df 100644 --- a/Code/Mantid/DataHandling/src/LoadRawSpectrum0.cpp +++ b/Code/Mantid/DataHandling/src/LoadRawSpectrum0.cpp @@ -94,16 +94,16 @@ namespace Mantid // Create the 2D workspace for the output DataObjects::Workspace2D_sptr localWorkspace =createWorkspace(total_specs, m_lengthIn,m_lengthIn-1,title); - Sample& sample = localWorkspace->mutableSample(); + Run& run = localWorkspace->mutableRun(); if(bLoadlogFiles) { runLoadLog(m_filename,localWorkspace); Property* log = createPeriodLog(1); - if (log) sample.addLogData(log); + if (log) run.addLogData(log); } // Set the total proton charge for this run - setProtonCharge(sample); + setProtonCharge(run); WorkspaceGroup_sptr wsgrp_sptr = createGroupWorkspace(); setWorkspaceProperty("OutputWorkspace", title, wsgrp_sptr, localWorkspace,m_numberOfPeriods, false); @@ -121,13 +121,13 @@ namespace Mantid //remove previous period data std::stringstream prevPeriod; prevPeriod << "PERIOD " << (period); - //std::string prevPeriod="PERIOD "+suffix.str(); - Sample& sampleObj = localWorkspace->mutableSample(); - sampleObj.removeLogData(prevPeriod.str()); + Run& runObj = localWorkspace->mutableRun(); + runObj.removeLogData(prevPeriod.str()); //add current period data Property* log = createPeriodLog(period+1); if (log) - { sampleObj.addLogData(log); + { + runObj.addLogData(log); } } //skip all spectra except the first one in each period diff --git a/Code/Mantid/DataHandling/src/SaveCanSAS1D.cpp b/Code/Mantid/DataHandling/src/SaveCanSAS1D.cpp index a59836101a3..d8a538f9d13 100644 --- a/Code/Mantid/DataHandling/src/SaveCanSAS1D.cpp +++ b/Code/Mantid/DataHandling/src/SaveCanSAS1D.cpp @@ -7,7 +7,7 @@ #include "MantidGeometry/IComponent.h" #include "MantidAPI/WorkspaceValidators.h" #include "MantidKernel/MantidVersion.h" -#include "MantidAPI/Sample.h" +#include "MantidAPI/Run.h" #include <boost/shared_ptr.hpp> #include <fstream> @@ -253,11 +253,12 @@ namespace Mantid { //initialise the run number to an empty string, this may or may not be changed later std::string run; - try { - Kernel::Property *logP=m_workspace->sample().getLogData("run_number"); - run = logP->value(); + if( m_workspace->run().hasProperty("run_number") ) + { + Kernel::Property *logP = m_workspace->run().getLogData("run_number"); + run = logP->value(); } - catch(Exception::NotFoundError) + else { g_log.debug() << "Didn't find RunNumber log in workspace. Writing <Run></Run> to the CANSAS file\n"; } @@ -453,18 +454,17 @@ namespace Mantid std::string sasProcsvn="\n\t\t\t<term name=\"svn\">"; sasProcsvn+=version; sasProcsvn+="</term>"; - //outFile<<sasProcsvn; sasProcess+=sasProcsvn; - const API::Sample& sample= m_workspace->sample(); - std::string user_file=""; - try + const API::Run& run= m_workspace->run(); + std::string user_file(""); + if( run.hasProperty("UserFile") ) { - user_file=sample.getLogData("UserFile")->value(); + user_file = run.getLogData("UserFile")->value(); } - catch(std::runtime_error&ex) + else { - g_log.debug()<<ex.what()<<std::endl; + g_log.warning()<< "Run does not contain \"UserFile\" information. A blank entry will be written." <<std::endl; } std::string sasProcuserfile="\n\t\t\t<term name=\"user_file\">"; diff --git a/Code/Mantid/DataHandling/test/LoadCanSAS1dTest.h b/Code/Mantid/DataHandling/test/LoadCanSAS1dTest.h index 30eb98b87f0..a4a489efb89 100644 --- a/Code/Mantid/DataHandling/test/LoadCanSAS1dTest.h +++ b/Code/Mantid/DataHandling/test/LoadCanSAS1dTest.h @@ -56,7 +56,7 @@ public: TS_ASSERT_THROWS_NOTHING( ws = Mantid::API::AnalysisDataService::Instance().retrieve(outputSpace) ); Mantid::DataObjects::Workspace2D_sptr ws2d = boost::dynamic_pointer_cast<Mantid::DataObjects::Workspace2D>(ws); - Mantid::Kernel::Property *logP = ws2d->sample().getLogData("run_number"); + Mantid::Kernel::Property *logP = ws2d->run().getLogData("run_number"); TS_ASSERT_EQUALS( logP->value(), "LOQ48097") //Single histogram diff --git a/Code/Mantid/DataHandling/test/LoadDAETest.h b/Code/Mantid/DataHandling/test/LoadDAETest.h index 3fe42eb3ffb..dca0673bb19 100644 --- a/Code/Mantid/DataHandling/test/LoadDAETest.h +++ b/Code/Mantid/DataHandling/test/LoadDAETest.h @@ -52,12 +52,12 @@ public: // TS_ASSERT_THROWS(m_loader.execute(),std::runtime_error); // Set inputs - m_loader.setPropertyValue("DAEname", m_inputDAE); - m_loader.setPropertyValue("SpectrumMin", "1"); - m_loader.setPropertyValue("SpectrumMax", "2"); + TS_ASSERT_THROWS_NOTHING(m_loader.setPropertyValue("DAEname", m_inputDAE)) + TS_ASSERT_THROWS_NOTHING(m_loader.setPropertyValue("SpectrumMin", "1")) + TS_ASSERT_THROWS_NOTHING(m_loader.setPropertyValue("SpectrumMax", "2")) m_outputSpace = "DAEouter"; - m_loader.setPropertyValue("OutputWorkspace", m_outputSpace); + TS_ASSERT_THROWS_NOTHING(m_loader.setPropertyValue("OutputWorkspace", m_outputSpace)) std::string result; TS_ASSERT_THROWS_NOTHING( result = m_loader.getPropertyValue("DAEname") ) diff --git a/Code/Mantid/DataHandling/test/LoadLogTest.h b/Code/Mantid/DataHandling/test/LoadLogTest.h index a2c63c5524a..af0f111126d 100644 --- a/Code/Mantid/DataHandling/test/LoadLogTest.h +++ b/Code/Mantid/DataHandling/test/LoadLogTest.h @@ -70,7 +70,7 @@ public: // boost::shared_ptr<Sample> sample = output->getSample(); - Property *l_property = output->sample().getLogData("HRP37129_ICPevent"); + Property *l_property = output->run().getLogData("HRP37129_ICPevent"); TimeSeriesProperty<std::string> *l_timeSeries = dynamic_cast<TimeSeriesProperty<std::string>*>(l_property); std::string timeSeriesString = l_timeSeries->value(); @@ -124,27 +124,27 @@ public: // obtain the expected log files which should be in the same directory as the raw datafile - Property *l_property = output->sample().getLogData( std::string("ICPevent") ); + Property *l_property = output->run().getLogData( std::string("ICPevent") ); TimeSeriesProperty<std::string> *l_timeSeriesString = dynamic_cast<TimeSeriesProperty<std::string>*>(l_property); std::string timeSeriesString = l_timeSeriesString->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,28), "2007-Nov-13 15:19:13 BEGIN" ); - l_property = output->sample().getLogData( std::string("cphs_6") ); + l_property = output->run().getLogData( std::string("cphs_6") ); TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); timeSeriesString = l_timeSeriesDouble->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,23), "2007-Nov-13 15:16:20 0" ); - l_property = output->sample().getLogData( std::string("PROP3") ); + l_property = output->run().getLogData( std::string("PROP3") ); l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); timeSeriesString = l_timeSeriesDouble->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,23), "2007-Nov-13 15:16:20 0" ); - l_property = output->sample().getLogData( std::string("SE_He_Level") ); + l_property = output->run().getLogData( std::string("SE_He_Level") ); l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); timeSeriesString = l_timeSeriesDouble->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,24), "2007-Nov-13 15:17:08 -1" ); - l_property = output->sample().getLogData( std::string("TEMP1") ); + l_property = output->run().getLogData( std::string("TEMP1") ); l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); timeSeriesString = l_timeSeriesDouble->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,23), "2007-Nov-13 15:16:20 0" ); @@ -193,7 +193,7 @@ public: // obtain the expected log files which should be in the same directory as the raw datafile - Property *l_property = output->sample().getLogData( std::string("ICPevent") ); + Property *l_property = output->run().getLogData( std::string("ICPevent") ); TimeSeriesProperty<std::string> *l_timeSeriesString = dynamic_cast<TimeSeriesProperty<std::string>*>(l_property); std::string timeSeriesString = l_timeSeriesString->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,26), "2007-Nov-16 13:25:48 END" ); @@ -241,17 +241,17 @@ void testExecWiththreecolumnLogfile() // obtain the expected log files which should be in the same directory as the raw datafile - Property *l_property = output->sample().getLogData( std::string("ICPevent") ); + Property *l_property = output->run().getLogData( std::string("ICPevent") ); TimeSeriesProperty<std::string> *l_timeSeriesString = dynamic_cast<TimeSeriesProperty<std::string>*>(l_property); std::string timeSeriesString = l_timeSeriesString->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,36), "2009-Nov-10 17:22:13 CHANGE_PERIOD" ); - l_property =output->sample().getLogData( std::string("J6CX") ); + l_property =output->run().getLogData( std::string("J6CX") ); TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); timeSeriesString = l_timeSeriesDouble->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,20), "2009-Nov-10 17:22:14" ); - l_property = output->sample().getLogData( std::string("BeamCurrent") ); + l_property = output->run().getLogData( std::string("BeamCurrent") ); l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); timeSeriesString = l_timeSeriesDouble->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,20), "2009-Nov-10 10:14:03" ); @@ -300,12 +300,12 @@ void testloadlogwithalternatedatastream() // obtain the expected log files which should be in the same directory as the raw datafile - Property *l_property = output->sample().getLogData( std::string("ICPevent") ); + Property *l_property = output->run().getLogData( std::string("ICPevent") ); TimeSeriesProperty<std::string> *l_timeSeriesString = dynamic_cast<TimeSeriesProperty<std::string>*>(l_property); std::string timeSeriesString = l_timeSeriesString->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,36), "2009-Nov-11 11:25:57 CHANGE_PERIOD" ); - Property* string_property = output->sample().getLogData( std::string("RF1Ampon") ); + Property* string_property = output->run().getLogData( std::string("RF1Ampon") ); TimeSeriesProperty<std::string> *l_timeSeriesString1 = dynamic_cast<TimeSeriesProperty<std::string>*>(string_property); std::map<dateAndTime, std::string> vmap=l_timeSeriesString1->valueAsMap(); std::map<dateAndTime, std::string>::const_iterator itr; @@ -313,14 +313,14 @@ void testloadlogwithalternatedatastream() {TS_ASSERT_EQUALS( itr->second, "False" ); } - string_property = output->sample().getLogData( std::string("ShutterStatus") ); + string_property = output->run().getLogData( std::string("ShutterStatus") ); l_timeSeriesString1 = dynamic_cast<TimeSeriesProperty<std::string>*>(string_property); std::map<dateAndTime, std::string> vmap1=l_timeSeriesString1->valueAsMap(); for(itr=vmap1.begin();itr!=vmap1.end();++itr) {TS_ASSERT_EQUALS( itr->second, "OPEN" ); } - Property* double_property = output->sample().getLogData( std::string("b2v2") ); + Property* double_property = output->run().getLogData( std::string("b2v2") ); TimeSeriesProperty<double> *l_timeSeriesDouble1 = dynamic_cast<TimeSeriesProperty<double>*>(double_property); std::map<dateAndTime,double> vmapb2v2=l_timeSeriesDouble1->valueAsMap(); std::map<dateAndTime,double>::const_iterator vmapb2v2itr; diff --git a/Code/Mantid/DataHandling/test/LoadRaw2Test.h b/Code/Mantid/DataHandling/test/LoadRaw2Test.h index 9285936c429..3d6075cda48 100644 --- a/Code/Mantid/DataHandling/test/LoadRaw2Test.h +++ b/Code/Mantid/DataHandling/test/LoadRaw2Test.h @@ -76,7 +76,7 @@ public: TS_ASSERT( ! output2D-> isDistribution() ) // Check the proton charge has been set correctly - TS_ASSERT_DELTA( output2D->sample().getProtonCharge(), 171.0353, 0.0001 ) + TS_ASSERT_DELTA( output2D->run().getProtonCharge(), 171.0353, 0.0001 ) //---------------------------------------------------------------------- // Tests taken from LoadInstrumentTest to check sub-algorithm is running properly @@ -101,7 +101,7 @@ public: // Test code copied from LoadLogTest to check sub-algorithm is running properly //---------------------------------------------------------------------- // boost::shared_ptr<Sample> sample = output2D->sample(); - Property *l_property = output2D->sample().getLogData( std::string("TEMP1") ); + Property *l_property = output2D->run().getLogData( std::string("TEMP1") ); TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); std::string timeSeriesString = l_timeSeriesDouble->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,23), "2007-Nov-13 15:16:20 0" ); @@ -269,17 +269,20 @@ public: // Check these are the same TS_ASSERT_EQUALS( output1->getInstrument(), output2->getInstrument() ) TS_ASSERT_EQUALS( &(output1->spectraMap()), &(output2->spectraMap()) ) - TS_ASSERT_DIFFERS( &(output1->sample()), &(output2->sample()) ) + TS_ASSERT_EQUALS( &(output1->sample()), &(output2->sample()) ) + TS_ASSERT_DIFFERS( &(output1->run()), &(output2->run()) ) TS_ASSERT_EQUALS( output1->getInstrument(), output6->getInstrument() ) TS_ASSERT_EQUALS( &(output1->spectraMap()), &(output6->spectraMap()) ) - TS_ASSERT_DIFFERS( &(output1->sample()), &(output6->sample()) ) + TS_ASSERT_EQUALS( &(output1->sample()), &(output6->sample()) ) + TS_ASSERT_DIFFERS( &(output1->run()), &(output6->run()) ) + AnalysisDataService::Instance().remove("multiperiod2"); - AnalysisDataService::Instance().remove("multiperiod2_2"); - AnalysisDataService::Instance().remove("multiperiod2_3"); - AnalysisDataService::Instance().remove("multiperiod2_4"); - AnalysisDataService::Instance().remove("multiperiod2_5"); - AnalysisDataService::Instance().remove("multiperiod2_6"); + AnalysisDataService::Instance().remove("multiperiod2_2"); + AnalysisDataService::Instance().remove("multiperiod2_3"); + AnalysisDataService::Instance().remove("multiperiod2_4"); + AnalysisDataService::Instance().remove("multiperiod2_5"); + AnalysisDataService::Instance().remove("multiperiod2_6"); } diff --git a/Code/Mantid/DataHandling/test/LoadRaw3Test.h b/Code/Mantid/DataHandling/test/LoadRaw3Test.h index a3917b72201..69d1fe18df0 100644 --- a/Code/Mantid/DataHandling/test/LoadRaw3Test.h +++ b/Code/Mantid/DataHandling/test/LoadRaw3Test.h @@ -80,7 +80,7 @@ public: TS_ASSERT( ! output2D-> isDistribution() ) // Check the proton charge has been set correctly - TS_ASSERT_DELTA( output2D->sample().getProtonCharge(), 171.0353, 0.0001 ) + TS_ASSERT_DELTA( output2D->run().getProtonCharge(), 171.0353, 0.0001 ) //---------------------------------------------------------------------- //Tests taken from LoadInstrumentTest to check sub-algorithm is running properly @@ -105,12 +105,12 @@ public: // Test code copied from LoadLogTest to check sub-algorithm is running properly //---------------------------------------------------------------------- // boost::shared_ptr<Sample> sample = output2D->getSample(); - Property *l_property = output2D->sample().getLogData( std::string("TEMP1") ); + Property *l_property = output2D->run().getLogData( std::string("TEMP1") ); TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); std::string timeSeriesString = l_timeSeriesDouble->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,23), "2007-Nov-13 15:16:20 0" ); - l_property = output2D->sample().getLogData( "run_number" ); + l_property = output2D->run().getLogData( "run_number" ); TS_ASSERT_EQUALS( l_property->value(), "15869" ); //---------------------------------------------------------------------- @@ -383,13 +383,15 @@ public: TS_ASSERT_EQUALS( outsptr1->getInstrument(), outsptr2->getInstrument() ) TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr2->spectraMap()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr2->sample())) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr3->sample()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr4->sample()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr5->sample()) ) + TS_ASSERT_EQUALS( &(outsptr1->sample()), &(outsptr2->sample()) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr2->run())) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr3->run()) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr4->run()) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr5->run()) ) TS_ASSERT_EQUALS( outsptr1->getInstrument(), outsptr6->getInstrument() ) TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr6->spectraMap()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr6->sample()) ) + TS_ASSERT_EQUALS( &(outsptr1->sample()), &(outsptr6->sample()) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr6->run()) ) itr1=wsNamevec.begin(); for (;itr1!=wsNamevec.end();++itr1) @@ -498,7 +500,7 @@ public: TS_ASSERT( ! output2D-> isDistribution() ) // Check the proton charge has been set correctly - TS_ASSERT_DELTA( output2D->sample().getProtonCharge(), 171.0353, 0.0001 ) + TS_ASSERT_DELTA( output2D->run().getProtonCharge(), 171.0353, 0.0001 ) //---------------------------------------------------------------------- // Tests taken from LoadInstrumentTest to check sub-algorithm is running properly @@ -522,7 +524,7 @@ public: ////---------------------------------------------------------------------- // Test code copied from LoadLogTest to check sub-algorithm is running properly //---------------------------------------------------------------------- - Property *l_property = output2D->sample().getLogData( std::string("TEMP1") ); + Property *l_property = output2D->run().getLogData( std::string("TEMP1") ); TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); std::string timeSeriesString = l_timeSeriesDouble->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,23), "2007-Nov-13 15:16:20 0" ); @@ -628,13 +630,13 @@ public: TS_ASSERT_EQUALS( monoutsptr1->getInstrument(), monoutsptr2->getInstrument() ) TS_ASSERT_EQUALS( &(monoutsptr1->spectraMap()), &(monoutsptr2->spectraMap()) ) - TS_ASSERT_DIFFERS( &(monoutsptr1->sample()), &(monoutsptr2->sample()) ) - TS_ASSERT_DIFFERS( &(monoutsptr1->sample()), &(monoutsptr3->sample()) ) - TS_ASSERT_DIFFERS( &(monoutsptr1->sample()), &(monoutsptr4->sample()) ) - TS_ASSERT_DIFFERS( &(monoutsptr1->sample()), &(monoutsptr5->sample()) ) + TS_ASSERT_DIFFERS( &(monoutsptr1->run()), &(monoutsptr2->run()) ) + TS_ASSERT_DIFFERS( &(monoutsptr1->run()), &(monoutsptr3->run()) ) + TS_ASSERT_DIFFERS( &(monoutsptr1->run()), &(monoutsptr4->run()) ) + TS_ASSERT_DIFFERS( &(monoutsptr1->run()), &(monoutsptr5->run()) ) TS_ASSERT_EQUALS( monoutsptr1->getInstrument(), monoutsptr6->getInstrument() ) TS_ASSERT_EQUALS( &(monoutsptr1->spectraMap()), &(monoutsptr6->spectraMap()) ) - TS_ASSERT_DIFFERS( &(monoutsptr1->sample()), &(monoutsptr6->sample()) ) + TS_ASSERT_DIFFERS( &(monoutsptr1->run()), &(monoutsptr6->run()) ) Workspace_sptr wsSptr=AnalysisDataService::Instance().retrieve("multiperiod"); WorkspaceGroup_sptr sptrWSGrp=boost::dynamic_pointer_cast<WorkspaceGroup>(wsSptr); @@ -686,13 +688,13 @@ public: TS_ASSERT_EQUALS( outsptr1->getInstrument(), outsptr2->getInstrument() ) TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr2->spectraMap()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr2->sample() )) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr3->sample() ) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr4->sample() ) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr5->sample() ) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr2->run() )) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr3->run() ) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr4->run() ) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr5->run() ) ) TS_ASSERT_EQUALS( outsptr1->getInstrument(), outsptr6->getInstrument() ) TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr6->spectraMap()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr6->sample() ) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr6->run() ) ) it=monitorwsNamevec.begin(); for (;it!=monitorwsNamevec.end();++it) diff --git a/Code/Mantid/DataHandling/test/LoadRawBin0Test.h b/Code/Mantid/DataHandling/test/LoadRawBin0Test.h index 442480700eb..5d8ca48d069 100644 --- a/Code/Mantid/DataHandling/test/LoadRawBin0Test.h +++ b/Code/Mantid/DataHandling/test/LoadRawBin0Test.h @@ -78,7 +78,7 @@ public: TS_ASSERT( ! output2D-> isDistribution() ) // Check the proton charge has been set correctly - TS_ASSERT_DELTA( output2D->sample().getProtonCharge(), 171.0353, 0.0001 ) + TS_ASSERT_DELTA( output2D->run().getProtonCharge(), 171.0353, 0.0001 ) AnalysisDataService::Instance().remove(outputSpace); } @@ -141,15 +141,17 @@ public: TS_ASSERT_EQUALS( outsptr1->dataX(1), outsptr6->dataX(1) ) - TS_ASSERT_EQUALS( outsptr1->getInstrument(), outsptr2->getInstrument() ) + TS_ASSERT_EQUALS( outsptr1->getInstrument(), outsptr2->getInstrument() ) TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr2->spectraMap()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr2->sample())) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr3->sample()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr4->sample()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr5->sample()) ) + TS_ASSERT_EQUALS( &(outsptr1->sample()), &(outsptr2->sample())) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr2->run())) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr3->run()) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr4->run()) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr5->run()) ) TS_ASSERT_EQUALS( outsptr1->getInstrument(), outsptr6->getInstrument() ) TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr6->spectraMap()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr6->sample()) ) + TS_ASSERT_EQUALS( &(outsptr1->sample()), &(outsptr6->sample()) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr6->run()) ) itr1=wsNamevec.begin(); for (;itr1!=wsNamevec.end();++itr1) diff --git a/Code/Mantid/DataHandling/test/LoadRawSpectrum0Test.h b/Code/Mantid/DataHandling/test/LoadRawSpectrum0Test.h index 2c3d1e7e2a9..f666d8446ab 100644 --- a/Code/Mantid/DataHandling/test/LoadRawSpectrum0Test.h +++ b/Code/Mantid/DataHandling/test/LoadRawSpectrum0Test.h @@ -79,7 +79,7 @@ public: TS_ASSERT( ! output2D-> isDistribution() ) // Check the proton charge has been set correctly - TS_ASSERT_DELTA( output2D->sample().getProtonCharge(), 171.0353, 0.0001 ) + TS_ASSERT_DELTA( output2D->run().getProtonCharge(), 171.0353, 0.0001 ) AnalysisDataService::Instance().remove(outputSpace); } @@ -149,18 +149,19 @@ public: TS_ASSERT_EQUALS( outsptr1->getInstrument(), outsptr2->getInstrument() ) TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr2->spectraMap()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr2->sample())) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr3->sample()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr4->sample()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr5->sample()) ) + TS_ASSERT_EQUALS( &(outsptr1->sample()), &(outsptr2->sample())) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr2->run())) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr3->run()) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr4->run()) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr5->run()) ) TS_ASSERT_EQUALS( outsptr1->getInstrument(), outsptr6->getInstrument() ) TS_ASSERT_EQUALS( &(outsptr1->spectraMap()), &(outsptr6->spectraMap()) ) - TS_ASSERT_DIFFERS( &(outsptr1->sample()), &(outsptr6->sample()) ) + TS_ASSERT_DIFFERS( &(outsptr1->run()), &(outsptr6->run()) ) } private: - LoadRawSpectrum0 loader;//,loader2,loader3; + LoadRawSpectrum0 loader; std::string inputFile; std::string outputSpace; }; diff --git a/Code/Mantid/DataHandling/test/LoadRawTest.h b/Code/Mantid/DataHandling/test/LoadRawTest.h index 1ef912c7f80..e5aaf58b3e2 100644 --- a/Code/Mantid/DataHandling/test/LoadRawTest.h +++ b/Code/Mantid/DataHandling/test/LoadRawTest.h @@ -77,7 +77,7 @@ public: TS_ASSERT( ! output2D-> isDistribution() ) // Check the proton charge has been set correctly - TS_ASSERT_DELTA( output2D->sample().getProtonCharge(), 171.0353, 0.0001 ) + TS_ASSERT_DELTA( output2D->run().getProtonCharge(), 171.0353, 0.0001 ) //---------------------------------------------------------------------- // Tests taken from LoadInstrumentTest to check sub-algorithm is running properly @@ -102,7 +102,7 @@ public: // Test code copied from LoadLogTest to check sub-algorithm is running properly //---------------------------------------------------------------------- //boost::shared_ptr<Sample> sample = output2D->getSample(); - Property *l_property = output2D->sample().getLogData( std::string("TEMP1") ); + Property *l_property = output2D->run().getLogData( std::string("TEMP1") ); TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); std::string timeSeriesString = l_timeSeriesDouble->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,23), "2007-Nov-13 15:16:20 0" ); @@ -302,7 +302,7 @@ public: // Check these are the same TS_ASSERT_EQUALS( output1->getInstrument(), output2->getInstrument() ) TS_ASSERT_EQUALS( &(output1->spectraMap()), &(output2->spectraMap()) ) - TS_ASSERT_EQUALS( output1->sample().getProtonCharge(), output2->sample().getProtonCharge() ) + TS_ASSERT_EQUALS( output1->run().getProtonCharge(), output2->run().getProtonCharge() ) TS_ASSERT_EQUALS( output1->sample().getGeometryFlag(), output2->sample().getGeometryFlag() ) TS_ASSERT_EQUALS( output1->sample().getThickness(), output2->sample().getThickness() ) TS_ASSERT_EQUALS( output1->sample().getHeight(), output2->sample().getHeight() ) @@ -310,7 +310,7 @@ public: TS_ASSERT_EQUALS( output1->getInstrument(), output6->getInstrument() ) TS_ASSERT_EQUALS( &(output1->spectraMap()), &(output6->spectraMap()) ) - TS_ASSERT_EQUALS( output1->sample().getProtonCharge(), output6->sample().getProtonCharge() ) + TS_ASSERT_EQUALS( output1->run().getProtonCharge(), output6->run().getProtonCharge() ) TS_ASSERT_EQUALS( output1->sample().getGeometryFlag(), output6->sample().getGeometryFlag() ) TS_ASSERT_EQUALS( output1->sample().getThickness(), output6->sample().getThickness() ) TS_ASSERT_EQUALS( output1->sample().getHeight(), output6->sample().getHeight() ) @@ -318,7 +318,7 @@ public: TS_ASSERT_EQUALS( output1->getInstrument(), output12->getInstrument() ) TS_ASSERT_EQUALS( &(output1->spectraMap()), &(output12->spectraMap()) ) - TS_ASSERT_EQUALS( output1->sample().getProtonCharge(), output12->sample().getProtonCharge() ) + TS_ASSERT_EQUALS( output1->run().getProtonCharge(), output12->run().getProtonCharge() ) TS_ASSERT_EQUALS( output1->sample().getGeometryFlag(), output12->sample().getGeometryFlag() ) TS_ASSERT_EQUALS( output1->sample().getThickness(), output12->sample().getThickness() ) TS_ASSERT_EQUALS( output1->sample().getHeight(), output12->sample().getHeight() ) diff --git a/Code/Mantid/DataHandling/test/ManagedRawFileWorkspace2DTest.h b/Code/Mantid/DataHandling/test/ManagedRawFileWorkspace2DTest.h index a8f078324e7..2a8cdd68f16 100644 --- a/Code/Mantid/DataHandling/test/ManagedRawFileWorkspace2DTest.h +++ b/Code/Mantid/DataHandling/test/ManagedRawFileWorkspace2DTest.h @@ -136,7 +136,7 @@ public: TS_ASSERT( ! output2D-> isDistribution() ) // Check the proton charge has been set correctly - TS_ASSERT_DELTA( output2D->sample().getProtonCharge(), 171.0353, 0.0001 ) + TS_ASSERT_DELTA( output2D->run().getProtonCharge(), 171.0353, 0.0001 ) //---------------------------------------------------------------------- // Tests taken from LoadInstrumentTest to check sub-algorithm is running properly @@ -161,7 +161,7 @@ public: // Test code copied from LoadLogTest to check sub-algorithm is running properly //---------------------------------------------------------------------- // boost::shared_ptr<Sample> sample = output2D->getSample(); - Property *l_property = output2D->sample().getLogData( std::string("TEMP1") ); + Property *l_property = output2D->run().getLogData( std::string("TEMP1") ); TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); std::string timeSeriesString = l_timeSeriesDouble->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,23), "2007-Nov-13 15:16:20 0" ); diff --git a/Code/Mantid/DataHandling/test/SaveCanSAS1dTest.h b/Code/Mantid/DataHandling/test/SaveCanSAS1dTest.h index 1f4c1561fb9..e966848998a 100644 --- a/Code/Mantid/DataHandling/test/SaveCanSAS1dTest.h +++ b/Code/Mantid/DataHandling/test/SaveCanSAS1dTest.h @@ -117,16 +117,7 @@ public: remove(m_filename.c_str()); } - -// testing of searchandreplaceSpecialChars is done. - //I made this method public and tested,changed back to private. - /* void xtestspecialcharacters() - { - SaveCanSAS1D savealg; - std::string input="sasdjksd<aw&gjkjk\"j"; - savealg.searchandreplaceSpecialChars(input); - }*/ - private : +private : const std::string m_rawoutws, m_filename; std::string m_runNum; MatrixWorkspace_sptr ws; diff --git a/Code/Mantid/DataObjects/inc/MantidDataObjects/EventWorkspace.h b/Code/Mantid/DataObjects/inc/MantidDataObjects/EventWorkspace.h index 80d646d8d87..c4cd960fca2 100644 --- a/Code/Mantid/DataObjects/inc/MantidDataObjects/EventWorkspace.h +++ b/Code/Mantid/DataObjects/inc/MantidDataObjects/EventWorkspace.h @@ -132,7 +132,7 @@ class DLLExport EventWorkspace : public API::MatrixWorkspace int blocksize() const; /// Get the number of histograms. aka the number of pixels or detectors. - const int getNumberHistograms() const; + int getNumberHistograms() const; long int getMemorySize() const; @@ -196,7 +196,7 @@ class DLLExport EventWorkspace : public API::MatrixWorkspace std::size_t getNumberEvents() const; /// Returns true always - an EventWorkspace always represents histogramm-able data - virtual const bool isHistogramData() const; + virtual bool isHistogramData() const; int MRUSize() const; diff --git a/Code/Mantid/DataObjects/inc/MantidDataObjects/Workspace1D.h b/Code/Mantid/DataObjects/inc/MantidDataObjects/Workspace1D.h index fc24d682a21..c162b10d14c 100644 --- a/Code/Mantid/DataObjects/inc/MantidDataObjects/Workspace1D.h +++ b/Code/Mantid/DataObjects/inc/MantidDataObjects/Workspace1D.h @@ -63,7 +63,7 @@ public: virtual int blocksize() const; ///Returns the number of histgrams - always 1 in this case - const int getNumberHistograms() const { return 1; } + int getNumberHistograms() const { return 1; } //inheritance redirections // Reimplemented these Histogram1D methods simply to hide the other ones diff --git a/Code/Mantid/DataObjects/inc/MantidDataObjects/Workspace2D.h b/Code/Mantid/DataObjects/inc/MantidDataObjects/Workspace2D.h index ca24d6c0406..0264c7dfd88 100644 --- a/Code/Mantid/DataObjects/inc/MantidDataObjects/Workspace2D.h +++ b/Code/Mantid/DataObjects/inc/MantidDataObjects/Workspace2D.h @@ -73,7 +73,7 @@ public: virtual void setData(int const, const Histogram1D::RCtype::ptr_type&, const Histogram1D::RCtype::ptr_type&); /// Returns the histogram number - const int getNumberHistograms() const; + int getNumberHistograms() const; //section required for iteration virtual int size() const; diff --git a/Code/Mantid/DataObjects/inc/MantidDataObjects/WorkspaceSingleValue.h b/Code/Mantid/DataObjects/inc/MantidDataObjects/WorkspaceSingleValue.h index a88894a638a..667d6cbd877 100644 --- a/Code/Mantid/DataObjects/inc/MantidDataObjects/WorkspaceSingleValue.h +++ b/Code/Mantid/DataObjects/inc/MantidDataObjects/WorkspaceSingleValue.h @@ -70,7 +70,7 @@ public: virtual int blocksize() const { return 1; } - const int getNumberHistograms() const + int getNumberHistograms() const { return 1; } //inheritance redirections diff --git a/Code/Mantid/DataObjects/src/EventWorkspace.cpp b/Code/Mantid/DataObjects/src/EventWorkspace.cpp index ce00910d814..a46ee5c3a64 100644 --- a/Code/Mantid/DataObjects/src/EventWorkspace.cpp +++ b/Code/Mantid/DataObjects/src/EventWorkspace.cpp @@ -104,7 +104,7 @@ using Kernel::Exception::NotImplementedError; /** Get the number of histograms, usually the same as the number of pixels or detectors. @returns the number of histograms / event lists */ - const int EventWorkspace::getNumberHistograms() const + int EventWorkspace::getNumberHistograms() const { return this->data.size(); } @@ -125,7 +125,7 @@ using Kernel::Exception::NotImplementedError; //----------------------------------------------------------------------------- /// Returns true always - an EventWorkspace always represents histogramm-able data /// @returns If the data is a histogtram - always true for an eventWorkspace - const bool EventWorkspace::isHistogramData() const + bool EventWorkspace::isHistogramData() const { return true; } diff --git a/Code/Mantid/DataObjects/src/Workspace2D.cpp b/Code/Mantid/DataObjects/src/Workspace2D.cpp index f80cde4b62c..fcbdd80204c 100644 --- a/Code/Mantid/DataObjects/src/Workspace2D.cpp +++ b/Code/Mantid/DataObjects/src/Workspace2D.cpp @@ -133,7 +133,7 @@ namespace Mantid /** Gets the number of histograms \return Integer */ - const int + int Workspace2D::getNumberHistograms() const { return getHistogramNumberHelper(); diff --git a/Code/Mantid/Geometry/inc/MantidGeometry/IComponent.h b/Code/Mantid/Geometry/inc/MantidGeometry/IComponent.h index 1ca99902cfa..67a1172a443 100644 --- a/Code/Mantid/Geometry/inc/MantidGeometry/IComponent.h +++ b/Code/Mantid/Geometry/inc/MantidGeometry/IComponent.h @@ -64,7 +64,7 @@ public: /// Destructor virtual ~IComponent(){} //! Returns the ComponentID - a unique identifier of the component. - virtual const ComponentID getComponentID()const = 0; + virtual ComponentID getComponentID()const = 0; //! Assign a parent IComponent. Previous parent link is lost virtual void setParent(IComponent*)= 0; //! Return a pointer to the current parent. diff --git a/Code/Mantid/Geometry/inc/MantidGeometry/Instrument/Component.h b/Code/Mantid/Geometry/inc/MantidGeometry/Instrument/Component.h index cc41e347e1d..f2adccff0a8 100644 --- a/Code/Mantid/Geometry/inc/MantidGeometry/Instrument/Component.h +++ b/Code/Mantid/Geometry/inc/MantidGeometry/Instrument/Component.h @@ -74,7 +74,7 @@ public: /// Destructor virtual ~Component(); //! Returns the ComponentID - a unique identifier of the component. - const ComponentID getComponentID()const; + ComponentID getComponentID()const; //! Assign a parent component. Previous parent link is lost void setParent(IComponent*); //! Return a pointer to the current parent. diff --git a/Code/Mantid/Geometry/inc/MantidGeometry/Instrument/DetectorGroup.h b/Code/Mantid/Geometry/inc/MantidGeometry/Instrument/DetectorGroup.h index 1ed78f0b00e..45507a85943 100644 --- a/Code/Mantid/Geometry/inc/MantidGeometry/Instrument/DetectorGroup.h +++ b/Code/Mantid/Geometry/inc/MantidGeometry/Instrument/DetectorGroup.h @@ -122,7 +122,7 @@ private: // functions inherited from IComponent Component* clone() const{ return NULL; } - const ComponentID getComponentID(void) const{ return NULL; } + ComponentID getComponentID(void) const{ return NULL; } boost::shared_ptr<const IComponent> getParent() const { return boost::shared_ptr<const IComponent>(); diff --git a/Code/Mantid/Geometry/inc/MantidGeometry/Instrument/ParametrizedComponent.h b/Code/Mantid/Geometry/inc/MantidGeometry/Instrument/ParametrizedComponent.h index 50c794e997e..554c248ba53 100644 --- a/Code/Mantid/Geometry/inc/MantidGeometry/Instrument/ParametrizedComponent.h +++ b/Code/Mantid/Geometry/inc/MantidGeometry/Instrument/ParametrizedComponent.h @@ -63,7 +63,7 @@ public: IComponent* clone() const; //! Returns the ComponentID - a unique identifier of the component. - const ComponentID getComponentID()const; + ComponentID getComponentID()const; //! Assign a parent IComponent. Previous parent link is lost void setParent(IComponent*); diff --git a/Code/Mantid/Geometry/src/Instrument/Component.cpp b/Code/Mantid/Geometry/src/Instrument/Component.cpp index e11ad3609b9..91db542ceb8 100644 --- a/Code/Mantid/Geometry/src/Instrument/Component.cpp +++ b/Code/Mantid/Geometry/src/Instrument/Component.cpp @@ -71,7 +71,7 @@ IComponent* Component::clone() const /*! Get the component's ID * @return ID */ -const ComponentID Component::getComponentID()const +ComponentID Component::getComponentID()const { return ComponentID((const IComponent*)(this)); } diff --git a/Code/Mantid/Geometry/src/Instrument/ParametrizedComponent.cpp b/Code/Mantid/Geometry/src/Instrument/ParametrizedComponent.cpp index b6474685226..8e6c9dc79e9 100644 --- a/Code/Mantid/Geometry/src/Instrument/ParametrizedComponent.cpp +++ b/Code/Mantid/Geometry/src/Instrument/ParametrizedComponent.cpp @@ -33,7 +33,7 @@ namespace Mantid /*! Get the component's ID * @return ID */ - const ComponentID ParametrizedComponent::getComponentID()const + ComponentID ParametrizedComponent::getComponentID()const { return ComponentID(m_base); } diff --git a/Code/Mantid/Kernel/inc/MantidKernel/ConfigService.h b/Code/Mantid/Kernel/inc/MantidKernel/ConfigService.h index 04e8ebb5afd..a5c19117948 100644 --- a/Code/Mantid/Kernel/inc/MantidKernel/ConfigService.h +++ b/Code/Mantid/Kernel/inc/MantidKernel/ConfigService.h @@ -119,7 +119,7 @@ namespace Mantid // Starts up the logging void configureLogging(); /// Provies a string of a default configuration - const std::string defaultConfig() const; + std::string defaultConfig() const; /// Writes out a fresh user properties file void createUserPropertiesFile() const; /// Convert any relative paths to absolute ones and store them locally so that diff --git a/Code/Mantid/Kernel/inc/MantidKernel/Property.h b/Code/Mantid/Kernel/inc/MantidKernel/Property.h index 89cc7163c8b..78ac490d1fa 100644 --- a/Code/Mantid/Kernel/inc/MantidKernel/Property.h +++ b/Code/Mantid/Kernel/inc/MantidKernel/Property.h @@ -112,7 +112,7 @@ public: virtual const PropertyHistory createHistory() const; /// returns the direction of the property - const unsigned int direction() const + unsigned int direction() const { return m_direction; } diff --git a/Code/Mantid/Kernel/inc/MantidKernel/PropertyWithValue.h b/Code/Mantid/Kernel/inc/MantidKernel/PropertyWithValue.h index 708cd330607..0492d011915 100644 --- a/Code/Mantid/Kernel/inc/MantidKernel/PropertyWithValue.h +++ b/Code/Mantid/Kernel/inc/MantidKernel/PropertyWithValue.h @@ -113,7 +113,7 @@ void toValue(const std::string& strvalue, T& value) } template <typename T> -void toValue(const std::string& strvalue, boost::shared_ptr<T>& value) +void toValue(const std::string&, boost::shared_ptr<T>&) { throw boost::bad_lexical_cast(); } diff --git a/Code/Mantid/Kernel/src/ConfigService.cpp b/Code/Mantid/Kernel/src/ConfigService.cpp index 0c727b8ff4f..ece7f4da919 100644 --- a/Code/Mantid/Kernel/src/ConfigService.cpp +++ b/Code/Mantid/Kernel/src/ConfigService.cpp @@ -485,7 +485,7 @@ namespace Kernel * Provides a default Configuration string to use if the config file cannot be loaded. * @returns The string value of default properties */ - const std::string ConfigServiceImpl::defaultConfig() const + std::string ConfigServiceImpl::defaultConfig() const { std::string propFile = "# logging configuration" diff --git a/Code/Mantid/Kernel/src/Property.cpp b/Code/Mantid/Kernel/src/Property.cpp index bf86cf08b43..6a9759489c0 100644 --- a/Code/Mantid/Kernel/src/Property.cpp +++ b/Code/Mantid/Kernel/src/Property.cpp @@ -42,6 +42,7 @@ Property::~Property() */ Property& Property::operator=( const Property& right ) { + (void)right; // Get rid of compiler warning but we need the argument for doxygen return *this; } diff --git a/Code/Mantid/Kernel/src/SupportBasic.cpp b/Code/Mantid/Kernel/src/SupportBasic.cpp index 60820d8f4b7..fc0cf8e0a4b 100644 --- a/Code/Mantid/Kernel/src/SupportBasic.cpp +++ b/Code/Mantid/Kernel/src/SupportBasic.cpp @@ -85,7 +85,9 @@ int extractWord(std::string& Line,const std::string& Word,const int cnt) // Pos == Start of find unsigned int LinePt=minSize+pos; for(;minSize<Word.size() && LinePt<Line.size() - && Word[minSize]==Line[LinePt];LinePt++,minSize++); + && Word[minSize]==Line[LinePt];LinePt++,minSize++) + { + } Line.erase(pos,LinePt-(pos-1)); return 1; diff --git a/Code/Mantid/Nexus/inc/MantidNexus/LoadISISNexus2.h b/Code/Mantid/Nexus/inc/MantidNexus/LoadISISNexus2.h index eee7cb1fb55..5c741a4aaf5 100644 --- a/Code/Mantid/Nexus/inc/MantidNexus/LoadISISNexus2.h +++ b/Code/Mantid/Nexus/inc/MantidNexus/LoadISISNexus2.h @@ -5,7 +5,6 @@ // Includes //---------------------------------------------------------------------- #include "MantidAPI/Algorithm.h" -#include "MantidAPI/Sample.h" #include "MantidDataObjects/Workspace2D.h" #include "MantidNexus/NexusClasses.h" #include <climits> @@ -83,6 +82,8 @@ namespace Mantid void checkOptionalProperties(); /// Run LoadInstrument as a subalgorithm void runLoadInstrument(DataObjects::Workspace2D_sptr); + /// Load in details about the run + void loadRunDetails(DataObjects::Workspace2D_sptr local_workspace, NXEntry & entry); /// Load in details about the sample void loadSampleData(DataObjects::Workspace2D_sptr, NXEntry & entry); /// Load log data from the nexus file diff --git a/Code/Mantid/Nexus/inc/MantidNexus/LoadSNSNexus.h b/Code/Mantid/Nexus/inc/MantidNexus/LoadSNSNexus.h index 86e67157926..172e5de81ec 100644 --- a/Code/Mantid/Nexus/inc/MantidNexus/LoadSNSNexus.h +++ b/Code/Mantid/Nexus/inc/MantidNexus/LoadSNSNexus.h @@ -5,7 +5,6 @@ // Includes //---------------------------------------------------------------------- #include "MantidAPI/Algorithm.h" -#include "MantidAPI/Sample.h" #include "MantidDataObjects/Workspace2D.h" #include "MantidNexus/NexusClasses.h" diff --git a/Code/Mantid/Nexus/inc/MantidNexus/NexusFileIO.h b/Code/Mantid/Nexus/inc/MantidNexus/NexusFileIO.h index 4a0349e061c..f0bf1fc0998 100644 --- a/Code/Mantid/Nexus/inc/MantidNexus/NexusFileIO.h +++ b/Code/Mantid/Nexus/inc/MantidNexus/NexusFileIO.h @@ -1,7 +1,7 @@ #ifndef NEXUSFILEIO_H #define NEXUSFILEIO_H #include <napi.h> -#include "MantidDataObjects/Workspace2D.h" +#include "MantidAPI/MatrixWorkspace.h" #include "MantidKernel/TimeSeriesProperty.h" #include <boost/date_time/posix_time/posix_time.hpp> #include "boost/date_time/local_time_adjustor.hpp" @@ -50,23 +50,19 @@ namespace Mantid /// open the nexus file for writing int openNexusWrite(const std::string& fileName); - /// open the nexus file for reading - int openNexusRead(const std::string& fileName, int& workspaceNumber); /// write the header ifon for the Mantid workspace format int writeNexusProcessedHeader( const std::string& title); - /// write sample related data /// close the nexus file int closeNexusFile(); - - int writeNexusProcessedSample( const std::string& title,const Mantid::API::Sample& sample); - /// read sample data - int readNexusProcessedSample(Mantid::API::Sample& sample); + /// Write a Nexus sample section + int writeNexusProcessedSample( const std::string& title, const API::Sample & sample, + const Mantid::API::Run& runProperties); /// write the workspace data int writeNexusProcessedData( const API::MatrixWorkspace_const_sptr& localworkspace, - const bool& uniformSpectra, const std::vector<int>& spec); + const bool& uniformSpectra, const std::vector<int>& spec); /// find size of open entry data section int getWorkspaceSize( int& numberOfSpectra, int& numberOfChannels, int& numberOfXpoints , - bool& uniformBounds, std::string& axesNames, std::string& yUnits ); + bool& uniformBounds, std::string& axesNames, std::string& yUnits ); /// read X values for one (or the generic if uniform) spectra int getXValues(MantidVec& xValues, const int& spectra); /// read values and errors for spectra @@ -77,19 +73,10 @@ namespace Mantid /// write the source XML file used, if it exists bool writeNexusInstrumentXmlName(const std::string& instrumentXml,const std::string& date, const std::string& version); - /// read the source XML file used - bool readNexusInstrumentXmlName(std::string& instrumentXml,std::string& date, - std::string& version); - /// read the source XML file used - std::string readNexusInstrumentName(); /// write an instrument section - currently only the name bool writeNexusInstrument(const API::IInstrument_const_sptr& instrument); /// write any spectra map information to Nexus file bool writeNexusProcessedSpectraMap(const API::MatrixWorkspace_const_sptr& localWorkspace, const std::vector<int>& spec); - /// read spectra map information - bool readNexusProcessedSpectraMap(API::MatrixWorkspace_sptr localWorkspace); - /// Read the vertical axis (axis(1)) values - bool readNexusProcessedAxis(API::MatrixWorkspace_sptr localWorkspace); /// write instrument parameters bool writeNexusParameterMap(API::MatrixWorkspace_const_sptr ws); /// read instrument parameters @@ -107,18 +94,12 @@ namespace Mantid /// write a text value plus possible attribute bool writeNxText( const std::string& name, const std::string& value, const std::vector<std::string>& attributes, const std::vector<std::string>& avalues); - /// read a text value plus possible attribute - bool readNxText(const std::string& name, std::string& value, std::vector<std::string>& attributes, - std::vector<std::string>& avalues); /// write an NXnote with standard fields (but NX_CHAR rather than NX_BINARY data) bool writeNxNote(const std::string& noteName, const std::string& author, const std::string& date, const std::string& description, const std::string& pairValues); /// write a flost value plus possible attributes bool writeNxFloat(const std::string& name, const double& value, const std::vector<std::string>& attributes, const std::vector<std::string>& avalues); - /// read a float value and possible attributes - bool readNxFloat(const std::string& name, double& value, std::vector<std::string>& attributes, - std::vector<std::string>& avalues); /// write a float array along with any defined attributes bool writeNxFloatArray(const std::string& name, const std::vector<double>& values, const std::vector<std::string>& attributes, const std::vector<std::string>& avalues); @@ -129,8 +110,6 @@ namespace Mantid void writeNexusDoubleLog(const Kernel::TimeSeriesProperty<double> *d_timeSeries); /// Write NXlog data for given string TimeSeriesProperty void writeNexusStringLog(const Kernel::TimeSeriesProperty<std::string> *s_timeSeries); - /// read the named NXlog and create TimeSeriesProp in sample - void readNXlog(const char* nxname, Mantid::API::Sample& sample); /// check if the gievn item exists in the current level bool checkEntryAtLevel(const std::string& item) const; /// check if given attribute name is in currently opened entry diff --git a/Code/Mantid/Nexus/inc/MantidNexus/NexusFileWriter.h b/Code/Mantid/Nexus/inc/MantidNexus/NexusFileWriter.h deleted file mode 100644 index 4684e12762d..00000000000 --- a/Code/Mantid/Nexus/inc/MantidNexus/NexusFileWriter.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef NEXUSFILEWRITER_H -#define NEXUSFILEWRITER_H -#include <napi.h> -#include "MantidDataObjects/Workspace2D.h" -namespace Mantid -{ - namespace NeXus - { - /** @class NexusFileWriter NexusFileWriter.h NeXus/NexusFileWriter.h - - Utility method for saving NeXus format of Mantid Workspace - THIS CODE IS NOT USED - replaced by NexusFileIO - - Copyright © 2007-8 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory - - 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://svn.mantidproject.org/mantid/trunk/Code/Mantid>. - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - class DLLExport NexusFileWriter - { - public: - /// Default constructor - NexusFileWriter(); - - /// Destructor - ~NexusFileWriter() {} - - /// open the nexus file - int openNexusWrite(const std::string& fileName, const std::string& entryName); - /// write the header ifon for the Mantid workspace format - int writeNexusProcessedHeader( const std::string& entryName, const std::string& title); - /// write sample related data - int writeNexusProcessedSample( const std::string& entryName, const std::string& title, - const boost::shared_ptr<Mantid::API::Sample> sample); - /// write the workspace data - int writeNexusProcessedData( const std::string& entryName, - const boost::shared_ptr<Mantid::DataObjects::Workspace2D> localworkspace, - const bool uniformSpectra, const int fromY, const int toY); - /// write the algorithm and environment information - int writeNexusProcessedProcess(const boost::shared_ptr<Mantid::DataObjects::Workspace2D> localworkspace); - /// write the source XML file used, if it exists - bool writeNexusInstrumentXmlName(const std::string& instrumentXml,const std::string& date, - const std::string& version); - /// write an instrument section - currently only the name - bool writeNexusInstrument(const boost::shared_ptr<API::Instrument>& instrument); - /// close the nexus file - int closeNexusFile(); - - private: - /// Nexus file handle - NXhandle fileID; - /// Nexus format to use for writing - NXaccess m_nexusformat; - /// Nexus compression method - int m_nexuscompression; - /// write a text value plus possible attribute - bool writeNxText(NXhandle fileID, std::string name, std::string value, std::vector<std::string> attributes, - std::vector<std::string> avalues); - /// write an NXnote with standard fields (but NX_CHAR rather than NX_BINARY data) - bool writeNxNote(const std::string& noteName, const std::string& author, const std::string& date, - const std::string& description, const std::string& pairValues); - /// write a flost value plus possible attributes - bool writeNxFloat(const std::string name, const double& value, const std::vector<std::string> attributes, - const std::vector<std::string> avalues); - /// write test field - int writeNexusTextField( const NXhandle& h, const std::string& name, const std::string& value); - /// search for exisiting MantidWorkpace_n entries in opened file - int findMantidWSEntries(); - /// nexus file name - std::string m_filename; - ///static reference to the logger class - static Kernel::Logger& g_log; - - }; - - } // namespace NeXus -} // namespace Mantid - -#endif /* NEXUSFILEWRITER_H */ diff --git a/Code/Mantid/Nexus/src/LoadISISNexus.cpp b/Code/Mantid/Nexus/src/LoadISISNexus.cpp index 5724be36f4e..07adeb167bc 100644 --- a/Code/Mantid/Nexus/src/LoadISISNexus.cpp +++ b/Code/Mantid/Nexus/src/LoadISISNexus.cpp @@ -580,7 +580,7 @@ namespace Mantid openNexusData("proton_charge"); { getNexusData(&m_proton_charge); - ws->mutableSample().setProtonCharge(m_proton_charge); + ws->mutableRun().setProtonCharge(m_proton_charge); } closeNexusData(); @@ -650,13 +650,13 @@ namespace Mantid *(value.get()+(i+1)*vinfo.dims[1]-1) = 0; // ensure the terminating zero logv->addValue(t,std::string(value.get()+i*vinfo.dims[1])); } - ws->mutableSample().addLogData(logv); + ws->mutableRun().addLogData(logv); if (std::string(nxname.get()) == "icp_event") { LogParser parser(logv); - ws->mutableSample().addLogData(parser.createPeriodLog(period)); - ws->mutableSample().addLogData(parser.createAllPeriodsLog()); - ws->mutableSample().addLogData(parser.createRunningLog()); + ws->mutableRun().addLogData(parser.createPeriodLog(period)); + ws->mutableRun().addLogData(parser.createAllPeriodsLog()); + ws->mutableRun().addLogData(parser.createRunningLog()); } } else if (vinfo.type == NX_FLOAT32) @@ -669,7 +669,7 @@ namespace Mantid time_t t = start_t + int(times[i]); logv->addValue(t,value[i]); } - ws->mutableSample().addLogData(logv); + ws->mutableRun().addLogData(logv); } else if (vinfo.type == NX_INT32) { @@ -681,7 +681,7 @@ namespace Mantid time_t t = start_t + int(times[i]); logv->addValue(t,value[i]); } - ws->mutableSample().addLogData(logv); + ws->mutableRun().addLogData(logv); } else { diff --git a/Code/Mantid/Nexus/src/LoadISISNexus2.cpp b/Code/Mantid/Nexus/src/LoadISISNexus2.cpp index b867af7dfde..3e7b5e1baba 100644 --- a/Code/Mantid/Nexus/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Nexus/src/LoadISISNexus2.cpp @@ -198,6 +198,7 @@ namespace Mantid runLoadInstrument(local_workspace); local_workspace->mutableSpectraMap().populate(spec(),udet(),udet.dim0()); + loadRunDetails(local_workspace, entry); loadSampleData(local_workspace, entry); m_progress->report("Loading logs"); loadLogs(local_workspace, entry); @@ -548,6 +549,20 @@ namespace Mantid // runLoadInstrumentFromNexus(localWorkspace); //} } + + /** + * Load data about the run + * @param local_workspace The workspace to load the run information in to + * @param entry The Nexus entry + */ + void LoadISISNexus2::loadRunDetails(DataObjects::Workspace2D_sptr local_workspace, NXEntry & entry) + { + API::Run & run = local_workspace->mutableRun(); + run.setProtonCharge(entry.getFloat("proton_charge")); + + std::string run_num = boost::lexical_cast<std::string>(entry.getInt("run_number")); + run.addLogData(new PropertyWithValue<std::string>("run_number", run_num)); + } /** * Load data about the sample @@ -556,15 +571,6 @@ namespace Mantid */ void LoadISISNexus2::loadSampleData(DataObjects::Workspace2D_sptr local_workspace, NXEntry & entry) { - Sample &sampleDets = local_workspace->mutableSample(); - sampleDets.setProtonCharge(entry.getFloat("proton_charge")); - - std::string runDet = - boost::lexical_cast<std::string>(entry.getInt("run_number")); - //The sample is left to delete the property - sampleDets.addLogData( - new PropertyWithValue<std::string>("run_number", runDet)); - /// Sample geometry NXInt spb = entry.openNXInt("isis_vms_compat/SPB"); // Just load the index we need, not the whole block. The flag is the third value in @@ -609,13 +615,13 @@ namespace Mantid nxLog.close(); continue; } - ws->mutableSample().addLogData(logv); + ws->mutableRun().addLogData(logv); if (it->nxname == "icp_event") { LogParser parser(logv); - ws->mutableSample().addLogData(parser.createPeriodLog(period)); - ws->mutableSample().addLogData(parser.createAllPeriodsLog()); - ws->mutableSample().addLogData(parser.createRunningLog()); + ws->mutableRun().addLogData(parser.createPeriodLog(period)); + ws->mutableRun().addLogData(parser.createAllPeriodsLog()); + ws->mutableRun().addLogData(parser.createRunningLog()); } nxLog.close(); } @@ -640,7 +646,7 @@ namespace Mantid selog.close(); continue; } - ws->mutableSample().addLogData(logv); + ws->mutableRun().addLogData(logv); nxLog.close(); } selog.close(); diff --git a/Code/Mantid/Nexus/src/LoadMuonLog.cpp b/Code/Mantid/Nexus/src/LoadMuonLog.cpp index 09060a1ad72..2de06fa0c78 100644 --- a/Code/Mantid/Nexus/src/LoadMuonLog.cpp +++ b/Code/Mantid/Nexus/src/LoadMuonLog.cpp @@ -64,7 +64,6 @@ void LoadMuonLog::exec() // Also set the sample name at this point, as part of the sample related log data. const MatrixWorkspace_sptr localWorkspace = getProperty("Workspace"); - // boost::shared_ptr<API::Sample> sample = localWorkspace->getSample(); localWorkspace->mutableSample().setName(nxload.getSampleName()); // Attempt to load the content of each NXlog section into the Sample object @@ -105,12 +104,12 @@ void LoadMuonLog::exec() // store Property in Sample object and delete unused object if ( nxload.logTypeNumeric(i) ) { - localWorkspace->mutableSample().addLogData(l_PropertyDouble); + localWorkspace->mutableRun().addLogData(l_PropertyDouble); delete l_PropertyString; } else { - localWorkspace->mutableSample().addLogData(l_PropertyString); + localWorkspace->mutableRun().addLogData(l_PropertyString); delete l_PropertyDouble; } prog.report(); diff --git a/Code/Mantid/Nexus/src/LoadMuonNexus.cpp b/Code/Mantid/Nexus/src/LoadMuonNexus.cpp index 0d9aab13801..0607bd77256 100644 --- a/Code/Mantid/Nexus/src/LoadMuonNexus.cpp +++ b/Code/Mantid/Nexus/src/LoadMuonNexus.cpp @@ -565,17 +565,15 @@ namespace Mantid { Kernel::TimeSeriesProperty<double>* p = new Kernel::TimeSeriesProperty<double>("fromNexus"); p->addValue(start_time(),-90.); - localWorkspace->mutableSample().addLogData(p); + localWorkspace->mutableRun().addLogData(p); } - NXEntry run = root.openEntry("run"); - localWorkspace->setTitle(run.getString("title")); + NXEntry nxRun = root.openEntry("run"); + localWorkspace->setTitle(nxRun.getString("title")); - std::string runDet = - boost::lexical_cast<std::string>(run.getInt("number")); + std::string run_num = boost::lexical_cast<std::string>(nxRun.getInt("number")); //The sample is left to delete the property - localWorkspace->mutableSample().addLogData( - new PropertyWithValue<std::string>("run_number", runDet)); + localWorkspace->mutableRun().addLogData(new PropertyWithValue<std::string>("run_number", run_num)); } diff --git a/Code/Mantid/Nexus/src/LoadMuonNexus2.cpp b/Code/Mantid/Nexus/src/LoadMuonNexus2.cpp index f9c31af5602..1ff3fc19007 100644 --- a/Code/Mantid/Nexus/src/LoadMuonNexus2.cpp +++ b/Code/Mantid/Nexus/src/LoadMuonNexus2.cpp @@ -283,16 +283,14 @@ namespace Mantid NXLog nxLog = runlogs.openNXLog(it->nxname); Kernel::Property* logv = nxLog.createTimeSeries(start_time); if (!logv) continue; - ws->mutableSample().addLogData(logv); + ws->mutableRun().addLogData(logv); } ws->setTitle(entry.getString("title")); - std::string runDet = - boost::lexical_cast<std::string>(entry.getInt("run_number")); + std::string run_num = boost::lexical_cast<std::string>(entry.getInt("run_number")); //The sample is left to delete the property - ws->mutableSample().addLogData( - new PropertyWithValue<std::string>("run_number", runDet)); + ws->mutableRun().addLogData(new PropertyWithValue<std::string>("run_number", run_num)); ws->populateInstrumentParameters(); } diff --git a/Code/Mantid/Nexus/src/LoadNexusProcessed.cpp b/Code/Mantid/Nexus/src/LoadNexusProcessed.cpp index f3fc2742d7c..543a5db533f 100644 --- a/Code/Mantid/Nexus/src/LoadNexusProcessed.cpp +++ b/Code/Mantid/Nexus/src/LoadNexusProcessed.cpp @@ -491,10 +491,9 @@ namespace Mantid void LoadNexusProcessed::readSampleGroup(NXEntry & mtd_entry, DataObjects::Workspace2D_sptr local_workspace) { NXMainClass sample = mtd_entry.openNXClass<NXMainClass>("sample"); - //boost::shared_ptr<Mantid::API::Sample> sample_details = local_workspace->getSample(); try { - local_workspace->mutableSample().setProtonCharge(sample.getDouble("proton_charge")); + local_workspace->mutableRun().setProtonCharge(sample.getDouble("proton_charge")); } catch(std::runtime_error & ) { @@ -561,7 +560,7 @@ namespace Mantid g_log.debug() << "set sample height=" << height->getSingleValue(0) << std::endl; } } - else local_workspace->mutableSample().addLogData(p); + else local_workspace->mutableRun().addLogData(p); } } } diff --git a/Code/Mantid/Nexus/src/LoadSNSNexus.cpp b/Code/Mantid/Nexus/src/LoadSNSNexus.cpp index 473a070cff4..ce5088b8b12 100644 --- a/Code/Mantid/Nexus/src/LoadSNSNexus.cpp +++ b/Code/Mantid/Nexus/src/LoadSNSNexus.cpp @@ -37,7 +37,6 @@ LoadSNSNexus::LoadSNSNexus():m_L1(0) {} /// Initialisation method. void LoadSNSNexus::init() { - std::cerr << "00:" << std::endl; // REMOVE declareProperty(new FileProperty("Filename", "", FileProperty::Load, ".nxs"), "The name of the SNS Nexus file to load" ); declareProperty(new WorkspaceProperty<Workspace>("OutputWorkspace","",Direction::Output)); @@ -143,10 +142,9 @@ API::Workspace_sptr LoadSNSNexus::loadEntry(NXEntry entry,int period, double pro (WorkspaceFactory::Instance().create("Workspace2D",nSpectra,nBins+1,nBins)); ws->setTitle(entry.name()); - std::string runDet = entry.getString("run_number"); + std::string run_num = entry.getString("run_number"); //The sample is left to delete the property - ws->mutableSample().addLogData( - new PropertyWithValue<std::string>("run_number", runDet)); + ws->mutableRun().addLogData(new PropertyWithValue<std::string>("run_number", run_num)); ws->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); ws->setYUnit("Counts"); @@ -219,11 +217,11 @@ API::Workspace_sptr LoadSNSNexus::loadEntry(NXEntry entry,int period, double pro ws->getAxis(1)->spectraNo(i)= i+1; } ws->mutableSpectraMap().populate(spectra.get(),spectra.get(),nSpectra); - std::cerr << "loadEntry10:" << std::endl;// REMOVE + NXFloat proton_charge = entry.openNXFloat("proton_charge"); proton_charge.load(); //ws->getSample()->setProtonCharge(*proton_charge()); - ws->mutableSample().setProtonCharge(*proton_charge()); + ws->mutableRun().setProtonCharge(*proton_charge()); std::cerr << "loadEntry11:" << std::endl;// REMOVE //---- Now load the instrument using the LoadInstrumentFromSNSNexus algorithm ---- diff --git a/Code/Mantid/Nexus/src/NexusFileIO.cpp b/Code/Mantid/Nexus/src/NexusFileIO.cpp index d5691ccccf4..de583a674ee 100644 --- a/Code/Mantid/Nexus/src/NexusFileIO.cpp +++ b/Code/Mantid/Nexus/src/NexusFileIO.cpp @@ -134,62 +134,6 @@ namespace Mantid return(0); } - int NexusFileIO::openNexusRead(const std::string& fileName, int& workspaceNumber ) - { - // Open named file and entry "mantid_workspace_<n> - file must exist - // If workspaceNumber>0, use as value on <n>, otherwise take highest - // - // @throw Exception::FileError if cannot open Nexus file for reading, or no - // mantid_workspace_<n> entry - // - NXaccess mode; - NXstatus status; - std::string className="NXentry"; - std::string mantidEntryName; - m_filename=fileName; - mode = NXACC_READ; - // check file exists - if(!Poco::File(fileName).exists()) - { - g_log.error("File not found " + fileName); - throw Exception::FileError("File not found:" , fileName); - } - // open for reading - status=NXopen(fileName.c_str(), mode, &fileID); - if(status==NX_ERROR) - { - g_log.error("Unable to open file " + fileName); - throw Exception::FileError("Unable to open File:" , fileName); - } - // search for mantid_workspace_<n> entries - int count=findMantidWSEntries(); - if(count<1) - { - g_log.error("File contains no mantid_workspace_ entries " + fileName); - throw Exception::FileError("File contains no mantid_workspace_ entries: " , fileName); - } - // - // if workspaceNumber==0 then take highest existing workspace, else look for given number - // - if( workspaceNumber>0 ) - { - if( workspaceNumber<=count ) - { - count=workspaceNumber; - } - else - { - g_log.error("Requested entry number is greater than available in file: " + fileName); - throw Exception::FileError("File does not contains mantid_workspace_" + workspaceNumber , fileName); - } - } - std::stringstream suffix; - suffix << (count); - mantidEntryName="mantid_workspace_"+suffix.str(); - status=NXopengroup(fileID,mantidEntryName.c_str(),className.c_str()); - return(status==NX_OK ? 0:1); - } - int NexusFileIO::closeNexusFile() { @@ -247,38 +191,6 @@ namespace Mantid return(true); } - bool NexusFileIO::readNexusInstrumentXmlName(std::string& instrumentXml,std::string& date, - std::string& version) - { - std::vector<std::string> attributes,avalues; - if( ! readNxText( "instrument_source", instrumentXml, attributes, avalues) ) - return(false); - for(unsigned int i=1;i<=attributes.size();i++) - { - if(attributes[i-1].compare("date") == 0) - { - date=avalues[i-1]; - } - else if(attributes[i-1].compare("version") == 0) - { - version=avalues[i-1]; - } - } - - return(true); - } - - std::string NexusFileIO::readNexusInstrumentName() - { - std::vector<std::string> attributes,avalues; - std::string name; - NXstatus status=NXopengroup(fileID,"instrument","NXinstrument"); - if (status==NX_ERROR) return ""; - if (! readNxText("name",name,attributes,avalues) ) name = ""; - NXclosegroup(fileID); - return name; - } - bool NexusFileIO::writeNexusInstrument(const API::IInstrument_const_sptr& instrument) { NXstatus status; @@ -318,40 +230,7 @@ namespace Mantid status=NXclosedata(fileID); return(true); } - // - // read an NXdata entry with char values along with attribute names and values - // - bool NexusFileIO::readNxText(const std::string& name, std::string& value, std::vector<std::string>& attributes, - std::vector<std::string>& avalues) - { - NXstatus status; - status=NXopendata(fileID, name.c_str()); - if(status==NX_ERROR) - return(false); - int length,type; - char aname[NX_MAXNAMELEN]; - char avalue[NX_MAXNAMELEN]; // value is not restricted to this, but it is a reasonably large value - while(NXgetnextattr(fileID,aname,&length,&type)==NX_OK) - { - if(type==NX_CHAR) // ignoring non char attributes - { - attributes.push_back(aname); - NXgetattr(fileID,aname,(void *)avalue,&length,&type); - avalues.push_back(avalue); - } - } - int rank,dim[1]; - status=NXgetinfo(fileID, &rank, dim, &type); - if(type==NX_CHAR && dim[0]>0) - { - char *dvalue=new char[dim[0]+1]; - status=NXgetdata(fileID, (void *)dvalue); - dvalue[dim[0]]='\0'; - value=dvalue; - } - status=NXclosedata(fileID); - return(true); - } + // // write an NXdata entry with Float value // @@ -371,32 +250,6 @@ namespace Mantid return(true); } // - // read an NXdata entry with Float value - // - bool NexusFileIO::readNxFloat(const std::string& name, double& value, std::vector<std::string>& attributes, - std::vector<std::string>& avalues) - { - NXstatus status; - status=NXopendata(fileID, name.c_str()); - if(status==NX_ERROR) - return(false); - int length=NX_MAXNAMELEN,type; - char aname[NX_MAXNAMELEN]; - char avalue[NX_MAXNAMELEN]; // value is not restricted to this (64), but should be sufficient - while(NXgetnextattr(fileID,aname,&length,&type)==NX_OK) - { - if(type==NX_CHAR) // ignoring non char attributes - { - attributes.push_back(aname); - NXgetattr(fileID,aname,(void *)avalue,&length,&type); - avalues.push_back(avalue); - } - } - status=NXgetdata(fileID, (void*)&value); - status=NXclosedata(fileID); - return(true); - } - // // write an NXdata entry with Float array values // bool NexusFileIO::writeNxFloatArray(const std::string& name, const std::vector<double>& values, const std::vector<std::string>& attributes, @@ -436,7 +289,6 @@ namespace Mantid for(size_t i=0;i<values.size();i++) { strncpy(&strs[i*maxlen],values[i].c_str(),maxlen); - //strs[i]=static_cast<char*> values[i].c_str(); } status=NXputdata(fileID, (void*)strs); status=NXclosedata(fileID); @@ -479,7 +331,8 @@ namespace Mantid // Write sample related information to the nexus file //} - int NexusFileIO::writeNexusProcessedSample( const std::string& name,const Mantid::API::Sample& sample) + int NexusFileIO::writeNexusProcessedSample( const std::string& name, const API::Sample & sample, + const Mantid::API::Run& runProperties) { NXstatus status; @@ -496,8 +349,16 @@ namespace Mantid return(3); // Write proton_charge here, if available. Note that TOFRaw has this at the NXentry level, though there is // some debate if this is appropriate. Hence for Mantid write it to the NXsample section as it is stored in Sample. - const double totalProtonCharge=sample.getProtonCharge(); - if( totalProtonCharge>0 ) + double totalProtonCharge(-1.0); + try + { + totalProtonCharge = runProperties.getProtonCharge(); + } + catch(Exception::NotFoundError&) + { + } + + if( totalProtonCharge > 0.0 ) { attributes.push_back("units"); avalues.push_back("microAmps*hour"); @@ -505,13 +366,12 @@ namespace Mantid return(4); } // Examine TimeSeries (Log) data and call function to write double or string data - std::vector<Kernel::Property*> sampleProps=sample.getLogData(); + std::vector<Kernel::Property*> sampleProps = runProperties.getLogData(); for(unsigned int i=0;i<sampleProps.size();i++) { std::string name=sampleProps[i]->name(); std::string type=sampleProps[i]->type(); - //std::string value=sampleProps[i]->value(); TimeSeriesProperty<std::string> *s_timeSeries=dynamic_cast<TimeSeriesProperty<std::string>*>(sampleProps[i]); if(s_timeSeries!=0) { @@ -563,65 +423,6 @@ namespace Mantid } - /*! - Read Nexus Sample section - @param sample pointer to the workspace sample data - @return 0 on success - */ - int NexusFileIO::readNexusProcessedSample( Mantid::API::Sample& sample) - { - NXstatus status; - - //open sample entry - status=NXopengroup(fileID,"sample","NXsample"); - if(status==NX_ERROR) - return(1); - // - std::vector<std::string> attributes,avalues; - std::string name; - if( checkEntryAtLevel("name") ) - { - readNxText( "name", name, attributes, avalues); - } - else - name=""; // Missing name entry, set null - - sample.setName(name); - // Read proton_charge, if available. Note that TOFRaw has this at the NXentry level, though there is - // some debate if this is appropriate. Hence for Mantid read it from the NXsample section as it is stored in Sample. - double totalProtonCharge; - if( checkEntryAtLevel("proton_charge") ) - { - if( readNxFloat( "proton_charge", totalProtonCharge, attributes, avalues) ) - { - sample.setProtonCharge(totalProtonCharge); - if(attributes.size()==1) // check units if present - if(attributes[0].compare("units")==0 && avalues[0].compare("microAmps*hour")!=0) - g_log.warning("Unexpected units of Proton charge ignored: " + avalues[0]); - } - } - // - char *nxname,*nxclass; - int nxdatatype; - nxname= new char[NX_MAXNAMELEN]; - nxclass = new char[NX_MAXNAMELEN]; - // - // search for NXlog sections to read - status=NXinitgroupdir(fileID); // just in case - while( (status=NXgetnextentry(fileID,nxname,nxclass,&nxdatatype)) == NX_OK ) - { - std::string nxClass=nxclass; - if(nxClass=="NXlog") - { - readNXlog(nxname,sample); - } - } - delete[] nxname; - delete[] nxclass; - // - status=NXclosegroup(fileID); - return((status==NX_ERROR)?3:0); - } void NexusFileIO::writeNexusDoubleLog(const TimeSeriesProperty<double> *d_timeSeries) { @@ -743,113 +544,6 @@ namespace Mantid // } - void NexusFileIO::readNXlog(const char* nxname, Mantid::API::Sample& sample) - { - // read an NXlog section and save the timeseries data within the sample - NXstatus status; - status=NXopengroup(fileID,nxname,"NXlog"); - if(status==NX_ERROR) return; - // - int stat,rank,dims[4],type; - char values[]="value",time[]="time"; // section names - // - // read time values - status=NXopendata(fileID,time); - if(status==NX_ERROR) - { - status=NXclosegroup(fileID); - return; - } - status=NXgetinfo(fileID,&rank,dims,&type); - double* timeVals= new double[dims[0]]; - status=NXgetdata(fileID,timeVals); - - char buffer[26]; - int length=25; - type=NX_CHAR; - status=NXgetattr(fileID, "start", buffer, &length, &type); - if(status==NX_ERROR) - { - g_log.warning("readNXlog found NXlog with no start time - ignoring log "); - NXclosedata(fileID); - NXclosegroup(fileID); - return; - } - buffer[length]='\0'; - //struct tm *tm; - std::string startT=buffer; - if( (startT.find('T')) >0 ) - startT.replace(startT.find('T'),1," "); - //boost::posix_time::ptime pt=boost::posix_time::time_from_string(startT); - //time_t startTimeOld=to_time_t(pt); - time_t startTime=createTime_t_FromString(startT); - //strptime(buffer,"%Y-%m-%dT%H:%M:%S",tm); - //time_t startTime = mktime(tm); - status=NXclosedata(fileID); - // read data values - stat=NXopendata(fileID,values); - stat=NXgetinfo(fileID,&rank,dims,&type); - if(type==NX_FLOAT64) - { - TimeSeriesProperty<double> *l_PropertyDouble = new TimeSeriesProperty<double>(nxname); - double* dataVals= new double[dims[0]]; - status=NXgetdata(fileID,dataVals); - for( int j=0;j<dims[0];j++) - { - l_PropertyDouble->addValue(startTime+static_cast<time_t>(timeVals[j]), dataVals[j]); - } - char aname[] = "type"; - char adata[NX_MAXNAMELEN]; - int iDataLen = NX_MAXNAMELEN,iType = NX_CHAR; - NXgetattr(fileID, aname, adata, &iDataLen, &iType); - std::string logType = std::string(adata,iDataLen); - if (logType == "int") - { - TimeSeriesProperty<int> *l_Property = new TimeSeriesProperty<int>(nxname); - std::map<dateAndTime, double> pd = l_PropertyDouble->valueAsMap(); - for(std::map<dateAndTime, double>::const_iterator p=pd.begin();p!=pd.end();p++) - { - l_Property->addValue(p->first,int(p->second)); - } - delete l_PropertyDouble; - sample.addLogData(l_Property); - } - else if (logType == "bool") - { - TimeSeriesProperty<bool> *l_Property = new TimeSeriesProperty<bool>(nxname); - std::map<dateAndTime, double> pd = l_PropertyDouble->valueAsMap(); - for(std::map<dateAndTime, double>::const_iterator p=pd.begin();p!=pd.end();p++) - { - l_Property->addValue(p->first,p->second != 0.0); - } - delete l_PropertyDouble; - sample.addLogData(l_Property); - } - else - { - sample.addLogData(l_PropertyDouble); - } - } - else if(type==NX_CHAR) - { - TimeSeriesProperty<std::string> *l_PropertyString = new TimeSeriesProperty<std::string>(nxname); - char* dataVals= new char[dims[0]*dims[1]]; - status=NXgetdata(fileID,(void *)dataVals); - char* value=new char[dims[1]+1]; - value[dims[1]]='\0'; - for( int j=0;j<dims[0];j++) - { - value=strncpy(value,&dataVals[j*dims[1]],dims[1]); - l_PropertyString->addValue(startTime+static_cast<time_t>(timeVals[j]), value); - } - delete[] value; - sample.addLogData(l_PropertyString); - } - status=NXclosedata(fileID); - status=NXclosegroup(fileID); - } - - int NexusFileIO::writeNexusProcessedData( const API::MatrixWorkspace_const_sptr& localworkspace, const bool& uniformSpectra, const std::vector<int>& spec) { @@ -1423,148 +1117,6 @@ namespace Mantid return(true); } - bool NexusFileIO::readNexusProcessedSpectraMap(API::MatrixWorkspace_sptr localWorkspace) - { - /*! read the details of the spectra detector mapping to the Nexus file using the format proposed for - Muon data. Use this to build spectraMap - @param localWorkspace The workspace - @return true for OK, false for error - */ - - SpectraDetectorMap& spectraMap = localWorkspace->mutableSpectraMap(); - NXstatus status; - status=NXopengroup(fileID,"instrument","NXinstrument"); - if(status==NX_ERROR) - return(false); - // - if(!checkEntryAtLevel("detector")) // to avoid Nexus Error messages - { - NXclosegroup(fileID); - return(false); - } - status=NXopengroup(fileID,"detector","NXdetector"); - if(status==NX_ERROR) - { - NXclosegroup(fileID); - return(false); - } - // - // read data from Nexus sections detector_{index,count,list} - int dim[1],rank,type; - status=NXopendata(fileID, "detector_index"); - status=NXgetinfo(fileID, &rank, dim, &type); - if(status==NX_ERROR || rank!=1 || type!=NX_INT32) - { - status=NXclosedata(fileID); - status=NXclosegroup(fileID); - return(false); - } - int nSpectra=dim[0]; - int *detector_index=new int[nSpectra]; - int *detector_count=new int[nSpectra]; - status=NXgetdata(fileID, (void*)detector_index); - status=NXclosedata(fileID); - // - status=NXopendata(fileID, "detector_count"); - status=NXgetdata(fileID, (void*)detector_count); - status=NXclosedata(fileID); - // - status=NXopendata(fileID, "detector_list"); - status=NXgetinfo(fileID, &rank, dim, &type); - int nDet=dim[0]; - int *detector_list=new int[nDet]; - status=NXgetdata(fileID, (void*)detector_list); - status=NXclosedata(fileID); - - int *spectra = NULL; - status=NXopendata(fileID, "spectra"); - if (status == NX_OK) - { - status=NXgetinfo(fileID, &rank, dim, &type); - int nSpec=dim[0]; - assert(nSpec == nSpectra); - spectra=new int[nSpec]; - status=NXgetdata(fileID, (void*)spectra); - status=NXclosedata(fileID); - } - else - { - spectra = new int[nSpectra]; - for(int i=0;i<nSpectra;i++) - spectra[i] = i + 1; - } - - // build spectra_list for populate method - int *spectra_list=new int[nDet]; - for(int i=0;i<nSpectra;i++) - { - int s = spectra[i]; - int offset=detector_index[i]; - for(int j=0;j<detector_count[i];j++) - { - spectra_list[offset+j]=s; - } - } - spectraMap.populate(spectra_list,detector_list,nDet); //Populate the Spectra Map with parameters - - // tidy up - delete[] detector_list; - delete[] detector_index; - delete[] detector_count; - delete[] spectra_list; - delete[] spectra; - // - status=NXclosegroup(fileID); // close detector group - status=NXclosegroup(fileID); // close instrument group - - return(true); - } - - bool NexusFileIO::readNexusProcessedAxis(API::MatrixWorkspace_sptr localWorkspace) - { - NXstatus status; - // Populate the vertical axis from the "axis2" attribute - status=NXopengroup(fileID,"workspace","NXdata"); - if (status==NX_ERROR) - { - NXclosegroup(fileID); - return(false); - } - status=NXopendata(fileID,"axis2"); - if (status==NX_ERROR) - { - NXclosegroup(fileID); - NXclosedata(fileID); - return(false); - } - int rank,dim[2],type; - NXgetinfo(fileID, &rank, dim, &type); - - // If this is not a spectrum axis, replace the default axis with a numeric one - Axis* axis2 = localWorkspace->getAxis(1); - if (axis2->unit()) - { - Axis* const newAxis = new NumericAxis(dim[0]); - // Copy over the unit (set in LoadNexusProcessed) - newAxis->unit() = axis2->unit(); - localWorkspace->replaceAxis(1,newAxis); - // Change the cached pointer to point to the new axis - axis2 = newAxis; - } - // Create a vector of the correct size and read in the axis values - std::vector<double> axisVals(dim[0]); - NXgetdata(fileID,&axisVals[0]); - // Set the axis values - for (int i=0; i < dim[0]; ++i) - axis2->setValue(i,axisVals[i]); - - // Clean up - NXclosedata(fileID); - status=NXclosegroup(fileID); - - return(true); - } - bool NexusFileIO::writeNexusParameterMap(API::MatrixWorkspace_const_sptr ws) { /*! Writes the instrument parameter map if not empty. Must be called inside NXentry group. @@ -1579,70 +1131,6 @@ namespace Mantid } - bool NexusFileIO::readNexusParameterMap(API::MatrixWorkspace_sptr ws) - { - /*! Reads the instrument parameter map from the data string in "instrument_parameter_map" group (NXnote). - Must be called inside NXentry group. - @param ws The workspace - @return true for OK, false for error - */ - - if (NX_ERROR == NXopengroup(fileID,"instrument_parameter_map","NXnote")) return false; - // - std::string value; - std::vector<std::string> avalues,attributes; - - if( ! readNxText( "data", value, attributes, avalues) ) - return(false); - - Geometry::ParameterMap& params = ws->instrumentParameters(); - params.clear(); - IInstrument_sptr instr = ws->getBaseInstrument(); - - typedef boost::tokenizer<boost::char_separator<char> > tokenizer; - - boost::char_separator<char> sep("|"); - tokenizer parTok(value, sep); - // Iterate over the properties - for (tokenizer::iterator it = parTok.begin(); it != parTok.end(); ++it) - { - if ( ! it->empty() ) - { - Geometry::IComponent* comp = 0; - tokenizer itemTok(*it,boost::char_separator<char>(";")); - tokenizer::iterator i = itemTok.begin(); - std::string compName = *i++; - if (compName.find("detID:") != std::string::npos) - { - int detID = atoi(compName.substr(6).c_str()); - comp = instr->getDetector(detID).get(); - if (!comp) - { - g_log.warning()<<"Cannot find detector "<<detID<<'\n'; - continue; - } - } - else - { - comp = instr->getComponentByName(compName).get(); - if (!comp) - { - g_log.warning()<<"Cannot find component "<<compName<<'\n'; - continue; - } - } - std::string type = *i++; - std::string name = *i++; - std::string val = *i; - params.add(type,comp,name,val); - } - } - - NXclosegroup(fileID); - return(true); - - } - /** * Write bin masking information * @param ws The workspace diff --git a/Code/Mantid/Nexus/src/NexusFileWriter.cpp b/Code/Mantid/Nexus/src/NexusFileWriter.cpp deleted file mode 100644 index 4b7412b7e8e..00000000000 --- a/Code/Mantid/Nexus/src/NexusFileWriter.cpp +++ /dev/null @@ -1,457 +0,0 @@ -// NexusFileWriter -// @author Ronald Fowler -// -// This code is not used anywhere now, so should be deleted -// Replaced by NexusFileIO clas -// -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include <vector> -#include <sstream> -#include <napi.h> -#include <stdlib.h> -#ifdef _WIN32 -#include <io.h> -#endif /* _WIN32 */ -#include "MantidNexus/NexusFileWriter.h" -#include "Poco/File.h" -#include <boost/shared_ptr.hpp> - -namespace Mantid -{ -namespace NeXus -{ - using namespace Kernel; - using namespace API; - - Logger& NexusFileWriter::g_log = Logger::get("NexusFileWriter"); - - /// Empty default constructor - NexusFileWriter::NexusFileWriter() : - m_nexusformat(NXACC_CREATE5), m_nexuscompression(NX_COMP_LZW) - { - } - - int NexusFileWriter::writeNexusTextField( const NXhandle& h, const std::string& name, const std::string& value) - { - // write a NXdata section "name" with string value "value" (not used?) - int status; - int dims_array[1] = { value.size() }; - status=NXmakedata(h, name.c_str(), NX_CHAR, 1, dims_array); - status=NXopendata(h, name.c_str()); - status=NXputdata(h, (void*)&(value[0])); - status=NXclosedata(h); - return(0); - } - -// -// Write out the data in a workspace in Nexus "Processed" format. -// This *Proposed* standard comprises the fields: -// <NXentry name="{Name of entry}"> -// <title> -// {Extended title for entry} -// </title> -// <definition URL="http://www.nexusformat.org/instruments/xml/NXprocessed.xml" -// version="1.0"> -// NXprocessed -// </definition> -// <NXsample name="{Name of sample}">? -// {Any relevant sample information necessary to define the data.} -// </NXsample> -// <NXdata name="{Name of processed data}"> -// <values signal="1" type="NX_FLOAT[:,:]" axes="axis1:axis2">{Processed values}</values> -// <axis1 type="NX_FLOAT[:]">{Values of the first dimension's axis}</axis1> -// <axis2 type="NX_FLOAT[:]">{Values of the second dimension's axis}</axis2> -// </NXdata> -// <NXprocess name="{Name of process}">? -// {Any relevant information about the steps used to process the data.} -// </NXprocess> -// </NXentry> - - int NexusFileWriter::openNexusWrite(const std::string& fileName, const std::string& entryName) - { - // open named file and entry - file may exist - // @throw Exception::FileError if cannot open Nexus file for writing - // - NXaccess mode; - NXstatus status; - std::string className="NXentry"; - std::string mantidEntryName=entryName; // temp allow this for existing files - m_filename=fileName; - if(Poco::File(m_filename).exists()) - mode = NXACC_RDWR; - else - { - if( fileName.find(".xml") < fileName.size() || fileName.find(".XML") < fileName.size() ) - { - mode = NXACC_CREATEXML; - m_nexuscompression = NX_COMP_NONE; - } - else - mode = m_nexusformat; - mantidEntryName="mantid_workspace_1"; - } - status=NXopen(fileName.c_str(), mode, &fileID); - if(status==NX_ERROR) - { - g_log.error("Unable to open file " + fileName); - throw Exception::FileError("Unable to open File:" , fileName); - } - if(mode==NXACC_RDWR) - { - int count=findMantidWSEntries(); - std::stringstream suffix; - suffix << (count+1); - mantidEntryName="mantid_workspace_"+suffix.str(); - } - status=NXmakegroup(fileID,mantidEntryName.c_str(),className.c_str()); - if(status==NX_ERROR) - return(2); - status=NXopengroup(fileID,mantidEntryName.c_str(),className.c_str()); - return(0); - } - - int NexusFileWriter::closeNexusFile() - { - NXstatus status; - status=NXclosegroup(fileID); - status=NXclose(&fileID); - return(0); - } - int NexusFileWriter::writeNexusProcessedHeader( const std::string& entryName, - const std::string& title) - { - // Write Nexus mantid workspace header fields for the NXentry/IXmantid/NXprocessed field. - // The URLs are not correct - std::string className="NXentry"; - std::vector<std::string> attributes,avalues; - if( ! writeNxText(fileID, "title", title, attributes, avalues) ) - return(3); - // - attributes.push_back("URL"); - avalues.push_back("http://www.nexusformat.org/instruments/xml/NXprocessed.xml"); - attributes.push_back("Version"); - avalues.push_back("1.0"); - // this may not be the "correct" long term path, but it is valid at present - if( ! writeNxText(fileID, "definition", className, attributes, avalues) ) - return(3); - avalues.clear(); - avalues.push_back("http://www.isis.rl.ac.uk/xml/IXmantid.xml"); - avalues.push_back("1.0"); - if( ! writeNxText(fileID, "definition_local", className, attributes, avalues) ) - return(3); - return(0); - } - bool NexusFileWriter::writeNexusInstrumentXmlName(const std::string& instrumentXml,const std::string& date, - const std::string& version) - { - std::vector<std::string> attributes,avalues; - if(date != "") - { - attributes.push_back("date"); - avalues.push_back(date); - } - if(version != "") - { - attributes.push_back("Version"); - avalues.push_back(version); - } - if( ! writeNxText(fileID, "instrument_source", instrumentXml, attributes, avalues) ) - return(false); - return(true); - } - bool NexusFileWriter::writeNexusInstrument(const boost::shared_ptr<API::Instrument>& instrument) - { - NXstatus status; - - //write instrument entry - status=NXmakegroup(fileID,"instrument","NXinstrument"); - if(status==NX_ERROR) - return(false); - status=NXopengroup(fileID,"instrument","NXinstrument"); - // - std::string name=instrument->getName(); - std::vector<std::string> attributes,avalues; - if( ! writeNxText(fileID, "name", name, attributes, avalues) ) - return(false); - - status=NXclosegroup(fileID); - - return ((status==NX_ERROR)? true : false); - } -// -// write an NXdata entry with char values -// - bool NexusFileWriter::writeNxText(NXhandle fileID, std::string name, std::string value, std::vector<std::string> attributes, - std::vector<std::string> avalues) - { - NXstatus status; - int dimensions[1]; - dimensions[0]=value.size()+1; - status=NXmakedata(fileID, name.c_str(), NX_CHAR, 1, dimensions); - if(status==NX_ERROR) return(false); - status=NXopendata(fileID, name.c_str()); - for(size_t it=0; it<attributes.size(); ++it) - status=NXputattr(fileID, attributes[it].c_str(), (void*)avalues[it].c_str(), avalues[it].size(), NX_CHAR); - status=NXputdata(fileID, (void*)value.c_str()); - status=NXclosedata(fileID); - return(true); - } -// -// write an NXdata entry with Float value -// - bool NexusFileWriter::writeNxFloat(const std::string name, const double& value, const std::vector<std::string> attributes, - const std::vector<std::string> avalues) - { - NXstatus status; - int dimensions[1]; - dimensions[0]=1; - status=NXmakedata(fileID, name.c_str(), NX_FLOAT64, 1, dimensions); - if(status==NX_ERROR) return(false); - status=NXopendata(fileID, name.c_str()); - for(size_t it=0; it<attributes.size(); ++it) - status=NXputattr(fileID, attributes[it].c_str(), (void*)avalues[it].c_str(), avalues[it].size(), NX_CHAR); - status=NXputdata(fileID, (void*)&value); - status=NXclosedata(fileID); - return(true); - } -// -// Write an NXnote entry with data giving parameter pair values for algorithm history and environment -// Use NX_CHAR instead of NX_BINARY for the parameter values to make more simple. -// - bool NexusFileWriter::writeNxNote(const std::string& noteName, const std::string& author, const std::string& date, - const std::string& description, const std::string& pairValues) - { - NXstatus status; - status=NXmakegroup(fileID,noteName.c_str(),"NXnote"); - if(status==NX_ERROR) - return(false); - status=NXopengroup(fileID,noteName.c_str(),"NXnote"); - // - std::vector<std::string> attributes,avalues; - if(date!="") - { - attributes.push_back("date"); - avalues.push_back(date); - } - if( ! writeNxText(fileID, "author", author, attributes, avalues) ) - return(false); - attributes.clear(); - avalues.clear(); - if( ! writeNxText(fileID, "description", description, attributes, avalues) ) - return(false); - if( ! writeNxText(fileID, "data", pairValues, attributes, avalues) ) - return(false); - - status=NXclosegroup(fileID); - return(true); - } -// -// Write sample related information to the nexus file -//} - - int NexusFileWriter::writeNexusProcessedSample( const std::string& entryName, const std::string& name, - const boost::shared_ptr<Mantid::API::Sample> sample) - { - NXstatus status; - - //write sample entry - status=NXmakegroup(fileID,"sample","NXsample"); - if(status==NX_ERROR) - return(2); - status=NXopengroup(fileID,"sample","NXsample"); - // - std::vector<std::string> attributes,avalues; - if( ! writeNxText(fileID, "name", name, attributes, avalues) ) - return(3); - // Write proton_charge here, if available. Note that TOFRaw has this at the NXentry level, though there is - // some debate if this is appropriate. Hence for Mantid write it to the NXsample section as it is stored in Sample. - const double totalProtonCharge=sample->getProtonCharge(); - if( totalProtonCharge>0 ) - { - attributes.push_back("units"); - avalues.push_back("microAmps*hour"); - if( ! writeNxFloat( "proton_charge", totalProtonCharge, attributes, avalues) ) - return(4); - } - - status=NXclosegroup(fileID); - - return((status==NX_ERROR)?3:0); - } - - int NexusFileWriter::writeNexusProcessedData( const std::string& entryName, - const boost::shared_ptr<Mantid::DataObjects::Workspace2D> localworkspace, - const bool uniformSpectra, const int m_spec_min, const int m_spec_max) - { - NXstatus status; - - //write data entry - status=NXmakegroup(fileID,"workspace","NXdata"); - if(status==NX_ERROR) - return(2); - status=NXopengroup(fileID,"workspace","NXdata"); - // write workspace data - const int nHist=localworkspace->getNumberHistograms(); - if(nHist<1) - return(2); - const int nSpectBins=localworkspace->dataY(0).size(); - const int nSpect=m_spec_max-m_spec_min+1; - int dims_array[2] = { nSpect,nSpectBins }; - std::string name=localworkspace->getTitle(); - if(name.size()==0) - name="values"; - int start[2]={0,0},asize[2]={1,dims_array[1]}; - status=NXcompmakedata(fileID, name.c_str(), NX_FLOAT64, 2, dims_array,m_nexuscompression,asize); - status=NXopendata(fileID, name.c_str()); - - for(int i=m_spec_min;i<=m_spec_max;i++) - { - status=NXputslab(fileID, (void*)&(localworkspace->dataY(i)[0]),start,asize); - start[0]++; - } - int signal=1; - status=NXputattr (fileID, "signal", &signal, 1, NX_INT32); - Mantid::API::Axis *xAxis=localworkspace->getAxis(0); - Mantid::API::Axis *yAxis=localworkspace->getAxis(1); - std::string xLabel,yLabel; - if(xAxis->isSpectra()) - xLabel="spectraNumber"; - else - xLabel=xAxis->unit()->unitID(); - std::vector<double> histNumber; - if(yAxis->isSpectra()) - { - yLabel="spectraNumber"; - for(int i=m_spec_min;i<=m_spec_max;i++) - histNumber.push_back((double)yAxis->spectraNo(i)); - } - else - yLabel=yAxis->unit()->unitID(); - const std::string axesNames=xLabel+":"+yLabel; - status=NXputattr (fileID, "axes", (void*)axesNames.c_str(), axesNames.size(), NX_CHAR); - status=NXclosedata(fileID); - // error - name="errors"; - //status=NXmakedata(fileID, name.c_str(), NX_FLOAT64, 2, dims_array); - status=NXcompmakedata(fileID, name.c_str(), NX_FLOAT64, 2, dims_array,m_nexuscompression,asize); - status=NXopendata(fileID, name.c_str()); - start[0]=0; - for(int i=m_spec_min;i<=m_spec_max;i++) - { - status=NXputslab(fileID, (void*)&(localworkspace->dataE(i)[0]),start,asize); - start[0]++; - } - status=NXclosedata(fileID); - // write X data, as single array or all values if "ragged" - if(uniformSpectra) - { - dims_array[0]=localworkspace->dataX(1).size(); - status=NXmakedata(fileID, "axis1", NX_FLOAT64, 1, dims_array); - status=NXopendata(fileID, "axis1"); - status=NXputdata(fileID, (void*)&(localworkspace->dataX(1)[0])); - } - else - { - dims_array[0]=nSpect; - dims_array[1]=localworkspace->dataX(1).size(); - status=NXmakedata(fileID, "axis1", NX_FLOAT64, 2, dims_array); - status=NXopendata(fileID, "axis1"); - start[0]=0; asize[1]=dims_array[1]; - for(int i=m_spec_min;i<=m_spec_max;i++) - { - status=NXputslab(fileID, (void*)&(localworkspace->dataX(i)[0]),start,asize); - start[0]++; - } - } - std::string dist=(localworkspace->isDistribution()) ? "1" : "0"; - status=NXputattr(fileID, "distribution", (void*)dist.c_str(), 2, NX_CHAR); - status=NXclosedata(fileID); - // write axis2, maybe just spectra number - dims_array[0]=m_spec_max-m_spec_min+1; - status=NXmakedata(fileID, "axis2", NX_FLOAT64, 1, dims_array); - status=NXopendata(fileID, "axis2"); - status=NXputdata(fileID, (void*)&(histNumber[m_spec_min])); - status=NXclosedata(fileID); - - status=NXclosegroup(fileID); - return((status==NX_ERROR)?3:0); - } - - int NexusFileWriter::writeNexusProcessedProcess(const boost::shared_ptr<Mantid::DataObjects::Workspace2D> localworkspace) - { - // Write Process section - NXstatus status; - status=NXmakegroup(fileID,"process","NXprocess"); - if(status==NX_ERROR) - return(2); - status=NXopengroup(fileID,"process","NXprocess"); - //Mantid:API::Workspace xxx; - const API::WorkspaceHistory history=localworkspace->getHistory(); - const std::vector<AlgorithmHistory>& algHist = history.getAlgorithmHistories(); - std::stringstream output,algorithmNumber; - EnvironmentHistory envHist; - - //dump output to sting - output << envHist; - char buffer [25]; - time_t now; - time(&now); - strftime (buffer,25,"%Y-%b-%d %H:%M:%S",localtime(&now)); - writeNxNote("MantidEnvironment","mantid",buffer,"Mantid Environment data",output.str()); -//map used to order the history by execution order - typedef std::map <unsigned int,std::string> orderedHistMap; - orderedHistMap ordMap; - int histsize = static_cast<int>(algHist.size()); - for(int i=0; i < histsize;i++) - { - std::stringstream algNumber,algData; - // algNumber << "MantidAlgorithm_" << i; - algHist[i].printSelf(algData); - //get execute count - int nexecCount=algHist[i].execCount(); - //order by execute count - ordMap.insert(orderedHistMap::value_type(nexecCount,algData.str())); - // writeNxNote(algNumber.str(),"mantid","","Mantid Algorithm data",algData.str()); - } - int num=0; - std::map <unsigned int,std::string>::iterator m_Iter; - for (m_Iter=ordMap.begin( );m_Iter!=ordMap.end( );++m_Iter) - { - ++num; - std::stringstream algNumber; - algNumber << "MantidAlgorithm_" << num; - writeNxNote(algNumber.str(),"mantid","","Mantid Algorithm data",m_Iter->second); - } - status=NXclosegroup(fileID); - return(0); - } - - int NexusFileWriter::findMantidWSEntries() - { - // search exiting file for entries of form mantid_workspace_<n> and return count - int count=0; - NXstatus status; - char *nxname,*nxclass; - int nxdatatype; - nxname= new char[NX_MAXNAMELEN]; - nxclass = new char[NX_MAXNAMELEN]; - // - // read nexus fields at this level - while( (status=NXgetnextentry(fileID,nxname,nxclass,&nxdatatype)) == NX_OK ) - { - std::string nxClass=nxclass; - if(nxClass=="NXentry") - { - std::string nxName=nxname; - if(nxName.find("mantid_workspace_")==0) - count++; - } - } - delete[] nxname; - delete[] nxclass; - return count; - } -} // namespace NeXus -} // namespace Mantid diff --git a/Code/Mantid/Nexus/src/SaveNexusProcessed.cpp b/Code/Mantid/Nexus/src/SaveNexusProcessed.cpp index 92b01e7c5b3..b85e1688a78 100644 --- a/Code/Mantid/Nexus/src/SaveNexusProcessed.cpp +++ b/Code/Mantid/Nexus/src/SaveNexusProcessed.cpp @@ -16,6 +16,9 @@ #include <cmath> #include <boost/shared_ptr.hpp> +using namespace Mantid::Kernel; +using namespace Mantid::API; + namespace Mantid { namespace NeXus @@ -24,9 +27,6 @@ namespace NeXus // Register the algorithm into the algorithm factory DECLARE_ALGORITHM(SaveNexusProcessed) - using namespace Kernel; - using namespace API; - using namespace DataObjects; /// Empty default constructor SaveNexusProcessed::SaveNexusProcessed() : @@ -155,8 +155,8 @@ namespace NeXus nexusFile->writeNexusInstrumentXmlName("NoNameAvailable","",""); progress(0.7); -// boost::shared_ptr<Mantid::API::Sample> sample=m_inputWorkspace->getSample(); - if( nexusFile->writeNexusProcessedSample(m_inputWorkspace->sample().getName(), m_inputWorkspace->sample()) != 0 ) + if( nexusFile->writeNexusProcessedSample(m_inputWorkspace->sample().getName(), m_inputWorkspace->sample(), + m_inputWorkspace->run()) != 0 ) { g_log.error("Failed to write NXsample"); throw Exception::FileError("Failed to write NXsample", m_filename); diff --git a/Code/Mantid/Nexus/test/LoadISISNexusTest.h b/Code/Mantid/Nexus/test/LoadISISNexusTest.h index 028a1a8f265..c15d3f47c20 100644 --- a/Code/Mantid/Nexus/test/LoadISISNexusTest.h +++ b/Code/Mantid/Nexus/test/LoadISISNexusTest.h @@ -43,34 +43,34 @@ public: TS_ASSERT_EQUALS(ws->spectraMap().nElements(),17792); - const std::vector< Property* >& logs = ws->sample().getLogData(); - TS_ASSERT_EQUALS(logs.size(),26); + const std::vector< Property* >& logs = ws->run().getLogData(); + TS_ASSERT_EQUALS(logs.size(),27); - TimeSeriesProperty<std::string>* slog = dynamic_cast<TimeSeriesProperty<std::string>*>(ws->sample().getLogData("icp_event")); + TimeSeriesProperty<std::string>* slog = dynamic_cast<TimeSeriesProperty<std::string>*>(ws->run().getLogData("icp_event")); TS_ASSERT(slog); std::string str = slog->value(); TS_ASSERT_EQUALS(str.size(),1023); TS_ASSERT_EQUALS(str.substr(0,37),"2009-Apr-28 09:20:29 CHANGE_PERIOD 1"); - slog = dynamic_cast<TimeSeriesProperty<std::string>*>(ws->sample().getLogData("icp_debug")); + slog = dynamic_cast<TimeSeriesProperty<std::string>*>(ws->run().getLogData("icp_debug")); TS_ASSERT(slog); TS_ASSERT_EQUALS(slog->size(),50); - TimeSeriesProperty<double>* dlog = dynamic_cast<TimeSeriesProperty<double>*>(ws->sample().getLogData("total_counts")); + TimeSeriesProperty<double>* dlog = dynamic_cast<TimeSeriesProperty<double>*>(ws->run().getLogData("total_counts")); TS_ASSERT(dlog); TS_ASSERT_EQUALS(dlog->size(),172); - dlog = dynamic_cast<TimeSeriesProperty<double>*>(ws->sample().getLogData("period")); + dlog = dynamic_cast<TimeSeriesProperty<double>*>(ws->run().getLogData("period")); TS_ASSERT(dlog); TS_ASSERT_EQUALS(dlog->size(),172); - TimeSeriesProperty<bool>* blog = dynamic_cast<TimeSeriesProperty<bool>*>(ws->sample().getLogData("period 1")); + TimeSeriesProperty<bool>* blog = dynamic_cast<TimeSeriesProperty<bool>*>(ws->run().getLogData("period 1")); TS_ASSERT(blog); TS_ASSERT_EQUALS(blog->size(),1); TS_ASSERT_EQUALS(ws->sample().getName(),""); - Property *l_property = ws->sample().getLogData( "run_number" ); + Property *l_property = ws->run().getLogData( "run_number" ); TS_ASSERT_EQUALS( l_property->value(), "49886" ); } void testExec2() diff --git a/Code/Mantid/Nexus/test/LoadMuonLogTest.h b/Code/Mantid/Nexus/test/LoadMuonLogTest.h index fa253d84c03..bc86095d08f 100644 --- a/Code/Mantid/Nexus/test/LoadMuonLogTest.h +++ b/Code/Mantid/Nexus/test/LoadMuonLogTest.h @@ -72,7 +72,8 @@ public: TS_ASSERT( ! result.compare(outputSpace)); - TS_ASSERT_THROWS_NOTHING(loaderNexusFile.execute()); + loaderNexusFile.setChild(true); + loaderNexusFile.execute(); TS_ASSERT( loaderNexusFile.isExecuted() ); @@ -84,12 +85,12 @@ public: // obtain the expected log data which was read from the Nexus file (NXlog) - Property *l_property = output->sample().getLogData( std::string("BEAMLOG_CURRENT") ); + Property *l_property = output->run().getLogData( std::string("BEAMLOG_CURRENT") ); TimeSeriesProperty<double> *l_timeSeriesDouble1 = dynamic_cast<TimeSeriesProperty<double>*>(l_property); std::string timeSeriesString = l_timeSeriesDouble1->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,27), "2006-Nov-21 07:03:08 182.8" ); - l_property = output->sample().getLogData( std::string("BEAMLOG_FREQ") ); + l_property = output->run().getLogData( std::string("BEAMLOG_FREQ") ); TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); timeSeriesString = l_timeSeriesDouble->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,24), "2006-Nov-21 07:03:08 50" ); diff --git a/Code/Mantid/Nexus/test/LoadMuonNexus2Test.h b/Code/Mantid/Nexus/test/LoadMuonNexus2Test.h index 8a0402813a8..120b60d587b 100644 --- a/Code/Mantid/Nexus/test/LoadMuonNexus2Test.h +++ b/Code/Mantid/Nexus/test/LoadMuonNexus2Test.h @@ -101,7 +101,7 @@ public: //---------------------------------------------------------------------- // Test code copied from LoadLogTest to check sub-algorithm is running properly //---------------------------------------------------------------------- - Property *l_property = output->sample().getLogData( std::string("temperature_1_log") ); + Property *l_property = output->run().getLogData( std::string("temperature_1_log") ); TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); std::map<dateAndTime, double> asMap = l_timeSeriesDouble ->valueAsMap(); TS_ASSERT_EQUALS(l_timeSeriesDouble->size(),37); @@ -341,7 +341,7 @@ public: //---------------------------------------------------------------------- // Test code copied from LoadLogTest to check sub-algorithm is running properly //---------------------------------------------------------------------- - Property *l_property = output->sample().getLogData( std::string("temperature_1_log") ); + Property *l_property = output->run().getLogData( std::string("temperature_1_log") ); TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); std::map<dateAndTime, double> asMap = l_timeSeriesDouble ->valueAsMap(); TS_ASSERT_EQUALS(l_timeSeriesDouble->size(),42); @@ -443,7 +443,7 @@ public: //---------------------------------------------------------------------- // Test code copied from LoadLogTest to check sub-algorithm is running properly //---------------------------------------------------------------------- - Property *l_property = output->sample().getLogData( std::string("temperature_1_log") ); + Property *l_property = output->run().getLogData( std::string("temperature_1_log") ); TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); std::map<dateAndTime, double> asMap = l_timeSeriesDouble ->valueAsMap(); TS_ASSERT_EQUALS(l_timeSeriesDouble->size(),31); diff --git a/Code/Mantid/Nexus/test/LoadMuonNexusTest.h b/Code/Mantid/Nexus/test/LoadMuonNexusTest.h index bbc184646bb..68016d1bb5c 100644 --- a/Code/Mantid/Nexus/test/LoadMuonNexusTest.h +++ b/Code/Mantid/Nexus/test/LoadMuonNexusTest.h @@ -110,7 +110,7 @@ public: // Test code copied from LoadLogTest to check sub-algorithm is running properly //---------------------------------------------------------------------- //boost::shared_ptr<Sample> sample = output->getSample(); - Property *l_property = output->sample().getLogData( std::string("beamlog_current") ); + Property *l_property = output->run().getLogData( std::string("beamlog_current") ); TimeSeriesProperty<double> *l_timeSeriesDouble = dynamic_cast<TimeSeriesProperty<double>*>(l_property); std::string timeSeriesString = l_timeSeriesDouble->value(); TS_ASSERT_EQUALS( timeSeriesString.substr(0,27), "2006-Nov-21 07:03:08 182.8" ); diff --git a/Code/Mantid/Nexus/test/LoadNexusProcessedTest.h b/Code/Mantid/Nexus/test/LoadNexusProcessedTest.h index 5ce55deffb4..c6c697d0570 100644 --- a/Code/Mantid/Nexus/test/LoadNexusProcessedTest.h +++ b/Code/Mantid/Nexus/test/LoadNexusProcessedTest.h @@ -51,7 +51,7 @@ public: // Test proton charge from the sample block - TS_ASSERT_DELTA(matrix_ws->sample().getProtonCharge(), 30.14816, 1e-5) + TS_ASSERT_DELTA(matrix_ws->run().getProtonCharge(), 30.14816, 1e-5) //Test history const std::vector<AlgorithmHistory>& alghist = matrix_ws->getHistory().getAlgorithmHistories(); diff --git a/Code/Mantid/Nexus/test/LoadRSaveNLoadNcspTest.h b/Code/Mantid/Nexus/test/LoadRSaveNLoadNcspTest.h index e987e40930b..5a818b61d1b 100644 --- a/Code/Mantid/Nexus/test/LoadRSaveNLoadNcspTest.h +++ b/Code/Mantid/Nexus/test/LoadRSaveNLoadNcspTest.h @@ -137,7 +137,7 @@ void testExecOnLoadraw() TS_ASSERT_EQUALS( output->YUnit(), "Counts" ) // Check the proton charge has been set correctly - TS_ASSERT_DELTA( output->sample().getProtonCharge(), 0.8347, 0.0001 ) + TS_ASSERT_DELTA( output->run().getProtonCharge(), 0.8347, 0.0001 ) // // check that the instrument data has been loaded, copied from LoadInstrumentTest @@ -205,19 +205,17 @@ void testExecOnLoadraw() // obtain the expected log data which was read from the Nexus file (NXlog) - //boost::shared_ptr<Sample> sample = output->getSample(); - Property *l_property =output->sample().getLogData( std::string("height") ); + Property *l_property =output->run().getLogData( std::string("height") ); TimeSeriesProperty<double> *l_timeSeriesDouble1 = dynamic_cast<TimeSeriesProperty<double>*>(l_property); std::string timeSeriesString = l_timeSeriesDouble1->value(); - // // Testing log data - this was failing at one time as internal format of log data changed, but now OK again // TS_ASSERT_EQUALS( timeSeriesString.substr(0,30), "2008-Jun-17 11:10:44 -0.86526" ); - l_property = output->sample().getLogData( std::string("ICPevent") ); + l_property = output->run().getLogData( std::string("ICPevent") ); TimeSeriesProperty<std::string> *l_timeSeriesString = dynamic_cast<TimeSeriesProperty<std::string>*>(l_property); timeSeriesString = l_timeSeriesString->value(); // diff --git a/Code/Mantid/Nexus/test/LoadSNSNexusTest.h b/Code/Mantid/Nexus/test/LoadSNSNexusTest.h index 2efedacd181..f48c46de9b1 100644 --- a/Code/Mantid/Nexus/test/LoadSNSNexusTest.h +++ b/Code/Mantid/Nexus/test/LoadSNSNexusTest.h @@ -58,7 +58,7 @@ public: TS_ASSERT_EQUALS(ws->spectraMap().nElements(),77824); - const std::vector< Property* >& logs = ws->sample().getLogData(); + const std::vector< Property* >& logs = ws->run().getLogData(); TS_ASSERT_EQUALS(logs.size(),1); //------------ Instrument Loading Sub-Test ----------------------- @@ -79,25 +79,25 @@ public: TS_ASSERT_EQUALS(detectors[304]->getName(), "bank1, (1,0)"); /* - TimeSeriesProperty<std::string>* slog = dynamic_cast<TimeSeriesProperty<std::string>*>(ws->sample().getLogData("icp_event")); + TimeSeriesProperty<std::string>* slog = dynamic_cast<TimeSeriesProperty<std::string>*>(ws->run().getLogData("icp_event")); TS_ASSERT(slog); std::string str = slog->value(); TS_ASSERT_EQUALS(str.size(),1023); TS_ASSERT_EQUALS(str.substr(0,37),"2009-Apr-28 09:20:29 CHANGE_PERIOD 1"); - slog = dynamic_cast<TimeSeriesProperty<std::string>*>(ws->sample().getLogData("icp_debug")); + slog = dynamic_cast<TimeSeriesProperty<std::string>*>(ws->run().getLogData("icp_debug")); TS_ASSERT(slog); TS_ASSERT_EQUALS(slog->size(),50); - TimeSeriesProperty<double>* dlog = dynamic_cast<TimeSeriesProperty<double>*>(ws->sample().getLogData("total_counts")); + TimeSeriesProperty<double>* dlog = dynamic_cast<TimeSeriesProperty<double>*>(ws->run().getLogData("total_counts")); TS_ASSERT(dlog); TS_ASSERT_EQUALS(dlog->size(),172); - dlog = dynamic_cast<TimeSeriesProperty<double>*>(ws->sample().getLogData("period")); + dlog = dynamic_cast<TimeSeriesProperty<double>*>(ws->run().getLogData("period")); TS_ASSERT(dlog); TS_ASSERT_EQUALS(dlog->size(),172); - TimeSeriesProperty<bool>* blog = dynamic_cast<TimeSeriesProperty<bool>*>(ws->sample().getLogData("period 1")); + TimeSeriesProperty<bool>* blog = dynamic_cast<TimeSeriesProperty<bool>*>(ws->run().getLogData("period 1")); TS_ASSERT(blog); TS_ASSERT_EQUALS(blog->size(),1); */ diff --git a/Code/Mantid/Nexus/test/SaveNexusProcessedTest.h b/Code/Mantid/Nexus/test/SaveNexusProcessedTest.h index 8b72b409e75..322e9878654 100644 --- a/Code/Mantid/Nexus/test/SaveNexusProcessedTest.h +++ b/Code/Mantid/Nexus/test/SaveNexusProcessedTest.h @@ -93,7 +93,7 @@ public: //TS_ASSERT_THROWS_NOTHING( result = algToBeTested.getPropertyValue("EntryName") ) //TS_ASSERT( ! result.compare(entryName)); - // changed so that 1D workspaces are no longer written. + // changed so that 1D workspaces are no longer written. TS_ASSERT_THROWS_NOTHING(algToBeTested.execute()); TS_ASSERT( algToBeTested.isExecuted() ); diff --git a/Code/Mantid/PythonAPI/src/api_exports.cpp b/Code/Mantid/PythonAPI/src/api_exports.cpp index 21ce0c026ed..b7b975e6e69 100644 --- a/Code/Mantid/PythonAPI/src/api_exports.cpp +++ b/Code/Mantid/PythonAPI/src/api_exports.cpp @@ -188,7 +188,7 @@ namespace PythonAPI return_value_policy< copy_const_reference >() ) .def("getInstrument", &Mantid::API::MatrixWorkspace::getInstrument) .def("getDetector", &Mantid::API::MatrixWorkspace::getDetector) - .def("getSampleDetails", &Mantid::API::MatrixWorkspace::sample, return_internal_reference<>() ) + .def("getRun", &Mantid::API::MatrixWorkspace::run, return_internal_reference<>() ) .def("__add__", (binary_fn1)&WorkspaceAlgebraProxy::plus) .def("__add__", (binary_fn2)&WorkspaceAlgebraProxy::plus) .def("__radd__",(binary_fn2)&WorkspaceAlgebraProxy::rplus) @@ -211,10 +211,10 @@ namespace PythonAPI .def("__idiv__",(binary_fn2)&WorkspaceAlgebraProxy::inplace_divide) // Deprecated, here for backwards compatability .def("blocksize", &Mantid::API::MatrixWorkspace::blocksize) + .def("getSampleDetails", &Mantid::API::MatrixWorkspace::run, return_internal_reference<>() ) ; } - void export_tableworkspace() { // Declare the pointer @@ -253,9 +253,6 @@ namespace PythonAPI ; } - // Sample class - BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Sample_getLogData_overloads, getLogData, 0, 1) - void export_sample() { //Pointer @@ -263,12 +260,7 @@ namespace PythonAPI //Sample class class_< Mantid::API::Sample, boost::noncopyable >("Sample", no_init) - .def("getLogData", (Mantid::Kernel::Property* (Mantid::API::Sample::*)(const std::string&) const)&Sample::getLogData, - return_internal_reference<>()) - .def("getLogData", (const std::vector<Mantid::Kernel::Property*> & (Mantid::API::Sample::*)() const)&Sample::getLogData, - return_internal_reference<>()) .def("getName", &Mantid::API::Sample::getName, return_value_policy<copy_const_reference>()) - .def("getProtonCharge", &Mantid::API::Sample::getProtonCharge, return_value_policy< copy_const_reference>()) .def("getGeometryFlag", &Mantid::API::Sample::getGeometryFlag) .def("getThickness", &Mantid::API::Sample::getThickness) .def("getHeight", &Mantid::API::Sample::getHeight) @@ -276,6 +268,21 @@ namespace PythonAPI ; } + void export_run() + { + //Pointer + register_ptr_to_python<Mantid::API::Run*>(); + + //Run class + class_< Mantid::API::Run, boost::noncopyable >("Run", no_init) + .def("getLogData", (Mantid::Kernel::Property* (Mantid::API::Run::*)(const std::string&) const)&Run::getLogData, + return_internal_reference<>()) + .def("getLogData", (const std::vector<Mantid::Kernel::Property*> & (Mantid::API::Run::*)() const)&Run::getLogData, + return_internal_reference<>()) + .def("getProtonCharge", &Mantid::API::Run::getProtonCharge) + ; + } + void export_instrument() { //Pointer to the interface @@ -358,6 +365,7 @@ namespace PythonAPI export_tableworkspace(); export_workspacegroup(); export_sample(); + export_run(); export_instrument(); export_workspace_property(); export_workspacefactory(); diff --git a/Code/Mantid/build.sh b/Code/Mantid/build.sh index b83b74a315b..4645aec39da 100755 --- a/Code/Mantid/build.sh +++ b/Code/Mantid/build.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # Build the Mantid library using scons-local in the Third_Party directory # @@ -7,9 +7,28 @@ # # Third_Party is not part of rpm distribution, so look for local scons # -sc=`which scons 2>/dev/null` -if test x$sc = x; then - python ../Third_Party/src/scons-local/scons.py $* $MANTID_BUILD_FLAGS -else - $sc $* $MANTID_BUILD_FLAGS +#sc=`which scons 2>/dev/null` +#if test x$sc = x; then +# python ../Third_Party/src/scons-local/scons.py $* $MANTID_BUILD_FLAGS +#else +# $sc $* $MANTID_BUILD_FLAGS +#fi + +## Perform the build and exit if there were errors +scons $* $MANTID_BUILD_FLAGS +if [ $? -ne 0 ]; then + exit fi + +## Move the libraries around to the correct place +# PLUGINS="Algorithms CurveFitting DataObjects DataHandling Nexus" +# SHAREDDIR=Bin/Shared +# PLUGINDIR=Bin/Plugins + +# for i in $PLUGINS; do +# lib=${SHAREDDIR}/libMantid${i}.so +# if [ -e $lib ]; then +# echo "Moving ${lib} to $PLUGINDIR" +# mv {${SHAREDDIR},$PLUGINDIR}/libMantid${i}.so +# fi +# done diff --git a/Code/RPM_Kit/mantid.spec.template b/Code/RPM_Kit/mantid.spec.template index bf395d91270..e40748d80e1 100644 --- a/Code/RPM_Kit/mantid.spec.template +++ b/Code/RPM_Kit/mantid.spec.template @@ -109,6 +109,9 @@ for i in qtiplotrc.py qtiUtil.py mantidplotrc.py mantidplot.py; do install -m755 Code/qtiplot/qtiplot/$i $RPM_BUILD_ROOT/%{mantidbindir}/$i done install -m755 Code/Mantid/PythonAPI/MantidFramework.py $RPM_BUILD_ROOT/%{mantidbindir} +install -m755 Code/Mantid/PythonAPI/MantidHeader.py $RPM_BUILD_ROOT/%{mantidbindir} +install -m755 Code/Mantid/PythonAPI/MantidStartup.py $RPM_BUILD_ROOT/%{mantidbindir} +install -m755 Code/Mantid/PythonAPI/MantidScript $RPM_BUILD_ROOT/%{mantidbindir} # on ubuntu sip goes into /usr/lib/pyshared etc # not sure why this is needed diff --git a/Code/qtiplot/MantidQt/CustomDialogs/src/PlotAsymmetryByLogValueDialog.cpp b/Code/qtiplot/MantidQt/CustomDialogs/src/PlotAsymmetryByLogValueDialog.cpp index 9442109f7a8..61c0ed981ed 100644 --- a/Code/qtiplot/MantidQt/CustomDialogs/src/PlotAsymmetryByLogValueDialog.cpp +++ b/Code/qtiplot/MantidQt/CustomDialogs/src/PlotAsymmetryByLogValueDialog.cpp @@ -174,7 +174,7 @@ void PlotAsymmetryByLogValueDialog::fillLogBox(const QString&) Mantid::API::AnalysisDataService::Instance().retrieve(gws->getNames()[1]) ); } - const std::vector< Mantid::Kernel::Property* >& props = mws->sample().getLogData(); + const std::vector< Mantid::Kernel::Property* >& props = mws->run().getLogData(); if (gws) { std::vector<std::string> wsNames = gws->getNames(); @@ -211,4 +211,4 @@ void PlotAsymmetryByLogValueDialog::fillLogBox(const QString&) catch(std::exception& e) { } -} \ No newline at end of file +} diff --git a/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.cpp b/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.cpp index 613a6a37849..656b76e820f 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.cpp +++ b/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.cpp @@ -1845,7 +1845,7 @@ void FitPropertyBrowser::setLogValue(const QString& lv) ); if (ws) { - const std::vector<Mantid::Kernel::Property*> logs = ws->sample().getLogData(); + const std::vector<Mantid::Kernel::Property*> logs = ws->run().getLogData(); for(int i=0;i<logs.size();++i) { m_logs << QString::fromStdString(logs[i]->name()); diff --git a/Code/qtiplot/qtiplot/src/Mantid/MantidSampleLogDialog.cpp b/Code/qtiplot/qtiplot/src/Mantid/MantidSampleLogDialog.cpp index 687c339d9f8..2dc25d6ae53 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/MantidSampleLogDialog.cpp +++ b/Code/qtiplot/qtiplot/src/Mantid/MantidSampleLogDialog.cpp @@ -179,7 +179,7 @@ void MantidSampleLogDialog::init() { throw std::runtime_error("Wrong type of a Workspace"); } - const std::vector< Mantid::Kernel::Property * > & logData = ws->sample().getLogData();//ws->getSample()->getLogData(); + const std::vector< Mantid::Kernel::Property * > & logData = ws->run().getLogData(); std::vector< Mantid::Kernel::Property * >::const_iterator pEnd = logData.end(); int max_length(0); for( std::vector< Mantid::Kernel::Property * >::const_iterator pItr = logData.begin(); diff --git a/Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp b/Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp index 559ad13d605..666d5b92c38 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp +++ b/Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp @@ -1652,7 +1652,7 @@ void MantidUI::importNumSeriesLog(const QString &wsName, const QString &logname, Mantid::API::MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(getWorkspace(wsName)); if (!ws) return; - Mantid::Kernel::Property * logData =ws->sample().getLogData(logname.toStdString()); //ws->getSample()->getLogData(logname.toStdString()); + Mantid::Kernel::Property * logData =ws->run().getLogData(logname.toStdString()); if (!logData) return; Mantid::Kernel::LogFilter flt(logData); @@ -1682,7 +1682,7 @@ void MantidUI::importNumSeriesLog(const QString &wsName, const QString &logname, { try { - f = dynamic_cast<Mantid::Kernel::TimeSeriesProperty<bool> *>(ws->sample().getLogData("running"));//ws->getSample()->getLogData("running")); + f = dynamic_cast<Mantid::Kernel::TimeSeriesProperty<bool> *>(ws->run().getLogData("running")); if (f) flt.addFilter(f); else { @@ -1699,7 +1699,7 @@ void MantidUI::importNumSeriesLog(const QString &wsName, const QString &logname, if (filter == 2 || filter ==3) { - std::vector<Mantid::Kernel::Property*> ps =ws->sample().getLogData(); //ws->getSample()->getLogData(); + std::vector<Mantid::Kernel::Property*> ps =ws->run().getLogData(); for(std::vector<Mantid::Kernel::Property*>::const_iterator it=ps.begin();it!=ps.end();it++) if ((*it)->name().find("period ") == 0) { diff --git a/Code/qtiplot/qtiplot/src/Mantid/SequentialFitDialog.cpp b/Code/qtiplot/qtiplot/src/Mantid/SequentialFitDialog.cpp index aaac8507b9a..7aa4ef402fd 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/SequentialFitDialog.cpp +++ b/Code/qtiplot/qtiplot/src/Mantid/SequentialFitDialog.cpp @@ -167,7 +167,7 @@ void SequentialFitDialog::validateLogs(const QString wsName) ); if (ws) { - const std::vector<Mantid::Kernel::Property*> logs = ws->sample().getLogData(); + const std::vector<Mantid::Kernel::Property*> logs = ws->run().getLogData(); QStringList logNames; for(int i=0;i<logs.size();++i) { -- GitLab