9#include <framework/core/Module.h>
10#include <cdc/dataobjects/CDCHit.h>
11#include <framework/datastore/StoreArray.h>
12#include <trg/cdc/dataobjects/Bitstream.h>
13#include <trg/cdc/dataobjects/CDCTriggerSegmentHit.h>
14#include <trg/cdc/Cosim.h>
21#include <unordered_map>
32 namespace CDCTrigger {
33 enum class Priority :
unsigned char {nothing, first, second};
35 std::unordered_map<unsigned, Priority> toPriorityMap = {{0, Priority::nothing},
36 {1, Priority::second},
37 {2, Priority::second},
40 Priority toPriority(
unsigned priorityPosition)
42 return toPriorityMap[priorityPosition];
44 enum MergerOut :
long unsigned int {priorityTime, fastestTime, edgeTime, hitmap, secondPriorityHit};
75 void event()
override;
81 static constexpr std::array<int, 9>
nMergers = {10, 10, 12, 14, 16, 18, 20, 22, 24};
84 static constexpr std::array<int, m_nSubModules>
nAxialMergers = {10, 12, 16, 20, 24};
135 using signalBus = std::array<outputArray, m_nSubModules>;
169 std::string
cwd = getcurrentdir();
187 std::array<pid_t, m_nSubModules>
m_pid;
217 std::array<streamPair, m_nSubModules>
stream;
231 void write(
const char* message, FILE* outstream);
243 std::istream*
ins =
nullptr;
257 template<
size_t nEdges>
259 std::array<timeVec, nSegmentsInMerger>,
260 std::array<timeVec, nSegmentsInMerger>,
261 std::array<timeVec, nEdges>,
262 std::array<std::bitset<nWiresInMerger>, 1>,
263 std::array<std::bitset<nSegmentsInMerger>, 1> >;
265 template<
size_t nEdges>
292 using TSMap = std::unordered_map<short, WireSet>;
297 using edgeMap = std::unordered_map<unsigned short, timeVec*>;
314 using edgeList = std::unordered_map<unsigned short, std::vector<unsigned short>>;
328 CDCTrigger::Priority
priority(
int index);
339 unsigned short trgTime(
int index,
int iFirstHit);
377 std::bitset<4>
timeStamp(
int index,
int iFirstHit);
409 template<CDCTrigger::MergerOut field,
size_t w
idth>
410 void pack(inputVector::reverse_iterator& rInput,
Class to hold one clock cycle of raw bit content.
This class is the interface between TSim/basf2 TSF module and the firmware simulation core of XSim/IS...
std::array< priorityHitStructInClock, m_nClockPerEvent > priorityHitStruct
all priority hits map in Merger
std::vector< mergerStructElement< nEdges > > mergerStruct
data structure to hold merger output
int m_iFirstHit
ID of the earlist CDC hit in an event.
void initializeMerger()
Get CDC hits from the DataStore and distribute them to clocks.
std::array< FILE *, 2 > streamPair
file handlers of pipes
static constexpr std::array< int, 9 > nMergers
number of mergers in each super layer
void computeEdges()
Compute the map from merger cell ID to all its related edge fields.
bool m_simulateCC
flag to simulate front-end clock counter
int m_TDCCountForT0
TDC count value from T0.
int m_debugLevel
debug level specified in the steering file
void saveFirmwareOutput()
save firmware output
unsigned short trgTime(int index, int iFirstHit)
Get the trigger time of the CDC hit.
Belle2::StoreArray< CDCHit > m_cdcHits
CDCHit array.
std::array< edgeList, 2 > m_edge
map from cell ID to related edge ID
std::bitset< 4 > timeStamp(int index, int iFirstHit)
Get the trigger time stamp of a hit.
std::string design_libname_post
path to the simulation snapshot
outputArray read(FILE *instream)
write TSF output signals from the worker
std::array< mergerOutput, m_nSubModules > mergerOutArray
Merger output array.
static constexpr int nCellsInLayer
Number of wire/cells in a single layer per merger unit.
std::tuple< std::array< timeVec, nSegmentsInMerger >, std::array< timeVec, nSegmentsInMerger >, std::array< timeVec, nEdges >, std::array< std::bitset< nWiresInMerger >, 1 >, std::array< std::bitset< nSegmentsInMerger >, 1 > > mergerStructElement
data structure to hold merger output <priority time (4 bits x 16), fast time (4 bits x 16),...
std::array< cellList, 5 > innerInvEdge
list of cell ID related to edge timing
StoreArray< CDCTriggerSegmentHit > m_tsHits
unpacked track segment hit
std::vector< registeredStructElement > registeredStruct
vector of registeredStructElement
bool notHit(CDCTrigger::MergerOut field, unsigned iTS, registeredStructElement ®)
Whether a time field in a merger has been hit in the clock cycle.
priorityHitStruct m_priorityHit
list keeping the index of priority hit of a TS for making fastsim ts hit object
WireSet segmentID(int iHit)
Get the list of associated track segments with a hit.
void initialize() override
spawn child process for workers, open pipes to pass data
mergerOutArray outputFromMerger
bits format of merger output / TSF input
std::string cwd
current diretory
void pack(inputVector::reverse_iterator &rInput, unsigned number, mergerStructElement< 5 > &output)
Pack the merger output data structure to TSF input vector.
void event() override
Things to do for each event.
CDCTrigger::Priority priority(int index)
write TSF input signals to the worker
std::vector< short > WireSet
Wire set.
std::map< unsigned, priorityHitStructInSL > priorityHitStructInClock
priority hits map in Merger for a clock
static constexpr size_t timeWidth
bit width for priority time and fast time
std::bitset< mergerWidth > mergerVector
Merger vector.
static constexpr int nTrackers
number of trackers
std::vector< unsigned short > cellList
cell list
std::string m_outputCollectionName
Name of the StoreArray holding the found TS hits.
std::array< inputFromMerger, m_nSubModules > inputToTSFArray
input array to TSF
std::string design_libname_pre
path to the simulation snapshot
std::bitset< timeWidth > timeVec
element of data structure to hold merger output
std::vector< mergerVector > mergerOutput
Merger output.
std::array< std::array< int, 2 >, m_nSubModules > inputFileDescriptor
array holding file descriptors of pipes
static constexpr int m_nClockPerEvent
how many clocks to simulate per event
std::string m_outputBitstreamNameTo2D
Name of the StoreArray holding the raw bit content to 2D trackers.
void terminate() override
close the pipes and wait for children to die.
std::array< outputVector, nTrackers > outputArray
output array
std::array< outputArray, m_nSubModules > outputToTracker
array holding TSF output data
std::array< char, width_out > outputVector
output vector
std::vector< inputVector > inputFromMerger
input array from Merger
std::array< char, mergerWidth > inputVector
input array
StoreArray< signalBitStream > m_bitsTo2D
bitstream of TSF output to 2D tracker
std::array< std::array< int, 2 >, m_nSubModules > outputFileDescriptor
array holding file descriptors of pipes
void setSecondPriority(unsigned priTS, unsigned iHit, timeVec hitTime, unsigned lr, mergerStructElement< 5 > &mergerData, registeredStructElement ®isteredCell, priorityHitInMerger &priorityHit)
set 2nd priority info
static constexpr std::array< int, m_nSubModules > nAxialMergers
number of mergers in axial super layers
std::array< TSMap, 2 > m_tsMap
map from cell ID to TS ID, for inner and outer Merger
CDCTriggerTSFFirmwareModule()
Constructor.
std::string wdbName_pre
wdb name prefix
std::vector< bool > m_stubLUT
list of flags to run a TSF firmware simulation with dummy L/R LUT (to speed up loading)
std::unordered_map< unsigned short, timeVec * > edgeMap
edge wire list
std::string simengine_libname
path to the simulation engine
char * getData(inputToTSFArray)
get the XSI compliant format from the bits format TSF input
void write(const char *message, FILE *outstream)
write TSF input signals to the worker
inputToTSFArray inputToTSF
XSI compliant format of input to TSF.
void saveFastOutput(short iclock)
save fast TSIM output
static constexpr int nSegmentsInMerger
number of track segments in a single merger unit
bool m_allPositiveTime
switch If true, the trigger time of the hit with largest TDC count becomes 0.
std::array< pid_t, m_nSubModules > m_pid
'1' in XSI VHDL simulation
static constexpr int mergerWidth
merger output data width
std::array< outputArray, m_nSubModules > signalBus
signal bus
std::string wdbName_post
wdb name extension
static constexpr int clockPeriod
data clock period (32ns) in unit of 2ns
unsigned short mergerNumber(int index)
Get the merger unit ID in a super layer.
std::string lib_extension
extension of lib
static constexpr int nWiresInMerger
number of wire/cell in a single merger unit
bool m_mergerOnly
flag to only simulation merger and not TSF
std::array< cellList, 3 > outerInvEdge
list of cell ID related to edge timing
std::map< unsigned, mergerStruct< 5 > > dataAcrossClocks
data structure to hold merger output
void simulateMerger(unsigned iclock)
Simulate 1 clock of merger.
std::string m_hitCollectionName
Name of the StoreArray containing the input CDC hits.
std::array< std::bitset< nCellsInLayer >, 3 > registeredStructElement
record when a time slow has been registered by a hit <priority time, fast time, edge timing>
std::istream * ins
data stream
std::unordered_map< short, WireSet > TSMap
TS map.
static constexpr int m_nSubModules
number of TSF to simulate
std::vector< priorityHitInMerger > priorityHitStructInSL
priority hits map in Merger for a SL
std::map< unsigned, int > priorityHitInMerger
priority hits map in Merger
std::array< streamPair, m_nSubModules > stream
array holding file handlers of pipes
unsigned short mergerCellID(int index)
Get the cell ID in the merger.
std::unordered_map< unsigned short, std::vector< unsigned short > > edgeList
edge wire list
static constexpr int width_out
width of output data width
void registerHit(CDCTrigger::MergerOut field, unsigned iTS, registeredStructElement ®)
Register the timing field so that later hits won't overwrite it.
std::vector< std::vector< int > > iAxialHitInClock
CDC hit ID in each clock.
std::string m_outputBitstreamNameToETF
Name of the StoreArray holding the raw bit content to ETF.
Accessor to arrays stored in the data store.
Abstract base class for different kinds of events.