Skip to content

Commit

Permalink
refs #6667 Exported parameter type from the parameter map
Browse files Browse the repository at this point in the history
Very ugly done, as python should be able to retrieve the value and type together. But can not find better way at the moment.
  • Loading branch information
abuts committed Jun 5, 2013
1 parent a3ad112 commit 6fa81f4
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ 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
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
/// Get a parameter defined as a double
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,39 @@ namespace Mantid
return getParameter<double>(pname, recursive);
}

/**
* Get a parameter's type -- this is HACK untill Python can export property regardless of type properly
* @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
*/
std::string getParameterType(const std::string& pname, bool recursive = true)const
{
Parameter_sptr param = Parameter_sptr(); //Null shared pointer
if( recursive )
{
param = m_map->getRecursive(this, pname);
}
else
{
param = m_map->get(this, pname);
}
if(param)
return std::string(param->type());
else
return std::string("");
}
/**
* Get a parameter defined as a bool
* @param pname :: The name of the parameter
* @param recursive :: If true the search will walk up through the parent components
* @returns A list of values
*/
std::vector<bool> getBoolParameter(const std::string& pname, bool recursive = true) const
{
return getParameter<bool>(pname, recursive);
}

/**
* Get a parameter defined as a Kernel::V3D
* @param pname :: The name of the parameter
Expand Down Expand Up @@ -224,6 +257,7 @@ namespace Mantid
virtual void writeXML(Poco::XML::XMLWriter & writer) const;
virtual void appendXML(std::ostream& xmlStream) const;


protected:
/// Parent component in the tree
const IComponent* m_parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ namespace Mantid
virtual std::set<std::string> getParameterNames(bool recursive = true) const;
/// Returns a boolean indicating whether the parameter exists or not
bool hasParameter(const std::string & name, bool recursive = true) const;
// Hack used untill Geomertry can not exprot different types parematers properly
std::string getParameterType(const std::string & name, bool recursive = true) const;
/**
* Get a parameter defined as a double
* @param pname :: The name of the parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace Geometry

}


/** Empty constructor
* Create a component with null parent
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ namespace Mantid
(void) name; //Avoid compiler warning
return false;
}
/** Detectors group assumed to be non-parameterized */
std::string DetectorGroup::getParameterType(const std::string & /*name*/, bool /*recursive = true*/) const
{
return std::string("");
}

/// Default implementation
std::vector<double> DetectorGroup::getNumberParameter(const std::string&, bool) const
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/Geometry/test/ComponentTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class ComponentTest : public CxxTest::TestSuite
TS_ASSERT(ancs.size() == 1);
TS_ASSERT_EQUALS(ancs[0]->getName(), parent.getName());
TS_ASSERT(ancs[0]->isParametrized());

std::string type=ancs[0]->getParameterType("Child");
}

void testGetFullName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ namespace
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getParameterNames,Component::getParameterNames,0,1);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_hasParameter,Component::hasParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getNumberParameter,Component::getNumberParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getBoolParameter,Component::getBoolParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getPositionParameter,Component::getPositionParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getRotationParameter,Component::getRotationParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getStringParameter,Component::getStringParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getParameterType,Component::getParameterType,1,2);


}

void export_Component()
Expand All @@ -23,9 +27,19 @@ void export_Component()
.def("getParameterNames", &Component::getParameterNames, Component_getParameterNames())
.def("hasParameter", &Component::hasParameter, Component_hasParameter())
.def("getNumberParameter", &Component::getNumberParameter, Component_getNumberParameter())
.def("getBoolParameter", &Component::getBoolParameter, Component_getBoolParameter())
.def("getPositionParameter", &Component::getPositionParameter, Component_getPositionParameter())
.def("getRotationParameter", &Component::getRotationParameter, Component_getRotationParameter())
.def("getStringParameter", &Component::getStringParameter, Component_getStringParameter())
// HACK -- python should return parameters regardless of type. this is untill rows below this do not work
.def("getParameterType", &Component::getParameterType, Component_getParameterType())

.def("getParameter", &Component::getNumberParameter, Component_getNumberParameter())
.def("getParameter", &Component::getBoolParameter, Component_getBoolParameter())
.def("getParameter", &Component::getStringParameter, Component_getStringParameter())
.def("getParameter", &Component::getPositionParameter, Component_getPositionParameter())
.def("getParameter", &Component::getRotationParameter, Component_getRotationParameter())

;

}
Expand Down
10 changes: 5 additions & 5 deletions Code/Mantid/instrument/MAPS_Parameters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
</parameter>

<!-- Setting diag to reject zero backgrounds -->
<parameter name="diag_samp_zero">
<parameter name="diag_samp_zero" type="bool">
<value val="False"/>
</parameter>

Expand Down Expand Up @@ -243,17 +243,17 @@
<!-- List of the words which can be used as a command line arguments to define reducer keywords
the form is reducer_keword1=synonim1=synonim2=synonim3;reducer_keword1=synonim1a
each synonims met in command line are converted into appropriate reducer keyword
-->
<parameter name="synonims" type="string">
<value> val="normalise_method=norm_method;
<value val="normalise_method=norm_method;
fix_ei=fixei;
save_formats=save_format;
sum_runs=sum;
wb_integr_range=detector_van_range;
van_mass=vanadium-mass"
</value>
/>
</parameter>
-->

<!-- -->
</component-link>

Expand Down
20 changes: 14 additions & 6 deletions Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ def setup_mtd_instrument(self, workspace = None):
except:
self.instrument = None
raise RuntimeError('Cannot load instrument for prefix "%s"' % self.instr_name)
self.help();
#instr_pattern = os.path.join(idf_dir,self.instr_name + '*_Definition.xml')
#idf_files = glob.glob(instr_pattern)
#if len(idf_files) > 0:
Expand Down Expand Up @@ -842,7 +843,10 @@ def init_idf_params(self):
def get_default_parameter(self, name):
if self.instrument is None:
raise ValueError("Cannot init default parameter, instrument has not been loaded.")
values = self.instrument.getNumberParameter(name)
try :
values = self.instrument.getParameter(name)
except :
pass
if len(values) != 1:
raise ValueError('Instrument parameter file does not contain a definition for "%s". Cannot continue' % name)
return values[0]
Expand All @@ -852,7 +856,8 @@ def get_default_parameter_and_type(self,name):
"""
if self.instrument is None:
raise ValueError("Cannot init default parameter, instrument has not been loaded.")
values = self.instrument.getNumberParameter(name)

values = self.instrument.getParameter(name)
if len(values) != 1 :
values = self.instrument.getStringParameter(name)
if len(values) != 1 :
Expand Down Expand Up @@ -881,10 +886,13 @@ def help(self,keyword=None) :

if keyword==None :
par_names = self.instrument.getParameterNames()
print "****: ***************************************************************************** ";
print "****: There are ", len(par_names), "default reduction parameters availible, namely: ";
for i in xrange(0,len(par_names),4):
print "****: {0}\t {1}\t {2}\t {3}\n".format(par_names[i],par_names[i+1],par_names[i+2],par_names[i+3]),
print "****: ***************************************************************************** "
print "****: There are ", len(par_names), " reduction parameters availible to change, namely: "
for i in xrange(0,len(par_names),1):
#print "****: {0}\t {1}\t {2}\t {3}\n".format(par_names[i],par_names[i+1],par_names[i+2],par_names[i+3]),
print par_names[i],
print type(self.instrument.getParameterType(par_names[i])),
print self.instrument.getParameterType(par_names[i])
print "****:"
print "****: type help(parameter_name) to get help on a parameter with specified name"
print "****: ***************************************************************************** ";
Expand Down

0 comments on commit 6fa81f4

Please sign in to comment.