diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/Run.h b/Code/Mantid/Framework/API/inc/MantidAPI/Run.h index 424a21ed8aee2eb5fd878b2ca7f143828cbd7ed6..74e4494feb85efa0ec6e264f688a05706b34d35a 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/Run.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/Run.h @@ -128,10 +128,16 @@ namespace Mantid //@} private: + static const int ADDABLES; + static const std::string ADDABLE[]; + /// A pointer to a property manager Kernel::PropertyManager m_manager; /// The name of the proton charge property std::string m_protonChargeName; + + /// Adds all the time series in from one property manager into another + void mergeMergables(Mantid::Kernel::PropertyManager & sum, const Mantid::Kernel::PropertyManager & toAdd); }; /** diff --git a/Code/Mantid/Framework/API/src/Run.cpp b/Code/Mantid/Framework/API/src/Run.cpp index d2a55c607a9923dbfc77d85d150c1770c9e79ad2..38875a4373442a71706dfc99c7d61c1389c348d5 100644 --- a/Code/Mantid/Framework/API/src/Run.cpp +++ b/Code/Mantid/Framework/API/src/Run.cpp @@ -14,6 +14,9 @@ namespace API using namespace Kernel; +const int Run::ADDABLES = 4; +const std::string Run::ADDABLE[ADDABLES] = {"tot_prtn_chrg", "rawfrm", "goodfrm", "dur"}; + //---------------------------------------------------------------------- // Public member functions //---------------------------------------------------------------------- @@ -57,17 +60,82 @@ using namespace Kernel; //----------------------------------------------------------------------------------------------- /** - * Addition operator - * @param rhs :: The object that is being added to this. + * Adds just the properties that are safe to add. All time series are + * merged together and the list of addable properties are added + * @param rhs The object that is being added to this. * @returns A reference to the summed object */ Run& Run::operator+=(const Run& rhs) { - //The propery manager operator will have to handle it - m_manager += rhs.m_manager; + //merge and copy properties where there is no risk of corrupting data + mergeMergables(m_manager, rhs.m_manager); + + // Other properties are added to gether if they are on the approved list + for(int i = 0; i < ADDABLES; ++i ) + { + // get a pointer to the property on the right-handside worksapce + Property * right; + try + { + right = rhs.m_manager.getProperty(ADDABLE[i]); + } + catch (Exception::NotFoundError err) + { + //if it's not there then ignore it and move on + continue; + } + // now deal with the left-handside + Property * left; + try + { + left = m_manager.getProperty(ADDABLE[i]); + } + catch (Exception::NotFoundError err) + { + //no property on the left-handside, create one and copy the right-handside across verbatum + m_manager.declareProperty(right->clone(), ""); + continue; + } + + left->operator+=(right); + + } return *this; } + /** Adds all the time series in the second property manager to those in the first + * @param sum the properties to add to + * @param toAdd the properties to add + */ + void Run::mergeMergables(Mantid::Kernel::PropertyManager & sum, const Mantid::Kernel::PropertyManager & toAdd) + { + // get pointers to all the properties on the right-handside and prepare to loop through them + const std::vector<Property*> inc = toAdd.getProperties(); + std::vector<Property*>::const_iterator end = inc.end(); + for (std::vector<Property*>::const_iterator it=inc.begin(); it != end;++it) + { + const std::string rhs_name = (*it)->name(); + try + { + //now get pointers to the same properties on the left-handside + Property * lhs_prop(sum.getProperty(rhs_name)); + lhs_prop->merge(*it); + +/* TimeSeriesProperty * timeS = dynamic_cast< TimeSeriesProperty * >(lhs_prop); + if (timeS) + { + (*lhs_prop) += (*it); + }*/ + } + catch (Exception::NotFoundError err) + { + //copy any properties that aren't already on the left hand side + Property * copy = (*it)->clone(); + //And we add a copy of that property to *this + sum.declareProperty(copy, ""); + } + } + } //----------------------------------------------------------------------------------------------- /** diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Property.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Property.h index 374069499d188ff41c0a16dfa7fe5772adb2b8d8..097551aa3d54ca253cb4482a8b180940ef8d806e 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/Property.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/Property.h @@ -122,7 +122,7 @@ public: } /// Add to this - virtual Property& operator+=( Property * rhs ); + virtual Property& operator+=( Property const * rhs ); virtual void filterByTime(const Kernel::DateAndTime start, const Kernel::DateAndTime stop); virtual void splitByTime(Kernel::TimeSplitterType& splitter, std::vector< Property * > outputs) const; @@ -135,6 +135,12 @@ public: virtual size_t getMemorySize() const { return sizeof(Property); } + /** Just returns the property (*this) unless overridden + * @return a property with the value + */ + virtual Property& merge( Property * ) + { return *this; } + protected: /// Constructor Property( const std::string& name, const std::type_info& type, const unsigned int direction = Direction::Input); diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h index f3a483d335c1379d2f725f21032314b9fbd94722..864fc056bf8d08084d3fb692095ee8b74aaa32a5 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/PropertyWithValue.h @@ -320,9 +320,9 @@ public: //-------------------------------------------------------------------------------------- ///Add the value of another property - virtual PropertyWithValue& operator+=( Property * right ) + virtual PropertyWithValue& operator+=( Property const * right ) { - PropertyWithValue * rhs = dynamic_cast< PropertyWithValue * >(right); + PropertyWithValue const * rhs = dynamic_cast< PropertyWithValue const * >(right); if (rhs) { diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/TimeSeriesProperty.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/TimeSeriesProperty.h index e880a3edfadf90047207971b63225e67a10dea65..5c70b21f9c87376486fd0f0fc6314faa68d8ab45 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/TimeSeriesProperty.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/TimeSeriesProperty.h @@ -112,11 +112,20 @@ public: return m_propertySeries.size() * (sizeof(TYPE) + sizeof(DateAndTime)); } + /** Just returns the property (*this) unless overridden + * @param rhs a property that is merged in some descendent classes + * @return a property with the value + */ + virtual TimeSeriesProperty& merge(Property * rhs) + { + return operator+=(rhs); + } + //-------------------------------------------------------------------------------------- ///Add the value of another property - virtual TimeSeriesProperty& operator+=( Property * right ) + virtual TimeSeriesProperty& operator+=( Property const * right ) { - TimeSeriesProperty * rhs = dynamic_cast< TimeSeriesProperty * >(right); + TimeSeriesProperty const * rhs = dynamic_cast< TimeSeriesProperty const * >(right); if (rhs) { @@ -131,7 +140,7 @@ public: } //Count the REAL size. - m_size = m_propertySeries.size(); + m_size = static_cast<int>(m_propertySeries.size()); } else @@ -165,7 +174,7 @@ public: } } //Cache the size for later. Any filtered TSP's will have to fend for themselves. - m_size = m_propertySeries.size(); + m_size = static_cast<int>(m_propertySeries.size()); } @@ -493,7 +502,7 @@ public: */ int realSize() const { - return m_propertySeries.size(); + return static_cast<int>(m_propertySeries.size()); } @@ -631,7 +640,7 @@ public: // // Insert the whole list in one go. // m_propertySeries.insert(list.begin(), list.end()); - m_size = m_propertySeries.size(); + m_size = static_cast<int>(m_propertySeries.size()); } //----------------------------------------------------------------------------------------------- diff --git a/Code/Mantid/Framework/Kernel/src/Property.cpp b/Code/Mantid/Framework/Kernel/src/Property.cpp index 9bfdb8487f7fc1720cb7d702a5c4f869cf556531..b0f73398d7344de7db1976daf57b65290531d0e1 100644 --- a/Code/Mantid/Framework/Kernel/src/Property.cpp +++ b/Code/Mantid/Framework/Kernel/src/Property.cpp @@ -165,7 +165,7 @@ void Property::setUnits(std::string unit) * @return the augmented property * @throw NotImplementedError always, since this should have been overridden */ -Property& Property::operator+=( Property * rhs ) +Property& Property::operator+=( Property const * rhs ) { (void) rhs; //Avoid compiler warning std::stringstream msg; @@ -173,7 +173,6 @@ Property& Property::operator+=( Property * rhs ) throw Exception::NotImplementedError(msg.str()); } - //------------------------------------------------------------------------------------------------- /** Filter out a property by time. Will be overridden by TimeSeriesProperty (only) * @param start :: the beginning time to filter from diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp index 3cb38f6cdfd646c45a7e4c62a73f119240c7d12b..42a135603fd777aae72ccd90a8d0454de9747bc6 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp @@ -3338,7 +3338,7 @@ void SANSRunWindow::setNumberPeriods(const int key, const int num) if (num > 0) { - label->setText("/??");//label->setText("/" + QString::number(num)); + label->setText("/" + QString::number(num)); if (userentry->text().isEmpty()) {//default period to analysis is the first one userentry->setText("1"); diff --git a/Code/Mantid/Scripts/SANS/isis_reduction_steps.py b/Code/Mantid/Scripts/SANS/isis_reduction_steps.py index d18e90ee651f1dac8a3426652584a65b483c9d29..473fed50f5d01f6131143dcbad438e25bab2a6b5 100644 --- a/Code/Mantid/Scripts/SANS/isis_reduction_steps.py +++ b/Code/Mantid/Scripts/SANS/isis_reduction_steps.py @@ -98,15 +98,6 @@ class LoadRun(ReductionStep): SpectrumMin=self._spec_min, SpectrumMax=self._spec_max) SANS2D_log_file = mtd[workspace] - - #get rid of these two lines when files store their logs properly - log_file = alg.getPropertyValue("Filename") - base_name = os.path.splitext(log_file)[0] - if base_name.endswith('-add'): - #remove the add files specifier, if it's there - base_name = base_name.rpartition('-add')[0] - SANS2D_log_file = base_name+'.log' - numPeriods = self._find_workspace_num_periods(workspace) #deal with the difficult situation of not reporting the period of single period files