artdaq_demo  v2_10_00
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
MisbehaviorTest_policy.cc
1 #include "artdaq/Application/Routing/RoutingMasterPolicy.hh"
2 #include "artdaq/Application/Routing/PolicyMacros.hh"
3 #include <fhiclcpp/ParameterSet.h>
4 #include <messagefacility/MessageLogger/MessageLogger.h>
5 
6 namespace demo
7 {
11  class MisbehaviorTest : public artdaq::RoutingMasterPolicy
12  {
13  public:
28  explicit MisbehaviorTest(fhicl::ParameterSet ps);
29 
33  virtual ~MisbehaviorTest() = default;
34 
39  artdaq::detail::RoutingPacket GetCurrentTable() override;
40  private:
41  artdaq::Fragment::sequence_id_t misbehave_after_;
42  size_t misbehave_pause_ms_;
43  bool misbehave_conflicting_table_data_;
44  bool misbehave_corrupt_table_data_;
45  bool misbehave_overload_event_builder_;
46  };
47 
48  MisbehaviorTest::MisbehaviorTest(fhicl::ParameterSet ps)
49  : RoutingMasterPolicy(ps)
50  , misbehave_after_(ps.get<size_t>("misbehave_after_n_events", 1000))
51  , misbehave_pause_ms_(ps.get<size_t>("misbehave_pause_time_ms", 0))
52  , misbehave_conflicting_table_data_(ps.get<bool>("misbehave_send_conflicting_table_data", false))
53  , misbehave_corrupt_table_data_(ps.get<bool>("misbehave_send_corrupt_table_data", false))
54  , misbehave_overload_event_builder_(ps.get<bool>("misbehave_overload_event_builder", false))
55  {
56  auto count = (misbehave_conflicting_table_data_ ? 1 : 0) + (misbehave_corrupt_table_data_ ? 1 : 0) + (misbehave_overload_event_builder_ ? 1 : 0) + (misbehave_pause_ms_ > 0 ? 1 : 0);
57  if (count > 1)
58  {
59  mf::LogWarning("MisbehaviorTest") << "Only one misbehavior is allowed at a time!";
60  exit(3);
61  }
62  }
63 
64  artdaq::detail::RoutingPacket MisbehaviorTest::GetCurrentTable()
65  {
66  auto tokens = getTokensSnapshot();
67  artdaq::detail::RoutingPacket output;
68 
69  auto half = tokens->size() / 2;
70  size_t counter = 0;
71  for(;counter < half;++counter)
72  {
73  output.emplace_back(artdaq::detail::RoutingPacketEntry(next_sequence_id_++, tokens->at(counter)));
74  }
75 
76  if (next_sequence_id_ > misbehave_after_)
77  {
78  if (tokens->size() > 0)
79  {
80  if (misbehave_pause_ms_ > 0)
81  {
82  mf::LogError("MisbehaviorTest") << "Pausing for " << misbehave_pause_ms_ << " milliseconds before sending table update";
83  usleep(misbehave_pause_ms_ * 1000);
84  }
85  if (misbehave_conflicting_table_data_)
86  {
87  mf::LogError("MisbehaviorTest") << "Adding conflicting data point to output";
88  output.emplace_back(next_sequence_id_, tokens->at(counter) + 1);
89  }
90  if (misbehave_corrupt_table_data_)
91  {
92  mf::LogError("MisbehaviorTest") << "Adding random data point";
93  output.emplace_back(rand(), rand());
94  }
95  if (misbehave_overload_event_builder_)
96  {
97  mf::LogError("MisbehaviorTest") << "Sending 100 events in a row to Rank " << tokens->at(0);
98  for (auto ii = 0; ii < 100; ++ii)
99  {
100  output.emplace_back(next_sequence_id_++, tokens->at(0));
101  }
102  }
103  misbehave_after_ += misbehave_after_;
104  }
105  }
106 
107  for (;counter < tokens->size();++counter)
108  {
109  output.emplace_back(artdaq::detail::RoutingPacketEntry(next_sequence_id_++, tokens->at(counter)));
110  }
111 
112  return output;
113  }
114 }
115 
116 DEFINE_ARTDAQ_ROUTING_POLICY(demo::MisbehaviorTest)
MisbehaviorTest(fhicl::ParameterSet ps)
MisbehaviorTest Constructor.
artdaq::detail::RoutingPacket GetCurrentTable() override
Generate and return a Routing Table.
A test RoutingMasterPolicy which does various &quot;bad&quot; things, determined by configuration.
virtual ~MisbehaviorTest()=default
MisbehaviorTest default Destructor.