DAS  3.0
Das Analysis System
SelfAwareBranch.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPLv3-or-later
2 //
3 // SPDX-FileCopyrightText: Patrick L.S. Connor <patrick.connor@cern.ch>
4 
5 #pragma once
6 
7 #include <cmath>
8 
9 #include <functional>
10 #include <string>
11 #include <vector>
12 
13 namespace Darwin::Tools {
14 
21 template<typename... Args>
23 public:
24  virtual void Fill (Args... args) = 0;
25  virtual void Clear () = 0;
26  virtual ~SelfAwareBranch () = default;
27 };
28 
43 template<typename U /* output branch type */, typename... Args>
44 class SelfAwarePlainBranch : public SelfAwareBranch<Args...> {
45  U * ptr;
46  std::function<U(Args...)> setter;
47 public:
49  const std::string& name,
50  std::function<U(Args...)> setter
51  ) : ptr(flow.GetBranchWriteOnly<U>(name))
52  , setter(setter) { }
53  void Fill (Args... args) override { *ptr = setter(args...); }
54  void Clear () override { *ptr = std::nan("NaN"); }
55 };
56 
73 template<typename U /* output branch type */, typename... Args>
74 class SelfAwareVectorBranch : public SelfAwareBranch<Args...> {
75  std::vector<U> * ptr;
76  std::function<U(Args...)> setter;
77 public:
79  const std::string& name,
80  std::function<U(Args...)> setter
81  ) : ptr(flow.GetBranchWriteOnly<std::vector<U>>(name))
82  , setter(setter) { }
83  void Fill (Args... args) override { ptr->push_back(setter(args...)); }
84  void Clear () override { ptr->clear(); }
85 };
86 
87 } // end of Darwin::Tools namespace
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.name
name
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:48
Darwin::Tools::SelfAwarePlainBranch::setter
std::function< U(Args...)> setter
Definition: SelfAwareBranch.h:46
Darwin::Tools::Flow
User-friendly handling of input and output n-tuples.
Definition: Flow.h:80
Darwin::Tools::SelfAwarePlainBranch::SelfAwarePlainBranch
SelfAwarePlainBranch(Tools::Flow &flow, const std::string &name, std::function< U(Args...)> setter)
Definition: SelfAwareBranch.h:48
Darwin::Tools::SelfAwareVectorBranch::SelfAwareVectorBranch
SelfAwareVectorBranch(Tools::Flow &flow, const std::string &name, std::function< U(Args...)> setter)
Definition: SelfAwareBranch.h:78
Ntupliser_cfg.args
args
Definition: Ntupliser_cfg.py:11
Darwin::Tools::SelfAwareVectorBranch::setter
std::function< U(Args...)> setter
Definition: SelfAwareBranch.h:76
Darwin::Tools::SelfAwareVectorBranch::Fill
void Fill(Args... args) override
Definition: SelfAwareBranch.h:83
Darwin::Tools::SelfAwarePlainBranch::Fill
void Fill(Args... args) override
Definition: SelfAwareBranch.h:53
Darwin::Tools::SelfAwarePlainBranch::Clear
void Clear() override
Definition: SelfAwareBranch.h:54
Darwin::Tools::SelfAwarePlainBranch
Type for a plain-type branch that knows how to fill itself.
Definition: SelfAwareBranch.h:44
Darwin::Tools::SelfAwareVectorBranch
Type for a vector branch that knows how to fill itself.
Definition: SelfAwareBranch.h:74
Darwin::Tools::SelfAwarePlainBranch::ptr
U * ptr
for NANOAOD-lile tree, expect Bool_t, Char_t, UChar_t, UInt, ...
Definition: SelfAwareBranch.h:45
Darwin::Tools::SelfAwareVectorBranch::Clear
void Clear() override
Definition: SelfAwareBranch.h:84
Darwin::Tools
Classes and functions related to the framework.
Definition: Darwin_dict.cxx:1144
Darwin::Tools::SelfAwareBranch::Fill
virtual void Fill(Args... args)=0
Darwin::Tools::SelfAwareBranch::Clear
virtual void Clear()=0
Darwin::Tools::SelfAwareVectorBranch::ptr
std::vector< U > * ptr
Definition: SelfAwareBranch.h:75
Darwin::Tools::SelfAwareBranch::~SelfAwareBranch
virtual ~SelfAwareBranch()=default
Darwin::Tools::SelfAwareBranch
Abstract type for a branch that knows how to fill itself.
Definition: SelfAwareBranch.h:22