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
3 changes: 2 additions & 1 deletion form/persistence/persistence_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "persistence_utils.hpp"
#include "storage/istorage.hpp"

#include <cstdint>
#include <memory>
#include <stdexcept>
#include <string>
Expand Down Expand Up @@ -98,7 +99,7 @@ std::unique_ptr<token> persistence_reader::get_token(std::string const& creator,
std::string const full_label = build_full_label(row_space, label);
std::string const index_label = build_full_label(row_space, "index");

int const row_id = store_reader_->get_index(
std::uint64_t const row_id = store_reader_->get_index(
token{config_item->file_name, index_label, config_item->technology}, id, tech_settings_);
return std::make_unique<token>(
config_item->file_name, full_label, config_item->technology, row_id);
Expand Down
10 changes: 6 additions & 4 deletions form/root_storage/root_rfield_read_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#include <TFile.h> // IWYU pragma: keep

#include <cassert>
#include <cstdint>
#include <cstring>
#include <memory>
#include <mutex>
#include <stdexcept>
#include <string>
#include <typeinfo>
#include <utility>

namespace {
std::mutex& root_rfield_read_mutex()
Expand Down Expand Up @@ -87,7 +87,9 @@ namespace form::detail::experimental {
}
}

bool root_rfield_read_container_imp::read(int id, void const** data, std::type_info const& type)
bool root_rfield_read_container_imp::read(std::uint64_t id,
void const** data,
std::type_info const& type)
{
std::scoped_lock const guard(root_rfield_read_mutex());
try {
Expand Down Expand Up @@ -117,7 +119,7 @@ namespace form::detail::experimental {
return true;
}

int root_rfield_read_container_imp::entries()
std::uint64_t root_rfield_read_container_imp::entries()
{
std::scoped_lock const guard(root_rfield_read_mutex());

Expand All @@ -140,7 +142,7 @@ namespace form::detail::experimental {
" does not exist");
}

return static_cast<int>(reader_->GetNEntries());
return static_cast<std::uint64_t>(reader_->GetNEntries());
}

void root_rfield_read_container_imp::create_view(std::type_info const& type)
Expand Down
5 changes: 3 additions & 2 deletions form/root_storage/root_rfield_read_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "storage/storage_read_container.hpp"

#include <cstdint>
#include <memory>
#include <string>

Expand Down Expand Up @@ -36,8 +37,8 @@ namespace form::detail::experimental {

void set_file(std::shared_ptr<i_storage_file> file) override;
void prime(std::type_info const& type) override;
bool read(int id, void const** data, std::type_info const& type) override;
int entries() override;
bool read(std::uint64_t id, void const** data, std::type_info const& type) override;
std::uint64_t entries() override;

private:
std::shared_ptr<TFile> tfile_;
Expand Down
99 changes: 48 additions & 51 deletions form/root_storage/root_tbranch_read_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
#include <TTree.h>
#include <gsl/pointers>

#include <cstdint>
#include <memory>
#include <mutex>
#include <stdexcept>
#include <string>
#include <typeinfo>
#include <utility>

using namespace form::detail::experimental;

Expand All @@ -31,6 +33,43 @@ namespace {
static std::mutex m;
return m;
}

// Allocates a buffer for a fundamental branch type; the caller owns it.
gsl::owner<void*> new_fundamental(Int_t data_type, std::type_info const& type)
{
switch (data_type) {
case kChar_t:
return new Char_t;
case kUChar_t:
return new UChar_t;
case kShort_t:
return new Short_t;
case kUShort_t:
return new UShort_t;
case kInt_t:
return new Int_t;
case kUInt_t:
return new UInt_t;
case kLong_t:
return new Long_t;
case kULong_t:
return new ULong_t;
case kLong64_t:
return new Long64_t;
case kULong64_t:
return new ULong64_t;
case kFloat_t:
return new Float_t;
case kDouble_t:
return new Double_t;
case kBool_t:
return new Bool_t;
default:
throw std::runtime_error(
std::string{"root_tbranch_read_container_imp::read unsupported fundamental type: "} +
demangle_name(type));
}
}
}

root_tbranch_read_container_imp::root_tbranch_read_container_imp(std::string const& name) :
Expand Down Expand Up @@ -86,7 +125,9 @@ void root_tbranch_read_container_imp::prime(std::type_info const& type)
}
}

bool root_tbranch_read_container_imp::read(int id, void const** data, std::type_info const& type)
bool root_tbranch_read_container_imp::read(std::uint64_t id,
void const** data,
std::type_info const& type)
{
std::scoped_lock const guard(root_tbranch_read_mutex());

Expand All @@ -106,7 +147,7 @@ bool root_tbranch_read_container_imp::read(int id, void const** data, std::type_
if (branch_ == nullptr) {
throw std::runtime_error("root_tbranch_read_container_imp::read no branch found");
}
if (id >= tree_->GetEntries()) {
if (std::cmp_greater_equal(id, tree_->GetEntries())) {
return false;
}

Expand All @@ -123,51 +164,7 @@ bool root_tbranch_read_container_imp::read(int id, void const** data, std::type_
if (dict_info->Property() & EProperty::kIsFundamental) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
auto* fund_info = static_cast<TDataType*>(dict_info); // Already checked to be fundamental
switch (fund_info->GetType()) {
case kChar_t:
branch_buffer = new Char_t;
break;
case kUChar_t:
branch_buffer = new UChar_t;
break;
case kShort_t:
branch_buffer = new Short_t;
break;
case kUShort_t:
branch_buffer = new UShort_t;
break;
case kInt_t:
branch_buffer = new Int_t;
break;
case kUInt_t:
branch_buffer = new UInt_t;
break;
case kLong_t:
branch_buffer = new Long_t;
break;
case kULong_t:
branch_buffer = new ULong_t;
break;
case kLong64_t:
branch_buffer = new Long64_t;
break;
case kULong64_t:
branch_buffer = new ULong64_t;
break;
case kFloat_t:
branch_buffer = new Float_t;
break;
case kDouble_t:
branch_buffer = new Double_t;
break;
case kBool_t:
branch_buffer = new Bool_t;
break;
default:
throw std::runtime_error(
std::string{"root_tbranch_read_container_imp::read unsupported fundamental type: "} +
demangle_name(type));
};
branch_buffer = new_fundamental(fund_info->GetType(), type);
branch_status = tree_->SetBranchAddress(
col_name().c_str(), branch_buffer, nullptr, EDataType(fund_info->GetType()), false);
} else {
Expand All @@ -194,8 +191,8 @@ bool root_tbranch_read_container_imp::read(int id, void const** data, std::type_
std::to_string(branch_status));
}

Long64_t const tentry = tree_->LoadTree(id);
branch_->GetEntry(tentry);
// ROOT addresses entries as Long64_t; id < GetEntries() was checked above.
branch_->GetEntry(tree_->LoadTree(static_cast<Long64_t>(id)));
*data = branch_buffer;

// Reset the branch address to avoid unwanted ownership issues.
Expand All @@ -204,7 +201,7 @@ bool root_tbranch_read_container_imp::read(int id, void const** data, std::type_
return true;
}

int root_tbranch_read_container_imp::entries()
std::uint64_t root_tbranch_read_container_imp::entries()
{
std::scoped_lock const guard(root_tbranch_read_mutex());

Expand All @@ -224,5 +221,5 @@ int root_tbranch_read_container_imp::entries()
if (branch_ == nullptr) {
throw std::runtime_error("root_tbranch_read_container_imp::entries no branch found");
}
return static_cast<int>(tree_->GetEntries());
return static_cast<std::uint64_t>(tree_->GetEntries());
}
5 changes: 3 additions & 2 deletions form/root_storage/root_tbranch_read_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "storage/storage_read_container.hpp"

#include <cstdint>
#include <memory>
#include <string>

Expand All @@ -25,8 +26,8 @@ namespace form::detail::experimental {
void set_file(std::shared_ptr<i_storage_file> file) override;
void prime(std::type_info const& type) override;

bool read(int id, void const** data, std::type_info const& type) override;
int entries() override;
bool read(std::uint64_t id, void const** data, std::type_info const& type) override;
std::uint64_t entries() override;

private:
std::shared_ptr<TFile> tfile_;
Expand Down
11 changes: 6 additions & 5 deletions form/storage/istorage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ namespace form::detail::experimental {
i_storage_reader() = default;
virtual ~i_storage_reader() = default;

virtual int get_index(token const& token,
std::string const& id,
form::experimental::config::tech_setting_config const& settings) = 0;
virtual std::uint64_t get_index(
token const& token,
std::string const& id,
form::experimental::config::tech_setting_config const& settings) = 0;
virtual void prime(token const& token,
std::type_info const& type,
form::experimental::config::tech_setting_config const& settings) = 0;
Expand Down Expand Up @@ -99,8 +100,8 @@ namespace form::detail::experimental {

virtual void set_file(std::shared_ptr<i_storage_file> file) = 0;
virtual void prime(std::type_info const& type) = 0;
virtual bool read(int id, void const** data, std::type_info const& type) = 0;
virtual int entries() = 0;
virtual bool read(std::uint64_t id, void const** data, std::type_info const& type) = 0;
virtual std::uint64_t entries() = 0;

virtual void set_attribute(std::string const& name, std::string const& value) = 0;
};
Expand Down
5 changes: 3 additions & 2 deletions form/storage/storage_read_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "core/container_naming.hpp"
#include "storage/istorage.hpp"

#include <cstdint>
#include <memory>
#include <stdexcept>
#include <string>
Expand All @@ -27,14 +28,14 @@ void storage_read_container::set_file(std::shared_ptr<i_storage_file> file) { fi

void storage_read_container::prime(std::type_info const& /*type*/) {}

bool storage_read_container::read(int /* id*/,
bool storage_read_container::read(std::uint64_t /* id*/,
void const** /*data*/,
std::type_info const& /* type*/)
{
return false;
}

int storage_read_container::entries() { return 0; }
std::uint64_t storage_read_container::entries() { return 0; }

void storage_read_container::set_attribute(std::string const& /*name*/,
std::string const& /*value*/)
Expand Down
5 changes: 3 additions & 2 deletions form/storage/storage_read_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "istorage.hpp"

#include <cstdint>
#include <memory>
#include <string>

Expand All @@ -24,8 +25,8 @@ namespace form::detail::experimental {
void set_file(std::shared_ptr<i_storage_file> file) override;
void prime(std::type_info const& type) override;

bool read(int id, void const** data, std::type_info const& type) override;
int entries() override;
bool read(std::uint64_t id, void const** data, std::type_info const& type) override;
std::uint64_t entries() override;

void set_attribute(std::string const& name, std::string const& value) override;

Expand Down
17 changes: 9 additions & 8 deletions form/storage/storage_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "storage/istorage.hpp"

#include <cstddef>
#include <cstdint>
#include <map>
#include <memory>
#include <stdexcept>
Expand Down Expand Up @@ -60,9 +61,10 @@ namespace form::detail::experimental {
}
}

int storage_reader::get_index(token const& token,
std::string const& id,
form::experimental::config::tech_setting_config const& settings)
std::uint64_t storage_reader::get_index(
token const& token,
std::string const& id,
form::experimental::config::tech_setting_config const& settings)
{
auto const& index = index_map(token, settings);
auto const found = index.find(id);
Expand Down Expand Up @@ -113,7 +115,7 @@ std::vector<std::string> storage_reader::list_indices(
return result;
}

std::map<std::string, int> const& storage_reader::index_map(
std::map<std::string, std::uint64_t> const& storage_reader::index_map(
token const& token, form::experimental::config::tech_setting_config const& settings)
{
auto const cont_key = std::make_pair(token.file_name(), token.container_name());
Expand Down Expand Up @@ -143,9 +145,9 @@ std::map<std::string, int> const& storage_reader::index_map(
cont->second->set_file(file->second);
}

std::map<std::string, int> index;
std::map<std::string, std::uint64_t> index;
auto const& type = typeid(std::string);
int row = 0;
std::uint64_t row = 0;
void const* raw_data = nullptr;
while (cont->second->read(row, &raw_data, type)) {
std::unique_ptr<std::string const> const id(static_cast<std::string const*>(raw_data));
Expand Down Expand Up @@ -189,6 +191,5 @@ void storage_reader::read_container(token const& token,
cont->second->set_attribute(key, value);
}
}
// TODO: token::id() is a 64-bit row; the read container interface still takes an int entry. Narrow explicitly here (exact for all realistic row counts). Widening the read path to 64-bit is a follow-up PR.
cont->second->read(static_cast<int>(token.id()), data, type);
cont->second->read(token.id(), data, type);
}
Loading
Loading