Skip to content

Commit

Permalink
apply clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
lubynets committed Jul 22, 2024
1 parent 0cd0774 commit 1b4aee8
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 48 deletions.
2 changes: 1 addition & 1 deletion core/BranchConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class VectorConfig {

int name_strlen{0};
for (const auto& entry : map_) {
name_strlen = std::max(name_strlen, (int)entry.first.length());
name_strlen = std::max(name_strlen, (int) entry.first.length());
}
name_strlen += 4;

Expand Down
40 changes: 20 additions & 20 deletions infra/AnalysisEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace AnalysisTree {

AnalysisEntry::~AnalysisEntry() {
for(auto& br : branches_) {
for (auto& br : branches_) {
delete br.first;
}
}
Expand All @@ -24,18 +24,18 @@ bool AnalysisEntry::ApplyCutOnBranch(const Branch& br, Cuts* cuts, int i_channel
}

bool AnalysisEntry::ApplyCutOnBranches(std::vector<const Branch*>& br, std::vector<Cuts*>& cuts, std::vector<int>& ch) const {
if(br.size() != cuts.size() || cuts.size() != ch.size()) {
if (br.size() != cuts.size() || cuts.size() != ch.size()) {
throw std::runtime_error("AnalysisTree::AnalysisEntry::ApplyCutOnBranches() - Branch, Cuts and Ch vectors must have the same size");
}
bool ok{true};
std::vector<const BranchChannel*> bch_vec;
std::vector<size_t> id_vec;
bch_vec.reserve(br.size());
id_vec.reserve(br.size());
for(int i=0; i<br.size(); i++) {
for (int i = 0; i < br.size(); i++) {
BranchChannel* bchptr = new BranchChannel(br.at(i), ch.at(i));
if(cuts.at(i) != nullptr) {
if(!cuts.at(i)->Apply(*bchptr)) {
if (cuts.at(i) != nullptr) {
if (!cuts.at(i)->Apply(*bchptr)) {
ok = false;
delete bchptr;
break;
Expand All @@ -45,7 +45,7 @@ bool AnalysisEntry::ApplyCutOnBranches(std::vector<const Branch*>& br, std::vect
id_vec.emplace_back(br.at(i)->GetId());
}
bool result = ok && (!cuts_ || cuts_->Apply(bch_vec, id_vec));
for(auto& bv : bch_vec) {
for (auto& bv : bch_vec) {
delete bv;
}
return result;
Expand All @@ -64,20 +64,20 @@ bool AnalysisEntry::ApplyCutOnBranches(const Branch& br1, Cuts* cuts1, int ch1,
}

double AnalysisEntry::FillVariable(const Variable& var, std::vector<const Branch*>& br, std::vector<int>& id) {
if(br.size() != id.size()) {
if (br.size() != id.size()) {
throw std::runtime_error("AnalysisTree::AnalysisEntry::FillVariable() - Branch and Id vectors must have the same size");
}
std::vector<const BranchChannel*> bch_vec;
std::vector<size_t> id_vec;
bch_vec.reserve(br.size());
id_vec.reserve(br.size());
for(int i=0; i<br.size(); i++) {
for (int i = 0; i < br.size(); i++) {
BranchChannel* bchptr = new BranchChannel(br.at(i), id.at(i));
bch_vec.emplace_back(bchptr);
id_vec.emplace_back(br.at(i)->GetId());
}
double result = var.GetValue(bch_vec, id_vec);
for(auto& bv : bch_vec) {
for (auto& bv : bch_vec) {
delete bv;
}
return result;
Expand Down Expand Up @@ -116,7 +116,7 @@ void AnalysisEntry::FillFromEveHeaders() {
br_vec.reserve(branches_.size());
cuts_vec.reserve(branches_.size());
id_vec.reserve(branches_.size());
for(auto& br : branches_) {
for (auto& br : branches_) {
br_vec.emplace_back(br.first);
cuts_vec.emplace_back(br.second);
id_vec.emplace_back(0);
Expand Down Expand Up @@ -150,11 +150,11 @@ void AnalysisEntry::FillFromOneChannalizedBranch() {
br_vec.reserve(branches_.size());
cuts_vec.reserve(branches_.size());
id_vec.resize(branches_.size());
for(const auto& br : branches_) {
for (const auto& br : branches_) {
br_vec.emplace_back(br.first);
cuts_vec.emplace_back(br.second);
}
for(auto& ehi : eve_header_indices_) {
for (auto& ehi : eve_header_indices_) {
id_vec.at(ehi) = 0;
}

Expand All @@ -178,7 +178,7 @@ void AnalysisEntry::FillFromOneChannalizedBranch() {
* It iterates over registered matches and fills variables
*/
void AnalysisEntry::FillFromTwoChannalizedBranches() {
if(matching_ == nullptr) {
if (matching_ == nullptr) {
throw std::runtime_error("AnalysisEntry::FillFromTwoChannalizedBranches() - Matching between non-EventHeader branches must be set");
}

Expand All @@ -191,11 +191,11 @@ void AnalysisEntry::FillFromTwoChannalizedBranches() {
br_vec.reserve(branches_.size());
cuts_vec.reserve(branches_.size());
id_vec.resize(branches_.size());
for(const auto& br : branches_) {
for (const auto& br : branches_) {
br_vec.emplace_back(br.first);
cuts_vec.emplace_back(br.second);
}
for(auto& ehi : eve_header_indices_) {
for (auto& ehi : eve_header_indices_) {
id_vec.at(ehi) = 0;
}

Expand Down Expand Up @@ -236,22 +236,22 @@ void AnalysisEntry::Init(const Configuration& conf, const std::map<std::string,
var4weight_.Init(conf);

int i{0};
for(auto& bn : branch_names_) {
if(conf.GetBranchConfig(bn).GetType() == DetType::kEventHeader) {
for (auto& bn : branch_names_) {
if (conf.GetBranchConfig(bn).GetType() == DetType::kEventHeader) {
eve_header_indices_.push_back(i);
} else {
non_eve_header_indices_.push_back(i);
}
i++;
}
if(branch_names_.size() == 0) {
if (branch_names_.size() == 0) {
throw std::runtime_error("AnalysisEntry::Init() - at least 1 branch is needed");
}
if(non_eve_header_indices_.size() > 2) {
if (non_eve_header_indices_.size() > 2) {
throw std::runtime_error("AnalysisEntry::Init() - 2 non-EventHeader branches are allowed as maximum");
}

if(non_eve_header_indices_.size() == 2) {
if (non_eve_header_indices_.size() == 2) {
auto match_info = conf.GetMatchInfo(*std::next(branch_names_.begin(), non_eve_header_indices_.at(0)), *std::next(branch_names_.begin(), non_eve_header_indices_.at(1)));
SetIsInvertedMatching(match_info.second);
SetMatching((Matching*) matches.find(match_info.first)->second);
Expand Down
8 changes: 4 additions & 4 deletions infra/AnalysisEntry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class AnalysisEntry {
AnalysisEntry() = default;
virtual ~AnalysisEntry();

explicit AnalysisEntry(std::vector<Variable> vars, Cuts* cuts = nullptr, Variable vars4weight={}) : vars_(std::move(vars)),
var4weight_(std::move(vars4weight)),
cuts_(cuts) {
explicit AnalysisEntry(std::vector<Variable> vars, Cuts* cuts = nullptr, Variable vars4weight = {}) : vars_(std::move(vars)),
var4weight_(std::move(vars4weight)),
cuts_(cuts) {
var4weight_.IfEmptyVariableConvertToOnes(vars_.at(0));
FillBranchNames();
};
Expand Down Expand Up @@ -77,7 +77,7 @@ class AnalysisEntry {
Matching* matching_{nullptr};///< non-owning
bool is_inverted_matching_{false};

array2D values_{};///< channels<variables>
array2D values_{}; ///< channels<variables>
array1D weights_{};///< channels<weights>

ClassDef(AnalysisEntry, 1);
Expand Down
20 changes: 11 additions & 9 deletions infra/BranchChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ void BranchChannel::MergeContentFromTwoChannels(const BranchChannel& first, cons
int matching_case{-1};
bool first_channel_active = !first.IsNullChannel();
bool second_channel_active = !second.IsNullChannel();
if(first_channel_active) {
if(second_channel_active) matching_case = 0;
else matching_case = 1;
if (first_channel_active) {
if (second_channel_active) matching_case = 0;
else
matching_case = 1;
} else {
if(second_channel_active) matching_case = 2;
else throw std::runtime_error("BranchChannel::MergeContentFromTwoChannels() : both channels are null");
if (second_channel_active) matching_case = 2;
else
throw std::runtime_error("BranchChannel::MergeContentFromTwoChannels() : both channels are null");
}

if(first_channel_active) CopyContent(first);
if(second_channel_active) CopyContent(second, second.branch_->GetBranchName());
if (first_channel_active) CopyContent(first);
if (second_channel_active) CopyContent(second, second.branch_->GetBranchName());
this->SetValue(branch_->GetField("matching_case"), matching_case);
}

Expand All @@ -69,14 +71,14 @@ double BranchChannel::Value(const Field& v) const {
// assert(v.GetBranchId() == branch_->GetId()); // TODO
assert(v.IsInitialized());

if(v.GetName() == "ones") return 1;
if (v.GetName() == "ones") return 1;

using AnalysisTree::Types;
switch (v.GetFieldType()) {
case Types::kFloat: return ANALYSISTREE_UTILS_VISIT(get_field_struct<float>(v.GetFieldId()), data_ptr_);
case Types::kInteger: return ANALYSISTREE_UTILS_VISIT(get_field_struct<int>(v.GetFieldId()), data_ptr_);
case Types::kBool: return ANALYSISTREE_UTILS_VISIT(get_field_struct<bool>(v.GetFieldId()), data_ptr_);
default: throw std::runtime_error("Field type is not correct!"); //NOTE commented because of Ones field NOTE now commented again
default: throw std::runtime_error("Field type is not correct!");//NOTE commented because of Ones field NOTE now commented again
}
}

Expand Down
2 changes: 1 addition & 1 deletion infra/Chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ Configuration* Chain::CloneConfiguration() const {
const int Nbranches = lob->GetEntries();
for (int i = 0; i < Nbranches; i++) {
std::string name_i = lob->At(i)->GetName();
if(name_i.back() == '.') {
if (name_i.back() == '.') {
name_i.pop_back();
}
result->RemoveBranchConfig(name_i);
Expand Down
2 changes: 1 addition & 1 deletion infra/Chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Chain : public TChain {
/**
* @brief Clones tree without friends
*/
TTree* CloneChain(int nentries=0);
TTree* CloneChain(int nentries = 0);

/**
* @brief Clones Configuration of input Chain without friends
Expand Down
2 changes: 1 addition & 1 deletion infra/Cuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool Cuts::Apply(std::vector<const BranchChannel*>& bch, std::vector<size_t>& id
if (!is_init_) {
throw std::runtime_error("Cuts::Apply - cut is not initialized!!");
}
if(bch.size() != id.size()) {
if (bch.size() != id.size()) {
throw std::runtime_error("AnalysisTree::Cuts::Apply() - BranchChannel and Id vectors must have the same size");
}
// std::all_of(cuts_.begin(), cuts_.end(), Apply(a, a_id, b, b_id)); //TODO
Expand Down
2 changes: 1 addition & 1 deletion infra/Field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void Field::Init(const BranchConfig& branch_conf) {
branch_type_ = branch_conf.GetType();
field_id_ = branch_conf.GetFieldId(field_);
field_type_ = branch_conf.GetFieldType(field_);
if (field_id_ == UndefValueInt && field_!="ones") {
if (field_id_ == UndefValueInt && field_ != "ones") {
std::cout << "WARNING!! Field::Init - " << field_ << " is not found in branch " << branch_ << std::endl;
}
is_init_ = true;
Expand Down
6 changes: 3 additions & 3 deletions infra/PlainTreeFiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#include "TTree.h"

#include "TaskManager.hpp"
#include "PlainTreeFiller.hpp"
#include "TaskManager.hpp"

namespace AnalysisTree {

Expand Down Expand Up @@ -57,8 +57,8 @@ void PlainTreeFiller::Init() {
plain_tree_->Branch(leaf_name.c_str(), &(vars_.at(i)), Form("%s/F", leaf_name.c_str()));
}

for(auto& cm : cuts_map_) {
if(cm.second != nullptr) {
for (auto& cm : cuts_map_) {
if (cm.second != nullptr) {
cm.second->Init(*(TaskManager::GetInstance()->GetChain()->GetConfiguration()));
}
}
Expand Down
2 changes: 1 addition & 1 deletion infra/SimpleCut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ SimpleCut::SimpleCut(const Variable& var, double min, double max, std::string ti
}

bool SimpleCut::Apply(std::vector<const BranchChannel*>& bch, std::vector<size_t>& id) const {
if(bch.size() != id.size()) {
if (bch.size() != id.size()) {
throw std::runtime_error("AnalysisTree::SimpleCut::Apply() - BranchChannel and Id vectors must have the same size");
}
std::vector<double> variables;
Expand Down
4 changes: 2 additions & 2 deletions infra/TaskManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ void TaskManager::Finish() {
std::cout << "Output file is " << out_file_name_ << std::endl;
std::cout << "Output tree is " << out_tree_name_ << std::endl;
out_file_->cd();
if(out_tree_->GetListOfFriends() != nullptr) {
if(out_tree_->GetListOfFriends()->GetEntries() != 0) {
if (out_tree_->GetListOfFriends() != nullptr) {
if (out_tree_->GetListOfFriends()->GetEntries() != 0) {
std::cout << "Warining: TaskManager::Finish() - out_tree_ has friends which can be wrongly read from the output file\n";
}
}
Expand Down
8 changes: 4 additions & 4 deletions infra/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ double Variable::GetValue(const BranchChannel& object) const {

double Variable::GetValue(std::vector<const BranchChannel*>& bch, std::vector<size_t>& id) const {
assert(is_init_);
if(bch.size() != id.size()) {
if (bch.size() != id.size()) {
throw std::runtime_error("AnalysisTree::Variable::GetValue() - BranchChannel and Id vectors must have the same size");
}
vars_.clear();
for (const auto& field : fields_) {
bool success{false};
for(int i=0; i<bch.size(); i++) {
if(field.GetBranchId() == id.at(i)) {
for (int i = 0; i < bch.size(); i++) {
if (field.GetBranchId() == id.at(i)) {
vars_.emplace_back(bch.at(i)->Value(field));
success = true;
break;
}
}
if(!success) {
if (!success) {
throw std::runtime_error("Variable::Fill - Cannot fill value from branch " + field.GetBranchName());
}
}
Expand Down

0 comments on commit 1b4aee8

Please sign in to comment.