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