|
4 | 4 |
|
5 | 5 | #include "GenericContainerFiller.hpp" |
6 | 6 |
|
| 7 | +#include <fstream> |
| 8 | + |
7 | 9 | using namespace AnalysisTree; |
8 | 10 |
|
9 | 11 | GenericContainerFiller::GenericContainerFiller(std::string fileInName, std::string treeInName) : file_in_name_(std::move(fileInName)), |
10 | 12 | tree_in_name_(std::move(treeInName)) {} |
11 | 13 |
|
12 | 14 | void GenericContainerFiller::Init() { |
13 | | - file_in_ = TFile::Open(file_in_name_.c_str(), "read"); |
14 | | - if (file_in_ == nullptr) throw std::runtime_error("GenericContainerFiller::Run(): file_in_ == nullptr"); |
| 15 | + tree_in_ = new TChain(tree_in_name_.c_str()); |
| 16 | + |
| 17 | + auto ends_with = [](const std::string& str, const std::string& suffix) { |
| 18 | + if (suffix.size() > str.size()) return false; |
| 19 | + return std::equal(suffix.rbegin(), suffix.rend(), str.rbegin()); |
| 20 | + }; |
| 21 | + |
| 22 | + if(ends_with(file_in_name_, ".root")) { |
| 23 | + tree_in_->Add(file_in_name_.c_str()); |
| 24 | + } else { |
| 25 | + std::ifstream filelist(file_in_name_); |
| 26 | + std::string line; |
15 | 27 |
|
16 | | - tree_in_ = file_in_->Get<TTree>(tree_in_name_.c_str()); |
17 | | - if (tree_in_ == nullptr) throw std::runtime_error("GenericContainerFiller::Run(): tree_in_ == nullptr"); |
| 28 | + if (!filelist) throw std::runtime_error("GenericContainerFiller::Init(): filelist " + file_in_name_ + " is missing"); |
| 29 | + |
| 30 | + while (std::getline(filelist, line)) { |
| 31 | + tree_in_->Add(line.c_str()); |
| 32 | + } |
| 33 | + } |
18 | 34 |
|
19 | 35 | if (!fields_to_ignore_.empty() && !fields_to_preserve_.empty()) throw std::runtime_error("GenericContainerFiller::Run(): !fields_to_ignore_.empty() && !fields_to_preserve_.empty()"); |
20 | 36 |
|
@@ -74,7 +90,7 @@ void GenericContainerFiller::Finish() { |
74 | 90 | config_.Write("Configuration"); |
75 | 91 | tree_out_->Write(); |
76 | 92 | file_out_->Close(); |
77 | | - file_in_->Close(); |
| 93 | + delete tree_in_; |
78 | 94 | } |
79 | 95 |
|
80 | 96 | void GenericContainerFiller::Run(int nEntries) { |
|
0 commit comments