EventSelWildcard_t.cpp
Go to the documentation of this file.
6 
7 #include <bitset>
8 #include <iostream>
9 #include <string>
10 #include <vector>
11 
12 using namespace art;
13 using namespace fhicl;
14 using namespace std;
15 using art::PathSpec;
16 
17 constexpr size_t numBits = 12; // There must be a better way than this but I
18  // choose to avoid modifying a whole slew of code
19  // using the array instead of push_back()s.
20 constexpr size_t numPatterns = 12;
21 constexpr size_t numTestMasks = 9;
22 
23 typedef std::vector<std::vector<bool>> Answers;
24 
25 typedef std::vector<string> Strings;
26 typedef std::vector<Strings> VStrings;
27 typedef std::vector<std::bitset<numBits>> VBools;
28 
29 std::ostream&
30 operator<<(std::ostream& ost, const Strings& strings)
31 {
32  for (auto const& element : strings) {
33  ost << element << " ";
34  }
35  return ost;
36 }
37 
38 void
39 testone(const Strings& paths,
40  const Strings& pattern,
41  const std::bitset<numBits>& mask,
42  bool answer,
43  int jmask)
44 {
45  EventSelector selector{pattern};
46 
47  int number_of_trigger_paths = 0;
48  std::vector<unsigned char> bitArray;
49 
50  HLTGlobalStatus bm(mask.size());
54  HLTPathStatus const ready{art::hlt::Ready};
55 
56  for (unsigned int b = 0; b < mask.size(); ++b) {
57  bm.at(b) = (mask[b] ? pass : fail);
58 
59  // There is an alternate version of the function acceptEvent
60  // that takes an array of characters as an argument instead
61  // of a TriggerResults object. These next few lines build
62  // that array so we can test that also.
63  if ((number_of_trigger_paths % 4) == 0)
64  bitArray.push_back(0);
65  int byteIndex = number_of_trigger_paths / 4;
66  int subIndex = number_of_trigger_paths % 4;
67  bitArray[byteIndex] |= (mask[b] ? art::hlt::Pass : art::hlt::Fail)
68  << (subIndex * 2);
69  ++number_of_trigger_paths;
70  }
71 
72  if (jmask == 8 && mask.size() > 4) {
73  bm.at(0) = ready;
74  bm.at(4) = ex;
75  bitArray[0] = (bitArray[0] & 0xfc) | art::hlt::Ready;
76  bitArray[1] = (bitArray[1] & 0xfc) | art::hlt::Exception;
77  }
78 
79  ParameterSet trigger_pset;
80  trigger_pset.put<Strings>("trigger_paths", paths);
81  ParameterSetRegistry::put(trigger_pset);
82 
83  TriggerResults const results_id{bm, trigger_pset.id()};
84  bool const result = selector.acceptEvent(ScheduleID::first(), results_id);
85  if (result != answer) {
86  std::cerr << "failed to compare pattern with mask using pset ID: "
87  << "correct=" << answer << " "
88  << "results=" << std::boolalpha << result << '\n'
89  << "pattern=" << pattern << "\n"
90  << "mask=" << mask << "\n"
91  << "jmask = " << jmask << "\n";
92  abort();
93  }
94 }
95 
96 void
97 testall(const Strings& paths,
98  const VStrings& patterns,
99  const VBools& masks,
100  const Answers& answers)
101 {
102  for (unsigned int i = 0; i < patterns.size(); ++i) {
103  for (unsigned int j = 0; j < masks.size(); ++j) {
104  testone(paths, patterns[i], masks[j], answers[i][j], j);
105  }
106  }
107 }
108 
109 int
111 {
112  Strings const paths{"HLTx1",
113  "HLTx2",
114  "HLTy1",
115  "HLTy2",
116  "CALIBx1",
117  "CALIBx2",
118  "CALIBy1",
119  "CALIBy2",
120  "DEBUGx1",
121  "DEBUGx2",
122  "DEBUGy1",
123  "DEBUGy2"};
124  assert(size(paths) == numBits);
125 
126  // Create our test patterns. Each of these will be tested against each mask.
127 
128  VStrings patterns(numPatterns);
129  patterns[0] = {"*"};
130  patterns[1] = {"!*"};
131  patterns[2] = {"HLTx1", "HLTy1"};
132  patterns[3] = {"CALIBx2", "!HLTx2"};
133  patterns[4] = {"HLT*"};
134  patterns[5] = {"!HLT*"};
135  patterns[6] = {"DEBUG*1", "HLT?2"};
136  patterns[7] = {"D*x1", "CALIBx*"};
137  patterns[8] = {"HL*1", "C?LIB*2"};
138  patterns[9] = {"H*x1"};
139  patterns[10] = {"!H*x1"};
140  patterns[11] = {"C?LIB*2"};
141 
142  auto to_bits = [](std::string bit_string) {
143  // The provided string assumes that the first character corresponds to
144  // index 0 of the bitset. However, this is the opposite convention that
145  // std::bitset uses. We therefore reverse the characters.
146  std::reverse(begin(bit_string), end(bit_string));
147  return std::bitset<numBits>{bit_string};
148  };
149 
150  VBools testmasks(numTestMasks);
151  testmasks[0] = to_bits("000000000000");
152  testmasks[1] = to_bits("111111111111");
153  testmasks[2] = to_bits("100000000000");
154  testmasks[3] = to_bits("010000000000");
155  testmasks[4] = to_bits("000000001000");
156  testmasks[5] = to_bits("111100100000");
157  testmasks[6] = to_bits("000001000010");
158  testmasks[7] = to_bits("101001100101");
159  testmasks[8] =
160  to_bits("000001001111"); // For j=8 only, the first HLTx1 (false)
161  // is reset to ready and the fifth
162  // CALIBx2 (true) is reset to exception.
163  // Create the answers
164 
165  Answers ans;
166 
167  std::vector<bool> ansstar; // Answers for criteria star: {{ "*" }};
168  ansstar.push_back(false); // f f f f f f f f f f f f
169  ansstar.push_back(true); // t t t t t t t t t t t t
170  ansstar.push_back(true); // t f f f f f f f f f f f
171  ansstar.push_back(true); // f t f f f f f f f f f f
172  ansstar.push_back(true); // f f f f f f f f t f f f
173  ansstar.push_back(true); // t t t t f f t f f f f f
174  ansstar.push_back(true); // f f f f f t f f f f t f
175  ansstar.push_back(true); // t f f f f t t f f t f t
176  ansstar.push_back(true); // r f f f e t f f t t t t
177 
178  ans.push_back(ansstar);
179 
180  std::vector<bool> ansnotstar; // Answers for criteria notstar: {{ "!*" }};
181  ansnotstar.push_back(true); // f f f f f f f f f f f f
182  ansnotstar.push_back(false); // t t t t t t t t t t t t
183  ansnotstar.push_back(false); // t f f f f f f f f f f f
184  ansnotstar.push_back(false); // f t f f f f f f f f f f
185  ansnotstar.push_back(false); // f f f f f f f f t f f f
186  ansnotstar.push_back(false); // t t t t f f t f f f f f
187  ansnotstar.push_back(false); // f f f f f t f f f f t f
188  ansnotstar.push_back(false); // t f f f f t t f f t f t
189  ansnotstar.push_back(false); // r f f f e t f f t t t t
190 
191  ans.push_back(ansnotstar);
192 
193  std::vector<bool> ans0; // Answers for criteria 0:{{ "HLTx1", "HLTy1" }};
194  ans0.push_back(false); // f f f f f f f f f f f f
195  ans0.push_back(true); // t t t t t t t t t t t t
196  ans0.push_back(true); // t f f f f f f f f f f f
197  ans0.push_back(false); // f t f f f f f f f f f f
198  ans0.push_back(false); // f f f f f f f f t f f f
199  ans0.push_back(true); // t t t t f f t f f f f f
200  ans0.push_back(false); // f f f f f t f f f f t f
201  ans0.push_back(true); // t f f f f t t f f t f t
202  ans0.push_back(false); // r f f f e t f f t t t t
203 
204  ans.push_back(ans0);
205 
206  std::vector<bool> ans1; // Answers for criteria 1:{{"CALIBx2","!HLTx2"}};
207  ans1.push_back(true); // f f f f f f f f f f f f
208  ans1.push_back(true); // t t t t t t t t t t t t
209  ans1.push_back(true); // t f f f f f f f f f f f
210  ans1.push_back(false); // f t f f f f f f f f f f
211  ans1.push_back(true); // f f f f f f f f t f f f
212  ans1.push_back(false); // t t t t f f t f f f f f
213  ans1.push_back(true); // f f f f f t f f f f t f
214  ans1.push_back(true); // t f f f f t t f f t f t
215  ans1.push_back(true); // r f f f e t f f t t t t
216 
217  ans.push_back(ans1);
218 
219  std::vector<bool> ans2; // Answers for criteria 2:{{ "HLT*" }};
220  ans2.push_back(false); // f f f f f f f f f f f f
221  ans2.push_back(true); // t t t t t t t t t t t t
222  ans2.push_back(true); // t f f f f f f f f f f f
223  ans2.push_back(true); // f t f f f f f f f f f f
224  ans2.push_back(false); // f f f f f f f f t f f f
225  ans2.push_back(true); // t t t t f f t f f f f f
226  ans2.push_back(false); // f f f f f t f f f f t f
227  ans2.push_back(true); // t f f f f t t f f t f t
228  ans2.push_back(false); // r f f f e t f f t t t t
229 
230  ans.push_back(ans2);
231 
232  std::vector<bool> ans3; // Answers for criteria 3:{{ "!HLT*" }};
233  ans3.push_back(true); // f f f f f f f f f f f f
234  ans3.push_back(false); // t t t t t t t t t t t t
235  ans3.push_back(false); // t f f f f f f f f f f f
236  ans3.push_back(false); // f t f f f f f f f f f f
237  ans3.push_back(true); // f f f f f f f f t f f f
238  ans3.push_back(false); // t t t t f f t f f f f f
239  ans3.push_back(true); // f f f f f t f f f f t f
240  ans3.push_back(false); // t f f f f t t f f t f t
241  ans3.push_back(false); // r f f f e t f f t t t t // ready is not fail
242 
243  ans.push_back(ans3);
244 
245  std::vector<bool> ans4; // Answers for criteria 4:{{"DEBUG*1","HLT?2"}};;
246  ans4.push_back(false); // f f f f f f f f f f f f
247  ans4.push_back(true); // t t t t t t t t t t t t
248  ans4.push_back(false); // t f f f f f f f f f f f
249  ans4.push_back(true); // f t f f f f f f f f f f
250  ans4.push_back(true); // f f f f f f f f t f f f
251  ans4.push_back(true); // t t t t f f t f f f f f
252  ans4.push_back(true); // f f f f f t f f f f t f
253  ans4.push_back(false); // t f f f f t t f f t f t
254  ans4.push_back(true); // r f f f e t f f t t t t
255 
256  ans.push_back(ans4);
257 
258  std::vector<bool> ans5; // Answers for criteria 5:{{ "D*x1", "CALIBx*" }};
259  ans5.push_back(false); // f f f f f f f f f f f f
260  ans5.push_back(true); // t t t t t t t t t t t t
261  ans5.push_back(false); // t f f f f f f f f f f f
262  ans5.push_back(false); // f t f f f f f f f f f f
263  ans5.push_back(true); // f f f f f f f f t f f f
264  ans5.push_back(false); // t t t t f f t f f f f f
265  ans5.push_back(true); // f f f f f t f f f f t f
266  ans5.push_back(true); // t f f f f t t f f t f t
267  ans5.push_back(true); // r f f f e t f f t t t t
268 
269  ans.push_back(ans5);
270 
271  std::vector<bool> ans6; // Answers for criteria 6:{{ "HL*1", "C?LIB*2" }};
272  ans6.push_back(false); // f f f f f f f f f f f f
273  ans6.push_back(true); // t t t t t t t t t t t t
274  ans6.push_back(true); // t f f f f f f f f f f f
275  ans6.push_back(false); // f t f f f f f f f f f f
276  ans6.push_back(false); // f f f f f f f f t f f f
277  ans6.push_back(true); // t t t t f f t f f f f f
278  ans6.push_back(true); // f f f f f t f f f f t f
279  ans6.push_back(true); // t f f f f t t f f t f t
280  ans6.push_back(true); // r f f f e t f f t t t t
281 
282  ans.push_back(ans6);
283 
284  std::vector<bool> ans7; // Answers for criteria7:{{ "H*x1" }};
285  ans7.push_back(false); // f f f f f f f f f f f f
286  ans7.push_back(true); // t t t t t t t t t t t t
287  ans7.push_back(true); // t f f f f f f f f f f f
288  ans7.push_back(false); // f t f f f f f f f f f f
289  ans7.push_back(false); // f f f f f f f f t f f f
290  ans7.push_back(true); // t t t t f f t f f f f f
291  ans7.push_back(false); // f f f f f t f f f f t f
292  ans7.push_back(true); // t f f f f t t f f t f t
293  ans7.push_back(false); // r f f f e t f f t t t t
294 
295  ans.push_back(ans7);
296 
297  std::vector<bool> ans8; // Answers for criteria8:{{ "!H*x1" }};
298  ans8.push_back(true); // f f f f f f f f f f f f
299  ans8.push_back(false); // t t t t t t t t t t t t
300  ans8.push_back(false); // t f f f f f f f f f f f
301  ans8.push_back(true); // f t f f f f f f f f f f
302  ans8.push_back(true); // f f f f f f f f t f f f
303  ans8.push_back(false); // t t t t f f t f f f f f
304  ans8.push_back(true); // f f f f f t f f f f t f
305  ans8.push_back(false); // t f f f f t t f f t f t
306  ans8.push_back(
307  false); // r f f f e t f f t t t t -- false because ready does not
308  // itself cause an accept
309 
310  ans.push_back(ans8);
311 
312  std::vector<bool> ans9; // Answers for criteria 9:{{ "C?LIB*2" }};
313  ans9.push_back(false); // f f f f f f f f f f f f
314  ans9.push_back(true); // t t t t t t t t t t t t
315  ans9.push_back(false); // t f f f f f f f f f f f
316  ans9.push_back(false); // f t f f f f f f f f f f
317  ans9.push_back(false); // f f f f f f f f t f f f
318  ans9.push_back(false); // t t t t f f t f f f f f
319  ans9.push_back(true); // f f f f f t f f f f t f
320  ans9.push_back(true); // t f f f f t t f f t f t
321  ans9.push_back(true); // r f f f e t f f t t t t
322 
323  ans.push_back(ans9);
324 
325  Strings bit_qualified_paths;
326  size_t i = 0;
327  for (auto const& name : paths) {
328  bit_qualified_paths.push_back(std::to_string(i) + ':' + name);
329  }
330 
331  // We are ready to run some tests
332 
333  testall(bit_qualified_paths, patterns, testmasks, ans);
334  return 0;
335 }
static QCString name
Definition: declinfo.cpp:673
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
constexpr size_t numTestMasks
static QCString result
std::string string
Definition: nybbler.cc:12
constexpr size_t numBits
int main()
static constexpr ScheduleID first()
Definition: ScheduleID.h:50
STL namespace.
void testall(const Strings &paths, const VStrings &patterns, const VBools &masks, const Answers &answers)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
std::vector< Bools > VBools
std::vector< std::bitset< numBits > > VBools
constexpr size_t numPatterns
void testone(const Strings &paths, const Strings &pattern, const std::bitset< numBits > &mask, bool answer, int jmask)
HLTPathStatus const pass
HLTPathStatus const fail
ParameterSetID id() const
std::vector< Strings > VStrings
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
Definition: qstring.cpp:11649
std::string pattern
Definition: regex_t.cc:35
static bool * b
Definition: config.cpp:1043
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
std::vector< std::string > Strings
std::vector< string > Strings
std::vector< Strings > VStrings
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
std::vector< std::vector< bool > > Answers
void put(std::string const &key)