CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GridAxis.h
Go to the documentation of this file.
1 #ifndef NPSTAT_GRIDAXIS_HH_
2 #define NPSTAT_GRIDAXIS_HH_
3 
15 #include <vector>
16 #include <utility>
17 #include <string>
18 #include <iostream>
19 
20 #include "Alignment/Geners/interface/ClassId.hh"
21 
22 namespace npstat {
30  class GridAxis
31  {
32  public:
34 
38  explicit GridAxis(const std::vector<double>& coords,
39  bool useLogSpace=false);
40  GridAxis(const std::vector<double>& coords, const char* label,
41  bool useLogSpace=false);
43 
45 
46  inline const std::vector<double>& coords() const {return coords_;}
47  inline const std::string& label() const {return label_;}
48  inline bool usesLogSpace() const {return useLogSpace_;}
50 
64  std::pair<unsigned,double> getInterval(double coordinate) const;
65 
80  std::pair<unsigned,double> linearInterval(double coordinate) const;
81 
83 
84  inline unsigned nCoords() const {return npt_;}
85  inline double coordinate(const unsigned i) const
86  {return coords_.at(i);}
87  inline double min() const {return coords_.front();}
88  inline double max() const {return coords_.back();}
89  inline double length() const {return coords_.back() - coords_.front();}
90  inline bool isUniform() const {return false;}
91  inline unsigned nIntervals() const {return coords_.size() - 1;}
92  inline double intervalWidth(const unsigned i=0) const
93  {return coords_.at(i+1) - coords_.at(i);}
95 
97  bool operator==(const GridAxis& r) const;
98 
100  inline bool operator!=(const GridAxis& r) const
101  {return !(*this == r);}
102 
107  bool isClose(const GridAxis& r, double tol) const;
108 
110  inline void setLabel(const char* newlabel)
111  {label_ = newlabel ? newlabel : "";}
112 
114 
115  inline gs::ClassId classId() const {return gs::ClassId(*this);}
116  bool write(std::ostream& of) const;
118 
119  static inline const char* classname() {return "npstat::GridAxis";}
120  static inline unsigned version() {return 2;}
121  static GridAxis* read(const gs::ClassId& id, std::istream& in);
122 
123  private:
124  void initialize();
125 
126  std::vector<double> coords_;
127  std::vector<double> logs_;
129  unsigned npt_;
131 
132  inline GridAxis() : npt_(0), useLogSpace_(false) {}
133  };
134 }
135 
136 #endif // NPSTAT_GRIDAXIS_HH_
137 
void initialize()
Definition: GridAxis.cc:12
std::string label_
Definition: GridAxis.h:128
gs::ClassId classId() const
Definition: GridAxis.h:115
static const char * classname()
Definition: GridAxis.h:119
int i
Definition: DBlmapReader.cc:9
bool isUniform() const
Definition: GridAxis.h:90
double min() const
Definition: GridAxis.h:87
std::pair< unsigned, double > getInterval(double coordinate) const
Definition: GridAxis.cc:58
double intervalWidth(const unsigned i=0) const
Definition: GridAxis.h:92
const std::string & label() const
Definition: GridAxis.h:47
double max() const
Definition: GridAxis.h:88
bool operator==(const GridAxis &r) const
Definition: GridAxis.cc:174
unsigned nIntervals() const
Definition: GridAxis.h:91
double length() const
Definition: GridAxis.h:89
static unsigned version()
Definition: GridAxis.h:120
unsigned npt_
Definition: GridAxis.h:129
double coordinate(const unsigned i) const
Definition: GridAxis.h:85
unsigned nCoords() const
Definition: GridAxis.h:84
bool usesLogSpace() const
Definition: GridAxis.h:48
bool operator!=(const GridAxis &r) const
Definition: GridAxis.h:100
bool isClose(const GridAxis &r, double tol) const
Definition: GridAxis.cc:181
std::vector< double > logs_
Definition: GridAxis.h:127
void setLabel(const char *newlabel)
Definition: GridAxis.h:110
static GridAxis * read(const gs::ClassId &id, std::istream &in)
Definition: GridAxis.cc:154
volatile std::atomic< bool > shutdown_flag false
const std::vector< double > & coords() const
Definition: GridAxis.h:46
bool write(std::ostream &of) const
Definition: GridAxis.cc:144
std::pair< unsigned, double > linearInterval(double coordinate) const
Definition: GridAxis.cc:88
std::vector< double > coords_
Definition: GridAxis.h:126