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