CMS 3D CMS Logo

DeepBoostedJetFeatures.h
Go to the documentation of this file.
1 #ifndef DataFormats_BTauReco_DeepBoostedJetFeatures_h
2 #define DataFormats_BTauReco_DeepBoostedJetFeatures_h
3 
4 #include <string>
5 #include <vector>
6 #include <unordered_map>
8 
9 namespace btagbtvdeep {
10 
12 
13 public:
14 
15  bool empty() const {
16  return is_empty_;
17  }
18 
19  void add(const std::string& name){
21  }
22 
23  void reserve(const std::string& name, unsigned capacity){
24  feature_map_[name].reserve(capacity);
25  }
26 
27  void fill(const std::string& name, float value){
28  auto item = feature_map_.find(name);
29  if (item != feature_map_.end()){
30  item->second.push_back(value);
31  is_empty_ = false;
32  }else{
33  throw cms::Exception("InvalidArgument") << "[DeepBoostedJetFeatures::fill()] Feature " << name << " has not been registered";
34  }
35  }
36 
37  void set(const std::string& name, const std::vector<float>& vec){
38  feature_map_[name] = vec;
39  }
40 
41  void check_consistency(const std::vector<std::string> &names) const {
42  if (names.empty()) return;
43  const auto ref_len = get(names.front()).size();
44  for (unsigned i=1; i<names.size(); ++i){
45  if (get(names[i]).size() != ref_len){
46  throw cms::Exception("InvalidArgument") << "[DeepBoostedJetFeatures::check_consistency()] Inconsistent variable length "
47  << get(names[i]).size() << " for " << names[i] << ", should be " << ref_len;
48  }
49  }
50  }
51 
52  const std::vector<float>& get(const std::string& name) const {
53  auto item = feature_map_.find(name);
54  if (item != feature_map_.end()){
55  return item->second;
56  }else{
57  throw cms::Exception("InvalidArgument") << "[DeepBoostedJetFeatures::get()] Feature " << name << " does not exist!";
58  }
59  }
60 
61 private:
62  bool is_empty_ = true;
63  std::unordered_map<std::string, std::vector<float>> feature_map_;
64 
65 };
66 
67 }
68 
69 #endif // DataFormats_BTauReco_DeepBoostedJetFeatures_h
size
Write out results.
const std::string names[nVars_]
void reserve(const std::string &name, unsigned capacity)
Definition: value.py:1
void check_consistency(const std::vector< std::string > &names) const
std::unordered_map< std::string, std::vector< float > > feature_map_
void add(const std::string &name)
void fill(const std::string &name, float value)