Class HelicitySequence

java.lang.Object
org.jlab.detector.helicity.HelicitySequence
Direct Known Subclasses:
HelicitySequenceDelayed

public class HelicitySequence extends Object
Stores a sequence of helicity states and provides timestamp- or state-count- based search of helicity state based on the measured sequence or pseudo-random generator sequence, and provides some integrity checking of the sequence, including comparing the measured and generator sequences. ____________________________________________________________________ Getter methods naming convention: Prefixes: "get" - based on state count "search" - based on finding timestamp in the measured sequence "predict" - based on generator seed time and expected periodicity Suffixes: "Generated" - use the psuedo-random generator's sequence ____________________________________________________________________ The generator methods are able to look past the measured range, while the non-generator methods cannot. The inputs to initialize the sequence are HelicityState objects, one per window at the helicity board clock frequency, which contain important information for constructing and validating the sequence (e.g. helicity and sync bits and timestamps). The return values from getters are just HelicityBit objects and represent the HWP-corrected helicity. See HelicityAnalysisSimple for an example on using this class.
Author:
baltzell
  • Field Details Link icon

  • Constructor Details Link icon

    • HelicitySequence Link icon

      public HelicitySequence()
  • Method Details Link icon

    • getHalfWavePlate Link icon

      public boolean getHalfWavePlate()
    • size Link icon

      public final int size()
      Get the the number of states in the sequence.
      Returns:
      the number of states
    • addState Link icon

      public final boolean addState(HelicityState state)
      Add a state to the sequence, unless the same timestamp already exists or it has undefined bits, and keep them ordered by timestamp. Note, these HelicityStates do not have to be added in order, as they will be automatically ordered by timestamp upon insertion.
      Parameters:
      state - the state to add
      Returns:
      whether the state was added
    • getBitInQuartet Link icon

      public static final HelicityBit getBitInQuartet(HelicityBit firstBit, int bitIndex)
      Given the first helicity state in a quartet, get another bit in that quartet.
      Parameters:
      firstBit - first helicity state in the quartet
      bitIndex - index of the state to retrieve (0/1/2/3)
      Returns:
      the requested bit
    • searchIndex Link icon

      protected final int searchIndex(long timestamp)
      Get the state index of a TI timestamp, based on binary search within the measured sequence. This returns invalid (-1) if the timestamp is not contained within the range of measured states.
      Parameters:
      timestamp - TI timestamp (i.e. RUN::config.timestamp)
      Returns:
      index
    • predictIndex Link icon

      public int predictIndex(long timestamp)
      Get the state index of a TI timestamp, based only on the first measured state's timestamp and the helicity periodicity. This returns invalid (-1) if the timestamp is before the measured states.
      Parameters:
      timestamp -
      Returns:
      index
    • getState Link icon

      protected HelicityState getState(int n)
      Get the nth state in the measured sequence.
      Parameters:
      n - the index of the state, where 0 corresponds to the first state
      Returns:
      the helicity state, null if outside the mesaured range
    • searchState Link icon

      protected HelicityState searchState(long timestamp)
      Find the state corresponding to a given timestamp in the measured sequence.
      Parameters:
      timestamp - TI timestamp (i.e. RUN::config.timestamp)
      Returns:
      the helicity state, null if timestamp is outside of measured range
    • get Link icon

      protected HelicityBit get(int n)
      Get the nth state in the measured sequence.
      Parameters:
      n - the index of the state, where 0 corresponds to the first state
      Returns:
      the helicity state, HelicityBit.UDF if outside the mesaured range
    • search Link icon

      public HelicityBit search(long timestamp)
      Find the state corresponding to a given timestamp in the measured sequence.
      Parameters:
      timestamp - TI timestamp (i.e. RUN::config.timestamp)
      Returns:
      the helicity state, null if timestamp is outside of measured range
    • search Link icon

      public HelicityBit search(long timestamp, int offset)
      Find the state corresponding to a given timestamp in the measured sequence.
      Parameters:
      timestamp - TI timestamp (i.e. RUN::config.timestamp)
      offset - number of states offset
      Returns:
      the helicity state, null if timestamp is outside of measured range
    • getGenerated Link icon

      protected HelicityBit getGenerated(int n)
      Predict the nth state in the sequence. This uses the pseudo-random sequence of the helicity hardware to generate the sequence into the infinite future and requires that enough states were provided to initialize it. Returns null if generator cannot be initialized or the state is before the measured ones (i.e. negative).
      Parameters:
      n - the index of the state
      Returns:
      the helicity bit
    • predictGenerated Link icon

      public HelicityBit predictGenerated(long timestamp)
      Predict the state of a TI timestamp. This uses the pseudo-random sequence of the helicity hardware to generate the sequence into the infinite future and requires that enough states were provided to initialize it. Returns null if generator cannot be initialized or timestamp is before the generator timestamp.
      Parameters:
      timestamp - TI timestamp (i.e. RUN::config.timestamp)
      Returns:
      the helicity bit
    • initialized Link icon

      public boolean initialized()
      Get whether the pseudo-random generator is initialized. This must be true before calling the predict methods, because they require a working generator. The number of valid states required to intialize the generator is
      invalid reference
      HelicityGenerator.REGISTER_SIZE
      .
      Returns:
      whether initialized
    • show Link icon

      public void show()
    • getTimestamp Link icon

      public long getTimestamp(int index)
      Get the TI-timestamp of a state in the sequence.
      Parameters:
      index - the index of the state
      Returns:
      the timestamp of the state
    • analyze Link icon

      protected final boolean analyze()
      Analyze the sequence, prune false states, initialize the generator.
      Returns:
      sequence integrity
    • integrityCheck Link icon

      public final boolean integrityCheck()
      Perform integrity checking on the sequence.
      Returns:
      whether the integrity checking succeeded
    • initialize Link icon

      public void initialize(org.jlab.jnp.hipo4.io.HipoReader reader)
    • initialize Link icon

      public void initialize(List<String> filenames)
    • initialize Link icon

      public void initialize(String... filenames)
    • getStates Link icon

      public List<HelicityState> getStates()
    • addStream Link icon

      public void addStream(TreeSet<HelicityState> states)
      Detect and add state changes from a "stream" of measured helicities to the sequence. WARNING: Unlike addState, this requires that previously added states are all earlier in time than the input stream. NOTE: In order to detect state changes, TreeSet is used to ensure the input state stream is sorted by timestamp, HelicityState's natural order.
      Parameters:
      states - stream of states
    • addStream Link icon

      public void addStream(org.jlab.jnp.hipo4.data.SchemaFactory schema, ConstantsManager conman, List<String> filenames)
      Parameters:
      schema -
      conman -
      filenames -
    • getBanks Link icon

      public List<org.jlab.jnp.hipo4.data.Bank> getBanks(org.jlab.jnp.hipo4.data.SchemaFactory schema)
      Get a list of HEL::flip banks corresponding to this sequence
      Parameters:
      schema -
      Returns:
      list of HEL::flip banks
    • writeFlips Link icon

      public void writeFlips(org.jlab.jnp.hipo4.io.HipoWriterSorted writer, int tag)
      Write all states from this sequence into new HEL::flip banks in new, tagged events
      Parameters:
      writer -
      tag -
    • writeFlips Link icon

      public static void writeFlips(org.jlab.jnp.hipo4.io.HipoWriterSorted writer, TreeSet<HelicityState> stream)
      Write all state changes from a stream into new HEL::flip banks in new, tagged events
      Parameters:
      writer -
      stream -