Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IOTypes.hh
Go to the documentation of this file.
1 ///
2 /// @file IOTypes.hh
3 /// @brief Declarations for Hammer IO structs
4 ///
5 
6 //**** This file is a part of the HAMMER library
7 //**** Copyright (C) 2016 - 2020 The HAMMER Collaboration
8 //**** HAMMER is licensed under version 3 of the GPL; see COPYING for details
9 //**** Please note the MCnet academic guidelines; see GUIDELINES for details
10 
11 // -*- C++ -*-
12 #ifndef HAMMER_TOOLS_IOTYPES_HH
13 #define HAMMER_TOOLS_IOTYPES_HH
14 
15 #include <vector>
16 #include <utility>
17 #include <memory>
18 #include <iostream>
19 #include <set>
20 #include <string>
21 
23 
24 #ifdef HAVE_ROOT
25 #include "Rtypes.h"
26 #endif
27 
28 namespace Hammer {
29 
30  enum RecordType : char { UNDEFINED = 'u', HEADER = 'b', EVENT = 'e', HISTOGRAM = 'h', RATE = 'r', HISTOGRAM_DEFINITION = 'd' };
31 
32  struct IOBuffer {
36  };
37 
38  std::ostream& operator<<(std::ostream& os, const IOBuffer& buf);
39  std::istream& operator>>(std::istream& is, IOBuffer& buf);
40 
41  namespace Serial {
42 
43  class DetachedBuffers;
44 
45  }
46 
47  class IOBuffers {
48  public:
49 
50  IOBuffers();
51  explicit IOBuffers(std::unique_ptr<Serial::DetachedBuffers>&& data);
52  IOBuffers(const IOBuffers&) = delete;
53  IOBuffers& operator=(const IOBuffers&) = delete;
56  ~IOBuffers();
57 
58  public:
59 
60  using iterator = std::vector<IOBuffer>::iterator;
61  using const_iterator = std::vector<IOBuffer>::const_iterator;
62  using reverse_iterator = std::vector<IOBuffer>::reverse_iterator;
63  using const_reverse_iterator = std::vector<IOBuffer>::const_reverse_iterator;
64 
65  IOBuffer& at(size_t pos);
66  const IOBuffer& at(size_t pos) const;
67 
68  IOBuffer& operator[](size_t pos);
69  const IOBuffer& operator[](size_t pos) const;
70 
71  IOBuffer& front();
72  const IOBuffer& front() const;
73 
74  IOBuffer& back();
75  const IOBuffer& back() const;
76 
77  size_t size() const;
78  bool empty() const;
79 
80  iterator begin() noexcept;
81  const_iterator begin() const noexcept;
82  const_iterator cbegin() const noexcept;
83 
84  iterator end() noexcept;
85  const_iterator end() const noexcept;
86  const_iterator cend() const noexcept;
87 
88  reverse_iterator rbegin() noexcept;
89  const_reverse_iterator rbegin() const noexcept;
90  const_reverse_iterator crbegin() const noexcept;
91 
92  reverse_iterator rend() noexcept;
93  const_reverse_iterator rend() const noexcept;
94  const_reverse_iterator crend() const noexcept;
95 
96  void clear();
97 
98  private:
99 
100  void init();
101 
102  private:
103 
104  std::vector<IOBuffer> _buffers;
105  std::unique_ptr<Serial::DetachedBuffers> _pOwner;
106 
107  };
108 
109  std::ostream& operator<<(std::ostream& os, const IOBuffers& buf);
110 
111 #ifdef HAVE_ROOT
112 
113  struct RootIOBuffer {
114  Char_t kind;
115  Int_t length;
116  Int_t maxLength;
117  UChar_t* start;
118 
119  RootIOBuffer& operator=(const IOBuffer& other);
120  };
121 
122 #endif
123 
124  ///@brief contents of a histogram bin after full contraction (real weights)
125  /// to be used to export the histogram outside Hammer
126  struct BinContents {
127  double sumWi; ///< sum of weights
128  double sumWi2; ///< sum of squared weights
129  size_t n; ////< number of entries in the bin
130  };
131 
132  using IOHistogram = std::vector<BinContents>;
133 
134  struct HistoInfo {
135  std::string name;
136  std::string scheme;
137  std::set<std::set<size_t>> eventGroupId;
138  };
139 
140 }
141 
142 #endif
std::vector< IOBuffer > _buffers
Definition: IOTypes.hh:104
std::vector< IOBuffer >::reverse_iterator reverse_iterator
Definition: IOTypes.hh:62
std::vector< IOBuffer >::iterator iterator
Definition: IOTypes.hh:60
const_iterator cend() const noexcept
Definition: IOTypes.cc:150
from libcpp map cimport map from libcpp set cimport set as cset from libcpp string cimport string from libcpp pair cimport pair from libcpp vector cimport vector from libcpp unordered_map cimport unordered_map from libcpp cimport bool from libc stdint cimport uint32_t
Definition: cppdefs.pxd:17
istream & operator>>(istream &is, IOBuffer &buf)
Definition: IOTypes.cc:28
YAML::Emitter & operator<<(YAML::Emitter &out, const ProcessDefinitions &s)
IOBuffer & operator[](size_t pos)
Definition: IOTypes.cc:98
std::unique_ptr< Serial::DetachedBuffers > _pOwner
Definition: IOTypes.hh:105
reverse_iterator rend() noexcept
Definition: IOTypes.cc:166
IOBuffer & at(size_t pos)
Definition: IOTypes.cc:90
std::vector< BinContents > IOHistogram
Definition: IOTypes.hh:132
RecordType kind
Definition: IOTypes.hh:33
std::string scheme
Definition: IOTypes.hh:136
IOBuffer & back()
Definition: IOTypes.cc:114
Hammer configuration definitions.
std::vector< IOBuffer >::const_reverse_iterator const_reverse_iterator
Definition: IOTypes.hh:63
const_iterator cbegin() const noexcept
Definition: IOTypes.cc:138
RecordType
Definition: IOTypes.hh:30
bool empty() const
Definition: IOTypes.cc:126
const_reverse_iterator crbegin() const noexcept
Definition: IOTypes.cc:162
size_t size() const
Definition: IOTypes.cc:122
iterator begin() noexcept
Definition: IOTypes.cc:130
contents of a histogram bin after full contraction (real weights) to be used to export the histogram ...
Definition: IOTypes.hh:126
from libcpp map cimport map from libcpp set cimport set as cset from libcpp string cimport string from libcpp pair cimport pair from libcpp vector cimport vector from libcpp unordered_map cimport unordered_map from libcpp cimport bool from libc stdint cimport uint8_t
Definition: cppdefs.pxd:17
iterator end() noexcept
Definition: IOTypes.cc:142
IOBuffer & front()
Definition: IOTypes.cc:106
reverse_iterator rbegin() noexcept
Definition: IOTypes.cc:154
uint8_t * start
Definition: IOTypes.hh:35
double sumWi
sum of weights
Definition: IOTypes.hh:127
std::set< std::set< size_t > > eventGroupId
Definition: IOTypes.hh:137
std::string name
Definition: IOTypes.hh:135
double sumWi2
sum of squared weights
Definition: IOTypes.hh:128
const_reverse_iterator crend() const noexcept
Definition: IOTypes.cc:174
uint32_t length
Definition: IOTypes.hh:34
std::vector< IOBuffer >::const_iterator const_iterator
Definition: IOTypes.hh:61
IOBuffers & operator=(const IOBuffers &)=delete