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  StorableHistoNDFunctor() = delete;
61 
63 
64  unsigned minDim() const override { return table_.dim(); };
65 
66  double operator()(const double* point, unsigned dim) const override;
67 
69  inline unsigned interpolationDegree() const { return deg_; }
70 
72  void setInterpolationDegree(const unsigned deg);
73 
75 
76  inline Table& interpolator() { return table_; }
77  inline const Table& interpolator() const { return table_; }
79 
81 
82  inline ArrayND<Numeric>& table() { return const_cast<ArrayND<Numeric>&>(table_.binContents()); }
83 
84  inline const ArrayND<Numeric>& table() const { return table_.binContents(); }
86 
88  inline void setConverter(const Converter& conv) { conv_ = conv; }
89 
91  // Method related to "geners" I/O
92  gs::ClassId classId() const override { return gs::ClassId(*this); }
93  bool write(std::ostream& of) const override;
95 
96  // I/O methods needed for reading
97  static inline const char* classname();
98  static inline unsigned version() { return 1; }
99  static StorableHistoNDFunctor* read(const gs::ClassId& id, std::istream& in);
100 
101  protected:
102  bool isEqual(const StorableMultivariateFunctor& other) const override {
103  // Note the use of static_cast rather than dynamic_cast below.
104  // static_cast works faster and it is guaranteed to succeed here.
105  const StorableHistoNDFunctor& r = static_cast<const StorableHistoNDFunctor&>(other);
106  return table_ == r.table_ && deg_ == r.deg_ && this->description() == other.description();
107  }
108 
109  private:
111  unsigned deg_;
112  Converter conv_;
113 
114  static void validateInterDegree(unsigned deg, bool isUniform);
115  };
116 } // namespace npstat
117 
119 
120 #include "Alignment/Geners/interface/binaryIO.hh"
121 #include "Alignment/Geners/interface/CPP11_auto_ptr.hh"
122 #include "Alignment/Geners/interface/IOException.hh"
123 
125 
126 namespace npstat {
127  template <class Numeric, class Axis, class Converter>
128  double StorableHistoNDFunctor<Numeric, Axis, Converter>::operator()(const double* point, const unsigned dim) const {
129  return conv_(interpolateHistoND(table_, point, dim, deg_));
130  }
131 
132  template <class Numeric, class Axis, class Converter>
134  static const std::string myClass(gs::template_class_name<Numeric, Axis>("npstat::StorableHistoNDFunctor"));
135  return myClass.c_str();
136  }
137 
138  template <class Numeric, class Axis, class Converter>
140  gs::write_pod(of, this->description());
141  gs::write_pod(of, deg_);
142  return table_.classId().write(of) && table_.write(of);
143  }
144 
145  template <class Numeric, class Axis, class Converter>
147  const gs::ClassId& id, std::istream& in) {
148  static const gs::ClassId current(gs::ClassId::makeId<StorableHistoNDFunctor<Numeric, Axis> >());
149  current.ensureSameId(id);
150 
151  std::string descr;
152  gs::read_pod(in, &descr);
153  unsigned deg;
154  gs::read_pod(in, &deg);
155  gs::ClassId tabid(in, 1);
156  if (in.fail())
157  throw gs::IOReadFailure(
158  "In npstat::StorableHistoNDFunctor::read: "
159  "input stream failure");
160  CPP11_auto_ptr<Table> tab(Table::read(tabid, in));
161  return new StorableHistoNDFunctor(*tab, deg, descr);
162  }
163 
164  template <class Numeric, class Axis, class Converter>
166  validateInterDegree(deg, table_.isUniformlyBinned());
167  deg_ = deg;
168  }
169 
170  template <class Numeric, class Axis, class Converter>
172  const bool isUniform) {
173  const bool ok = isUniform ? (deg == 0 || deg == 1 || deg == 3) : (deg == 0 || deg == 1);
174  if (!ok)
176  "In npstat::StorableHistoNDFunctor::validateInterDegree: "
177  "unsupported interpolation degree");
178  }
179 } // namespace npstat
180 
181 #endif // NPSTAT_STORABLEHISTONDFUNCTOR_HH_
npstat::StorableHistoNDFunctor::classId
gs::ClassId classId() const override
Definition: StorableHistoNDFunctor.h:92
npstat::StorableHistoNDFunctor::validateInterDegree
static void validateInterDegree(unsigned deg, bool isUniform)
Definition: StorableHistoNDFunctor.h:171
npstat::StorableHistoNDFunctor::isEqual
bool isEqual(const StorableMultivariateFunctor &other) const override
Definition: StorableHistoNDFunctor.h:102
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
npstat::HistoND::dim
unsigned dim() const
Definition: HistoND.h:173
npstat::StorableHistoNDFunctor::deg_
unsigned deg_
Definition: StorableHistoNDFunctor.h:111
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:64
npstat::StorableHistoNDFunctor::table
const ArrayND< Numeric > & table() const
Definition: StorableHistoNDFunctor.h:84
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:69
npstat::StorableHistoNDFunctor::interpolator
Table & interpolator()
Definition: StorableHistoNDFunctor.h:76
trackingPlots.other
other
Definition: trackingPlots.py:1464
npstat::NpstatInvalidArgument
Definition: NpstatException.h:38
npstat::StorableHistoNDFunctor
Definition: StorableHistoNDFunctor.h:26
npstat::StorableHistoNDFunctor::setInterpolationDegree
void setInterpolationDegree(const unsigned deg)
Definition: StorableHistoNDFunctor.h:165
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:98
npstat::StorableHistoNDFunctor::classname
static const char * classname()
Definition: StorableHistoNDFunctor.h:133
recoMuon::in
Definition: RecoMuonEnumerators.h:6
npstat::StorableHistoNDFunctor::operator()
double operator()(const double *point, unsigned dim) const override
Definition: StorableHistoNDFunctor.h:128
npstat::StorableHistoNDFunctor::write
bool write(std::ostream &of) const override
Definition: StorableHistoNDFunctor.h:139
npstat::ArrayND< Numeric >
npstat::StorableHistoNDFunctor::interpolator
const Table & interpolator() const
Definition: StorableHistoNDFunctor.h:77
npstat::StorableHistoNDFunctor::table
ArrayND< Numeric > & table()
Definition: StorableHistoNDFunctor.h:82
npstat::HistoND
Definition: HistoAxis.h:23
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
alignCSCRings.r
r
Definition: alignCSCRings.py:93
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
npstat::StorableHistoNDFunctor::table_
Table table_
Definition: StorableHistoNDFunctor.h:110
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:88
npstat::StorableHistoNDFunctor::read
static StorableHistoNDFunctor * read(const gs::ClassId &id, std::istream &in)
Definition: StorableHistoNDFunctor.h:146
npstat::HistoND::binContents
const ArrayND< Numeric > & binContents() const
Definition: HistoND.h:182
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:62
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:112
conv
EPOS::IO_EPOS conv
Definition: ReggeGribovPartonMCHadronizer.cc:42