Typedefs | Functions | Variables
EventSelector_t.cpp File Reference
#include "art/Framework/Core/EventSelector.h"
#include "canvas/Persistency/Common/TriggerResults.h"
#include "fhiclcpp/ParameterSet.h"
#include "fhiclcpp/ParameterSetRegistry.h"
#include <iostream>
#include <string>
#include <vector>

Go to the source code of this file.

Typedefs

typedef bool Answers[numPatterns][numMasks]
 
typedef std::vector< std::stringStrings
 
typedef std::vector< StringsVStrings
 
typedef std::vector< boolBools
 
typedef std::vector< BoolsVBools
 

Functions

std::ostream & operator<< (std::ostream &ost, const Strings &s)
 
std::ostream & operator<< (std::ostream &ost, const Bools &b)
 
void testone (const Strings &paths, const Strings &pattern, const Bools &mask, bool answer, int jmask)
 
void testall (const Strings &paths, const VStrings &patterns, const VBools &masks, const Answers &answers)
 
int main ()
 

Variables

constexpr size_t numBits = 5
 
constexpr int numPatterns = 11
 
constexpr int numMasks = 9
 

Typedef Documentation

Definition at line 18 of file EventSelector_t.cpp.

Definition at line 21 of file EventSelector_t.cpp.

Definition at line 19 of file EventSelector_t.cpp.

Definition at line 22 of file EventSelector_t.cpp.

Definition at line 20 of file EventSelector_t.cpp.

Function Documentation

int main ( void  )

Definition at line 113 of file EventSelector_t.cpp.

114 {
115  Strings const paths{"a1", "a2", "a3", "a4", "a5"};
116  assert(size(paths) == numBits);
117 
118  VStrings patterns(numPatterns);
119  patterns[0] = {"a1", "a2"};
120  patterns[1] = {"!a1", "!a2"};
121  patterns[2] = {"a1", "!a2"};
122  patterns[3] = {"*"};
123  patterns[4] = {"!*"};
124  patterns[5] = {"*", "!*"};
125  patterns[6] = {"*", "!a2"};
126  patterns[7] = {"!*", "a2"};
127  patterns[8] = {"a1", "a2", "a5"};
128  patterns[9] = {"a3", "a4"};
129  patterns[10] = {"!a5"};
130 
131  VBools testmasks(numMasks);
132  testmasks[0] = {true, false, true, false, true};
133  testmasks[1] = {false, true, true, false, true};
134  testmasks[2] = {true, true, true, false, true};
135  testmasks[3] = {false, false, true, false, true};
136  testmasks[4] = {false, false, false, false, false};
137  testmasks[5] = {true, true, true, true, true};
138  testmasks[6] = {true, true, true, true, false};
139  testmasks[7] = {false, false, false, false, true};
140  testmasks[8] = {false,
141  false,
142  false,
143  false,
144  false}; // Not sure why this duplicates [4] above
145 
146  Answers ans = {
147  {true, true, true, false, false, true, true, false, false},
148  {true, true, false, true, true, false, false, true, true},
149  {true, false, true, true, true, true, true, true, true},
150  {true, true, true, true, false, true, true, true, false}, // last column
151  // changed due to
152  // treatment of
153  // excp
154  {false, false, false, false, true, false, false, false, false},
155  {true, true, true, true, true, true, true, true, false}, // last column
156  // changed due to
157  // treatment of
158  // excp
159  {true, true, true, true, true, true, true, true, true},
160  {false, true, true, false, true, true, true, false, false},
161  {true, true, true, true, false, true, true, true, false}, // last column
162  // changed due to
163  // treatment of
164  // excp
165  {true, true, true, true, false, true, true, false, false},
166  {false, false, false, false, true, false, true, false, false} // last column
167  // changed due
168  // to
169  // treatment
170  // of excp
171  };
172 
173  Strings bit_qualified_paths;
174  size_t i = 0;
175  for (auto const& name : paths) {
176  bit_qualified_paths.push_back(to_string(i) + ':' + name);
177  }
178 
179  // We are ready to run some tests
180  testall(bit_qualified_paths, patterns, testmasks, ans);
181  return 0;
182 }
static QCString name
Definition: declinfo.cpp:673
constexpr size_t numBits
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
std::vector< Bools > VBools
constexpr int numMasks
std::vector< Strings > VStrings
void testall(const Strings &paths, const VStrings &patterns, const VBools &masks, const Answers &answers)
std::vector< std::string > Strings
constexpr int numPatterns
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
std::vector< std::vector< bool > > Answers
std::ostream& operator<< ( std::ostream &  ost,
const Strings s 
)

Definition at line 25 of file EventSelector_t.cpp.

26 {
27  for (auto const& str : s) {
28  ost << str << " ";
29  }
30  return ost;
31 }
static QCString * s
Definition: config.cpp:1042
static QCString str
std::ostream& operator<< ( std::ostream &  ost,
const Bools b 
)

Definition at line 34 of file EventSelector_t.cpp.

35 {
36  for (unsigned int i = 0; i < b.size(); ++i) {
37  ost << b[i] << " ";
38  }
39  return ost;
40 }
static bool * b
Definition: config.cpp:1043
void testall ( const Strings paths,
const VStrings patterns,
const VBools masks,
const Answers answers 
)

Definition at line 100 of file EventSelector_t.cpp.

104 {
105  for (unsigned int i = 0; i < patterns.size(); ++i) {
106  for (unsigned int j = 0; j < masks.size(); ++j) {
107  testone(paths, patterns[i], masks[j], answers[i][j], j);
108  }
109  }
110 }
void testone(const Strings &paths, const Strings &pattern, const Bools &mask, bool answer, int jmask)
void testone ( const Strings paths,
const Strings pattern,
const Bools mask,
bool  answer,
int  jmask 
)

Definition at line 43 of file EventSelector_t.cpp.

48 {
49  EventSelector selector{pattern};
50 
51  int number_of_trigger_paths = 0;
52  std::vector<unsigned char> bitArray;
53 
54  HLTGlobalStatus bm(mask.size());
59  for (unsigned int b = 0; b < mask.size(); ++b) {
60  bm.at(b) = (mask[b] ? pass : fail);
61 
62  // There is an alternate version of the function acceptEvent
63  // that takes an array of characters as an argument instead
64  // of a TriggerResults object. These next few lines build
65  // that array so we can test that also.
66  if ((number_of_trigger_paths % 4) == 0)
67  bitArray.push_back(0);
68  int byteIndex = number_of_trigger_paths / 4;
69  int subIndex = number_of_trigger_paths % 4;
70  bitArray[byteIndex] |= (mask[b] ? art::hlt::Pass : art::hlt::Fail)
71  << (subIndex * 2);
72  ++number_of_trigger_paths;
73  }
74 
75  if (jmask == 8 && mask.size() > 4) {
76  bm.at(0) = ready;
77  bm.at(4) = ex;
78  bitArray[0] = (bitArray[0] & 0xfc) | art::hlt::Ready;
79  bitArray[1] = (bitArray[1] & 0xfc) | art::hlt::Exception;
80  }
81 
82  ParameterSet trigger_pset;
83  trigger_pset.put<Strings>("trigger_paths", paths);
84  ParameterSetRegistry::put(trigger_pset);
85 
86  TriggerResults const results_id{bm, trigger_pset.id()};
87  bool const result = selector.acceptEvent(ScheduleID::first(), results_id);
88  if (result != answer) {
89  std::cerr << "failed to compare pattern with mask using pset ID: "
90  << "correct=" << answer << " "
91  << "results=" << std::boolalpha << result << '\n'
92  << "pattern=" << pattern << "\n"
93  << "mask=" << mask << "\n"
94  << "jmask = " << jmask << "\n";
95  abort();
96  }
97 }
static QCString result
HLTPathStatus const pass
HLTPathStatus const fail
ParameterSetID id() const
std::string pattern
Definition: regex_t.cc:35
static bool * b
Definition: config.cpp:1043
std::vector< std::string > Strings
void put(std::string const &key)

Variable Documentation

constexpr size_t numBits = 5

Definition at line 14 of file EventSelector_t.cpp.

constexpr int numMasks = 9

Definition at line 16 of file EventSelector_t.cpp.

constexpr int numPatterns = 11

Definition at line 15 of file EventSelector_t.cpp.