<commit_before>/// HEADER
#include <csapex/model/subgraph_node.h>

/// PROJECT
#include <csapex/msg/input_transition.h>
#include <csapex/msg/output_transition.h>
#include <csapex/model/graph/graph_impl.h>
#include <csapex/signal/slot.h>
#include <csapex/signal/event.h>
#include <csapex/model/node.h>
#include <csapex/model/node_handle.h>
#include <csapex/model/node_modifier.h>
#include <csapex/msg/io.h>
#include <csapex/msg/generic_vector_message.hpp>
#include <csapex/param/parameter_factory.h>
#include <csapex/param/bitset_parameter.h>
#include <csapex/utility/debug.h>
#include <csapex/model/node_worker.h>

/// SYSTEM
#include <iostream>

using namespace csapex;

SubgraphNode::SubgraphNode(GraphImplementationPtr graph)
    : graph_(graph),
      transition_relay_in_(new InputTransition),
      transition_relay_out_(new OutputTransition),
      is_subgraph_finished_(false),
      is_iterating_(false), has_sent_current_iteration_(false),
      is_initialized_(false),

      activation_event_(nullptr),
      deactivation_event_(nullptr),

      guard_(-1)
{
    transition_relay_in_->setActivationFunction(delegate::Delegate0<>(this, &SubgraphNode::subgraphHasProducedAllMessages));
    observe(transition_relay_out_->messages_processed, delegate::Delegate0<>(this, &SubgraphNode::currentIterationIsProcessed));
}

SubgraphNode::~SubgraphNode()
{
    guard_ = 0xDEADBEEF;
}

bool SubgraphNode::canRunInSeparateProcess() const
{
    return false;
}

GraphPtr SubgraphNode::getGraph() const
{
    return graph_;
}

GraphImplementationPtr SubgraphNode::getLocalGraph() const
{
    return graph_;
}

void SubgraphNode::initialize(NodeHandlePtr node_handle)
{
    Node::initialize(node_handle);

    if(node_handle->getUUIDProvider()) {
        graph_->setParent(node_handle->getUUIDProvider()->shared_from_this(), node_handle->getUUID().getAbsoluteUUID());
    }
}

void SubgraphNode::setNodeFacade(csapex::NodeFacadeImplementation* graph_node_facade)
{
    graph_->setNodeFacade(graph_node_facade);
}

void SubgraphNode::detach()
{
    graph_->clear();
    Node::detach();
}

void SubgraphNode::tearDown()
{
    is_initialized_ = false;
}

void SubgraphNode::reset()
{
    Node::reset();

    graph_->resetActivity();

    {
        std::unique_lock<std::recursive_mutex> lock(continuation_mutex_);
        continuation_ = Continuation();
    }

    transition_relay_out_->reset();
    transition_relay_in_->reset();
}

void SubgraphNode::stateChanged()
{
    Node::stateChanged();

    if(!is_initialized_) {
        is_initialized_ = true;
    }
}
void SubgraphNode::setup(NodeModifier &modifier)
{
    setupVariadic(modifier);

    activation_event_ = createInternalEvent(connection_types::makeEmpty<connection_types::AnyMessage>(), graph_->makeUUID("event_activation"), "activation");
    deactivation_event_ = createInternalEvent(connection_types::makeEmpty<connection_types::AnyMessage>(), graph_->makeUUID("event_deactivation"), "deactivation");
}

void SubgraphNode::activation()
{
    if(activation_event_) {
        TokenDataConstPtr data(new connection_types::AnyMessage);
        TokenPtr token = std::make_shared<Token>(data);
        token->setActivityModifier(ActivityModifier::ACTIVATE);
        activation_event_->triggerWith(token);
    }
}

void SubgraphNode::deactivation()
{
    if(deactivation_event_) {
        TokenDataConstPtr data(new connection_types::AnyMessage);
        TokenPtr token = std::make_shared<Token>(data);
        token->setActivityModifier(ActivityModifier::DEACTIVATE);
        deactivation_event_->triggerWith(token);
    }
}

bool SubgraphNode::canProcess() const
{
    if(!is_initialized_) {
        //TRACE ainfo << "cannot process: not initialized" << std::endl;
        return false;
    }
    if(!transition_relay_out_->canStartSendingMessages()) {
        //TRACE ainfo << "cannot process, out relay cannot send" << std::endl;
        return false;
    }
    return true;
}


void SubgraphNode::setupParameters(Parameterizable &params)
{
    setupVariadicParameters(params);

    params.addParameter(param::ParameterFactory::declareBool("iterate_containers",
                                                             param::ParameterDescription("When true, input vectors will be iterated internally"),
                                                             false));


    std::map<std::string, std::pair<int, bool> > flags;<commit_msg>Do not process graphs without global connections<commit_after>/// HEADER
#include <csapex/model/subgraph_node.h>

/// PROJECT
#include <csapex/msg/input_transition.h>
#include <csapex/msg/output_transition.h>
#include <csapex/model/graph/graph_impl.h>
#include <csapex/signal/slot.h>
#include <csapex/signal/event.h>
#include <csapex/model/node.h>
#include <csapex/model/node_handle.h>
#include <csapex/model/node_modifier.h>
#include <csapex/msg/io.h>
#include <csapex/msg/generic_vector_message.hpp>
#include <csapex/param/parameter_factory.h>
#include <csapex/param/bitset_parameter.h>
#include <csapex/utility/debug.h>
#include <csapex/model/node_worker.h>

/// SYSTEM
#include <iostream>

using namespace csapex;

SubgraphNode::SubgraphNode(GraphImplementationPtr graph)
    : graph_(graph),
      transition_relay_in_(new InputTransition),
      transition_relay_out_(new OutputTransition),
      is_subgraph_finished_(false),
      is_iterating_(false), has_sent_current_iteration_(false),
      is_initialized_(false),

      activation_event_(nullptr),
      deactivation_event_(nullptr),

      guard_(-1)
{
    transition_relay_in_->setActivationFunction(delegate::Delegate0<>(this, &SubgraphNode::subgraphHasProducedAllMessages));
    observe(transition_relay_out_->messages_processed, delegate::Delegate0<>(this, &SubgraphNode::currentIterationIsProcessed));
}

SubgraphNode::~SubgraphNode()
{
    guard_ = 0xDEADBEEF;
}

bool SubgraphNode::canRunInSeparateProcess() const
{
    return false;
}

GraphPtr SubgraphNode::getGraph() const
{
    return graph_;
}

GraphImplementationPtr SubgraphNode::getLocalGraph() const
{
    return graph_;
}

void SubgraphNode::initialize(NodeHandlePtr node_handle)
{
    Node::initialize(node_handle);

    if(node_handle->getUUIDProvider()) {
        graph_->setParent(node_handle->getUUIDProvider()->shared_from_this(), node_handle->getUUID().getAbsoluteUUID());
    }
}

void SubgraphNode::setNodeFacade(csapex::NodeFacadeImplementation* graph_node_facade)
{
    graph_->setNodeFacade(graph_node_facade);
}

void SubgraphNode::detach()
{
    graph_->clear();
    Node::detach();
}

void SubgraphNode::tearDown()
{
    is_initialized_ = false;
}

void SubgraphNode::reset()
{
    Node::reset();

    graph_->resetActivity();

    {
        std::unique_lock<std::recursive_mutex> lock(continuation_mutex_);
        continuation_ = Continuation();
    }

    transition_relay_out_->reset();
    transition_relay_in_->reset();
}

void SubgraphNode::stateChanged()
{
    Node::stateChanged();

    if(!is_initialized_) {
        is_initialized_ = true;
    }
}
void SubgraphNode::setup(NodeModifier &modifier)
{
    setupVariadic(modifier);

    activation_event_ = createInternalEvent(connection_types::makeEmpty<connection_types::AnyMessage>(), graph_->makeUUID("event_activation"), "activation");
    deactivation_event_ = createInternalEvent(connection_types::makeEmpty<connection_types::AnyMessage>(), graph_->makeUUID("event_deactivation"), "deactivation");
}

void SubgraphNode::activation()
{
    if(activation_event_) {
        TokenDataConstPtr data(new connection_types::AnyMessage);
        TokenPtr token = std::make_shared<Token>(data);
        token->setActivityModifier(ActivityModifier::ACTIVATE);
        activation_event_->triggerWith(token);
    }
}

void SubgraphNode::deactivation()
{
    if(deactivation_event_) {
        TokenDataConstPtr data(new connection_types::AnyMessage);
        TokenPtr token = std::make_shared<Token>(data);
        token->setActivityModifier(ActivityModifier::DEACTIVATE);
        deactivation_event_->triggerWith(token);
    }
}

bool SubgraphNode::canProcess() const
{
    if(!is_initialized_) {
        //TRACE ainfo << "cannot process: not initialized" << std::endl;
        return false;
    }
    if(!transition_relay_out_->canStartSendingMessages()) {
        //TRACE ainfo << "cannot process, out relay cannot send" << std::endl;
        return false;
    }
    if(transition_relay_in_->hasConnection() ||
            transition_relay_out_->hasConnection()) {
        return true;
    } else {
        return false;
    }
}


void SubgraphNode::setupParameters(Parameterizable &params)
{
    setupVariadicParameters(params);

    params.addParameter(param::ParameterFactory::declareBool("iterate_containers",
                                                             param::ParameterDescription("When true, input vectors will be iterated internally"),
                                                             false));


    std::map<std::string, std::pair<int, bool> > flags;
{'fraction_non_alphanumeric': 0.12552812986435402, 'fraction_numerical': 0.00088948187680676, 'mean_word_length': 4.363744782349434, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2968943', 'n_tokens_mistral': 2766, 'n_tokens_neox': 2734, 'n_words': 396}