Skip to content

Commit

Permalink
refs #9082 Intermediate checkout
Browse files Browse the repository at this point in the history
Should compile, but copying algorithm is incomplete&needs a bit more thinking.
  • Loading branch information
abuts committed Apr 22, 2014
1 parent 285f66b commit 5977de5
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 142 deletions.
76 changes: 54 additions & 22 deletions Code/Mantid/Framework/Algorithms/src/CopyInstrumentParameters.cpp
Expand Up @@ -81,40 +81,72 @@ void CopyInstrumentParameters::exec()
auto Name1=inst1->getName();
auto Name2=inst2->getName();

// vector of all components contained, in target instrument
std::vector<IComponent_const_sptr> targComponents;
inst2->getChildren(targComponents,true);

auto it = givParams.begin();
for(;it!= givParams.end(); it++)
Geometry::ParameterMap targMap;

//// vector of all components contained in the target instrument
//std::vector<IComponent_const_sptr> targComponents;
//// flattens instrument definition tree
//inst2->getChildren(targComponents,true);
//// multimap of existing instrument parameters
//std::multimap<std::string,IComponent const *> existingComponents;
//for(size_t i=0;i<targComponents.size();i++)
//{
// if (dynamic_cast<IDetector const *>(targComponents[i].get()))
// continue;
// existingComponents.insert(std::pair<std::string,IComponent const *>(targComponents[i]->getFullName(),targComponents[i].get()));
//}

auto it = givParams.begin();
for(;it!= givParams.end(); it++)
{
IComponent * oldComponent=it->first;


const Geometry::IComponent* targComp = 0;

IDetector *pOldDet = dynamic_cast<IDetector *>(oldComponent);
if (pOldDet)
{
detid_t detID = pOldDet->getID();
targComp = inst2->getDetector(detID).get();
if (!targComp)
{
g_log.warning()<<"Target instrument does not have detector with ID "<<detID<<'\n';
continue;
}
}
else
{
auto oldPlace=it->first;
std::string source_name=oldPlace->getFullName();
std::string source_name=oldComponent->getFullName();
size_t nameStart = source_name.find(Name1);
std::string targ_name = source_name.replace(nameStart,nameStart+Name1.size(),Name2);
for(size_t i=0;i<targComponents.size();i++)
//existingComponents.
targComp = inst2->getComponentByName(targ_name).get();
if (!targComp)
{
if(targComponents[i]->getFullName() == targ_name)
auto old_comp_map = oldComponent->getParameterMap();
auto it = old_comp_map->begin();
for(;it!=old_comp_map->end();it++)
{
if (targComponents[i]->isParametrized())
{
//void ParameterMap::copyFromParameterMap(const IComponent* oldComp,
// const IComponent* newComp, const ParameterMap *oldPMap)

targComponents[i]->getParameterMap()->copyFromParameterMap(oldPlace,
targComponents[i].get(), &givParams) ;
}
else
{
}
auto pParam = (*it).second.get();
targMap.add(pParam->type(),inst2.get(),targ_name,pParam->asString());
}
continue;
}

}
// process existing target component


}

// unchanged Copy parameters
m_receivingWorkspace->replaceInstrumentParameters( targMap );

}
else
{
// unchanged Copy parameters
// unchanged Copy parameters
m_receivingWorkspace->replaceInstrumentParameters( givParams );

}
Expand Down
Expand Up @@ -72,8 +72,6 @@ namespace Mantid
virtual IComponent* clone() const=0;
/// Destructor
virtual ~IComponent(){}
//! Returns true if the Component is parametrized (has a parameter map)
virtual bool isParametrized() const = 0;
//! Returns the ComponentID - a unique identifier of the component.
virtual ComponentID getComponentID()const = 0;
//! Assign a parent IComponent. Previous parent link is lost
Expand Down Expand Up @@ -132,7 +130,7 @@ namespace Mantid
virtual std::set<std::string> getParameterNames(bool recursive = true) const = 0;
/// Returns a boolean indicating if the component has the named parameter
virtual bool hasParameter(const std::string & name, bool recursive = true) const = 0;
//Hack untill proper python export functions are defined
//Hack until proper python export functions are defined
virtual std::string getParameterType(const std::string& pname, bool recursive = true)const=0;
// 06/05/2010 MG: Templated virtual functions cannot be defined so we have to resort to
// one for each type, luckily there won't be too many
Expand All @@ -153,7 +151,9 @@ namespace Mantid
/** Prints a text representation of itself
*/
virtual void printSelf(std::ostream&) const = 0;

//! Returns true if the Component is parametrized (has a parameter map)
virtual bool isParametrized() const = 0;
/// Returns pointer to const parameter map
virtual const ParameterMap * getParameterMap()=0;
};

Expand Down
Expand Up @@ -160,9 +160,9 @@ namespace Mantid
/// Set the default type of the instrument view. The possible values are:
/// 3D, CYLINDRICAL_X, CYLINDRICAL_Y, CYLINDRICAL_Z, SPHERICAL_X, SPHERICAL_Y, SPHERICAL_Z
void setDefaultView(const std::string& type);
/// Retrieves from which side the instrument to be viewed from when the instrument viewer first starts, possiblities are "Z+, Z-, X+, ..."
/// Retrieves from which side the instrument to be viewed from when the instrument viewer first starts, possibilities are "Z+, Z-, X+, ..."
std::string getDefaultAxis() const {return m_defaultViewAxis;}
/// Retrieves from which side the instrument to be viewed from when the instrument viewer first starts, possiblities are "Z+, Z-, X+, ..."
/// Retrieves from which side the instrument to be viewed from when the instrument viewer first starts, possibilities are "Z+, Z-, X+, ..."
void setDefaultViewAxis(const std::string &axis) {m_defaultViewAxis = axis;}
// Allow access by index
using CompAssembly::getChild;
Expand Down Expand Up @@ -244,7 +244,7 @@ namespace Mantid
const IComponent* m_sourceCache;

/// Hold a list of places where a chopper can be situated
/// A pointer so that parameterized intruments are still fast to create.
/// A pointer so that parameterized instruments are still fast to create.
std::vector<const ObjComponent*> * m_chopperPoints;

/// Purpose to hold copy of samplePos component. For now assumed to be just one component
Expand All @@ -266,7 +266,7 @@ namespace Mantid

/// Stores the default type of the instrument view: 3D or one of the "unwrapped"
std::string m_defaultView;
/// Stores from which side the instrument will be viewed from, initially in the instrument viewer, possiblities are "Z+, Z-, X+, ..."
/// Stores from which side the instrument will be viewed from, initially in the instrument viewer, possibilities are "Z+, Z-, X+, ..."
std::string m_defaultViewAxis;

/// Pointer to the "real" instrument, for parametrized Instrument
Expand Down
Expand Up @@ -92,7 +92,6 @@ namespace Mantid

IComponent* clone() const;

bool isParametrized() const;

//! Returns the ComponentID - a unique identifier of the component.
ComponentID getComponentID()const;
Expand Down Expand Up @@ -186,7 +185,7 @@ namespace Mantid
}

/**
* Get a parameter's type -- this is HACK untill Python can export property regardless of the property type
* Get a parameter's type -- this is HACK until Python can export property regardless of the property type
* @param pname :: The name of the parameter
* @param recursive :: If true the search will walk up through the parent components
* @returns std::string describing parameter type or empty string if the type is not found
Expand Down Expand Up @@ -268,17 +267,17 @@ namespace Mantid
virtual void writeXML(Poco::XML::XMLWriter & writer) const;
virtual void appendXML(std::ostream& xmlStream) const;

bool isParametrized() const;
virtual const ParameterMap * getParameterMap(){return m_map;}
protected:
/// Parent component in the tree
const IComponent* m_parent;
/// The base component - this is the unmodifed component (without the parameters). Stored
/// The base component - this is the unmodified component (without the parameters). Stored
/// as a pointer to Component so that it's properties can be accessed without casting each time
const Component* m_base;
/// A const pointer to a const ParameterMap containing the parameters
/// A pointer to const ParameterMap containing the parameters
const ParameterMap *m_map;
/// Flag to determine if component is parameterized
bool m_isParametrized;


//! Name of the component
std::string m_name;
Expand All @@ -297,7 +296,7 @@ namespace Mantid
template <class TYPE>
std::vector<TYPE> getParameter(const std::string & p_name, bool recursive) const
{
if (m_isParametrized)
if (m_map)
{
Parameter_sptr param = Parameter_sptr(); //Null shared pointer
if( recursive )
Expand Down Expand Up @@ -325,7 +324,7 @@ namespace Mantid
}

protected:
// This method is only required for efficent caching of parameterized components and
// This method is only required for efficient caching of parameterized components and
// should not form part of the interface. It is an implementation detail.
template<typename T> friend class ComponentPool;
/// Swap the current references to the un-parameterized component and parameter map for new ones
Expand Down
Expand Up @@ -143,6 +143,8 @@ namespace Mantid
/// Return separator for list of names of detectors
std::string getNameSeparator() const { return ";"; }

/// returns pointer to the const parameter map
virtual const ParameterMap * getParameterMap();
protected:
/// The ID of this effective detector
int m_id;
Expand All @@ -153,7 +155,7 @@ namespace Mantid
/// The collection of grouped detectors
DetCollection m_detectors;
/** the parameter describes the topology of the detector's group namely if detectors form a box or a ring.
* the topology is undefined on construction and caclulated on first request */
* the topology is undefined on construction and calculated on first request */
mutable det_topology group_topology;
/// group centre is the geometrical centre of the detectors group calculated when the calculate group topology is invoked
mutable Kernel::V3D groupCentre;
Expand Down
Expand Up @@ -288,7 +288,7 @@ namespace Geometry

/// internal parameter map instance
pmap m_map;
/// internal cache map instance for cached postition values
/// internal cache map instance for cached position values
mutable Kernel::Cache<const ComponentID, Kernel::V3D > m_cacheLocMap;
/// internal cache map instance for cached rotation values
mutable Kernel::Cache<const ComponentID, Kernel::Quat > m_cacheRotMap;
Expand Down

0 comments on commit 5977de5

Please sign in to comment.