Belle II Software  release-06-00-14
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_nword = 3075;
60  } else if (m_T3DMOD == 1) {
61  m_copper_address = 0x11000003;
62  m_copper_ab = 1;
63 // m_nword = 3075;
64  } else if (m_T3DMOD == 2) {
65  m_copper_address = 0x11000004;
66  m_copper_ab = 0;
67 // m_nword = 3075;
68  } else if (m_T3DMOD == 3) {
69  m_copper_address = 0x11000004;
70  m_copper_ab = 1;
71 // m_nword = 3075;
72  } else {
73  B2ERROR("trgcdct3dunpacker:cooper address is not set");
74  m_copper_address = 0;
75  m_copper_ab = 0;
76 // m_nword = 3075;
77  }
78 
79 }
80 
82 {
83 }
84 
86 {
87 }
88 
90 {
91  StoreArray<RawTRG> raw_trgarray;
92  for (int i = 0; i < raw_trgarray.getEntries(); i++) {
93  for (int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
94  if (raw_trgarray[i]->GetNodeID(j) == m_copper_address) {
95 
96  if (raw_trgarray[i]->GetDetectorNwords(j, m_copper_ab) == m_nword_2k) {
97  int firm_id = (raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab))[0];
98  if (firm_id == 0x32444620) { // 2D fitter
99  fillTreeTRGCDCT3DUnpacker_2dfitter(raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab), raw_trgarray[i]->GetEveNo(j));
100  } else {
101  fillTreeTRGCDCT3DUnpacker(raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab), raw_trgarray[i]->GetEveNo(j));
102  }
103  }
104  // 2.6k, 15 TS version
105  else if (raw_trgarray[i]->GetDetectorNwords(j, m_copper_ab) == m_nword_2624) {
106  fillTreeTRGCDCT3DUnpacker_2624(raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab), raw_trgarray[i]->GetEveNo(j));
107  }
108  }
109  }
110  }
111 }
112 
114 {
115 
116  const unsigned nword_header = 3; // updated from 2 to 3
117 
118  long dataHeader = buf[nword_header] & 0xffff0000;
119  if (dataHeader != 0xdddd0000) {
120  // wrong data block header
121  return ;
122  }
123 
124  //StoreArray<TRGCDCT3DUnpackerStore> storeAry;
125  for (int clk = 0; clk < nClks; clk++) { // 0..47
126 
127  m_store.appendNew();
128  int ntups = m_store.getEntries() - 1;
129  int* bitArray[nLeafs + nLeafsExtra];
130  setLeafPointersArray(m_store[ntups], bitArray);
131  for (int l = 0; l < nLeafs + nLeafsExtra; l++) *bitArray[l] = 0;
132 
133  m_store[ntups]->m_evt = evt;
134  m_store[ntups]->m_clk = clk;
135  m_store[ntups]->m_firmid = buf[0];
136  m_store[ntups]->m_firmver = buf[1];
137 
139  //cout<<"nClks: "<<nClks<<endl;
140  //cout<<"Up,Left is MSB, Down,Right is LSB"<<endl;
141  //for (unsigned _wd = 0; _wd < nBits / 32 + nword_header; _wd++)
142  //{
143  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd]);
144  // stringstream wd_s;
145  // wd_s << setfill('0') << setw(2) << _wd;
146  // stringstream wd_s_d;
147  // wd_s_d << setfill('0') << setw(2) << _wd-nword_header;
148  // if (_wd < nword_header) cout<<"clk["<<clk<<"] hd["<<wd_s.str()<<"] "<<buf_b<<endl;
149  // else cout<<"clk["<<clk<<"] wd["<<wd_s_d.str()<<"] "<<buf_b<<endl;
150  //}
151 
152  //cout<<"nClks: "<<nClks<<endl;
153  //for (int _wd = 0; _wd < nBits / 32; _wd++)
154  //{
155  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd + nword_header]);
156  // cout<<"clk["<<clk<<"] wd["<<_wd<<"] "<<buf_b<<endl;
157  //}
158 
159  for (unsigned _wd = 0; _wd < nBits_2k / 32; _wd++) { // 0..19
160  unsigned wd = buf[clk * (nBits_2k / 32) + _wd + nword_header];
161  for (int bb = 0; bb < 32; bb++) { // bit by bit
162  if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
163  int bitPosition = (nBits_2k - 1) - _wd * 32 - bb;
164  for (int leaf = 0; // Find a leaf that covers the bit.
165  leaf < nLeafs; leaf++) {
166  int bitMaxOfTheLeaf = BitMap[leaf][0];
167  int bitWidOfTheLeaf = BitMap[leaf][1];
168  int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
169  if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
170  *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
171  }
172  }
173  }
174  }
175  }
176  }
177 }
178 
180 {
181 
182  const unsigned nword_header = 3; // updated from 2 to 3
183 
184  long dataHeader = buf[nword_header] & 0xffff0000;
185  if (dataHeader != 0xdddd0000) {
186  // wrong data block header
187  return ;
188  }
189 
190  //StoreArray<TRGCDCT3DUnpackerStore> storeAry;
191  for (int clk = 0; clk < nClks; clk++) { // 0..47
192 
193  m_store.appendNew();
194  int ntups = m_store.getEntries() - 1;
195  int* bitArray[nLeafs_2dfitter + nLeafsExtra];
196  setLeafPointersArray_2dfitter(m_store[ntups], bitArray);
197  for (int l = 0; l < nLeafs_2dfitter + nLeafsExtra; l++) *bitArray[l] = 0;
198 
199  m_store[ntups]->m_evt = evt;
200  m_store[ntups]->m_clk = clk;
201  m_store[ntups]->m_firmid = buf[0];
202  m_store[ntups]->m_firmver = buf[1];
203 
205  //cout<<"nClks: "<<nClks<<endl;
206  //cout<<"Up,Left is MSB, Down,Right is LSB"<<endl;
207  //for (unsigned _wd = 0; _wd < nBits / 32 + nword_header; _wd++)
208  //{
209  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd]);
210  // stringstream wd_s;
211  // wd_s << setfill('0') << setw(2) << _wd;
212  // stringstream wd_s_d;
213  // wd_s_d << setfill('0') << setw(2) << _wd-nword_header;
214  // if (_wd < nword_header) cout<<"clk["<<clk<<"] hd["<<wd_s.str()<<"] "<<buf_b<<endl;
215  // else cout<<"clk["<<clk<<"] wd["<<wd_s_d.str()<<"] "<<buf_b<<endl;
216  //}
217 
218  //cout<<"nClks: "<<nClks<<endl;
219  //for (int _wd = 0; _wd < nBits / 32; _wd++)
220  //{
221  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd + nword_header]);
222  // cout<<"clk["<<clk<<"] wd["<<_wd<<"] "<<buf_b<<endl;
223  //}
224 
225  for (unsigned _wd = 0; _wd < nBits_2k / 32; _wd++) { // 0..19
226  unsigned wd = buf[clk * (nBits_2k / 32) + _wd + nword_header];
227  for (int bb = 0; bb < 32; bb++) { // bit by bit
228  if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
229  int bitPosition = (nBits_2k - 1) - _wd * 32 - bb;
230  for (int leaf = 0; // Find a leaf that covers the bit.
231  leaf < nLeafs_2dfitter; leaf++) {
232  int bitMaxOfTheLeaf = BitMap_2dfitter[leaf][0];
233  int bitWidOfTheLeaf = BitMap_2dfitter[leaf][1];
234  int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
235  if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
236  *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
237  }
238  }
239  }
240  }
241  }
242  }
243 }
244 
245 
247 {
248 
249  const unsigned nword_header = 3; // updated from 2 to 3
250 
251  long dataHeader = buf[nword_header] & 0xffff0000;
252  if (dataHeader != 0xdddd0000) {
253  // wrong data block header
254  return ;
255  }
256 
257  //StoreArray<TRGCDCT3DUnpackerStore> storeAry;
258  for (int clk = 0; clk < nClks; clk++) { // 0..47
259 
260  m_store.appendNew();
261  int ntups = m_store.getEntries() - 1;
262  int* bitArray[nLeafs_2624 + nLeafsExtra];
263  setLeafPointersArray_2624(m_store[ntups], bitArray);
264  for (int l = 0; l < nLeafs_2624 + nLeafsExtra; l++) *bitArray[l] = 0;
265 
266  m_store[ntups]->m_evt = evt;
267  m_store[ntups]->m_clk = clk;
268  m_store[ntups]->m_firmid = buf[0];
269  m_store[ntups]->m_firmver = buf[1];
270 
272  //cout<<"nClks: "<<nClks<<endl;
273  //cout<<"Up,Left is MSB, Down,Right is LSB"<<endl;
274  //for (unsigned _wd = 0; _wd < nBits / 32 + nword_header; _wd++)
275  //{
276  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd]);
277  // stringstream wd_s;
278  // wd_s << setfill('0') << setw(2) << _wd;
279  // stringstream wd_s_d;
280  // wd_s_d << setfill('0') << setw(2) << _wd-nword_header;
281  // if (_wd < nword_header) cout<<"clk["<<clk<<"] hd["<<wd_s.str()<<"] "<<buf_b<<endl;
282  // else cout<<"clk["<<clk<<"] wd["<<wd_s_d.str()<<"] "<<buf_b<<endl;
283  //}
284 
285  //cout<<"nClks: "<<nClks<<endl;
286  //for (int _wd = 0; _wd < nBits / 32; _wd++)
287  //{
288  // bitset<32> buf_b(buf[clk * (nBits / 32) + _wd + nword_header]);
289  // cout<<"clk["<<clk<<"] wd["<<_wd<<"] "<<buf_b<<endl;
290  //}
291 
292  for (unsigned _wd = 0; _wd < nBits_2624 / 32; _wd++) { // 0..19
293  unsigned wd = buf[clk * (nBits_2624 / 32) + _wd + nword_header];
294  for (int bb = 0; bb < 32; bb++) { // bit by bit
295  if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
296  int bitPosition = (nBits_2624 - 1) - _wd * 32 - bb;
297  for (int leaf = 0; // Find a leaf that covers the bit.
298  leaf < nLeafs_2624; leaf++) {
299  int bitMaxOfTheLeaf = BitMap_2624[leaf][0];
300  int bitWidOfTheLeaf = BitMap_2624[leaf][1];
301  int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
302  if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
303  *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
304  }
305  }
306  }
307  }
308  }
309  }
310 }
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.
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.