Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/AnalysisTreeCoreLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#pragma link C++ class AnalysisTree::VectorConfig<int>+;
#pragma link C++ class AnalysisTree::VectorConfig<float>+;
#pragma link C++ class AnalysisTree::VectorConfig<double>+;
#pragma link C++ class AnalysisTree::VectorConfig<bool>+;
#pragma link C++ class AnalysisTree::ConfigElement+;
#pragma link C++ class AnalysisTree::Configuration_v3+;
Expand Down
34 changes: 27 additions & 7 deletions core/BranchConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ Types BranchConfig::GetFieldType(const std::string& sField) const {
id = VectorConfig<float>::GetId(sField);
if (id != UndefValueShort) return Types::kFloat;

id = VectorConfig<double>::GetId(sField);
if (id != UndefValueShort) return Types::kDouble;

id = VectorConfig<bool>::GetId(sField);
if (id != UndefValueShort) return Types::kBool;

Expand All @@ -81,6 +84,9 @@ ShortInt_t BranchConfig::GetFieldId(const std::string& sField) const {
id = VectorConfig<float>::GetId(sField);
if (id != UndefValueShort) return id;

id = VectorConfig<double>::GetId(sField);
if (id != UndefValueShort) return id;

id = VectorConfig<bool>::GetId(sField);
if (id != UndefValueShort) return id;

Expand All @@ -89,24 +95,30 @@ ShortInt_t BranchConfig::GetFieldId(const std::string& sField) const {

BranchConfig BranchConfig::Clone(const std::string& name, DetType type) const {
BranchConfig result(name, type);
for (const auto& field : AnalysisTree::VectorConfig<int>::map_) {
if (field.second.id_ >= 0) {
result.AddField<int>(field.first, field.second.id_, field.second.title_);
}
}
for (const auto& field : AnalysisTree::VectorConfig<float>::map_) {
if (field.second.id_ >= 0) {
result.AddField<float>(field.first, field.second.id_, field.second.title_);
}
}
for (const auto& field : AnalysisTree::VectorConfig<int>::map_) {
for (const auto& field : AnalysisTree::VectorConfig<double>::map_) {
if (field.second.id_ >= 0) {
result.AddField<int>(field.first, field.second.id_, field.second.title_);
result.AddField<double>(field.first, field.second.id_, field.second.title_);
}
}
for (const auto& field : AnalysisTree::VectorConfig<bool>::map_) {
if (field.second.id_ >= 0) {
result.AddField<bool>(field.first, field.second.id_, field.second.title_);
}
}
result.AnalysisTree::VectorConfig<bool>::size_ = AnalysisTree::VectorConfig<bool>::size_;
result.AnalysisTree::VectorConfig<int>::size_ = AnalysisTree::VectorConfig<int>::size_;
result.AnalysisTree::VectorConfig<float>::size_ = AnalysisTree::VectorConfig<float>::size_;
result.AnalysisTree::VectorConfig<double>::size_ = AnalysisTree::VectorConfig<double>::size_;
result.AnalysisTree::VectorConfig<bool>::size_ = AnalysisTree::VectorConfig<bool>::size_;

return result;
}
Expand All @@ -118,11 +130,14 @@ BranchConfig BranchConfig::CloneAndMerge(const BranchConfig& attached) const {

auto result = Clone(name1 + "_" + name2, type1);

for (const auto& field : attached.AnalysisTree::VectorConfig<int>::map_) {
result.AddField<int>(name2 + "_" + field.first, name2 + ": " + field.second.title_);
}
for (const auto& field : attached.AnalysisTree::VectorConfig<float>::map_) {
result.AddField<float>(name2 + "_" + field.first, name2 + ": " + field.second.title_);
}
for (const auto& field : attached.AnalysisTree::VectorConfig<int>::map_) {
result.AddField<int>(name2 + "_" + field.first, name2 + ": " + field.second.title_);
for (const auto& field : attached.AnalysisTree::VectorConfig<double>::map_) {
result.AddField<double>(name2 + "_" + field.first, name2 + ": " + field.second.title_);
}
for (const auto& field : attached.AnalysisTree::VectorConfig<bool>::map_) {
result.AddField<bool>(name2 + "_" + field.first, name2 + ": " + field.second.title_);
Expand Down Expand Up @@ -190,6 +205,7 @@ void VectorConfig<T>::RemoveField(const std::string& name, int id) {
m.second.id_--;
}
}
size_--;
}

void BranchConfig::RemoveField(const std::string& name) {
Expand All @@ -203,6 +219,7 @@ void BranchConfig::RemoveField(const std::string& name) {
}
if (field_type == Types::kInteger) VectorConfig<int>::RemoveField(name, field_id);
if (field_type == Types::kFloat) VectorConfig<float>::RemoveField(name, field_id);
if (field_type == Types::kDouble) VectorConfig<double>::RemoveField(name, field_id);
if (field_type == Types::kBool) VectorConfig<bool>::RemoveField(name, field_id);
}

Expand All @@ -214,10 +231,13 @@ void BranchConfig::GuaranteeFieldNameVacancy(const std::string& name) const {

void BranchConfig::Print() const {
std::cout << "Branch " << name_ << " (" << title_ << ") consists of:" << std::endl;
std::cout << "\nFloating fields:" << std::endl;
VectorConfig<float>::Print();
std::cout << "\nInteger fields:" << std::endl;
VectorConfig<int>::Print();
std::cout << "\nFloating fields:" << std::endl;
VectorConfig<float>::Print();
const std::string double_fields_empty_message = VectorConfig<double>::map_.empty() ? " no double fields in this branch" : "";
std::cout << "\nDouble fields:" << double_fields_empty_message << std::endl;
VectorConfig<double>::Print();
const std::string boolean_fields_empty_message = VectorConfig<bool>::map_.empty() ? " no boolean fields in this branch" : "";
std::cout << "\nBoolean fields:" << boolean_fields_empty_message << std::endl
<< std::endl;
Expand Down
4 changes: 2 additions & 2 deletions core/BranchConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class VectorConfig {
/**
* Maybe better design choise would be use composition over inheritance (?)
*/
class BranchConfig : public VectorConfig<int>, public VectorConfig<float>, public VectorConfig<bool> {
class BranchConfig : public VectorConfig<int>, public VectorConfig<float>, public VectorConfig<double>, public VectorConfig<bool> {

public:
BranchConfig() = default;
Expand Down Expand Up @@ -174,7 +174,7 @@ class BranchConfig : public VectorConfig<int>, public VectorConfig<float>, publi
size_t id_{0};
DetType type_{DetType(UndefValueShort)};

ClassDefOverride(BranchConfig, 4);
ClassDefOverride(BranchConfig, 5);
};

// BranchConfig Merge(const BranchConfig& primary, const BranchConfig& secondary);
Expand Down
20 changes: 20 additions & 0 deletions core/BranchConfig.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ TEST(BranchConfig, Basics) {
EXPECT_EQ(branch_config.GetFieldId("pz"), TrackFields::kPz);
}

TEST(BranchConfig, RemoveField) {
BranchConfig branch_config("RecTrack", DetType::kTrack);
branch_config.AddFields<float>({"f0", "f1", "f2"}, "just a test field");
EXPECT_EQ(branch_config.GetSize<float>(), 3);

branch_config.RemoveField("f1");
EXPECT_FALSE(branch_config.HasField("f1"));
EXPECT_EQ(branch_config.GetSize<float>(), 2);
EXPECT_EQ(branch_config.GetFieldId("f0"), 0);
EXPECT_EQ(branch_config.GetFieldId("f2"), 1);

// a field added after removal must get the next free id, not collide with existing ones
branch_config.AddField<float>("f3", "just a test field");
EXPECT_EQ(branch_config.GetFieldId("f3"), 2);
EXPECT_EQ(branch_config.GetSize<float>(), 3);

EXPECT_THROW(branch_config.RemoveField("pT"), std::runtime_error);
EXPECT_EQ(branch_config.GetSize<float>(), 3);
}

}// namespace

#endif//ANALYSISTREE_CORE_BRANCHCONFIG_TEST_H_
1 change: 1 addition & 0 deletions core/Constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ enum class Types : ShortInt_t {
kFloat = 0,
kInteger,
kBool,
kDouble,
kNumberOfTypes
};

Expand Down
12 changes: 12 additions & 0 deletions core/Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ std::vector<int>& Container::Vector<int>() { return ints_; }
template<>
std::vector<float>& Container::Vector<float>() { return floats_; }
template<>
std::vector<double>& Container::Vector<double>() { return doubles_; }
template<>
std::vector<bool>& Container::Vector<bool>() { return bools_; }

template<>
const std::vector<int>& Container::GetVector<int>() const { return ints_; }
template<>
const std::vector<float>& Container::GetVector<float>() const { return floats_; }
template<>
const std::vector<double>& Container::GetVector<double>() const { return doubles_; }
template<>
const std::vector<bool>& Container::GetVector<bool>() const { return bools_; }

void Container::Init(const AnalysisTree::BranchConfig& branch) {
doubles_.resize(branch.GetSize<double>());
floats_.resize(branch.GetSize<float>());
ints_.resize(branch.GetSize<int>());
bools_.resize(branch.GetSize<bool>());
Expand All @@ -42,6 +47,13 @@ void Container::Print() const noexcept {
}
std::cout << std::endl;
}
if (!doubles_.empty()) {
std::cout << "Double fields: ";
for (auto d : doubles_) {
std::cout << d << " ";
}
std::cout << std::endl;
}
if (!bools_.empty()) {
std::cout << "Boolean fields: ";
for (auto b : bools_) {
Expand Down
8 changes: 5 additions & 3 deletions core/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace AnalysisTree {

/// A class to store any number of integers, floats and bools.
/// A class to store any number of doubles, floats, integers and bools.
/**
* Consists of IndexedObject and separate std::vector<T>, for T={float, int, bool}.
* Consists of IndexedObject and separate std::vector<T>, for T={double, float, int, bool}.
* Intended to be used as a base class for all AnalysysTree objects.
*/

Expand All @@ -22,6 +22,7 @@ class Container : public IndexedObject {
explicit Container(size_t id) : IndexedObject(id) {}
Container(size_t id, const BranchConfig& branch)
: IndexedObject(id),
doubles_(branch.GetSize<double>()),
floats_(branch.GetSize<float>()),
ints_(branch.GetSize<int>()),
bools_(branch.GetSize<bool>()) {}
Expand Down Expand Up @@ -57,11 +58,12 @@ class Container : public IndexedObject {
virtual void Print() const noexcept;

protected:
std::vector<double> doubles_{};
std::vector<float> floats_{};
std::vector<int> ints_{};
std::vector<bool> bools_{};

ClassDefOverride(Container, 2);
ClassDefOverride(Container, 3);
};

}// namespace AnalysisTree
Expand Down
29 changes: 29 additions & 0 deletions core/Container.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ TEST(Container, Basics) {
EXPECT_EQ(container.GetField<bool>(0), true);
}

TEST(Container, Double) {
Container container;
EXPECT_EQ(container.GetSize<double>(), 0);

BranchConfig config("RecTrack", DetType::kTrack);
config.AddField<double>("test_d", "just a test field");
config.AddField<float>("test_f", "just a test field");

EXPECT_EQ(config.GetFieldType("test_d"), Types::kDouble);
EXPECT_EQ(config.GetFieldId("test_d"), 0);
EXPECT_EQ(config.GetFieldId("test_f"), 0);

container.Init(config);
EXPECT_EQ(container.GetSize<double>(), 1);

// value which cannot be represented exactly in float precision
const double value = 1. + 1e-12;
container.SetField(value, 0);
EXPECT_EQ(container.GetField<double>(0), value);
EXPECT_NE(static_cast<float>(value), value);

auto clone = config.Clone("RecTrackClone", DetType::kTrack);
EXPECT_EQ(clone.GetFieldType("test_d"), Types::kDouble);
EXPECT_EQ(clone.GetSize<double>(), 1);

config.RemoveField("test_d");
EXPECT_FALSE(config.HasField("test_d"));
}

}// namespace

#endif//ANALYSISTREE_CORE_CONTAINER_TEST_HPP_
7 changes: 7 additions & 0 deletions infra/Branch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ Field Branch::NewVariable(const std::string& field_name, const std::string& titl
using AnalysisTree::Types;

switch (type) {
case Types::kDouble: {
config_.template AddField<double>(field_name, title);
break;
}
case Types::kFloat: {
config_.template AddField<float>(field_name, title);
break;
Expand Down Expand Up @@ -117,6 +121,7 @@ void Branch::CloneVariables(const AnalysisTree::BranchConfig& other) {
}// map elements
};

import_fields_from_map(other.GetMap<double>(), AnalysisTree::Types::kDouble);
import_fields_from_map(other.GetMap<float>(), AnalysisTree::Types::kFloat);
import_fields_from_map(other.GetMap<int>(), AnalysisTree::Types::kInteger);
import_fields_from_map(other.GetMap<bool>(), AnalysisTree::Types::kBool);
Expand Down Expand Up @@ -190,6 +195,7 @@ void Branch::CreateMapping(const Branch* other, std::string branch_name_prefix)
other->CheckFrozen();

const std::map<AnalysisTree::Types, std::string> types_map = {
{AnalysisTree::Types::kDouble, "double"},
{AnalysisTree::Types::kFloat, "float"},
{AnalysisTree::Types::kInteger, "integer"},
{AnalysisTree::Types::kBool, "bool"}};
Expand Down Expand Up @@ -218,6 +224,7 @@ std::vector<std::string> Branch::GetFieldNames() const {
result.push_back(element.first);
}
};
fill_vector_from_map(config_.GetMap<double>());
fill_vector_from_map(config_.GetMap<float>());
fill_vector_from_map(config_.GetMap<int>());
fill_vector_from_map(config_.GetMap<bool>());
Expand Down
2 changes: 2 additions & 0 deletions infra/BranchChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ double BranchChannel::Value(const Field& v) const {

using AnalysisTree::Types;
switch (v.GetFieldType()) {
case Types::kDouble: return ANALYSISTREE_UTILS_VISIT(get_field_struct<double>(v.GetFieldId()), data_ptr_);
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_);
Expand All @@ -85,6 +86,7 @@ double BranchChannel::Value(const Field& v) const {
void BranchChannel::SetValue(const Field& v, double value) {
using AnalysisTree::Types;
switch (v.GetFieldType()) {
case Types::kDouble: ANALYSISTREE_UTILS_VISIT(set_field_struct<double>(value, v.GetFieldId()), data_ptr_); break;
case Types::kFloat: ANALYSISTREE_UTILS_VISIT(set_field_struct<float>(value, v.GetFieldId()), data_ptr_); break;
case Types::kInteger: ANALYSISTREE_UTILS_VISIT(set_field_struct<int>(value, v.GetFieldId()), data_ptr_); break;
case Types::kBool: ANALYSISTREE_UTILS_VISIT(set_field_struct<bool>(value, v.GetFieldId()), data_ptr_); break;
Expand Down
1 change: 1 addition & 0 deletions infra/BranchHashHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ inline std::size_t BranchConfigHasher(const AnalysisTree::BranchConfig& config)
}
};

hash_fields(config.GetMap<double>(), Type::kDouble);
hash_fields(config.GetMap<float>(), Type::kFloat);
hash_fields(config.GetMap<int>(), Type::kInteger);
hash_fields(config.GetMap<bool>(), Type::kBool);
Expand Down
4 changes: 4 additions & 0 deletions infra/ChainDrawHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ void ChainDrawHelper::DrawFieldTransform(std::string& expr) {
std::string type_str{};

switch (type) {
case (Types::kDouble): {
type_str = "double";
break;
}
case (Types::kFloat): {
type_str = "float";
break;
Expand Down
1 change: 1 addition & 0 deletions infra/Field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Field {
throw std::runtime_error("Field::Fill - Field " + field_ + " is not initialized");
}
switch (field_type_) {
case Types::kDouble: return object.template GetField<double>(field_id_);
case Types::kFloat: return object.template GetField<float>(field_id_);
case (Types::kInteger): return object.template GetField<int>(field_id_);
case Types::kBool: return object.template GetField<bool>(field_id_);
Expand Down
Loading
Loading