From 2f9746ecd6f98bf51e210ddc2b5689d7e87f13cf Mon Sep 17 00:00:00 2001 From: Nick Draper Date: Wed, 20 Aug 2014 14:43:45 +0100 Subject: [PATCH] re #10139 inst parameters listed for detectors --- .../Algorithms/src/SetInstrumentParameter.cpp | 23 ++++++-- .../Geometry/inc/MantidGeometry/IComponent.h | 5 +- .../inc/MantidGeometry/Instrument/Component.h | 12 +++++ .../MantidGeometry/Instrument/DetectorGroup.h | 13 +++++ .../MantidGeometry/Instrument/ParameterMap.h | 2 +- .../Geometry/src/Instrument/Component.cpp | 27 ++++++++++ .../Geometry/src/Instrument/DetectorGroup.cpp | 10 ++++ .../Geometry/src/Instrument/ParameterMap.cpp | 10 +++- .../InstrumentWindowPickTab.cpp | 54 +++++++++++++++++++ .../InstrumentWindowPickTab.h | 1 + 10 files changed, 149 insertions(+), 8 deletions(-) diff --git a/Code/Mantid/Framework/Algorithms/src/SetInstrumentParameter.cpp b/Code/Mantid/Framework/Algorithms/src/SetInstrumentParameter.cpp index 9b6af27c8b1b..454a42e9c989 100644 --- a/Code/Mantid/Framework/Algorithms/src/SetInstrumentParameter.cpp +++ b/Code/Mantid/Framework/Algorithms/src/SetInstrumentParameter.cpp @@ -91,17 +91,20 @@ namespace Algorithms Strings::strip(paramValue); auto inst = ws->getInstrument(); - //set default to whole instrument std::vector dets; - boost::shared_ptr cmpt = inst; + std::vector cmptList; + //set default to whole instrument + cmptList.push_back(inst); + if (!detectorList.empty()) { dets = inst->getDetectors(detectorList); } else if (cmptName.length() > 0) { - //get the first matching cmpt - cmpt = inst->getComponentByName(cmptName); + //get all matching cmpts + cmptList = inst->getAllComponentsWithName(cmptName); + } auto& paramMap = ws->instrumentParameters(); @@ -114,7 +117,17 @@ namespace Algorithms } else { - addParameter(paramMap, cmpt.get(),paramName,paramType,paramValue); + if (cmptList.size() > 0) + { + for (auto it = cmptList.begin(); it != cmptList.end(); ++it) + { + addParameter(paramMap, it->get(),paramName,paramType,paramValue); + } + } + else + { + g_log.warning("Could not find the component requested."); + } } } diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/IComponent.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/IComponent.h index 2f98e3c946be..4e44f39d2bec 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/IComponent.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/IComponent.h @@ -132,6 +132,8 @@ namespace Mantid //@{ /// Return the names of the parameters for this component virtual std::set getParameterNames(bool recursive = true) const = 0; + ///return the parameter names and the component they are from + virtual std::map getParameterNamesByComponent() 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 until proper python export functions are defined @@ -150,7 +152,8 @@ namespace Mantid virtual std::vector getIntParameter(const std::string& pname, bool recursive = true) const = 0; /// Get a parameter defined as a boolean virtual std::vector getBoolParameter(const std::string& pname, bool recursive = true) const = 0; - + ///get a string representation of a parameter + virtual std::string getParameterAsString(const std::string& pname, bool recursive = true) const =0; //@} /** Prints a text representation of itself */ diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/Component.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/Component.h index 2c33bc494baa..f6cd649a2df6 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/Component.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/Component.h @@ -161,6 +161,8 @@ namespace Mantid // one for each type, luckily there won't be too many /// Return the parameter names virtual std::set getParameterNames(bool recursive = true) const; + ///return the parameter names and the component they are from + virtual std::map Component::getParameterNamesByComponent() const; /// Returns a boolean indicating if the component has the named parameter virtual bool hasParameter(const std::string & name, bool recursive = true) const; @@ -254,6 +256,16 @@ namespace Mantid } //@} + std::string getParameterAsString(const std::string& pname, bool recursive = true) const + { + std::string retVal = ""; + if (m_map) + { + retVal = m_map->getString(this, pname, recursive); + } + return retVal; + } + void printSelf(std::ostream&) const; /// Returns the address of the base component diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorGroup.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorGroup.h index ffb7495c6608..8cceaf8df926 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorGroup.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorGroup.h @@ -85,6 +85,8 @@ namespace Mantid // one for each type, luckily there won't be too many /// Return the parameter names virtual std::set getParameterNames(bool recursive = true) const; + ///return the parameter names and the component they are from + virtual std::map getParameterNamesByComponent() 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 @@ -135,6 +137,17 @@ namespace Mantid */ std::vector getBoolParameter(const std::string& pname, bool recursive = true) const; + /** + * Get a string representation of a paramete + * @param pname :: The name of the parameter + * @param recursive :: If true the search will walk up through the parent components + * @returns A empty string as this is not a parameterized component + */ + std::string getParameterAsString(const std::string& pname, bool recursive = true) const + { + return ""; + } + /** returns the detector's group topology if it has been calculated before or invokes the procedure of calculating such topology if it was not */ det_topology getTopology(Kernel::V3D ¢er)const; diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/ParameterMap.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/ParameterMap.h index c1cba73d0b87..bd9fcf4e26e1 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/ParameterMap.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/ParameterMap.h @@ -235,7 +235,7 @@ namespace Geometry } /// Return the value of a parameter as a string - std::string getString(const IComponent* comp,const std::string& name) const; + std::string getString(const IComponent* comp,const std::string& name, bool recursive = false) const; /// Returns a string parameter as vector's first element if exists and an empty vector if it doesn't std::vector getString(const std::string& compName,const std::string& name) const { diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/Component.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/Component.cpp index 700b085dacfe..3686015d5ff4 100644 --- a/Code/Mantid/Framework/Geometry/src/Instrument/Component.cpp +++ b/Code/Mantid/Framework/Geometry/src/Instrument/Component.cpp @@ -493,6 +493,33 @@ namespace Geometry return names; } + /** + * Get the names of the parameters for this component and it's parents. + * @param recursive :: If true, the parameters for all of the parent components are also included + * @returns A map of strings giving the parameter names and the component they are from, warning this contains shared pointers keeping transient objects alive, do not keep longer than needed + */ + std::map Component::getParameterNamesByComponent() const + { + auto retVal = std::map(); + if (!m_map) return retVal; + + std::set names = m_map->names(this); + for (auto itNames = names.begin(); itNames != names.end(); ++itNames) + { + retVal.insert(std::pair(*itNames,this->getComponentID())); + } + + //Walk up the tree and find the parameters attached to the parent components + boost::shared_ptr parent = getParent(); + if( parent ) + { + auto parentNames = parent->getParameterNamesByComponent(); + //this should discard duplicates + retVal.insert(parentNames.begin(), parentNames.end()); + } + return retVal; + } + /** * Returns a boolean indicating if the component has the named parameter * @param name :: The name of the parameter diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/DetectorGroup.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/DetectorGroup.cpp index 93289cbee740..9a2d200b6202 100644 --- a/Code/Mantid/Framework/Geometry/src/Instrument/DetectorGroup.cpp +++ b/Code/Mantid/Framework/Geometry/src/Instrument/DetectorGroup.cpp @@ -343,6 +343,16 @@ namespace Mantid return std::set(); } + /** + * Get the names of the parameters for this component and it's parents. + * @param recursive :: If true, the parameters for all of the parent components are also included + * @returns A map of strings giving the parameter names and the component they are from, warning this contains shared pointers keeping transient objects alive, do not keep longer than needed + */ + std::map DetectorGroup::getParameterNamesByComponent() const + { + return std::map(); + } + /** * Get the bounding box for this group of detectors. It is simply the sum of the bounding boxes of its constituents. * @param boundingBox :: [Out] The resulting bounding box is stored here. diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/ParameterMap.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/ParameterMap.cpp index 77fae890d1c8..ae0c944a7105 100644 --- a/Code/Mantid/Framework/Geometry/src/Instrument/ParameterMap.cpp +++ b/Code/Mantid/Framework/Geometry/src/Instrument/ParameterMap.cpp @@ -833,9 +833,17 @@ namespace Mantid * @param name :: Parameter name * @return string representation of the parameter */ - std::string ParameterMap::getString(const IComponent* comp, const std::string& name) const + std::string ParameterMap::getString(const IComponent* comp, const std::string& name, bool recursive) const { Parameter_sptr param = get(comp,name); + if( recursive ) + { + param = getRecursive(comp,name); + } + else + { + param = get(comp,name); + } if (!param) return ""; return param->asString(); } diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.cpp index 934a0c41bee2..d8cf90e42af7 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.cpp @@ -9,6 +9,7 @@ #include "PeakMarker2D.h" #include "MantidKernel/ConfigService.h" +#include "MantidKernel/DynamicFactory.h" #include "MantidGeometry/Instrument/ParameterMap.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/ITableWorkspace.h" @@ -366,6 +367,8 @@ void InstrumentWindowPickTab::updateSelectionInfo(int detid) xUnits = QString::fromStdString(instrActor->getWorkspace()->getAxis(0)->unit()->caption()); } text += "X units: " + xUnits + '\n'; + // display info about peak overlays + text += getParameterInfo(det); } else { @@ -376,6 +379,8 @@ void InstrumentWindowPickTab::updateSelectionInfo(int detid) // display info about peak overlays text += getNonDetectorInfo(); + + if ( !text.isEmpty() ) { m_selectionInfoDisplay->setText(text); @@ -386,6 +391,55 @@ void InstrumentWindowPickTab::updateSelectionInfo(int detid) } } +/** + * Form a string for output from the components instrument parameters + */ +QString InstrumentWindowPickTab::getParameterInfo(Mantid::Geometry::IComponent_const_sptr comp) +{ + QString text = ""; + std::map > mapCmptToNameVector; + + auto paramNames = comp->getParameterNamesByComponent(); + for (auto itParamName = paramNames.begin(); itParamName != paramNames.end(); ++itParamName) + { + //build the data structure I need Map comp id -> vector of names + std::string paramName = itParamName->first; + Mantid::Geometry::ComponentID paramCompId = itParamName->second; + //attempt to insert this will fail silently if the key already exists + if ( mapCmptToNameVector.find(paramCompId) == mapCmptToNameVector.end() ) + { + mapCmptToNameVector.insert(std::pair >(paramCompId,std::vector())); + } + //get the vector out and add the name + mapCmptToNameVector[paramCompId].push_back(paramName); + } + + //walk out from the selected component + Mantid::Geometry::IComponent_const_sptr paramComp = comp; + while (paramComp) + { + auto& compParamNames = mapCmptToNameVector[paramComp->getComponentID()]; + if (compParamNames.size() > 0) + { + text += QString::fromStdString("\nParameters from: " + paramComp->getName() + "\n"); + std::sort(compParamNames.begin(), compParamNames.end(),Mantid::Kernel::CaseInsensitiveStringComparator()); + for (auto itParamName = compParamNames.begin(); itParamName != compParamNames.end(); ++itParamName) + { + std::string paramName = *itParamName; + //no need to search recursively as we are asking from the matching component + std::string paramValue = paramComp->getParameterAsString(paramName,false); + if (paramValue != "") + { + text += QString::fromStdString(paramName + ": " + paramValue + "\n"); + } + } + } + paramComp = paramComp->getParent(); + } + + return text; +} + /** * Display the miniplot's context menu. */ diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.h b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.h index 82676001f9de..fe48d1a64a72 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.h +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.h @@ -100,6 +100,7 @@ private slots: std::vector* err = NULL); QString getTubeXUnitsName(TubeXUnits unit) const; QString getNonDetectorInfo(); + QString getParameterInfo(Mantid::Geometry::IComponent_const_sptr comp); QColor getShapeBorderColor() const; static double getOutOfPlaneAngle(const Mantid::Kernel::V3D& pos, const Mantid::Kernel::V3D& origin, const Mantid::Kernel::V3D& normal);