Belle II Software  release-08-01-10
TrgBit.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 #include <cstdio>
9 #include <trg/gdl/TrgBit.h>
10 #include <framework/datastore/StoreObjPtr.h>
11 
12 using namespace Belle2;
13 
14 std::string
15 TrgBit::version(void) const
16 {
17  return "20180623";
18 }
19 
20 std::string
22 {
23  return _ftdlVersion[nconf_ftdl];
24 }
25 
27  : _exp(0),
28  _run(0),
29  nconf_psnm(0),
30  nconf_ftdl(0),
31  nconf_input(0),
32  _isFiredFilled(false)
33 {
34 
36  _exp = bevt->getExperiment();
37  _run = bevt->getRun();
38 
39  // set nconf_ftdl, nconf_psnm, nconf_input, n_input, n_output
40  mapNumber(_exp, _run);
41 
43  if (trgsum.isValid()) {
44  for (unsigned i = 0; i < 6; i++) {
45  unsigned i32b = trgsum->getInputBits(i);
46  unsigned f32b = trgsum->getFtdlBits(i);
47  unsigned p32b = trgsum->getPsnmBits(i);
48  _input.set(i32b, i);
49  _ftdl.set(f32b, i);
50  _psnm.set(p32b, i);
51  for (unsigned j = 0; j < 32; j++) {
52  if (j + i * 32 < n_input)
53  _itdVector.push_back((i32b & (1 << j)) ? 1 : 0);
54  if (j + i * 32 < n_output) {
55  _ftdVector.push_back((f32b & (1 << j)) ? 1 : 0);
56  _psnVector.push_back((p32b & (1 << j)) ? 1 : 0);
57  }
58  }
59  }
60  timtype = trgsum->getTimType();
61  _isFiredFilled = true;
62  }
63 }
64 
66 {
67 }
68 
69 bool
70 TrgBit::isFired(const char* bitname) const
71 {
72  for (unsigned i = 0; i < N_BITS_RESERVED; i++) {
73  if (! strcmp(_inputBitNames[i], bitname)) {
74  return isFired((input) i);
75  }
76  }
77  for (unsigned i = 0; i < N_BITS_RESERVED; i++) {
78  if (! strcmp(_outputBitNames[i], bitname)) {
79  return isFired((output) i);
80  }
81  }
82  return false;
83 }
84 
85 bool
86 TrgBit::isFired(input a) const
87 {
88  unsigned bit = _inputMap[nconf_input][a];
89  if (bit == 999) return false;
90  return _input.isFired(bit);
91 }
92 
93 bool
94 TrgBit::isFiredInput(input a) const
95 {
96  unsigned bit = _inputMap[nconf_input][a];
97  if (bit == 999) return false;
98  return _input.isFired(bit);
99 }
100 
101 bool
102 TrgBit::isFired(output a) const
103 {
104  unsigned bit = _outputMap[nconf_ftdl][a];
105  if (bit == 999) return false;
106  return _ftdl.isFired(bit);
107 }
108 
109 bool
110 TrgBit::isFiredFtdl(output a) const
111 {
112  unsigned bit = _outputMap[nconf_ftdl][a];
113  if (bit == 999) return false;
114  return _ftdl.isFired(bit);
115 }
116 
117 bool
118 TrgBit::isFiredInput(unsigned ith_bit) const
119 {
120  return _input.isFired(ith_bit);
121 }
122 
123 bool
124 TrgBit::isFiredInput(const char* bitname) const
125 {
126  unsigned bit = getInputBitNum(bitname);
127  if (bit == 999) return false;
128  return _input.isFired(bit);
129 }
130 
131 bool
132 TrgBit::isFiredFtdl(unsigned ith_bit) const
133 {
134  return _ftdl.isFired(ith_bit);
135 }
136 
137 bool
138 TrgBit::isFiredFtdl(const char* bitname) const
139 {
140  unsigned bit = getOutputBitNum(bitname);
141  if (bit == 999) return false;
142  return _ftdl.isFired(bit);
143 }
144 
145 bool
146 TrgBit::isFiredPsnm(output a) const
147 {
148  unsigned bit = _outputMap[nconf_ftdl][a];
149  if (bit == 999) return false;
150  return _psnm.isFired(bit);
151 }
152 
153 bool
154 TrgBit::isFiredPsnm(const char* bitname) const
155 {
156  unsigned bit = getOutputBitNum(bitname);
157  if (bit == 999) return false;
158  return _psnm.isFired(bit);
159 }
160 
161 bool
162 TrgBit::isFiredPsnm(unsigned ith_bit) const
163 {
164  return _psnm.isFired(ith_bit);
165 }
166 
169 {
170  return timtype;
171 }
172 
173 unsigned
174 TrgBit::preScaleValue(output a) const
175 {
176  if (_outputMap[nconf_ftdl][a] == 999) return 0;
177  return _psnmValues[nconf_psnm][_outputMap[nconf_ftdl][a]];
178 }
179 
180 unsigned
181 TrgBit::preScaleValue(unsigned i) const
182 {
183  return _psnmValues[nconf_psnm][i];
184 }
185 
186 void
187 TrgBit::InputBitPattern::set(unsigned a, unsigned b)
188 {
189  _pattern[b] = a;
190 }
191 
192 void
193 TrgBit::OutputBitPattern::set(unsigned a, unsigned b)
194 {
195  _pattern[b] = a;
196 }
197 
198 bool
200 {
201  unsigned wd = bit / 32;
202  unsigned position = bit % 32;
203  return (_pattern[wd] >> position) & 1;
204 }
205 
206 bool
208 {
209  unsigned wd = bit / 32;
210  unsigned position = bit % 32;
211  return (_pattern[wd] >> position) & 1;
212 }
213 
214 int
216 {
217  if (a >= 32 * N_INPUT_ARRAY) return 0;
218  const unsigned i = a / 32;
219  const unsigned j = a % 32;
220 
221  if ((_pattern[i] >> j) & 1) return 1;
222  return 0;
223 }
224 
225 int
227 {
228  if (a >= 32 * N_OUTPUT_ARRAY) return 0;
229  const unsigned i = a / 32;
230  const unsigned j = a % 32;
231 
232  if ((_pattern[i] >> j) & 1) return 1;
233  return 0;
234 }
235 
236 const char*
237 TrgBit::getInputBitName(unsigned ith_bit) const
238 {
239  for (unsigned i = 0; i < N_BITS_RESERVED; i++) {
240  unsigned j = _inputMap[nconf_input][i];
241  if (ith_bit == j) return _inputBitNames[i];
242  }
243  return "N/A";
244 }
245 
246 const char*
247 TrgBit::getOutputBitName(unsigned ith_bit) const
248 {
249  for (unsigned i = 0; i < N_BITS_RESERVED; i++) {
250  unsigned j = _outputMap[nconf_ftdl][i];
251  if (ith_bit == j) return _outputBitNames[i];
252  }
253  return "N/A";
254 }
255 
256 void
258 {
259  for (unsigned i = 0; i < n_output; i++) {
260  for (unsigned j = 0; j < N_BITS_RESERVED; j++) {
261  unsigned k = _outputMap[nconf_ftdl][j];
262  if (i == k) {
263  printf("%3u %10s %d\n", i, _outputBitNames[j], _psnmValues[nconf_psnm][i]);
264  break;
265  }
266  }
267  }
268 }
269 
270 void
271 TrgBit::printConf(void) const
272 {
273  printf("TrgBit class: exp(%u), run(%u), nconf_psnm(%u), nconf_ftdl(%u), nconf_input(%u), n_input(%u), n_output(%u)\n", _exp, _run,
274  nconf_psnm, nconf_ftdl, nconf_input, n_input, n_output);
275 }
276 
277 int
278 TrgBit::getBitNum(const char* bitname) const
279 {
280  int inum = getInputBitNum(bitname);
281  if (inum == 999) {
282  return -getOutputBitNum(bitname) - 1;
283  } else {
284  return inum;
285  }
286 }
287 
288 unsigned
289 TrgBit::getInputBitNum(const char* bitname) const
290 {
291  for (unsigned i = 0; i < N_BITS_RESERVED; i++) {
292  if (! strcmp(_inputBitNames[i], bitname)) {
293  return _inputMap[nconf_input][i];
294  }
295  }
296  return 999;
297 }
298 
299 unsigned
300 TrgBit::getOutputBitNum(const char* bitname) const
301 {
302  for (unsigned i = 0; i < N_BITS_RESERVED; i++) {
303  if (! strcmp(_outputBitNames[i], bitname)) {
304  return _outputMap[nconf_ftdl][i];
305  }
306  }
307  return 999;
308 }
309 
310 bool
311 TrgBit::isUsed(input a) const
312 {
313  unsigned bit = _inputMap[nconf_input][a];
314  if (bit == 999) return false;
315  return true;
316 }
317 
318 bool
319 TrgBit::isUsed(output a) const
320 {
321  unsigned bit = _outputMap[nconf_ftdl][a];
322  if (bit == 999) return false;
323  return true;
324 }
325 
326 bool
327 TrgBit::isUsed(const char* bitname) const
328 {
329  if (getInputBitNum(bitname) != 999) {
330  return true;
331  } else if (getOutputBitNum(bitname) != 999) {
332  return true;
333  }
334  return false;
335 }
336 
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:111
ETimingType
types of trigger timing source defined in b2tt firmware
Definition: TRGSummary.h:43
int operator[](unsigned)
Bit.
Definition: TrgBit.cc:215
bool isFired(unsigned bit) const
get fired or not
Definition: TrgBit.cc:199
unsigned _pattern[6]
hit pattern
Definition: TrgBit.h:71
void set(unsigned pattern, unsigned wordPosition)
reads/sets a bit.
Definition: TrgBit.cc:187
int operator[](unsigned)
Bit.
Definition: TrgBit.cc:226
bool isFired(unsigned bit) const
get fired or not
Definition: TrgBit.cc:207
void set(unsigned pattern, unsigned wordPosition)
reads/sets a bit.
Definition: TrgBit.cc:193
const char * getInputBitName(unsigned ith_bit) const
returns bit name
Definition: TrgBit.cc:237
std::vector< unsigned > _itdVector
hit information in vector
Definition: TrgBit.h:220
bool isFired(output bitname) const
returns true if the psnm bit is fired.
Definition: TrgBit.cc:102
bool isUsed(input a) const
Whether the bit exists for the run.
Definition: TrgBit.cc:311
std::string version(void) const
returns TrgBit version;
Definition: TrgBit.cc:15
std::string versionFTDL(void) const
returns FTDL version;
Definition: TrgBit.cc:21
int getBitNum(const char *bitname) const
returns bit number for the exprun, if >=0 it is input_bitnum if <0 it is -output_bitnum-1
Definition: TrgBit.cc:278
unsigned getOutputBitNum(const char *bitname) const
returns bit number
Definition: TrgBit.cc:300
virtual ~TrgBit()
Destructor.
Definition: TrgBit.cc:65
unsigned getInputBitNum(const char *bitname) const
returns bit number
Definition: TrgBit.cc:289
void printConf(void) const
print configuration values
Definition: TrgBit.cc:271
unsigned preScaleValue(output A) const
returns pre-scale value.
Definition: TrgBit.cc:174
TrgBit()
Constructor.
Definition: TrgBit.cc:26
void printPreScaleValues(void) const
print prescale values
Definition: TrgBit.cc:257
TRGSummary::ETimingType getTimingSource(void) const
returns timing source
Definition: TrgBit.cc:168
Abstract base class for different kinds of events.