<commit_before>#include <fstream>
#include <iostream>

#include <glob.h>

#include <json/json.h>

#include <pdal/StageFactory.hpp>

#include <entwine/third/arbiter/arbiter.hpp>
#include <entwine/reader/query.hpp>
#include <entwine/reader/reader.hpp>
#include <entwine/tree/clipper.hpp>
#include <entwine/types/bounds.hpp>
#include <entwine/types/delta.hpp>
#include <entwine/types/metadata.hpp>
#include <entwine/types/schema.hpp>
#include <entwine/types/structure.hpp>
#include <entwine/util/executor.hpp>

#include "read-queries/entwine.hpp"
#include "read-queries/unindexed.hpp"
#include "util/buffer-pool.hpp"

#include "session.hpp"

namespace
{
    /*
    std::vector<std::string> resolve(
            const std::vector<std::string>& dirs,
            const std::string& name)
    {
        glob_t buffer;
        for (std::size_t i(0); i < dirs.size(); ++i)
        {
            auto flags(GLOB_NOSORT | GLOB_TILDE);
            if (i) flags |= GLOB_APPEND;

            glob((dirs[i] + "/" + name + ".*").c_str(), flags, 0, &buffer);
        }

        std::vector<std::string> results;
        for (std::size_t i(0); i < buffer.gl_pathc; ++i)
        {
            results.push_back(buffer.gl_pathv[i]);
        }

        globfree(&buffer);

        return results;
    }
    */

    std::string getTypeString(const entwine::Structure& structure)
    {
        if (structure.dimensions() == 2)
        {
            if (structure.tubular()) return "octree";
            else return "quadtree";
        }
        else if (structure.dimensions() == 3 && !structure.tubular())
        {
            return "octree";
        }
        else
        {
            throw std::runtime_error("Invalid structure");
        }
    }
}

Session::Session(
        pdal::StageFactory& stageFactory,
        std::mutex& factoryMutex)
    : m_stageFactory(stageFactory)
    , m_factoryMutex(factoryMutex)
    , m_initOnce()
    , m_source()
    , m_entwine()
{ }

Session::~Session()
{ }

bool Session::initialize(
        const std::string& name,
        std::vector<std::string> paths,
        entwine::OuterScope& outerScope,
        std::shared_ptr<entwine::Cache> cache)
{
    m_initOnce.ensure([this, &name, &paths, &cache, &outerScope]()
    {
        std::cout << "Discovering " << name << std::endl;

        if (resolveIndex(name, paths, outerScope, cache))
        {
            std::cout << "\tIndex for " << name << " found" << std::endl;

            Json::Value json;
            const entwine::Metadata& metadata(m_entwine->metadata());

            const std::size_t numPoints(
                    metadata.manifest().pointStats().inserts());

            json["type"] = getTypeString(metadata.structure());
            json["numPoints"] = static_cast<Json::UInt64>(numPoints);
            json["schema"] = metadata.schema().toJson();
            json["bounds"] = metadata.boundsNativeCubic().toJson();
            json["boundsConforming"] =
                metadata.boundsNativeConforming().toJson();
            json["srs"] = metadata.srs();
            json["baseDepth"] = static_cast<Json::UInt64>(
                    metadata.structure().nullDepthEnd());

            if (const entwine::Delta* delta = metadata.delta())
            {
                const entwine::Point& scale(delta->scale());

                if (scale.x == scale.y && scale.x == scale.z)
                {
                    json["scale"] = scale.x;
                }
                else
                {
                    json["scale"] = scale.toJsonArray();
                }

                json["offset"] = delta->offset().toJsonArray();
            }

            m_info = json.toStyledString();
        }
        else if (resolveSource(name, paths))
        {<commit_msg>Add reprojection, if it exists, to info call.<commit_after>#include <fstream>
#include <iostream>

#include <glob.h>

#include <json/json.h>

#include <pdal/StageFactory.hpp>

#include <entwine/third/arbiter/arbiter.hpp>
#include <entwine/reader/query.hpp>
#include <entwine/reader/reader.hpp>
#include <entwine/tree/clipper.hpp>
#include <entwine/types/bounds.hpp>
#include <entwine/types/delta.hpp>
#include <entwine/types/metadata.hpp>
#include <entwine/types/reprojection.hpp>
#include <entwine/types/schema.hpp>
#include <entwine/types/structure.hpp>
#include <entwine/util/executor.hpp>

#include "read-queries/entwine.hpp"
#include "read-queries/unindexed.hpp"
#include "util/buffer-pool.hpp"

#include "session.hpp"

namespace
{
    /*
    std::vector<std::string> resolve(
            const std::vector<std::string>& dirs,
            const std::string& name)
    {
        glob_t buffer;
        for (std::size_t i(0); i < dirs.size(); ++i)
        {
            auto flags(GLOB_NOSORT | GLOB_TILDE);
            if (i) flags |= GLOB_APPEND;

            glob((dirs[i] + "/" + name + ".*").c_str(), flags, 0, &buffer);
        }

        std::vector<std::string> results;
        for (std::size_t i(0); i < buffer.gl_pathc; ++i)
        {
            results.push_back(buffer.gl_pathv[i]);
        }

        globfree(&buffer);

        return results;
    }
    */

    std::string getTypeString(const entwine::Structure& structure)
    {
        if (structure.dimensions() == 2)
        {
            if (structure.tubular()) return "octree";
            else return "quadtree";
        }
        else if (structure.dimensions() == 3 && !structure.tubular())
        {
            return "octree";
        }
        else
        {
            throw std::runtime_error("Invalid structure");
        }
    }
}

Session::Session(
        pdal::StageFactory& stageFactory,
        std::mutex& factoryMutex)
    : m_stageFactory(stageFactory)
    , m_factoryMutex(factoryMutex)
    , m_initOnce()
    , m_source()
    , m_entwine()
{ }

Session::~Session()
{ }

bool Session::initialize(
        const std::string& name,
        std::vector<std::string> paths,
        entwine::OuterScope& outerScope,
        std::shared_ptr<entwine::Cache> cache)
{
    m_initOnce.ensure([this, &name, &paths, &cache, &outerScope]()
    {
        std::cout << "Discovering " << name << std::endl;

        if (resolveIndex(name, paths, outerScope, cache))
        {
            std::cout << "\tIndex for " << name << " found" << std::endl;

            Json::Value json;
            const entwine::Metadata& metadata(m_entwine->metadata());

            const std::size_t numPoints(
                    metadata.manifest().pointStats().inserts());

            json["type"] = getTypeString(metadata.structure());
            json["numPoints"] = static_cast<Json::UInt64>(numPoints);
            json["schema"] = metadata.schema().toJson();
            json["bounds"] = metadata.boundsNativeCubic().toJson();
            json["boundsConforming"] =
                metadata.boundsNativeConforming().toJson();
            json["srs"] = metadata.srs();
            json["baseDepth"] = static_cast<Json::UInt64>(
                    metadata.structure().nullDepthEnd());

            if (const entwine::Reprojection* r = metadata.reprojection())
            {
                json["reprojection"] = r->toJson();
            }

            if (const entwine::Delta* delta = metadata.delta())
            {
                const entwine::Point& scale(delta->scale());

                if (scale.x == scale.y && scale.x == scale.z)
                {
                    json["scale"] = scale.x;
                }
                else
                {
                    json["scale"] = scale.toJsonArray();
                }

                json["offset"] = delta->offset().toJsonArray();
            }

            m_info = json.toStyledString();
        }
        else if (resolveSource(name, paths))
        {
{'fraction_non_alphanumeric': 0.1526579997425666, 'fraction_numerical': 0.002316900501995109, 'mean_word_length': 2.105515587529976, 'pattern_counts': {'":': 0, '<': 80, '<?xml version=': 0, '>': 55, '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': '1516266', 'n_tokens_mistral': 2429, 'n_tokens_neox': 2323, 'n_words': 410}