Belle II Software  release-05-01-25
trgcdctsfUnpackerModule.cc
1 //---------------------------------------------------------------
2 // $Id$
3 //---------------------------------------------------------------
4 // Filename : trgcdctsfUnpackerModule.cc
5 // Section : TRG CDCTSF
6 // Owner :
7 // Email :
8 //---------------------------------------------------------------
9 // Description : TRG CDCTSF Unpacker Module
10 //---------------------------------------------------------------
11 // 1.00 : 2017/07/26 : First version
12 //---------------------------------------------------------------
13 
14 #include <trg/cdc/modules/trgcdctsfUnpacker/trgcdctsfUnpackerModule.h>
15 #include <bitset>
16 
17 using namespace std;
18 using namespace Belle2;
19 using namespace TRGCDCTSF;
20 
22 REG_MODULE(TRGCDCTSFUnpacker);
23 
24 string TRGCDCTSFUnpackerModule::version() const
25 {
26  return string("1.00");
27 }
28 
29 TRGCDCTSFUnpackerModule::TRGCDCTSFUnpackerModule()
30  : Module::Module()
31 {
32 
33  string desc = "TRGCDCTSFUnpackerModule(" + version() + ")";
34  setDescription(desc);
36  addParam("TSFMOD", m_TSFMOD,
37  "TSF module number",
38  0);
39 
40 
41 
42  B2DEBUG(20, "trgcdctsfunpacker: Constructor done.");
43 
44 
45 }
46 
48 {
49 }
50 
52 {
53 }
54 
56 {
57  char c_name[100];
58  sprintf(c_name, "TRGCDCTSFUnpackerStore%d", m_TSFMOD);
59  storeAry.registerInDataStore(c_name);
60 
62  _exp = bevt->getExperiment();
63  _run = bevt->getRun();
64 
65  //set copper address
66  if (m_TSFMOD == 0) {
67  m_copper_address = 0x11000007;
68  m_copper_ab = 0;
69  } else if (m_TSFMOD == 1) {
70  if (_exp > 7 || (_exp == 7 && _run > 4023)) {
71  m_copper_address = 0x11000009;
72  m_copper_ab = 0;
73  } else {
74  m_copper_address = 0x11000007;
75  m_copper_ab = 1;
76  }
77  } else if (m_TSFMOD == 2) {
78  m_copper_address = 0x11000008;
79  m_copper_ab = 0;
80  } else if (m_TSFMOD == 3) {
81  m_copper_address = 0x11000008;
82  m_copper_ab = 1;
83  } else if (m_TSFMOD == 4) {
84  if (_exp > 7 || (_exp == 7 && _run > 4023)) {
85  m_copper_address = 0x11000007;
86  m_copper_ab = 1;
87  } else {
88  m_copper_address = 0x11000009;
89  m_copper_ab = 0;
90  }
91  } else if (m_TSFMOD == 5) {
92  m_copper_address = 0x11000009;
93  m_copper_ab = 1;
94  } else if (m_TSFMOD == 6) {
95  m_copper_address = 0x1100000a;
96  m_copper_ab = 0;
97  } else {
98  B2ERROR("trgcdctsfunpacker:cooper address is not set");
99  m_copper_address = 0;
100  m_copper_ab = 0;
101  }
102 
103 
104  //set bitmap
105  if (m_TSFMOD == 0 || m_TSFMOD == 4 || m_TSFMOD == 6) {
106  m_nBits = nBits_2k;
107  m_nword = nword_2k;
108  for (int i = 0; i < nLeafs; i++) {
109  for (int j = 0; j < 2; j++) {
110  //m_BitMap[i][j] = BitMap_2k[i][j];
111  }
112  }
113  } else if (m_TSFMOD == 1 || m_TSFMOD == 2 || m_TSFMOD == 3 || m_TSFMOD == 5) {
114  m_nBits = nBits_4k;
115  m_nword = nword_4k;
116  for (int i = 0; i < nLeafs; i++) {
117  for (int j = 0; j < 2; j++) {
118  //m_BitMap[i][j] = BitMap_4k[i][j];
119  }
120  }
121  } else {
122  B2ERROR("trgcdctsfunpacker:cooper address is not set");
123  m_nBits = 0;
124  m_nword = 0;
125  for (int i = 0; i < nLeafs; i++) {
126  for (int j = 0; j < 2; j++) {
127  //m_BitMap[i][j] = 0;
128  }
129  }
130  }
131 
132 }
133 
135 {
136 }
137 
139 {
140 }
141 
143 {
144  StoreArray<RawTRG> raw_trgarray;
145  for (int i = 0; i < raw_trgarray.getEntries(); i++) {
146  for (int j = 0; j < raw_trgarray[i]->GetNumEntries(); j++) {
147  if (raw_trgarray[i]->GetNodeID(j) == m_copper_address) {
148  if (raw_trgarray[i]->GetDetectorNwords(j, m_copper_ab) == m_nword) {
149  // get the firm_vers beforehand to know 10 or 15 TS version
150  int firm_vers = (raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab))[1];
151  // condition for 15 TS version:
152  // TSF1: X"19041805" or newer than X"19052105"
153  // TSF3: X"19041805" or newer than X"19052105"
154  // TSF5: X"19041901" or newer than X"19061105"
155  if (m_TSFMOD == 1 && (firm_vers == 0x19041805 || firm_vers > 0x19052105)) {
156  fillTreeCDCTSF_4k15ts(raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab), raw_trgarray[j]->GetEveNo(j));
157  } else if (m_TSFMOD == 3 && (firm_vers == 0x19041805 || firm_vers > 0x19052105)) {
158  fillTreeCDCTSF_4k15ts(raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab), raw_trgarray[j]->GetEveNo(j));
159  } else if (m_TSFMOD == 5 && (firm_vers == 0x19041901 || firm_vers > 0x19061105)) {
160  fillTreeCDCTSF_4k15ts(raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab), raw_trgarray[j]->GetEveNo(j));
161  } else {
162  fillTreeCDCTSF(raw_trgarray[i]->GetDetectorBuffer(j, m_copper_ab), raw_trgarray[j]->GetEveNo(j));
163  }
164  }
165  }
166  }
167  }
168 }
169 
171 {
172 
173  const unsigned nword_header = 3;
174 
175  for (int clk = 0; clk < nClks; clk++) { // 0..47
176 
177  storeAry.appendNew();
178  int ntups = storeAry.getEntries() - 1;
179  int* bitArray[nLeafs + nLeafsExtra];
180  setLeafPointersArray(storeAry[ntups], bitArray);
181  for (int l = 0; l < nLeafs + nLeafsExtra; l++) *bitArray[l] = 0;
182 
183  storeAry[ntups]->m_evt = evt;
184  storeAry[ntups]->m_clk = clk;
185  storeAry[ntups]->m_firmid = buf[0];
186  storeAry[ntups]->m_firmver = buf[1];
187  storeAry[ntups]->m_N2DTS = 10;
188 
189 
190  for (int _wd = 0; _wd < m_nBits / 32; _wd++) { // 0..19
191  int wd = buf[clk * (m_nBits / 32) + _wd + nword_header];
192  bitset<32> bwd(wd);
193  for (int bb = 0; bb < 32; bb++) { // bit by bit
194  if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
195  int bitPosition = (m_nBits - 1) - _wd * 32 - bb;
196  for (int leaf = 0; // Find a leaf that covers the bit.
197  leaf < nLeafs; leaf++) {
198  //int bitMaxOfTheLeaf = m_BitMap[leaf][0];
199  //int bitWidOfTheLeaf = m_BitMap[leaf][1];
200  int bitMaxOfTheLeaf = 0 ;
201  if (m_nword == nword_2k) { bitMaxOfTheLeaf = BitMap_2k[leaf][0]; }
202  else {bitMaxOfTheLeaf = BitMap_4k[leaf][0];}
203 
204  int bitWidOfTheLeaf = 0 ;
205  if (m_nword == nword_2k) { bitWidOfTheLeaf = BitMap_2k[leaf][1]; }
206  else {bitWidOfTheLeaf = BitMap_4k[leaf][1];}
207 
208  int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
209  if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
210  *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
211  }
212  }
213  }
214  }
215  }
216  }
217 }
218 
220 {
221 
222  const unsigned nword_header = 3;
223 
224  for (int clk = 0; clk < nClks; clk++) { // 0..47
225 
226  storeAry.appendNew();
227  int ntups = storeAry.getEntries() - 1;
228  int* bitArray[nLeafs_4k15ts + nLeafsExtra];
229  setLeafPointersArray_4k15ts(storeAry[ntups], bitArray);
230  for (int l = 0; l < nLeafs_4k15ts + nLeafsExtra; l++) *bitArray[l] = 0;
231 
232  storeAry[ntups]->m_evt = evt;
233  storeAry[ntups]->m_clk = clk;
234  storeAry[ntups]->m_firmid = buf[0];
235  storeAry[ntups]->m_firmver = buf[1];
236  storeAry[ntups]->m_N2DTS = 15;
237 
238 
239  for (int _wd = 0; _wd < m_nBits / 32; _wd++) { // 0..19
240  int wd = buf[clk * (m_nBits / 32) + _wd + nword_header];
241  bitset<32> bwd(wd);
242  for (int bb = 0; bb < 32; bb++) { // bit by bit
243  if ((wd >> (31 - bb)) & 1) { /* MSB to LSB */
244  int bitPosition = (m_nBits - 1) - _wd * 32 - bb;
245  for (int leaf = 0; // Find a leaf that covers the bit.
246  leaf < nLeafs_4k15ts; leaf++) {
247  int bitMaxOfTheLeaf = BitMap_4k15ts[leaf][0];
248  int bitWidOfTheLeaf = BitMap_4k15ts[leaf][1];
249  int bitMinOfTheLeaf = bitMaxOfTheLeaf - bitWidOfTheLeaf;
250  if (bitMinOfTheLeaf <= bitPosition && bitPosition <= bitMaxOfTheLeaf) {
251  *bitArray[leaf] |= (1 << (bitPosition - bitMinOfTheLeaf));
252  }
253  }
254  }
255  }
256  }
257  }
258 }
259 
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::version
std::string version() const
returns version of TRGCDCTSFUnpackerModule.
Definition: trgcdctsfUnpackerModule.cc:24
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::m_copper_address
unsigned int m_copper_address
address of copper module
Definition: trgcdctsfUnpackerModule.h:1882
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::fillTreeCDCTSF
virtual void fillTreeCDCTSF(int *buf, int evt)
Unpacker main function.
Definition: trgcdctsfUnpackerModule.cc:170
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module::c_ParallelProcessingCertified
@ 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:82
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::storeAry
StoreArray< TRGCDCTSFUnpackerStore > storeAry
StoreArray of TRGCDCTSFUnpackerStore.
Definition: trgcdctsfUnpackerModule.h:1872
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::m_copper_ab
unsigned int m_copper_ab
address of copper module
Definition: trgcdctsfUnpackerModule.h:1884
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::beginRun
virtual void beginRun() override
Called when new run started.
Definition: trgcdctsfUnpackerModule.cc:134
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::endRun
virtual void endRun() override
Called when run ended.
Definition: trgcdctsfUnpackerModule.cc:138
Belle2::Module::setPropertyFlags
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:210
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::terminate
virtual void terminate() override
Called when processing ended.
Definition: trgcdctsfUnpackerModule.cc:51
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::_run
unsigned _run
run number
Definition: trgcdctsfUnpackerModule.h:1892
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::m_nword
int m_nword
number of word
Definition: trgcdctsfUnpackerModule.h:1879
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::m_TSFMOD
int m_TSFMOD
TSF module number.
Definition: trgcdctsfUnpackerModule.h:1887
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::_exp
unsigned _exp
exp number
Definition: trgcdctsfUnpackerModule.h:1890
Belle2::Module::addParam
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:562
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::m_nBits
int m_nBits
bitmap
Definition: trgcdctsfUnpackerModule.h:1877
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::~TRGCDCTSFUnpackerModule
virtual ~TRGCDCTSFUnpackerModule()
Destructor.
Definition: trgcdctsfUnpackerModule.cc:47
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::event
virtual void event() override
Called event by event.
Definition: trgcdctsfUnpackerModule.cc:142
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::initialize
virtual void initialize() override
Initilizes TRGCDCTSFUnpackerModuel.
Definition: trgcdctsfUnpackerModule.cc:55
Belle2::TRGCDCTSF::TRGCDCTSFUnpackerModule::fillTreeCDCTSF_4k15ts
virtual void fillTreeCDCTSF_4k15ts(int *buf, int evt)
Unpacker main function for 4k, 15 TS version.
Definition: trgcdctsfUnpackerModule.cc:219