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  GridAxis(const std::vector<double>& coords, bool useLogSpace=false);
39  GridAxis(const std::vector<double>& coords, const char* label,
40  bool useLogSpace=false);
42 
44 
45  inline const std::vector<double>& coords() const {return coords_;}
46  inline const std::string& label() const {return label_;}
47  inline bool usesLogSpace() const {return useLogSpace_;}
49 
63  std::pair<unsigned,double> getInterval(double coordinate) const;
64 
79  std::pair<unsigned,double> linearInterval(double coordinate) const;
80 
82 
83  inline unsigned nCoords() const {return npt_;}
84  inline double coordinate(const unsigned i) const
85  {return coords_.at(i);}
86  inline double min() const {return coords_.front();}
87  inline double max() const {return coords_.back();}
88  inline double length() const {return coords_.back() - coords_.front();}
89  inline bool isUniform() const {return false;}
90  inline unsigned nIntervals() const {return coords_.size() - 1;}
91  inline double intervalWidth(const unsigned i=0) const
92  {return coords_.at(i+1) - coords_.at(i);}
94 
96  bool operator==(const GridAxis& r) const;
97 
99  inline bool operator!=(const GridAxis& r) const
100  {return !(*this == r);}
101 
106  bool isClose(const GridAxis& r, double tol) const;
107 
109  inline void setLabel(const char* newlabel)
110  {label_ = newlabel ? newlabel : "";}
111 
113 
114  inline gs::ClassId classId() const {return gs::ClassId(*this);}
115  bool write(std::ostream& of) const;
117 
118  static inline const char* classname() {return "npstat::GridAxis";}
119  static inline unsigned version() {return 2;}
120  static GridAxis* read(const gs::ClassId& id, std::istream& in);
121 
122  private:
123  inline GridAxis() : npt_(0), useLogSpace_(false) {}
124 
125  void initialize();
126 
127  std::vector<double> coords_;
128  std::vector<double> logs_;
130  unsigned npt_;
132 
133  };
134 }
135 
136 #endif // NPSTAT_GRIDAXIS_HH_
137 
void initialize()
Definition: GridAxis.cc:12
std::string label_
Definition: GridAxis.h:129
gs::ClassId classId() const
Definition: GridAxis.h:114
static const char * classname()
Definition: GridAxis.h:118
int i
Definition: DBlmapReader.cc:9
bool isUniform() const
Definition: GridAxis.h:89
double min() const
Definition: GridAxis.h:86
std::pair< unsigned, double > getInterval(double coordinate) const
Definition: GridAxis.cc:58
double intervalWidth(const unsigned i=0) const
Definition: GridAxis.h:91
const std::string & label() const
Definition: GridAxis.h:46
double max() const
Definition: GridAxis.h:87
bool operator==(const GridAxis &r) const
Definition: GridAxis.cc:174
unsigned nIntervals() const
Definition: GridAxis.h:90
double length() const
Definition: GridAxis.h:88
static unsigned version()
Definition: GridAxis.h:119
unsigned npt_
Definition: GridAxis.h:130
double coordinate(const unsigned i) const
Definition: GridAxis.h:84
unsigned nCoords() const
Definition: GridAxis.h:83
bool usesLogSpace() const
Definition: GridAxis.h:47
bool operator!=(const GridAxis &r) const
Definition: GridAxis.h:99
bool isClose(const GridAxis &r, double tol) const
Definition: GridAxis.cc:181
std::vector< double > logs_
Definition: GridAxis.h:128
void setLabel(const char *newlabel)
Definition: GridAxis.h:109
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:45
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:127