The Gaudi Framework  master (37c0b60a)
H1.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIUTILS_H1_H
12 #define GAUDIUTILS_H1_H 1
13 // ============================================================================
14 // Include files
15 // ============================================================================
16 namespace {
17  // ==========================================================================
19  typedef std::pair<double, double> Bin;
21  typedef std::vector<Bin> Bins;
22  // ==========================================================================
28  struct Edges final {
29  //
30  void setHighEdge( double value ) { high = value; }
31  void setLowEdge( double value ) { low = value; }
32  void setNBins( unsigned int value ) { nbins = value; }
33  void setEdges( std::vector<double> value ) { edges = std::move( value ); }
34  //
35  Edges& operator-=( double value ) {
36  setLowEdge( value );
37  return *this;
38  }
39  Edges& operator+=( double value ) {
40  setHighEdge( value );
41  return *this;
42  }
43  Edges& operator*=( std::vector<double> value ) {
44  setEdges( std::move( value ) );
45  return *this;
46  }
47  Edges& operator/=( unsigned int value ) {
48  setNBins( value );
49  return *this;
50  }
51  //
52  bool ok() const { return edges.empty() ? low < high && 0 < nbins : 2 < edges.size(); }
53  unsigned int nBins() const { return edges.empty() ? nbins : edges.size() - 1; }
54  //
55  double low;
56  double high;
57  unsigned int nbins;
58  std::vector<double> edges;
59  };
60  // ==========================================================================
66  struct H1 final {
67  //
68  void setName( std::string value ) { m_name = std::move( value ); }
69  void setTitle( std::string value ) { m_title = std::move( value ); }
70 
71  void setEdges( Edges value ) { m_edges = std::move( value ); }
72  void setHighEdge( const double value ) { m_edges.setHighEdge( value ); }
73  void setLowEdge( const double value ) { m_edges.setLowEdge( value ); }
74  void setNBins( const unsigned int value ) { m_edges.setNBins( value ); }
75 
76  void setBins( Bins value ) { m_bins = std::move( value ); }
77  //
78  H1& operator*=( std::string value ) {
79  setName( std::move( value ) );
80  return *this;
81  }
82  H1& operator/=( std::string value ) {
83  setTitle( std::move( value ) );
84  return *this;
85  }
86  H1& operator^=( const double value ) {
87  setHighEdge( value );
88  return *this;
89  }
90  H1& operator-=( const double value ) {
91  setLowEdge( value );
92  return *this;
93  }
94  H1& operator|=( const unsigned int value ) {
95  setNBins( value );
96  return *this;
97  }
98 
99  H1& operator&=( Edges value ) {
100  setEdges( std::move( value ) );
101  return *this;
102  }
103  H1& operator+=( Bins value ) {
104  setBins( std::move( value ) );
105  return *this;
106  }
107  //
108  bool ok() const {
109  if ( m_bins.empty() ) { return false; }
110  if ( !m_edges.ok() ) { return false; }
111  if ( m_bins.size() != m_edges.nBins() + 2 ) { return false; }
112  return true;
113  }
114  //
115  std::string m_name;
116  std::string m_title;
117  Edges m_edges;
118  Bins m_bins;
119  };
120  // ==========================================================================
126  struct H2 final {
127  //
128  void setName( std::string value ) { m_name = std::move( value ); }
129  void setTitle( std::string value ) { m_title = std::move( value ); }
130  void setXEdges( Edges value ) { m_xedges = std::move( value ); }
131  void setYEdges( Edges value ) { m_yedges = std::move( value ); }
132  void setBins( Bins value ) { m_bins = std::move( value ); }
133  //
134  H2& operator*=( std::string value ) {
135  setName( std::move( value ) );
136  return *this;
137  }
138  H2& operator/=( std::string value ) {
139  setTitle( std::move( value ) );
140  return *this;
141  }
142  H2& operator&=( Edges value ) {
143  setXEdges( std::move( value ) );
144  return *this;
145  }
146  H2& operator|=( Edges value ) {
147  setYEdges( std::move( value ) );
148  return *this;
149  }
150  H2& operator+=( Bins value ) {
151  setBins( std::move( value ) );
152  return *this;
153  }
154  //
155  bool ok() const {
156  if ( m_bins.empty() ) { return false; }
157  if ( !m_xedges.ok() ) { return false; }
158  if ( !m_yedges.ok() ) { return false; }
159  if ( m_bins.size() != ( m_xedges.nBins() + 2 ) * ( m_yedges.nBins() + 2 ) ) { return false; }
160  return true;
161  }
162  //
163  //
164  std::string m_name;
165  std::string m_title;
166  Edges m_xedges;
167  Edges m_yedges;
168  Bins m_bins;
169  };
170  // ==========================================================================
176  struct H3 final {
177  //
178  void setName( std::string value ) { m_name = std::move( value ); }
179  void setTitle( std::string value ) { m_title = std::move( value ); }
180  void setXEdges( Edges value ) { m_xedges = std::move( value ); }
181  void setYEdges( Edges value ) { m_yedges = std::move( value ); }
182  void setZEdges( Edges value ) { m_zedges = std::move( value ); }
183  void setBins( Bins value ) { m_bins = std::move( value ); }
184  //
185  H3& operator*=( std::string value ) {
186  setName( std::move( value ) );
187  return *this;
188  }
189  H3& operator/=( std::string value ) {
190  setTitle( std::move( value ) );
191  return *this;
192  }
193  H3& operator&=( Edges value ) {
194  setXEdges( std::move( value ) );
195  return *this;
196  }
197  H3& operator|=( Edges value ) {
198  setYEdges( std::move( value ) );
199  return *this;
200  }
201  H3& operator-=( Edges value ) {
202  setZEdges( std::move( value ) );
203  return *this;
204  }
205  H3& operator+=( Bins value ) {
206  setBins( std::move( value ) );
207  return *this;
208  }
209  //
210  bool ok() const {
211  if ( m_bins.empty() ) { return false; }
212  if ( !m_xedges.ok() ) { return false; }
213  if ( !m_yedges.ok() ) { return false; }
214  if ( !m_zedges.ok() ) { return false; }
215  if ( m_bins.size() != ( m_xedges.nBins() + 2 ) * ( m_yedges.nBins() + 2 ) * ( m_zedges.nBins() + 2 ) ) {
216  return false;
217  }
218  return true;
219  }
220  //
221  //
222  std::string m_name;
223  std::string m_title;
224  Edges m_xedges;
225  Edges m_yedges;
226  Edges m_zedges;
227  Bins m_bins;
228  };
229 
230  // ==========================================================================
231 } // end of anonymous namespace
232 // ============================================================================
233 // The END
234 // ============================================================================
235 #endif // GAUDIUTILS_H1_H
std::string
STL class.
std::move
T move(T... args)
std::pair< double, double >
std::vector
STL class.