CMS 3D CMS Logo

LutNetworkFixedPointCommon.h
Go to the documentation of this file.
1 /*
2  * LutNetworkCommon.h
3  *
4  * Created on: Jan 13, 2023
5  * Author: kbunkow
6  */
7 
8 #ifndef L1Trigger_L1TMuonOverlapPhase2_LutNetworkFixedPointCommon_h
9 #define L1Trigger_L1TMuonOverlapPhase2_LutNetworkFixedPointCommon_h
10 
11 #include <ap_fixed.h>
12 #include <ap_int.h>
13 #include <array>
14 #include <vector>
15 #include <limits>
16 
17 #include <boost/property_tree/ptree.hpp>
18 
19 namespace lutNN {
20 
21  template <int W, int I>
22  const ap_ufixed<W, I> max_ap_ufixed() {
23  static_assert(I < 64, "this max_ap_ufixed works only for I < 64");
24  return ap_ufixed<W, I, AP_RND, AP_SAT>(std::numeric_limits<uint64_t>::max());
25  //AP_SAT Saturate the value to the maximum value in case of overflow
26  }
27 
28  template <int W, int I>
29  const ap_fixed<W, I> max_ap_fixed() {
30  static_assert(I < 64, "this max_ap_ufixed works only for I < 64");
31  return ap_fixed<W, I, AP_RND, AP_SAT>(std::numeric_limits<uint64_t>::max());
32  //AP_SAT Saturate the value to the maximum value in case of overflow
33  }
34 
35 #define PUT_VAR(tree, keyPath, var) tree.put((keyPath) + "." + #var, (var));
36 
37 #define CHECK_VAR(tree, keyPath, var) \
38  if ((var) != tree.get<int>((keyPath) + "." + #var)) \
39  throw std::runtime_error((keyPath) + "." + #var + " has different value in the file then given");
40 
42  public:
44 
45  virtual void save(const std::string& filename) = 0;
46  virtual void load(const std::string& filename) = 0;
47 
48  virtual void run(std::vector<float>& inputs, float noHitVal, std::vector<double>& nnResult) = 0;
49 
50  //pt in the hardware scale, ptGeV = (ptHw -1) / 2
51  virtual int getCalibratedHwPt() = 0;
52  };
53 
54 } // namespace lutNN
55 
56 #endif /* L1Trigger_L1TMuonOverlapPhase2_LutNetworkFixedPointCommon_h */
const ap_fixed< W, I > max_ap_fixed()
virtual void save(const std::string &filename)=0
virtual void run(std::vector< float > &inputs, float noHitVal, std::vector< double > &nnResult)=0
const std::complex< double > I
Definition: I.h:8
const ap_ufixed< W, I > max_ap_ufixed()
virtual void load(const std::string &filename)=0