Package org.jlab.detector.helicity
Class HelicitySequence
java.lang.Object
org.jlab.detector.helicity.HelicitySequence
- Direct Known Subclasses:
- HelicitySequenceDelayed
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 SummaryFieldsModifier and TypeFieldDescriptionprotected booleanprotected final HelicityGeneratorprotected final Map<Long,HelicityGenerator> protected booleanprotected doubleprotected HelicityPatternprotected final List<HelicityState>static final double
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionfinal booleanaddState(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.voidaddStream(TreeSet<HelicityState> states) Detect and add state changes from a "stream" of measured helicities to the sequence.voidaddStream(org.jlab.jnp.hipo4.data.SchemaFactory schema, ConstantsManager conman, List<String> filenames) protected final booleananalyze()Analyze the sequence, prune false states, initialize the generator.protected HelicityBitget(int n) Get the nth state in the measured sequence.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 sequencestatic final HelicityBitgetBitInQuartet(HelicityBit firstBit, int bitIndex) Given the first helicity state in a quartet, get another bit in that quartet.protected HelicityBitgetGenerated(int n) Predict the nth state in the sequence.booleanprotected HelicityStategetState(int n) Get the nth state in the measured sequence.longgetTimestamp(int index) Get the TI-timestamp of a state in the sequence.voidinitialize(String... filenames) voidinitialize(List<String> filenames) voidinitialize(org.jlab.jnp.hipo4.io.HipoReader reader) booleanGet whether the pseudo-random generator is initialized.final booleanPerform integrity checking on the sequence.predictGenerated(long timestamp) Predict the state of a TI timestamp.intpredictIndex(long timestamp) Get the state index of a TI timestamp, based only on the first measured state's timestamp and the helicity periodicity.search(long timestamp) Find the state corresponding to a given timestamp in the measured sequence.search(long timestamp, int offset) Find the state corresponding to a given timestamp in the measured sequence.protected final intsearchIndex(long timestamp) Get the state index of a TI timestamp, based on binary search within the measured sequence.protected HelicityStatesearchState(long timestamp) Find the state corresponding to a given timestamp in the measured sequence.voidshow()final intsize()Get the the number of states in the sequence.voidwriteFlips(org.jlab.jnp.hipo4.io.HipoWriterSorted writer, int tag) Write all states from this sequence into new HEL::flip banks in new, tagged eventsstatic voidwriteFlips(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
- 
Field Details- 
TIMESTAMP_CLOCKpublic static final double TIMESTAMP_CLOCK- See Also:
 
- 
helicityClockprotected double helicityClock
- 
pattern
- 
halfWavePlateprotected boolean halfWavePlate
- 
analyzedprotected boolean analyzed
- 
generators
- 
generator
- 
states
 
- 
- 
Constructor Details- 
HelicitySequencepublic HelicitySequence()
 
- 
- 
Method Details- 
getHalfWavePlatepublic boolean getHalfWavePlate()
- 
sizepublic final int size()Get the the number of states in the sequence.- Returns:
- the number of states
 
- 
addStateAdd a state to the sequence, unless the same timestamp already exists or it has undefined bits, and keep them ordered by timestamp. Note, theseHelicityStates 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
 
- 
getBitInQuartetGiven 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
 
- 
searchIndexprotected 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
 
- 
predictIndexpublic 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
 
- 
getStateGet 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
 
- 
searchStateFind 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
 
- 
getGet 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
 
- 
searchFind 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
 
- 
searchFind 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
 
- 
getGeneratedPredict 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
 
- 
predictGeneratedPredict 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
 
- 
initializedpublic 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 isHelicityGenerator.REGISTER_SIZE.- Returns:
- whether initialized
 
- 
showpublic void show()
- 
getTimestamppublic 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
 
- 
analyzeprotected final boolean analyze()Analyze the sequence, prune false states, initialize the generator.- Returns:
- sequence integrity
 
- 
integrityCheckpublic final boolean integrityCheck()Perform integrity checking on the sequence.- Returns:
- whether the integrity checking succeeded
 
- 
initializepublic void initialize(org.jlab.jnp.hipo4.io.HipoReader reader) 
- 
initialize
- 
initialize
- 
getStates
- 
addStreamDetect 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
 
- 
addStreampublic void addStream(org.jlab.jnp.hipo4.data.SchemaFactory schema, ConstantsManager conman, List<String> filenames) - Parameters:
- schema-
- conman-
- filenames-
 
- 
getBanksGet a list of HEL::flip banks corresponding to this sequence- Parameters:
- schema-
- Returns:
- list of HEL::flip banks
 
- 
writeFlipspublic 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-
 
- 
writeFlipspublic 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-
 
 
-