コード例 #1
0
ファイル: ParameterMap.cpp プロジェクト: spaceyatom/mantid
/**Return a const iterator pointing to a named parameter of a given type.
 * @param comp :: Component to which parameter is related
 * @param name :: Parameter name
 * @param type :: An optional type string. If empty, any type is returned
 * @returns The iterator parameter of the given type if it exists or a NULL
 * shared pointer if not
*/
component_map_cit ParameterMap::positionOf(const IComponent *comp,
                                           const char *name,
                                           const char *type) const {
  pmap_cit result = m_map.end();
  if (!comp)
    return result;
  const bool anytype = (strlen(type) == 0);
  if (!m_map.empty()) {
    const ComponentID id = comp->getComponentID();
    pmap_cit it_found = m_map.find(id);
    if (it_found != m_map.end()) {
      pmap_cit itr = m_map.lower_bound(id);
      pmap_cit itr_end = m_map.upper_bound(id);
      for (; itr != itr_end; ++itr) {
        Parameter_sptr param = itr->second;
        if (boost::iequals(param->nameAsCString(), name) &&
            (anytype || param->type() == type)) {
          result = itr;
          break;
        }
      }
    }
  }
  return result;
}
コード例 #2
0
ファイル: ParameterMap.cpp プロジェクト: spaceyatom/mantid
/**
 * Return the value of a parameter as a string
 * @param comp :: Component to which parameter is related
 * @param name :: Parameter name
 * @param recursive :: Whether to travel up the instrument tree if not found at
 * this level
 * @return string representation of the parameter
 */
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();
}
コード例 #3
0
ファイル: Component.cpp プロジェクト: nimgould/mantid
 /**
 * Get a parameter's short description
 * Only parameterized component can have description
 *
 * @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 if such description is defined
 * or empty string if not.
 */
 std::string Component::getParamShortDescription(const std::string &pname,
   bool recursive) const {
     if (!m_map){ // no tooltips for non-parameterized components
       return std::string("");
     }
     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 param->getShortDescription();
     else
       return std::string("");
 }
コード例 #4
0
/**
 * Returns the value associated to a parameter name in the IDF
 * @param parameterName :: parameter name in the IDF
 * @return the value associated to the parameter name
 */
std::string DetectorEfficiencyCorUser::getValFromInstrumentDef(
    const std::string &parameterName) {

  const ParameterMap &pmap = m_inputWS->constInstrumentParameters();
  Instrument_const_sptr instrument = m_inputWS->getInstrument();
  Parameter_sptr par =
      pmap.getRecursive(instrument->getChild(0).get(), parameterName);
  if (par) {
    std::string ret = par->asString();
    g_log.debug() << "Parsed parameter " << parameterName << ": " << ret
                  << "\n";
    return ret;
  } else {
    throw Kernel::Exception::InstrumentDefinitionError(
        "There is no <" + parameterName + "> in the instrument definition!");
  }
}
コード例 #5
0
 /** FASTER LOOKUP in multithreaded loops. Return a named parameter
  * @param comp :: Component to which parameter is related
  * @param name :: Parameter name
  * @returns The named parameter if it exists or a NULL shared pointer if not
  */
 Parameter_sptr ParameterMap::get(const IComponent* comp, const char* name) const
 {
   if( m_map.empty() ) return Parameter_sptr();
   const ComponentID id = comp->getComponentID();
   pmap_cit it_found = m_map.find(id);
   if (it_found == m_map.end())
   {
     return Parameter_sptr();
   }
   pmap_cit itr = m_map.lower_bound(id);
   pmap_cit itr_end = m_map.upper_bound(id);
   for( ; itr != itr_end; ++itr )
   {
     Parameter_sptr param = itr->second;
     if( strcmp(param->nameAsCString(), name) == 0 )
     {
       return param;
     }
   }
   return Parameter_sptr();
 }
コード例 #6
0
ファイル: ParameterMap.cpp プロジェクト: spaceyatom/mantid
/** Look for a parameter in the given component by the type of the parameter.
* @param comp :: Component to which parameter is related
* @param type :: Parameter type
* @returns The typed parameter if it exists or a NULL shared pointer if not
*/
Parameter_sptr ParameterMap::getByType(const IComponent *comp,
                                       const std::string &type) const {
  Parameter_sptr result = Parameter_sptr();
  PARALLEL_CRITICAL(m_mapAccess) {
    if (!m_map.empty()) {
      const ComponentID id = comp->getComponentID();
      pmap_cit it_found = m_map.find(id);
      if (it_found != m_map.end()) {
        if (it_found->first) {
          pmap_cit itr = m_map.lower_bound(id);
          pmap_cit itr_end = m_map.upper_bound(id);
          for (; itr != itr_end; ++itr) {
            Parameter_sptr param = itr->second;
            if (boost::iequals(param->type(), type)) {
              result = param;
              break;
            }
          }
        } // found->firdst
      }   // it_found != m_map.end()
    }     //!m_map.empty()
  }       // PARALLEL_CRITICAL(m_map_access)
  return result;
}
コード例 #7
0
ファイル: ParameterMap.cpp プロジェクト: spaceyatom/mantid
/** Create or adjust "pos" parameter for a component
 * Assumed that name either equals "x", "y" or "z" otherwise this
 * method will not add or modify "pos" parameter
 * @param comp :: Component
 * @param name :: name of the parameter
 * @param value :: value
 * @param pDescription :: a pointer (may be NULL) to a string, containing
 * parameter's
 * description. If provided, the contents of the string is copied to the
 * parameters
 * memory
  */
void ParameterMap::addPositionCoordinate(
    const IComponent *comp, const std::string &name, const double value,
    const std::string *const pDescription) {
  Parameter_sptr param = get(comp, pos());
  V3D position;
  if (param) {
    // so "pos" already defined
    position = param->value<V3D>();
  } else {
    // so "pos" is not defined - therefore get position from component
    position = comp->getPos();
  }

  // adjust position

  if (name.compare(posx()) == 0)
    position.setX(value);
  else if (name.compare(posy()) == 0)
    position.setY(value);
  else if (name.compare(posz()) == 0)
    position.setZ(value);
  else {
    g_log.warning() << "addPositionCoordinate() called with unrecognized "
                       "coordinate symbol: " << name;
    // set description if one is provided
    if (pDescription) {
      param->setDescription(*pDescription);
    }
    return;
  }

  // clear the position cache
  clearPositionSensitiveCaches();
  // finally add or update "pos" parameter
  addV3D(comp, pos(), position, pDescription);
}
コード例 #8
0
    /** SLOWER LOOKUP in multithreaded loops. Return a named parameter of a given type
     * @param comp :: Component to which parameter is related
     * @param name :: Parameter name
     * @param type :: An optional type string
     * @returns The named parameter of the given type if it exists or a NULL shared pointer if not
     */
    Parameter_sptr ParameterMap::get(const IComponent* comp, const std::string& name, 
                                     const std::string & type) const
    {
      if( m_map.empty() ) return Parameter_sptr();
      const ComponentID id = comp->getComponentID();
      pmap_cit it_found = m_map.find(id);
      if (it_found == m_map.end())
      {
        return Parameter_sptr();
      }
      pmap_cit itr = m_map.lower_bound(id);
      pmap_cit itr_end = m_map.upper_bound(id);

      const bool anytype = type.empty();
      for( ; itr != itr_end; ++itr )
      {
        Parameter_sptr param = itr->second;
        if( param->name() == name && (anytype || param->type() == type) )
        {
          return param;
        }
      }
      return Parameter_sptr();
    }
コード例 #9
0
 /**  
  * Return the value of a parameter as a string
  * @param comp :: Component to which parameter is related
  * @param name :: Parameter name
  * @return string representation of the parameter
  */
 std::string ParameterMap::getString(const IComponent* comp, const std::string& name)
 {
   Parameter_sptr param = get(comp,name);
   if (!param) return "";
   return param->asString();
 }
コード例 #10
0
    /** Create or adjust "rot" parameter for a component
     * Assumed that name either equals "rotx", "roty" or "rotz" otherwise this 
     * method will not add/modify "rot" parameter
     * @param comp :: Component
     * @param name :: Parameter name
     * @param deg :: Parameter value in degrees
    */
    void ParameterMap::addRotationParam(const IComponent* comp,const std::string& name, const double deg)
    {
      Parameter_sptr param = get(comp,"rot");
      Quat quat;

      Parameter_sptr paramRotX = get(comp,"rotx");
      Parameter_sptr paramRotY = get(comp,"roty");
      Parameter_sptr paramRotZ = get(comp,"rotz");
      double rotX, rotY, rotZ;

      if ( paramRotX )
        rotX = paramRotX->value<double>();
      else
        rotX = 0.0;

      if ( paramRotY )
        rotY = paramRotY->value<double>();
      else
        rotY = 0.0;

      if ( paramRotZ )
        rotZ = paramRotZ->value<double>();
      else
        rotZ = 0.0;
        

      // adjust rotation

      if ( name.compare("rotx")==0 )
      {
        if (paramRotX)
          paramRotX->set(deg);
        else
          addDouble(comp, "rotx", deg);

        quat = Quat(deg,V3D(1,0,0))*Quat(rotY,V3D(0,1,0))*Quat(rotZ,V3D(0,0,1));
      }
      else if ( name.compare("roty")==0 )
      {
        if (paramRotY)
          paramRotY->set(deg);
        else
          addDouble(comp, "roty", deg);

        quat = Quat(rotX,V3D(1,0,0))*Quat(deg,V3D(0,1,0))*Quat(rotZ,V3D(0,0,1));
      }
      else if ( name.compare("rotz")==0 )
      {
        if (paramRotZ)
          paramRotZ->set(deg);
        else
          addDouble(comp, "rotz", deg);

        quat = Quat(rotX,V3D(1,0,0))*Quat(rotY,V3D(0,1,0))*Quat(deg,V3D(0,0,1));
      }
      else
      {
        g_log.warning() << "addRotationParam() called with unrecognised coordinate symbol: " << name;
        return;
      }

      //clear the position cache
      clearCache();

      // finally add or update "pos" parameter
      if (param)
        param->set(quat);
      else
        addQuat(comp, "rot", quat);
    }