Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/7437_doc_ca…
Browse files Browse the repository at this point in the history
…libration

Conflicts:
	Code/Mantid/scripts/Calibration/tube.py

It was necessary to merge master into 7437 to solve conflicts.

re #7437
  • Loading branch information
gesnerpassos committed Jul 19, 2013
2 parents cb43f1f + 0596e18 commit 3039afc
Show file tree
Hide file tree
Showing 57 changed files with 1,511 additions and 1,044 deletions.
4 changes: 3 additions & 1 deletion Code/Mantid/Framework/API/src/Run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ Kernel::Logger& Run::g_log = Kernel::Logger::get("Run");
*/
void Run::setProtonCharge(const double charge)
{
const std::string PROTON_CHARGE_UNITS("uA.hour");
if( !hasProperty(PROTON_CHARGE_LOG_NAME) )
{
addProperty(PROTON_CHARGE_LOG_NAME, charge, "uA.hour");
addProperty(PROTON_CHARGE_LOG_NAME, charge, PROTON_CHARGE_UNITS);
}
else
{
Kernel::Property *charge_prop = getProperty(PROTON_CHARGE_LOG_NAME);
charge_prop->setValue(boost::lexical_cast<std::string>(charge));
charge_prop->setUnits(PROTON_CHARGE_UNITS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ namespace Mantid
eNumber = 2
};

// struct OpRequirements
// {
// bool matchXSize;
// bool keepEventWorkspace;
// };


/**
BinaryOperation supports the implementation of a binary operation on two input workspaces.
It inherits from the Algorithm class, and overrides the init() & exec() methods.
Expand Down Expand Up @@ -111,7 +104,7 @@ namespace Mantid
virtual bool checkEventCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs);

/// Checks the overall size compatibility of two workspaces
virtual bool checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
virtual std::string checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;

/// Checks if the spectra at the given index of either input workspace is masked. If so then the output spectra has zeroed data
/// and is also masked. The function returns true if further processing is not required on the spectra.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace Mantid
protected:
// Overridden BinaryOperation method
/// Checks the overall size compatability of two workspaces
virtual bool checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
virtual std::string checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
};

} // namespace Algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace Mantid

void checkRequirements();

bool checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
std::string checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace Mantid
void performEventBinaryOperation(DataObjects::EventList & lhs, const double& rhsY, const double& rhsE);

void checkRequirements();
bool checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
std::string checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
bool checkUnitCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
bool checkCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace Mantid
const double& rhsY, const double& rhsE);

void checkRequirements();
virtual bool checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
virtual std::string checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace Mantid
void performEventBinaryOperation(DataObjects::EventList & lhs, const double& rhsY, const double& rhsE);

void checkRequirements();
bool checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
std::string checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
bool checkCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
void operateOnRun(const API::Run& lhs, const API::Run& rhs, API::Run & ans) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DLLExport PoissonErrors : public BinaryOperation
const MantidVec& rhsY, const MantidVec& rhsE, MantidVec& YOut, MantidVec& EOut);
void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut);
virtual bool checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
virtual std::string checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;

/// The name of the first input workspace property for BinaryOperation
virtual std::string inputPropName1() const { return "InputWorkspace";}
Expand Down
106 changes: 53 additions & 53 deletions Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/WeightedMean.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,71 +8,71 @@

namespace Mantid
{
namespace Algorithms
{
/** An algorithm to calculate the weighted mean of two workspaces.
namespace Algorithms
{
/** An algorithm to calculate the weighted mean of two workspaces.
Required Properties:
<UL>
<LI> InputWorkspace1 - The name of the first input workspace.</LI>
<LI> InputWorkspace2 - The name of the second input workspace. </LI>
<LI> OutputWorkspace - The name of the workspace in which to store the result.</LI>
</UL>
Required Properties:
<UL>
<LI> InputWorkspace1 - The name of the first input workspace.</LI>
<LI> InputWorkspace2 - The name of the second input workspace. </LI>
<LI> OutputWorkspace - The name of the workspace in which to store the result.</LI>
</UL>
@author Robert Dalgliesh, ISIS, RAL
@date 12/1/2010
@author Robert Dalgliesh, ISIS, RAL
@date 12/1/2010
Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
Copyright &copy; 2010 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://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport WeightedMean : public BinaryOperation
{
public:
/// Empty Constructor
WeightedMean() : BinaryOperation() {}
/// Empty Destructor
virtual ~WeightedMean() {}
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport WeightedMean : public BinaryOperation
{
public:
/// Empty Constructor
WeightedMean() : BinaryOperation() {}
/// Empty Destructor
virtual ~WeightedMean() {}

virtual const std::string name() const { return "WeightedMean"; }
virtual int version() const { return (1); }
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "Arithmetic";}
virtual const std::string name() const { return "WeightedMean"; }
virtual int version() const { return (1); }
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "Arithmetic";}

private:
/// Sets documentation strings for this algorithm
virtual void initDocs();
// Overridden BinaryOperation methods
void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
const MantidVec& rhsY, const MantidVec& rhsE, MantidVec& YOut, MantidVec& EOut);
void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut);
virtual bool checkCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
virtual bool checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
private:
/// Sets documentation strings for this algorithm
virtual void initDocs();
// Overridden BinaryOperation methods
void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
const MantidVec& rhsY, const MantidVec& rhsE, MantidVec& YOut, MantidVec& EOut);
void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut);
virtual bool checkCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
virtual std::string checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;

/// The name of the first input workspace property for BinaryOperation
virtual std::string inputPropName1() const { return "InputWorkspace1";}
/// The name of the second input workspace property for BinaryOperation
virtual std::string inputPropName2() const { return "InputWorkspace2";}
};
/// The name of the first input workspace property for BinaryOperation
virtual std::string inputPropName1() const { return "InputWorkspace1";}
/// The name of the second input workspace property for BinaryOperation
virtual std::string inputPropName2() const { return "InputWorkspace2";}
};

} // namespace Algorithms
} // namespace Algorithms
} // namespace Mantid

#endif /*MANTID_ALGORITHMS_WEIGHTEDMEAN_H_*/
70 changes: 50 additions & 20 deletions Code/Mantid/Framework/Algorithms/src/BinaryOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,10 @@ namespace Mantid
}

// Check the size compatibility
if (!checkSizeCompatibility(lhs,rhs))
std::string checkSizeCompatibilityResult = checkSizeCompatibility(lhs,rhs);
if (!checkSizeCompatibilityResult.empty())
{
std::ostringstream ostr;
ostr<<"The sizes of the two workspaces " <<
"(" << lhs->getName() << ": " << lhs->getNumberHistograms() << " spectra, blocksize " << lhs->blocksize() << ")"
<< " and " <<
"(" << rhs->getName() << ": " << rhs->getNumberHistograms() << " spectra, blocksize " << rhs->blocksize() << ")"
<< " are not compatible for algorithm "<<this->name();
g_log.error() << ostr.str() << std::endl;
throw std::invalid_argument( ostr.str() );
throw std::invalid_argument(checkSizeCompatibilityResult);
}

return true;
Expand Down Expand Up @@ -366,31 +360,67 @@ namespace Mantid
* must divide be the size of the smaller workspace leaving no remainder
* @param lhs :: the first workspace to compare
* @param rhs :: the second workspace to compare
* @retval true The two workspaces are size compatible
* @retval false The two workspaces are NOT size compatible
* @retval "" The two workspaces are size compatible
* @retval "<reason why not compatible>" The two workspaces are NOT size compatible
*/
bool BinaryOperation::checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const
std::string BinaryOperation::checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const
{
const size_t lhsSize = lhs->size();
const size_t rhsSize = rhs->size();
// A SingleValueWorkspace on the right matches anything
if ( rhsSize == 1 ) return true;
// The rhs must not be smaller than the lhs
if ( lhsSize < rhsSize ) return false;
if ( rhsSize == 1 ) return "";
// The lhs must not be smaller than the rhs
if ( lhsSize < rhsSize ) return "Left hand side smaller than right hand side.";

//Did checkRequirements() tell us that the X histogram size did not matter?
if (!m_matchXSize)
{
//If so, only the vertical # needs to match
return (lhs->getNumberHistograms() == rhs->getNumberHistograms());


if ( lhs->getNumberHistograms() == rhs->getNumberHistograms() )
{
return "";
}
else
{
return "Number of histograms not identical.";
}
}
// Otherwise they must match both ways, or horizontally or vertically with the other rhs dimension=1
if ( rhs->blocksize() == 1 && lhs->getNumberHistograms() == rhs->getNumberHistograms() ) return true;
if ( rhs->blocksize() == 1 && lhs->getNumberHistograms() == rhs->getNumberHistograms() ) return "";
// Past this point, we require the X arrays to match. Note this only checks the first spectrum
if ( !WorkspaceHelpers::matchingBins(lhs,rhs,true) ) return false;
if ( !WorkspaceHelpers::matchingBins(lhs,rhs,true) )
{
return "X arrays must match when performing this operation on a 2D workspaces.";
}

const size_t rhsSpec = rhs->getNumberHistograms();

return ( lhs->blocksize() == rhs->blocksize() && ( rhsSpec==1 || lhs->getNumberHistograms() == rhsSpec ) );
if ( lhs->blocksize() == rhs->blocksize())
{
if ( rhsSpec==1 || lhs->getNumberHistograms() == rhsSpec )
{
return "";
}
else
{
//can't be more specific as if this is reached both failed and only one or both are needed
return "Left and right sides should contain the same amount of spectra or the right side should contian only one spectra.";
}
}
else
{
//blocksize check failed, but still check the number of spectra to see if that was wrong too
if ( rhsSpec==1 || lhs->getNumberHistograms() == rhsSpec )
{
return "Number of y values not equal on left and right sides.";
}
else
{
//can't be more specific as if this is reached both failed and only one or both are needed
return "Number of y values not equal on left and right sides and the right side contained neither only one spectra or the same amount of spectra as the left.";
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace Mantid
* must divide be the size of the smaller workspace leaving no remainder
* @param lhs :: the workspace treated as the lhs to compare
* @param rhs :: the workspace treated as the rhs to compare
* @retval true The two workspaces are size compatible
* @retval false The two workspaces are NOT size compatible
* @retval "" The two workspaces are size compatible
* @retval "<reason why not compatible>" The two workspaces are NOT size compatible
*/
bool CommutativeBinaryOperation::checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const
std::string CommutativeBinaryOperation::checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const
{
// Don't allow this for EventWorkspaces. See for instance Multiply::checkSizeCompatability
if( boost::dynamic_pointer_cast<const DataObjects::EventWorkspace>(lhs) ||
Expand Down
31 changes: 21 additions & 10 deletions Code/Mantid/Framework/Algorithms/src/Divide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,44 +201,55 @@ namespace Mantid
*
* @param lhs :: the first workspace to compare
* @param rhs :: the second workspace to compare
* @retval true The two workspaces are size compatible
* @retval false The two workspaces are NOT size compatible
* @retval "" The two workspaces are size compatible
* @retval "<reason why not compatible>" The two workspaces are NOT size compatible
*/
bool Divide::checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const
std::string Divide::checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const
{
// --- Check for event workspaces - different than workspaces 2D! ---

// A SingleValueWorkspace on the right matches anything
if (rhs->size()==1) return true;
if (rhs->size()==1) return "";

// A SingleValueWorkspace on the left only matches if rhs was single value too. Why are you using mantid to do simple math?!?
if (lhs->size()==1) return false;
if (lhs->size()==1) return "The left side cannot contain a single value if the right side isn't also a single value.";

// If RHS only has one value (1D vertical), the number of histograms needs to match.
// Each lhs spectrum will be divided by that scalar
//std::cout << "rhs->blocksize() " << rhs->blocksize() << std::endl;
if ( rhs->blocksize() == 1 && lhs->getNumberHistograms() == rhs->getNumberHistograms() ) return true;
if ( rhs->blocksize() == 1 && lhs->getNumberHistograms() == rhs->getNumberHistograms() ) return "";

if (m_matchXSize)
{
// Past this point, for a 2D WS operation, we require the X arrays to match. Note this only checks the first spectrum
if ( !WorkspaceHelpers::matchingBins(lhs,rhs,true) ) return false;
if ( !WorkspaceHelpers::matchingBins(lhs,rhs,true) )
{
return "X arrays must match when dividing 2D workspaces.";
}
}

// We don't need to check for matching bins for events. Yay events!
const size_t rhsSpec = rhs->getNumberHistograms();

// If the rhs has a single spectrum, then we can divide. The block size does NOT need to match,
if (rhsSpec == 1) return true;
if (rhsSpec == 1) return "";

// Are we allowing the division by different # of spectra, using detector IDs to match up?
if (m_AllowDifferentNumberSpectra)
{
return true;
return "";
}

// Otherwise, the number of histograms needs to match, but the block size of each does NOT need to match.
return ( lhs->getNumberHistograms() == rhs->getNumberHistograms() );

if ( lhs->getNumberHistograms() == rhs->getNumberHistograms() )
{
return "";
}
else
{
return "Number of histograms not identical.";
}

}

Expand Down

0 comments on commit 3039afc

Please sign in to comment.