00001 #include "artdaq/Application/Routing/RoutingMasterPolicy.hh" 00002 #include "artdaq/Application/Routing/PolicyMacros.hh" 00003 #include <fhiclcpp/ParameterSet.h> 00004 #include <messagefacility/MessageLogger/MessageLogger.h> 00005 00006 namespace demo 00007 { 00011 class MisbehaviorTest : public artdaq::RoutingMasterPolicy 00012 { 00013 public: 00028 explicit MisbehaviorTest(fhicl::ParameterSet ps); 00029 00033 virtual ~MisbehaviorTest() = default; 00034 00039 artdaq::detail::RoutingPacket GetCurrentTable() override; 00040 private: 00041 artdaq::Fragment::sequence_id_t misbehave_after_; 00042 size_t misbehave_pause_ms_; 00043 bool misbehave_conflicting_table_data_; 00044 bool misbehave_corrupt_table_data_; 00045 bool misbehave_overload_event_builder_; 00046 }; 00047 00048 MisbehaviorTest::MisbehaviorTest(fhicl::ParameterSet ps) 00049 : RoutingMasterPolicy(ps) 00050 , misbehave_after_(ps.get<size_t>("misbehave_after_n_events", 1000)) 00051 , misbehave_pause_ms_(ps.get<size_t>("misbehave_pause_time_ms", 0)) 00052 , misbehave_conflicting_table_data_(ps.get<bool>("misbehave_send_conflicting_table_data", false)) 00053 , misbehave_corrupt_table_data_(ps.get<bool>("misbehave_send_corrupt_table_data", false)) 00054 , misbehave_overload_event_builder_(ps.get<bool>("misbehave_overload_event_builder", false)) 00055 { 00056 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); 00057 if (count > 1) 00058 { 00059 mf::LogWarning("MisbehaviorTest") << "Only one misbehavior is allowed at a time!"; 00060 exit(3); 00061 } 00062 } 00063 00064 artdaq::detail::RoutingPacket MisbehaviorTest::GetCurrentTable() 00065 { 00066 auto tokens = getTokensSnapshot(); 00067 artdaq::detail::RoutingPacket output; 00068 00069 auto half = tokens->size() / 2; 00070 size_t counter = 0; 00071 for(;counter < half;++counter) 00072 { 00073 output.emplace_back(artdaq::detail::RoutingPacketEntry(next_sequence_id_++, tokens->at(counter))); 00074 } 00075 00076 if (next_sequence_id_ > misbehave_after_) 00077 { 00078 if (tokens->size() > 0) 00079 { 00080 if (misbehave_pause_ms_ > 0) 00081 { 00082 mf::LogError("MisbehaviorTest") << "Pausing for " << misbehave_pause_ms_ << " milliseconds before sending table update"; 00083 usleep(misbehave_pause_ms_ * 1000); 00084 } 00085 if (misbehave_conflicting_table_data_) 00086 { 00087 mf::LogError("MisbehaviorTest") << "Adding conflicting data point to output"; 00088 output.emplace_back(next_sequence_id_, tokens->at(counter) + 1); 00089 } 00090 if (misbehave_corrupt_table_data_) 00091 { 00092 mf::LogError("MisbehaviorTest") << "Adding random data point"; 00093 output.emplace_back(rand(), rand()); 00094 } 00095 if (misbehave_overload_event_builder_) 00096 { 00097 mf::LogError("MisbehaviorTest") << "Sending 100 events in a row to Rank " << tokens->at(0); 00098 for (auto ii = 0; ii < 100; ++ii) 00099 { 00100 output.emplace_back(next_sequence_id_++, tokens->at(0)); 00101 } 00102 } 00103 misbehave_after_ += misbehave_after_; 00104 } 00105 } 00106 00107 for (;counter < tokens->size();++counter) 00108 { 00109 output.emplace_back(artdaq::detail::RoutingPacketEntry(next_sequence_id_++, tokens->at(counter))); 00110 } 00111 00112 return output; 00113 } 00114 } 00115 00116 DEFINE_ARTDAQ_ROUTING_POLICY(demo::MisbehaviorTest)