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"
16 #include "cetlib/exception.h"
17 #include "fhiclcpp/ParameterSet.h"
29 CommandableFragmentGenerator(ps)
32 , timestampScale_(ps.get<int>(
"timestamp_scale_factor", 1))
33 , readout_buffer_(nullptr)
34 , fragment_type_(static_cast<decltype(fragment_type_)>(artdaq::Fragment::InvalidFragmentType))
35 , distribution_type_(static_cast<
ToyHardwareInterface::DistributionType>(ps.get<int>(
"distribution_type")))
37 hardware_interface_->AllocateReadoutBuffer(&readout_buffer_);
39 metadata_.board_serial_number = hardware_interface_->SerialNumber();
40 metadata_.num_adc_bits = hardware_interface_->NumADCBits();
42 switch (hardware_interface_->BoardType())
45 fragment_type_ = toFragmentType(
"TOY1");
48 fragment_type_ = toFragmentType(
"TOY2");
51 throw cet::exception(
"ToySimulator") <<
"Unable to determine board type supplied by hardware";
57 hardware_interface_->FreeReadoutBuffer(readout_buffer_);
60 bool demo::ToySimulator::getNext_(artdaq::FragmentPtrs& frags)
78 std::size_t bytes_read = 0;
79 hardware_interface_->FillBuffer(readout_buffer_, &bytes_read);
90 std::unique_ptr<artdaq::Fragment> fragptr(
91 artdaq::Fragment::FragmentBytes(bytes_read,
92 ev_counter(), fragment_id(),
94 metadata_, timestamp_));
95 frags.emplace_back(std::move(fragptr));
97 std::unique_ptr<artdaq::Fragment> fragptr(
98 artdaq::Fragment::FragmentBytes( 1024-40,
99 ev_counter(), fragment_id(),
101 metadata_, timestamp_));
102 frags.emplace_back(std::move(fragptr));
103 artdaq::detail::RawFragmentHeader *hdr = (artdaq::detail::RawFragmentHeader*)(frags.back()->headerBeginBytes());
105 hdr->word_count = ceil( (bytes_read+32) / static_cast<double>(
sizeof(artdaq::RawDataType)) );
109 memcpy(frags.back()->dataBeginBytes(), readout_buffer_, bytes_read);
111 TRACE( 50,
"ToySimulator::getNext_ after memcpy %zu bytes and std::move dataSizeBytes()=%zu metabytes=%zu", bytes_read, frags.back()->sizeBytes(),
sizeof(metadata_) );
113 if (metricMan !=
nullptr)
115 metricMan->sendMetric(
"Fragments Sent", ev_counter(),
"Events", 3);
119 timestamp_ += timestampScale_;
124 void demo::ToySimulator::start()
126 hardware_interface_->StartDatataking();
129 void demo::ToySimulator::stop()
131 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 ...