ATLAS Offline Software
JetStreamerTest.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
8 #include "gtest/gtest.h"
11 #include <vector>
12 #include <memory>
13 
14 using vec = std::vector<std::size_t>;
15 
16 std::unique_ptr<JetStreamer> make_streamer(int test){
17 
18  auto null_stream = std::unique_ptr<IJetStream>{nullptr};
19 
20  auto streamer = std::unique_ptr<JetStreamer> (nullptr);
21 
22  if (test == 0) {
23  std::vector<std::size_t> jets0 {1, 2};
24 
25  auto stream0 = std::make_unique<SimpleJetStream>(jets0,
26  std::move(null_stream),
27  0
28  );
29  streamer = std::make_unique<JetStreamer>(std::move(stream0));
30 
31  return streamer;
32  } else if (test == 1) {
33 
34  std::vector<std::size_t> jets_cs {5, 6, 7};
35  std::size_t k2{2};
36 
37  auto stream0 =
38  std::make_unique<CombinationsJetStream>(jets_cs,
39  std::move(null_stream),
40  k2,
41  0
42  );
43  streamer.reset(new JetStreamer(std::move(stream0)));
44  return streamer;
45  } else if (test == 2) {
46 
47  std::vector<std::size_t> jets0 {1, 2};
48  std::vector<std::size_t> jets1 {3, 4};
49  auto stream1 =
50  std::make_unique<SimpleJetStream>(jets1,
51  std::move(null_stream),
52  1
53  );
54 
55 
56  auto stream0 =
57  std::make_unique<SimpleJetStream>(jets0,
58  std::move(stream1),
59  0
60  );
61 
62  streamer.reset(new JetStreamer(std::move(stream0)));
63  return streamer;
64  } else if (test == 3) {
65 
66  std::vector<std::size_t> jets_cs {5, 6, 7};
67  std::size_t k2{2};
68  std::vector<std::size_t> jets0 {1, 2};
69 
70 
71 
72  auto stream1 =
73  std::make_unique<CombinationsJetStream>(jets_cs,
74  std::move(null_stream),
75  k2,
76  1
77  );
78 
79 
80  auto stream0 =
81  std::make_unique<SimpleJetStream>(jets0,
82  std::move(stream1),
83  0
84  );
85 
86  streamer.reset(new JetStreamer(std::move(stream0)));
87  return streamer;
88  } else if (test == 4) {
89 
90  std::vector<std::size_t> jets_cs {5, 6, 7};
91  std::size_t k2{2};
92  std::vector<std::size_t> jets0 {1, 2};
93 
94 
95  auto stream1 =
96  std::make_unique<SimpleJetStream>(jets0,
97  std::move(null_stream),
98  1
99  );
100 
101 
102  auto stream0 =
103  std::make_unique<CombinationsJetStream>(jets_cs,
104  std::move(stream1),
105  k2,
106  0
107  );
108 
109  streamer.reset(new JetStreamer(std::move(stream0)));
110  return streamer;
111  } else if (test == 5) {
112 
113 
114  std::vector<std::size_t> jets_cs {5, 6, 7};
115  std::size_t k2{2};
116  std::vector<std::size_t> jets0 {1, 2};
117  std::vector<std::size_t> jets1 {3, 4};
118 
119  auto stream2 =
120  std::make_unique<SimpleJetStream>(jets1,
121  std::move(null_stream),
122  2
123  );
124 
125  auto stream1 =
126  std::make_unique<CombinationsJetStream>(jets_cs,
127  std::move(stream2),
128  k2,
129  1
130  );
131 
132 
133  auto stream0 =
134  std::make_unique<SimpleJetStream>(jets0,
135  std::move(stream1),
136  0
137  );
138 
139  streamer.reset(new JetStreamer(std::move(stream0)));
140 
141  return streamer;
142  } else if (test == 6) {
143 
144 
145  std::vector<std::size_t> jets_cs {};
146  std::size_t k2{2};
147  std::vector<std::size_t> jets0 {1, 2};
148  std::vector<std::size_t> jets1 {3, 4};
149 
150  auto stream2 =
151  std::make_unique<SimpleJetStream>(jets1,
152  std::move(null_stream),
153  2
154  );
155 
156  auto stream1 =
157  std::make_unique<CombinationsJetStream>(jets_cs,
158  std::move(stream2),
159  k2,
160  1
161  );
162 
163 
164  auto stream0 =
165  std::make_unique<SimpleJetStream>(jets0,
166  std::move(stream1),
167  0
168  );
169 
170  streamer.reset(new JetStreamer(std::move(stream0)));
171 
172  return streamer;
173  } else if (test == 7) {
174 
175 
176  std::vector<std::size_t> jets_cs {5, 6, 7};
177  std::size_t k4{4};
178  std::vector<std::size_t> jets0 {1, 2};
179  std::vector<std::size_t> jets1 {3, 4};
180 
181  auto stream2 =
182  std::make_unique<SimpleJetStream>(jets1,
183  std::move(null_stream),
184  2
185  );
186 
187  auto stream1 =
188  std::make_unique<CombinationsJetStream>(jets_cs,
189  std::move(stream2),
190  k4,
191  1
192  );
193 
194 
195  auto stream0 =
196  std::make_unique<SimpleJetStream>(jets0,
197  std::move(stream1),
198  0
199  );
200 
201  streamer.reset(new JetStreamer(std::move(stream0)));
202 
203  return streamer;
204  } else if (test == 8) {
205 
206  auto stream0 = std::unique_ptr<IJetStream>(nullptr);
207  streamer.reset(new JetStreamer(std::move(stream0)));
208  return streamer;
209  } else {
210  std::cerr << "unknown test << " << test << '\n';
211  return streamer;
212  }
213 }
214 
215 TEST(JetStreamerTester, oneSimpleJetStream) {
216  // Cycle around the input vector
217  auto streamer = make_streamer(0);
218  EXPECT_EQ (vec{1}, streamer->next());
219  EXPECT_EQ (vec{2}, streamer->next());
220  EXPECT_EQ (vec{}, streamer->next());
221 }
222 
223 
224 TEST(JetStreamerTester, oneCombinationsJetStream) {
225  // Cycle around the input vector
226  auto streamer = make_streamer(1);
227  vec v0{5, 6};
228  vec v1{5, 7};
229  vec v2{6, 7};
230  EXPECT_EQ (v0, streamer->next());
231  EXPECT_EQ (v1, streamer->next());
232  EXPECT_EQ (v2, streamer->next());
233  EXPECT_EQ (vec{}, streamer->next());
234 }
235 
236 
237 TEST(JetStreamerTester, twoSimpleJetStreams) {
238  // Cycle around the input vector
239  auto streamer = make_streamer(2);
240  vec v0{3, 1};
241  vec v1{4, 1};
242  vec v2{3, 2};
243  vec v3{4, 2};
244 
245  EXPECT_EQ (v0, streamer->next());
246  EXPECT_EQ (v1, streamer->next());
247  EXPECT_EQ (v2, streamer->next());
248  EXPECT_EQ (v3, streamer->next());
249  EXPECT_EQ (vec{}, streamer->next());
250 }
251 
252 TEST(JetStreamerTester, SimpleThenCombinationsJetStreams) {
253  // Cycle around the input vector
254  auto streamer = make_streamer(3);
255  vec v0{5, 6, 1};
256  vec v1{5, 7, 1};
257  vec v2{6, 7, 1};
258  vec v3{5, 6, 2};
259  vec v4{5, 7, 2};
260  vec v5{6, 7, 2};
261 
262  EXPECT_EQ (v0, streamer->next());
263  EXPECT_EQ (v1, streamer->next());
264  EXPECT_EQ (v2, streamer->next());
265  EXPECT_EQ (v3, streamer->next());
266  EXPECT_EQ (v4, streamer->next());
267  EXPECT_EQ (v5, streamer->next());
268  EXPECT_EQ (vec{}, streamer->next());
269 }
270 
271 TEST(JetStreamerTester, CombinationsThenSimpleJetStreams) {
272  // Cycle around the input vector
273  auto streamer = make_streamer(4);
274  vec v0{1, 5, 6};
275  vec v1{2, 5, 6};
276  vec v2{1, 5, 7};
277  vec v3{2, 5, 7};
278  vec v4{1, 6, 7};
279  vec v5{2, 6, 7};
280 
281  EXPECT_EQ (v0, streamer->next());
282  EXPECT_EQ (v1, streamer->next());
283  EXPECT_EQ (v2, streamer->next());
284  EXPECT_EQ (v3, streamer->next());
285  EXPECT_EQ (v4, streamer->next());
286  EXPECT_EQ (v5, streamer->next());
287  EXPECT_EQ (vec{}, streamer->next());
288 }
289 
290 TEST(JetStreamerTester, SimmpleThenCombinationsThenSimpleJetStreams) {
291  // Cycle around the input vector
292  auto streamer = make_streamer(5);
293  vec v0{3, 5, 6, 1};
294  vec v1{4, 5, 6, 1};
295  vec v2{3, 5, 7, 1};
296  vec v3{4, 5, 7, 1};
297  vec v4{3, 6, 7, 1};
298  vec v5{4, 6, 7, 1};
299  vec v6{3, 5, 6, 2};
300  vec v7{4, 5, 6, 2};
301  vec v8{3, 5, 7, 2};
302  vec v9{4, 5, 7, 2};
303  vec v10{3, 6, 7, 2};
304  vec v11{4, 6, 7, 2};
305 
306  EXPECT_EQ (v0, streamer->next());
307  EXPECT_EQ (v1, streamer->next());
308  EXPECT_EQ (v2, streamer->next());
309  EXPECT_EQ (v3, streamer->next());
310  EXPECT_EQ (v4, streamer->next());
311  EXPECT_EQ (v5, streamer->next());
312  EXPECT_EQ (v6, streamer->next());
313  EXPECT_EQ (v7, streamer->next());
314  EXPECT_EQ (v8, streamer->next());
315  EXPECT_EQ (v9, streamer->next());
316  EXPECT_EQ (v10, streamer->next());
317  EXPECT_EQ (v11, streamer->next());
318  EXPECT_EQ (vec{}, streamer->next());
319 }
320 
321 TEST(JetStreamerTester, InvalidJetIndices) {
322  // Cycle around the input vector
323  auto streamer = make_streamer(6);
324  EXPECT_EQ (vec{}, streamer->next());
325 }
326 
327 
328 TEST(JetStreamerTester, InvalidNchooseK) {
329  // Cycle around the input vector
330  auto streamer = make_streamer(7);
331  EXPECT_EQ (vec{}, streamer->next());
332 }
333 
334 TEST(JetStreamerTester, InvalidJetStream) {
335  // Cycle around the input vector
336  auto streamer = make_streamer(8);
337  EXPECT_EQ (vec{}, streamer->next());
338 }
AthenaPoolExample_Write.stream1
stream1
Definition: AthenaPoolExample_Write.py:118
TEST
TEST(JetStreamerTester, oneSimpleJetStream)
Definition: JetStreamerTest.cxx:215
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
AthenaPoolExample_Write.stream2
stream2
Definition: AthenaPoolExample_Write.py:126
TrigInDetValidation_Base.test
test
Definition: TrigInDetValidation_Base.py:147
JetStreamer.h
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
Definition: JetStreamerTest.cxx:6
parseMapping.v0
def v0
Definition: parseMapping.py:149
IJetStream.h
make_streamer
std::unique_ptr< JetStreamer > make_streamer(int test)
Definition: JetStreamerTest.cxx:16
ReadCellNoiseFromCoolCompare.v2
v2
Definition: ReadCellNoiseFromCoolCompare.py:364
JetStreamer
Definition: JetStreamer.h:25
checker_macros.h
Define macros for attributes used to control the static checker.