5 #include "artdaq-demo/Generators/ToySimulator.hh"
7 #include "canvas/Utilities/Exception.h"
9 #include "artdaq/Application/GeneratorMacros.hh"
10 #include "artdaq-core/Utilities/SimpleLookupPolicy.hh"
12 #include "artdaq-core-demo/Overlays/ToyFragment.hh"
13 #include "artdaq-core-demo/Overlays/FragmentType.hh"
15 #include "fhiclcpp/ParameterSet.h"
23 #define TRACE_NAME "ToySimulator"
25 #include "cetlib_except/exception.h"
29 CommandableFragmentGenerator(ps)
32 , timestampScale_(ps.get<int>(
"timestamp_scale_factor", 1))
34 , readout_buffer_(
nullptr)
35 , fragment_type_(
static_cast<decltype(fragment_type_)
>(artdaq::Fragment::InvalidFragmentType))
36 , distribution_type_(static_cast<ToyHardwareInterface::DistributionType>(ps.get<
int>(
"distribution_type")))
38 hardware_interface_->AllocateReadoutBuffer(&readout_buffer_);
40 metadata_.board_serial_number = hardware_interface_->SerialNumber();
41 metadata_.num_adc_bits = hardware_interface_->NumADCBits();
42 TRACE( TLVL_INFO,
"ToySimulator ctor metadata_.unused=0x%zu sizeof(metadata_)=%zd"
43 , metadata_.unused,
sizeof(metadata_) );
45 switch (hardware_interface_->BoardType())
48 fragment_type_ = toFragmentType(
"TOY1");
51 fragment_type_ = toFragmentType(
"TOY2");
54 throw cet::exception(
"ToySimulator") <<
"Unable to determine board type supplied by hardware";
60 hardware_interface_->FreeReadoutBuffer(readout_buffer_);
63 bool demo::ToySimulator::getNext_(artdaq::FragmentPtrs& frags)
81 std::size_t bytes_read = 0;
82 hardware_interface_->FillBuffer(readout_buffer_, &bytes_read);
93 std::unique_ptr<artdaq::Fragment> fragptr(
94 artdaq::Fragment::FragmentBytes(bytes_read,
95 ev_counter(), fragment_id(),
97 metadata_, timestamp_));
98 frags.emplace_back(std::move(fragptr));
100 std::unique_ptr<artdaq::Fragment> fragptr(
101 artdaq::Fragment::FragmentBytes( 1024 - 40,
102 ev_counter(), fragment_id(),
104 metadata_, timestamp_));
105 frags.emplace_back(std::move(fragptr));
106 artdaq::detail::RawFragmentHeader *hdr = (artdaq::detail::RawFragmentHeader*)(frags.back()->headerBeginBytes());
108 hdr->word_count = ceil((bytes_read + 32) / static_cast<double>(
sizeof(artdaq::RawDataType)));
112 memcpy(frags.back()->dataBeginBytes(), readout_buffer_, bytes_read);
114 TLOG_ARB(50,
"ToySimulator") <<
"ToySimulator::getNext_ after memcpy " << std::to_string(bytes_read)
115 <<
" bytes and std::move dataSizeBytes()=" << std::to_string(frags.back()->sizeBytes()) <<
" metabytes=" << std::to_string(
sizeof(metadata_)) << TLOG_ENDL;
117 if (metricMan !=
nullptr)
119 metricMan->sendMetric(
"Fragments Sent", ev_counter(),
"Events", 3, artdaq::MetricMode::LastPoint);
123 timestamp_ += timestampScale_;
128 void demo::ToySimulator::start()
130 hardware_interface_->StartDatataking();
133 void demo::ToySimulator::stop()
135 hardware_interface_->StopDatataking();
A use-after-free expliot distribution.
ToySimulator(fhicl::ParameterSet const &ps)
ToySimulator Constructor.
JCF, Mar-17-2016: ToyHardwareInterface is meant to mimic a vendor-provided hardware API...
virtual ~ToySimulator()
Shutdown the ToySimulator.
ToySimulator is a simple type of fragment generator intended to be studied by new users of artdaq as ...