@@ -33,6 +33,15 @@ void PlainTreeFiller::SetFieldsToPreserve(const std::vector<std::string>& fields
3333 }
3434}
3535
36+ void PlainTreeFiller::SetFieldsToRename (const std::vector<std::pair<std::string, std::string>>& fields_to_rename) {
37+ if (branch_name_.empty ()) {
38+ throw std::runtime_error (" PlainTreeFiller::SetFieldsToRename() must be called after PlainTreeFiller::AddBranch()\n " );
39+ }
40+ for (const auto & ftr : fields_to_rename) {
41+ fields_to_rename_.emplace ((branch_name_ + " ." + ftr.first ).c_str (), (branch_name_ + " ." + ftr.second ).c_str ());
42+ }
43+ }
44+
3645void PlainTreeFiller::Init () {
3746 if (is_ignore_defual_fields_) {
3847 std::vector<std::string> defaultFieldsNames;
@@ -103,6 +112,9 @@ void PlainTreeFiller::Init() {
103112 std::string leaf_name = leafNames.at (iLeaf);
104113 if (!fields_to_ignore_.empty () && std::find (fields_to_ignore_.begin (), fields_to_ignore_.end (), leaf_name) != fields_to_ignore_.end ()) continue ;
105114 if (!fields_to_preserve_.empty () && std::find (fields_to_preserve_.begin (), fields_to_preserve_.end (), leaf_name) == fields_to_preserve_.end ()) continue ;
115+ if (!fields_to_rename_.empty () && fields_to_rename_.find (leaf_name) != fields_to_rename_.end ()) {
116+ leaf_name = fields_to_rename_.at (leaf_name);
117+ }
106118 if (!is_prepend_leaves_with_branchname_) leaf_name.erase (0 , branch_name_.size () + 1 );
107119 std::replace (leaf_name.begin (), leaf_name.end (), ' .' , ' _' );
108120 if (vars_.at (iLeaf).type_ == Types::kFloat ) plain_tree_->Branch (leaf_name.c_str (), &vars_.at (iLeaf).float_ , Form (" %s/F" , leaf_name.c_str ()));
0 commit comments