Belle II Software development
trgcdctsfUnpackerModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <trg/cdc/modules/trgcdctsfUnpacker/trgcdctsfUnpackerModule.h>
10#include <bitset>
11
12using namespace std;
13using namespace Belle2;
14using namespace TRGCDCTSF;
15
17REG_MODULE(TRGCDCTSFUnpacker);
18
20{
21 return string("1.00");
22}
23
25 : Module::Module()
26{
27
28 string desc = "TRGCDCTSFUnpackerModule(" + version() + ")";
29 setDescription(desc);
31 addParam("TSFMOD", m_TSFMOD,
32 "TSF module number",
33 0);
34
35
36
37 B2DEBUG(20, "trgcdctsfunpacker: Constructor done.");
38
39
40}
41
43{
44}
45
47{
48}
49
51{
52 char c_name[100];
53 sprintf(c_name, "TRGCDCTSFUnpackerStore%d", m_TSFMOD);
54 storeAry.registerInDataStore(c_name);
55
57 _exp = bevt->getExperiment();
58 _run = bevt->getRun();
59
60 //set copper address
61 if (m_TSFMOD == 0) {
62 m_copper_address = 0x11000007;
63 m_copper_ab = 0;
64 m_pcie40_address = 0x10000001;
65 m_pcie40_ch = 12;
66 } else if (m_TSFMOD == 1) {
67 if (_exp > 7 || (_exp == 7 && _run > 4023)) {
68 m_copper_address = 0x11000009;
69 m_copper_ab = 0;
70 m_pcie40_address = 0x10000001;
71 m_pcie40_ch = 13;
72 } else {
73 m_copper_address = 0x11000007;
74 m_copper_ab = 1;
75 m_pcie40_address = 0x10000001;
76 m_pcie40_ch = 13;
77 }
78 } else if (m_TSFMOD == 2) {
79 m_copper_address = 0x11000008;
80 m_copper_ab = 0;
81 m_pcie40_address = 0x10000001;
82 m_pcie40_ch = 14;
83 } else if (m_TSFMOD == 3) {
84 m_copper_address = 0x11000008;
85 m_copper_ab = 1;
86 m_pcie40_address = 0x10000001;
87 m_pcie40_ch = 15;
88 } else if (m_TSFMOD == 4) {
89 if (_exp > 7 || (_exp == 7 && _run > 4023)) {
90 m_copper_address = 0x11000007;
91 m_copper_ab = 1;
92 m_pcie40_address = 0x10000001;
93 m_pcie40_ch = 16;
94 } else {
95 m_copper_address = 0x11000009;
96 m_copper_ab = 0;
97 m_pcie40_address = 0x10000001;
98 m_pcie40_ch = 16;
99 }
100 } else if (m_TSFMOD == 5) {
101 m_copper_address = 0x11000009;
102 m_copper_ab = 1;
103 m_pcie40_address = 0x10000001;
104 m_pcie40_ch = 17;
105 } else if (m_TSFMOD == 6) {
106 m_copper_address = 0x1100000a;
107 m_copper_ab = 0;
108 m_pcie40_address = 0x10000001;
109 m_pcie40_ch = 18;
110 } else {
111 B2ERROR("trgcdctsfunpacker:cooper address is not set");
113 m_copper_ab = 0;
115 m_pcie40_ch = 0;
116 }
117
118
119 //set bitmap
120 if (m_TSFMOD == 0 || m_TSFMOD == 4 || m_TSFMOD == 6) {
121 m_nBits = nBits_2k;
122 m_nword = nword_2k;
123 for (int i = 0; i < nLeafs; i++) {
124 for (int j = 0; j < 2; j++) {
125 //m_BitMap[i][j] = BitMap_2k[i][j];
126 }
127 }
128 } else if (m_TSFMOD == 1 || m_TSFMOD == 2 || m_TSFMOD == 3 || m_TSFMOD == 5) {
129 m_nBits = nBits_4k;
130 m_nword = nword_4k;
131 for (int i = 0; i < nLeafs; i++) {
132 for (int j = 0; j < 2; j++) {
133 //m_BitMap[i][j] = BitMap_4k[i][j];
134 }
135 }
136 } else {
137 B2ERROR("trgcdctsfunpacker:cooper address is not set");
138 m_nBits = 0;
139 m_nword = 0;
140 for (int i = 0; i < nLeafs; i++) {
141 for (int j = 0; j < 2; j++) {
142 //m_BitMap[i][j] = 0;
143 }
144 }
145 }
146
147}
148
150{
151}
152
154{
155}
156
158{
159 StoreArray<RawTRG> raw_trgarray;
160 for (int i = 0; i < raw_trgarray.getEntries(); i++) {
161
162 // Check PCIe40 data or Copper data
163 if (raw_trgarray[i]->GetMaxNumOfCh(0) == 48) { m_pciedata = true; }
164 else if (raw_trgarray[i]->GetMaxNumOfCh(0) == 4) { m_pciedata = false; }
165 else { B2FATAL("TRGCDCTSFUnpackerModule: Invalid value of GetMaxNumOfCh from raw data: " << LogVar("Number of ch: ", raw_trgarray[i]->GetMaxNumOfCh(0))); }
166
167 unsigned int node_id = 0;
168 unsigned int ch_id = 0;
169 if (m_pciedata) {
170 node_id = m_pcie40_address;
171 ch_id = m_pcie40_ch;
172 } else {
173 node_id = m_copper_address;
174 ch_id = m_copper_ab;
175 }
176
177 for (int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
178 if (raw_trgarray[i]->GetNodeID(j) == node_id) {
179 if (raw_trgarray[i]->GetDetectorNwords(j, ch_id) == m_nword) {
180 // get the firm_vers beforehand to know 10 or 15 TS version
181 int firm_vers = (raw_trgarray[i]->GetDetectorBuffer(j, ch_id))[1];
182 // condition for 15 TS version:
183 // TSF1: X"19041805" or newer than X"19052105"
184 // TSF3: X"19041805" or newer than X"19052105"
185 // TSF5: X"19041901" or newer than X"19061105"
186 if (m_TSFMOD == 1 && (firm_vers == 0x19041805 || firm_vers > 0x19052105)) {
187 fillTreeCDCTSF_4k15ts(raw_trgarray[i]->GetDetectorBuffer(j, ch_id), raw_trgarray[j]->GetEveNo(j));
188 } else if (m_TSFMOD == 3 && (firm_vers == 0x19041805 || firm_vers > 0x19052105)) {
189 fillTreeCDCTSF_4k15ts(raw_trgarray[i]->GetDetectorBuffer(j, ch_id), raw_trgarray[j]->GetEveNo(j));
190 } else if (m_TSFMOD == 5 && (firm_vers == 0x19041901 || firm_vers > 0x19061105)) {
191 fillTreeCDCTSF_4k15ts(raw_trgarray[i]->GetDetectorBuffer(j, ch_id), raw_trgarray[j]->GetEveNo(j));
192 } else {
193 fillTreeCDCTSF(raw_trgarray[i]->GetDetectorBuffer(j, ch_id), raw_trgarray[j]->GetEveNo(j));
194 }
195 }
196 }
197 }
198 }
199}
200
202{
203
204 const unsigned nword_header = 3;
205
206 for (int clk = 0; clk < nClks; clk++) { // 0..47
207
208 storeAry.appendNew();
209 int ntups = storeAry.getEntries() - 1;
210 int* bitArray[nLeafs + nLeafsExtra];
211 setLeafPointersArray(storeAry[ntups], bitArray);
212 for (int l = 0; l < nLeafs + nLeafsExtra; l++) *bitArray[l] = 0;
213
214 storeAry[ntups]->m_evt = evt;
215 storeAry[ntups]->m_clk = clk;
216 storeAry[ntups]->m_firmid = buf[0];
217 storeAry[ntups]->m_firmver = buf[1];
218 storeAry[ntups]->m_N2DTS = 10;
219
220
221 for (int _wd = 0; _wd < m_nBits / 32; _wd++) { // 0..19
222 unsigned wd = buf[clk * (m_nBits / 32) + _wd + nword_header];
223 bitset<32> bwd(wd);
224 for (int bb = 0; bb < 32; bb++) { // bit by bit
225 if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
226 int bitPosition = (m_nBits - 1) - _wd * 32 - bb;
227 for (int leaf = 0; // Find a leaf that covers the bit.
228 leaf < nLeafs; leaf++) {
229 //int bitMaxOfTheLeaf = m_BitMap[leaf][0];
230 //int bitWidOfTheLeaf = m_BitMap[leaf][1];
231 int bitMaxOfTheLeaf = 0 ;
232 if (m_nword == nword_2k) { bitMaxOfTheLeaf = BitMap_2k[leaf][0]; }
233 else {bitMaxOfTheLeaf = BitMap_4k[leaf][0];}
234
235 int bitWidOfTheLeaf = 0 ;
236 if (m_nword == nword_2k) { bitWidOfTheLeaf = BitMap_2k[leaf][1]; }
237 else {bitWidOfTheLeaf = BitMap_4k[leaf][1];}
238
239 int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
240 if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
241 *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
242 }
243 }
244 }
245 }
246 }
247 }
248}
249
251{
252
253 const unsigned nword_header = 3;
254
255 for (int clk = 0; clk < nClks; clk++) { // 0..47
256
257 storeAry.appendNew();
258 int ntups = storeAry.getEntries() - 1;
259 int* bitArray[nLeafs_4k15ts + nLeafsExtra];
260 setLeafPointersArray_4k15ts(storeAry[ntups], bitArray);
261 for (int l = 0; l < nLeafs_4k15ts + nLeafsExtra; l++) *bitArray[l] = 0;
262
263 storeAry[ntups]->m_evt = evt;
264 storeAry[ntups]->m_clk = clk;
265 storeAry[ntups]->m_firmid = buf[0];
266 storeAry[ntups]->m_firmver = buf[1];
267 storeAry[ntups]->m_N2DTS = 15;
268
269
270 for (int _wd = 0; _wd < m_nBits / 32; _wd++) { // 0..19
271 unsigned wd = buf[clk * (m_nBits / 32) + _wd + nword_header];
272 bitset<32> bwd(wd);
273 for (int bb = 0; bb < 32; bb++) { // bit by bit
274 if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
275 int bitPosition = (m_nBits - 1) - _wd * 32 - bb;
276 for (int leaf = 0; // Find a leaf that covers the bit.
277 leaf < nLeafs_4k15ts; leaf++) {
278 int bitMaxOfTheLeaf = BitMap_4k15ts[leaf][0];
279 int bitWidOfTheLeaf = BitMap_4k15ts[leaf][1];
280 int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
281 if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
282 *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
283 }
284 }
285 }
286 }
287 }
288 }
289}
290
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
StoreArray< TRGCDCTSFUnpackerStore > storeAry
StoreArray of TRGCDCTSFUnpackerStore.
virtual void fillTreeCDCTSF(int *buf, int evt)
Unpacker main function.
virtual void initialize() override
Initilizes TRGCDCTSFUnpackerModuel.
virtual void event() override
Called event by event.
virtual void endRun() override
Called when run ended.
unsigned int m_pcie40_ch
channel ID of PCIe40 module
virtual void terminate() override
Called when processing ended.
virtual void beginRun() override
Called when new run started.
unsigned int m_pcie40_address
address of PCIe40 module
unsigned int m_copper_address
address of copper module
std::string version() const
returns version of TRGCDCTSFUnpackerModule.
virtual void fillTreeCDCTSF_4k15ts(int *buf, int evt)
Unpacker main function for 4k, 15 TS version.
unsigned int m_copper_ab
address of copper module
Class to store variables with their name which were sent to the logging service.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
STL namespace.