Ejemplo n.º 1
0
 def _connect_shmem_cli(self, tag):
     # ShmemClients open a connection in connect() and close it in
     # the destructor. By creating a new client every time, we ensure
     # that python call the destructor in the gc routine.
     self.shmem_cli = PyShmemClient()
     for retry in range(SHMEM_CONN_MAX_RETRIES):
         #establish connection to available server - blocking
         status = int(self.shmem_cli.connect(tag, 0))
         if status == 0:
             break
         time.sleep(0.01)
     assert not status, 'shmem connect failure %d' % status
     #wait for first configure datagram - blocking
     view = self.shmem_cli.get(self.shmem_kwargs)
     assert view
     # Release shmem buffer after copying Transition data
     # cpo: copy L1Accepts too because some shmem
     # applications like AMI's pickN can hold references
     # to dgrams for a long time, consuming the shmem buffers
     # and creating a deadlock situation. could revisit this
     # later and only deep-copy arrays inside pickN, for example
     # but would be more fragile.
     barray = bytes(view[:_dgSize(view)])
     self.shmem_cli.freeByIndex(self.shmem_kwargs['index'],
                                self.shmem_kwargs['size'])
     view = memoryview(barray)
     return view
Ejemplo n.º 2
0
    def __init__(self, xtc_files, configs=[], fds=[], tag=None, run=None):
        """ Opens xtc_files and stores configs.
        If file descriptors (fds) is given, reuse the given file descriptors.
        """
        self.xtc_files = []
        self.shmem_cli = None
        self.shmem_kwargs = {'index': -1, 'size': 0, 'cli_cptr': None}
        self.configs = []
        self._timestamps = []  # built when iterating
        self._run = run

        if isinstance(xtc_files, (str)):
            self.xtc_files = np.array([xtc_files], dtype='U%s' % FN_L)
        elif isinstance(xtc_files, (list, np.ndarray)):
            if len(xtc_files) > 0:  # handles smalldata-only case
                if xtc_files[0] == 'shmem':
                    self.shmem_cli = PyShmemClient()
                    #establish connection to available server - blocking
                    status = int(self.shmem_cli.connect(tag, 0))
                    assert not status, 'shmem connect failure %d' % status
                    #wait for first configure datagram - blocking
                    view = self.shmem_cli.get(self.shmem_kwargs)
                    assert view
                    # Release shmem buffer after copying Transition data
                    if _service(view) != TransitionId.L1Accept:
                        barray = bytes(view[:_dgSize(view)])
                        self.shmem_cli.freeByIndex(self.shmem_kwargs['index'],
                                                   self.shmem_kwargs['size'])
                        view = memoryview(barray)
                    d = dgram.Dgram(view=view, \
                                    shmem_index=self.shmem_kwargs['index'], \
                                    shmem_size=self.shmem_kwargs['size'], \
                                    shmem_cli_cptr=self.shmem_kwargs['cli_cptr'], \
                                    shmem_cli_pyobj=self.shmem_cli)
                    self.configs += [d]
                else:
                    self.xtc_files = np.asarray(xtc_files, dtype='U%s' % FN_L)

        self.given_fds = True if len(fds) > 0 else False
        if self.given_fds:
            self.fds = np.asarray(fds, dtype=np.int32)
        else:
            self.fds = np.array([
                os.open(xtc_file, os.O_RDONLY) for xtc_file in self.xtc_files
            ],
                                dtype=np.int32)

        given_configs = True if len(configs) > 0 else False
        if given_configs:
            self.configs = configs
        elif xtc_files[0] != 'shmem':
            self.configs = [dgram.Dgram(file_descriptor=fd) for fd in self.fds]

        self.det_classes, self.xtc_info, self.det_info_table = self.get_det_class_table(
        )
        self.calibconst = {
        }  # initialize to empty dict - will be populated by run class
Ejemplo n.º 3
0
    def __init__(self, xtc_files, configs=[], fds=[], tag=None, run=None, max_retries=0):
        """ Opens xtc_files and stores configs.
        If file descriptors (fds) is given, reuse the given file descriptors.
        """
        self.xtc_files = []
        self.shmem_cli = None
        self.shmem_kwargs = {'index':-1,'size':0,'cli_cptr':None}
        self.configs = []
        self._timestamps = [] # built when iterating
        self._run = run
        self.found_endrun = True
        self.buffered_beginruns = []
        self.max_retries = max_retries

        if isinstance(xtc_files, (str)):
            self.xtc_files = np.array([xtc_files], dtype='U%s'%FN_L)
        elif isinstance(xtc_files, (list, np.ndarray)):
            if len(xtc_files) > 0: # handles smalldata-only case
                if xtc_files[0] == 'shmem':
                    self.shmem_cli = PyShmemClient()
                    #establish connection to available server - blocking
                    status = int(self.shmem_cli.connect(tag,0))
                    assert not status,'shmem connect failure %d' % status
                    #wait for first configure datagram - blocking
                    view = self.shmem_cli.get(self.shmem_kwargs)
                    assert view
                    # Release shmem buffer after copying Transition data
                    # cpo: copy L1Accepts too because some shmem
                    # applications like AMI's pickN can hold references
                    # to dgrams for a long time, consuming the shmem buffers
                    # and creating a deadlock situation. could revisit this
                    # later and only deep-copy arrays inside pickN, for example
                    # but would be more fragile.
                    barray = bytes(view[:_dgSize(view)])
                    self.shmem_cli.freeByIndex(self.shmem_kwargs['index'], self.shmem_kwargs['size'])
                    view = memoryview(barray)
                    d = dgram.Dgram(view=view)
                    self.configs += [d]
                else:
                    self.xtc_files = np.asarray(xtc_files, dtype='U%s'%FN_L)


        self.given_fds = True if len(fds) > 0 else False
        if self.given_fds:
            self.fds = np.asarray(fds, dtype=np.int32)
        else:
            self.fds = np.array([os.open(xtc_file, os.O_RDONLY) for xtc_file in self.xtc_files], dtype=np.int32)
        
        given_configs = True if len(configs) > 0 else False
        if given_configs:
            self.configs = configs
        elif xtc_files[0] != 'shmem':
            self.configs = [dgram.Dgram(file_descriptor=fd, max_retries=self.max_retries) for fd in self.fds]

        self.calibconst = {} # initialize to empty dict - will be populated by run class
Ejemplo n.º 4
0
    def __init__(self, xtc_files, configs=[], tag=None, run=None):
        """ Opens xtc_files and stores configs."""
        self.xtc_files = []
        self.shmem_cli = None
        self.shmem_kwargs = {'index':-1,'size':0,'cli_cptr':None}
        self.configs = []
        self.fds = []
        self._timestamps = [] # built when iterating 
        self._run = run

        if isinstance(xtc_files, (str)):
            self.xtc_files = np.array([xtc_files], dtype='U%s'%FN_L)
            assert len(self.xtc_files) > 0
        elif isinstance(xtc_files, (list, np.ndarray)):
            if len(xtc_files) > 0: # handles smalldata-only case
                if xtc_files[0] == 'shmem':
                    self.shmem_cli = PyShmemClient()
                    #establish connection to available server - blocking
                    status = int(self.shmem_cli.connect(tag,0))
                    assert not status,'shmem connect failure %d' % status
                    #wait for first configure datagram - blocking
                    view = self.shmem_cli.get(self.shmem_kwargs)
                    assert view
                    d = dgram.Dgram(view=view, \
                                    shmem_index=self.shmem_kwargs['index'], \
                                    shmem_size=self.shmem_kwargs['size'], \
                                    shmem_cli_cptr=self.shmem_kwargs['cli_cptr'], \
                                    shmem_cli_pyobj=self.shmem_cli)
                    self.configs += [d]
                else:    
                    self.xtc_files = np.asarray(xtc_files, dtype='U%s'%FN_L)
                    assert len(self.xtc_files) > 0
            
        given_configs = True if len(configs) > 0 else False
        
        if given_configs: 
            self.configs = configs
        
        for i, xtcdata_filename in enumerate(self.xtc_files):
            self.fds.append(os.open(xtcdata_filename,
                            os.O_RDONLY))
            if not given_configs: 
                d = dgram.Dgram(file_descriptor=self.fds[-1])
                self.configs += [d]

        self.det_class_table, self.xtc_info = self.get_det_class_table()
        self.calibs = {} # initialize to empty dict - will be populated by run class