27 Branch(
const Branch&) =
default;
28 Branch(Branch&&) =
default;
29 Branch& operator=(Branch&&) =
default;
30 Branch& operator=(
const Branch&) =
default;
32 explicit Branch(
BranchConfig config) : config_(std::move(config)) {
38 Branch(
BranchConfig config, T* data) : config_(std::move(config)), data_(data) {
42 Branch(
BranchConfig config, BranchPointer ptr) : config_(std::move(config)), data_(std::move(ptr)) {
49 std::vector<std::pair<
Field ,
Field >> field_pairs;
53 [[nodiscard]] std::string GetBranchName()
const {
return config_.GetName(); }
54 [[nodiscard]] DetType GetBranchType()
const {
return config_.GetType(); }
55 [[nodiscard]]
const BranchConfig& GetConfig()
const {
return config_; }
59 BranchChannel NewChannel();
60 BranchChannel NullChannel();
62 Field NewVariable(
const std::string& field_name,
const std::string& title, AnalysisTree::Types type);
63 void CloneVariables(
const AnalysisTree::BranchConfig& other);
66 [[nodiscard]]
size_t size()
const;
68 BranchChannel operator[](
size_t i_channel)
const {
69 return BranchChannel(
this, i_channel);
72 std::vector<std::string> GetFieldNames()
const;
74 [[nodiscard]]
size_t GetId()
const {
75 return ANALYSISTREE_UTILS_VISIT(get_id_struct(), data_);
78 [[nodiscard]] BranchPointer GetData()
const {
return data_; }
80 [[nodiscard]] T& GetDataRaw() {
return ANALYSISTREE_UTILS_GET<T>(data_); }
82 [[nodiscard]] Field GetField(std::string field_name)
const {
83 Field field(config_.GetName(), std::move(field_name));
89 AnalysisTree::BranchConfig config_;
91 bool is_mutable_{
false};
92 bool is_frozen_{
false};
93 std::size_t config_hash_{0};
96 AnalysisTree::Configuration* parent_config{
nullptr};
97 mutable std::map<
const Branch* ,
FieldsMapping> copy_fields_mapping;
100 void Freeze(
bool freeze =
true) { is_frozen_ = freeze; };
101 void SetMutable(
bool is_mutable =
true) { Branch::is_mutable_ = is_mutable; }
104 inline void CheckFrozen(
bool expected =
true)
const {
105 if (is_frozen_ != expected) {
106 const std::string prefix = expected ?
"un" :
"";
107 const std::string message =
"Branch " + config_.GetName() +
" is " + prefix +
"frozen while the opposite was expected";
108 throw std::runtime_error(message);
111 inline void CheckMutable(
bool expected =
true)
const {
112 if (is_mutable_ != expected) {
113 const std::string prefix = expected ?
"im" :
"";
114 const std::string message =
"Branch " + config_.GetName() +
" is " + prefix +
"mutable while the opposite was expected";
115 throw std::runtime_error(message);
126 template<
typename... Args>
127 auto GetVars(Args... field_name) {
128 return GetVarsImpl(std::array<std::string,
sizeof...(Args)>{{std::string(field_name)...}},
129 std::make_index_sequence<
sizeof...(Args)>());
135 void UseFields(std::vector<std::pair<std::string, std::reference_wrapper<Field>>>&& vars,
bool ignore_missing =
false);
142 template<
typename EntityPtr>
143 constexpr static const bool is_event_header_v =
144 std::is_same_v<AnalysisTree::EventHeader, std::remove_const_t<std::remove_pointer_t<EntityPtr>>>;
149 void CreateMapping(
const Branch* other, std::string branch_name_prefix =
"")
const;
151 void UpdateConfigHash();
153 [[nodiscard]] AnalysisTree::ShortInt_t Hash()
const {
154 const auto hasher = std::hash<std::string>();
155 return AnalysisTree::ShortInt_t(hasher(config_.GetName()));