void linear_population_growth_generator::parseConfig( boost::property_tree::ptree & config ) {

    if( config.get_child_optional( "A" ) == boost::none ) {
        config.put( "A", m_A);
    } else {
        m_A = config.get<double>( "A", m_A );
    }

    if( config.get_child_optional( "B" ) == boost::none ) {
        config.put("B", m_B );
    } else {
        m_B = config.get<double>( "B", m_B );
    }
}
Esempio n. 2
1
void ReadParticles(PartList &list,
                          const boost::property_tree::ptree &pt) {

  auto particleTree = pt.get_child_optional("ParticleList");
  if (!particleTree)
    return;
  for (auto const &v : particleTree.get()) {
    auto tmp = ParticleProperties(v.second);
    auto p = std::make_pair(tmp.name(), tmp);
    auto last = list.insert(p);

    if (!last.second) {
      LOG(INFO) << "ReadParticles() | Particle " << last.first->first
                << " already exists in list. We overwrite its parameters!";
      last.first->second = tmp;
    }
    tmp = last.first->second;

    // cparity is optional
    double cparity = 0.0;
    try {
      cparity = tmp.GetQuantumNumber("Cparity");
    } catch (std::exception &ex) {
    }

    LOG(DEBUG) << "ReadParticles() | Particle " << tmp.name()
               << " (id=" << tmp.GetId() << ") "
               << " J(PC)=" << tmp.GetSpinQuantumNumber("Spin") << "("
               << tmp.GetQuantumNumber("Parity") << cparity << ") "
               << " mass=" << tmp.GetMass()
               << " decayType=" << tmp.GetDecayType();
  }

  return;
}
Esempio n. 3
0
bool rai_daemon::daemon_config::upgrade_json (unsigned version_a, boost::property_tree::ptree & tree_a)
{
	auto result (false);
	switch (version_a)
	{
	case 1:
	{
		auto opencl_enable_l (tree_a.get_optional <bool> ("opencl_enable"));
		if (!opencl_enable_l)
		{
			tree_a.put ("opencl_enable", "false");
		}
		auto opencl_l (tree_a.get_child_optional ("opencl"));
		if (!opencl_l)
		{
			boost::property_tree::ptree opencl_l;
			opencl.serialize_json (opencl_l);
			tree_a.put_child ("opencl", opencl_l);
		}
		tree_a.put ("version", "2");
		result = true;
	}
	case 2:
		break;
	default:
		throw std::runtime_error ("Unknown daemon_config version");
	}
	return result;
}
Esempio n. 4
0
    void Key::unSerialize(boost::property_tree::ptree& node)
    {
        LOG(LogLevel::INFOS) << "Unserializing Key...";

        if (node.get_child_optional("KeyDiversification"))
        {
            boost::property_tree::ptree keydivnode = node.get_child("KeyDiversification");
            d_key_diversification = KeyDiversification::getKeyDiversificationFromType(keydivnode.get_child("<xmlattr>.keyDiversificationType").get_value<std::string>());
            boost::property_tree::ptree kdnode = keydivnode.get_child(d_key_diversification->getDefaultXmlNodeName());
            if (!kdnode.empty())
            {
                d_key_diversification->unSerialize(kdnode);
            }
        }

        d_storeCipheredData = node.get_child("IsCiphered").get_value<bool>(false);
        uncipherKeyData(node);
        LOG(LogLevel::INFOS) << "Unserializing Key storage...";
        d_key_storage = KeyStorage::getKeyStorageFromType(static_cast<KeyStorageType>(node.get_child("<xmlattr>.keyStorageType").get_value<unsigned int>()));
        if (d_key_storage)
        {
            boost::property_tree::ptree ksnode = node.get_child(d_key_storage->getDefaultXmlNodeName());
            if (!ksnode.empty())
            {
                d_key_storage->unSerialize(ksnode);
            }
        }
    }
Esempio n. 5
0
        std::vector<STEMScannerGeometry*> TF_Datasource::parseProjectionStackProperties(const boost::property_tree::ptree& node, unsigned int imageCount) 
        {
            if (!node.get_child_optional("convergent").is_initialized())
                throw Exception("TF_Datasource can only read projection metadata of type TF_ProjectionMetaData");

            std::string filename = node.get_child("image").get<std::string>("<xmlattr>.filename");
            float tiltAngle = node.get_child("tiltAngle").get<float>("<xmlattr>.value");
            float focalDistanceBase = node.get_child("focalDistanceBase").get<float>("<xmlattr>.value");
            float focusAtImage = node.get_child("focusAtImage").get<float>("<xmlattr>.value");
            float focalDistanceBetweenImages = node.get_child("focalDistanceBetweenImages").get<float>("<xmlattr>.value");
            float beamOpeningAngle = node.get_child("beamOpeningAngle").get<float>("<xmlattr>.value");

            boost::filesystem::path pathToImage( filename );            
            unsigned int imagesInStack = ImageDeserializer::getNumberOfImagesInStack( getAbsoluteImageLocation(pathToImage).string() );

            std::vector<STEMScannerGeometry*> result;

            for (unsigned int i = 0; i < imagesInStack; i++)
            {
                ScannerGeometry* rotatedGeometry = satRotator.createRotatedScannerGeometry(tiltAngle, 0.0f);
                STEMScannerGeometry* stemGeometry = dynamic_cast<STEMScannerGeometry*>(rotatedGeometry);
                stemGeometry->setFocalDifferenceBetweenImages(focalDistanceBetweenImages);
                stemGeometry->setConfocalOpeningHalfAngle(beamOpeningAngle);
                float focusPosition = focalDistanceBase + (focalDistanceBetweenImages * (float) (imagesInStack-i) );
                stemGeometry->setFocalDepth(focusPosition);
                stemGeometry->setTiltAngle(tiltAngle);
                result.push_back(stemGeometry);
            }

            return result;
        }
 ImageStackDirectoryDatasource::MetaDataNode ImageStackDirectoryDatasource::parseProjectionProperties(const boost::property_tree::ptree& node) const
 {
     MetaDataNode props;
     props.onLogarithmicScale = node.get_child_optional("logscale").is_initialized();
     props.tiltAngle = node.get_child("tiltAngle").get<float>("<xmlattr>.value");
     props.xmlNode = node;
     return props;
 }
Esempio n. 7
0
void ptree_entry_to_query(const boost::property_tree::ptree& ptree,
                         const std::string& entry_name,
                         LayerParameters* p_params) {
  auto given_entry = ptree.get_child_optional(entry_name);
  if (given_entry) {
    (*p_params)[entry_name] = given_entry.get().data();
  }
}
Esempio n. 8
0
	bool upgrade_json (unsigned version_a, boost::property_tree::ptree & tree_a)
	{
		auto result (false);
		switch (version_a)
		{
			case 1:
			{
				rai::account account;
				account.decode_account (tree_a.get<std::string> ("account"));
				tree_a.erase ("account");
				tree_a.put ("account", account.to_account ());
				tree_a.erase ("version");
				tree_a.put ("version", "2");
				result = true;
			}
			case 2:
			{
				boost::property_tree::ptree rpc_l;
				rpc.serialize_json (rpc_l);
				tree_a.put ("rpc_enable", "false");
				tree_a.put_child ("rpc", rpc_l);
				tree_a.erase ("version");
				tree_a.put ("version", "3");
				result = true;
			}
			case 3:
			{
				auto opencl_enable_l (tree_a.get_optional<bool> ("opencl_enable"));
				if (!opencl_enable_l)
				{
					tree_a.put ("opencl_enable", "false");
				}
				auto opencl_l (tree_a.get_child_optional ("opencl"));
				if (!opencl_l)
				{
					boost::property_tree::ptree opencl_l;
					opencl.serialize_json (opencl_l);
					tree_a.put_child ("opencl", opencl_l);
				}
				tree_a.put ("version", "4");
				result = true;
			}
			case 4:
				break;
			default:
				throw std::runtime_error ("Unknown qt_wallet_config version");
		}
		return result;
	}
Esempio n. 9
0
ParticleProperties::ParticleProperties(boost::property_tree::ptree pt)
    : Properties(pt.get<std::string>("<xmlattr>.Name"), pt.get<pid>("Pid")) {

  for (const auto &v : pt.get_child("")) {
    if (v.first == "QuantumNumber") {
      // QuantumNumbers which can be of type int or ComPWA::Spin
      std::string type = v.second.get<std::string>("<xmlattr>.Type");

      // We have to distinguish between spin and integer quantum numbers
      if (v.second.get<std::string>("<xmlattr>.Class") == "Spin") {
        auto value = v.second.get<double>("<xmlattr>.Value");
        double valueZ = 0.0;
        try { // Projection of spin is optional (e.g. (I,I3))
          valueZ = v.second.get<double>("<xmlattr>.Projection");
        } catch (std::exception &ex) {
        }
        spinQuantumNumbers_.insert(
            std::make_pair(type, ComPWA::Spin(value, valueZ)));
      } else if (v.second.get<std::string>("<xmlattr>.Class") == "Int") {
        auto value = v.second.get<int>("<xmlattr>.Value");
        intQuantumNumbers_.insert(std::make_pair(type, value));
      } else {
        throw BadParameter(
            "ParticleProperties::ParticleProperties() | "
            "QuantumNumber is neither of type 'Spin' nor of type "
            "'Int'!");
      }
    } else if (v.first == "Parameter") {
      // Parameter (e.g. Mass)
      if (v.second.get<std::string>("<xmlattr>.Type") != "Mass")
        continue;
     Mass = FitParameter();
     Mass.load(v.second);
    } else {
    }
  }

  // Info on the particle decay is stored as it is as property_tree and later
  // used by AbstractDynamicalFunctions (e.g. RelativisticBreitWigner).
  auto decayInfo = pt.get_child_optional("DecayInfo");
  if (decayInfo) {
   DecayInfo = decayInfo.get();
  } else {
   DecayInfo.put("<xmlattr>.Type", "Stable");
  }
}
Esempio n. 10
0
void ReprojectPCL::updateConfig(const boost::property_tree::ptree &pt) {
    BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ <<  " " << id();

    using namespace boost::property_tree;

    Filter::updateConfig(pt);

    boost::optional<const boost::property_tree::ptree& > ocvo = pt.get_child_optional( "options.cameraMatrix" );
    if (ocvo.is_initialized()) {
	if( toffy::commons::checkOCVNone(*ocvo) ) {
	    boost::property_tree::ptree os;
	    os.put_child("cameraMatrix",*ocvo);
	    cv::FileStorage fs = commons::loadOCVnode(os);
	    //Mat val;
	    fs.getFirstTopLevelNode() >> _cameraMatrix;
	    cout << fs.getFirstTopLevelNode().name() << endl;
	    fs.release();
	} else
Esempio n. 11
0
void
plugin_factory::load_settings(const boost::property_tree::ptree& settings)
{
  using boost::property_tree::ptree;

  BOOST_AUTO(path, settings.get_child_optional("path"));
  if (path) {
    BOOST_FOREACH(const ptree::value_type& v, *path) {
      boost::filesystem::path plugin_path(v.second.get<std::string>(""));
      if (plugin_path.is_absolute()) {
        load_dir(plugin_path);
      }
      else {
        load_dir(boost::filesystem::current_path() / plugin_path);
      }
    }
  }
  else {
Esempio n. 12
0
    /* static */ bool Parser::parse_description( std::string & description, boost::property_tree::ptree const & root )
    {
        OptionalPTree values = root.get_child_optional( "values" );

        if( !values )
        {
            return false;
        }

        boost::optional<std::string> desc = values->get_optional<std::string>( "statusmessage" );

        if( !desc )
        {
            return false;
        }

        description = *desc;

        return true;
    }
    /* static */ bool Parser::parse_server_state(ServerState & server_state, GazeData & gaze_data, CalibResult & calib_result, Screen & screen, boost::property_tree::ptree const & root, bool& has_gaze_data, bool& has_calib_result)
    {
        OptionalPTree values = root.get_child_optional("values");

        if (!values)
        {
            return false;
        }

        Parser::parse_calib_result(calib_result, root, has_calib_result);

        OptionalPTree frame = values->get_child_optional("frame");
        has_gaze_data = static_cast<bool>(frame);

        if (has_gaze_data)
        {
            gaze_data.time = frame->get<int>("time");
            gaze_data.fix = frame->get<bool>("fix");
            gaze_data.state  = frame->get<int>("state");
            parse_point2d(gaze_data.raw, frame->get_child("raw"));
            parse_point2d(gaze_data.raw, frame->get_child("avg"));
            parse_eye(gaze_data.lefteye, frame->get_child("lefteye"));
            parse_eye(gaze_data.righteye, frame->get_child("righteye"));
        }

        server_state.push               = values->get<bool>("push", server_state.push);
        server_state.heartbeatinterval  = values->get<int>("heartbeatinterval", server_state.heartbeatinterval);
        server_state.version            = values->get<int>("version", server_state.version);
        server_state.trackerstate       = values->get<int>("trackerstate", server_state.trackerstate);
        server_state.framerate          = values->get<int>("framerate", server_state.framerate);
        server_state.iscalibrated       = values->get<bool>("iscalibrated", server_state.iscalibrated);
        server_state.iscalibrating      = values->get<bool>("iscalibrating", server_state.iscalibrating);

        screen.screenindex = values->get<int>("screenindex", screen.screenindex);
        screen.screenresw  = values->get<int>("screenresw", screen.screenresw);
        screen.screenresh  = values->get<int>("screenresh", screen.screenresh);
        screen.screenpsyw  = values->get<float>("screenpsyw", screen.screenpsyw);
        screen.screenpsyh  = values->get<float>("screenpsyh", screen.screenpsyh);
        return true;
    }
Esempio n. 14
0
bool AstProvider::parse(const ::boost::property_tree::ptree& tree, MessageCallback callback)
{
	boost::optional< const pt::ptree& > child = tree.get_child_optional("provider");
	if (!child) {
		CompileMessage error(CompileMessage::type_t::Error, CdefMessage::CDE101, callback, "Provider block not defined");
		return false;
	}

	// get the name associated with this collection
	_label = child.get().get_value<string>();

	// Loop through all properties on this level
	for (const pt::ptree::value_type &v : child.get())
	{
		if (boost::iequals(v.first.data(), "application"))
			_application = child.get().get<string>("application");
		else if (boost::iequals(v.first.data(), "uuid")) {
			// read and Validate the uuid
			string uuid = v.second.data();
			if (!isValidUuid(uuid)) {
				CompileMessage error(CompileMessage::type_t::Error, CdefMessage::CDE102, callback, "The provider '%s' contains an invalid uuid", _label.c_str());
				return false;
			}
			_uuid = string_generator()(uuid);
		}
		else if (boost::iequals(v.first.data(), "counterset")) {
			AstCounterSetPtr counterset = AstCounterSet::create();
			if(!counterset->parse(v.second, callback))
				return false;
			
			counterset->setParent(shared_from_this());

			// the contructor will throw an exception if a syntax error was detected.
			this->push_back(counterset);
		}
	}

	return isSane(callback);
}
Esempio n. 15
0
    void Key::unSerialize(boost::property_tree::ptree& node)
    {
        LOG(LogLevel::INFOS) << "Unserializing Key...";

        if (node.get_child_optional("KeyDiversification"))
        {
            boost::property_tree::ptree keydivnode = node.get_child("KeyDiversification");
            d_key_diversification = KeyDiversification::getKeyDiversificationFromType(keydivnode.get_child("<xmlattr>.keyDiversificationType").get_value<std::string>());
            boost::property_tree::ptree kdnode = keydivnode.get_child(d_key_diversification->getDefaultXmlNodeName());
            if (!kdnode.empty())
            {
                d_key_diversification->unSerialize(kdnode);

                std::shared_ptr<ComputerMemoryKeyStorage> cmks = std::dynamic_pointer_cast<ComputerMemoryKeyStorage>(d_key_diversification);
                if (cmks)
                {
                    if (cmks->getRandom())
                    {
                        fromString(AccessInfo::generateSimpleKey(getLength()));
                    }
                }
            }
        }

        d_storeCipheredData = node.get_child("IsCiphered").get_value<bool>(false);
        uncipherKeyData(node);
        LOG(LogLevel::INFOS) << "Unserializing Key storage...";
        d_key_storage = KeyStorage::getKeyStorageFromType(static_cast<KeyStorageType>(node.get_child("<xmlattr>.keyStorageType").get_value<unsigned int>()));
        if (d_key_storage)
        {
            boost::property_tree::ptree ksnode = node.get_child(d_key_storage->getDefaultXmlNodeName());
            if (!ksnode.empty())
            {
                d_key_storage->unSerialize(ksnode);
            }
        }
    }
Esempio n. 16
0
TEST (PCL, KdTreeFLANN_32_vs_64_bit)
{
  KdTreeFLANN<PointXYZ> tree;
  tree.setInputCloud (cloud_in);

  std::vector<std::vector<int> > nn_indices_vector;
  for (size_t i = 0; i < cloud_in->size (); ++i)
    if (isFinite ((*cloud_in)[i]))
    {
      std::vector<int> nn_indices;
      std::vector<float> nn_dists;
      tree.radiusSearch ((*cloud_in)[i], 0.02, nn_indices, nn_dists);

      nn_indices_vector.push_back (nn_indices);
    }



  for (size_t vec_i = 0; vec_i < nn_indices_vector.size (); ++vec_i)
  {
    char str[512];
    sprintf (str, "point_%d", int (vec_i));
    boost::optional<boost::property_tree::ptree&> tree = xml_property_tree.get_child_optional (str);
    if (!tree)
      FAIL ();

    int vec_size = tree.get ().get<int> ("size");
    EXPECT_EQ (vec_size, nn_indices_vector[vec_i].size ());

    for (size_t n_i = 0; n_i < nn_indices_vector[vec_i].size (); ++n_i)
    {
      sprintf (str, "nn_%d", int (n_i));
      int neighbor_index = tree.get ().get<int> (str);
      EXPECT_EQ (neighbor_index, nn_indices_vector[vec_i][n_i]);
    }
  }
}
    void parse_configuration( boost::property_tree::ptree & config ) {
        boost::property_tree::ptree lconfig;

        if( config.get_child_optional( "mutation" ) != boost::none ) {
            lconfig = config.get_child( "mutation" );
        }

        if( lconfig.get_child_optional( "mutation_per_sequence" ) == boost::none ) {
            lconfig.put("mutation_per_sequence", m_mutation_rate );
        } else {
            m_mutation_rate = lconfig.get< real_type >( "mutation_per_sequence", m_mutation_rate );
        }

        if( lconfig.get_child_optional( "rng.seed" ) != boost::none ) {
            m_seed = lconfig.get< seed_type >( "rng.seed", m_seed );
        }

        if( m_seed == 0 ) {
            m_seed = clotho::utility::clock_type::now().time_since_epoch().count();
            lconfig.put("rng.seed", m_seed );
        }

        config.put_child( "mutation", lconfig );
    }
Esempio n. 18
0
void Agent::setProperties(const boost::property_tree::ptree& properties) {
    static const std::string LOG_LEVEL("log.level");
    static const std::string ENDPOINT_SOURCE_PATH("endpoint-sources.filesystem");
    static const std::string SERVICE_SOURCE_PATH("service-sources.filesystem");
    static const std::string OPFLEX_PEERS("opflex.peers");
    static const std::string OPFLEX_SSL_MODE("opflex.ssl.mode");
    static const std::string OPFLEX_SSL_CA_STORE("opflex.ssl.ca-store");
    static const std::string OPFLEX_SSL_CERT_PATH("opflex.ssl.client-cert.path");
    static const std::string OPFLEX_SSL_CERT_PASS("opflex.ssl.client-cert.password");
    static const std::string HOSTNAME("hostname");
    static const std::string PORT("port");
    static const std::string OPFLEX_INSPECTOR("opflex.inspector.enabled");
    static const std::string OPFLEX_INSPECTOR_SOCK("opflex.inspector.socket-name");
    static const std::string OPFLEX_NOTIF("opflex.notif.enabled");
    static const std::string OPFLEX_NOTIF_SOCK("opflex.notif.socket-name");
    static const std::string OPFLEX_NOTIF_OWNER("opflex.notif.socket-owner");
    static const std::string OPFLEX_NOTIF_GROUP("opflex.notif.socket-group");
    static const std::string OPFLEX_NOTIF_PERMS("opflex.notif.socket-permissions");

    static const std::string OPFLEX_NAME("opflex.name");
    static const std::string OPFLEX_DOMAIN("opflex.domain");

    static const std::string RENDERERS_STITCHED_MODE("renderers.stitched-mode");

    optional<std::string> logLvl =
        properties.get_optional<std::string>(LOG_LEVEL);
    if (logLvl) {
        setLoggingLevel(logLvl.get());
    }

    boost::optional<std::string> ofName =
        properties.get_optional<std::string>(OPFLEX_NAME);
    if (ofName) opflexName = ofName;
    boost::optional<std::string> ofDomain =
        properties.get_optional<std::string>(OPFLEX_DOMAIN);
    if (ofDomain) opflexDomain = ofDomain;

    boost::optional<bool> enabInspector =
        properties.get_optional<bool>(OPFLEX_INSPECTOR);
    boost::optional<std::string> inspSocket =
        properties.get_optional<std::string>(OPFLEX_INSPECTOR_SOCK);
    if (enabInspector) enableInspector = enabInspector;
    if (inspSocket) inspectorSock = inspSocket;

    boost::optional<bool> enabNotif =
        properties.get_optional<bool>(OPFLEX_NOTIF);
    boost::optional<std::string> notSocket =
        properties.get_optional<std::string>(OPFLEX_NOTIF_SOCK);
    boost::optional<std::string> notOwner =
        properties.get_optional<std::string>(OPFLEX_NOTIF_OWNER);
    boost::optional<std::string> notGrp =
        properties.get_optional<std::string>(OPFLEX_NOTIF_GROUP);
    boost::optional<std::string> notPerms =
        properties.get_optional<std::string>(OPFLEX_NOTIF_PERMS);
    if (enabNotif) enableNotif = enabNotif;
    if (notSocket) notifSock = notSocket;
    if (notOwner) notifOwner = notOwner;
    if (notGrp) notifGroup = notGrp;
    if (notPerms) notifPerms = notPerms;

    optional<const ptree&> endpointSource =
        properties.get_child_optional(ENDPOINT_SOURCE_PATH);

    if (endpointSource) {
        for (const ptree::value_type &v : endpointSource.get())
            endpointSourcePaths.insert(v.second.data());
    }

    optional<const ptree&> serviceSource =
        properties.get_child_optional(SERVICE_SOURCE_PATH);

    if (serviceSource) {
        for (const ptree::value_type &v : serviceSource.get())
            serviceSourcePaths.insert(v.second.data());
    }

    optional<const ptree&> peers =
        properties.get_child_optional(OPFLEX_PEERS);
    if (peers) {
        for (const ptree::value_type &v : peers.get()) {
            optional<std::string> h =
                v.second.get_optional<std::string>(HOSTNAME);
            optional<int> p =
                v.second.get_optional<int>(PORT);
            if (h && p) {
                opflexPeers.insert(make_pair(h.get(), p.get()));
            }
        }
    }

    boost::optional<std::string> confSslMode =
        properties.get_optional<std::string>(OPFLEX_SSL_MODE);
    boost::optional<std::string> confsslCaStore =
        properties.get_optional<std::string>(OPFLEX_SSL_CA_STORE);
    boost::optional<std::string> confsslClientCert =
        properties.get_optional<std::string>(OPFLEX_SSL_CERT_PATH);
    boost::optional<std::string> confsslClientCertPass =
        properties.get_optional<std::string>(OPFLEX_SSL_CERT_PASS);
    if (confSslMode)
        sslMode = confSslMode;
    if (confsslCaStore)
        sslCaStore = confsslCaStore;
    if (confsslClientCert)
        sslClientCert = confsslClientCert;
    if (confsslClientCertPass)
        sslClientCertPass = confsslClientCertPass;

    typedef Renderer* (*rend_create)(Agent&);
    typedef std::unordered_map<std::string, rend_create> rend_map_t;
    static rend_map_t rend_map =
        boost::assign::map_list_of(RENDERERS_STITCHED_MODE,
                                   StitchedModeRenderer::create);

    for (rend_map_t::value_type& v : rend_map) {
        optional<const ptree&> rtree =
            properties.get_child_optional(v.first);
        if (rtree) {
            Renderer* r = v.second(*this);
            renderers.push_back(r);
            r->setProperties(rtree.get());
        }
    }
}
Esempio n. 19
0
    /* static */ bool Parser::parse_calib_result( CalibResult & calib_result, boost::property_tree::ptree const & root, bool & has_calib_result )
    {
        OptionalPTree values = root.get_child_optional( "values" );
        has_calib_result = false;

        if( !values )
        {
            return true;
        }

        OptionalPTree calibresult = values->get_child_optional( "calibresult" );

        if( !calibresult )
        {
            return false;
        }

        calib_result.result = calibresult->get<bool>( "result" );
        calib_result.deg = calibresult->get<float>( "deg" );
        calib_result.degl = calibresult->get<float>( "degl" );
        calib_result.degr = calibresult->get<float>( "degr" );

        OptionalPTree calibpoints = calibresult->get_child_optional( "calibpoints" );

        if( !calibpoints )
        {
            return false;
        }

        std::vector<CalibPoint> & calibpoints_vector = calib_result.calibpoints;
        calibpoints_vector.reserve( calibpoints->size() );
        boost::property_tree::ptree::const_iterator it = calibpoints->begin();
        boost::property_tree::ptree::const_iterator end = calibpoints->end();

        for( ; it != end; ++it )
        {
            CalibPoint calib_point;

            calib_point.state = it->second.get<int>( "state" );
            parse_point2d( calib_point.cp, it->second.get_child( "cp" ) );
            parse_point2d( calib_point.mecp, it->second.get_child( "mecp" ) );

            PTree const & acd = it->second.get_child( "acd" );
            calib_point.acd.ad = acd.get<float>( "ad" );
            calib_point.acd.adl = acd.get<float>( "adl" );
            calib_point.acd.adr = acd.get<float>( "adr" );

            PTree const & mepix = it->second.get_child( "mepix" );
            calib_point.mepix.mep = mepix.get<float>( "mep" );
            calib_point.mepix.mepl = mepix.get<float>( "mepl" );
            calib_point.mepix.mepr = mepix.get<float>( "mepr" );

            PTree const & asdp = it->second.get_child( "asdp" );
            calib_point.asdp.asd = asdp.get<float>( "asd" );
            calib_point.asdp.asdl = asdp.get<float>( "asdl" );
            calib_point.asdp.asdr = asdp.get<float>( "asdr" );

            calibpoints_vector.push_back( calib_point );
        }

        has_calib_result = true;
        return true;
    }
Esempio n. 20
0
Logging::InitResult				Logging::Init( const char*								processName,
        const boost::property_tree::ptree&		loggingSection )
{
    //	Logging configuration settings block

    boost::log::settings 		configSettings;

    //	Start by loading the core configuration

    {
        auto	coreSection = loggingSection.get_child_optional( "core" );

        if( !coreSection.is_initialized() )
        {
            Logger( "LoggingConfigInit" ).WarningStream() << "Missing 'core' section in logging configuration." << std::endl;
        }
        else
        {
            CoreSettings		coreSettings;

            auto		parseResult = coreSettings.Parse( *coreSection );

            if( parseResult.Failed() )
            {
                Logger( "LoggingConfigInit" ).ErrorStream() << "Error parsing 'core' settings in logging configuration.  Using Default Config." << std::endl;

                g_boostLogManager.DefaultLoggingConfig( processName );

                return( InitResult::Failure( ErrorCodes::BAD_CORE_SETTINGS, "Bad Logging Core Settings.  Using Default Config." ) );
            }

            SetIfInitialized( configSettings, "Core.DisableLogging", coreSettings.fieldValue( "disable_logging" ) );
            SetIfInitialized( configSettings, "Core.Filter", coreSettings.fieldValue( "filter" ) );
        }
    }

    //	Next, the console(s) configuration

    {
        auto	consolesSection = loggingSection.get_child_optional( "consoles" );
        auto	consoleSection = loggingSection.get_child_optional( "console" );

        if( !consolesSection.is_initialized() && !consoleSection.is_initialized() )
        {
            Logger( "LoggingConfigInit" ).WarningStream() << "No console(s) section in logging configuration." << std::endl;
        }
        else
        {
            if( consolesSection.is_initialized() )
            {
                auto consoleRange = consolesSection->equal_range( "console" );

                for( auto itrConsoleSpec = consoleRange.first; itrConsoleSpec != consoleRange.second; ++itrConsoleSpec )
                {
                    ConsoleSpec		consoleSpec;

                    auto			parseResult = consoleSpec.Parse( itrConsoleSpec->second );

                    if( parseResult.Failed() )
                    {
                        Logger( "LoggingConfigInit" ).ErrorStream() << "Error parsing 'console' specification in logging configuration.  Skipping bad console specification." << std::endl;

                        continue;
                    }

                    std::string		prefix = std::string( "Sinks." ) + consoleSpec.sink_name();

                    configSettings[prefix + ".Destination"] = "Console";
                    configSettings[prefix + ".AutoFlush"] = consoleSpec.auto_flush();

                    SetIfInitialized( configSettings, prefix + std::string( ".Filter" ), consoleSpec.fieldValue( "filter" ) );
                    SetIfInitialized( configSettings, prefix + std::string( ".Format" ), consoleSpec.fieldValue( "format" ) );
                    SetIfInitialized( configSettings, prefix + std::string( ".Asynchronous" ), consoleSpec.fieldValue( "asynchronous" ) );
                }
            }
        }

        if( consoleSection.is_initialized() )
        {
            ConsoleSpec		consoleSpec;

            auto			parseResult = consoleSpec.Parse( *consoleSection );

            if( parseResult.Failed() )
            {
                Logger( "LoggingConfigInit" ).ErrorStream() << "Error parsing 'console' specification in logging configuration.  Skipping bad console specification." << std::endl;
            }
            else
            {
                std::string		prefix = std::string( "Sinks." ) + consoleSpec.sink_name();

                configSettings[prefix + ".Destination"] = "Console";
                configSettings[prefix + ".AutoFlush"] = consoleSpec.auto_flush();

                SetIfInitialized( configSettings, prefix + std::string( ".Filter" ), consoleSpec.fieldValue( "filter" ) );
                SetIfInitialized( configSettings, prefix + std::string( ".Format" ), consoleSpec.fieldValue( "format" ) );
                SetIfInitialized( configSettings, prefix + std::string( ".Asynchronous" ), consoleSpec.fieldValue( "asynchronous" ) );
            }
        }
    }

    //	Get a collection of all the logging files to open

    {
        auto	filesSection = loggingSection.get_child_optional( "files" );

        if( !filesSection.is_initialized() )
        {
            Logger( "LoggingConfigInit" ).ErrorStream() << "Missing 'files' section in logging configuration.  Using Default Config." << std::endl;

            g_boostLogManager.DefaultLoggingConfig( processName );

            return( InitResult::Failure( ErrorCodes::MISSING_FILES_SECTION, "Missing 'files' section in logging configuration.  Using Default Config." ) );
        }

        auto fileRange = filesSection->equal_range( "file" );

        for( auto itrFileSpec = fileRange.first; itrFileSpec != fileRange.second; ++itrFileSpec )
        {
            LogFileSpec		fileSpec;

            auto		parseResult = fileSpec.Parse( itrFileSpec->second );

            if( parseResult.Failed() )
            {
                Logger( "LoggingConfigInit" ).ErrorStream() << "Error parsing 'file' specification in logging configuration.  Using Default Config." << std::endl;

                g_boostLogManager.DefaultLoggingConfig( processName );

                return( InitResult::Failure( ErrorCodes::BAD_FILE_SPEC, "Bad File Specification.  Using Default Config." ) );
            }

            std::string		prefix = std::string( "Sinks." ) + fileSpec.sink_name();

            configSettings[prefix + ".Destination"] = "TextFile";
            configSettings[prefix + ".FileName"] = fileSpec.file_name();
            configSettings[prefix + ".AutoFlush"] = fileSpec.auto_flush();

            SetIfInitialized( configSettings, prefix + std::string( ".Target" ), fileSpec.fieldValue( "target" ) );
            SetIfInitialized( configSettings, prefix + std::string( ".Filter" ), fileSpec.fieldValue( "filter" ) );
            SetIfInitialized( configSettings, prefix + std::string( ".Format" ), fileSpec.fieldValue( "format" ) );
            SetIfInitialized( configSettings, prefix + std::string( ".Asynchronous" ), fileSpec.fieldValue( "asynchronous" ) );

            SetIfInitialized( configSettings, prefix + std::string( ".RotationSize" ), fileSpec.fieldValue( "rotation_size" ) );

            if( fileSpec.fieldValue( "rotation_interval" ).is_initialized() &&  fileSpec.fieldValue( "rotation_time_period" ).is_initialized() )
            {
                Logger( "LoggingConfigInit" ).ErrorStream() << "Both 'rotation_interval' and 'rotation_time_period' are defined in configuration.  Using 'rotation_interval'." << std::endl;

                SetIfInitialized( configSettings, prefix + std::string( ".RotationInterval" ), fileSpec.fieldValue( "rotation_interval" ) );
            }
            else
            {
                SetIfInitialized( configSettings, prefix + std::string( ".RotationInterval" ), fileSpec.fieldValue( "rotation_interval" ) );
                SetIfInitialized( configSettings, prefix + std::string( ".RotationTimePoint" ), fileSpec.fieldValue( "rotation_time_point" ) );
            }

            SetIfInitialized( configSettings, prefix + std::string( ".MaxSize" ), fileSpec.fieldValue( "max_size" ) );
            SetIfInitialized( configSettings, prefix + std::string( ".MinFreeSpace" ), fileSpec.fieldValue( "min_free_space" ) );

            SetIfInitialized( configSettings, prefix + std::string( ".ScanForFiles" ), fileSpec.fieldValue( "scan_for_files" ) );
        }
    }

    //	Start by stripping out all the existing sinks.  There should only be the startup console and file anyway.

    boost::log::core::get()->remove_all_sinks();

    //	Initialize from the settings we just pulled from the config and signal that the filters have changed

    boost::log::init_from_settings( configSettings );

    //	Add the common attributes

    boost::log::add_common_attributes();

    //	Signal that the filters have changed

    FiltersChanged();

    //	Write to the log file

    Logger( "LoggingConfigInit" ).NormalStream() << "Logging initialized from configuration file." << std::endl;

    //	Finished with Success

    return( InitResult::Success() );
}
Esempio n. 21
0
style_rules::style_rules(const pt::ptree &conf)
{
   // see if there are any style rewrite rules
   optional<const pt::ptree &> rewrites = conf.get_child_optional("rewrite");
   if (rewrites)
   {
      for (pt::ptree::const_iterator itr = rewrites->begin();
           itr != rewrites->end(); ++itr) 
      {
         string from_style = itr->first;
         string to_style = rewrites->get<string>(from_style);
         m_rewrites.insert(make_pair(from_style, to_style));
      }
   }

   // see if there are any style format listings
   optional<const pt::ptree &> formats = conf.get_child_optional("formats");
   if (formats)
   {
      for (pt::ptree::const_iterator itr = formats->begin();
           itr != formats->end(); ++itr) 
      {
         string style = itr->first;
         string fmt_str = formats->get<string>(style);
         protoFmt fmts = parse_formats(fmt_str);
         m_formats.insert(make_pair(style, fmts));
      }
   }

   // see if we're forcing the return types. yeah, it's a nasty hack
   // and we should lean on the toolkit guys to get rid of this as
   // soon as we can...
   optional<const pt::ptree &> forced_formats = conf.get_child_optional("forced_formats");
   if (forced_formats)
   {
      for (pt::ptree::const_iterator itr = forced_formats->begin();
           itr != forced_formats->end(); ++itr) 
      {
         string style = itr->first;
         string fmt_str = forced_formats->get<string>(style);
         protoFmt fmt = get_format_for(fmt_str);
         if (fmt == fmtNone)
         {
            throw std::runtime_error((boost::format("In [forced_formats] for style `%1%', the string `%2%' is not recognised as a format.") % style % fmt_str).str());
         }
         m_forced_formats.insert(make_pair(style, fmt));
      }
   }

   // find out what the max zoom levels are for each tile so
   // that the check can check whether or not the tile is
   // within the world, as far as TMS coords are concerned.
   optional<const pt::ptree &> zoom_limits = conf.get_child_optional("zoom_limits");
   if (zoom_limits) 
   {
      for (pt::ptree::const_iterator itr = zoom_limits->begin();
           itr != zoom_limits->end(); ++itr) 
      {
         string style = itr->first;
         int max_zoom = zoom_limits->get<int>(style);
         m_zoom_limits.insert(make_pair(style, max_zoom));
      }
   }
}