artdaq  v3_01_00
CommandableFragmentGenerator_t.cc
1 #define TRACE_NAME "CommandableFragmentGenerator_t"
2 
3 #define BOOST_TEST_MODULE CommandableFragmentGenerator_t
4 #include <boost/test/auto_unit_test.hpp>
5 
6 #include "artdaq-core/Data/Fragment.hh"
7 #include "artdaq-core/Data/ContainerFragment.hh"
8 #include "artdaq/Application/CommandableFragmentGenerator.hh"
9 #include "artdaq/DAQrate/RequestSender.hh"
10 
11 #define MULTICAST_MODE 0
12 
13 namespace artdaqtest
14 {
15  class CommandableFragmentGeneratorTest;
16 }
17 
23 {
24 public:
28  explicit CommandableFragmentGeneratorTest(const fhicl::ParameterSet& ps);
29 
31 
32 protected:
40  bool getNext_(artdaq::FragmentPtrs& frags) override;
41 
46  bool checkHWStatus_() override { return !hwFail_.load(); }
47 
51  void start() override;
52 
56  void stopNoMutex() override;
57 
61  void stop() override;
62 
66  void pause() override;
67 
71  void resume() override;
72 
73 public:
78  void setFireCount(size_t count) { fireCount_ = count; }
79 
83  void setHwFail() { hwFail_ = true; }
84 
88  void waitForFrags() {
89  auto start_time = std::chrono::steady_clock::now();
90  while (fireCount_ > 0) { usleep(1000); }
91  TLOG(TLVL_INFO) << "Waited " << std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - start_time).count() << " us for events to be picked up by CFG" ;
92  }
93 private:
94  std::atomic<size_t> fireCount_;
95  std::atomic<bool> hwFail_;
96  artdaq::Fragment::timestamp_t ts_;
97  bool hw_stop_;
98 };
99 
101  : CommandableFragmentGenerator(ps)
102  , fireCount_(1)
103  , hwFail_(false)
104  , ts_(0)
105  , hw_stop_(false)
106 {}
107 
108 bool
110 {
111  while (fireCount_ > 0)
112  {
113  frags.emplace_back(new artdaq::Fragment(ev_counter(), fragment_id(), artdaq::Fragment::FirstUserFragmentType, ++ts_));
114  fireCount_--;
115  }
116 
117  return !hw_stop_;
118 }
119 
120 void
122 
123 void
125 
126 void
128 
129 void
131 
132 void
134 
135 BOOST_AUTO_TEST_SUITE(CommandableFragmentGenerator_t)
136 
137 BOOST_AUTO_TEST_CASE(Simple)
138 {
139  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
140  TLOG(TLVL_INFO) << "Simple test case BEGIN" ;
141  fhicl::ParameterSet ps;
142  ps.put<int>("board_id", 1);
143  ps.put<int>("fragment_id", 1);
145  artdaq::FragmentPtrs fps;
146  auto sts = testGen.getNext(fps);
147  BOOST_REQUIRE_EQUAL(sts, true);
148  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
149  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
150  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
151  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
152  TLOG(TLVL_INFO) << "Simple test case END" ;
153 }
154 
155 BOOST_AUTO_TEST_CASE(IgnoreRequests)
156 {
157  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
158  TLOG(TLVL_INFO) << "IgnoreRequests test case BEGIN" ;
159  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
160  const int DELAY_TIME = 1;
161  fhicl::ParameterSet ps;
162  ps.put<int>("board_id", 1);
163  ps.put<int>("fragment_id", 1);
164  ps.put<int>("request_port", REQUEST_PORT);
165 #if MULTICAST_MODE
166  ps.put<std::string>("request_address", "227.18.12.29");
167 #else
168  ps.put<std::string>("request_address", "localhost");
169 #endif
170  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
171  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0);
172  ps.put<bool>("separate_data_thread", true);
173  ps.put<bool>("separate_monitoring_thread", false);
174  ps.put<int64_t>("hardware_poll_interval_us", 0);
175  ps.put<std::string>("request_mode", "ignored");
176  ps.put("request_delay_ms", DELAY_TIME);
177  ps.put("send_requests", true);
178 
179  artdaq::RequestSender t(ps);
181  gen.StartCmd(1, 0xFFFFFFFF, 1);
182  t.AddRequest(53, 35);
183 
184  artdaq::FragmentPtrs fps;
185  auto sts = gen.getNext(fps);
186  BOOST_REQUIRE_EQUAL(sts, true);
187  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
188  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
189  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
190  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
191  gen.StopCmd(0xFFFFFFFF, 1);
192  gen.joinThreads();
193  TLOG(TLVL_INFO) << "IgnoreRequests test case END" ;
194 }
195 
196 BOOST_AUTO_TEST_CASE(SingleMode)
197 {
198  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
199  TLOG(TLVL_INFO) << "SingleMode test case BEGIN" ;
200  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
201  const int DELAY_TIME = 100;
202  fhicl::ParameterSet ps;
203  ps.put<int>("board_id", 1);
204  ps.put<int>("fragment_id", 1);
205  ps.put<int>("request_port", REQUEST_PORT);
206 #if MULTICAST_MODE
207  ps.put<std::string>("request_address", "227.18.12.30");
208 #else
209  ps.put<std::string>("request_address", "localhost");
210 #endif
211  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
212  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0);
213  ps.put<bool>("separate_data_thread", true);
214  ps.put<bool>("separate_monitoring_thread", false);
215  ps.put<int64_t>("hardware_poll_interval_us", 0);
216  ps.put<std::string>("request_mode", "single");
217  ps.put("request_delay_ms", DELAY_TIME);
218  ps.put("send_requests", true);
219 
220  artdaq::RequestSender t(ps);
221  t.AddRequest(1, 1);
222 
224  gen.StartCmd(1, 0xFFFFFFFF, 1);
225  gen.waitForFrags();
226 
227  artdaq::FragmentPtrs fps;
228  auto sts = gen.getNext(fps);
229  auto type = artdaq::Fragment::FirstUserFragmentType;
230  BOOST_REQUIRE_EQUAL(sts, true);
231  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
232  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
233  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
234  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
235  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
236  fps.clear();
237 
238  t.AddRequest(2, 5);
239  sts = gen.getNext(fps);
240  BOOST_REQUIRE_EQUAL(sts, true);
241  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
242  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
243  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
244  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
245  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
246  fps.clear();
247 
248  gen.setFireCount(2);
249  gen.waitForFrags();
250  t.AddRequest(4, 7);
251  sts = gen.getNext(fps);
252  BOOST_REQUIRE_EQUAL(sts, true);
253  BOOST_REQUIRE_EQUAL(fps.size(), 2);
254  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
255  auto ts = artdaq::Fragment::InvalidTimestamp;
256  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
257  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
258  auto emptyType = artdaq::Fragment::EmptyFragmentType;
259  BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
260  fps.pop_front();
261  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
262  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7);
263  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
264  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
265  fps.clear();
266 
267  gen.StopCmd(0xFFFFFFFF, 1);
268  gen.joinThreads();
269  TLOG(TLVL_INFO) << "SingleMode test case END" ;
270 }
271 
272 BOOST_AUTO_TEST_CASE(BufferMode)
273 {
274  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
275  TLOG(TLVL_INFO) << "BufferMode test case BEGIN" ;
276  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
277  const int DELAY_TIME = 100;
278  fhicl::ParameterSet ps;
279  ps.put<int>("board_id", 1);
280  ps.put<int>("fragment_id", 1);
281  ps.put<int>("request_port", REQUEST_PORT);
282 #if MULTICAST_MODE
283  ps.put<std::string>("request_address", "227.18.12.31");
284 #else
285  ps.put<std::string>("request_address", "localhost");
286 #endif
287  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
288  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0);
289  ps.put<bool>("separate_data_thread", true);
290  ps.put<bool>("separate_monitoring_thread", false);
291  ps.put<int64_t>("hardware_poll_interval_us", 0);
292  ps.put<std::string>("request_mode", "buffer");
293  ps.put("request_delay_ms", DELAY_TIME);
294  ps.put("send_requests", true);
295 
296  artdaq::RequestSender t(ps);
297  t.AddRequest(1, 1);
298 
300  gen.StartCmd(1, 0xFFFFFFFF, 1);
301 
302 
303  artdaq::FragmentPtrs fps;
304  auto sts = gen.getNext(fps);
305  BOOST_REQUIRE_EQUAL(sts, true);
306  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
307  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
308  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
309  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
310  auto type = artdaq::Fragment::ContainerFragmentType;
311  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
312  BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 * sizeof(artdaq::detail::RawEventHeader) + sizeof(artdaq::ContainerFragment::Metadata));
313  auto cf = artdaq::ContainerFragment(*fps.front());
314  BOOST_REQUIRE_EQUAL(cf.block_count(), 1);
315  BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
316  type = artdaq::Fragment::FirstUserFragmentType;
317  BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
318  fps.clear();
319 
320  t.AddRequest(2, 5);
321  sts = gen.getNext(fps);
322  BOOST_REQUIRE_EQUAL(sts, true);
323  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
324  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
325  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
326  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
327  type = artdaq::Fragment::ContainerFragmentType;
328  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
329  auto cf2 = artdaq::ContainerFragment(*fps.front());
330  BOOST_REQUIRE_EQUAL(cf2.block_count(), 0);
331  BOOST_REQUIRE_EQUAL(cf2.missing_data(), false);
332  type = artdaq::Fragment::EmptyFragmentType;
333  BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
334  fps.clear();
335 
336  gen.setFireCount(2);
337  gen.waitForFrags();
338  t.AddRequest(4, 7);
339  sts = gen.getNext(fps);
340  BOOST_REQUIRE_EQUAL(sts, true);
341  BOOST_REQUIRE_EQUAL(fps.size(), 2);
342 
343  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
344  auto ts = artdaq::Fragment::InvalidTimestamp;
345  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
346  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
347  auto emptyType = artdaq::Fragment::EmptyFragmentType;
348  BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
349  BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words());
350  fps.pop_front();
351  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
352  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7);
353  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
354  type = artdaq::Fragment::ContainerFragmentType;
355  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
356  auto cf3 = artdaq::ContainerFragment(*fps.front());
357  BOOST_REQUIRE_EQUAL(cf3.block_count(), 2);
358  BOOST_REQUIRE_EQUAL(cf3.missing_data(), false);
359  type = artdaq::Fragment::FirstUserFragmentType;
360  BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type);
361  fps.clear();
362 
363 
364  gen.StopCmd(0xFFFFFFFF, 1);
365  gen.joinThreads();
366 
367 
368  TLOG(TLVL_INFO) << "BufferMode test case END" ;
369 }
370 
371 BOOST_AUTO_TEST_CASE(WindowMode_Function)
372 {
373  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
374  TLOG(TLVL_INFO) << "WindowMode_Function test case BEGIN" ;
375  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
376  const int DELAY_TIME = 100;
377  fhicl::ParameterSet ps;
378  ps.put<int>("board_id", 1);
379  ps.put<int>("fragment_id", 1);
380  ps.put<int>("request_port", REQUEST_PORT);
381 #if MULTICAST_MODE
382  ps.put<std::string>("request_address", "227.18.12.32");
383 #else
384  ps.put<std::string>("request_address", "localhost");
385 #endif
386  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
387  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 0);
388  ps.put<bool>("separate_data_thread", true);
389  ps.put<bool>("separate_monitoring_thread", false);
390  ps.put<int64_t>("hardware_poll_interval_us", 0);
391  ps.put<size_t>("data_buffer_depth_fragments", 5);
392  ps.put<std::string>("request_mode", "window");
393  ps.put("request_delay_ms", DELAY_TIME);
394  ps.put("send_requests", true);
395 
396  artdaq::RequestSender t(ps);
397  t.AddRequest(1, 1);
398 
400  gen.StartCmd(1, 0xFFFFFFFF, 1);
401 
402  artdaq::FragmentPtrs fps;
403  auto sts = gen.getNext(fps);
404  BOOST_REQUIRE_EQUAL(sts, true);
405  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
406  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
407  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
408  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
409  auto type = artdaq::Fragment::ContainerFragmentType;
410  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
411  BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 * sizeof(artdaq::detail::RawEventHeader) + sizeof(artdaq::ContainerFragment::Metadata));
412  auto cf = artdaq::ContainerFragment(*fps.front());
413  BOOST_REQUIRE_EQUAL(cf.block_count(), 1);
414  BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
415  type = artdaq::Fragment::FirstUserFragmentType;
416  BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
417  fps.clear();
418 
419  // No data for request
420  t.AddRequest(2, 2);
421  sts = gen.getNext(fps);
422  BOOST_REQUIRE_EQUAL(sts, true);
423  BOOST_REQUIRE_EQUAL(fps.size(), 0);
424 
425  gen.setFireCount(1);
426  gen.waitForFrags();
427  sts = gen.getNext(fps);
428  BOOST_REQUIRE_EQUAL(sts, true);
429  BOOST_REQUIRE_EQUAL(fps.size(), 1);
430  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
431  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 2);
432  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
433  type = artdaq::Fragment::ContainerFragmentType;
434  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
435  auto cf2 = artdaq::ContainerFragment(*fps.front());
436  BOOST_REQUIRE_EQUAL(cf2.block_count(), 1);
437  BOOST_REQUIRE_EQUAL(cf2.missing_data(), false);
438  type = artdaq::Fragment::FirstUserFragmentType;
439  BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
440  fps.clear();
441 
442  // Missing Request Timeout
443  gen.setFireCount(2);
444  gen.waitForFrags();
445  t.AddRequest(4, 3);
446  sts = gen.getNext(fps);
447  BOOST_REQUIRE_EQUAL(sts, true);
448  BOOST_REQUIRE_EQUAL(fps.size(), 1);
449 
450  usleep(1500000);
451  sts = gen.getNext(fps);
452  BOOST_REQUIRE_EQUAL(sts, true);
453  BOOST_REQUIRE_EQUAL(fps.size(), 2);
454 
455 
456  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
457  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
458  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
459  type = artdaq::Fragment::ContainerFragmentType;
460  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
461  auto cf3 = artdaq::ContainerFragment(*fps.front());
462  BOOST_REQUIRE_EQUAL(cf3.block_count(), 1);
463  BOOST_REQUIRE_EQUAL(cf3.missing_data(), false);
464  type = artdaq::Fragment::FirstUserFragmentType;
465  BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type);
466  fps.pop_front();
467 
468  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
469  auto ts = artdaq::Fragment::InvalidTimestamp;
470  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
471  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
472  auto emptyType = artdaq::Fragment::EmptyFragmentType;
473  BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
474  BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words());
475  fps.clear();
476 
477  // Data-taking has passed request
478  gen.setFireCount(10);
479  gen.waitForFrags();
480  t.AddRequest(5, 4);
481  sts = gen.getNext(fps);
482  BOOST_REQUIRE_EQUAL(sts, true);
483  BOOST_REQUIRE_EQUAL(fps.size(), 1);
484  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
485  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
486  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 5);
487  type = artdaq::Fragment::ContainerFragmentType;
488  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
489  auto cf4 = artdaq::ContainerFragment(*fps.front());
490  BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
491  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
492  type = artdaq::Fragment::EmptyFragmentType;
493  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
494  fps.clear();
495 
496  gen.StopCmd(0xFFFFFFFF, 1);
497  TLOG(TLVL_INFO) << "WindowMode_Function test case END" ;
498  gen.joinThreads();
499 
500 }
501 
502 // 1. Both start and end before any data in buffer "RequestBeforeBuffer"
503 // 2. Start before buffer, end in buffer "RequestStartsBeforeBuffer"
504 // 3. Start befoer buffer, end after buffer "RequestOutsideBuffer"
505 // 4. Start and end in buffer "RequestInBuffer"
506 // 5. Start in buffer, end after buffer "RequestEndsAfterBuffer"
507 // 6. Start and end after buffer "RequestAfterBuffer"
508 BOOST_AUTO_TEST_CASE(WindowMode_RequestBeforeBuffer)
509 {
510  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
511  TLOG(TLVL_INFO) << "WindowMode_RequestBeforeBuffer test case BEGIN" ;
512  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
513  const int DELAY_TIME = 100;
514  fhicl::ParameterSet ps;
515  ps.put<int>("board_id", 1);
516  ps.put<int>("fragment_id", 1);
517  ps.put<int>("request_port", REQUEST_PORT);
518 #if MULTICAST_MODE
519  ps.put<std::string>("request_address", "227.18.12.32");
520 #else
521  ps.put<std::string>("request_address", "localhost");
522 #endif
523  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
524  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
525  ps.put<bool>("separate_data_thread", true);
526  ps.put<bool>("separate_monitoring_thread", false);
527  ps.put<int64_t>("hardware_poll_interval_us", 0);
528  ps.put<size_t>("data_buffer_depth_fragments", 5);
529  ps.put<std::string>("request_mode", "window");
530  ps.put("request_delay_ms", DELAY_TIME);
531  ps.put("send_requests", true);
532 
533  artdaq::RequestSender t(ps);
534 
536  gen.StartCmd(1, 0xFFFFFFFF, 1);
537 
538  artdaq::FragmentPtrs fps;
539  int sts;
540  artdaq::Fragment::type_t type;
541 
542  // 1. Both start and end before any data in buffer
543  // -- Should return ContainerFragment with MissingData bit set and zero Fragments
544  gen.setFireCount(9); // Buffer start is at ts 6, end at 10
545  gen.waitForFrags();
546  t.AddRequest(1, 1); // Requesting data from ts 1 to 3
547 
548  sts = gen.getNext(fps);
549  BOOST_REQUIRE_EQUAL(sts, true);
550  BOOST_REQUIRE_EQUAL(fps.size(), 1);
551  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
552  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
553  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
554  type = artdaq::Fragment::ContainerFragmentType;
555  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
556  auto cf4 = artdaq::ContainerFragment(*fps.front());
557  BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
558  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
559  type = artdaq::Fragment::EmptyFragmentType;
560  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
561 
562  gen.StopCmd(0xFFFFFFFF, 1);
563  TLOG(TLVL_INFO) << "WindowMode_RequestBeforeBuffer test case END" ;
564 
565 }
567 {
568  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
569  TLOG(TLVL_INFO) << "WindowMode_RequestStartsBeforeBuffer test case BEGIN" ;
570  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
571  const int DELAY_TIME = 100;
572  fhicl::ParameterSet ps;
573  ps.put<int>("board_id", 1);
574  ps.put<int>("fragment_id", 1);
575  ps.put<int>("request_port", REQUEST_PORT);
576 #if MULTICAST_MODE
577  ps.put<std::string>("request_address", "227.18.12.32");
578 #else
579  ps.put<std::string>("request_address", "localhost");
580 #endif
581  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
582  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
583  ps.put<bool>("separate_data_thread", true);
584  ps.put<bool>("separate_monitoring_thread", false);
585  ps.put<int64_t>("hardware_poll_interval_us", 0);
586  ps.put<size_t>("data_buffer_depth_fragments", 5);
587  ps.put<std::string>("request_mode", "window");
588  ps.put("request_delay_ms", DELAY_TIME);
589  ps.put("send_requests", true);
590 
591  artdaq::RequestSender t(ps);
592 
594  gen.StartCmd(1, 0xFFFFFFFF, 1);
595 
596  artdaq::FragmentPtrs fps;
597  int sts;
598  artdaq::Fragment::type_t type;
599 
600  gen.waitForFrags();
601  gen.setFireCount(9); // Buffer contains 6 to 10
602  gen.waitForFrags();
603 
604  // 2. Start before buffer, end in buffer
605  // -- Should return ContainerFragment with MissingData bit set and one or more Fragments
606  t.AddRequest(1, 4); // Requesting data from ts 4 to 6
607 
608  sts = gen.getNext(fps);
609  BOOST_REQUIRE_EQUAL(sts, true);
610  BOOST_REQUIRE_EQUAL(fps.size(), 1);
611  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
612  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
613  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
614  type = artdaq::Fragment::ContainerFragmentType;
615  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
616  auto cf4 = artdaq::ContainerFragment(*fps.front());
617  BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
618  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
619  type = artdaq::Fragment::FirstUserFragmentType;
620  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
621 
622  gen.StopCmd(0xFFFFFFFF, 1);
623  gen.joinThreads();
624  TLOG(TLVL_INFO) << "WindowMode_RequestStartsBeforeBuffer test case END" ;
625 
626 }
627 BOOST_AUTO_TEST_CASE(WindowMode_RequestOutsideBuffer)
628 {
629  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
630  TLOG(TLVL_INFO) << "WindowMode_RequestOutsideBuffer test case BEGIN" ;
631  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
632  const int DELAY_TIME = 100;
633  fhicl::ParameterSet ps;
634  ps.put<int>("board_id", 1);
635  ps.put<int>("fragment_id", 1);
636  ps.put<int>("request_port", REQUEST_PORT);
637 #if MULTICAST_MODE
638  ps.put<std::string>("request_address", "227.18.12.32");
639 #else
640  ps.put<std::string>("request_address", "localhost");
641 #endif
642  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
643  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 4);
644  ps.put<size_t>("window_close_timeout_us", 500000);
645  ps.put<bool>("separate_data_thread", true);
646  ps.put<bool>("separate_monitoring_thread", false);
647  ps.put<int64_t>("hardware_poll_interval_us", 0);
648  ps.put<size_t>("data_buffer_depth_fragments", 5);
649  ps.put<std::string>("request_mode", "window");
650  ps.put("request_delay_ms", DELAY_TIME);
651  ps.put("send_requests", true);
652 
653  artdaq::RequestSender t(ps);
654 
656  gen.StartCmd(1, 0xFFFFFFFF, 1);
657 
658  artdaq::FragmentPtrs fps;
659  int sts;
660  artdaq::Fragment::type_t type;
661 
662  gen.waitForFrags();
663  gen.setFireCount(9); // Buffer contains 6 to 10
664  gen.waitForFrags();
665 
666  // 3. Start before buffer, end after buffer
667  // -- Should not return until buffer passes end or timeout (check both cases), MissingData bit set
668 
669  t.AddRequest(1, 6); // Requesting data from ts 6 to 9, buffer will contain 10
670  sts = gen.getNext(fps);
671  BOOST_REQUIRE_EQUAL(sts, true);
672  BOOST_REQUIRE_EQUAL(fps.size(), 1);
673  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
674  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 6);
675  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
676  type = artdaq::Fragment::ContainerFragmentType;
677  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
678  auto cf = artdaq::ContainerFragment(*fps.front());
679  BOOST_REQUIRE_EQUAL(cf.block_count(), 4);
680  BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
681  type = artdaq::Fragment::FirstUserFragmentType;
682  BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
683  fps.clear();
684 
685  t.AddRequest(2, 9); // Requesting data from ts 9 to 12
686  sts = gen.getNext(fps);
687  BOOST_REQUIRE_EQUAL(sts, true);
688  BOOST_REQUIRE_EQUAL(fps.size(), 0);
689 
690  gen.setFireCount(3); // Buffer start is at ts 10, end at 13
691  gen.waitForFrags();
692 
693  sts = gen.getNext(fps);
694  BOOST_REQUIRE_EQUAL(sts, true);
695  BOOST_REQUIRE_EQUAL(fps.size(), 1);
696  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
697  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 9);
698  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
699  type = artdaq::Fragment::ContainerFragmentType;
700  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
701  auto cf2 = artdaq::ContainerFragment(*fps.front());
702  BOOST_REQUIRE_EQUAL(cf2.block_count(), 3);
703  BOOST_REQUIRE_EQUAL(cf2.missing_data(), true);
704  type = artdaq::Fragment::FirstUserFragmentType;
705  BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
706  fps.clear();
707 
708 
709 
710  t.AddRequest(3, 12); // Requesting data from ts 11 to 14
711 
712  sts = gen.getNext(fps);
713  BOOST_REQUIRE_EQUAL(sts, true);
714  BOOST_REQUIRE_EQUAL(fps.size(), 0);
715 
716  usleep(550000);
717 
718  sts = gen.getNext(fps);
719  BOOST_REQUIRE_EQUAL(sts, true);
720  BOOST_REQUIRE_EQUAL(fps.size(), 1);
721  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
722  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 12);
723  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
724  type = artdaq::Fragment::ContainerFragmentType;
725  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
726  auto cf4 = artdaq::ContainerFragment(*fps.front());
727  BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
728  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
729  type = artdaq::Fragment::FirstUserFragmentType;
730  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
731 
732  gen.StopCmd(0xFFFFFFFF, 1);
733  gen.joinThreads();
734  TLOG(TLVL_INFO) << "WindowMode_RequestOutsideBuffer test case END" ;
735 
736 }
737 BOOST_AUTO_TEST_CASE(WindowMode_RequestInBuffer)
738 {
739  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
740  TLOG(TLVL_INFO) << "WindowMode_RequestInBuffer test case BEGIN" ;
741  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
742  const int DELAY_TIME = 100;
743  fhicl::ParameterSet ps;
744  ps.put<int>("board_id", 1);
745  ps.put<int>("fragment_id", 1);
746  ps.put<int>("request_port", REQUEST_PORT);
747 #if MULTICAST_MODE
748  ps.put<std::string>("request_address", "227.18.12.32");
749 #else
750  ps.put<std::string>("request_address", "localhost");
751 #endif
752  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
753  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
754  ps.put<bool>("separate_data_thread", true);
755  ps.put<bool>("separate_monitoring_thread", false);
756  ps.put<int64_t>("hardware_poll_interval_us", 0);
757  ps.put<size_t>("data_buffer_depth_fragments", 5);
758  ps.put<std::string>("request_mode", "window");
759  ps.put("request_delay_ms", DELAY_TIME);
760  ps.put("send_requests", true);
761 
762  artdaq::RequestSender t(ps);
763 
765  gen.StartCmd(1, 0xFFFFFFFF, 1);
766 
767  artdaq::FragmentPtrs fps;
768  int sts;
769  artdaq::Fragment::type_t type;
770  gen.waitForFrags();
771 
772  // 4. Start and end in buffer
773  // -- Should return ContainerFragment with one or more Fragments
774  gen.setFireCount(5); // Buffer start is at ts 2, end at 6
775  gen.waitForFrags();
776  t.AddRequest(1, 3); // Requesting data from ts 3 to 5
777 
778  sts = gen.getNext(fps);
779  BOOST_REQUIRE_EQUAL(sts, true);
780  BOOST_REQUIRE_EQUAL(fps.size(), 1);
781  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
782  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
783  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
784  type = artdaq::Fragment::ContainerFragmentType;
785  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
786  auto cf4 = artdaq::ContainerFragment(*fps.front());
787  BOOST_REQUIRE_EQUAL(cf4.block_count(), 3);
788  BOOST_REQUIRE_EQUAL(cf4.missing_data(), false);
789  type = artdaq::Fragment::FirstUserFragmentType;
790  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
791 
792  gen.StopCmd(0xFFFFFFFF, 1);
793  TLOG(TLVL_INFO) << "WindowMode_RequestInBuffer test case END" ;
794 
795 }
797 {
798  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
799  TLOG(TLVL_INFO) << "WindowMode_RequestEndsAfterBuffer test case BEGIN" ;
800  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
801  const int DELAY_TIME = 100;
802  fhicl::ParameterSet ps;
803  ps.put<int>("board_id", 1);
804  ps.put<int>("fragment_id", 1);
805  ps.put<int>("request_port", REQUEST_PORT);
806 #if MULTICAST_MODE
807  ps.put<std::string>("request_address", "227.18.12.32");
808 #else
809  ps.put<std::string>("request_address", "localhost");
810 #endif
811  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
812  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
813  ps.put<size_t>("window_close_timeout_us", 500000);
814  ps.put<bool>("separate_data_thread", true);
815  ps.put<bool>("separate_monitoring_thread", false);
816  ps.put<int64_t>("hardware_poll_interval_us", 0);
817  ps.put<size_t>("data_buffer_depth_fragments", 5);
818  ps.put<std::string>("request_mode", "window");
819  ps.put("request_delay_ms", DELAY_TIME);
820  ps.put("send_requests", true);
821 
822  artdaq::RequestSender t(ps);
823 
825  gen.StartCmd(1, 0xFFFFFFFF, 1);
826 
827  artdaq::FragmentPtrs fps;
828  int sts;
829  artdaq::Fragment::type_t type;
830  gen.waitForFrags();
831  gen.setFireCount(5); // Buffer contains 2 to 6
832  gen.waitForFrags();
833 
834  // 5. Start in buffer, end after buffer
835  // -- Should not return until buffer passes end or timeout (check both cases). MissingData bit set if timeout
836  t.AddRequest(1, 5); // Requesting data from ts 5 to 7
837  sts = gen.getNext(fps);
838  BOOST_REQUIRE_EQUAL(sts, true);
839  BOOST_REQUIRE_EQUAL(fps.size(), 0);
840 
841  gen.setFireCount(2); // Buffer contains 4 to 8
842  gen.waitForFrags();
843  sts = gen.getNext(fps);
844  BOOST_REQUIRE_EQUAL(sts, true);
845  BOOST_REQUIRE_EQUAL(fps.size(), 1);
846  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
847  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
848  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
849  type = artdaq::Fragment::ContainerFragmentType;
850  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
851  auto cf = artdaq::ContainerFragment(*fps.front());
852  BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
853  BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
854  type = artdaq::Fragment::FirstUserFragmentType;
855  BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
856  fps.clear();
857 
858  t.AddRequest(2, 8); // Requesting data from ts 8 to 10
859 
860  sts = gen.getNext(fps);
861  BOOST_REQUIRE_EQUAL(sts, true);
862  BOOST_REQUIRE_EQUAL(fps.size(), 0);
863 
864  usleep(550000);
865 
866  sts = gen.getNext(fps);
867  BOOST_REQUIRE_EQUAL(sts, true);
868  BOOST_REQUIRE_EQUAL(fps.size(), 1);
869  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
870  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 8);
871  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
872  type = artdaq::Fragment::ContainerFragmentType;
873  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
874  auto cf4 = artdaq::ContainerFragment(*fps.front());
875  BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
876  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
877  type = artdaq::Fragment::FirstUserFragmentType;
878  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
879 
880  gen.StopCmd(0xFFFFFFFF, 1);
881  gen.joinThreads();
882  TLOG(TLVL_INFO) << "WindowMode_RequestEndsAfterBuffer test case END" ;
883 
884 }
885 BOOST_AUTO_TEST_CASE(WindowMode_RequestAfterBuffer)
886 {
887  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
888  TLOG(TLVL_INFO) << "WindowMode_RequestAfterBuffer test case BEGIN" ;
889  const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
890  const int DELAY_TIME = 100;
891  fhicl::ParameterSet ps;
892  ps.put<int>("board_id", 1);
893  ps.put<int>("fragment_id", 1);
894  ps.put<int>("request_port", REQUEST_PORT);
895 #if MULTICAST_MODE
896  ps.put<std::string>("request_address", "227.18.12.32");
897 #else
898  ps.put<std::string>("request_address", "localhost");
899 #endif
900  ps.put<artdaq::Fragment::timestamp_t>("request_window_offset", 0);
901  ps.put<artdaq::Fragment::timestamp_t>("request_window_width", 3);
902  ps.put<size_t>("window_close_timeout_us", 500000);
903  ps.put<bool>("separate_data_thread", true);
904  ps.put<bool>("separate_monitoring_thread", false);
905  ps.put<int64_t>("hardware_poll_interval_us", 0);
906  ps.put<size_t>("data_buffer_depth_fragments", 5);
907  ps.put<std::string>("request_mode", "window");
908  ps.put("request_delay_ms", DELAY_TIME);
909  ps.put("send_requests", true);
910 
911  artdaq::RequestSender t(ps);
912 
914  gen.StartCmd(1, 0xFFFFFFFF, 1);
915 
916  artdaq::FragmentPtrs fps;
917  int sts;
918  artdaq::Fragment::type_t type;
919  gen.waitForFrags();
920 
921  // 6. Start and end after buffer
922  // -- Should not return until buffer passes end or timeout (check both cases). MissingData bit set if timeout
923  gen.setFireCount(9); // Buffer start is 6, end at 10
924  gen.waitForFrags();
925  t.AddRequest(1, 11); // Requesting data from ts 11 to 13
926 
927  sts = gen.getNext(fps);
928  BOOST_REQUIRE_EQUAL(sts, true);
929  BOOST_REQUIRE_EQUAL(fps.size(), 0);
930  gen.setFireCount(1); // Buffer start is 7, end at 11
931  gen.waitForFrags();
932  sts = gen.getNext(fps);
933  BOOST_REQUIRE_EQUAL(sts, true);
934  BOOST_REQUIRE_EQUAL(fps.size(), 0);
935 
936  gen.setFireCount(3); // Buffer start is 10, end at 14
937  gen.waitForFrags();
938  sts = gen.getNext(fps);
939  BOOST_REQUIRE_EQUAL(sts, true);
940  BOOST_REQUIRE_EQUAL(fps.size(), 1);
941  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
942  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 11);
943  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
944  type = artdaq::Fragment::ContainerFragmentType;
945  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
946  auto cf = artdaq::ContainerFragment(*fps.front());
947  BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
948  BOOST_REQUIRE_EQUAL(cf.missing_data(), false);
949  type = artdaq::Fragment::FirstUserFragmentType;
950  BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
951  fps.clear();
952 
953  t.AddRequest(2, 16); // Requesting data from ts 15 to 17
954  sts = gen.getNext(fps);
955  BOOST_REQUIRE_EQUAL(sts, true);
956  BOOST_REQUIRE_EQUAL(fps.size(), 0);
957 
958  usleep(550000);
959 
960  sts = gen.getNext(fps);
961  BOOST_REQUIRE_EQUAL(sts, true);
962  BOOST_REQUIRE_EQUAL(fps.size(), 1);
963  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
964  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 16);
965  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
966  type = artdaq::Fragment::ContainerFragmentType;
967  BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
968  auto cf4 = artdaq::ContainerFragment(*fps.front());
969  BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
970  BOOST_REQUIRE_EQUAL(cf4.missing_data(), true);
971  type = artdaq::Fragment::EmptyFragmentType;
972  BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
973 
974  gen.StopCmd(0xFFFFFFFF, 1);
975  gen.joinThreads();
976  TLOG(TLVL_INFO) << "WindowMode_RequestAfterBuffer test case END" ;
977 
978 }
979 
980 BOOST_AUTO_TEST_CASE(HardwareFailure_NonThreaded)
981 {
982  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
983  TLOG(TLVL_INFO) << "HardwareFailure_NonThreaded test case BEGIN" ;
984  fhicl::ParameterSet ps;
985  ps.put<int>("board_id", 1);
986  ps.put<int>("fragment_id", 1);
987  ps.put<bool>("separate_data_thread", false);
988  ps.put<bool>("separate_monitoring_thread", false);
989  ps.put<int64_t>("hardware_poll_interval_us", 10);
990 
992  gen.StartCmd(1, 0xFFFFFFFF, 1);
993 
994  artdaq::FragmentPtrs fps;
995  auto sts = gen.getNext(fps);
996  BOOST_REQUIRE_EQUAL(sts, true);
997  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
998  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
999  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
1000  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1001  fps.clear();
1002 
1003  gen.setFireCount(1);
1004  gen.setHwFail();
1005  usleep(10000);
1006  sts = gen.getNext(fps);
1007  BOOST_REQUIRE_EQUAL(sts, false);
1008  BOOST_REQUIRE_EQUAL(fps.size(), 0);
1009 
1010  gen.StopCmd(0xFFFFFFFF, 1);
1011  gen.joinThreads();
1012  TLOG(TLVL_INFO) << "HardwareFailure_NonThreaded test case END" ;
1013 }
1014 
1015 BOOST_AUTO_TEST_CASE(HardwareFailure_Threaded)
1016 {
1017  artdaq::configureMessageFacility("CommandableFragmentGenerator_t");
1018  TLOG(TLVL_INFO) << "HardwareFailure_Threaded test case BEGIN" ;
1019  fhicl::ParameterSet ps;
1020  ps.put<int>("board_id", 1);
1021  ps.put<int>("fragment_id", 1);
1022  ps.put<bool>("separate_data_thread", true);
1023  ps.put<bool>("separate_monitoring_thread", true);
1024  ps.put<int64_t>("hardware_poll_interval_us", 750000);
1025 
1027  gen.StartCmd(1, 0xFFFFFFFF, 1);
1028 
1029 
1030 
1031  artdaq::FragmentPtrs fps;
1032  auto sts = gen.getNext(fps);
1033  BOOST_REQUIRE_EQUAL(sts, true);
1034  BOOST_REQUIRE_EQUAL(fps.size(), 1u);
1035  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
1036  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
1037  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1038  fps.clear();
1039 
1040  gen.setFireCount(1);
1041  gen.setHwFail();
1042  sts = gen.getNext(fps);
1043  BOOST_REQUIRE_EQUAL(sts, true);
1044  BOOST_REQUIRE_EQUAL(fps.size(), 1);
1045  BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
1046  BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 2);
1047  BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1048 
1049  fps.clear();
1050  sleep(1);
1051  gen.setFireCount(1);
1052  sts = gen.getNext(fps);
1053  BOOST_REQUIRE_EQUAL(sts, false);
1054  BOOST_REQUIRE_EQUAL(fps.size(), 0);
1055 
1056  gen.StopCmd(0xFFFFFFFF, 1);
1057  gen.joinThreads();
1058  TLOG(TLVL_INFO) << "HardwareFailure_Threaded test case END" ;
1059 }
1060 
1061 BOOST_AUTO_TEST_SUITE_END()
bool getNext_(artdaq::FragmentPtrs &frags) override
Generate data and return it to CommandableFragmentGenerator.
CommandableFragmentGenerator derived class for testing.
The RequestSender contains methods used to send data requests and Routing tokens. ...
void StopCmd(uint64_t timeout, uint64_t timestamp)
Stop the CommandableFragmentGenerator.
CommandableFragmentGeneratorTest(const fhicl::ParameterSet &ps)
CommandableFragmentGeneratorTest Constructor.
void StartCmd(int run, uint64_t timeout, uint64_t timestamp)
Start the CommandableFragmentGenerator.
bool getNext(FragmentPtrs &output) overridefinal
getNext calls either applyRequests or getNext_ to get any data that is ready to be sent to the EventB...
bool checkHWStatus_() override
Returns whether the hwFail flag has not been set.
void stopNoMutex() override
Perform immediate stop actions. No-Op.
void start() override
Perform start actions. No-Op.
CommandableFragmentGenerator is a FragmentGenerator-derived abstract class that defines the interface...
void resume() override
Perform resume actions. No-Op.
void pause() override
Perform pause actions. No-Op.
void stop() override
Perform stop actions. No-Op.
void AddRequest(Fragment::sequence_id_t seqID, Fragment::timestamp_t timestamp)
Add a request to the request list.
void waitForFrags()
Wait for all fragments generated to be read by the CommandableFragmentGenerator
void joinThreads()
Join any data-taking threads. Should be called when destructing CommandableFragmentGenerator.
void setFireCount(size_t count)
Have getNext_ generate count fragments.