public class FastEventBuilder extends ModuleAdapter
Ring Buffer (single producer, lock free) for a single input channel
| Gate (producer cannot go beyond this point)
|
__|__
/ | \
/1 _|_ 2\ <---- Build Threads 1-M
|__/ \__| |
|6 | | 3| |
^ |__|___|__| |
| \ 5 | 4 / |
Producer-> \__|__/ V
|
|
| Barrier (at last sequence produced)
Actual input channel ring buffers have thousands of events (not 6).
The producer is a single input channel which reads incoming data,
parses it and places it into the ring buffer.
The leading consumer of each ring is a build thread - one for each input channel.
All build threads consume slots that the input channels fill.
There are a fixed number of build threads which can be set in the config file.
After initially consuming and filling all slots (once around ring),
the producer (input channel) will only take additional slots that the post-build thread
is finished with.
N Input Channels
(evio bank RB1_ RB2_ ... RBN_
ring buffers) | | |
| | |
V V V
| / / _
| / / /
| / / /
| / / < Crossbar of
| / / \ Connections
|/ / \
| / \
|/ | | -
V V V
BuildingThreads: BT1 BT2 BTM
Grab 1 bank from | | |
each ring, | | |
build event, and | | |
place in | | |
output channel(s) \ | /
\ | /
V V V
Output Channel(s): OC1: RB1 RB2 RBM
(1 ring buffer for OC2: RB1 RB2 RBM ...
each build thread
in each channel)
M != N in general
M = 1 by default
--------------------------------------------------------------------------------------------------
SEQUENCES :
Example of 3 channels, 2 build threads, and releasing channel ring slots for reuse.
Chan/Ring 0 Chan 1 Chan 2
_____ _____ _____
/ | \ / | \ / | \
/1 _|_ 6\ /1 _|_ 6\ /1 _|_ 6\
|__/ \__| |__/ \__| |__/ \__|
|2 | | 5| |2 | | 5| |2 | | 5|
|__|___|__| |__|___|__| |__|___|__|
\ 3 | 4 / \ 3 | 4 / \ 3 | 4 /
\__|__/ \__|__/ \__|__/
\ \ / \ _/ |
\ \ / \ __/ |
\ `----, / \ __/ |
\ `----, / \ __/ |
\ `----, __/\_ |
\ / `---/--, \__ |
\ / / \ \____ |
| | / \ \ |
Sequences: [0][0] [0][1] [0][2] | [1][0] [1][1] [1][2]
|
Build Threads: BT 0 | BT 1
|
Gating sequence arrays are seq[bt][chan].
A gating sequence(s) is the last sequence (group of sequences)
on a ring that must reach a value (be done with that slot item)
for the ring to be able to reuse it.
|
seq[0][0],[0][1],[0][2] | seq[1][0],[1][1],[1][2]
|
|
BT0 uses all the events, |
represented by the above seqs, |
in building a single event. |
Before an input channel can reuse a place on the ring (say 4, although at that point its number would be 6+4=10), all the gating sequences for that ring must reach that same value (4) or higher. This signals that all users (BT0 and BT1) are done using that ring item.
For example, let's say that on Chan0, BT0 is done with 4 so that [0][0] = 4, but BT1 is only done with 3 so that [1][0] = 3, then Ring0 cannot reuse slot 4. It's not until BT1 is done with 4 ([1][0] = 4) that slot 4 is released. Remember that in the above example BT0 will process even numbered events, and BT1 the odd which means BT1 will skip over 4 - at the same time setting [1][0] = 4.
--------------------------------------------------------------------------------------------------Each BuildingThread - of which there may be any number - takes one bank from each ring buffer (and therefore input channel), skipping every Mth, and builds them into a single event. The built event is placed in a ring buffer of an output channel. This is by round robin if more than one channel or on all output channels if a control event, or the first output channel's first ring if user event. Each output channel has the same number of ring buffers as build threads. This avoids any contention and locking while writing. Each build thread only writes to a fixed, single ring buffer of each output channel. It is the job of each output channel to merge the contents of their rings into a single, ordered output stream.
NOTE: When building, any Control events must appear on each channel in the same order. If not, an exception may be thrown. If so, the Control event is passed along to all output channels. If no output channels are defined in the config file, this module builds, but discards all events.Modifier and Type | Class and Description |
---|---|
(package private) class |
FastEventBuilder.BuildingThread
This thread is started by the PRESTART transition.
|
ModuleAdapter.RateCalculatorThread
Modifier and Type | Field and Description |
---|---|
protected int |
ringItemCount
Number of items in build thread ring buffers.
|
attributeMap, avgEventSize, emu, endCallback, epThreadsSetInConfig, errorMsg, eventCountTotal, eventProducingThreads, eventRate, goodChunk_X_EtBufSize, id, inputChanLevels, inputChanNames, inputChannelCount, inputChannels, logger, maxEventSize, minEventSize, moduleState, name, outputChanLevels, outputChanNames, outputChannelCount, outputChannels, outputOrder, paused, prestartCallback, RateCalculator, representStatistics, statGatheringPeriod, statistics, timeStatsOn, timeToBuild, wordCountTotal, wordRate
Constructor and Description |
---|
FastEventBuilder(java.lang.String name,
java.util.Map<java.lang.String,java.lang.String> attributeMap,
Emu emu)
Constructor creates a new EventBuilding instance.
|
Modifier and Type | Method and Description |
---|---|
void |
end()
This method implements the END transition of the CODA run control state machine.
|
int |
getInternalRingCount()
Get the number of items this EmuModule object has in its internal rings.
|
void |
go()
This method implements the GO transition of the CODA run control state machine.
|
void |
prestart()
This method implements the PRESTART transition of the CODA run control state machine.
|
void |
reset()
This method implements the RESET transition of the CODA run control state machine.
|
addInputChannels, addOutputChannels, adjustStatistics, clearChannels, download, eventToOutputChannel, eventToOutputChannel, getAttr, getEndCallback, getError, getEventProducingThreadCount, getInputChannels, getInputLevels, getInputNames, getIntAttr, getOutputChannels, getOutputLevels, getOutputNames, getOutputOrder, getPrestartCallback, getStatistics, name, pause, registerEndCallback, registerPrestartCallback, representsEmuStatistics, state
protected int ringItemCount
public FastEventBuilder(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> attributeMap, Emu emu)
name
- name of moduleattributeMap
- map containing attributes of moduleemu
- emu which created this modulepublic int getInternalRingCount()
getInternalRingCount
in interface EmuModule
getInternalRingCount
in class ModuleAdapter
public void reset()
reset
in interface CODAStateMachine
reset
in class ModuleAdapter
public void end()
end
in interface CODAStateMachine
end
in class ModuleAdapter
public void prestart() throws CmdExecException
prestart
in interface CODAStateMachine
prestart
in class ModuleAdapter
CmdExecException
- if error during command execution.public void go() throws CmdExecException
go
in interface CODAStateMachine
go
in class ModuleAdapter
CmdExecException
- if not all prestart events were received