1 #include "artdaq-demo/Generators/AsciiSimulator.hh"
3 #include "canvas/Utilities/Exception.h"
5 #include "artdaq-core-demo/Overlays/AsciiFragment.hh"
6 #include "artdaq-core-demo/Overlays/AsciiFragmentWriter.hh"
7 #include "artdaq-core-demo/Overlays/FragmentType.hh"
8 #include "artdaq-core/Utilities/SimpleLookupPolicy.hh"
9 #include "artdaq/Generators/GeneratorMacros.hh"
10 #include "cetlib_except/exception.h"
11 #include "fhiclcpp/ParameterSet.h"
30 if ( input.size() <
sizeof( T ) /
sizeof(
char ) )
31 { input.insert( 0,
sizeof( T ) /
sizeof(
char ) - input.size(),
' ' ); }
32 else if ( input.size() >
sizeof( T ) /
sizeof(
char ) )
34 input.erase( 0, input.size() -
sizeof( T ) /
sizeof(
char ) );
37 uint64_t bigOutput = 0ull;
39 for ( uint i = 0; i < input.length(); ++i )
43 bigOutput += input[ input.length() - i - 1 ];
47 return static_cast<T
>( bigOutput );
52 : CommandableFragmentGenerator( ps )
53 , throttle_usecs_( ps.get<size_t>(
"throttle_usecs", 100000 ) )
54 , string1_( ps.get<std::string>(
"string1",
"All work and no play makes ARTDAQ a dull library" ) )
55 , string2_( ps.get<std::string>(
"string2",
"Hey, look at what ARTDAQ can do!" ) )
58 bool demo::AsciiSimulator::getNext_( artdaq::FragmentPtrs& frags )
70 if ( throttle_usecs_ > 0 )
72 size_t nchecks = throttle_usecs_ / 10000;
74 for (
size_t i_c = 0; i_c < nchecks; ++i_c )
76 usleep( throttle_usecs_ / 10000 );
78 if ( should_stop() ) {
return false; }
83 if ( should_stop() ) {
return false; }
87 size_t data_size = ev_counter() % 2 ? string1_.length() + 2 : string2_.length() + 2;
88 AsciiFragment::Metadata metadata;
89 std::string size_string =
"S:" + std::to_string( data_size ) +
",";
90 metadata.charsInLine = convertToASCII<AsciiFragment::Metadata::chars_in_line_t>( size_string );
110 std::size_t initial_payload_size = 0;
112 std::unique_ptr<artdaq::Fragment> fragptr( artdaq::Fragment::FragmentBytes(
113 initial_payload_size, ev_counter(), fragment_id(), FragmentType::ASCII, metadata ) );
114 frags.emplace_back( std::move( fragptr ) );
119 AsciiFragmentWriter newfrag( *frags.back() );
121 newfrag.set_hdr_line_number(
122 convertToASCII<AsciiFragment::Header::line_number_t>(
"LN:" + std::to_string( ev_counter() ) +
"," ) );
124 newfrag.resize( data_size );
127 std::string string_to_use = ev_counter() % 2 ? string1_ : string2_;
128 string_to_use +=
"\r\n";
131 for ( uint i = 0; i < string_to_use.length(); ++i )
134 *( newfrag.dataBegin() + i ) = string_to_use[ i ];
Generates ASCIIFragments filled with user-specified ASCII strings.
AsciiSimulator(fhicl::ParameterSet const &ps)
AsciiSimulator Constructor.
T convertToASCII(std::string input)
Convert sizeof(T) characters of a string to a number containing the ASCII representation of that stri...