code: def _get_sample_info(fname, res4, system_clock):
      """Determine the number of valid samples."""
      logger.info("Finding samples for %s: " % (fname,))
      if CTF.SYSTEM_CLOCK_CH in res4["ch_names"]:
          clock_ch = res4["ch_names"].index(CTF.SYSTEM_CLOCK_CH)
      else:
          clock_ch = None
      for k, ch in enumerate(res4["chs"]):
          if ch["ch_name"] == CTF.SYSTEM_CLOCK_CH:
              clock_ch = k
              break
      with open(fname, "rb") as fid:
          fid.seek(0, os.SEEK_END)
          st_size = fid.tell()
          fid.seek(0, 0)
          if (st_size - CTF.HEADER_SIZE) % (
              4 * res4["nsamp"] * res4["nchan"]
          ) != 0:
              raise RuntimeError(
                  "The number of samples is not an even multiple "
                  "of the trial size"
              )
          n_samp_tot = (st_size - CTF.HEADER_SIZE) // (
              4 * res4["nchan"]
          )
          n_trial = n_samp_tot // res4["nsamp"]
          n_samp = n_samp_tot
          if clock_ch is None:
              logger.info(
                  "    System clock channel is not available, assuming "
                  "all samples to be valid."
              )
          elif system_clock == "ignore":
              logger.info(
                  "    System clock channel is available, but ignored."
              )
          else:  # use it
              logger.info(
                  "    System clock channel is available, checking "
                  "which samples are valid."
              )
              for t in range(n_trial):
                  # Skip to the correct trial
                  samp_offset = t * res4["nsamp"]
                  offset = (
                      CTF.HEADER_SIZE
                      + (
                          samp_offset * res4["nchan"]
                          + (clock_ch * res4["nsamp"])
                      )
                      * 4
                  )
                  fid.seek(offset, 0)
                  this_data = np.fromfile(fid, ">i4", res4["nsamp"])
                  if len(this_data) != res4["nsamp"]:
                      raise RuntimeError(
                          "Cannot read data for trial %d" % (t + 1)
                      )
                  end = np.where(this_data == 0)[0]
                  if len(end) > 0:
                      n_samp = samp_offset + end[0]
                      break
      if n_samp < res4["nsamp"]:
          n_trial = 1
          logger.info(
              "    %d x %d = %d samples from %d chs"
              % (n_trial, n_samp, n_samp, res4["nchan"])
          )
      else:
          n_trial = n_samp // res4["nsamp"]
          n_omit = n_samp_tot - n_samp
          logger.info(
              "    %d x %d = %d samples from %d chs"
              % (n_trial, res4["nsamp"], n_samp, res4["nchan"])
          )
          if n_omit != 0:
              logger.info("    %d samples omitted at the end" % n_omit)
  
      return dict(
          n_samp=n_samp,
          n_samp_tot=n_samp_tot,
          block_size=res4["nsamp"],
          res4_nsamp=res4["nsamp"],
          n_chan=res4["nchan"],
      )
  
imports: import os
  import numpy
  from ..._fiff._digitization import _format_dig_points
  from ..._fiff.utils import _blk_read_lims, _mult_cal_one
  from ...utils import _check_fname, _check_option, _clean_names, fill_doc, logger, verbose
  from ..base import BaseRaw
  from .constants import CTF
  from .eeg import _read_eeg, _read_pos
  from .hc import _read_hc
  from .info import _annotate_bad_segments, _compose_meas_info, _read_bad_chans
  from .markers import _read_annotations_ctf_call
  from .res4 import _make_ctf_name, _read_res4
  from .trans import _make_ctf_coord_trans_set
label_desc: Use image node_id 3 for calling a global function with example usage: _get_sample_info(fname, res4, system_clock) and returns: dict