<commit_before>#include <thread>

#include <boost/property_tree/json_parser.hpp>

#include <pdal/PipelineReader.hpp>
#include <pdal/PDALUtils.hpp>
#include <pdal/Dimension.hpp>
#include <pdal/Options.hpp>
#include <pdal/Metadata.hpp>

#include "pdal-session.hpp"
#include "read-command.hpp"

namespace
{
    bool rasterOmit(pdal::Dimension::Id::Enum id)
    {
        // These Dimensions are not explicitly placed in the output buffer
        // for rasterized requests.
        return id == pdal::Dimension::Id::X || id == pdal::Dimension::Id::Y;
    }
}

PdalSession::PdalSession()
    : m_pipelineManager()
    , m_pointBuffer()
    , m_initOnce()
    , m_pdalIndex(new PdalIndex())
{ }

void PdalSession::initialize(const std::string& pipeline, const bool execute)
{
    m_initOnce.ensure([this, &pipeline, execute]() {
        std::istringstream ssPipeline(pipeline);
        pdal::PipelineReader pipelineReader(m_pipelineManager);
        pipelineReader.readPipeline(ssPipeline);

        // This segment could take a substantial amount of time.  The
        // PdalBindings wrapper ensures that it will run in a non-blocking
        // manner in the uv_work_queue.
        if (execute)
        {
            pdal::Options options;
            options.add("do_sample", false);
            m_pipelineManager.addFilter(
                "filters.stats",
                m_pipelineManager.getStage(),
                options);

            m_pipelineManager.execute();

            m_pointContext = m_pipelineManager.context();
            const pdal::PointBufferSet& pbSet(m_pipelineManager.buffers());
            m_pointBuffer = *pbSet.begin();

            if (!m_pointBuffer->hasDim(pdal::Dimension::Id::X) ||
                !m_pointBuffer->hasDim(pdal::Dimension::Id::Y) ||
                !m_pointBuffer->hasDim(pdal::Dimension::Id::Z))
            {
                throw std::runtime_error(
                    "Pipeline output should contain X, Y and Z dimensions");
            }
        }
    });
}

std::size_t PdalSession::getNumPoints() const
{
    return m_pointBuffer->size();
}

std::string PdalSession::getSchema() const
{
    std::ostringstream oss;
    boost::property_tree::ptree tree(pdal::utils::toPTree(m_pointContext));<commit_msg>Update to current PDAL interface.<commit_after>#include <thread>

#include <boost/property_tree/json_parser.hpp>

#include <pdal/PipelineReader.hpp>
#include <pdal/PDALUtils.hpp>
#include <pdal/Dimension.hpp>
#include <pdal/Options.hpp>
#include <pdal/Metadata.hpp>

#include "pdal-session.hpp"
#include "read-command.hpp"

namespace
{
    bool rasterOmit(pdal::Dimension::Id::Enum id)
    {
        // These Dimensions are not explicitly placed in the output buffer
        // for rasterized requests.
        return id == pdal::Dimension::Id::X || id == pdal::Dimension::Id::Y;
    }
}

PdalSession::PdalSession()
    : m_pipelineManager()
    , m_pointBuffer()
    , m_initOnce()
    , m_pdalIndex(new PdalIndex())
{ }

void PdalSession::initialize(const std::string& pipeline, const bool execute)
{
    m_initOnce.ensure([this, &pipeline, execute]() {
        std::istringstream ssPipeline(pipeline);
        pdal::PipelineReader pipelineReader(m_pipelineManager);
        pipelineReader.readPipeline(ssPipeline);

        // This segment could take a substantial amount of time.  The
        // PdalBindings wrapper ensures that it will run in a non-blocking
        // manner in the uv_work_queue.
        if (execute)
        {
            pdal::Options options;
            options.add("do_sample", false);
            m_pipelineManager.addFilter(
                "filters.stats",
                m_pipelineManager.getStage());

            m_pipelineManager.execute();

            m_pointContext = m_pipelineManager.context();
            const pdal::PointBufferSet& pbSet(m_pipelineManager.buffers());
            m_pointBuffer = *pbSet.begin();

            if (!m_pointBuffer->hasDim(pdal::Dimension::Id::X) ||
                !m_pointBuffer->hasDim(pdal::Dimension::Id::Y) ||
                !m_pointBuffer->hasDim(pdal::Dimension::Id::Z))
            {
                throw std::runtime_error(
                    "Pipeline output should contain X, Y and Z dimensions");
            }
        }
    });
}

std::size_t PdalSession::getNumPoints() const
{
    return m_pointBuffer->size();
}

std::string PdalSession::getSchema() const
{
    std::ostringstream oss;
    boost::property_tree::ptree tree(pdal::utils::toPTree(m_pointContext));
{'fraction_non_alphanumeric': 0.1258028792912514, 'fraction_numerical': 0.0, 'mean_word_length': 2.7981497056349873, 'pattern_counts': {'":': 0, '<': 17, '<?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': '2873911', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1359, 'n_words': 262}