当前位置: 首页>>代码示例>>C++>>正文


C++ GModelPar::read方法代码示例

本文整理汇总了C++中GModelPar::read方法的典型用法代码示例。如果您正苦于以下问题:C++ GModelPar::read方法的具体用法?C++ GModelPar::read怎么用?C++ GModelPar::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GModelPar的用法示例。


在下文中一共展示了GModelPar::read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: read_scales

/***********************************************************************//**
 * @brief Read instrument scales from XML element
 *
 * @param[in] xml XML source element.
 *
 * Reads the instrument scale factors from a tag with the following format
 *
 *      <scaling>
 *         <instrument name="LAT" scale="1.0" min="0.1" max="10.0" value="1.0" free="0"/>
 *         <instrument name="CTA" scale="1.0" min="0.1" max="10.0" value="0.5" free="0"/>
 *      </scaling>
 *
 * The instrument name is case sensitive, but any leading and trailing white
 * space will be removed.
 *
 * If no scaling tag is found, all instrument scale factors will be cleared.
 ***************************************************************************/
void GModel::read_scales(const GXmlElement& xml)
{
    // Clear any existing scales
    m_scales.clear();

    // Continue only if there is a <scaling> tag
    if (xml.elements("scaling") != 0) {

        // Get pointer on first instrument scale factors
        const GXmlElement* scales = xml.element("scaling", 0);

        // Determine number of scale factors
        int nscales = scales->elements("instrument");

        // Read all scale factors
        for (int i = 0; i < nscales; ++i) {
            const GXmlElement* par = scales->element("instrument", i);
            GModelPar scale;
            scale.read(*par);
            scale.name(gammalib::strip_whitespace(par->attribute("name")));
            m_scales.push_back(scale);
        }

    }

    // Return
    return;
}
开发者ID:TarekHC,项目名称:gammalib,代码行数:45,代码来源:GModel.cpp

示例2: read

/***********************************************************************//**
 * @brief Read model from XML element
 *
 * @param[in] xml XML element.
 *
 * @exception GException::invalid_value
 *            Model definition requires at least one node.
 *
 * Read the COMPTEL DRB fitting model from an XML element.
 *
 * The model is composed of nodes that define the normalization value as
 * function of Phibar value. The following XML file syntax is expected:
 *
 *     <source name="Background" type="DRBFitting" instrument="COM">
 *       <node>
 *         <parameter name="Phibar"        .../>
 *         <parameter name="Normalization" .../>
 *       </node>
 *       ...
 *       <node>
 *         <parameter name="Phibar"        .../>
 *         <parameter name="Normalization" .../>
 *       </node>
 *     </source>
 ***************************************************************************/
void GCOMModelDRBFitting::read(const GXmlElement& xml)
{
    // Free space for nodes
    m_phibars.clear();
    m_values.clear();

    // Get number of nodes from XML file
    int nodes = xml.elements("node");

    // Throw an error if there are no nodes
    if (nodes < 1) {
        std::string msg = "DRB fitting model requires at least one Phibar "
                          "node. Please correct XML format.";
        throw GException::invalid_value(G_READ, msg);
    }

    // Loop over all nodes
    for (int i = 0; i < nodes; ++i) {

        // Allocate node parameters
        GModelPar phibar;
        GModelPar normalization;
            
        // Get node
        const GXmlElement* node = xml.element("node", i);

        // Read Phibar parameter
        const GXmlElement* par = gammalib::xml_get_par(G_READ, *node, "Phibar");
        phibar.read(*par);

        // Read Normalization parameter
        par = gammalib::xml_get_par(G_READ, *node, "Normalization");
        normalization.read(*par);

        // Set parameter names
        std::string phibar_name        = "Phibar layer "+gammalib::str(i);
        std::string normalization_name = "Scale factor "+gammalib::str(i);

        // Set Phibar attributes
        phibar.name(phibar_name);
        phibar.unit("deg");
        phibar.has_grad(false);

        // Set normalization attributes
        normalization.name(normalization_name);
        normalization.unit("");
        normalization.has_grad(true);

        // Push node parameters on list
        m_phibars.push_back(phibar);
        m_values.push_back(normalization);

    } // endfor: looped over nodes

    // Set model name
    name(xml.attribute("name"));

    // Set instruments
    instruments(xml.attribute("instrument"));

    // Set observation identifiers
    ids(xml.attribute("id"));

    // Check flag if TS value should be computed
    bool tscalc = (xml.attribute("tscalc") == "1") ? true : false;

    // Set flag if TS value should be computed
    this->tscalc(tscalc);

    // Set pointers
    set_pointers();

    // Set evluation cache
    set_cache();

//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例3: read

/***********************************************************************//**
 * @brief Read model from XML element
 *
 * @param[in] xml XML element.
 *
 * @exception GException::model_invalid_parnum
 *            Invalid number of model parameters found in XML element.
 * @exception GException::model_invalid_parnames
 *            Invalid model parameter names found in XML element.
 *
 * Read the radial Polynom model information from an XML element. The XML
 * element is required to have at least one parameter. Parameters are named
 * "CoeffX", where "X" starts from "0".  
 *
 * @todo Implement a test of the coefficient boundaries.
 ***************************************************************************/
void GCTAModelRadialPolynom::read(const GXmlElement& xml)
{
    // Free space for coefficients
    m_coeffs.clear();

    // Get maximum number of coefficients from XML file
    int max_coeffs = xml.elements("parameter");

    // Throw an error if no parameters were found
    if (max_coeffs < 1) {
        std::string message = "Radial polynomial model requires at least"
                              " one coefficient.";
        throw GException::model_invalid_parnum(G_READ, xml, message);
    }

    // Verify XML file consistency and determine number of coefficients
    int ncoeffs = 0;
    std::vector<int> npar;
    npar.assign(max_coeffs, 0);
    for (int i = 0; i < max_coeffs; ++i) {

        // Get parameter element
        GXmlElement* par = static_cast<GXmlElement*>(xml.element("parameter", i));

        // Verify that parameter is indeed a coefficient
        if (par->attribute("name").compare(0,5,"Coeff") != 0) {
            throw GException::model_invalid_parnames(G_READ, xml, 
                  par->attribute("name"));
        }
        
        // Verify that parameter coefficient has index in valid range
        int index = -1;
        size_t nchars = par->attribute("name").length() - 5;
        if (nchars > 0) {
            index = toint(par->attribute("name").substr(5, nchars));
        }
        else {
            throw GException::model_invalid_parnames(G_READ, xml,
                  "Radial polynomial \"Coeff\" parameter has no index.");
        }
        if (index < 0) {
            throw GException::model_invalid_parnames(G_READ, xml,
                  "Radial polynomial \"Coeff\" parameter index < 0.");
        }
        if (index >= max_coeffs) {
            std::string message = "There are "+str(max_coeffs)+" parameters,"
                                  " hence polynomial coefficients are expected"
                                  " to run from 0 to "+str(max_coeffs-1)+", yet"
                                  " a coefficient with index "+str(index)+" was"
                                  " encountered.";
            throw GException::model_invalid_parnames(G_READ, xml, message);
        }

        // Increment parameter counter
        npar[index]++;
        
        // Update number of coefficients
        if (index+1 > ncoeffs) {
            ncoeffs = index + 1;
        }

    } // endfor: verified XML file consistency
    
    // Verify that the number of coefficients is between 1 and max_coeffs
    if (ncoeffs < 0 || ncoeffs > max_coeffs) {
        std::string message = "Radial polynomial model requires at between"
                              " 1 and "+str(max_coeffs)+" parameters.";
        throw GException::model_invalid_parnum(G_READ, xml, message);
    }

    // Verify that all parameters were found
    for (int i = 0; i < ncoeffs; ++i) {
        if (npar[i] == 0) {
            std::string message = "Parameter \"Coeff"+str(i)+"\" required,"
                                  " but not found in XML file.";
            throw GException::model_invalid_parnames(G_READ, xml, message);
        }
        else if (npar[i] > 1) {
            std::string message = "Multiple parameters \"Coeff"+str(i)+"\""
                                  " found in XML file.";
            throw GException::model_invalid_parnames(G_READ, xml, message);
        }
    }

//.........这里部分代码省略.........
开发者ID:adonath,项目名称:gammalib,代码行数:101,代码来源:GCTAModelRadialPolynom.cpp


注:本文中的GModelPar::read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。