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(), 0);
450 BOOST_REQUIRE_EQUAL(sts,
true);
451 BOOST_REQUIRE_EQUAL(fps.size(), 2);
454 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
455 auto ts = artdaq::Fragment::InvalidTimestamp;
456 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), ts);
457 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
458 auto emptyType = artdaq::Fragment::EmptyFragmentType;
459 BOOST_REQUIRE_EQUAL(fps.front()->type(), emptyType);
460 BOOST_REQUIRE_EQUAL(fps.front()->size(), artdaq::detail::RawFragmentHeader::num_words());
462 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
463 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
464 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 4);
465 type = artdaq::Fragment::ContainerFragmentType;
466 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
467 auto cf3 = artdaq::ContainerFragment(*fps.front());
468 BOOST_REQUIRE_EQUAL(cf3.block_count(), 1);
469 BOOST_REQUIRE_EQUAL(cf3.missing_data(),
false);
470 type = artdaq::Fragment::FirstUserFragmentType;
471 BOOST_REQUIRE_EQUAL(cf3.fragment_type(), type);
479 BOOST_REQUIRE_EQUAL(sts,
true);
480 BOOST_REQUIRE_EQUAL(fps.size(), 1);
481 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
482 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
483 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 5);
484 type = artdaq::Fragment::ContainerFragmentType;
485 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
486 auto cf4 = artdaq::ContainerFragment(*fps.front());
487 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
488 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
489 type = artdaq::Fragment::EmptyFragmentType;
490 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
494 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_Function test case END" << TLOG_ENDL;
507 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
508 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestBeforeBuffer test case BEGIN" << TLOG_ENDL;
509 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
510 const int DELAY_TIME = 100;
511 fhicl::ParameterSet ps;
512 ps.put<
int>(
"board_id", 1);
513 ps.put<
int>(
"fragment_id", 1);
514 ps.put<
int>(
"request_port", REQUEST_PORT);
516 ps.put<std::string>(
"request_address",
"227.18.12.32");
518 ps.put<std::string>(
"request_address",
"localhost");
520 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
521 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
522 ps.put<
bool>(
"separate_data_thread",
true);
523 ps.put<
bool>(
"separate_monitoring_thread",
false);
524 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
525 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
526 ps.put<std::string>(
"request_mode",
"window");
527 ps.put(
"request_delay_ms", DELAY_TIME);
528 ps.put(
"send_requests",
true);
535 artdaq::FragmentPtrs fps;
537 artdaq::Fragment::type_t type;
546 BOOST_REQUIRE_EQUAL(sts,
true);
547 BOOST_REQUIRE_EQUAL(fps.size(), 1);
548 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
549 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
550 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
551 type = artdaq::Fragment::ContainerFragmentType;
552 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
553 auto cf4 = artdaq::ContainerFragment(*fps.front());
554 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
555 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
556 type = artdaq::Fragment::EmptyFragmentType;
557 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
560 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestBeforeBuffer test case END" << TLOG_ENDL;
565 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
566 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestStartsBeforeBuffer test case BEGIN" << TLOG_ENDL;
567 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
568 const int DELAY_TIME = 100;
569 fhicl::ParameterSet ps;
570 ps.put<
int>(
"board_id", 1);
571 ps.put<
int>(
"fragment_id", 1);
572 ps.put<
int>(
"request_port", REQUEST_PORT);
574 ps.put<std::string>(
"request_address",
"227.18.12.32");
576 ps.put<std::string>(
"request_address",
"localhost");
578 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
579 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
580 ps.put<
bool>(
"separate_data_thread",
true);
581 ps.put<
bool>(
"separate_monitoring_thread",
false);
582 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
583 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
584 ps.put<std::string>(
"request_mode",
"window");
585 ps.put(
"request_delay_ms", DELAY_TIME);
586 ps.put(
"send_requests",
true);
593 artdaq::FragmentPtrs fps;
595 artdaq::Fragment::type_t type;
606 BOOST_REQUIRE_EQUAL(sts,
true);
607 BOOST_REQUIRE_EQUAL(fps.size(), 1);
608 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
609 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 4);
610 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
611 type = artdaq::Fragment::ContainerFragmentType;
612 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
613 auto cf4 = artdaq::ContainerFragment(*fps.front());
614 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
615 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
616 type = artdaq::Fragment::FirstUserFragmentType;
617 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
621 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestStartsBeforeBuffer test case END" << TLOG_ENDL;
626 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
627 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestOutsideBuffer test case BEGIN" << TLOG_ENDL;
628 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
629 const int DELAY_TIME = 100;
630 fhicl::ParameterSet ps;
631 ps.put<
int>(
"board_id", 1);
632 ps.put<
int>(
"fragment_id", 1);
633 ps.put<
int>(
"request_port", REQUEST_PORT);
635 ps.put<std::string>(
"request_address",
"227.18.12.32");
637 ps.put<std::string>(
"request_address",
"localhost");
639 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
640 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 4);
641 ps.put<
size_t>(
"window_close_timeout_us", 500000);
642 ps.put<
bool>(
"separate_data_thread",
true);
643 ps.put<
bool>(
"separate_monitoring_thread",
false);
644 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
645 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
646 ps.put<std::string>(
"request_mode",
"window");
647 ps.put(
"request_delay_ms", DELAY_TIME);
648 ps.put(
"send_requests",
true);
655 artdaq::FragmentPtrs fps;
657 artdaq::Fragment::type_t type;
668 BOOST_REQUIRE_EQUAL(sts,
true);
669 BOOST_REQUIRE_EQUAL(fps.size(), 1);
670 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
671 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 6);
672 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
673 type = artdaq::Fragment::ContainerFragmentType;
674 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
675 auto cf = artdaq::ContainerFragment(*fps.front());
676 BOOST_REQUIRE_EQUAL(cf.block_count(), 4);
677 BOOST_REQUIRE_EQUAL(cf.missing_data(),
false);
678 type = artdaq::Fragment::FirstUserFragmentType;
679 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
684 BOOST_REQUIRE_EQUAL(sts,
true);
685 BOOST_REQUIRE_EQUAL(fps.size(), 0);
691 BOOST_REQUIRE_EQUAL(sts,
true);
692 BOOST_REQUIRE_EQUAL(fps.size(), 1);
693 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
694 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 9);
695 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
696 type = artdaq::Fragment::ContainerFragmentType;
697 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
698 auto cf2 = artdaq::ContainerFragment(*fps.front());
699 BOOST_REQUIRE_EQUAL(cf2.block_count(), 3);
700 BOOST_REQUIRE_EQUAL(cf2.missing_data(),
true);
701 type = artdaq::Fragment::FirstUserFragmentType;
702 BOOST_REQUIRE_EQUAL(cf2.fragment_type(), type);
710 BOOST_REQUIRE_EQUAL(sts,
true);
711 BOOST_REQUIRE_EQUAL(fps.size(), 0);
716 BOOST_REQUIRE_EQUAL(sts,
true);
717 BOOST_REQUIRE_EQUAL(fps.size(), 1);
718 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
719 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 12);
720 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 3);
721 type = artdaq::Fragment::ContainerFragmentType;
722 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
723 auto cf4 = artdaq::ContainerFragment(*fps.front());
724 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
725 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
726 type = artdaq::Fragment::FirstUserFragmentType;
727 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
731 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestOutsideBuffer test case END" << TLOG_ENDL;
736 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
737 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestInBuffer test case BEGIN" << TLOG_ENDL;
738 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
739 const int DELAY_TIME = 100;
740 fhicl::ParameterSet ps;
741 ps.put<
int>(
"board_id", 1);
742 ps.put<
int>(
"fragment_id", 1);
743 ps.put<
int>(
"request_port", REQUEST_PORT);
745 ps.put<std::string>(
"request_address",
"227.18.12.32");
747 ps.put<std::string>(
"request_address",
"localhost");
749 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
750 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
751 ps.put<
bool>(
"separate_data_thread",
true);
752 ps.put<
bool>(
"separate_monitoring_thread",
false);
753 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
754 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
755 ps.put<std::string>(
"request_mode",
"window");
756 ps.put(
"request_delay_ms", DELAY_TIME);
757 ps.put(
"send_requests",
true);
764 artdaq::FragmentPtrs fps;
766 artdaq::Fragment::type_t type;
776 BOOST_REQUIRE_EQUAL(sts,
true);
777 BOOST_REQUIRE_EQUAL(fps.size(), 1);
778 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
779 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 3);
780 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
781 type = artdaq::Fragment::ContainerFragmentType;
782 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
783 auto cf4 = artdaq::ContainerFragment(*fps.front());
784 BOOST_REQUIRE_EQUAL(cf4.block_count(), 3);
785 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
false);
786 type = artdaq::Fragment::FirstUserFragmentType;
787 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
790 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestInBuffer test case END" << TLOG_ENDL;
795 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
796 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestEndsAfterBuffer test case BEGIN" << TLOG_ENDL;
797 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
798 const int DELAY_TIME = 100;
799 fhicl::ParameterSet ps;
800 ps.put<
int>(
"board_id", 1);
801 ps.put<
int>(
"fragment_id", 1);
802 ps.put<
int>(
"request_port", REQUEST_PORT);
804 ps.put<std::string>(
"request_address",
"227.18.12.32");
806 ps.put<std::string>(
"request_address",
"localhost");
808 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
809 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
810 ps.put<
size_t>(
"window_close_timeout_us", 500000);
811 ps.put<
bool>(
"separate_data_thread",
true);
812 ps.put<
bool>(
"separate_monitoring_thread",
false);
813 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
814 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
815 ps.put<std::string>(
"request_mode",
"window");
816 ps.put(
"request_delay_ms", DELAY_TIME);
817 ps.put(
"send_requests",
true);
824 artdaq::FragmentPtrs fps;
826 artdaq::Fragment::type_t type;
835 BOOST_REQUIRE_EQUAL(sts,
true);
836 BOOST_REQUIRE_EQUAL(fps.size(), 0);
841 BOOST_REQUIRE_EQUAL(sts,
true);
842 BOOST_REQUIRE_EQUAL(fps.size(), 1);
843 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
844 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 5);
845 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
846 type = artdaq::Fragment::ContainerFragmentType;
847 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
848 auto cf = artdaq::ContainerFragment(*fps.front());
849 BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
850 BOOST_REQUIRE_EQUAL(cf.missing_data(),
false);
851 type = artdaq::Fragment::FirstUserFragmentType;
852 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
858 BOOST_REQUIRE_EQUAL(sts,
true);
859 BOOST_REQUIRE_EQUAL(fps.size(), 0);
864 BOOST_REQUIRE_EQUAL(sts,
true);
865 BOOST_REQUIRE_EQUAL(fps.size(), 1);
866 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
867 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 8);
868 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
869 type = artdaq::Fragment::ContainerFragmentType;
870 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
871 auto cf4 = artdaq::ContainerFragment(*fps.front());
872 BOOST_REQUIRE_EQUAL(cf4.block_count(), 1);
873 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
874 type = artdaq::Fragment::FirstUserFragmentType;
875 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
879 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestEndsAfterBuffer test case END" << TLOG_ENDL;
884 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
885 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestAfterBuffer test case BEGIN" << TLOG_ENDL;
886 const int REQUEST_PORT = (seedAndRandom() % (32768 - 1024)) + 1024;
887 const int DELAY_TIME = 100;
888 fhicl::ParameterSet ps;
889 ps.put<
int>(
"board_id", 1);
890 ps.put<
int>(
"fragment_id", 1);
891 ps.put<
int>(
"request_port", REQUEST_PORT);
893 ps.put<std::string>(
"request_address",
"227.18.12.32");
895 ps.put<std::string>(
"request_address",
"localhost");
897 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_offset", 0);
898 ps.put<artdaq::Fragment::timestamp_t>(
"request_window_width", 3);
899 ps.put<
size_t>(
"window_close_timeout_us", 500000);
900 ps.put<
bool>(
"separate_data_thread",
true);
901 ps.put<
bool>(
"separate_monitoring_thread",
false);
902 ps.put<int64_t>(
"hardware_poll_interval_us", 0);
903 ps.put<
size_t>(
"data_buffer_depth_fragments", 5);
904 ps.put<std::string>(
"request_mode",
"window");
905 ps.put(
"request_delay_ms", DELAY_TIME);
906 ps.put(
"send_requests",
true);
913 artdaq::FragmentPtrs fps;
915 artdaq::Fragment::type_t type;
925 BOOST_REQUIRE_EQUAL(sts,
true);
926 BOOST_REQUIRE_EQUAL(fps.size(), 0);
930 BOOST_REQUIRE_EQUAL(sts,
true);
931 BOOST_REQUIRE_EQUAL(fps.size(), 0);
936 BOOST_REQUIRE_EQUAL(sts,
true);
937 BOOST_REQUIRE_EQUAL(fps.size(), 1);
938 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
939 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 11);
940 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
941 type = artdaq::Fragment::ContainerFragmentType;
942 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
943 auto cf = artdaq::ContainerFragment(*fps.front());
944 BOOST_REQUIRE_EQUAL(cf.block_count(), 3);
945 BOOST_REQUIRE_EQUAL(cf.missing_data(),
false);
946 type = artdaq::Fragment::FirstUserFragmentType;
947 BOOST_REQUIRE_EQUAL(cf.fragment_type(), type);
952 BOOST_REQUIRE_EQUAL(sts,
true);
953 BOOST_REQUIRE_EQUAL(fps.size(), 0);
958 BOOST_REQUIRE_EQUAL(sts,
true);
959 BOOST_REQUIRE_EQUAL(fps.size(), 1);
960 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
961 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 16);
962 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 2);
963 type = artdaq::Fragment::ContainerFragmentType;
964 BOOST_REQUIRE_EQUAL(fps.front()->type(), type);
965 auto cf4 = artdaq::ContainerFragment(*fps.front());
966 BOOST_REQUIRE_EQUAL(cf4.block_count(), 0);
967 BOOST_REQUIRE_EQUAL(cf4.missing_data(),
true);
968 type = artdaq::Fragment::EmptyFragmentType;
969 BOOST_REQUIRE_EQUAL(cf4.fragment_type(), type);
973 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"WindowMode_RequestAfterBuffer test case END" << TLOG_ENDL;
979 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
980 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"HardwareFailure_NonThreaded test case BEGIN" << TLOG_ENDL;
981 fhicl::ParameterSet ps;
982 ps.put<
int>(
"board_id", 1);
983 ps.put<
int>(
"fragment_id", 1);
984 ps.put<
bool>(
"separate_data_thread",
false);
985 ps.put<
bool>(
"separate_monitoring_thread",
false);
986 ps.put<int64_t>(
"hardware_poll_interval_us", 10);
989 gen.StartCmd(1, 0xFFFFFFFF, 1);
991 artdaq::FragmentPtrs fps;
992 auto sts = gen.getNext(fps);
993 BOOST_REQUIRE_EQUAL(sts,
true);
994 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
995 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
996 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
997 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1000 gen.setFireCount(1);
1003 sts = gen.getNext(fps);
1004 BOOST_REQUIRE_EQUAL(sts,
false);
1005 BOOST_REQUIRE_EQUAL(fps.size(), 0);
1007 gen.StopCmd(0xFFFFFFFF, 1);
1009 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"HardwareFailure_NonThreaded test case END" << TLOG_ENDL;
1014 artdaq::configureMessageFacility(
"CommandableFragmentGenerator_t");
1015 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"HardwareFailure_Threaded test case BEGIN" << TLOG_ENDL;
1016 fhicl::ParameterSet ps;
1017 ps.put<
int>(
"board_id", 1);
1018 ps.put<
int>(
"fragment_id", 1);
1019 ps.put<
bool>(
"separate_data_thread",
true);
1020 ps.put<
bool>(
"separate_monitoring_thread",
true);
1021 ps.put<int64_t>(
"hardware_poll_interval_us", 750000);
1024 gen.StartCmd(1, 0xFFFFFFFF, 1);
1028 artdaq::FragmentPtrs fps;
1029 auto sts = gen.getNext(fps);
1030 BOOST_REQUIRE_EQUAL(sts,
true);
1031 BOOST_REQUIRE_EQUAL(fps.size(), 1u);
1032 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
1033 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 1);
1034 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1037 gen.setFireCount(1);
1039 sts = gen.getNext(fps);
1040 BOOST_REQUIRE_EQUAL(sts,
true);
1041 BOOST_REQUIRE_EQUAL(fps.size(), 1);
1042 BOOST_REQUIRE_EQUAL(fps.front()->fragmentID(), 1);
1043 BOOST_REQUIRE_EQUAL(fps.front()->timestamp(), 2);
1044 BOOST_REQUIRE_EQUAL(fps.front()->sequenceID(), 1);
1048 gen.setFireCount(1);
1049 sts = gen.getNext(fps);
1050 BOOST_REQUIRE_EQUAL(sts,
false);
1051 BOOST_REQUIRE_EQUAL(fps.size(), 0);
1053 gen.StopCmd(0xFFFFFFFF, 1);
1055 TLOG_INFO(
"CommandableFragmentGenerator_t") <<
"HardwareFailure_Threaded test case END" << TLOG_ENDL;
1058 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.