<commit_before>///////////////////////////////////////////////////////////////////////////
//
// INCLUDE FILES
//
///////////////////////////////////////////////////////////////////////////
#include "wrap_syncpart.hh"

#include "pyORBIT_Object.hh"

#include "Bunch.hh"
#include "SyncPart.hh"

namespace wrap_orbit_syncpart{

  void error(const char* msg){ ORBIT_MPI_Finalize(msg); }

#ifdef __cplusplus
extern "C" {
#endif
	//---------------------------------------------------------
	//Python SyncParticle class definition
	//---------------------------------------------------------

	//constructor for python class wrapping SyncPart instance
	//It never will be called directly
	static PyObject* SyncPart_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
	{
		pyORBIT_Object* self;
		self = (pyORBIT_Object *) type->tp_alloc(type, 0);
		self->cpp_obj = NULL;
		return (PyObject *) self;
	}

  //initializator for python  SyncParticle class
  //this is implementation of the __init__ method
  static int SyncPart_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){

	  int nArgs = PyTuple_Size(args);
    if(nArgs != 1){
      error("SyncParticle constructor needs pyBunch instance as parameter.");
    }
		
		pyORBIT_Object* pyBunch = (pyORBIT_Object*) PyTuple_GetItem(args,0);
		Bunch* cpp_bunch = (Bunch*) pyBunch->cpp_obj;
		
		if(cpp_bunch->getSyncPart()->getPyWrapper() != NULL){
			error("You should not create SyncParticle class instance directly!");
		}

    self->cpp_obj = (void*) cpp_bunch->getSyncPart();
		cpp_bunch->getSyncPart()->setPyWrapper((PyObject *) self);

    return 0;
  }

  //-----------------------------------------------------
  //destructor for python SyncParticle class.
	//The destructor of cpp_obj is in the bunch class
  //-----------------------------------------------------
  //this is implementation of the __del__ method
  static void SyncPart_del(pyORBIT_Object* self){
		//std::cerr<<"The SyncPart __del__ has been called!"<<std::endl;
		self->ob_type->tp_free((PyObject*)self);
  }

	//Sets or returns the kinEnergy for the SyncPart object
  //  the action is depended on the number of arguments
  //  kinEnergy() - returns kinEnergy GeV
  //  kinEnergy(value) - sets the new value for pz and px=0,py=0
  static PyObject* SyncPart_kinEnergy(PyObject *self, PyObject *args){
    //if nVars == 0 this is get kinEnergy
    //if nVars == 1 this is set kinEnergy
    int nVars = PyTuple_Size(args);
    pyORBIT_Object* pySyncPart = (pyORBIT_Object*) self;
    double val = 0.;
    if(nVars == 0 ||  nVars == 1){
      if(nVars == 0){
        SyncPart* cpp_SyncPart = (SyncPart*) pySyncPart->cpp_obj;
        val = cpp_SyncPart->getEnergy();
        return Py_BuildValue("d",val);
      }
      else{
        //NO NEW OBJECT CREATED BY PyArg_ParseTuple! - NO NEED OF Py_DECREF()
        if(!PyArg_ParseTuple(	args,"d:kinEnergy",&val)){
          error("PySyncPart - kinEnergy(value) - a new value are needed");
        }
        SyncPart* cpp_SyncPart = (SyncPart*) pySyncPart->cpp_obj;
				val = cpp_SyncPart->energyToMomentum(val);
        cpp_SyncPart->setMomentum(val);
				val = cpp_SyncPart->momentumToEnergy(val);
      }
			return Py_BuildValue("d",val);
    }
    else{
      error("PySyncPart. You should call kinEnergy() or kinEnergy(value)");
    }
    Py_INCREF(Py_None);
    return Py_None;
  }

  //  beta() - returns beta
  static PyObject* SyncPart_beta(PyObject *self, PyObject *args){
    pyORBIT_Object* pySyncPart = (pyORBIT_Object*) self;
    double val = 0.;
		SyncPart* cpp_SyncPart = (SyncPart*) pySyncPart->cpp_obj;
		val = cpp_SyncPart->getBeta();
		return Py_BuildValue("d",val);
  }

  //  gamma() - returns gamma
  static PyObject* SyncPart_gamma(PyObject *self, PyObject *args){
    pyORBIT_Object* pySyncPart = (pyORBIT_Object*) self;
    double val = 0.;
		SyncPart* cpp_SyncPart = (SyncPart*) pySyncPart->cpp_obj;
		val = cpp_SyncPart->getGamma();
		return Py_BuildValue("d",val);
  }

  //  mass() - returns mass in GeV
  static PyObject* SyncPart_mass(PyObject *self, PyObject *args){
    pyORBIT_Object* pySyncPart = (pyORBIT_Object*) self;
    double val = 0.;
		SyncPart* cpp_SyncPart = (SyncPart*) pySyncPart->cpp_obj;
		val = cpp_SyncPart->getMass();
		return Py_BuildValue("d",val);
  }

 //Sets or returns the momentum for the SyncPart object
  //  the action is depended on the number of arguments<commit_msg>The warning was added to the mass method. User cannot change the mass through this method. The Bunch class should be used instead.<commit_after>///////////////////////////////////////////////////////////////////////////
//
// INCLUDE FILES
//
///////////////////////////////////////////////////////////////////////////
#include "wrap_syncpart.hh"

#include "pyORBIT_Object.hh"

#include "Bunch.hh"
#include "SyncPart.hh"

namespace wrap_orbit_syncpart{

  void error(const char* msg){ ORBIT_MPI_Finalize(msg); }

#ifdef __cplusplus
extern "C" {
#endif
	//---------------------------------------------------------
	//Python SyncParticle class definition
	//---------------------------------------------------------

	//constructor for python class wrapping SyncPart instance
	//It never will be called directly
	static PyObject* SyncPart_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
	{
		pyORBIT_Object* self;
		self = (pyORBIT_Object *) type->tp_alloc(type, 0);
		self->cpp_obj = NULL;
		return (PyObject *) self;
	}

  //initializator for python  SyncParticle class
  //this is implementation of the __init__ method
  static int SyncPart_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){

	  int nArgs = PyTuple_Size(args);
    if(nArgs != 1){
      error("SyncParticle constructor needs pyBunch instance as parameter.");
    }
		
		pyORBIT_Object* pyBunch = (pyORBIT_Object*) PyTuple_GetItem(args,0);
		Bunch* cpp_bunch = (Bunch*) pyBunch->cpp_obj;
		
		if(cpp_bunch->getSyncPart()->getPyWrapper() != NULL){
			error("You should not create SyncParticle class instance directly!");
		}

    self->cpp_obj = (void*) cpp_bunch->getSyncPart();
		cpp_bunch->getSyncPart()->setPyWrapper((PyObject *) self);

    return 0;
  }

  //-----------------------------------------------------
  //destructor for python SyncParticle class.
	//The destructor of cpp_obj is in the bunch class
  //-----------------------------------------------------
  //this is implementation of the __del__ method
  static void SyncPart_del(pyORBIT_Object* self){
		//std::cerr<<"The SyncPart __del__ has been called!"<<std::endl;
		self->ob_type->tp_free((PyObject*)self);
  }

	//Sets or returns the kinEnergy for the SyncPart object
  //  the action is depended on the number of arguments
  //  kinEnergy() - returns kinEnergy GeV
  //  kinEnergy(value) - sets the new value for pz and px=0,py=0
  static PyObject* SyncPart_kinEnergy(PyObject *self, PyObject *args){
    //if nVars == 0 this is get kinEnergy
    //if nVars == 1 this is set kinEnergy
    int nVars = PyTuple_Size(args);
    pyORBIT_Object* pySyncPart = (pyORBIT_Object*) self;
    double val = 0.;
    if(nVars == 0 ||  nVars == 1){
      if(nVars == 0){
        SyncPart* cpp_SyncPart = (SyncPart*) pySyncPart->cpp_obj;
        val = cpp_SyncPart->getEnergy();
        return Py_BuildValue("d",val);
      }
      else{
        //NO NEW OBJECT CREATED BY PyArg_ParseTuple! - NO NEED OF Py_DECREF()
        if(!PyArg_ParseTuple(	args,"d:kinEnergy",&val)){
          error("PySyncPart - kinEnergy(value) - a new value are needed");
        }
        SyncPart* cpp_SyncPart = (SyncPart*) pySyncPart->cpp_obj;
				val = cpp_SyncPart->energyToMomentum(val);
        cpp_SyncPart->setMomentum(val);
				val = cpp_SyncPart->momentumToEnergy(val);
      }
			return Py_BuildValue("d",val);
    }
    else{
      error("PySyncPart. You should call kinEnergy() or kinEnergy(value)");
    }
    Py_INCREF(Py_None);
    return Py_None;
  }

  //  beta() - returns beta
  static PyObject* SyncPart_beta(PyObject *self, PyObject *args){
    pyORBIT_Object* pySyncPart = (pyORBIT_Object*) self;
    double val = 0.;
		SyncPart* cpp_SyncPart = (SyncPart*) pySyncPart->cpp_obj;
		val = cpp_SyncPart->getBeta();
		return Py_BuildValue("d",val);
  }

  //  gamma() - returns gamma
  static PyObject* SyncPart_gamma(PyObject *self, PyObject *args){
    pyORBIT_Object* pySyncPart = (pyORBIT_Object*) self;
    double val = 0.;
		SyncPart* cpp_SyncPart = (SyncPart*) pySyncPart->cpp_obj;
		val = cpp_SyncPart->getGamma();
		return Py_BuildValue("d",val);
  }

  //  mass() - returns mass in GeV
  static PyObject* SyncPart_mass(PyObject *self, PyObject *args){
    pyORBIT_Object* pySyncPart = (pyORBIT_Object*) self;
    int nVars = PyTuple_Size(args);
		if(nVars > 0){
			error("PySyncPart - mass() - you should use bunch.mass(mass_value) instead!");
		}
    double val = 0.;
		SyncPart* cpp_SyncPart = (SyncPart*) pySyncPart->cpp_obj;
		val = cpp_SyncPart->getMass();
		return Py_BuildValue("d",val);
  }

 //Sets or returns the momentum for the SyncPart object
  //  the action is depended on the number of arguments
{'fraction_non_alphanumeric': 0.19419938244375828, 'fraction_numerical': 0.0034186149095721216, 'mean_word_length': 2.557865829737152, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 50, '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': '1849801', 'n_tokens_mistral': 2990, 'n_tokens_neox': 2860, 'n_words': 748}