Skip to content

Commit f3b5e01

Browse files
committed
improve reading trees in ROOTObjectReader
1 parent a13c58e commit f3b5e01

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/modules/DetectorHistogrammer/DetectorHistogrammerModule.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void DetectorHistogrammerModule::init() {
105105
// Create cluster charge plot
106106
std::string cluster_charge_name = "cluster_charge";
107107
std::string cluster_charge_title = "Cluster charge for " + detector_->getName() + ";cluster charge [ke];clusters";
108-
cluster_charge = new TH1D(cluster_charge_name.c_str(), cluster_charge_title.c_str(), 200, 0., 100.);
108+
cluster_charge = new TH1D(cluster_charge_name.c_str(), cluster_charge_title.c_str(), 1000, 0., 50.);
109109
}
110110

111111
void DetectorHistogrammerModule::run(unsigned int) {

src/modules/ROOTObjectReader/ROOTObjectReaderModule.cpp

+21-9
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,30 @@ void ROOTObjectReaderModule::init() {
9898

9999
// Read all the trees in the file
100100
TList* keys = input_file_->GetListOfKeys();
101+
std::set<std::string> tree_names;
102+
101103
for(auto&& object : *keys) {
102104
auto& key = dynamic_cast<TKey&>(*object);
103105
if(std::string(key.GetClassName()) == "TTree") {
104-
trees_.push_back(static_cast<TTree*>(key.ReadObjectAny(nullptr)));
106+
auto tree = static_cast<TTree*>(key.ReadObjectAny(nullptr));
107+
108+
// Check if a version of this tree has already been read
109+
if(tree_names.find(tree->GetName()) != tree_names.end()) {
110+
LOG(TRACE) << "Skipping copy of tree with name " << tree->GetName()
111+
<< " because one with identical name has already been processed";
112+
continue;
113+
}
114+
tree_names.insert(tree->GetName());
115+
116+
// Check if this tree should be used
117+
if((!include_.empty() && include_.find(tree->GetName()) == include_.end()) ||
118+
(!exclude_.empty() && exclude_.find(tree->GetName()) != exclude_.end())) {
119+
LOG(TRACE) << "Ignoring tree with " << tree->GetName()
120+
<< " objects because it has been excluded or not explicitly included";
121+
continue;
122+
}
123+
124+
trees_.push_back(tree);
105125
}
106126
}
107127

@@ -111,14 +131,6 @@ void ROOTObjectReaderModule::init() {
111131

112132
// Loop over all found trees
113133
for(auto& tree : trees_) {
114-
// Check if this tree should be used
115-
if((!include_.empty() && include_.find(tree->GetName()) == include_.end()) ||
116-
(!exclude_.empty() && exclude_.find(tree->GetName()) != exclude_.end())) {
117-
LOG(TRACE) << "Ignoring tree with " << tree->GetName()
118-
<< " objects because it has been excluded or not explicitly included";
119-
continue;
120-
}
121-
122134
// Loop over the list of branches and create the set of receiver objects
123135
TObjArray* branches = tree->GetListOfBranches();
124136
for(int i = 0; i < branches->GetEntries(); i++) {

0 commit comments

Comments
 (0)