R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
Mille.h
Go to the documentation of this file.
1#pragma once
2#include "MilleEntry.h"
3#include <cstddef>
4#include <cstdint>
5#include <fstream>
6#include <string_view>
7#include <utility>
8#include <vector>
9
10namespace R3B
11{
12 constexpr auto DEFAULT_BUFFER_SIZE = std::size_t{ 10000 };
13 template <typename IndexType = int, typename ValueType = float>
15 {
16 public:
17 MilleBuffer() = default;
18 void clear()
19 {
20 index_buffer_.clear();
21 value_buffer_.clear();
22 }
23 auto get_current_size() -> std::size_t { return index_buffer_.size() + value_buffer_.size(); }
24 inline void add_entry(IndexType index, ValueType value) // NOLINT
25 {
26 index_buffer_.emplace_back(index);
27 value_buffer_.emplace_back(value);
28 }
29 auto is_empty() -> bool { return get_current_size() == 0; }
30
31 auto get_indices() -> const auto& { return index_buffer_; }
32 auto get_values() -> const auto& { return value_buffer_; }
33
34 private:
35 std::vector<IndexType> index_buffer_; // buffer to store local and global indices
36 std::vector<ValueType> value_buffer_; // buffer to store local and global derivatives
37 };
38
39 class Mille
40 {
41 public:
42 explicit Mille(std::string_view outFileName, bool asBinary = true, bool writeZero = false);
43 void set_buffer_size(std::size_t buffer_size) { max_buffer_size_ = buffer_size; }
44
60 void mille(const MilleDataPoint& data_point);
61 void special(const std::vector<std::pair<int, float>>& special_data);
62 void reset();
63
71 void end();
72 void close();
73
74 auto get_n_entries() const -> uint64_t { return num_of_entries_; }
75
76 private:
77 bool has_special_done_ = false;
78 bool is_binary_ = true;
79 bool is_zero_written_ = false;
82 std::ofstream output_file_;
83 uint64_t num_of_entries_ = 0;
84
85 static constexpr unsigned int max_label_size_ = (0xFFFFFFFF - (1U << 31U));
86
87 void check_buffer_size(std::size_t nLocal, std::size_t nGlobal);
88 void write_to_binary();
90 };
91} // namespace R3B
std::vector< ValueType > value_buffer_
Definition Mille.h:36
auto is_empty() -> bool
Definition Mille.h:29
void add_entry(IndexType index, ValueType value)
Definition Mille.h:24
auto get_indices() -> const auto &
Definition Mille.h:31
auto get_current_size() -> std::size_t
Definition Mille.h:23
void clear()
Definition Mille.h:18
auto get_values() -> const auto &
Definition Mille.h:32
std::vector< IndexType > index_buffer_
Definition Mille.h:35
MilleBuffer()=default
void write_to_non_binary()
Definition Mille.cxx:142
auto get_n_entries() const -> uint64_t
Definition Mille.h:74
bool has_special_done_
if true, special(..) already called for this record
Definition Mille.h:77
void mille(const MilleDataPoint &data_point)
Write the MilleDataPoint structure to the internal data buffer of the type MilleBuffer.
Definition Mille.cxx:55
void check_buffer_size(std::size_t nLocal, std::size_t nGlobal)
Definition Mille.cxx:156
Mille(std::string_view outFileName, bool asBinary=true, bool writeZero=false)
Definition Mille.cxx:42
void close()
Definition Mille.cxx:155
std::ofstream output_file_
C-binary for output.
Definition Mille.h:82
bool is_binary_
if false output as text
Definition Mille.h:78
static constexpr unsigned int max_label_size_
Definition Mille.h:85
std::size_t max_buffer_size_
Maximum size of the data buffer.
Definition Mille.h:81
bool is_zero_written_
if true also write out derivatives/labels ==0
Definition Mille.h:79
void write_to_binary()
Definition Mille.cxx:132
void reset()
Definition Mille.cxx:149
void set_buffer_size(std::size_t buffer_size)
Definition Mille.h:43
MilleBuffer< int, float > buffer_
Data buffer to store the points of the events.
Definition Mille.h:80
void special(const std::vector< std::pair< int, float > > &special_data)
Definition Mille.cxx:97
void end()
Streaming an entry data to the output file.
Definition Mille.cxx:121
uint64_t num_of_entries_
Definition Mille.h:83
constexpr auto DEFAULT_BUFFER_SIZE
Definition Mille.h:12