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