<commit_before>#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>

#include <iostream>
#include <string>

#include "sixtracklib/testlib.h"
#include "sixtracklib/sixtracklib.hpp"

int main( int argc, char* argv[] )
{
    namespace st = sixtrack;

    using size_t      = st::Buffer::size_type;
    using track_job_t = st::TrackJobCpu;

    st::Buffer input_pb;
    st::Buffer pb;
    st::Buffer eb;

    st::Particles* particles = nullptr;

    int NUM_PARTICLES                  = 0;
    int NUM_TURNS                      = 10;
    int NUM_TURNS_ELEM_BY_ELEM         = 3;
    int OUTPUT_SKIP                    = 1;
    int track_status                   = 0;

    /* -------------------------------------------------------------------- */
    /* Read command line parameters */

    if( argc < 3 )
    {
        std::cout << "Usage: " << argv[ 0 ]
                  << " PATH_TO_PARTICLES PATH_TO_BEAM_ELEMENTS" << std::endl;
        return 0;
    }

    if( ( argc >= 3 ) &&
        ( argv[ 1 ] != nullptr ) && ( std::strlen( argv[ 1 ] ) > 0u ) &&
        ( argv[ 2 ] != nullptr ) && ( std::strlen( argv[ 2 ] ) > 0u ) )
    {
        input_pb.readFromFile( argv[ 1 ] );
        eb.readFromFile( argv[ 2 ] );

        NUM_PARTICLES = st::Particles::FromBuffer(
            input_pb, 0u )->getNumParticles();
    }

    /* --------------------------------------------------------------------- */
    /* Prepare input and tracking data from run-time parameters: */

    std::printf("%-30s = %10d\n","NUM_PARTICLES",NUM_PARTICLES);
    std::printf("%-30s = %10d\n","NUM_TURNS",NUM_TURNS);
    std::printf("%-30s = %10d\n","NUM_TURNS_ELEM_BY_ELEM",NUM_TURNS_ELEM_BY_ELEM);
    std::printf("%-30s = %10d\n","OUTPUT_SKIP", OUTPUT_SKIP);

    if( NUM_PARTICLES >= 0 )
    {
        particles = pb.createNew< st::Particles >(
            st::Particles::FromBuffer( input_pb, 0u )->getNumParticles() );
    }

    if( ( eb.getNumObjects() > size_t{ 0 } ) &&
        ( NUM_TURNS > NUM_TURNS_ELEM_BY_ELEM ) )
    {
        st::BeamMonitor* beam_monitor = eb.createNew< st::BeamMonitor >();
        beam_monitor->setNumStores( NUM_TURNS - NUM_TURNS_ELEM_BY_ELEM );
        beam_monitor->setStart( NUM_TURNS_ELEM_BY_ELEM );
        beam_monitor->setSkip( OUTPUT_SKIP );
        beam_monitor->setIsRolling( true );
    }

    /* ********************************************************************* */
    /* ****               PERFORM TRACKING OPERATIONS                ******* */
    /* ********************************************************************* */

    if( ( particles != nullptr ) && ( NUM_PARTICLES > 0 ) && ( NUM_TURNS > 0 ) )
    {
        /* Create the track_job */
        track_job_t job( pb, eb, nullptr, NUM_TURNS_ELEM_BY_ELEM );

        if( NUM_TURNS_ELEM_BY_ELEM > 0 )
        {
            track_status |= st::trackElemByElem( job, NUM_TURNS_ELEM_BY_ELEM );
        }

        if( NUM_TURNS > NUM_TURNS_ELEM_BY_ELEM )
        {
            track_status |= st::track( job, NUM_TURNS );
        }

        /* ****************************************************************** */
        /* ****               PERFORM OUTPUT OPERATIONS                ****** */
        /* ****************************************************************** */

        /* NOTE: for the CPU Track Job, collect (currently) performs no
         * operations. Since this *might* change in the future, it's
         * mandated to always call NS(TrackJobCpu_collect)() before
         * accessing the particles, the beam elements or the
         * output buffer */

        st::collect( job );

        if( track_status == 0 )
        {
            st::Buffer* out_buffer = nullptr;

            if( job.hasOutputBuffer() )
            {
                out_buffer = job.ptrOutputBuffer();
            }

            if( job.hasElemByElemOutput() )<commit_msg>examples/cxx: use updated public trackJob API for example<commit_after>#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>

#include <iostream>
#include <string>

#include "sixtracklib/testlib.h"
#include "sixtracklib/sixtracklib.hpp"

int main( int argc, char* argv[] )
{
    namespace st = sixtrack;

    using size_t      = st::Buffer::size_type;
    using track_job_t = st::TrackJobCpu;

    st::Buffer input_pb;
    st::Buffer pb;
    st::Buffer eb;

    st::Particles* particles = nullptr;

    int NUM_PARTICLES                  = 0;
    int NUM_TURNS                      = 10;
    int NUM_TURNS_ELEM_BY_ELEM         = 3;
    int OUTPUT_SKIP                    = 1;
    int track_status                   = 0;

    /* -------------------------------------------------------------------- */
    /* Read command line parameters */

    if( argc < 3 )
    {
        std::cout << "Usage: " << argv[ 0 ]
                  << " PATH_TO_PARTICLES PATH_TO_BEAM_ELEMENTS" << std::endl;
        return 0;
    }

    if( ( argc >= 3 ) &&
        ( argv[ 1 ] != nullptr ) && ( std::strlen( argv[ 1 ] ) > 0u ) &&
        ( argv[ 2 ] != nullptr ) && ( std::strlen( argv[ 2 ] ) > 0u ) )
    {
        input_pb.readFromFile( argv[ 1 ] );
        eb.readFromFile( argv[ 2 ] );

        NUM_PARTICLES = st::Particles::FromBuffer(
            input_pb, 0u )->getNumParticles();
    }

    /* --------------------------------------------------------------------- */
    /* Prepare input and tracking data from run-time parameters: */

    std::printf("%-30s = %10d\n","NUM_PARTICLES",NUM_PARTICLES);
    std::printf("%-30s = %10d\n","NUM_TURNS",NUM_TURNS);
    std::printf("%-30s = %10d\n","NUM_TURNS_ELEM_BY_ELEM",NUM_TURNS_ELEM_BY_ELEM);
    std::printf("%-30s = %10d\n","OUTPUT_SKIP", OUTPUT_SKIP);

    if( NUM_PARTICLES >= 0 )
    {
        particles = pb.createNew< st::Particles >(
            st::Particles::FromBuffer( input_pb, 0u )->getNumParticles() );
    }

    if( ( eb.getNumObjects() > size_t{ 0 } ) &&
        ( NUM_TURNS > NUM_TURNS_ELEM_BY_ELEM ) )
    {
        st::BeamMonitor* beam_monitor = eb.createNew< st::BeamMonitor >();
        beam_monitor->setNumStores( NUM_TURNS - NUM_TURNS_ELEM_BY_ELEM );
        beam_monitor->setStart( NUM_TURNS_ELEM_BY_ELEM );
        beam_monitor->setSkip( OUTPUT_SKIP );
        beam_monitor->setIsRolling( true );
    }

    /* ********************************************************************* */
    /* ****               PERFORM TRACKING OPERATIONS                ******* */
    /* ********************************************************************* */

    if( ( particles != nullptr ) && ( NUM_PARTICLES > 0 ) && ( NUM_TURNS > 0 ) )
    {
        /* Create the track_job */
        track_job_t job( pb, eb, nullptr, NUM_TURNS_ELEM_BY_ELEM );

        if( NUM_TURNS_ELEM_BY_ELEM > 0 )
        {
            track_status |= st::trackElemByElem( job, NUM_TURNS_ELEM_BY_ELEM );
        }

        if( NUM_TURNS > NUM_TURNS_ELEM_BY_ELEM )
        {
            track_status |= st::trackUntil( job, NUM_TURNS );
        }

        /* ****************************************************************** */
        /* ****               PERFORM OUTPUT OPERATIONS                ****** */
        /* ****************************************************************** */

        /* NOTE: for the CPU Track Job, collect (currently) performs no
         * operations. Since this *might* change in the future, it's
         * mandated to always call NS(TrackJobCpu_collect)() before
         * accessing the particles, the beam elements or the
         * output buffer */

        st::collect( job );

        if( track_status == 0 )
        {
            st::Buffer* out_buffer = nullptr;

            if( job.hasOutputBuffer() )
            {
                out_buffer = job.ptrOutputBuffer();
            }

            if( job.hasElemByElemOutput() )
{'fraction_non_alphanumeric': 0.22781253990550376, 'fraction_numerical': 0.010726599412590984, 'mean_word_length': 1.9836190476190476, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 53, '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': '219660', 'n_tokens_mistral': 2635, 'n_tokens_neox': 2395, 'n_words': 471}