Skip to content

Commit 91e831a

Browse files
authored
Add PlainTreeFiller and TaskManager features (#145)
* PlainTreeFiller - add warning when try to ignore or preserve absent field * follow prev. commit * PlainTreeFiller: enable fields renaming * PlainTreeFiller - add warning when try to rename absent field * add GetObjectWithNullptrCheck to HelperFunctions * for (auto& -> for (const auto& * enable start TaskManager::Run() from arbitrary event * bugfix const in AnalysisTask.test.cpp; fix typos in ReadMe * bugfix a500e40 for the case of chain_->GetEntries() == 0
1 parent 2b64796 commit 91e831a

16 files changed

Lines changed: 105 additions & 45 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ Basic objects are:<br>
2929
- Hit (position and signal)<br>
3030
- Module (id and signal)<br>
3131
Four mentioned objects are so-called channelized:
32-
they contain set of channels (namely tracks, prticles, hits or modules) in each event<br>
32+
they contain set of channels (namely tracks, particles, hits or modules) in each event<br>
3333
- EventHeader (vertex position) - contains information related to specific event<br>
3434
- DataHeader - contains common information for all events<br>
3535
- Matching - establishes a correspondence between channels in channelized objects (e.g. between simulated particle and reconstructed track).
3636

37-
Additionaly to mandatory information specified in round brackets (a.k.a. "default fileds"), each object can contain any number of integer, floating or boolean fields (a.k.a. "user-defined fields").
37+
Additionally to mandatory information specified in round brackets (a.k.a. "default fields"), each object can contain any number of integer, floating or boolean fields (a.k.a. "user-defined fields").
3838
Information about all fields in all branches is stored in Configuration object.
3939

4040
## Installation

core/BranchConfig.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class BranchConfig : public VectorConfig<int>, public VectorConfig<float>, publi
113113
}
114114
template<typename T>
115115
void AddFields(const std::vector<std::string>& names, const std::string& title = "") {
116-
for (auto& n : names) {
116+
for (const auto& n : names) {
117117
GuaranteeFieldNameVacancy(n);
118118
}
119119
VectorConfig<T>::AddFields(names, title);
@@ -127,7 +127,7 @@ class BranchConfig : public VectorConfig<int>, public VectorConfig<float>, publi
127127
void RemoveField(const std::string& name);
128128

129129
void RemoveFields(const std::vector<std::string>& names) {
130-
for (auto& n : names) {
130+
for (const auto& n : names) {
131131
RemoveField(n);
132132
}
133133
}

core/Configuration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ BranchConfig& Configuration::GetBranchConfig(const std::string& name) {
6565
}
6666

6767
const BranchConfig& Configuration::GetBranchConfig(const std::string& name) const {
68-
for (auto& branch : branches_) {
68+
for (const auto& branch : branches_) {
6969
if (branch.second.GetName() == name)
7070
return branch.second;
7171
}
@@ -187,7 +187,7 @@ void Configuration::RemoveBranchConfig(const std::string& branchname) {
187187

188188
std::vector<std::string> Configuration::GetMatchesOfBranch(const std::string& branchname) const {
189189
std::vector<std::string> matches{};
190-
for (auto& ma : matches_) {
190+
for (const auto& ma : matches_) {
191191
if (ma.GetFirstBranchName() == branchname || ma.GetSecondBranchName() == branchname)
192192
matches.emplace_back(ma.GetDataBranchName());
193193
}

core/Configuration.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Configuration : public TObject {
102102

103103
static MatchingIndex MakeMatchingIndex(const std::vector<MatchingConfig>& matches) {
104104
MatchingIndex result;
105-
for (auto& match : matches) {
105+
for (const auto& match : matches) {
106106
std::array<std::string, 2> map_key{match.GetFirstBranchName(), match.GetSecondBranchName()};
107107
auto emplace_result = result.emplace(map_key, match.GetDataBranchName());
108108
if (!emplace_result.second) {
@@ -114,7 +114,7 @@ class Configuration : public TObject {
114114

115115
static std::vector<MatchingConfig> MakeMatchConfigsFromIndex(const MatchingIndex& matching_index) {
116116
std::vector<MatchingConfig> result;
117-
for (auto& matching_index_element : matching_index) {
117+
for (const auto& matching_index_element : matching_index) {
118118
result.emplace_back(matching_index_element.first[0],
119119
matching_index_element.first[1],
120120
matching_index_element.second);
@@ -130,10 +130,10 @@ class Configuration : public TObject {
130130
* @param other
131131
*/
132132
void Merge(const Configuration& other) {
133-
for (auto& other_branch : other.branches_) {
133+
for (const auto& other_branch : other.branches_) {
134134
const auto other_id = other_branch.second.GetId();
135135
const auto other_name = other_branch.second.GetName();
136-
for (auto& local_branch : branches_) {
136+
for (const auto& local_branch : branches_) {
137137
if (other_id == local_branch.second.GetId()) {
138138
throw std::runtime_error("Configurations contain branches with the same id-s");
139139
}

infra/AnalysisEntry.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace AnalysisTree {
1010

1111
AnalysisEntry::~AnalysisEntry() {
12-
for (auto& br : branches_) {
12+
for (const auto& br : branches_) {
1313
delete br.first;
1414
}
1515
}
@@ -45,7 +45,7 @@ bool AnalysisEntry::ApplyCutOnBranches(std::vector<const Branch*>& br, std::vect
4545
id_vec.emplace_back(br.at(i)->GetId());
4646
}
4747
bool result = ok && (!cuts_ || cuts_->Apply(bch_vec, id_vec));
48-
for (auto& bv : bch_vec) {
48+
for (const auto& bv : bch_vec) {
4949
delete bv;
5050
}
5151
return result;
@@ -77,7 +77,7 @@ double AnalysisEntry::FillVariable(const Variable& var, std::vector<const Branch
7777
id_vec.emplace_back(br.at(i)->GetId());
7878
}
7979
double result = var.GetValue(bch_vec, id_vec);
80-
for (auto& bv : bch_vec) {
80+
for (const auto& bv : bch_vec) {
8181
delete bv;
8282
}
8383
return result;
@@ -116,7 +116,7 @@ void AnalysisEntry::FillFromEveHeaders() {
116116
br_vec.reserve(branches_.size());
117117
cuts_vec.reserve(branches_.size());
118118
id_vec.reserve(branches_.size());
119-
for (auto& br : branches_) {
119+
for (const auto& br : branches_) {
120120
br_vec.emplace_back(br.first);
121121
cuts_vec.emplace_back(br.second);
122122
id_vec.emplace_back(0);
@@ -154,7 +154,7 @@ void AnalysisEntry::FillFromOneChannalizedBranch() {
154154
br_vec.emplace_back(br.first);
155155
cuts_vec.emplace_back(br.second);
156156
}
157-
for (auto& ehi : eve_header_indices_) {
157+
for (const auto& ehi : eve_header_indices_) {
158158
id_vec.at(ehi) = 0;
159159
}
160160

@@ -195,7 +195,7 @@ void AnalysisEntry::FillFromTwoChannalizedBranches() {
195195
br_vec.emplace_back(br.first);
196196
cuts_vec.emplace_back(br.second);
197197
}
198-
for (auto& ehi : eve_header_indices_) {
198+
for (const auto& ehi : eve_header_indices_) {
199199
id_vec.at(ehi) = 0;
200200
}
201201

@@ -216,7 +216,7 @@ void AnalysisEntry::FillFromTwoChannalizedBranches() {
216216
}
217217

218218
void AnalysisEntry::FillBranchNames() {
219-
for (auto& var : vars_) {
219+
for (const auto& var : vars_) {
220220
const auto& br = var.GetBranches();
221221
branch_names_.insert(br.begin(), br.end());
222222
}
@@ -236,7 +236,7 @@ void AnalysisEntry::Init(const Configuration& conf, const std::map<std::string,
236236
var4weight_.Init(conf);
237237

238238
int i{0};
239-
for (auto& bn : branch_names_) {
239+
for (const auto& bn : branch_names_) {
240240
if (conf.GetBranchConfig(bn).GetType() == DetType::kEventHeader) {
241241
eve_header_indices_.push_back(i);
242242
} else {

infra/Branch.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void Branch::ClearChannels() {
107107

108108
void Branch::CloneVariables(const AnalysisTree::BranchConfig& other) {
109109
auto import_fields_from_map = [this](const std::map<std::string, ConfigElement>& map, AnalysisTree::Types type) {
110-
for (auto& element : map) {
110+
for (const auto& element : map) {
111111
auto field_name = element.first;
112112
if (config_.HasField(field_name)) {
113113
std::cout << "Field '" << field_name << "' already exists" << std::endl;
@@ -190,7 +190,7 @@ void Branch::CreateMapping(const Branch* other, std::string branch_name_prefix)
190190

191191
std::cout << "New cached mapping " << other->config_.GetName() << " --> " << config_.GetName() << std::endl;
192192
FieldsMapping fields_mapping;
193-
for (auto& field_name_other : other->GetFieldNames()) {
193+
for (const auto& field_name_other : other->GetFieldNames()) {
194194
std::string field_name_target = branch_name_prefix + field_name_other;
195195
if (!config_.HasField(field_name_target)) { continue; }
196196
fields_mapping.field_pairs.emplace_back(other->GetField(field_name_other), GetField(field_name_target));
@@ -208,7 +208,7 @@ void Branch::UpdateConfigHash() {
208208
std::vector<std::string> Branch::GetFieldNames() const {
209209
std::vector<std::string> result;
210210
auto fill_vector_from_map = [&result](const std::map<std::string, ConfigElement>& fields_map) -> void {
211-
for (auto& element : fields_map) {
211+
for (const auto& element : fields_map) {
212212
result.push_back(element.first);
213213
}
214214
};

infra/BranchChannel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void BranchChannel::CopyContent(const BranchChannel& other, std::string branch_n
3535
/* Eval mapping */
3636
const auto& field_pairs = mapping_it->second.field_pairs;
3737

38-
for (auto& field_pair /* src : dst */ : field_pairs) {
38+
for (const auto& field_pair /* src : dst */ : field_pairs) {
3939
this->SetValue(field_pair.second, other.Value(field_pair.first));
4040
}
4141
}

infra/BranchHashHelper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ inline std::size_t BranchConfigHasher(const AnalysisTree::BranchConfig& config)
1919
hash_combine(hash, static_cast<AnalysisTree::ShortInt_t>(config.GetType()));
2020

2121
auto hash_fields = [&hash](const std::map<std::string, AnalysisTree::ConfigElement>& fields_map, Type field_type) {
22-
for (auto& field : fields_map) {
22+
for (const auto& field : fields_map) {
2323
hash_combine(hash, field.first, field.second.id_, static_cast<AnalysisTree::ShortInt_t>(field_type));
2424
}
2525
};

infra/Chain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void Chain::InitPointersToBranches(std::set<std::string> names) {
113113
if (CheckBranchExistence(branch.first) == 1)
114114
ANALYSISTREE_UTILS_VISIT(set_branch_address_struct(this, branch.first), branch.second);
115115
else if (CheckBranchExistence(branch.first) == 2)
116-
ANALYSISTREE_UTILS_VISIT(set_branch_address_struct(this, (branch.first + ".").c_str()), branch.second);
116+
ANALYSISTREE_UTILS_VISIT(set_branch_address_struct(this, branch.first + "."), branch.second);
117117
else
118118
throw std::runtime_error("AnalysisTree::InitPointersToBranches - Branch " + branch.first + " does not exist");
119119
}
@@ -225,7 +225,7 @@ std::vector<TChain*> Chain::GetTChains() {
225225
int Chain::CheckBranchExistence(const std::string& branchname) {
226226
auto v_chains = this->GetTChains();
227227

228-
for (auto& ch : v_chains) {
228+
for (const auto& ch : v_chains) {
229229
auto* lob = ch->GetListOfBranches();
230230
const int Nbranches = lob->GetEntries();
231231
for (int i = 0; i < Nbranches; i++) {

infra/Cuts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void Cuts::AddCut(const SimpleCut& cut) {
8383
}
8484

8585
void Cuts::AddCuts(const std::vector<SimpleCut>& cuts) {
86-
for (auto& cut : cuts) {
86+
for (const auto& cut : cuts) {
8787
AddCut(cut);
8888
}
8989
}

0 commit comments

Comments
 (0)