Class Evio

java.lang.Object
org.jlab.coda.emu.support.data.Evio

public class Evio extends Object

This class is used as a layer on top of evio to handle CODA3 specific details. The EMU will received evio data in standard CODA3 output (same as file format) which contains banks - in this case, ROC Raw Records and Physics Events all of which are in formats given below.


 ####################################
 Network Transfer Evio 4 Output Format:
 ####################################

 MSB(31)                          LSB(0)
 <---  32 bits ------------------------>
 _______________________________________
 |           Block Length              |
 |_____________________________________|
 |           Block Number              |
 |_____________________________________|
 |         Header Length = 8           |
 |_____________________________________|
 |            Event Count              |
 |_____________________________________|
 |             Reserved 1              |
 |_____________________________________|
 |        Bit Info          | Version  |
 |_____________________________________|
 |             Reserved 2              |
 |_____________________________________|
 |            Magic Number             |
 |_____________________________________|
 |                                     |
 |           Payload Bank              |
 |       (ROC Raw, Physics,            |
 |        Control or User event)       |
 |_____________________________________|
 |                                     |
 |           Payload Bank              |
 |_____________________________________|
 |                                     |
 |           Payload Bank              |
 |_____________________________________|
 |                                     |
 |           Payload Bank              |
 |_____________________________________|




 ############################
 ROC Raw Record:
 ############################

 MSB(31)                          LSB(0)
 <---  32 bits ------------------------>
 _______________________________________
 |           Event Length              |
 |_____________________________________|
 | S |   ROC ID     |  0x10  |    M    |
 |_____________________________________| ------
 |        Trigger Bank Length          |      ^
 |_____________________________________|      |
 |    0xFF1X        |  0x20  |    M    |      |
 |_____________________________________|      |
 | ID 1   |  0x01   |     ID len 1     |   Trigger Bank
 |_____________________________________|      |
 |           Event Number 1            |      |
 |_____________________________________|      |
 |       Timestamp1 (bits 31-0)        |      |
 |_____________________________________|      |
 |       Timestamp1 (bits 47-32)       |      |
 |_____________________________________|      |
 |             Misc. 1 (?)             |      |
 |_____________________________________|      |
 |                  ...                |      |
 |_____________________________________|      |
 |                                     |      |
 |    (One segment for each event)     |      |
 |                                     |      |
 |_____________________________________|      |
 | ID M   |  0x01   |     ID len M     |      |
 |_____________________________________|      |
 |           Event Number M            |      |
 |_____________________________________|      |
 |________   Timestamp M (?)   ________|      |
 |_____________________________________|      |
 |             Misc. M (?)             |      V
 |_____________________________________| ------
 |                                     |
 |         Data Block Bank 1           |
 |        (data of M events from       |
 |         1 to multiple modules)      |
 |                                     |
 |_____________________________________|
 |                  ...                |
 |_____________________________________|
 |                                     |
 |         Data Block Last             |
 |   (there will be only 1 block       |
 |   unless user used multiple DMAs)   |
 |                                     |
 |_____________________________________|


 M = number of events (0 = user event).
 0x0F01 is the Trigger Bank identifier.

 S is the 4-bit status:
 |_____________________________________|
 | Single|   Big    |  Error |  Sync   |
 | Event |  Endian  |        |  Event  |
 |  Mode |          |        |         |
 |_____________________________________|

  Endian bit is set if data is big endian


 ############################
 Physics Event:
 ############################

 MSB(31)                          LSB(0)
 <---  32 bits ------------------------>
 _______________________________________
 |           Event Length              |
 |_____________________________________|
 | builder = 0xFFXX |  0x10  |    M    |
 |_____________________________________| ------
 |     Built Trigger Bank Length       |      ^
 |_____________________________________|      |
 |    0xFF2X        |  0x20  |    N    |      |
 |_____________________________________|     Built
 |     2  EB (Common) Segments         |   Trigger Bank
 |_____________________________________|   (see below)
 |           ROC 1 Segment             |      |
 |_____________________________________|      |
 |                  ...                |      |
 |_____________________________________|      |
 |           ROC N Segment             |      V
 |_____________________________________| ------
 |                                     |
 |            Data Bank 1              |
 |     (wraps 1 or more data           |
 |         blocks for a ROC)           |
 |_____________________________________|
 |                                     |
 |                  ...                |
 |_____________________________________|
 |                                     |
 |            Data Bank N              |
 |      (One bank for each roc)        |
 |_____________________________________|


      M = number of events.
      N is the number of ROCs.
 0xFFXX is the id of the event builder
 0xFF2X is the Built Trigger Bank identifier



 ####################################
 Physics Event's Built Trigger Bank:
 ####################################

 MSB(31)                          LSB(0)
 <---  32 bits ------------------------>
 _______________________________________
 |     Built Trigger Bank Length       |
 |_____________________________________|
 |    0xFF2X        |  0x20  |    N    |
 |_____________________________________| --------
 | EB id  |   0xa   |        4         |    ^
 |_____________________________________|    |
 |________ First Event Number _________|    |
 |_____________________________________|    |
 |__________ Avg Timestamp 1 __________|    |
 |_____________________________________|    |
 |__________       ...       __________|    |
 |_____________________________________|    |
 |__________ Avg Timestamp M __________|    |
 |_____________________________________|    |
 |______ Run Number & Run Type ________|    |
 |_____________________________________|    |
 | EB id  |  0x05   |       Len        |    |
 |_____________________________________|    |
 |   Event Type 2   |  Event Type 1    |  Common Data
 |_____________________________________|    |
 |                  ...                |    |
 |_____________________________________|    |
 |  Event Type M    |  Event Type M-1  |    V
 |_____________________________________| -------
 |roc1 id |  0x01   |        Len       |    ^
 |_____________________________________|    |
 |         Timestamp for ev 1          |    |
 |_____________________________________|    |
 |           Misc. 1 for ev 1          |  ROC Data
 |_____________________________________|  (missing if single event mode,
 |                ...                  |   or sparsified and no timestamp
 |_____________________________________|   data available)
 |             Timestamp M             |    |
 |_____________________________________|    |
 |               Misc. M               |    |
 |_____________________________________|    |
 |                                     |    |
 |     (one for each ROC, to ROC N)    |    |
 |_____________________________________|    V


      N is the number of ROCs.
      M is the number of events.
 0xFF2X is the Built Trigger Bank identifier.



 ############################
 Physics Event's Data Bank:
 ############################

 MSB(31)                          LSB(0)
 <---  32 bits ------------------------>
 _______________________________________
 |         Data Bank Length            |
 |_____________________________________|
 | S |   ROC id     |  0x10  |    M    |
 |_____________________________________|
 |                                     |
 |        Data Block Bank 1            |
 |                                     |
 |_____________________________________|
 |                                     |
 |                  ...                |
 |_____________________________________|
 |                                     |
 |           Data Bank Last            |
 |                                     |
 |_____________________________________|


      M is the number of events.

 
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    buildPhysicsEventWithPhysics(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder)
    Build a single physics event with the given trigger bank and the given array of Physics events.
    static void
    buildPhysicsEventWithPhysics(org.jlab.coda.jevio.EvioNode[] inputNodes, ByteBuffer evBuf, int inputCount, int writeIndex, boolean fastCopyReady, int[] returnLen, ByteBuffer[] rocRecord)
    Build a single physics event with the given array of Physics events.
    static org.jlab.coda.jevio.EvioBank
    buildPhysicsEventWithRocRaw(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder)
    Build a single physics event with the given trigger bank and the given array of ROC raw records.
    static org.jlab.coda.jevio.EvioBank
    buildPhysicsEventWithRocRaw(org.jlab.coda.jevio.EvioNode[] rocNodes, boolean fastCopyReady, int numRocs, int writeIndex, ByteBuffer builtEventBuf, int[] returnLen, ByteBuffer[] rocRecord)
    Build a single physics event with the given array of ROC raw records.
    static boolean
    checkConsistency(PayloadBuffer[] buildingBanks, long eventNumber, int entangledCount)
    Check each payload bank - one from each input channel - for a number of issues:
    static void
    checkInput(PayloadBuffer pBuf, DataChannel channel, EventType eventType, org.jlab.coda.jevio.EvioNode inputNode, boolean recordIdError)
    Check the given payload buffer for correct record id, source id.
    static boolean
    checkInputType(int recordId, DataChannel channel, EventType eventType, org.jlab.coda.jevio.EvioNode inputNode)
    Check the given payload buffer for event type (physics, ROC raw, control, or user) as well as evio structure type.
    static void
    Check the given payload buffer for correct format (physics, ROC raw, control, or user).
    static int
    checkRecordIdSequence(int recordId, int expectedRecordId, boolean print, EventType eventType, DataChannel channel)
    Check the data coming over a channel for sequential record ids.
    static int
    createCodaTag(boolean sync, boolean error, boolean isBigEndian, boolean singleEventMode, int id)
    Create a 16-bit, CODA-format tag for a ROC Raw Record or Physics Event out of 4 status bits and a 12-bit id.
    static int
    createCodaTag(int status, int id)
    Create a 16-bit, CODA-format tag for a ROC Raw Record, Physics Event, or Data Transport Record out of 4-bit status/type and a 12-bit id.
    createControlBuffer(ControlType type, int runNumber, int runType, int eventsInRun, int eventsSinceSync, ByteOrder order, boolean error)
    Create a Control event with a ByteBuffer which is ready to read.
    static org.jlab.coda.jevio.EvioEvent
    createControlEvent(ControlType type, int runNumber, int runType, int eventsInRun, int eventsSinceSync, boolean error)
    Create a Control event.
    static void
    createRocRawRecordFast(int rocID, int triggerType, int detectorId, int status, int eventNumber, int numEvents, long timestamp, ByteBuffer buf, org.jlab.coda.jevio.CompactEventBuilder builder)
    Create an Evio ROC Raw record event/bank to be placed in a Data Transport record.
    static int[]
    generateData(int firstEvNum, int words, boolean isSEM, long timestamp)
    Generate a single data block bank of fake data.
    static int
    getTagCodaId(int codaTag)
    Get the id which is the lower 12 bits of the CODA-format tag.
    static int
    getTagStatus(int codaTag)
    Get the given CODA-format tag's status which is the upper 4 bits.
    static int
    getTagStatus(org.jlab.coda.jevio.EvioBank bank)
    Get the given bank's CODA-format tag's status which is the upper 4 bits.
    static void
    gotConsistentControlEvents(PayloadBuffer[] buildingBanks, int runNumber, int runType)
    When this is called all channels had control events.
    static boolean
    isBuiltTriggerBank(org.jlab.coda.jevio.EvioNode node)
    Determine whether a bank is a built trigger bank or not.
    static boolean
    isRawTriggerBank(org.jlab.coda.jevio.EvioNode node)
    Determine whether a bank is a trigger bank from a ROC or not.
    static boolean
    isSyncEvent(org.jlab.coda.jevio.EvioNode node)
    Determine whether a bank is a SYNC control event or not.
    static boolean
    isTagBigEndian(int codaTag)
    See if the given CODA-format tag indicates data is big endian.
    static boolean
    isTagSingleEventMode(int codaTag)
    See if the given CODA-format tag indicates the ROC is in single event mode.
    static boolean
    isTagSyncEvent(int codaTag)
    See if the given CODA-format tag indicates it is a sync event.
    static boolean
    isUserEvent(org.jlab.coda.jevio.EvioBank bank)
    Determine whether a bank is a USER event or not.
    static boolean
    isUserEvent(org.jlab.coda.jevio.EvioNode node)
    Determine whether an event is a USER event or not.
    static boolean
    makeTriggerBankFromPhysics(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder, int ebId, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop)
    Combine the trigger banks of all input payload banks of Physics event format (from previous event builder) into a single trigger bank which will be used in the final built event.
    static boolean
    makeTriggerBankFromPhysics(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.EvioNode[] rocNodes, org.jlab.coda.jevio.EvioNode[] triggerBanks, ByteBuffer[] inputBuffers, ByteBuffer evBuf, int ebId, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, boolean fastCopyReady, int timestampSlop, int[] returnLen, long[] longData, long[] commonLong, long[] firstInputCommonLong, long[] timestampsMin, long[] timestampsMax, short[] eventTypes, short[] eventTypesRoc1)
    Combine the trigger banks of all input payload banks of Physics event format (from previous event builder) into a single trigger bank which will be used in the final built event.
    static boolean
    makeTriggerBankFromPhysicsOrig(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder, int ebId, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop)
    Combine the trigger banks of all input payload banks of Physics event format (from previous event builder) into a single trigger bank which will be used in the final built event.
    static boolean
    makeTriggerBankFromRocRaw(PayloadBuffer[] inputPayloadBanks, ByteBuffer builtEventBuf, int ebId, long firstEventNumber, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop, int buildThreadOrder, long[] longData, short[] evData, int[] segmentData, int[] returnLen, int[] rocOffset, ByteBuffer[] rocRecord, org.jlab.coda.jevio.EvioNode[] rocNodes, boolean fastCopyReady)
    Combine the trigger banks of all input payload banks of ROC raw format into a single trigger bank which will be used in the final built event.
    static boolean
    makeTriggerBankFromRocRaw(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder, int ebId, long firstEventNumber, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop, int buildThreadOrder)
    Combine the trigger banks of all input payload banks of ROC raw format into a single trigger bank which will be used in the final built event.
    static boolean
    makeTriggerBankFromRocRaw(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder, int ebId, long firstEventNumber, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop, int buildThreadOrder, long[] longData, short[] evData, int[] segmentData, int[] returnLen)
    Combine the trigger banks of all input payload banks of ROC raw format into a single trigger bank which will be used in the final built event.
    static boolean
    makeTriggerBankFromRocRawOld(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder, int ebId, long firstEventNumber, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop, int buildThreadOrder)
    Combine the trigger banks of all input payload banks of ROC raw format into a single trigger bank which will be used in the final built event.
    static boolean
    makeTriggerBankFromRocRawOrig(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder, int ebId, long firstEventNumber, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop, int buildThreadOrder)
    Combine the trigger banks of all input payload banks of ROC raw format into a single trigger bank which will be used in the final built event.
    static int
    setTagEndian(int codaTag, boolean isBigEndian)
    Set the given CODA-format tag to indicate data is little/big endian.
    static boolean
    tagHasError(int codaTag)
    See if the given CODA-format tag indicates the ROC/EB has an error.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • createCodaTag

      public static int createCodaTag(boolean sync, boolean error, boolean isBigEndian, boolean singleEventMode, int id)
      Create a 16-bit, CODA-format tag for a ROC Raw Record or Physics Event out of 4 status bits and a 12-bit id.
      Parameters:
      sync - is sync event
      error - is error
      isBigEndian - data is big endian
      singleEventMode - is single event mode
      id - lowest 12 bits are id
      Returns:
      a 16-bit tag for a ROC Raw Record or Physics Event out of 4 status bits and a 12-bit id
    • createCodaTag

      public static int createCodaTag(int status, int id)
      Create a 16-bit, CODA-format tag for a ROC Raw Record, Physics Event, or Data Transport Record out of 4-bit status/type and a 12-bit id.
      Parameters:
      status - lowest 4 bits are status/type
      id - lowest 12 bits are id
      Returns:
      a 16-bit tag for a ROC Raw Record, Physics Event, or DTR out of 4-bit status/type and a 12-bit id
    • getTagCodaId

      public static int getTagCodaId(int codaTag)
      Get the id which is the lower 12 bits of the CODA-format tag.
      Parameters:
      codaTag - tag from evio bank.
      Returns:
      the id of the CODA-format tag.
    • isTagSingleEventMode

      public static boolean isTagSingleEventMode(int codaTag)
      See if the given CODA-format tag indicates the ROC is in single event mode. This condition is set by the ROC and it is only read here - never set.
      Parameters:
      codaTag - tag from evio bank.
      Returns:
      true if the ROC is in single event mode.
    • isTagSyncEvent

      public static boolean isTagSyncEvent(int codaTag)
      See if the given CODA-format tag indicates it is a sync event. This condition is set by the ROC and it is only read here - never set.
      Parameters:
      codaTag - tag from evio bank.
      Returns:
      true if is a sync event.
    • isTagBigEndian

      public static boolean isTagBigEndian(int codaTag)
      See if the given CODA-format tag indicates data is big endian. This condition is set by the ROC and may be set in emu if data is swapped.
      Parameters:
      codaTag - tag from evio bank.
      Returns:
      true if data is big endian.
    • setTagEndian

      public static int setTagEndian(int codaTag, boolean isBigEndian)
      Set the given CODA-format tag to indicate data is little/big endian.
      Parameters:
      codaTag - tag from evio bank.
      isBigEndian - true if big endian, else false
      Returns:
      new codaTag with bit set to indicate data endianness.
    • tagHasError

      public static boolean tagHasError(int codaTag)
      See if the given CODA-format tag indicates the ROC/EB has an error. This condition is set by the ROC/EB and it is only read here - never set.
      Parameters:
      codaTag - tag from evio bank.
      Returns:
      true if the ROC/EB has an error.
    • getTagStatus

      public static int getTagStatus(int codaTag)
      Get the given CODA-format tag's status which is the upper 4 bits.
      Parameters:
      codaTag - tag from evio bank.
      Returns:
      the status from various records/events/banks.
    • getTagStatus

      public static int getTagStatus(org.jlab.coda.jevio.EvioBank bank)
      Get the given bank's CODA-format tag's status which is the upper 4 bits.
      Parameters:
      bank - bank to analyze
      Returns:
      the status from given bank or -1 if bank arg is null.
    • isSyncEvent

      public static boolean isSyncEvent(org.jlab.coda.jevio.EvioNode node)
      Determine whether a bank is a SYNC control event or not.
      Parameters:
      node - object corresponding to evio structure
      Returns:
      true if arg is SYNC event, else false
    • isUserEvent

      public static boolean isUserEvent(org.jlab.coda.jevio.EvioBank bank)
      Determine whether a bank is a USER event or not. Only called on banks that were originally from the ROC and labeled as ROC Raw type.
      Parameters:
      bank - input bank
      Returns:
      true if arg is USER event, else false
    • isUserEvent

      public static boolean isUserEvent(org.jlab.coda.jevio.EvioNode node)
      Determine whether an event is a USER event or not. Only called on events that were originally from the ROC and labeled as ROC Raw type.
      Parameters:
      node - input node
      Returns:
      true if arg is USER event, else false
    • isRawTriggerBank

      public static boolean isRawTriggerBank(org.jlab.coda.jevio.EvioNode node)
      Determine whether a bank is a trigger bank from a ROC or not.
      Parameters:
      node - input node
      Returns:
      true if arg is trigger bank, else false
    • isBuiltTriggerBank

      public static boolean isBuiltTriggerBank(org.jlab.coda.jevio.EvioNode node)
      Determine whether a bank is a built trigger bank or not. In other words, has it been built by an event builder.
      Parameters:
      node - input node
      Returns:
      true if arg is a built trigger bank, else false
    • checkPayload

      public static void checkPayload(PayloadBuffer pBuf, DataChannel channel) throws EmuException
      Check the given payload buffer for correct format (physics, ROC raw, control, or user). All other buffers are ignored.

      No checks done on arguments. However, format of payload buffers is checked here for the first time.

      Parameters:
      pBuf - payload buffer to be examined
      channel - input channel
      Throws:
      EmuException - if physics or roc raw bank has improper format
    • checkInput

      public static void checkInput(PayloadBuffer pBuf, DataChannel channel, EventType eventType, org.jlab.coda.jevio.EvioNode inputNode, boolean recordIdError)
      Check the given payload buffer for correct record id, source id. Store sync and error info in payload buffer.
      Parameters:
      pBuf - payload buffer to be examined
      channel - input channel buffer is from
      eventType - type of input event in buffer
      inputNode - EvioNode object representing event
      recordIdError - non-fatal record id error found in checkInputType(int, DataChannel, EventType, EvioNode).
    • checkRecordIdSequence

      public static int checkRecordIdSequence(int recordId, int expectedRecordId, boolean print, EventType eventType, DataChannel channel)
      Check the data coming over a channel for sequential record ids. Send warning as printout.
      Parameters:
      recordId - id associated with an incoming evio event (each of which may contain several physics events)
      expectedRecordId - expected record id
      print - if true, print out when record id is out-of-seq.
      eventType - type of input event
      channel - input channel data is from
      Returns:
      next expected record id
    • checkInputType

      public static boolean checkInputType(int recordId, DataChannel channel, EventType eventType, org.jlab.coda.jevio.EvioNode inputNode) throws EmuException
      Check the given payload buffer for event type (physics, ROC raw, control, or user) as well as evio structure type.
      Parameters:
      recordId - id associated with an incoming evio event (each of which may contain several physics events)
      channel - input channel buffer is from
      eventType - type of input event
      inputNode - EvioNode object representing event
      Returns:
      true if there is a non-fatal error with mismatched record ids, else false
      Throws:
      EmuException - if event is unknown type; if physics or roc raw bank has improper format
    • checkConsistency

      public static boolean checkConsistency(PayloadBuffer[] buildingBanks, long eventNumber, int entangledCount) throws EmuException

      Check each payload bank - one from each input channel - for a number of issues:

      1. if there are any sync bits set, all must be sync banks
      2. the ROC ids of the banks must be unique
      3. at this point all banks are either physics events or ROC raw records, but must be identical types
      4. there are the same number of events in each bank
      Parameters:
      buildingBanks - array containing banks that will be built together
      eventNumber - first event number in each bank (used for diagnostic output). Currently event # will not be valid for SEB with multiple streams.
      entangledCount - also called blockLevel, it's the number of events entangled together in one data bank.
      Returns:
      true if non-fatal error occurred, else false
      Throws:
      EmuException - if some physics and others ROC raw event types; if there are a differing number of events in each payload bank; if some events have a sync bit set and others do not.
    • gotConsistentControlEvents

      public static void gotConsistentControlEvents(PayloadBuffer[] buildingBanks, int runNumber, int runType) throws EmuException
      When this is called all channels had control events. Check to see if all are identical.
      Parameters:
      buildingBanks - array containing events that will be built together
      runNumber - check this (correct) run # against the one in the control event
      runType - check this (correct) run type against the one in the control event
      Throws:
      EmuException - if events contain mixture of different control types; if prestart events contain bad data
    • createControlEvent

      public static org.jlab.coda.jevio.EvioEvent createControlEvent(ControlType type, int runNumber, int runType, int eventsInRun, int eventsSinceSync, boolean error)
      Create a Control event.
      
       Sync event:
       _______________________________________
       |          Event Length = 4           |
       |_____________________________________|
       |   type = 0xFFD0  |  0x1   |    0    |
       |_____________________________________|
       |                time                 |
       |_____________________________________|
       |   number of events since last sync  |
       |_____________________________________|
       |      number of events in run        |
       |_____________________________________|
      
       Prestart event:
       _______________________________________
       |          Event Length = 4           |
       |_____________________________________|
       |   type = 0xFFD1  |  0x1   |    0    |
       |_____________________________________|
       |                time                 |
       |_____________________________________|
       |              Run Number             |
       |_____________________________________|
       |               Run Type              |
       |_____________________________________|
      
      
       Go  (type = 0xFFD2), Pause (type = 0xFFD3) or
       End (type = 0xFFD4) event:
       _______________________________________
       |          Event Length = 4           |
       |_____________________________________|
       |       type       |  0x1   |    0    |
       |_____________________________________|
       |                time                 |
       |_____________________________________|
       |              (reserved)             |
       |_____________________________________|
       |      number of events in run        |
       |_____________________________________|
       
      Parameters:
      type - control type, must be SYNC, PRESTART, GO, PAUSE, or END
      runNumber - current run number for prestart event
      runType - current run type for prestart event
      eventsInRun - number of events so far in run for all except prestart event
      eventsSinceSync - number of events since last sync for sync event
      error - END control event sent due to error condition
      Returns:
      created Control event (EvioEvent object)
    • createControlBuffer

      public static PayloadBuffer createControlBuffer(ControlType type, int runNumber, int runType, int eventsInRun, int eventsSinceSync, ByteOrder order, boolean error)
      Create a Control event with a ByteBuffer which is ready to read.
      Parameters:
      type - control type, must be SYNC, PRESTART, GO, PAUSE, or END
      runNumber - current run number for prestart event
      runType - current run type for prestart event
      eventsInRun - number of events so far in run for all except prestart event
      eventsSinceSync - number of events since last sync for sync event
      order - byte order in which to write event into buffer
      error - END control event sent due to error condition
      Returns:
      created PayloadBuffer object containing Control event in byte buffer
    • makeTriggerBankFromPhysicsOrig

      public static boolean makeTriggerBankFromPhysicsOrig(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder, int ebId, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop) throws EmuException
      Combine the trigger banks of all input payload banks of Physics event format (from previous event builder) into a single trigger bank which will be used in the final built event. Any error which occurs but allows the build to continue will be noted in the return value. Errors which stop the event building cause an exception to be thrown.

      If timestamp checking is enabled, it will only be valid here if all physics events being currently built have come via previous event builders in which timestamp checking was enabled. In this case, each input bank must have timestamp information in its trigger bank or an exception with be thrown. The first level of event builders check the timestamp drift of each ROC. This (2nd or higher) level of event builder checks the average timestamp for an event from one group of ROCs against another group's. The trigger bank created in this method will contain the average timestamps.

      If run number and run type data are included in all input banks, then they will be checked for consistency. A non-fatal error will be returned if they are not.

      If sparsify flag is true, then no roc-specific data is included. The trigger bank is not sparsified if timestamps exist. Note that if incoming trigger banks are from events built in single event mode, then there will be no roc-specific data in that case as well. If roc-specific data is missing from any of the trigger banks, then it will be missing in the final trigger bank as well.

      Parameters:
      inputPayloadBanks - array containing a bank (Physics event) from each channel's payload buffer queue that will be built into one event
      builder - object used to build trigger bank
      ebId - id of event builder calling this method
      runNumber - run number to place in trigger bank
      runType - run type to place in trigger bank
      includeRunData - if true, add run number and run type
      sparsify - if true, do not add roc specific segments if no relevant data
      checkTimestamps - if true, check timestamp consistency and return false if inconsistent, include them in trigger bank
      timestampSlop - maximum number of timestamp ticks that timestamps can differ for a single event before the error bit is set in a bank's status. Only used when checkTimestamps arg is true
      Returns:
      true if non-fatal error occurred, else false
      Throws:
      EmuException - for major error in event building which necessitates stopping the build
    • makeTriggerBankFromPhysics

      public static boolean makeTriggerBankFromPhysics(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder, int ebId, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop) throws EmuException
      Combine the trigger banks of all input payload banks of Physics event format (from previous event builder) into a single trigger bank which will be used in the final built event. Any error which occurs but allows the build to continue will be noted in the return value. Errors which stop the event building cause an exception to be thrown.

      If timestamp checking is enabled, it will only be valid here if all physics events being currently built have come via previous event builders in which timestamp checking was enabled. In this case, each input bank must have timestamp information in its trigger bank or an exception with be thrown. The first level of event builders check the timestamp drift of each ROC. This (2nd or higher) level of event builder checks the average timestamp for an event from one group of ROCs against another group's. The trigger bank created in this method will contain the average timestamps.

      If run number and run type data are included in all input banks, then they will be checked for consistency. A non-fatal error will be returned if they are not.

      If sparsify flag is true, then no roc-specific data is included. The trigger bank is not sparsified if timestamps exist. Note that if incoming trigger banks are from events built in single event mode, then there will be no roc-specific data in that case as well. If roc-specific data is missing from any of the trigger banks, then it will be missing in the final trigger bank as well.

      Parameters:
      inputPayloadBanks - array containing a bank (Physics event) from each channel's payload buffer queue that will be built into one event
      builder - object used to build trigger bank
      ebId - id of event builder calling this method
      runNumber - run number to place in trigger bank
      runType - run type to place in trigger bank
      includeRunData - if true, add run number and run type
      sparsify - if true, do not add roc specific segments if no relevant data
      checkTimestamps - if true, check timestamp consistency and return false if inconsistent, include them in trigger bank
      timestampSlop - maximum number of timestamp ticks that timestamps can differ for a single event before the error bit is set in a bank's status. Only used when checkTimestamps arg is true
      Returns:
      true if non-fatal error occurred, else false
      Throws:
      EmuException - for major error in event building which necessitates stopping the build
    • makeTriggerBankFromPhysics

      public static boolean makeTriggerBankFromPhysics(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.EvioNode[] rocNodes, org.jlab.coda.jevio.EvioNode[] triggerBanks, ByteBuffer[] inputBuffers, ByteBuffer evBuf, int ebId, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, boolean fastCopyReady, int timestampSlop, int[] returnLen, long[] longData, long[] commonLong, long[] firstInputCommonLong, long[] timestampsMin, long[] timestampsMax, short[] eventTypes, short[] eventTypesRoc1) throws EmuException
      Combine the trigger banks of all input payload banks of Physics event format (from previous event builder) into a single trigger bank which will be used in the final built event. Any error which occurs but allows the build to continue will be noted in the return value. Errors which stop the event building cause an exception to be thrown.

      If timestamp checking is enabled, it will only be valid here if all physics events being currently built have come via previous event builders in which timestamp checking was enabled. In this case, each input bank must have timestamp information in its trigger bank or an exception with be thrown. The first level of event builders check the timestamp drift of each ROC. This (2nd or higher) level of event builder checks the average timestamp for an event from one group of ROCs against another group's. The trigger bank created in this method will contain the average timestamps.

      If run number and run type data are included in all input banks, then they will be checked for consistency. A non-fatal error will be returned if they are not.

      If sparsify flag is true, then no roc-specific data is included. The trigger bank is not sparsified if timestamps exist. Note that if incoming trigger banks are from events built in single event mode, then there will be no roc-specific data in that case as well. If roc-specific data is missing from any of the trigger banks, then it will be missing in the final trigger bank as well.

      Many of the inputs are externally provided arrays used here in order to avoid allocating them each time this method is called. Some, like rocNodes, triggerBanks, and inputBuffers, are quickly found in FastEventBuilder and easy to pass in.

      Parameters:
      inputPayloadBanks - array containing a bank (Physics event) from each channel's payload buffer queue that will be built into one event.
      rocNodes - array of EvioNodes of input banks.
      triggerBanks - array of EvioNodes of input trigger banks.
      inputBuffers - array of ByteBuffers of input banks.
      evBuf - ByteBuffer in which event is being built.
      ebId - id of event builder calling this method.
      runNumber - run number to place in trigger bank.
      runType - run type to place in trigger bank.
      includeRunData - if true, add run number and run type.
      sparsify - if true, do not add roc specific segments if no relevant data.
      checkTimestamps - if true, check timestamp consistency and return false if inconsistent, include them in trigger bank
      fastCopyReady - if true, ...
      timestampSlop - maximum number of timestamp ticks that timestamps can differ for a single event before the error bit is set in a bank's status. Only used when checkTimestamps arg is true.
      returnLen - array in which to return index in evBuf just past trigger bank.
      longData - array used to store long data of trigger bank.
      commonLong - array used to hold long trigger data for comparison of inputs.
      firstInputCommonLong - array used to hold long trigger data from first input.
      timestampsMin - array used to store min timestamp for each event.
      timestampsMax - array used to store max timestamp for each event.
      eventTypes - array used to hold short trigger data for comparison of inputs.
      eventTypesRoc1 - array used to store short trigger data from first input.
      Returns:
      true if non-fatal error occurred, else false
      Throws:
      EmuException - for major error in event building which necessitates stopping the build
    • makeTriggerBankFromRocRaw

      public static boolean makeTriggerBankFromRocRaw(PayloadBuffer[] inputPayloadBanks, ByteBuffer builtEventBuf, int ebId, long firstEventNumber, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop, int buildThreadOrder, long[] longData, short[] evData, int[] segmentData, int[] returnLen, int[] rocOffset, ByteBuffer[] rocRecord, org.jlab.coda.jevio.EvioNode[] rocNodes, boolean fastCopyReady) throws EmuException
      Combine the trigger banks of all input payload banks of ROC raw format into a single trigger bank which will be used in the final built event. Any error which occurs but allows the build to continue will be noted in the return value. Errors which stop the event building cause an exception to be thrown.

      To check timestamp consistency, for each event the difference between the max and min timestamps cannot exceed the argument timestampSlop. If it does for any event, this method returns true.

      If sparsify flag is true, then no roc-specific data is included. The trigger bank is not sparsified if timestamps and/or roc misc data exist.

      Many of the inputs are externally provided arrays used here in order to avoid allocating them each time this method is called. Some, like rocNodes, rocRecord, and rocOffset, are quickly found in FastEventBuilder and easy to pass in.

      Parameters:
      inputPayloadBanks - array containing a bank (ROC Raw) from each channel's payload bank queue that will be built into one event.
      builtEventBuf - ByteBuffer of event being built.
      ebId - id of event builder calling this method.
      firstEventNumber - event number to place in trigger bank.
      runNumber - run number to place in trigger bank.
      runType - run type to place in trigger bank.
      includeRunData - if true, add run number and run type.
      sparsify - if true, do not add roc specific segments if no such data.
      checkTimestamps - if true, check timestamp consistency and return false if inconsistent, include them in trigger bank.
      timestampSlop - maximum number of timestamp ticks that timestamps can differ for a single event before the error bit is set in a bank's status. Only used when checkTimestamps arg is true.
      buildThreadOrder - for debug printout, which build thread.
      longData - long array, passed in to avoid unnecessary object creation.
      evData - short array, passed in to avoid unnecessary object creation.
      segmentData - int array, passed in to avoid unnecessary object creation.
      returnLen - int array used to return index into builtEventBuf of where to write.
      rocOffset - array of rocNodes' backing buffer offsets.
      rocRecord - array of rocNodes' backing buffers.
      rocNodes - array of EvioNodes of input banks.
      fastCopyReady - if true, roc data buffer backing byte arrays and EB's ByteBufferSupply buffers both have the same endian value.
      Returns:
      true if recoverable error occurred, else false
      Throws:
      EmuException - for major error in event building which necessitates stopping the build
    • makeTriggerBankFromRocRaw

      public static boolean makeTriggerBankFromRocRaw(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder, int ebId, long firstEventNumber, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop, int buildThreadOrder) throws EmuException
      Combine the trigger banks of all input payload banks of ROC raw format into a single trigger bank which will be used in the final built event. Any error which occurs but allows the build to continue will be noted in the return value. Errors which stop the event building cause an exception to be thrown.

      To check timestamp consistency, for each event the difference between the max and min timestamps cannot exceed the argument timestampSlop. If it does for any event, this method returns true.

      If sparsify flag is true, then no roc-specific data is included. The trigger bank is not sparsified if timestamps and/or roc misc data exist.

      Parameters:
      inputPayloadBanks - array containing a bank (ROC Raw) from each channel's payload bank queue that will be built into one event
      builder - object used to build trigger bank
      ebId - id of event builder calling this method
      firstEventNumber - event number to place in trigger bank
      runNumber - run number to place in trigger bank
      runType - run type to place in trigger bank
      includeRunData - if true, add run number and run type
      sparsify - if true, do not add roc specific segments if no such data
      checkTimestamps - if true, check timestamp consistency and return false if inconsistent, include them in trigger bank
      timestampSlop - maximum number of timestamp ticks that timestamps can differ for a single event before the error bit is set in a bank's status. Only used when checkTimestamps arg is true
      buildThreadOrder - build thread number for debug printout
      Returns:
      true if recoverable error occurred, else false
      Throws:
      EmuException - for major error in event building which necessitates stopping the build
    • makeTriggerBankFromRocRaw

      public static boolean makeTriggerBankFromRocRaw(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder, int ebId, long firstEventNumber, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop, int buildThreadOrder, long[] longData, short[] evData, int[] segmentData, int[] returnLen) throws EmuException
      Combine the trigger banks of all input payload banks of ROC raw format into a single trigger bank which will be used in the final built event. Any error which occurs but allows the build to continue will be noted in the return value. Errors which stop the event building cause an exception to be thrown.

      To check timestamp consistency, for each event the difference between the max and min timestamps cannot exceed the argument timestampSlop. If it does for any event, this method returns true.

      If sparsify flag is true, then no roc-specific data is included. The trigger bank is not sparsified if timestamps and/or roc misc data exist.

      Parameters:
      inputPayloadBanks - array containing a bank (ROC Raw) from each channel's payload bank queue that will be built into one event
      builder - object used to build trigger bank
      ebId - id of event builder calling this method
      firstEventNumber - event number to place in trigger bank
      runNumber - run number to place in trigger bank
      runType - run type to place in trigger bank
      includeRunData - if true, add run number and run type
      sparsify - if true, do not add roc specific segments if no such data
      checkTimestamps - if true, check timestamp consistency and return false if inconsistent, include them in trigger bank
      timestampSlop - maximum number of timestamp ticks that timestamps can differ for a single event before the error bit is set in a bank's status. Only used when checkTimestamps arg is true
      buildThreadOrder - build thread number for debug printout
      longData - long array, passed in to avoid unnecessary object creation.
      evData - short array, passed in to avoid unnecessary object creation.
      segmentData - int array, passed in to avoid unnecessary object creation.
      returnLen - int array of length 1 used to return # of valid elements in segmentData.
      Returns:
      true if recoverable error occurred, else false
      Throws:
      EmuException - for major error in event building which necessitates stopping the build
    • makeTriggerBankFromRocRawOrig

      public static boolean makeTriggerBankFromRocRawOrig(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder, int ebId, long firstEventNumber, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop, int buildThreadOrder) throws EmuException
      Combine the trigger banks of all input payload banks of ROC raw format into a single trigger bank which will be used in the final built event. Any error which occurs but allows the build to continue will be noted in the return value. Errors which stop the event building cause an exception to be thrown.

      To check timestamp consistency, for each event the difference between the max and min timestamps cannot exceed the argument timestampSlop. If it does for any event, this method returns true.

      If sparsify flag is true, then no roc-specific data is included. The trigger bank is not sparsified if timestamps and/or roc misc data exist.

      Parameters:
      inputPayloadBanks - array containing a bank (ROC Raw) from each channel's payload bank queue that will be built into one event
      builder - object used to build trigger bank
      ebId - id of event builder calling this method
      firstEventNumber - event number to place in trigger bank
      runNumber - run number to place in trigger bank
      runType - run type to place in trigger bank
      includeRunData - if true, add run number and run type
      sparsify - if true, do not add roc specific segments if no such data
      checkTimestamps - if true, check timestamp consistency and return false if inconsistent, include them in trigger bank
      timestampSlop - maximum number of timestamp ticks that timestamps can differ for a single event before the error bit is set in a bank's status. Only used when checkTimestamps arg is true
      buildThreadOrder - build thread number for debug printout
      Returns:
      true if non fatal error occurred, else false
      Throws:
      EmuException - for major error in event building which necessitates stopping the build
    • makeTriggerBankFromRocRawOld

      public static boolean makeTriggerBankFromRocRawOld(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder, int ebId, long firstEventNumber, int runNumber, int runType, boolean includeRunData, boolean sparsify, boolean checkTimestamps, int timestampSlop, int buildThreadOrder) throws EmuException
      Combine the trigger banks of all input payload banks of ROC raw format into a single trigger bank which will be used in the final built event. Any error which occurs but allows the build to continue will be noted in the return value. Errors which stop the event building cause an exception to be thrown.

      To check timestamp consistency, for each event the difference between the max and min timestamps cannot exceed the argument timestampSlop. If it does for any event, this method returns true.

      If sparsify flag is true, then no roc-specific data is included. The trigger bank is not sparsified if timestamps and/or roc misc data exist.

      Parameters:
      inputPayloadBanks - array containing a bank (ROC Raw) from each channel's payload bank queue that will be built into one event
      builder - object used to build trigger bank
      ebId - id of event builder calling this method
      firstEventNumber - event number to place in trigger bank
      runNumber - run number to place in trigger bank
      runType - run type to place in trigger bank
      includeRunData - if true, add run number and run type
      sparsify - if true, do not add roc specific segments if no such data
      checkTimestamps - if true, check timestamp consistency and return false if inconsistent, include them in trigger bank
      timestampSlop - maximum number of timestamp ticks that timestamps can differ for a single event before the error bit is set in a bank's status. Only used when checkTimestamps arg is true
      buildThreadOrder - build thread number for debug printout
      Returns:
      true if non fatal error occurred, else false
      Throws:
      EmuException - for major error in event building which necessitates stopping the build
    • buildPhysicsEventWithPhysics

      public static void buildPhysicsEventWithPhysics(org.jlab.coda.jevio.EvioNode[] inputNodes, ByteBuffer evBuf, int inputCount, int writeIndex, boolean fastCopyReady, int[] returnLen, ByteBuffer[] rocRecord)
      Build a single physics event with the given array of Physics events.
      Parameters:
      inputNodes - array containing EvioNode events that will be built together.
      evBuf - ByteBuffer containing event being built.
      inputCount - number of input channels.
      writeIndex - index in evBuf's backing array to start writing.
      fastCopyReady - if true, roc data buffer backing byte arrays and EB's ByteBufferSupply buffers both have the same endian value.
      returnLen - int array used to return index into evBuf of where to write.
      rocRecord - array of backing buffers to inputNodes.
    • buildPhysicsEventWithPhysics

      public static void buildPhysicsEventWithPhysics(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder)
      Build a single physics event with the given trigger bank and the given array of Physics events.
      Parameters:
      inputPayloadBanks - array containing Physics events that will be built together
      builder - object used to build event
    • buildPhysicsEventWithRocRaw

      public static org.jlab.coda.jevio.EvioBank buildPhysicsEventWithRocRaw(org.jlab.coda.jevio.EvioNode[] rocNodes, boolean fastCopyReady, int numRocs, int writeIndex, ByteBuffer builtEventBuf, int[] returnLen, ByteBuffer[] rocRecord)
      Build a single physics event with the given array of ROC raw records. No data (only header) swapping is done.
      Parameters:
      rocNodes - array containing EvioNode events that will be built together.
      fastCopyReady - if true, roc data buffer backing byte arrays and EB's ByteBufferSupply buffers both have the same endian value.
      numRocs - number of input channels.
      writeIndex - index into evBuf to start writing.
      builtEventBuf - ByteBuffer containing event being built.
      returnLen - int array used to return index into evBuf of where to write.
      rocRecord - array of backing buffers to inputNodes.
      Returns:
      bank final built event
    • buildPhysicsEventWithRocRaw

      public static org.jlab.coda.jevio.EvioBank buildPhysicsEventWithRocRaw(PayloadBuffer[] inputPayloadBanks, org.jlab.coda.jevio.CompactEventBuilder builder)
      Build a single physics event with the given trigger bank and the given array of ROC raw records. Currently, no swapping is done since the bank in question may contain anything.
      Parameters:
      inputPayloadBanks - array containing ROC raw records that will be built together
      builder - object used to build trigger bank
      Returns:
      bank final built event
    • generateData

      public static int[] generateData(int firstEvNum, int words, boolean isSEM, long timestamp)
      Generate a single data block bank of fake data.
      Parameters:
      firstEvNum - starting event number
      words - amount of data in 32bit words besides event # and timestamp
      isSEM - in single event mode if true
      timestamp - 48-bit timestamp used only in single event mode
      Returns:
      array of ints containing generated data.
    • createRocRawRecordFast

      public static void createRocRawRecordFast(int rocID, int triggerType, int detectorId, int status, int eventNumber, int numEvents, long timestamp, ByteBuffer buf, org.jlab.coda.jevio.CompactEventBuilder builder) throws org.jlab.coda.jevio.EvioException
      Create an Evio ROC Raw record event/bank to be placed in a Data Transport record.
      Parameters:
      rocID - ROC id number
      triggerType - trigger type id number (0-15)
      detectorId - id of detector producing data in data block bank
      status - 4-bit status associated with data
      eventNumber - starting event number
      numEvents - number of physics events in created record
      timestamp - starting event's timestamp
      buf - ByteBuffer in which to write generated event
      builder - used to build evio events in buffer acquired from bbSupply
      Throws:
      org.jlab.coda.jevio.EvioException - if error in building evio event.