Belle II Software  release-06-00-14
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 
12 using namespace std;
13 using namespace Belle2;
14 using namespace TRGCDCTSF;
15 
17 REG_MODULE(TRGCDCTSFUnpacker);
18 
19 string TRGCDCTSFUnpackerModule::version() const
20 {
21  return string("1.00");
22 }
23 
24 TRGCDCTSFUnpackerModule::TRGCDCTSFUnpackerModule()
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  } else if (m_TSFMOD == 1) {
65  if (_exp > 7 || (_exp == 7 && _run > 4023)) {
66  m_copper_address = 0x11000009;
67  m_copper_ab = 0;
68  } else {
69  m_copper_address = 0x11000007;
70  m_copper_ab = 1;
71  }
72  } else if (m_TSFMOD == 2) {
73  m_copper_address = 0x11000008;
74  m_copper_ab = 0;
75  } else if (m_TSFMOD == 3) {
76  m_copper_address = 0x11000008;
77  m_copper_ab = 1;
78  } else if (m_TSFMOD == 4) {
79  if (_exp > 7 || (_exp == 7 && _run > 4023)) {
80  m_copper_address = 0x11000007;
81  m_copper_ab = 1;
82  } else {
83  m_copper_address = 0x11000009;
84  m_copper_ab = 0;
85  }
86  } else if (m_TSFMOD == 5) {
87  m_copper_address = 0x11000009;
88  m_copper_ab = 1;
89  } else if (m_TSFMOD == 6) {
90  m_copper_address = 0x1100000a;
91  m_copper_ab = 0;
92  } else {
93  B2ERROR("trgcdctsfunpacker:cooper address is not set");
94  m_copper_address = 0;
95  m_copper_ab = 0;
96  }
97 
98 
99  //set bitmap
100  if (m_TSFMOD == 0 || m_TSFMOD == 4 || m_TSFMOD == 6) {
101  m_nBits = nBits_2k;
102  m_nword = nword_2k;
103  for (int i = 0; i < nLeafs; i++) {
104  for (int j = 0; j < 2; j++) {
105  //m_BitMap[i][j] = BitMap_2k[i][j];
106  }
107  }
108  } else if (m_TSFMOD == 1 || m_TSFMOD == 2 || m_TSFMOD == 3 || m_TSFMOD == 5) {
109  m_nBits = nBits_4k;
110  m_nword = nword_4k;
111  for (int i = 0; i < nLeafs; i++) {
112  for (int j = 0; j < 2; j++) {
113  //m_BitMap[i][j] = BitMap_4k[i][j];
114  }
115  }
116  } else {
117  B2ERROR("trgcdctsfunpacker:cooper address is not set");
118  m_nBits = 0;
119  m_nword = 0;
120  for (int i = 0; i < nLeafs; i++) {
121  for (int j = 0; j < 2; j++) {
122  //m_BitMap[i][j] = 0;
123  }
124  }
125  }
126 
127 }
128 
130 {
131 }
132 
134 {
135 }
136 
138 {
139  StoreArray<RawTRG> raw_trgarray;
140  for (int i = 0; i < raw_trgarray.getEntries(); i++) {
141  for (int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
142  if (raw_trgarray[i]->GetNodeID(j) == m_copper_address) {
143  if (raw_trgarray[i]->GetDetectorNwords(j, m_copper_ab) == m_nword) {
144  // get the firm_vers beforehand to know 10 or 15 TS version
145  int firm_vers = (raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab))[1];
146  // condition for 15 TS version:
147  // TSF1: X"19041805" or newer than X"19052105"
148  // TSF3: X"19041805" or newer than X"19052105"
149  // TSF5: X"19041901" or newer than X"19061105"
150  if (m_TSFMOD == 1 && (firm_vers == 0x19041805 || firm_vers > 0x19052105)) {
151  fillTreeCDCTSF_4k15ts(raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab), raw_trgarray[j]->GetEveNo(j));
152  } else if (m_TSFMOD == 3 && (firm_vers == 0x19041805 || firm_vers > 0x19052105)) {
153  fillTreeCDCTSF_4k15ts(raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab), raw_trgarray[j]->GetEveNo(j));
154  } else if (m_TSFMOD == 5 && (firm_vers == 0x19041901 || firm_vers > 0x19061105)) {
155  fillTreeCDCTSF_4k15ts(raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab), raw_trgarray[j]->GetEveNo(j));
156  } else {
157  fillTreeCDCTSF(raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab), raw_trgarray[j]->GetEveNo(j));
158  }
159  }
160  }
161  }
162  }
163 }
164 
166 {
167 
168  const unsigned nword_header = 3;
169 
170  for (int clk = 0; clk < nClks; clk++) { // 0..47
171 
172  storeAry.appendNew();
173  int ntups = storeAry.getEntries() - 1;
174  int* bitArray[nLeafs + nLeafsExtra];
175  setLeafPointersArray(storeAry[ntups], bitArray);
176  for (int l = 0; l < nLeafs + nLeafsExtra; l++) *bitArray[l] = 0;
177 
178  storeAry[ntups]->m_evt = evt;
179  storeAry[ntups]->m_clk = clk;
180  storeAry[ntups]->m_firmid = buf[0];
181  storeAry[ntups]->m_firmver = buf[1];
182  storeAry[ntups]->m_N2DTS = 10;
183 
184 
185  for (int _wd = 0; _wd < m_nBits / 32; _wd++) { // 0..19
186  unsigned wd = buf[clk * (m_nBits / 32) + _wd + nword_header];
187  bitset<32> bwd(wd);
188  for (int bb = 0; bb < 32; bb++) { // bit by bit
189  if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
190  int bitPosition = (m_nBits - 1) - _wd * 32 - bb;
191  for (int leaf = 0; // Find a leaf that covers the bit.
192  leaf < nLeafs; leaf++) {
193  //int bitMaxOfTheLeaf = m_BitMap[leaf][0];
194  //int bitWidOfTheLeaf = m_BitMap[leaf][1];
195  int bitMaxOfTheLeaf = 0 ;
196  if (m_nword == nword_2k) { bitMaxOfTheLeaf = BitMap_2k[leaf][0]; }
197  else {bitMaxOfTheLeaf = BitMap_4k[leaf][0];}
198 
199  int bitWidOfTheLeaf = 0 ;
200  if (m_nword == nword_2k) { bitWidOfTheLeaf = BitMap_2k[leaf][1]; }
201  else {bitWidOfTheLeaf = BitMap_4k[leaf][1];}
202 
203  int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
204  if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
205  *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
206  }
207  }
208  }
209  }
210  }
211  }
212 }
213 
215 {
216 
217  const unsigned nword_header = 3;
218 
219  for (int clk = 0; clk < nClks; clk++) { // 0..47
220 
221  storeAry.appendNew();
222  int ntups = storeAry.getEntries() - 1;
223  int* bitArray[nLeafs_4k15ts + nLeafsExtra];
224  setLeafPointersArray_4k15ts(storeAry[ntups], bitArray);
225  for (int l = 0; l < nLeafs_4k15ts + nLeafsExtra; l++) *bitArray[l] = 0;
226 
227  storeAry[ntups]->m_evt = evt;
228  storeAry[ntups]->m_clk = clk;
229  storeAry[ntups]->m_firmid = buf[0];
230  storeAry[ntups]->m_firmver = buf[1];
231  storeAry[ntups]->m_N2DTS = 15;
232 
233 
234  for (int _wd = 0; _wd < m_nBits / 32; _wd++) { // 0..19
235  unsigned wd = buf[clk * (m_nBits / 32) + _wd + nword_header];
236  bitset<32> bwd(wd);
237  for (int bb = 0; bb < 32; bb++) { // bit by bit
238  if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
239  int bitPosition = (m_nBits - 1) - _wd * 32 - bb;
240  for (int leaf = 0; // Find a leaf that covers the bit.
241  leaf < nLeafs_4k15ts; leaf++) {
242  int bitMaxOfTheLeaf = BitMap_4k15ts[leaf][0];
243  int bitWidOfTheLeaf = BitMap_4k15ts[leaf][1];
244  int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
245  if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
246  *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
247  }
248  }
249  }
250  }
251  }
252  }
253 }
254 
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:95
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.
virtual void terminate() override
Called when processing ended.
virtual void beginRun() override
Called when new run started.
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
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.