Ejemplo n.º 1
0
    def from_name(cls, model, *args, **kwargs):
        """
        Create a Model object from its name.

        :param string model: Name of the model
        :param tuple args: Positional parameters as needed by ``__init__``
        :param dict kwargs: Keyword parameters as needed by ``__init__``

        This constructor is provided for backward compatibility. To specify
        where your model data is loaded from you should create and use your
        own custom cern.cpymad.model_locator.ModelLocator.

        """
        from cern.cpymad.service import default_model_locator
        mdata = default_model_locator.get_model(model)
        return cls(mdata, *args, **kwargs)
Ejemplo n.º 2
0
    def __init__(self, model, sequence='',optics='',histfile='',recursive_history=False):
        """
        Construct a Model object.

        :param ModelData model: model data as acquired through a ModelLocator
        :param string sequence: Name of the default sequence to use
        :param string optics: Name of optics to load, string or list of strings.
        :param string histfile: Name of file which will contain all Mad-X commands called.
        :param bool recursive_history: Recursively load commands of called files into histfile

        For backward compatibility reasons, the first parameter can also be
        the name of the model to be loaded. This is equivalent to the
        preferred Model.from_name() constructor.

        """
        if isinstance(model, model_locator.ModelData):
            mdata = model
        else:
            from cern.cpymad.service import default_model_locator
            mdata = default_model_locator.get_model(model)

        self.mdata = mdata
        self._mdef = mdata.model

        # Defining two pipes which are used for communicating...
        _child_pipe_recv,_parent_send=multiprocessing.Pipe(False)
        _parent_recv,_child_pipe_send=multiprocessing.Pipe(False)
        self._send=_parent_send.send
        self._recv=_parent_recv.recv

        self._mprocess=_modelProcess(_child_pipe_send,_child_pipe_recv,self.name,histfile,recursive_history)

        self._mprocess.start()

        atexit.register(self._mprocess.terminate)

        self._active={'optic':'','sequence':'','range':''}

        self._setup_initial(sequence,optics)