31 #ifndef minitreedataset_h 32 #define minitreedataset_h 37 #include "filval/filval.hpp" 38 #include "filval_root/filval_root.hpp" 45 class MiniTreeDataSet :
public DataSet,
48 std::map<std::string,std::string> input_filenames_with_labels;
50 std::string output_filename;
55 if (next_entry >= nentries)
return false;
56 fChain->GetEntry(next_entry);
63 int get_current_event(){
68 MiniTreeDataSet(
const std::string& output_filename,
const std::string input_filename)
70 input_filenames_with_labels({ {input_filename,
"signal"} }),
71 output_filename(output_filename),
73 TChain* chain =
new TChain(
"tree");
74 chain->Add(input_filename.c_str());
76 nentries = fChain->GetEntries();
77 output_file = TFile::Open(output_filename.c_str(),
"RECREATE");
78 this->fChain->SetBranchStatus(
"*",
false);
81 MiniTreeDataSet(
const std::string& output_filename,
const std::map<std::string,std::string>& filenames_with_labels)
83 input_filenames_with_labels(filenames_with_labels),
84 output_filename(output_filename),
86 TChain* chain =
new TChain(
"tree");
87 for(
auto& p : filenames_with_labels){
89 std::tie(filename, std::ignore) = p;
90 chain->Add(filename.c_str());
93 nentries = fChain->GetEntries();
94 output_file = TFile::Open(output_filename.c_str(),
"RECREATE");
95 this->fChain->SetBranchStatus(
"*",
false);
102 const std::string& get_current_event_label()
const{
103 TFile* file = fChain->GetFile();
104 std::string filename = file->GetName();
105 return input_filenames_with_labels.at(filename);
108 template <
typename T>
109 Value<T>* track_branch(
const std::string& bname){
110 TBranch* branch = fChain->GetBranch(bname.c_str());
111 if (branch ==
nullptr){
112 CRITICAL(
"Branch: " << bname <<
" does not exist in input tree.", -1);
114 T* bref = (T*) branch->GetAddress();
115 fChain->SetBranchStatus(bname.c_str(),
true);
116 INFO(
"Registering branch \"" << bname
117 <<
"\" with address " << bref
118 <<
" and type " <<
typeid(bref).name());
122 template <
typename T>
123 Value<T*>* track_branch_ptr(
const std::string& bname){
124 TBranch* branch = fChain->GetBranch(bname.c_str());
125 if (branch ==
nullptr){
126 CRITICAL(
"Branch: " << bname <<
" does not exist in input tree.", -1);
128 T* bref = (T*) branch->GetAddress();
129 fChain->SetBranchStatus(bname.c_str(),
true);
130 INFO(
"Registering pointer branch \"" << bname
131 <<
"\" with address " << bref
132 <<
" and type " <<
typeid(bref).name());
136 template <
typename T>
137 decltype(
auto) track_branch_vec(const
std::
string& size_bname, const
std::
string& value_bname){
138 track_branch_ptr<T>(value_bname);
139 return wrapper_vector<T>(lookup<int>(size_bname), lookup<T*>(value_bname), value_bname);
147 std::map<string,string> value_lookup = this->get_container_name_value_map();
148 gDirectory->WriteObjectAny(&value_lookup,
"std::map<std::string,std::string>",
"_value_lookup");
150 std::map<string,string> fn_impl_lookup = this->get_function_name_impl_map();
151 gDirectory->WriteObjectAny(&fn_impl_lookup,
"std::map<std::string,std::string>",
"_function_impl_lookup");
153 for(
auto container : containers){
154 container.second->save_as(
"outfile", SaveOption::ROOT);
158 #endif // minitreedataset_h
A value supplied by the dataset, not derived.
The namespace containing all filval classes and functions.