RDFAnalysis  0.1.1
Physics analysis with ROOT::RDataFrame
SysResultPtr.h
Go to the documentation of this file.
1 #ifndef RDFAnalysis_SysResultPtr_H
2 #define RDFAnalysis_SysResultPtr_H
3 
4 // Package includes
6 
12 namespace RDFAnalysis {
23  template <typename T>
24  class SysResultPtr {
25  public:
30  SysResultPtr(const std::string& nominalName) :
31  m_nominal(nominalName) {}
32 
39  template <typename U,
40  typename = std::enable_if_t<std::is_base_of<T, U>{} || std::is_same<T, U>{}, void>>
42  const std::string& nominalName,
43  const std::map<std::string, ROOT::RDF::RResultPtr<U>>& resultMap) :
44  m_nominal(nominalName)
45  {
46  for (const auto& p : resultMap)
47  addResult(p.first, p.second);
48  }
49 
51  auto begin() { return m_wrappers.begin(); }
52 
54  auto begin() const { return m_wrappers.begin(); }
55 
57  auto end() { return m_wrappers.end(); }
58 
60  auto end() const { return m_wrappers.end(); }
61 
64  std::size_t size() const { return m_wrappers.size(); }
65 
67  void setMap(const std::map<std::string, ResultWrapper<T>>& newMap) { m_wrappers = newMap; }
68 
70  void reset() { m_wrappers.clear(); }
71 
77  T* get(const std::string& syst)
78  {
79  auto itr = m_wrappers.find(syst);
80  return itr == m_wrappers.end()
81  ? m_wrappers.at(m_nominal).get()
82  : itr->second.get();
83  }
84 
91  // TODO (maybe) - make it impossible to overwrite a result with this
92  // method, or rather to make it throw an error if you try...
93  bool addResult(
94  const std::string& systematic,
95  const ResultWrapper<T>& result)
96  {
97  return m_wrappers.insert(std::make_pair(systematic, result) ).second;
98  }
99 
105  template <typename U,
106  typename = std::enable_if_t<std::is_base_of<T, U>{}, void>
107  >
109  m_nominal(other.m_nominal)
110  {
111  for (const auto& p : other)
112  m_wrappers.insert(std::make_pair(
113  p.first, ResultWrapper<T>(p.second) ) );
114  }
115 
117  operator bool() const { return m_wrappers.size() != 0; }
118 
119  private:
120  template <typename U>
121  friend class SysResultPtr;
122  std::string m_nominal;
123  std::map<std::string, ResultWrapper<T>> m_wrappers;
124  };
125 }
126 #endif //> !RDFAnalysis_SysResultPtr_H
SysResultPtr(const std::string &nominalName)
Create the result.
Definition: SysResultPtr.h:30
std::size_t size() const
Size of the map (i.e. the number of systematics affecting this result)
Definition: SysResultPtr.h:64
bool addResult(const std::string &systematic, const ResultWrapper< T > &result)
Add the result wrapper for a given systematic.
Definition: SysResultPtr.h:93
auto end()
Iterator to the end of the underlying map.
Definition: SysResultPtr.h:57
SysResultPtr(const SysResultPtr< U > &other)
Allow type conversions in copy construction.
Definition: SysResultPtr.h:108
Class for wrapping RResultPtrs.
Definition: CutflowDetail.h:11
auto begin()
Iterator to the start of the underlying map.
Definition: SysResultPtr.h:51
void setMap(const std::map< std::string, ResultWrapper< T >> &newMap)
Set from a map.
Definition: SysResultPtr.h:67
Class to wrap together RResultPtrs for different systematic variations.
Definition: SysResultPtr.h:24
void reset()
Reset all results.
Definition: SysResultPtr.h:70
auto end() const
Const iterator to the end of the underlying map.
Definition: SysResultPtr.h:60
Wrapper class for RResultPtrs.
Definition: ResultWrapper.h:25
auto begin() const
Const iterator to the start of the underlying map.
Definition: SysResultPtr.h:54
SysResultPtr(const std::string &nominalName, const std::map< std::string, ROOT::RDF::RResultPtr< U >> &resultMap)
Create the result from an existing map.
Definition: SysResultPtr.h:41