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