12 #include <klm/modules/KLMPacker/KLMPackerModule.h>
15 #include <framework/logging/Logger.h>
25 setDescription(
"KLM raw data packer (creates RawKLM from KLMDigits).");
26 setPropertyFlags(c_ParallelProcessingCertified);
43 B2FATAL(
"KLM electronics map is not available.");
52 std::vector<uint32_t> dataWords[8][4];
56 uint32_t buf[2] = {0};
63 digit.getSubdetector(), digit.getSection(), digit.getSector(),
64 digit.getLayer(), digit.getPlane(), digit.getStrip());
67 if (electronicsChannel ==
nullptr)
68 B2FATAL(
"Incomplete KLM electronics map.");
74 int lane = electronicsChannel->
getLane();
75 int plane = electronicsChannel->
getAxis();
78 digit.getCharge(), digit.getCTime(), digit.getTDC(),
79 bword1, bword2, bword3, bword4);
81 buf[0] |= ((bword1 << 16));
83 buf[1] |= ((bword3 << 16));
85 int copper = electronicsChannel->
getCopper() - BKLM_ID - 1;
86 int dataConcentrator = electronicsChannel->
getSlot() - 1;
87 dataWords[copper][dataConcentrator].push_back(buf[0]);
88 dataWords[copper][dataConcentrator].push_back(buf[1]);
90 int copper = electronicsChannel->
getCopper() - EKLM_ID - 1;
91 int dataConcentrator = electronicsChannel->
getSlot() - 1;
92 dataWords[copper + 4][dataConcentrator].push_back(buf[0]);
93 dataWords[copper + 4][dataConcentrator].push_back(buf[1]);
108 for (
int i = 0; i < 8; i++) {
110 packerInfo.
node_id = BKLM_ID + 1 + i;
112 packerInfo.
node_id = EKLM_ID + 1 + i - 4;
114 for (
int j = 0; j < 4; j++) {
115 nWords[j] = dataWords[i][j].size();
116 detectorBuf[j] =
new int[nWords[j] + 1];
117 for (
int k = 0; k < nWords[j]; k++)
118 detectorBuf[j][k] = dataWords[i][j][k];
119 detectorBuf[j][nWords[j]] = 0;
122 detectorBuf[1], nWords[1] + 1,
123 detectorBuf[2], nWords[2] + 1,
124 detectorBuf[3], nWords[3] + 1,
126 for (
int j = 0; j < 4; j++)
127 delete[] detectorBuf[j];
142 uint16_t& bword1, uint16_t& bword2, uint16_t& bword3, uint16_t& bword4)
148 bword1 |= (strip & 0x7F);
149 bword1 |= ((plane & 1) << 7);
150 bword1 |= ((lane & 0x1F) << 8);
151 bword1 |= (flag << 13);
152 bword2 |= (ctime & 0xFFFF);
153 bword3 |= (tdc & 0x3FF);
154 bword4 |= (charge & 0xFFF);