20 {
21 H5::H5File h5_file("mt_output.h5", H5F_ACC_TRUNC);
22 size_t n_threads = 5;
23 if (nargs >= 2) {
24 n_threads = std::stoi(argv[1]);
25 }
27 if (nargs >= 3) {
29 }
30 size_t ms_sleep = 0;
31 if (nargs >= 4) {
32 ms_sleep = std::stoi(argv[3]);
33 }
34 if (nargs > 4) {
35 std::cerr << std::format(
36 "usage: {} [n_threads] [n_events] [sleep (ms)]\n", argv[0]);
37 return 1;
38 }
39
40
42 consumers.
add(
"thread", [ms_sleep](
const out_t& o){
44 if (ms_sleep) {
45 std::this_thread::sleep_for(std::chrono::milliseconds(ms_sleep));
46 }
48 });
49 consumers.
add(
"event", [](
const out_t& o) {
51 });
52
53
57 std::cout << std::format(
58 "writing {} events each to {} threads, in batches of {}\n",
59 n_events,
60 n_threads,
62
64
65 std::vector<std::thread>
threads;
67 for (size_t thread_n = 0; thread_n < n_threads; thread_n++) {
69 [thread_n, n_events, &
writer](){
70 std::cout << "starting thread " << thread_n << "\n";
71 for (
size_t event_n = 0; event_n <
n_events; event_n++) {
73 }
74 });
75 }
76 for (auto& thread: threads) thread.join();
77 return 0;
78}
std::shared_ptr< HepMC3::Writer > writer
void add(const std::string &name, const std::function< T(I)> &, const T &default_value=T(), Compression=Compression::STANDARD)
This should be the only method you need in this class.
Writer< N, I > makeWriter(H5::Group &group, const std::string &name, const Consumers< I > &consumers, const std::array< hsize_t, N > &extent=internal::uniform< N >(5), hsize_t batch_size=defaults::batch_size)
makeWriter
H5Utils::Consumers< const out_t & > consumer_t