Skip to content

Commit 937b05d

Browse files
committed
enable run GenericContainerFiller with filelist
1 parent 24420e1 commit 937b05d

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

infra/GenericContainerFiller.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,33 @@
44

55
#include "GenericContainerFiller.hpp"
66

7+
#include <fstream>
8+
79
using namespace AnalysisTree;
810

911
GenericContainerFiller::GenericContainerFiller(std::string fileInName, std::string treeInName) : file_in_name_(std::move(fileInName)),
1012
tree_in_name_(std::move(treeInName)) {}
1113

1214
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;
1527

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+
}
1834

1935
if (!fields_to_ignore_.empty() && !fields_to_preserve_.empty()) throw std::runtime_error("GenericContainerFiller::Run(): !fields_to_ignore_.empty() && !fields_to_preserve_.empty()");
2036

@@ -74,7 +90,7 @@ void GenericContainerFiller::Finish() {
7490
config_.Write("Configuration");
7591
tree_out_->Write();
7692
file_out_->Close();
77-
file_in_->Close();
93+
delete tree_in_;
7894
}
7995

8096
void GenericContainerFiller::Run(int nEntries) {

infra/GenericContainerFiller.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include "Container.hpp"
1010
#include "Detector.hpp"
1111

12+
#include <TChain.h>
1213
#include <TFile.h>
13-
#include <TTree.h>
1414

1515
#include <string>
1616
#include <vector>
@@ -73,8 +73,7 @@ class GenericContainerFiller {
7373
std::string tree_out_name_{"aTree"};
7474
std::string branch_out_name_{"PlainBranch"};
7575

76-
TFile* file_in_{nullptr};
77-
TTree* tree_in_{nullptr};
76+
TChain* tree_in_{nullptr};
7877
TFile* file_out_{nullptr};
7978
TTree* tree_out_{nullptr};
8079

0 commit comments

Comments
 (0)