AnalysisTree
Loading...
Searching...
No Matches
VariantMagic.hpp
1/* Copyright (C) 2019-2021 GSI, Universität Tübingen, MEPhI
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Viktor Klochkov, Eugeny Kashirin, Ilya Selyuzhenkov */
4#ifndef ANALYSISTREE_INFRA_VARIANTMAGIC_HPP_
5#define ANALYSISTREE_INFRA_VARIANTMAGIC_HPP_
6
7// I'm really sorry about this, blame Oleg
8// To be removed after c++17 will be available everywhere
9
10#include "TTree.h"
11
12#include "Cuts.hpp"
13#include "Utils.hpp"
14#include "Variable.hpp"
15
16namespace AnalysisTree {
17
18struct get_id_struct : public Utils::Visitor<size_t> {
19 template<typename Entity>
20 size_t get_id(Entity* d) const { return d->GetId(); }
21 template<typename Entity>
22 size_t operator()(Entity* d) const { return get_id<Entity>(d); }
23};
24
25struct get_channel_struct : public Utils::Visitor<ChannelPointer> {
26 explicit get_channel_struct(size_t i) : i_channel_(i) {}
27 template<typename Entity>
28 ChannelPointer get_channel(Entity* d) const { return ChannelPointer(&(d->Channel(i_channel_))); }
29 template<typename Entity>
30 ChannelPointer operator()(Entity* d) const { return get_channel<Entity>(d); }
31 size_t i_channel_;
32};
33
35 template<typename Entity>
36 void clear_channels(Entity* d) const { d->ClearChannels(); }
37 template<typename Entity>
38 void operator()(Entity* d) const { clear_channels<Entity>(d); }
39};
40
41struct new_channel_struct : public Utils::Visitor<void> {
42 explicit new_channel_struct(BranchConfig* config) : config_(config) {}
43 template<typename Entity>
44 void new_channel(Entity* d) const {
45 auto channel = d->AddChannel();
46 channel->Init(*config_);
47 }
48 template<typename Entity>
49 void operator()(Entity* d) const { new_channel<Entity>(d); }
50 BranchConfig* config_;
51};
52
53struct copy_content_struct : public Utils::Visitor<void> {
54 template<typename T1, typename T2>
55 void copy_content(T1* ch1, T2* ch2) const {
56 *ch1 = T1(Container(*ch2));
57 }
58 template<typename T1, typename T2>
59 void copy_content(Particle* ch1, Track* ch2) const {
60 *ch1 = Particle(*ch2);
61 }
62 template<typename T1, typename T2>
63 void operator()(T1* ch1, T2* ch2) const { copy_content<T1, T2>(ch1, ch2); }
64};
65
66template<typename T>
67struct get_field_struct : public Utils::Visitor<double> {
68 explicit get_field_struct(int id) : id_(id) {}
69 template<typename Entity>
70 double get_field(Entity* d) const { return d->template GetField<T>(id_); }
71 template<typename Entity>
72 double operator()(Entity* d) const { return get_field<Entity>(d); }
73 int id_{-999};
74};
75
76template<typename T>
77struct set_field_struct : public Utils::Visitor<void> {
78 set_field_struct(double value, int id) : value_(value), id_(id) {}
79 template<typename Entity>
80 void set_field(Entity* d) const { d->template SetField<T>(value_, id_); }
81 template<typename Entity>
82 void operator()(Entity* d) const { set_field<Entity>(d); }
83 double value_{0.};
84 int id_{-999};
85};
86
87struct get_n_channels_struct : public Utils::Visitor<size_t> {
88 template<class Det>
89 size_t get_n_channels(Det* d) const { return d->GetNumberOfChannels(); }
90 template<typename Entity>
91 size_t operator()(Entity* d) const { return get_n_channels<Entity>(d); }
92};
93
95 set_branch_address_struct(TTree* tree, std::string name) : tree_(tree), name_(std::move(name)) {}
96 template<class Det>
97 int set_branch_address(Det*& d) const { return tree_->SetBranchAddress(name_.c_str(), &d); }
98 template<typename Entity>
99 int operator()(Entity*& d) const { return set_branch_address<Entity>(d); }
100 TTree* tree_{nullptr};
101 std::string name_;
102};
103
104}// namespace AnalysisTree
105
106#endif//ANALYSISTREE_INFRA_VARIANTMAGIC_HPP_
A class to store configuration of the Container.
Definition BranchConfig.hpp:118
A class to store any number of integers, floats and bools.
Definition Container.hpp:18
Definition Particle.hpp:11
A class for a generic track with determined momentum.
Definition Track.hpp:22
Cuts keep list of SimpleCuts. Logical AND is applied for all SimpleCut in the Cuts object.
Definition BranchConfig.cpp:10
Definition Utils.hpp:46
Definition VariantMagic.hpp:34
Definition VariantMagic.hpp:53
Definition VariantMagic.hpp:25
Definition VariantMagic.hpp:67
Definition VariantMagic.hpp:18
Definition VariantMagic.hpp:87
Definition VariantMagic.hpp:41
Definition VariantMagic.hpp:94
Definition VariantMagic.hpp:77