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 <fmt/core.h>
4#include <fstream>
5#include <string>
6
7namespace R3B
8{
9 constexpr auto DEFAULT_BUFFER_SIZE = std::size_t{ 10000 };
10 template <typename IndexType = int, typename ValueType = float>
12 {
13 public:
14 MilleBuffer() = default;
15 void clear()
16 {
17 index_buffer_.clear();
18 value_buffer_.clear();
19 }
20 inline auto get_current_size() -> std::size_t { return index_buffer_.size() + value_buffer_.size(); }
21 inline void add_entry(IndexType index, ValueType value) // NOLINT
22 {
23 index_buffer_.emplace_back(index);
24 value_buffer_.emplace_back(value);
25 }
26 inline auto is_empty() -> bool { return get_current_size() == 0; }
27
28 auto get_indices() -> const auto& { return index_buffer_; }
29 auto get_values() -> const auto& { return value_buffer_; }
30
31 private:
32 std::vector<IndexType> index_buffer_; // buffer to store local and global indices
33 std::vector<ValueType> value_buffer_; // buffer to store local and global derivatives
34 };
35
36 class Mille
37 {
38 public:
39 explicit Mille(std::string_view outFileName, bool asBinary = true, bool writeZero = false);
40 void set_buffer_size(std::size_t buffer_size) { max_buffer_size_ = buffer_size; }
41
42 void mille(const MilleDataPoint& data_point);
43 void special(const std::vector<std::pair<int, float>>& special_data);
44 inline void kill()
45 {
46 buffer_.clear();
47 has_special_done_ = false;
48 }
49 void end();
50 void close();
51
52 private:
53 bool has_special_done_ = false; // if true, special(..) already called for this record
54 bool is_binary_ = true; // if false output as text
55 bool is_zero_written_ = false; // if true also write out derivatives/labels ==0
57 std::size_t max_buffer_size_ = DEFAULT_BUFFER_SIZE;
58 static constexpr unsigned int max_label_size_ = (0xFFFFFFFF - (1U << 31U));
59 std::ofstream output_file_; // C-binary for output
60
61 void check_buffer_size(std::size_t nLocal, std::size_t nGlobal);
62 void write_to_binary();
63 void write_to_non_binary();
64 };
65} // namespace R3B
auto is_empty() -> bool
Definition Mille.h:26
void add_entry(IndexType index, ValueType value)
Definition Mille.h:21
auto get_indices() -> const auto &
Definition Mille.h:28
auto get_current_size() -> std::size_t
Definition Mille.h:20
void clear()
Definition Mille.h:15
auto get_values() -> const auto &
Definition Mille.h:29
MilleBuffer()=default
void mille(const MilleDataPoint &data_point)
Definition Mille.cxx:42
Mille(std::string_view outFileName, bool asBinary=true, bool writeZero=false)
Definition Mille.cxx:29
void close()
Definition Mille.cxx:135
void set_buffer_size(std::size_t buffer_size)
Definition Mille.h:40
void special(const std::vector< std::pair< int, float > > &special_data)
Definition Mille.cxx:84
void end()
Definition Mille.cxx:108
void kill()
Definition Mille.h:44
constexpr auto DEFAULT_BUFFER_SIZE
Definition Mille.h:9