CMS 3D CMS Logo

StorableHistoNDFunctor.h
Go to the documentation of this file.
1 #ifndef NPSTAT_STORABLEHISTONDFUNCTOR_HH_
2 #define NPSTAT_STORABLEHISTONDFUNCTOR_HH_
3 
17 
19 
20 namespace npstat {
25  template <class Numeric, class Axis = HistoAxis, class Converter = Same<Numeric> >
27  template <typename Num2, typename Axis2, typename Conv2>
28  friend class StorableHistoNDFunctor;
29 
30  public:
32 
34 
39  template <class Num2>
40  inline StorableHistoNDFunctor(const HistoND<Num2, Axis>& table, const unsigned degree = 1)
42  validateInterDegree(degree, table.isUniformlyBinned());
43  }
44 
45  template <class Num2>
46  inline StorableHistoNDFunctor(const HistoND<Num2, Axis>& table, const unsigned degree, const std::string& descr)
47  : StorableMultivariateFunctor(descr), table_(table), deg_(degree) {
48  validateInterDegree(degree, table.isUniformlyBinned());
49  }
51 
53  template <class Num2, class Conv2>
56  table_(tab.table_, Same<Num2>(), tab.title().c_str(), tab.accumulatedDataLabel().c_str()),
57  deg_(tab.deg_) {}
58 
60 
61  unsigned minDim() const override { return table_.dim(); };
62 
63  double operator()(const double* point, unsigned dim) const override;
64 
66  inline unsigned interpolationDegree() const { return deg_; }
67 
69  void setInterpolationDegree(const unsigned deg);
70 
72 
73  inline Table& interpolator() { return table_; }
74  inline const Table& interpolator() const { return table_; }
76 
78 
79  inline ArrayND<Numeric>& table() { return const_cast<ArrayND<Numeric>&>(table_.binContents()); }
80 
81  inline const ArrayND<Numeric>& table() const { return table_.binContents(); }
83 
85  inline void setConverter(const Converter& conv) { conv_ = conv; }
86 
88  // Method related to "geners" I/O
89  gs::ClassId classId() const override { return gs::ClassId(*this); }
90  bool write(std::ostream& of) const override;
92 
93  // I/O methods needed for reading
94  static inline const char* classname();
95  static inline unsigned version() { return 1; }
96  static StorableHistoNDFunctor* read(const gs::ClassId& id, std::istream& in);
97 
98  protected:
99  bool isEqual(const StorableMultivariateFunctor& other) const override {
100  // Note the use of static_cast rather than dynamic_cast below.
101  // static_cast works faster and it is guaranteed to succeed here.
102  const StorableHistoNDFunctor& r = static_cast<const StorableHistoNDFunctor&>(other);
103  return table_ == r.table_ && deg_ == r.deg_ && this->description() == other.description();
104  }
105 
106  private:
107  StorableHistoNDFunctor() = delete;
108 
110  unsigned deg_;
111  Converter conv_;
112 
113  static void validateInterDegree(unsigned deg, bool isUniform);
114  };
115 } // namespace npstat
116 
118 
119 #include "Alignment/Geners/interface/binaryIO.hh"
120 #include "Alignment/Geners/interface/CPP11_auto_ptr.hh"
121 #include "Alignment/Geners/interface/IOException.hh"
122 
124 
125 namespace npstat {
126  template <class Numeric, class Axis, class Converter>
127  double StorableHistoNDFunctor<Numeric, Axis, Converter>::operator()(const double* point, const unsigned dim) const {
128  return conv_(interpolateHistoND(table_, point, dim, deg_));
129  }
130 
131  template <class Numeric, class Axis, class Converter>
133  static const std::string myClass(gs::template_class_name<Numeric, Axis>("npstat::StorableHistoNDFunctor"));
134  return myClass.c_str();
135  }
136 
137  template <class Numeric, class Axis, class Converter>
139  gs::write_pod(of, this->description());
140  gs::write_pod(of, deg_);
141  return table_.classId().write(of) && table_.write(of);
142  }
143 
144  template <class Numeric, class Axis, class Converter>
146  const gs::ClassId& id, std::istream& in) {
147  static const gs::ClassId current(gs::ClassId::makeId<StorableHistoNDFunctor<Numeric, Axis> >());
148  current.ensureSameId(id);
149 
150  std::string descr;
151  gs::read_pod(in, &descr);
152  unsigned deg;
153  gs::read_pod(in, &deg);
154  gs::ClassId tabid(in, 1);
155  if (in.fail())
156  throw gs::IOReadFailure(
157  "In npstat::StorableHistoNDFunctor::read: "
158  "input stream failure");
159  CPP11_auto_ptr<Table> tab(Table::read(tabid, in));
160  return new StorableHistoNDFunctor(*tab, deg, descr);
161  }
162 
163  template <class Numeric, class Axis, class Converter>
165  validateInterDegree(deg, table_.isUniformlyBinned());
166  deg_ = deg;
167  }
168 
169  template <class Numeric, class Axis, class Converter>
171  const bool isUniform) {
172  const bool ok = isUniform ? (deg == 0 || deg == 1 || deg == 3) : (deg == 0 || deg == 1);
173  if (!ok)
175  "In npstat::StorableHistoNDFunctor::validateInterDegree: "
176  "unsupported interpolation degree");
177  }
178 } // namespace npstat
179 
180 #endif // NPSTAT_STORABLEHISTONDFUNCTOR_HH_
npstat::StorableHistoNDFunctor::classId
gs::ClassId classId() const override
Definition: StorableHistoNDFunctor.h:89
npstat::StorableHistoNDFunctor::validateInterDegree
static void validateInterDegree(unsigned deg, bool isUniform)
Definition: StorableHistoNDFunctor.h:170
npstat::StorableHistoNDFunctor::isEqual
bool isEqual(const StorableMultivariateFunctor &other) const override
Definition: StorableHistoNDFunctor.h:99
npstat::HistoND::dim
unsigned dim() const
Definition: HistoND.h:170
npstat::StorableHistoNDFunctor::deg_
unsigned deg_
Definition: StorableHistoNDFunctor.h:110
conv
static HepMC::IO_HEPEVT conv
Definition: BeamHaloProducer.cc:48
edmLumisInFiles.description
description
Definition: edmLumisInFiles.py:11
npstat::StorableHistoNDFunctor::StorableHistoNDFunctor
StorableHistoNDFunctor()=delete
npstat::StorableMultivariateFunctor::description
const std::string & description() const
Definition: StorableMultivariateFunctor.h:34
npstat::StorableHistoNDFunctor::StorableHistoNDFunctor
StorableHistoNDFunctor(const StorableHistoNDFunctor< Num2, Axis, Conv2 > &tab)
Definition: StorableHistoNDFunctor.h:54
npstat::StorableHistoNDFunctor::StorableHistoNDFunctor
StorableHistoNDFunctor(const HistoND< Num2, Axis > &table, const unsigned degree, const std::string &descr)
Definition: StorableHistoNDFunctor.h:46
npstat::StorableHistoNDFunctor::minDim
unsigned minDim() const override
Definition: StorableHistoNDFunctor.h:61
npstat::StorableHistoNDFunctor::table
const ArrayND< Numeric > & table() const
Definition: StorableHistoNDFunctor.h:81
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
npstat::StorableHistoNDFunctor::StorableHistoNDFunctor
StorableHistoNDFunctor(const HistoND< Num2, Axis > &table, const unsigned degree=1)
Definition: StorableHistoNDFunctor.h:40
npstat
Definition: AbsArrayProjector.h:14
npstat::StorableHistoNDFunctor::Table
HistoND< Numeric, Axis > Table
Definition: StorableHistoNDFunctor.h:31
SimpleFunctors.h
Interface definitions and concrete simple functors for a variety of functor-based calculations.
npstat::StorableHistoNDFunctor::interpolationDegree
unsigned interpolationDegree() const
Definition: StorableHistoNDFunctor.h:66
npstat::StorableHistoNDFunctor::interpolator
Table & interpolator()
Definition: StorableHistoNDFunctor.h:73
trackingPlots.other
other
Definition: trackingPlots.py:1465
npstat::NpstatInvalidArgument
Definition: NpstatException.h:38
npstat::StorableHistoNDFunctor
Definition: StorableHistoNDFunctor.h:26
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
npstat::StorableHistoNDFunctor::setInterpolationDegree
void setInterpolationDegree(const unsigned deg)
Definition: StorableHistoNDFunctor.h:164
npstat::interpolateHistoND
Float interpolateHistoND(const HistoND< Float, Axis > &histo, const double *coords, unsigned coordsDim, unsigned interpolationDegree)
Definition: interpolateHistoND.h:156
npstat::StorableHistoNDFunctor::version
static unsigned version()
Definition: StorableHistoNDFunctor.h:95
npstat::StorableHistoNDFunctor::classname
static const char * classname()
Definition: StorableHistoNDFunctor.h:132
recoMuon::in
Definition: RecoMuonEnumerators.h:6
npstat::StorableHistoNDFunctor::operator()
double operator()(const double *point, unsigned dim) const override
Definition: StorableHistoNDFunctor.h:127
npstat::StorableHistoNDFunctor::write
bool write(std::ostream &of) const override
Definition: StorableHistoNDFunctor.h:138
npstat::ArrayND< Numeric >
npstat::StorableHistoNDFunctor::interpolator
const Table & interpolator() const
Definition: StorableHistoNDFunctor.h:74
npstat::StorableHistoNDFunctor::table
ArrayND< Numeric > & table()
Definition: StorableHistoNDFunctor.h:79
npstat::HistoND
Definition: HistoAxis.h:23
alignCSCRings.r
r
Definition: alignCSCRings.py:93
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
overlapproblemtsosanalyzer_cfi.title
title
Definition: overlapproblemtsosanalyzer_cfi.py:7
npstat::StorableHistoNDFunctor::table_
Table table_
Definition: StorableHistoNDFunctor.h:109
StorableMultivariateFunctor.h
Interface definition for storable multivariate functors.
npstat::StorableMultivariateFunctor
Definition: StorableMultivariateFunctor.h:23
npstat::StorableHistoNDFunctor::setConverter
void setConverter(const Converter &conv)
Definition: StorableHistoNDFunctor.h:85
npstat::StorableHistoNDFunctor::read
static StorableHistoNDFunctor * read(const gs::ClassId &id, std::istream &in)
Definition: StorableHistoNDFunctor.h:145
npstat::HistoND::binContents
const ArrayND< Numeric > & binContents() const
Definition: HistoND.h:179
interpolateHistoND.h
Interpolate histogram contents.
point
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
NpstatException.h
Exceptions for the npstat namespace.
npstat::StorableHistoNDFunctor::~StorableHistoNDFunctor
~StorableHistoNDFunctor() override
Definition: StorableHistoNDFunctor.h:59
npstat::Same
Definition: SimpleFunctors.h:60
table_
Table table_
Definition: ExceptionActions.cc:21
HistoND.h
Arbitrary-dimensional histogram template.
npstat::StorableHistoNDFunctor::conv_
Converter conv_
Definition: StorableHistoNDFunctor.h:111