Skip to content

Commit

Permalink
Merge pull request #18831 from mantidproject/18390_improved_fix
Browse files Browse the repository at this point in the history
Avoid synchronization issues with ParameterMap::setDetectorInfo.
  • Loading branch information
peterfpeterson committed Feb 15, 2017
2 parents 39286bd + 55d4c07 commit 09b6749
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
9 changes: 7 additions & 2 deletions Framework/API/src/ExperimentInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ ExperimentInfo::ExperimentInfo()
: m_moderatorModel(), m_choppers(), m_sample(new Sample()),
m_run(new Run()), m_parmap(new ParameterMap()),
sptr_instrument(new Instrument()),
m_detectorInfo(boost::make_shared<Beamline::DetectorInfo>(0)) {}
m_detectorInfo(boost::make_shared<Beamline::DetectorInfo>(0)) {
m_parmap->setDetectorInfo(m_detectorInfo);
}

/**
* Constructs the object from a copy if the input. This leaves the new mutex
Expand Down Expand Up @@ -208,12 +210,13 @@ void ExperimentInfo::setInstrument(const Instrument_const_sptr &instr) {
m_detectorInfoWrapper = nullptr;
if (instr->isParametrized()) {
sptr_instrument = instr->baseInstrument();
m_parmap = instr->getParameterMap();
m_parmap = boost::make_shared<ParameterMap>(*instr->getParameterMap());
} else {
sptr_instrument = instr;
m_parmap = boost::make_shared<ParameterMap>();
}
m_detectorInfo = makeDetectorInfo(*sptr_instrument, *instr);
m_parmap->setDetectorInfo(m_detectorInfo);
// Detector IDs that were previously dropped because they were not part of the
// instrument may now suddenly be valid, so we have to reinitialize the
// detector grouping. Also the index corresponding to specific IDs may have
Expand Down Expand Up @@ -404,6 +407,7 @@ void ExperimentInfo::replaceInstrumentParameters(
m_spectrumInfoWrapper = nullptr;
m_detectorInfoWrapper = nullptr;
this->m_parmap.reset(new ParameterMap(pmap));
m_parmap->setDetectorInfo(m_detectorInfo);
}

/**
Expand All @@ -418,6 +422,7 @@ void ExperimentInfo::swapInstrumentParameters(Geometry::ParameterMap &pmap) {
m_spectrumInfoWrapper = nullptr;
m_detectorInfoWrapper = nullptr;
this->m_parmap->swap(pmap);
m_parmap->setDetectorInfo(m_detectorInfo);
}

/**
Expand Down
5 changes: 0 additions & 5 deletions Framework/API/src/MatrixWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ MatrixWorkspace::MatrixWorkspace(const MatrixWorkspace &other)
m_isCommonBinsFlag = other.m_isCommonBinsFlag;
m_masks = other.m_masks;
// TODO: Do we need to init m_monitorWorkspace?

// This call causes copying of m_parmap (ParameterMap). The constructor of
// ExperimentInfo just kept a shared_ptr to the same map as in other, which
// is not enough as soon as the maps in one of the workspaces it edited.
instrumentParameters();
}

/// Destructor
Expand Down
2 changes: 0 additions & 2 deletions Framework/Geometry/src/Instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,8 +1235,6 @@ const Beamline::DetectorInfo &Instrument::detectorInfo() const {
/// Only for use by ExperimentInfo. Sets the pointer to the DetectorInfo.
void Instrument::setDetectorInfo(
boost::shared_ptr<const Beamline::DetectorInfo> detectorInfo) {
if (m_map_nonconst)
m_map_nonconst->setDetectorInfo(detectorInfo);
m_detectorInfo = std::move(detectorInfo);
}
namespace Conversion {
Expand Down
5 changes: 1 addition & 4 deletions Framework/Geometry/src/Instrument/ParameterMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,10 +1165,7 @@ const Beamline::DetectorInfo &ParameterMap::detectorInfo() const {
/// Only for use by ExperimentInfo. Sets the pointer to the DetectorInfo.
void ParameterMap::setDetectorInfo(
boost::shared_ptr<const Beamline::DetectorInfo> detectorInfo) {
if (detectorInfo != m_detectorInfo) {
PARALLEL_CRITICAL(ParameterMap_setDetectorInfo)
m_detectorInfo = std::move(detectorInfo);
}
m_detectorInfo = std::move(detectorInfo);
}

} // Namespace Geometry
Expand Down

0 comments on commit 09b6749

Please sign in to comment.