<commit_before>#include <ros/ros.h>
#include <ros/callback_queue.h>

#include "arc_utilities/maybe.hpp"

#ifndef ROS_HELPERS_HPP
#define ROS_HELPERS_HPP

#define PARAM_NAME_WIDTH (50)

namespace ROSHelpers
{
    inline void Spin(const double loop_period)
    {
        while (ros::ok())
        {
            ros::getGlobalCallbackQueue()->callAvailable(ros::WallDuration(loop_period));
        }
    }

    template <typename T>
    inline T GetParam(ros::NodeHandle& nh, const std::string& param_name, const T& default_val)
    {
        T param_val;
        if (nh.getParam(param_name, param_val))
        {
            ROS_INFO_STREAM_NAMED("params", "Setting    " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        else
        {
            param_val = default_val;
            ROS_WARN_STREAM_NAMED("params", "Defaulting " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        return param_val;
    }

    template <typename T>
    inline T GetParam(ros::NodeHandle& nh, const std::string& param_name, T&& default_val)
    {
        T param_val;
        if (nh.getParam(param_name, param_val))
        {
            ROS_INFO_STREAM_NAMED("params", "Setting    " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        else
        {
            param_val = default_val;
            ROS_WARN_STREAM_NAMED("params", "Defaulting " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        return param_val;
    }


    template <typename T>
    inline T GetParamDebugLog(ros::NodeHandle& nh, const std::string& param_name, const T& default_val)
    {
        T param_val;
        if (nh.getParam(param_name, param_val))
        {
            ROS_DEBUG_STREAM_NAMED("params", "Setting    " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        else
        {
            param_val = default_val;
            ROS_DEBUG_STREAM_NAMED("params", "Defaulting " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        return param_val;
    }

    template <typename T>
    inline T GetParamDebugLog(ros::NodeHandle& nh, const std::string& param_name, T&& default_val)
    {
        T param_val;
        if (nh.getParam(param_name, param_val))
        {
            ROS_DEBUG_STREAM_NAMED("params", "Setting    " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        else
        {
            param_val = default_val;
            ROS_DEBUG_STREAM_NAMED("params", "Defaulting " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        return param_val;
    }

    template <typename T>
    inline Maybe::Maybe<T> GetParamRequired(ros::NodeHandle& nh, const std::string& param_name, const std::string& calling_fn_name)
    {
        ROS_DEBUG_STREAM_NAMED("params", "No default value for " << param_name << ": Value must be on paramter sever");
        T param_val;
        if (nh.getParam(param_name, param_val))
        {
            ROS_INFO_STREAM_NAMED("params", "Setting    " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
            return Maybe::Maybe<T>(param_val);
        }
        else
        {
            ROS_FATAL_STREAM_NAMED("params", "Cannot find " << param_name << " on parameter server for " << calling_fn_name << ": Value must be on paramter sever");
            return Maybe::Maybe<T>();
        }
    }
}

#endif // ROS_HELPERS_HPP
<commit_msg>Made more verbose error message when parameters are not found.<commit_after>#include <ros/ros.h>
#include <ros/callback_queue.h>

#include "arc_utilities/maybe.hpp"

#ifndef ROS_HELPERS_HPP
#define ROS_HELPERS_HPP

#define PARAM_NAME_WIDTH (50)

namespace ROSHelpers
{
    inline void Spin(const double loop_period)
    {
        while (ros::ok())
        {
            ros::getGlobalCallbackQueue()->callAvailable(ros::WallDuration(loop_period));
        }
    }

    template <typename T>
    inline T GetParam(ros::NodeHandle& nh, const std::string& param_name, const T& default_val)
    {
        T param_val;
        if (nh.getParam(param_name, param_val))
        {
            ROS_INFO_STREAM_NAMED("params", "Setting    " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        else
        {
            param_val = default_val;
            ROS_WARN_STREAM_NAMED("params", "Defaulting " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        return param_val;
    }

    template <typename T>
    inline T GetParam(ros::NodeHandle& nh, const std::string& param_name, T&& default_val)
    {
        T param_val;
        if (nh.getParam(param_name, param_val))
        {
            ROS_INFO_STREAM_NAMED("params", "Setting    " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        else
        {
            param_val = default_val;
            ROS_WARN_STREAM_NAMED("params", "Defaulting " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        return param_val;
    }


    template <typename T>
    inline T GetParamDebugLog(ros::NodeHandle& nh, const std::string& param_name, const T& default_val)
    {
        T param_val;
        if (nh.getParam(param_name, param_val))
        {
            ROS_DEBUG_STREAM_NAMED("params", "Setting    " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        else
        {
            param_val = default_val;
            ROS_DEBUG_STREAM_NAMED("params", "Defaulting " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        return param_val;
    }

    template <typename T>
    inline T GetParamDebugLog(ros::NodeHandle& nh, const std::string& param_name, T&& default_val)
    {
        T param_val;
        if (nh.getParam(param_name, param_val))
        {
            ROS_DEBUG_STREAM_NAMED("params", "Setting    " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        else
        {
            param_val = default_val;
            ROS_DEBUG_STREAM_NAMED("params", "Defaulting " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
        }
        return param_val;
    }

    template <typename T>
    inline Maybe::Maybe<T> GetParamRequired(ros::NodeHandle& nh, const std::string& param_name, const std::string& calling_fn_name)
    {
        ROS_DEBUG_STREAM_NAMED("params", "No default value for " << param_name << ": Value must be on paramter sever");
        T param_val;
        if (nh.getParam(param_name, param_val))
        {
            ROS_INFO_STREAM_NAMED("params", "Setting    " << std::left << std::setw(PARAM_NAME_WIDTH) << param_name << " to " << param_val);
            return Maybe::Maybe<T>(param_val);
        }
        else
        {
            ROS_FATAL_STREAM_NAMED("params", "Cannot find " << nh.getNamespace() << "/" << param_name << " on parameter server for " << calling_fn_name << ": Value must be on paramter sever");
            return Maybe::Maybe<T>();
        }
    }
}

#endif // ROS_HELPERS_HPP

{'fraction_non_alphanumeric': 0.1329105383888814, 'fraction_numerical': 0.0005397382269599245, 'mean_word_length': 2.558329332693231, 'pattern_counts': {'":': 4, '<': 231, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4723316', 'n_tokens_mistral': 2406, 'n_tokens_neox': 2334, 'n_words': 468}