artdaq_demo  v3_09_05
NthEvent_policy_t.cc
1 #define BOOST_TEST_MODULE (NthEvent_policy_t)
2 #include <boost/test/unit_test.hpp>
3 
4 #include "artdaq/RoutingPolicies/makeRoutingManagerPolicy.hh"
5 #include "fhiclcpp/ParameterSet.h"
6 #include "fhiclcpp/make_ParameterSet.h"
7 
8 BOOST_AUTO_TEST_SUITE(NthEvent_policy_t)
9 
10 BOOST_AUTO_TEST_CASE(Simple)
11 {
12  fhicl::ParameterSet ps;
13  fhicl::make_ParameterSet("receiver_ranks: [1,2,3,4] nth_event: 5 target_receiver: 3", ps);
14 
15  auto nth = artdaq::makeRoutingManagerPolicy("NthEvent", ps);
16 
17  BOOST_REQUIRE_EQUAL(nth->GetReceiverCount(), 4);
18 
19  // Extra token, and out of sequence
20  nth->Reset();
21  nth->AddReceiverToken(1, 1);
22  nth->AddReceiverToken(2, 1);
23  nth->AddReceiverToken(4, 1);
24  nth->AddReceiverToken(2, 1);
25  auto secondTable = nth->GetCurrentTable();
26  BOOST_REQUIRE_EQUAL(secondTable.size(), 3);
27  BOOST_REQUIRE_EQUAL(secondTable[0].destination_rank, 1);
28  BOOST_REQUIRE_EQUAL(secondTable[0].sequence_id, 1);
29  BOOST_REQUIRE_EQUAL(secondTable[1].destination_rank, 2);
30  BOOST_REQUIRE_EQUAL(secondTable[1].sequence_id, 2);
31  BOOST_REQUIRE_EQUAL(secondTable[2].destination_rank, 4);
32  BOOST_REQUIRE_EQUAL(secondTable[2].sequence_id, 3);
33 
34  // Adding empty number of tokens
35  nth->AddReceiverToken(1, 0);
36  auto thirdTable = nth->GetCurrentTable();
37  BOOST_REQUIRE_EQUAL(thirdTable.size(), 0);
38 
39  // Catching up to the extra token
40  nth->AddReceiverToken(1, 2);
41  nth->AddReceiverToken(3, 2);
42  nth->AddReceiverToken(4, 2);
43  auto fourthTable = nth->GetCurrentTable();
44  BOOST_REQUIRE_EQUAL(fourthTable.size(), 4);
45  BOOST_REQUIRE_EQUAL(fourthTable[0].destination_rank, 1);
46  BOOST_REQUIRE_EQUAL(fourthTable[0].sequence_id, 4);
47  BOOST_REQUIRE_EQUAL(fourthTable[1].destination_rank, 3);
48  BOOST_REQUIRE_EQUAL(fourthTable[1].sequence_id, 5);
49  BOOST_REQUIRE_EQUAL(fourthTable[2].destination_rank, 2);
50  BOOST_REQUIRE_EQUAL(fourthTable[2].sequence_id, 6);
51  BOOST_REQUIRE_EQUAL(fourthTable[3].destination_rank, 4);
52  BOOST_REQUIRE_EQUAL(fourthTable[3].sequence_id, 7);
53 
54  // Catching up to the missing token
55  nth->AddReceiverToken(2, 1);
56  auto fifthTable = nth->GetCurrentTable();
57  BOOST_REQUIRE_EQUAL(fifthTable.size(), 4);
58  BOOST_REQUIRE_EQUAL(fifthTable[0].destination_rank, 1);
59  BOOST_REQUIRE_EQUAL(fifthTable[0].sequence_id, 8);
60  BOOST_REQUIRE_EQUAL(fifthTable[1].destination_rank, 2);
61  BOOST_REQUIRE_EQUAL(fifthTable[1].sequence_id, 9);
62  BOOST_REQUIRE_EQUAL(fifthTable[2].destination_rank, 3);
63  BOOST_REQUIRE_EQUAL(fifthTable[2].sequence_id, 10);
64  BOOST_REQUIRE_EQUAL(fifthTable[3].destination_rank, 4);
65  BOOST_REQUIRE_EQUAL(fifthTable[3].sequence_id, 11);
66 
67  // Lots of "normal" tokens
68  nth->AddReceiverToken(1, 10);
69  nth->AddReceiverToken(2, 10);
70  nth->AddReceiverToken(4, 10);
71  auto sixthTable = nth->GetCurrentTable();
72  BOOST_REQUIRE_EQUAL(sixthTable.size(), 3);
73  BOOST_REQUIRE_EQUAL(sixthTable[0].destination_rank, 1);
74  BOOST_REQUIRE_EQUAL(sixthTable[0].sequence_id, 12);
75  BOOST_REQUIRE_EQUAL(sixthTable[1].destination_rank, 2);
76  BOOST_REQUIRE_EQUAL(sixthTable[1].sequence_id, 13);
77  BOOST_REQUIRE_EQUAL(sixthTable[2].destination_rank, 4);
78  BOOST_REQUIRE_EQUAL(sixthTable[2].sequence_id, 14);
79 
80  // Still no "nth" token
81  auto blankTable = nth->GetCurrentTable();
82  BOOST_REQUIRE_EQUAL(blankTable.size(), 0);
83 
84  // Some "nth" tokens
85  nth->AddReceiverToken(3, 3);
86  auto seventhTable = nth->GetCurrentTable();
87  BOOST_REQUIRE_EQUAL(seventhTable.size(), 15);
88  BOOST_REQUIRE_EQUAL(seventhTable[0].destination_rank, 3);
89  BOOST_REQUIRE_EQUAL(seventhTable[0].sequence_id, 15);
90  BOOST_REQUIRE_EQUAL(seventhTable[1].destination_rank, 1);
91  BOOST_REQUIRE_EQUAL(seventhTable[1].sequence_id, 16);
92  BOOST_REQUIRE_EQUAL(seventhTable[2].destination_rank, 2);
93  BOOST_REQUIRE_EQUAL(seventhTable[2].sequence_id, 17);
94  BOOST_REQUIRE_EQUAL(seventhTable[3].destination_rank, 4);
95  BOOST_REQUIRE_EQUAL(seventhTable[3].sequence_id, 18);
96  BOOST_REQUIRE_EQUAL(seventhTable[4].destination_rank, 1);
97  BOOST_REQUIRE_EQUAL(seventhTable[4].sequence_id, 19);
98  BOOST_REQUIRE_EQUAL(seventhTable[5].destination_rank, 3);
99  BOOST_REQUIRE_EQUAL(seventhTable[5].sequence_id, 20);
100  BOOST_REQUIRE_EQUAL(seventhTable[6].destination_rank, 2);
101  BOOST_REQUIRE_EQUAL(seventhTable[6].sequence_id, 21);
102  BOOST_REQUIRE_EQUAL(seventhTable[7].destination_rank, 4);
103  BOOST_REQUIRE_EQUAL(seventhTable[7].sequence_id, 22);
104  BOOST_REQUIRE_EQUAL(seventhTable[8].destination_rank, 1);
105  BOOST_REQUIRE_EQUAL(seventhTable[8].sequence_id, 23);
106  BOOST_REQUIRE_EQUAL(seventhTable[9].destination_rank, 2);
107  BOOST_REQUIRE_EQUAL(seventhTable[9].sequence_id, 24);
108  BOOST_REQUIRE_EQUAL(seventhTable[10].destination_rank, 3);
109  BOOST_REQUIRE_EQUAL(seventhTable[10].sequence_id, 25);
110  BOOST_REQUIRE_EQUAL(seventhTable[11].destination_rank, 4);
111  BOOST_REQUIRE_EQUAL(seventhTable[11].sequence_id, 26);
112  BOOST_REQUIRE_EQUAL(seventhTable[12].destination_rank, 1);
113  BOOST_REQUIRE_EQUAL(seventhTable[12].sequence_id, 27);
114  BOOST_REQUIRE_EQUAL(seventhTable[13].destination_rank, 2);
115  BOOST_REQUIRE_EQUAL(seventhTable[13].sequence_id, 28);
116  BOOST_REQUIRE_EQUAL(seventhTable[14].destination_rank, 4);
117  BOOST_REQUIRE_EQUAL(seventhTable[14].sequence_id, 29);
118 }
119 
120 BOOST_AUTO_TEST_SUITE_END()