1 #define BOOST_TEST_MODULE CommandableFragmentGenerator_t
2 #include <boost/test/auto_unit_test.hpp>
4 #include "artdaq-core/Data/Fragment.hh"
5 #include "artdaq-core/Data/ContainerFragment.hh"
6 #include "artdaq/Application/CommandableFragmentGenerator.hh"
7 #include "artdaq/DAQrate/RequestSender.hh"
9 #define MULTICAST_MODE 0
13 class CommandableFragmentGeneratorTest;
38 bool getNext_(artdaq::FragmentPtrs& frags)
override;
49 void start()
override;
64 void pause()
override;
87 auto start_time = std::chrono::steady_clock::now();
88 while (fireCount_ > 0) { usleep(1000); }
89 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"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" << TLOG_ENDL;
92 std::atomic<size_t> fireCount_;
93 std::atomic<bool> hwFail_;
94 artdaq::Fragment::timestamp_t ts_;
99 : CommandableFragmentGenerator(ps)
109 while (fireCount_ > 0)
111 frags.emplace_back(
new artdaq::Fragment(ev_counter(), fragment_id(), artdaq::Fragment::FirstUserFragmentType, ++ts_));
133 BOOST_AUTO_TEST_SUITE(CommandableFragmentGenerator_t)
137 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
138 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"Simple test case BEGIN" << TLOG_ENDL;
139 fhicl::ParameterSet ps;
140 ps.put<
int>(
"board_id", 1);
141 ps.put<
int>(
"fragment_id", 1);
143 artdaq::FragmentPtrs fps;
144 auto sts = testGen.getNext(fps);
145 BOOST_REQUIRE_EQUAL(sts,
true);
146 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
147 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
148 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
149 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
150 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"Simple test case END" << TLOG_ENDL;
155 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
156 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"IgnoreRequests test case BEGIN" << TLOG_ENDL;
157 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
158 const int DELAY_TIME = 1;
159 fhicl::ParameterSet ps;
160 ps.put<
int>(
"board_id", 1);
161 ps.put<
int>(
"fragment_id", 1);
162 ps.put<
int>(
"request_port", REQUEST_PORT);
164 ps.put<std::string>(
"request_address",
"227.18.12.29");
166 ps.put<std::string>(
"request_address",
"localhost");
168 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
169 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 0);
170 ps.put<
bool>(
"separate_data_thread",
true);
171 ps.put<
bool>(
"separate_monitoring_thread",
false);
172 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
173 ps.put<std::string>(
"request_mode",
"ignored");
174 ps.put(
"request_delay_ms", DELAY_TIME);
175 ps.put(
"send_requests",
true);
182 artdaq::FragmentPtrs fps;
184 BOOST_REQUIRE_EQUAL(sts,
true);
185 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
186 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
187 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
188 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
191 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"IgnoreRequests test case END" << TLOG_ENDL;
196 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
197 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"SingleMode test case BEGIN" << TLOG_ENDL;
198 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
199 const int DELAY_TIME = 100;
200 fhicl::ParameterSet ps;
201 ps.put<
int>(
"board_id", 1);
202 ps.put<
int>(
"fragment_id", 1);
203 ps.put<
int>(
"request_port", REQUEST_PORT);
205 ps.put<std::string>(
"request_address",
"227.18.12.30");
207 ps.put<std::string>(
"request_address",
"localhost");
209 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
210 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 0);
211 ps.put<
bool>(
"separate_data_thread",
true);
212 ps.put<
bool>(
"separate_monitoring_thread",
false);
213 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
214 ps.put<std::string>(
"request_mode",
"single");
215 ps.put(
"request_delay_ms", DELAY_TIME);
216 ps.put(
"send_requests",
true);
225 artdaq::FragmentPtrs fps;
227 auto type = artdaq::Fragment::FirstUserFragmentType;
228 BOOST_REQUIRE_EQUAL(sts,
true);
229 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
230 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
231 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
232 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
233 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
238 BOOST_REQUIRE_EQUAL(sts,
true);
239 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
240 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
241 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
242 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
243 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
250 BOOST_REQUIRE_EQUAL(sts,
true);
251 BOOST_REQUIRE_EQUAL(fps.size(), 2);
252 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
253 auto ts = artdaq::Fragment::InvalidTimestamp;
254 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
255 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
256 auto emptyType = artdaq::Fragment::EmptyFragmentType;
257 BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
259 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
260 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7);
261 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
262 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
267 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"SingleMode test case END" << TLOG_ENDL;
272 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
273 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"BufferMode test case BEGIN" << TLOG_ENDL;
274 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
275 const int DELAY_TIME = 100;
276 fhicl::ParameterSet ps;
277 ps.put<
int>(
"board_id", 1);
278 ps.put<
int>(
"fragment_id", 1);
279 ps.put<
int>(
"request_port", REQUEST_PORT);
281 ps.put<std::string>(
"request_address",
"227.18.12.31");
283 ps.put<std::string>(
"request_address",
"localhost");
285 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
286 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 0);
287 ps.put<
bool>(
"separate_data_thread",
true);
288 ps.put<
bool>(
"separate_monitoring_thread",
false);
289 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
290 ps.put<std::string>(
"request_mode",
"buffer");
291 ps.put(
"request_delay_ms", DELAY_TIME);
292 ps.put(
"send_requests",
true);
301 artdaq::FragmentPtrs fps;
303 BOOST_REQUIRE_EQUAL(sts,
true);
304 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
305 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
306 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
307 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
308 auto type = artdaq::Fragment::ContainerFragmentType;
309 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
310 BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 *
sizeof(artdaq::detail::RawEventHeader) +
sizeof(artdaq::ContainerFragment::Metadata));
311 auto cf = artdaq::ContainerFragment(*fps.front());
312 BOOST_REQUIRE_EQUAL(cf.block_count(), 1);
313 BOOST_REQUIRE_EQUAL(cf.missing_data(),
false);
314 type = artdaq::Fragment::FirstUserFragmentType;
315 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
320 BOOST_REQUIRE_EQUAL(sts,
true);
321 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
322 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
323 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
324 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
325 type = artdaq::Fragment::ContainerFragmentType;
326 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
327 auto cf2 = artdaq::ContainerFragment(*fps.front());
328 BOOST_REQUIRE_EQUAL(cf2.block_count(), 0);
329 BOOST_REQUIRE_EQUAL(cf2.missing_data(),
false);
330 type = artdaq::Fragment::EmptyFragmentType;
331 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
338 BOOST_REQUIRE_EQUAL(sts,
true);
339 BOOST_REQUIRE_EQUAL(fps.size(), 2);
341 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
342 auto ts = artdaq::Fragment::InvalidTimestamp;
343 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
344 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
345 auto emptyType = artdaq::Fragment::EmptyFragmentType;
346 BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
347 BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words());
349 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
350 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 7);
351 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
352 type = artdaq::Fragment::ContainerFragmentType;
353 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
354 auto cf3 = artdaq::ContainerFragment(*fps.front());
355 BOOST_REQUIRE_EQUAL(cf3.block_count(), 2);
356 BOOST_REQUIRE_EQUAL(cf3.missing_data(),
false);
357 type = artdaq::Fragment::FirstUserFragmentType;
358 BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type);
366 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"BufferMode test case END" << TLOG_ENDL;
371 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
372 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_Function test case BEGIN" << TLOG_ENDL;
373 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
374 const int DELAY_TIME = 100;
375 fhicl::ParameterSet ps;
376 ps.put<
int>(
"board_id", 1);
377 ps.put<
int>(
"fragment_id", 1);
378 ps.put<
int>(
"request_port", REQUEST_PORT);
380 ps.put<std::string>(
"request_address",
"227.18.12.32");
382 ps.put<std::string>(
"request_address",
"localhost");
384 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
385 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 0);
386 ps.put<
bool>(
"separate_data_thread",
true);
387 ps.put<
bool>(
"separate_monitoring_thread",
false);
388 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
389 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
390 ps.put<std::string>(
"request_mode",
"window");
391 ps.put(
"request_delay_ms", DELAY_TIME);
392 ps.put(
"send_requests",
true);
400 artdaq::FragmentPtrs fps;
402 BOOST_REQUIRE_EQUAL(sts,
true);
403 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
404 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
405 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
406 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
407 auto type = artdaq::Fragment::ContainerFragmentType;
408 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
409 BOOST_REQUIRE_GE(fps.front()->sizeBytes(), 2 *
sizeof(artdaq::detail::RawEventHeader) +
sizeof(artdaq::ContainerFragment::Metadata));
410 auto cf = artdaq::ContainerFragment(*fps.front());
411 BOOST_REQUIRE_EQUAL(cf.block_count(), 1);
412 BOOST_REQUIRE_EQUAL(cf.missing_data(),
false);
413 type = artdaq::Fragment::FirstUserFragmentType;
414 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
420 BOOST_REQUIRE_EQUAL(sts,
true);
421 BOOST_REQUIRE_EQUAL(fps.size(), 0);
426 BOOST_REQUIRE_EQUAL(sts,
true);
427 BOOST_REQUIRE_EQUAL(fps.size(), 1);
428 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
429 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 2);
430 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
431 type = artdaq::Fragment::ContainerFragmentType;
432 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
433 auto cf2 = artdaq::ContainerFragment(*fps.front());
434 BOOST_REQUIRE_EQUAL(cf2.block_count(), 1);
435 BOOST_REQUIRE_EQUAL(cf2.missing_data(),
false);
436 type = artdaq::Fragment::FirstUserFragmentType;
437 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
445 BOOST_REQUIRE_EQUAL(sts,
true);
446 BOOST_REQUIRE_EQUAL(fps.size(), 1);
450 BOOST_REQUIRE_EQUAL(sts,
true);
451 BOOST_REQUIRE_EQUAL(fps.size(), 2);
454 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
455 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
456 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
457 type = artdaq::Fragment::ContainerFragmentType;
458 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
459 auto cf3 = artdaq::ContainerFragment(*fps.front());
460 BOOST_REQUIRE_EQUAL(cf3.block_count(), 1);
461 BOOST_REQUIRE_EQUAL(cf3.missing_data(),
false);
462 type = artdaq::Fragment::FirstUserFragmentType;
463 BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type);
466 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
467 auto ts = artdaq::Fragment::InvalidTimestamp;
468 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
469 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
470 auto emptyType = artdaq::Fragment::EmptyFragmentType;
471 BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
472 BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words());
480 BOOST_REQUIRE_EQUAL(sts,
true);
481 BOOST_REQUIRE_EQUAL(fps.size(), 1);
482 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
483 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
484 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 5);
485 type = artdaq::Fragment::ContainerFragmentType;
486 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
487 auto cf4 = artdaq::ContainerFragment(*fps.front());
488 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
489 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
490 type = artdaq::Fragment::EmptyFragmentType;
491 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
495 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_Function test case END" << TLOG_ENDL;
508 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
509 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestBeforeBuffer test case BEGIN" << TLOG_ENDL;
510 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
511 const int DELAY_TIME = 100;
512 fhicl::ParameterSet ps;
513 ps.put<
int>(
"board_id", 1);
514 ps.put<
int>(
"fragment_id", 1);
515 ps.put<
int>(
"request_port", REQUEST_PORT);
517 ps.put<std::string>(
"request_address",
"227.18.12.32");
519 ps.put<std::string>(
"request_address",
"localhost");
521 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
522 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
523 ps.put<
bool>(
"separate_data_thread",
true);
524 ps.put<
bool>(
"separate_monitoring_thread",
false);
525 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
526 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
527 ps.put<std::string>(
"request_mode",
"window");
528 ps.put(
"request_delay_ms", DELAY_TIME);
529 ps.put(
"send_requests",
true);
536 artdaq::FragmentPtrs fps;
538 artdaq::Fragment::type_t type;
547 BOOST_REQUIRE_EQUAL(sts,
true);
548 BOOST_REQUIRE_EQUAL(fps.size(), 1);
549 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
550 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
551 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
552 type = artdaq::Fragment::ContainerFragmentType;
553 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
554 auto cf4 = artdaq::ContainerFragment(*fps.front());
555 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
556 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
557 type = artdaq::Fragment::EmptyFragmentType;
558 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
561 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestBeforeBuffer test case END" << TLOG_ENDL;
566 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
567 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestStartsBeforeBuffer test case BEGIN" << TLOG_ENDL;
568 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
569 const int DELAY_TIME = 100;
570 fhicl::ParameterSet ps;
571 ps.put<
int>(
"board_id", 1);
572 ps.put<
int>(
"fragment_id", 1);
573 ps.put<
int>(
"request_port", REQUEST_PORT);
575 ps.put<std::string>(
"request_address",
"227.18.12.32");
577 ps.put<std::string>(
"request_address",
"localhost");
579 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
580 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
581 ps.put<
bool>(
"separate_data_thread",
true);
582 ps.put<
bool>(
"separate_monitoring_thread",
false);
583 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
584 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
585 ps.put<std::string>(
"request_mode",
"window");
586 ps.put(
"request_delay_ms", DELAY_TIME);
587 ps.put(
"send_requests",
true);
594 artdaq::FragmentPtrs fps;
596 artdaq::Fragment::type_t type;
607 BOOST_REQUIRE_EQUAL(sts,
true);
608 BOOST_REQUIRE_EQUAL(fps.size(), 1);
609 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
610 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
611 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
612 type = artdaq::Fragment::ContainerFragmentType;
613 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
614 auto cf4 = artdaq::ContainerFragment(*fps.front());
615 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
616 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
617 type = artdaq::Fragment::FirstUserFragmentType;
618 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
622 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestStartsBeforeBuffer test case END" << TLOG_ENDL;
627 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
628 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestOutsideBuffer test case BEGIN" << TLOG_ENDL;
629 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
630 const int DELAY_TIME = 100;
631 fhicl::ParameterSet ps;
632 ps.put<
int>(
"board_id", 1);
633 ps.put<
int>(
"fragment_id", 1);
634 ps.put<
int>(
"request_port", REQUEST_PORT);
636 ps.put<std::string>(
"request_address",
"227.18.12.32");
638 ps.put<std::string>(
"request_address",
"localhost");
640 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
641 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 4);
642 ps.put<
size_t>(
"window_close_timeout_us", 500000);
643 ps.put<
bool>(
"separate_data_thread",
true);
644 ps.put<
bool>(
"separate_monitoring_thread",
false);
645 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
646 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
647 ps.put<std::string>(
"request_mode",
"window");
648 ps.put(
"request_delay_ms", DELAY_TIME);
649 ps.put(
"send_requests",
true);
656 artdaq::FragmentPtrs fps;
658 artdaq::Fragment::type_t type;
669 BOOST_REQUIRE_EQUAL(sts,
true);
670 BOOST_REQUIRE_EQUAL(fps.size(), 1);
671 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
672 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 6);
673 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
674 type = artdaq::Fragment::ContainerFragmentType;
675 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
676 auto cf = artdaq::ContainerFragment(*fps.front());
677 BOOST_REQUIRE_EQUAL(cf.block_count(), 4);
678 BOOST_REQUIRE_EQUAL(cf.missing_data(),
false);
679 type = artdaq::Fragment::FirstUserFragmentType;
680 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
685 BOOST_REQUIRE_EQUAL(sts,
true);
686 BOOST_REQUIRE_EQUAL(fps.size(), 0);
692 BOOST_REQUIRE_EQUAL(sts,
true);
693 BOOST_REQUIRE_EQUAL(fps.size(), 1);
694 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
695 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 9);
696 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
697 type = artdaq::Fragment::ContainerFragmentType;
698 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
699 auto cf2 = artdaq::ContainerFragment(*fps.front());
700 BOOST_REQUIRE_EQUAL(cf2.block_count(), 3);
701 BOOST_REQUIRE_EQUAL(cf2.missing_data(),
true);
702 type = artdaq::Fragment::FirstUserFragmentType;
703 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
711 BOOST_REQUIRE_EQUAL(sts,
true);
712 BOOST_REQUIRE_EQUAL(fps.size(), 0);
717 BOOST_REQUIRE_EQUAL(sts,
true);
718 BOOST_REQUIRE_EQUAL(fps.size(), 1);
719 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
720 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 12);
721 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
722 type = artdaq::Fragment::ContainerFragmentType;
723 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
724 auto cf4 = artdaq::ContainerFragment(*fps.front());
725 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
726 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
727 type = artdaq::Fragment::FirstUserFragmentType;
728 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
732 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestOutsideBuffer test case END" << TLOG_ENDL;
737 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
738 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestInBuffer test case BEGIN" << TLOG_ENDL;
739 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
740 const int DELAY_TIME = 100;
741 fhicl::ParameterSet ps;
742 ps.put<
int>(
"board_id", 1);
743 ps.put<
int>(
"fragment_id", 1);
744 ps.put<
int>(
"request_port", REQUEST_PORT);
746 ps.put<std::string>(
"request_address",
"227.18.12.32");
748 ps.put<std::string>(
"request_address",
"localhost");
750 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
751 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
752 ps.put<
bool>(
"separate_data_thread",
true);
753 ps.put<
bool>(
"separate_monitoring_thread",
false);
754 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
755 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
756 ps.put<std::string>(
"request_mode",
"window");
757 ps.put(
"request_delay_ms", DELAY_TIME);
758 ps.put(
"send_requests",
true);
765 artdaq::FragmentPtrs fps;
767 artdaq::Fragment::type_t type;
777 BOOST_REQUIRE_EQUAL(sts,
true);
778 BOOST_REQUIRE_EQUAL(fps.size(), 1);
779 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
780 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
781 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
782 type = artdaq::Fragment::ContainerFragmentType;
783 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
784 auto cf4 = artdaq::ContainerFragment(*fps.front());
785 BOOST_REQUIRE_EQUAL(cf4.block_count(), 3);
786 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
false);
787 type = artdaq::Fragment::FirstUserFragmentType;
788 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
791 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestInBuffer test case END" << TLOG_ENDL;
796 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
797 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestEndsAfterBuffer test case BEGIN" << TLOG_ENDL;
798 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
799 const int DELAY_TIME = 100;
800 fhicl::ParameterSet ps;
801 ps.put<
int>(
"board_id", 1);
802 ps.put<
int>(
"fragment_id", 1);
803 ps.put<
int>(
"request_port", REQUEST_PORT);
805 ps.put<std::string>(
"request_address",
"227.18.12.32");
807 ps.put<std::string>(
"request_address",
"localhost");
809 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
810 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
811 ps.put<
size_t>(
"window_close_timeout_us", 500000);
812 ps.put<
bool>(
"separate_data_thread",
true);
813 ps.put<
bool>(
"separate_monitoring_thread",
false);
814 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
815 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
816 ps.put<std::string>(
"request_mode",
"window");
817 ps.put(
"request_delay_ms", DELAY_TIME);
818 ps.put(
"send_requests",
true);
825 artdaq::FragmentPtrs fps;
827 artdaq::Fragment::type_t type;
836 BOOST_REQUIRE_EQUAL(sts,
true);
837 BOOST_REQUIRE_EQUAL(fps.size(), 0);
842 BOOST_REQUIRE_EQUAL(sts,
true);
843 BOOST_REQUIRE_EQUAL(fps.size(), 1);
844 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
845 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
846 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
847 type = artdaq::Fragment::ContainerFragmentType;
848 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
849 auto cf = artdaq::ContainerFragment(*fps.front());
850 BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
851 BOOST_REQUIRE_EQUAL(cf.missing_data(),
false);
852 type = artdaq::Fragment::FirstUserFragmentType;
853 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
859 BOOST_REQUIRE_EQUAL(sts,
true);
860 BOOST_REQUIRE_EQUAL(fps.size(), 0);
865 BOOST_REQUIRE_EQUAL(sts,
true);
866 BOOST_REQUIRE_EQUAL(fps.size(), 1);
867 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
868 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 8);
869 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
870 type = artdaq::Fragment::ContainerFragmentType;
871 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
872 auto cf4 = artdaq::ContainerFragment(*fps.front());
873 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
874 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
875 type = artdaq::Fragment::FirstUserFragmentType;
876 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
880 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestEndsAfterBuffer test case END" << TLOG_ENDL;
885 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
886 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestAfterBuffer test case BEGIN" << TLOG_ENDL;
887 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
888 const int DELAY_TIME = 100;
889 fhicl::ParameterSet ps;
890 ps.put<
int>(
"board_id", 1);
891 ps.put<
int>(
"fragment_id", 1);
892 ps.put<
int>(
"request_port", REQUEST_PORT);
894 ps.put<std::string>(
"request_address",
"227.18.12.32");
896 ps.put<std::string>(
"request_address",
"localhost");
898 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
899 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
900 ps.put<
size_t>(
"window_close_timeout_us", 500000);
901 ps.put<
bool>(
"separate_data_thread",
true);
902 ps.put<
bool>(
"separate_monitoring_thread",
false);
903 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
904 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
905 ps.put<std::string>(
"request_mode",
"window");
906 ps.put(
"request_delay_ms", DELAY_TIME);
907 ps.put(
"send_requests",
true);
914 artdaq::FragmentPtrs fps;
916 artdaq::Fragment::type_t type;
926 BOOST_REQUIRE_EQUAL(sts,
true);
927 BOOST_REQUIRE_EQUAL(fps.size(), 0);
931 BOOST_REQUIRE_EQUAL(sts,
true);
932 BOOST_REQUIRE_EQUAL(fps.size(), 0);
937 BOOST_REQUIRE_EQUAL(sts,
true);
938 BOOST_REQUIRE_EQUAL(fps.size(), 1);
939 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
940 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 11);
941 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
942 type = artdaq::Fragment::ContainerFragmentType;
943 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
944 auto cf = artdaq::ContainerFragment(*fps.front());
945 BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
946 BOOST_REQUIRE_EQUAL(cf.missing_data(),
false);
947 type = artdaq::Fragment::FirstUserFragmentType;
948 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
953 BOOST_REQUIRE_EQUAL(sts,
true);
954 BOOST_REQUIRE_EQUAL(fps.size(), 0);
959 BOOST_REQUIRE_EQUAL(sts,
true);
960 BOOST_REQUIRE_EQUAL(fps.size(), 1);
961 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
962 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 16);
963 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
964 type = artdaq::Fragment::ContainerFragmentType;
965 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
966 auto cf4 = artdaq::ContainerFragment(*fps.front());
967 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
968 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
969 type = artdaq::Fragment::EmptyFragmentType;
970 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
974 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestAfterBuffer test case END" << TLOG_ENDL;
980 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
981 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"HardwareFailure_NonThreaded test case BEGIN" << TLOG_ENDL;
982 fhicl::ParameterSet ps;
983 ps.put<
int>(
"board_id", 1);
984 ps.put<
int>(
"fragment_id", 1);
985 ps.put<
bool>(
"separate_data_thread",
false);
986 ps.put<
bool>(
"separate_monitoring_thread",
false);
987 ps.put<int64_t>(
"hardware_poll_interval_us", 10);
990 gen.StartCmd(1, 0xFFFFFFFF, 1);
992 artdaq::FragmentPtrs fps;
993 auto sts = gen.getNext(fps);
994 BOOST_REQUIRE_EQUAL(sts,
true);
995 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
996 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
997 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
998 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1001 gen.setFireCount(1);
1004 sts = gen.getNext(fps);
1005 BOOST_REQUIRE_EQUAL(sts,
false);
1006 BOOST_REQUIRE_EQUAL(fps.size(), 0);
1008 gen.StopCmd(0xFFFFFFFF, 1);
1010 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"HardwareFailure_NonThreaded test case END" << TLOG_ENDL;
1015 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
1016 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"HardwareFailure_Threaded test case BEGIN" << TLOG_ENDL;
1017 fhicl::ParameterSet ps;
1018 ps.put<
int>(
"board_id", 1);
1019 ps.put<
int>(
"fragment_id", 1);
1020 ps.put<
bool>(
"separate_data_thread",
true);
1021 ps.put<
bool>(
"separate_monitoring_thread",
true);
1022 ps.put<int64_t>(
"hardware_poll_interval_us", 750000);
1025 gen.StartCmd(1, 0xFFFFFFFF, 1);
1029 artdaq::FragmentPtrs fps;
1030 auto sts = gen.getNext(fps);
1031 BOOST_REQUIRE_EQUAL(sts,
true);
1032 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
1033 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
1034 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
1035 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1038 gen.setFireCount(1);
1040 sts = gen.getNext(fps);
1041 BOOST_REQUIRE_EQUAL(sts,
true);
1042 BOOST_REQUIRE_EQUAL(fps.size(), 1);
1043 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
1044 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 2);
1045 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1049 gen.setFireCount(1);
1050 sts = gen.getNext(fps);
1051 BOOST_REQUIRE_EQUAL(sts,
false);
1052 BOOST_REQUIRE_EQUAL(fps.size(), 0);
1054 gen.StopCmd(0xFFFFFFFF, 1);
1056 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"HardwareFailure_Threaded test case END" << TLOG_ENDL;
1059 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 setHwFail()
Set the hwFail flag.
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.