Skip to content

Commit

Permalink
refs #9082 fixed problem with detector in instrument ParameterMap
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Apr 24, 2014
1 parent 57e839e commit 2976949
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
Expand Up @@ -121,12 +121,13 @@ void CopyInstrumentParameters::exec()
size_t nameStart = source_name.find(Name1);
std::string targ_name = source_name.replace(nameStart,nameStart+Name1.size(),Name2);
//existingComponents.
targComp = inst2->getComponentByName(targ_name).get();
if (!targComp)
auto spTargComp = inst2->getComponentByName(targ_name);
if (!spTargComp)
{
g_log.warning()<<"Target instrument does not have component with full name "<<targ_name<<'\n';
g_log.warning()<<"Target instrument does not have component with full name: "<<targ_name<<'\n';
continue;
}
targComp = spTargComp->getBaseComponent();
}
// merge maps for existing target component
auto param = it->second.get();
Expand Down
Expand Up @@ -74,6 +74,8 @@ namespace Mantid
virtual ~IComponent(){}
//! Returns the ComponentID - a unique identifier of the component.
virtual ComponentID getComponentID()const = 0;
//! Returns const pointer to base component if this component is parametrized or pointer to itself if not. Currently is the same as getComponentID bar const cast;
virtual IComponent const * getBaseComponent()const = 0;
//! Assign a parent IComponent. Previous parent link is lost
virtual void setParent(IComponent*)= 0;
//! Return a pointer to the current parent.
Expand Down
Expand Up @@ -95,6 +95,8 @@ namespace Mantid

//! Returns the ComponentID - a unique identifier of the component.
ComponentID getComponentID()const;
//! Returns const pointer to base component if this component is parametrized or pointer to itself if not. Currently is the same as getComponentID bar const cast;
IComponent const * Component::getBaseComponent()const;

//! Assign a parent IComponent. Previous parent link is lost
void setParent(IComponent*);
Expand Down
Expand Up @@ -142,6 +142,10 @@ namespace Mantid

/// Return separator for list of names of detectors
std::string getNameSeparator() const { return ";"; }
/** Returns const pointer to itself. This currently (2914/04/24) contradicts the logic behind getComponentID overload, so CopyInstrumentParameters will fail on
grouped instrument but it is something TO DO: */
virtual IComponent const * getBaseComponent()const
{ return const_cast<const DetectorGroup*>(this);}
protected:
/// The ID of this effective detector
int m_id;
Expand Down
10 changes: 10 additions & 0 deletions Code/Mantid/Framework/Geometry/src/Instrument/Component.cpp
Expand Up @@ -100,8 +100,18 @@ namespace Geometry
return ComponentID(const_cast<Component*>(m_base));
else
return ComponentID(const_cast<Component*>(this));

}

const IComponent * Component::getBaseComponent()const
{
if (m_map)
return const_cast<const Component*>(m_base);
else
return const_cast<const Component*>(this);
}


//-------------------------------------------------------------------------------
/** Set the parent. Previous parenting is lost.
* @param comp :: the parent Component
Expand Down

0 comments on commit 2976949

Please sign in to comment.