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