14 #include "ROOT/RArrayView.hxx" 24 #include <type_traits> 35 using ColumnNames_t = std::vector<std::string>;
36 class TCustomColumnBase;
46 template <
typename... Types>
48 static constexpr std::size_t fgSize =
sizeof...(Types);
53 struct TFunctionTraits {
54 using Args_t =
typename TFunctionTraits<decltype(&T::operator())>::Args_t;
55 using ArgsNoDecay_t =
typename TFunctionTraits<decltype(&T::operator())>::ArgsNoDecay_t;
56 using Ret_t =
typename TFunctionTraits<decltype(&T::operator())>::Ret_t;
60 template <
typename R,
typename T,
typename... Args>
61 struct TFunctionTraits<
R (T::*)(Args...) const> {
63 using ArgsNoDecay_t = TTypeList<Args...>;
68 template <
typename R,
typename T,
typename... Args>
69 struct TFunctionTraits<
R (T::*)(Args...)> {
71 using ArgsNoDecay_t = TTypeList<Args...>;
76 template <
typename R,
typename... Args>
77 struct TFunctionTraits<
R (*)(Args...)> {
79 using ArgsNoDecay_t = TTypeList<Args...>;
84 template <
typename R,
typename... Args>
85 struct TFunctionTraits<
R(Args...)> {
87 using ArgsNoDecay_t = TTypeList<Args...>;
96 template <
typename T,
typename... Args>
97 struct TRemoveFirst<TTypeList<T, Args...>> {
98 using Types_t = TTypeList<Args...>;
102 template <
typename R,
typename F,
typename... Args>
103 std::function<
R(
unsigned int, Args...)> AddSlotParameter(F &
f, TTypeList<Args...>)
105 return [
f](
unsigned int, Args...
a) ->
R {
return f(
a...); };
114 template <
int N,
int...
S>
115 struct TGenStaticSeq : TGenStaticSeq<N - 1, N - 1, S...> {
119 struct TGenStaticSeq<0,
S...> {
120 using Type_t = TStaticSeq<
S...>;
123 template <
typename T>
124 struct TIsContainer {
127 template <
typename A>
128 static constexpr
bool Test(
A *
pt,
A const *cpt =
nullptr, decltype(pt->begin()) * =
nullptr,
129 decltype(pt->end()) * =
nullptr, decltype(cpt->begin()) * =
nullptr,
130 decltype(cpt->end()) * =
nullptr,
typename A::iterator *
pi =
nullptr,
131 typename A::const_iterator *pci =
nullptr)
133 using It_t =
typename A::iterator;
134 using CIt_t =
typename A::const_iterator;
135 using V_t =
typename A::value_type;
136 return std::is_same<Test_t, std::vector<bool>>::value ||
137 (std::is_same<decltype(pt->begin()), It_t>::value && std::is_same<decltype(pt->end()), It_t>::value &&
138 std::is_same<decltype(cpt->begin()), CIt_t>::value && std::is_same<decltype(cpt->end()), CIt_t>::value &&
139 std::is_same<decltype(**
pi), V_t &>::value && std::is_same<decltype(**pci), V_t const &>::value);
142 template <
typename A>
143 static constexpr
bool Test(...)
148 static const bool fgValue = Test<Test_t>(
nullptr);
152 template <
typename T>
153 struct TExtractType {
157 template <
typename T,
template <
typename...>
class U,
typename... Extras>
158 struct TExtractType<U<T, Extras...>> {
162 template <
typename T>
165 template <
typename BranchType,
typename... Rest>
166 struct TNeedJitting {
167 static constexpr
bool value = TNeedJitting<Rest...>::value;
170 template <
typename... Rest>
171 struct TNeedJitting<TInferType, Rest...> {
172 static constexpr
bool value =
true;
175 template <
typename T>
176 struct TNeedJitting<T> {
177 static constexpr
bool value =
false;
181 struct TNeedJitting<TInferType> {
182 static constexpr
bool value =
true;
185 using TVBPtr_t = std::shared_ptr<TTreeReaderValueBase>;
186 using TVBVec_t = std::vector<TVBPtr_t>;
196 template <
typename T>
197 struct TReaderValueOrArray {
201 template <
typename T>
202 struct TReaderValueOrArray<
std::array_view<T>> {
206 template <
typename T>
207 using ReaderValueOrArray_t =
typename TReaderValueOrArray<T>::Proxy_t;
213 template <
typename TDFValueTuple,
int...
S>
214 void InitTDFValues(
unsigned int slot, TDFValueTuple &valueTuple,
TTreeReader *
r,
const ColumnNames_t &bn,
215 const ColumnNames_t &tmpbn,
216 const std::map<std::string, std::shared_ptr<TCustomColumnBase>> &tmpBranches, TStaticSeq<S...>)
221 std::array<bool,
sizeof...(S)> isTmpColumn;
222 for (
auto i = 0u; i < isTmpColumn.size(); ++i)
223 isTmpColumn[i] = std::find(tmpbn.begin(), tmpbn.end(), bn.at(i)) != tmpbn.end();
228 std::initializer_list<int> expander{(isTmpColumn[
S]
229 ? std::get<S>(valueTuple).SetTmpColumn(slot, tmpBranches.at(bn.at(
S)).
get())
230 : std::get<S>(valueTuple).MakeProxy(r, bn.at(
S)),
237 template <
typename Filter>
238 void CheckFilter(Filter &)
240 using FilterRet_t =
typename TDF::TFunctionTraits<Filter>::Ret_t;
241 static_assert(std::is_same<FilterRet_t, bool>::value,
"filter functions must return a bool");
250 template <
typename F,
typename T>
251 void CheckReduce(F &, TTypeList<T, T>)
253 using Ret_t =
typename TFunctionTraits<F>::Ret_t;
254 static_assert(std::is_same<Ret_t, T>::value,
"reduce function must have return type equal to argument type");
260 template <
typename F,
typename T>
261 void CheckReduce(F &, T)
263 static_assert(
sizeof(F) == 0,
"reduce function must take exactly two arguments of the same type");
267 const ColumnNames_t &
PickBranchNames(
unsigned int nArgs,
const ColumnNames_t &bl,
const ColumnNames_t &defBl);
269 namespace ActionTypes {
290 template <typename T, bool ISV7HISTO = !std::is_base_of<TH1, T>::value>
292 const static bool fgValue = ISV7HISTO;
295 template <typename T, bool ISV7HISTO = TIsV7Histo<T>::fgValue>
297 static void SetCanExtendAllAxes(T &
h) { h.SetCanExtend(::
TH1::kAllAxes); }
298 static bool HasAxisLimits(T &h)
300 auto xaxis = h.GetXaxis();
301 return !(xaxis->GetXmin() == 0. && xaxis->GetXmax() == 0.);
305 template <
typename T>
306 struct HistoUtils<T, true> {
307 static void SetCanExtendAllAxes(T &) {}
308 static bool HasAxisLimits(T &) {
return true; }
TTreeReader is a simple, robust and fast interface to read values from a TTree, TChain or TNtuple...
Namespace for new ROOT classes and functions.
const ColumnNames_t & PickBranchNames(unsigned int nArgs, const ColumnNames_t &bl, const ColumnNames_t &defBl)
Returns local BranchNames or default BranchNames according to which one should be used...
Short_t Min(Short_t a, Short_t b)
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Extracts data from a TTree.
RooArgSet S(const RooAbsArg &v1)
Double_t Mean(Long64_t n, const T *a, const Double_t *w=0)
const char * ToConstCharPtr(const char *s)
std::string ColumnName2ColumnTypeName(const std::string &colName, TTree *tree, TCustomColumnBase *tmpBranch)
Return a string containing the type of the given branch.
Extracts array data from a TTree.
typedef void((*Func_t)())
Short_t Max(Short_t a, Short_t b)
void CheckTmpBranch(std::string_view branchName, TTree *treePtr)
A TTree object has a header with a name and a title.
static void Fill(TTree *tree, int init, int count)