Belle II Software  release-08-01-10
TRGCDCT3DUnpackerModule.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 //---------------------------------------------------------------
10 // Description : TRGCDCT3DUnpacker Module
11 //---------------------------------------------------------------
12 
13 #include <trg/cdc/modules/trgcdct3dUnpacker/TRGCDCT3DUnpackerModule.h>
14 
15 using namespace std;
16 using namespace Belle2;
17 using namespace TRGCDCT3DUNPACKERSPACE;
18 
20 REG_MODULE(TRGCDCT3DUnpacker);
21 
22 string TRGCDCT3DUnpackerModule::version() const
23 {
24  return string("1.10");
25 }
26 
27 TRGCDCT3DUnpackerModule::TRGCDCT3DUnpackerModule()
28  : Module::Module()
29 {
30 
31  string desc = "TRGCDCT3DUnpackerModule(" + version() + ")";
32  setDescription(desc);
34  addParam("T3DMOD", m_T3DMOD,
35  "T3D module number",
36  0);
37  B2DEBUG(20, "TRGCDCT3DUnpacker: Constructor done.");
38 }
39 
41 {
42 }
43 
45 {
46 }
47 
49 {
50  char c_name[100];
51  sprintf(c_name, "TRGCDCT3DUnpackerStore%d", m_T3DMOD);
52  m_store.registerInDataStore(c_name);
53  //StoreArray<TRGCDCT3DUnpackerStore>::registerPersistent();
54 
55  //set copper address
56  if (m_T3DMOD == 0) {
57  m_copper_address = 0x11000003;
58  m_copper_ab = 0;
59  m_pcie40_address = 0x10000001;
60  m_pcie40_ch = 4;
61 // m_nword = 3075;
62  } else if (m_T3DMOD == 1) {
63  m_copper_address = 0x11000003;
64  m_copper_ab = 1;
65  m_pcie40_address = 0x10000001;
66  m_pcie40_ch = 5;
67 // m_nword = 3075;
68  } else if (m_T3DMOD == 2) {
69  m_copper_address = 0x11000004;
70  m_copper_ab = 0;
71  m_pcie40_address = 0x10000001;
72  m_pcie40_ch = 6;
73 // m_nword = 3075;
74  } else if (m_T3DMOD == 3) {
75  m_copper_address = 0x11000004;
76  m_copper_ab = 1;
77  m_pcie40_address = 0x10000001;
78  m_pcie40_ch = 7;
79 // m_nword = 3075;
80  } else {
81  B2ERROR("trgcdct3dunpacker:cooper address is not set");
82  m_copper_address = 0;
83  m_copper_ab = 0;
84  m_pcie40_address = 0;
85  m_pcie40_ch = 0;
86 // m_nword = 3075;
87  }
88 
89 }
90 
92 {
93 }
94 
96 {
97 }
98 
100 {
101  StoreArray<RawTRG> raw_trgarray;
102  for (int i = 0; i < raw_trgarray.getEntries(); i++) {
103 
104  // Check PCIe40 data or Copper data
105  if (raw_trgarray[i]->GetMaxNumOfCh(0) == 48) { m_pciedata = true; }
106  else if (raw_trgarray[i]->GetMaxNumOfCh(0) == 4) { m_pciedata = false; }
107  else { B2FATAL("TRGCDCT3DUnpackerModule: Invalid value of GetMaxNumOfCh from raw data: " << LogVar("Number of ch: ", raw_trgarray[i]->GetMaxNumOfCh(0))); }
108 
109  unsigned int node_id = 0;
110  unsigned int ch_id = 0;
111  if (m_pciedata) {
112  node_id = m_pcie40_address;
113  ch_id = m_pcie40_ch;
114  } else {
115  node_id = m_copper_address;
116  ch_id = m_copper_ab;
117  }
118 
119  for (int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
120 
121  if (raw_trgarray[i]->GetNodeID(j) == node_id) {
122 
123  if (raw_trgarray[i]->GetDetectorNwords(j, ch_id) == m_nword_2k) {
124  int firm_id = (raw_trgarray[i]->GetDetectorBuffer(j, ch_id))[0];
125  if (firm_id == 0x32444620) { // 2D fitter
126  fillTreeTRGCDCT3DUnpacker_2dfitter(raw_trgarray[i]->GetDetectorBuffer(j, ch_id), raw_trgarray[i]->GetEveNo(j));
127  } else {
128  fillTreeTRGCDCT3DUnpacker(raw_trgarray[i]->GetDetectorBuffer(j, ch_id), raw_trgarray[i]->GetEveNo(j));
129  }
130  }
131  // 2.6k, 15 TS version
132  else if (raw_trgarray[i]->GetDetectorNwords(j, ch_id) == m_nword_2624) {
133  fillTreeTRGCDCT3DUnpacker_2624(raw_trgarray[i]->GetDetectorBuffer(j, ch_id), raw_trgarray[i]->GetEveNo(j));
134  }
135  }
136  }
137  }
138 }
139 
141 {
142 
143  const unsigned nword_header = 3; // updated from 2 to 3
144 
145  long dataHeader = buf[nword_header] & 0xffff0000;
146  if (dataHeader != 0xdddd0000) {
147  // wrong data block header
148  return ;
149  }
150 
151  //StoreArray<TRGCDCT3DUnpackerStore> storeAry;
152  for (int clk = 0; clk < nClks; clk++) { // 0..47
153 
154  m_store.appendNew();
155  int ntups = m_store.getEntries() - 1;
156  int* bitArray[nLeafs + nLeafsExtra];
157  setLeafPointersArray(m_store[ntups], bitArray);
158  for (int l = 0; l < nLeafs + nLeafsExtra; l++) *bitArray[l] = 0;
159 
160  m_store[ntups]->m_evt = evt;
161  m_store[ntups]->m_clk = clk;
162  m_store[ntups]->m_firmid = buf[0];
163  m_store[ntups]->m_firmver = buf[1];
164 
166  //cout<<"nClks: "<<nClks<<endl;
167  //cout<<"Up,Left is MSB, Down,Right is LSB"<<endl;
168  //for (unsigned _wd = 0; _wd < nBits / 32 + nword_header; _wd++)
169  //{
170  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd]);
171  // stringstream wd_s;
172  // wd_s << setfill('0') << setw(2) << _wd;
173  // stringstream wd_s_d;
174  // wd_s_d << setfill('0') << setw(2) << _wd-nword_header;
175  // if (_wd < nword_header) cout<<"clk["<<clk<<"] hd["<<wd_s.str()<<"] "<<buf_b<<endl;
176  // else cout<<"clk["<<clk<<"] wd["<<wd_s_d.str()<<"] "<<buf_b<<endl;
177  //}
178 
179  //cout<<"nClks: "<<nClks<<endl;
180  //for (int _wd = 0; _wd < nBits / 32; _wd++)
181  //{
182  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd + nword_header]);
183  // cout<<"clk["<<clk<<"] wd["<<_wd<<"] "<<buf_b<<endl;
184  //}
185 
186  for (unsigned _wd = 0; _wd < nBits_2k / 32; _wd++) { // 0..19
187  unsigned wd = buf[clk * (nBits_2k / 32) + _wd + nword_header];
188  for (int bb = 0; bb < 32; bb++) { // bit by bit
189  if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
190  int bitPosition = (nBits_2k - 1) - _wd * 32 - bb;
191  for (int leaf = 0; // Find a leaf that covers the bit.
192  leaf < nLeafs; leaf++) {
193  int bitMaxOfTheLeaf = BitMap[leaf][0];
194  int bitWidOfTheLeaf = BitMap[leaf][1];
195  int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
196  if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
197  *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
198  }
199  }
200  }
201  }
202  }
203  }
204 }
205 
207 {
208 
209  const unsigned nword_header = 3; // updated from 2 to 3
210 
211  long dataHeader = buf[nword_header] & 0xffff0000;
212  if (dataHeader != 0xdddd0000) {
213  // wrong data block header
214  return ;
215  }
216 
217  //StoreArray<TRGCDCT3DUnpackerStore> storeAry;
218  for (int clk = 0; clk < nClks; clk++) { // 0..47
219 
220  m_store.appendNew();
221  int ntups = m_store.getEntries() - 1;
222  int* bitArray[nLeafs_2dfitter + nLeafsExtra];
223  setLeafPointersArray_2dfitter(m_store[ntups], bitArray);
224  for (int l = 0; l < nLeafs_2dfitter + nLeafsExtra; l++) *bitArray[l] = 0;
225 
226  m_store[ntups]->m_evt = evt;
227  m_store[ntups]->m_clk = clk;
228  m_store[ntups]->m_firmid = buf[0];
229  m_store[ntups]->m_firmver = buf[1];
230 
232  //cout<<"nClks: "<<nClks<<endl;
233  //cout<<"Up,Left is MSB, Down,Right is LSB"<<endl;
234  //for (unsigned _wd = 0; _wd < nBits / 32 + nword_header; _wd++)
235  //{
236  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd]);
237  // stringstream wd_s;
238  // wd_s << setfill('0') << setw(2) << _wd;
239  // stringstream wd_s_d;
240  // wd_s_d << setfill('0') << setw(2) << _wd-nword_header;
241  // if (_wd < nword_header) cout<<"clk["<<clk<<"] hd["<<wd_s.str()<<"] "<<buf_b<<endl;
242  // else cout<<"clk["<<clk<<"] wd["<<wd_s_d.str()<<"] "<<buf_b<<endl;
243  //}
244 
245  //cout<<"nClks: "<<nClks<<endl;
246  //for (int _wd = 0; _wd < nBits / 32; _wd++)
247  //{
248  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd + nword_header]);
249  // cout<<"clk["<<clk<<"] wd["<<_wd<<"] "<<buf_b<<endl;
250  //}
251 
252  for (unsigned _wd = 0; _wd < nBits_2k / 32; _wd++) { // 0..19
253  unsigned wd = buf[clk * (nBits_2k / 32) + _wd + nword_header];
254  for (int bb = 0; bb < 32; bb++) { // bit by bit
255  if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
256  int bitPosition = (nBits_2k - 1) - _wd * 32 - bb;
257  for (int leaf = 0; // Find a leaf that covers the bit.
258  leaf < nLeafs_2dfitter; leaf++) {
259  int bitMaxOfTheLeaf = BitMap_2dfitter[leaf][0];
260  int bitWidOfTheLeaf = BitMap_2dfitter[leaf][1];
261  int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
262  if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
263  *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
264  }
265  }
266  }
267  }
268  }
269  }
270 }
271 
272 
274 {
275 
276  const unsigned nword_header = 3; // updated from 2 to 3
277 
278  long dataHeader = buf[nword_header] & 0xffff0000;
279  if (dataHeader != 0xdddd0000) {
280  // wrong data block header
281  return ;
282  }
283 
284  //StoreArray<TRGCDCT3DUnpackerStore> storeAry;
285  for (int clk = 0; clk < nClks; clk++) { // 0..47
286 
287  m_store.appendNew();
288  int ntups = m_store.getEntries() - 1;
289  int* bitArray[nLeafs_2624 + nLeafsExtra];
290  setLeafPointersArray_2624(m_store[ntups], bitArray);
291  for (int l = 0; l < nLeafs_2624 + nLeafsExtra; l++) *bitArray[l] = 0;
292 
293  m_store[ntups]->m_evt = evt;
294  m_store[ntups]->m_clk = clk;
295  m_store[ntups]->m_firmid = buf[0];
296  m_store[ntups]->m_firmver = buf[1];
297 
299  //cout<<"nClks: "<<nClks<<endl;
300  //cout<<"Up,Left is MSB, Down,Right is LSB"<<endl;
301  //for (unsigned _wd = 0; _wd < nBits / 32 + nword_header; _wd++)
302  //{
303  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd]);
304  // stringstream wd_s;
305  // wd_s << setfill('0') << setw(2) << _wd;
306  // stringstream wd_s_d;
307  // wd_s_d << setfill('0') << setw(2) << _wd-nword_header;
308  // if (_wd < nword_header) cout<<"clk["<<clk<<"] hd["<<wd_s.str()<<"] "<<buf_b<<endl;
309  // else cout<<"clk["<<clk<<"] wd["<<wd_s_d.str()<<"] "<<buf_b<<endl;
310  //}
311 
312  //cout<<"nClks: "<<nClks<<endl;
313  //for (int _wd = 0; _wd < nBits / 32; _wd++)
314  //{
315  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd + nword_header]);
316  // cout<<"clk["<<clk<<"] wd["<<_wd<<"] "<<buf_b<<endl;
317  //}
318 
319  for (unsigned _wd = 0; _wd < nBits_2624 / 32; _wd++) { // 0..19
320  unsigned wd = buf[clk * (nBits_2624 / 32) + _wd + nword_header];
321  for (int bb = 0; bb < 32; bb++) { // bit by bit
322  if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
323  int bitPosition = (nBits_2624 - 1) - _wd * 32 - bb;
324  for (int leaf = 0; // Find a leaf that covers the bit.
325  leaf < nLeafs_2624; leaf++) {
326  int bitMaxOfTheLeaf = BitMap_2624[leaf][0];
327  int bitWidOfTheLeaf = BitMap_2624[leaf][1];
328  int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
329  if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
330  *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
331  }
332  }
333  }
334  }
335  }
336  }
337 }
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
virtual void fillTreeTRGCDCT3DUnpacker_2624(int *buf, int evt)
Unpacker main function, 2.6k, 15 TS version.
virtual void fillTreeTRGCDCT3DUnpacker(int *buf, int evt)
Unpacker main function.
virtual void fillTreeTRGCDCT3DUnpacker_2dfitter(int *buf, int evt)
Unpacker main function.
virtual void initialize() override
Initilizes TRGCDCT3DUnpackerUnpackerModule.
virtual void event() override
Called event by event.
virtual void endRun() override
Called when run ended.
virtual void terminate() override
Called when processing ended.
int m_nword_2624
Number of words im raw data, 2.6k, 15 TS version.
virtual void beginRun() override
Called when new run started.
StoreArray< TRGCDCT3DUnpackerStore > m_store
Output datastore for unpacker.
std::string version() const
returns version of TRGCDCT3DUnpackerModule.
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.