From 09080eceab4ec0d609d2ca67c83656f415e9b182 Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Mon, 12 Jan 2026 19:01:18 +0000 Subject: [PATCH 1/9] FORM: Add IWYU header for std::exception --- form/form/form.cpp | 2 ++ form/storage/storage_container.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/form/form/form.cpp b/form/form/form.cpp index 8689685d..c899490a 100644 --- a/form/form/form.cpp +++ b/form/form/form.cpp @@ -2,6 +2,8 @@ #include "form.hpp" +#include + namespace form::experimental { form_interface::form_interface(std::shared_ptr tm, diff --git a/form/storage/storage_container.cpp b/form/storage/storage_container.cpp index 30a988c3..f9b4a4ed 100644 --- a/form/storage/storage_container.cpp +++ b/form/storage/storage_container.cpp @@ -3,6 +3,8 @@ #include "storage_container.hpp" #include "storage_file.hpp" +#include + using namespace form::detail::experimental; Storage_Container::Storage_Container(std::string const& name) : m_name(name), m_file(nullptr) {} From 3e0d75d51969634660ff4b7c0161438bb9cd4b08 Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Mon, 12 Jan 2026 20:25:48 +0000 Subject: [PATCH 2/9] FORM: Pass arg by const std::string& arg --- form/root_storage/root_tbranch_container.cpp | 2 +- form/root_storage/root_tbranch_container.hpp | 2 +- form/root_storage/root_ttree_container.cpp | 2 +- form/root_storage/root_ttree_container.hpp | 2 +- form/storage/istorage.hpp | 2 +- form/storage/storage_container.cpp | 2 +- form/storage/storage_container.hpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/form/root_storage/root_tbranch_container.cpp b/form/root_storage/root_tbranch_container.cpp index e8b7e566..49c062e1 100644 --- a/form/root_storage/root_tbranch_container.cpp +++ b/form/root_storage/root_tbranch_container.cpp @@ -117,7 +117,7 @@ void ROOT_TBranch_ContainerImp::commit() return; } -bool ROOT_TBranch_ContainerImp::read(int id, void const** data, std::string& type) +bool ROOT_TBranch_ContainerImp::read(int id, void const** data, std::string const& type) { if (m_tfile == nullptr) { throw std::runtime_error("ROOT_TBranch_ContainerImp::read no file attached"); diff --git a/form/root_storage/root_tbranch_container.hpp b/form/root_storage/root_tbranch_container.hpp index 3d2785dd..085ce9a0 100644 --- a/form/root_storage/root_tbranch_container.hpp +++ b/form/root_storage/root_tbranch_container.hpp @@ -27,7 +27,7 @@ namespace form::detail::experimental { void setupWrite(std::string const& type = "") override; void fill(void const* data) override; void commit() override; - bool read(int id, void const** data, std::string& type) override; + bool read(int id, void const** data, std::string const& type) override; private: std::shared_ptr m_tfile; diff --git a/form/root_storage/root_ttree_container.cpp b/form/root_storage/root_ttree_container.cpp index 1300f1ce..990ad851 100644 --- a/form/root_storage/root_ttree_container.cpp +++ b/form/root_storage/root_ttree_container.cpp @@ -69,7 +69,7 @@ void ROOT_TTree_ContainerImp::commit() throw std::runtime_error("ROOT_TTree_ContainerImp::commit not implemented"); } -bool ROOT_TTree_ContainerImp::read(int /* id*/, void const** /* data*/, std::string& /* type*/) +bool ROOT_TTree_ContainerImp::read(int /* id*/, void const** /* data*/, std::string const& /* type*/) { throw std::runtime_error("ROOT_TTree_ContainerImp::read not implemented"); } diff --git a/form/root_storage/root_ttree_container.hpp b/form/root_storage/root_ttree_container.hpp index 5133ebe8..c1d65b41 100644 --- a/form/root_storage/root_ttree_container.hpp +++ b/form/root_storage/root_ttree_container.hpp @@ -25,7 +25,7 @@ namespace form::detail::experimental { void setupWrite(std::string const& type = "") override; void fill(void const* data) override; void commit() override; - bool read(int id, void const** data, std::string& type) override; + bool read(int id, void const** data, std::string const& type) override; TTree* getTTree(); diff --git a/form/storage/istorage.hpp b/form/storage/istorage.hpp index 647c06df..f59357cf 100644 --- a/form/storage/istorage.hpp +++ b/form/storage/istorage.hpp @@ -58,7 +58,7 @@ namespace form::detail::experimental { virtual void setupWrite(std::string const& type = "") = 0; virtual void fill(void const* data) = 0; virtual void commit() = 0; - virtual bool read(int id, void const** data, std::string& type) = 0; + virtual bool read(int id, void const** data, std::string const& type) = 0; virtual void setAttribute(std::string const& name, std::string const& value) = 0; }; diff --git a/form/storage/storage_container.cpp b/form/storage/storage_container.cpp index f9b4a4ed..7ceb599c 100644 --- a/form/storage/storage_container.cpp +++ b/form/storage/storage_container.cpp @@ -19,7 +19,7 @@ void Storage_Container::fill(void const* /* data*/) { return; } void Storage_Container::commit() { return; } -bool Storage_Container::read(int /* id*/, void const** /*data*/, std::string& /* type*/) +bool Storage_Container::read(int /* id*/, void const** /*data*/, std::string const& /* type*/) { return false; } diff --git a/form/storage/storage_container.hpp b/form/storage/storage_container.hpp index 6b595048..b5a63dea 100644 --- a/form/storage/storage_container.hpp +++ b/form/storage/storage_container.hpp @@ -22,7 +22,7 @@ namespace form::detail::experimental { void setupWrite(std::string const& type = "") override; void fill(void const* data) override; void commit() override; - bool read(int id, void const** data, std::string& type) override; + bool read(int id, void const** data, std::string const& type) override; void setAttribute(std::string const& name, std::string const& value) override; From 55084a969007b2ce2f79af864a5d360249d16b8d Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Fri, 9 Jan 2026 22:34:02 +0000 Subject: [PATCH 3/9] Switch product from type_index to type_info --- phlex/model/products.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phlex/model/products.hpp b/phlex/model/products.hpp index 8c8b0120..6d330a5c 100644 --- a/phlex/model/products.hpp +++ b/phlex/model/products.hpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include @@ -15,7 +15,7 @@ namespace phlex::experimental { struct product_base { virtual ~product_base() = default; virtual void const* address() const = 0; - virtual std::type_index type() const = 0; + virtual std::type_info const& type() const = 0; }; template @@ -28,7 +28,7 @@ namespace phlex::experimental { explicit product(T&& prod) : obj{std::move(prod)} {} void const* address() const final { return &obj; } - virtual std::type_index type() const { return std::type_index{typeid(T)}; } + std::type_info const& type() const final { return typeid(T); } std::remove_cvref_t obj; }; From e1552cb5e1bbed20063161ccfdd6341e0460a784 Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Fri, 9 Jan 2026 22:34:36 +0000 Subject: [PATCH 4/9] Switch FORM from type_index to type_info --- form/form/form.cpp | 23 +++++++------ form/form/form.hpp | 6 ++-- form/form_module.cpp | 18 +++++------ form/persistence/ipersistence.hpp | 7 ++-- form/persistence/persistence.cpp | 15 +++++---- form/persistence/persistence.hpp | 6 ++-- form/root_storage/root_tbranch_container.cpp | 34 +++++++++++++------- form/root_storage/root_tbranch_container.hpp | 5 +-- form/root_storage/root_ttree_container.cpp | 4 +-- form/root_storage/root_ttree_container.hpp | 5 +-- form/storage/istorage.hpp | 11 ++++--- form/storage/storage.cpp | 25 +++++++++----- form/storage/storage.hpp | 6 ++-- form/storage/storage_container.cpp | 4 +-- form/storage/storage_container.hpp | 5 +-- test/form/reader.cpp | 16 ++++----- test/form/test_helpers.hpp | 7 ++-- test/form/writer.cpp | 16 ++++----- 18 files changed, 121 insertions(+), 92 deletions(-) diff --git a/form/form/form.cpp b/form/form/form.cpp index c899490a..5193ba1f 100644 --- a/form/form/form.cpp +++ b/form/form/form.cpp @@ -3,6 +3,7 @@ #include "form.hpp" #include +#include namespace form::experimental { @@ -32,12 +33,12 @@ namespace form::experimental { throw std::runtime_error("No configuration found for product: " + pb.label); } - std::string const type = m_type_map->names[pb.type]; + (void)m_type_map->names.at(pb.type->name()); - std::map products = {{pb.label, type}}; + std::map products = {{pb.label, pb.type}}; m_pers->createContainers(creator, products); - m_pers->registerWrite(creator, pb.label, pb.data, type); + m_pers->registerWrite(creator, pb.label, pb.data, *pb.type); m_pers->commitOutput(creator, segment_id); } @@ -56,18 +57,17 @@ namespace form::experimental { } // FIXME: Really only needed on first call - std::map product_types; + std::map product_types; for (auto const& pb : products) { - std::string const& type = m_type_map->names[pb.type]; - product_types.insert(std::make_pair(pb.label, type)); + product_types.insert(std::make_pair(pb.label, pb.type)); } m_pers->createContainers(creator, product_types); for (auto const& pb : products) { - std::string const& type = m_type_map->names[pb.type]; + (void)m_type_map->names.at(pb.type->name()); // FIXME: We could consider checking id to be identical for all product bases here - m_pers->registerWrite(creator, pb.label, pb.data, type); + m_pers->registerWrite(creator, pb.label, pb.data, *pb.type); } m_pers->commitOutput(creator, segment_id); @@ -83,8 +83,11 @@ namespace form::experimental { throw std::runtime_error("No configuration found for product: " + pb.label); } - std::string type = m_type_map->names[pb.type]; + std::string type; + m_pers->read(creator, pb.label, segment_id, &pb.data, *pb.type); - m_pers->read(creator, pb.label, segment_id, &pb.data, type); + // Validate that we know how to map this runtime string back to the expected C++ type. + // (This keeps the previous "type must be known" check behavior.) + (void)m_type_map->names.at(pb.type->name()); } } diff --git a/form/form/form.hpp b/form/form/form.hpp index 52b8e076..0c47780e 100644 --- a/form/form/form.hpp +++ b/form/form/form.hpp @@ -9,20 +9,20 @@ #include #include #include -#include +#include #include #include namespace form::experimental { struct product_type_names { - std::unordered_map names; + std::unordered_map names; }; struct product_with_name { std::string label; void const* data; - std::type_index type; + std::type_info const* type; }; class form_interface { diff --git a/form/form_module.cpp b/form/form_module.cpp index 3a902637..25cab344 100644 --- a/form/form_module.cpp +++ b/form/form_module.cpp @@ -82,7 +82,7 @@ namespace { // Create FORM product with metadata products.emplace_back(product_name, // label, from map key product_ptr->address(), // data, from phlex product_base - product_ptr->type() // type, from phlex product_base + &product_ptr->type() // type, from phlex product_base ); } @@ -112,14 +112,14 @@ PHLEX_REGISTER_ALGORITHMS(m, config) auto type_map = std::make_shared(); // Register some fundamental type for simple products - type_map->names[std::type_index(typeid(int))] = "int"; - type_map->names[std::type_index(typeid(long))] = "long"; - type_map->names[std::type_index(typeid(float))] = "float"; - type_map->names[std::type_index(typeid(double))] = "double"; - type_map->names[std::type_index(typeid(std::vector))] = "std::vector"; - type_map->names[std::type_index(typeid(std::vector))] = "std::vector"; - type_map->names[std::type_index(typeid(std::vector))] = "std::vector"; - type_map->names[std::type_index(typeid(std::vector))] = "std::vector"; + type_map->names[typeid(int).name()] = "int"; + type_map->names[typeid(long).name()] = "long"; + type_map->names[typeid(float).name()] = "float"; + type_map->names[typeid(double).name()] = "double"; + type_map->names[typeid(std::vector).name()] = "std::vector"; + type_map->names[typeid(std::vector).name()] = "std::vector"; + type_map->names[typeid(std::vector).name()] = "std::vector"; + type_map->names[typeid(std::vector).name()] = "std::vector"; // Extract configuration from Phlex config std::string output_file = config.get("output_file", "output.root"); diff --git a/form/persistence/ipersistence.hpp b/form/persistence/ipersistence.hpp index 36cd535b..5bd3b764 100644 --- a/form/persistence/ipersistence.hpp +++ b/form/persistence/ipersistence.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace form::experimental::config { class output_item_config; @@ -26,18 +27,18 @@ namespace form::detail::experimental { form::experimental::config::output_item_config const& outputItems) = 0; virtual void createContainers(std::string const& creator, - std::map const& products) = 0; + std::map const& products) = 0; virtual void registerWrite(std::string const& creator, std::string const& label, void const* data, - std::string const& type) = 0; + std::type_info const& type) = 0; virtual void commitOutput(std::string const& creator, std::string const& id) = 0; virtual void read(std::string const& creator, std::string const& label, std::string const& id, void const** data, - std::string& type) = 0; + const std::type_info& type) = 0; }; std::unique_ptr createPersistence(); diff --git a/form/persistence/persistence.cpp b/form/persistence/persistence.cpp index 0c1214e2..1092d509 100644 --- a/form/persistence/persistence.cpp +++ b/form/persistence/persistence.cpp @@ -4,6 +4,9 @@ #include #include +#include +#include +#include #include using namespace form::detail::experimental; @@ -31,13 +34,13 @@ void Persistence::configureOutputItems( } void Persistence::createContainers(std::string const& creator, - std::map const& products) + std::map const& products) { - std::map, std::string> containers; + std::map, std::type_info const*> containers; for (auto const& [label, type] : products) { containers.insert(std::make_pair(getPlacement(creator, label), type)); } - containers.insert(std::make_pair(getPlacement(creator, "index"), "std::string")); + containers.insert(std::make_pair(getPlacement(creator, "index"), &typeid(std::string))); m_store->createContainers(containers, m_tech_settings); return; } @@ -45,7 +48,7 @@ void Persistence::createContainers(std::string const& creator, void Persistence::registerWrite(std::string const& creator, std::string const& label, void const* data, - std::string const& type) + std::type_info const& type) { std::unique_ptr plcmnt = getPlacement(creator, label); m_store->fillContainer(*plcmnt, data, type); @@ -55,7 +58,7 @@ void Persistence::registerWrite(std::string const& creator, void Persistence::commitOutput(std::string const& creator, std::string const& id) { std::unique_ptr plcmnt = getPlacement(creator, "index"); - m_store->fillContainer(*plcmnt, &id, "std::string"); + m_store->fillContainer(*plcmnt, &id, typeid(std::string)); m_store->commitContainers(*plcmnt); return; } @@ -64,7 +67,7 @@ void Persistence::read(std::string const& creator, std::string const& label, std::string const& id, void const** data, - std::string& type) + const std::type_info& type) { std::unique_ptr token = getToken(creator, label, id); m_store->readContainer(*token, data, type, m_tech_settings); diff --git a/form/persistence/persistence.hpp b/form/persistence/persistence.hpp index 36af8ac5..397faca9 100644 --- a/form/persistence/persistence.hpp +++ b/form/persistence/persistence.hpp @@ -32,18 +32,18 @@ namespace form::detail::experimental { form::experimental::config::output_item_config const& output_items) override; void createContainers(std::string const& creator, - std::map const& products) override; + std::map const& products) override; void registerWrite(std::string const& creator, std::string const& label, void const* data, - std::string const& type) override; + std::type_info const& type) override; void commitOutput(std::string const& creator, std::string const& id) override; void read(std::string const& creator, std::string const& label, std::string const& id, void const** data, - std::string& type) override; + const std::type_info& type) override; private: std::unique_ptr getPlacement(std::string const& creator, std::string const& label); diff --git a/form/root_storage/root_tbranch_container.cpp b/form/root_storage/root_tbranch_container.cpp index 49c062e1..ac9a04a7 100644 --- a/form/root_storage/root_tbranch_container.cpp +++ b/form/root_storage/root_tbranch_container.cpp @@ -63,16 +63,17 @@ void ROOT_TBranch_ContainerImp::setParent(std::shared_ptr pa return; } -void ROOT_TBranch_ContainerImp::setupWrite(std::string const& type) +void ROOT_TBranch_ContainerImp::setupWrite(std::type_info const& type) { if (m_tree == nullptr) { throw std::runtime_error("ROOT_TBranch_ContainerImp::setupWrite no tree found"); } - auto dictInfo = TDictionary::GetDictionary(type.c_str()); + auto dictInfo = TDictionary::GetDictionary(type); if (m_branch == nullptr) { if (!dictInfo) { - throw std::runtime_error("ROOT_TBranch_ContainerImp::setupWrite unsupported type: " + type); + throw std::runtime_error(std::string{"ROOT_TBranch_ContainerImp::setupWrite unsupported type: "} + + type.name()); } if (dictInfo->Property() & EProperty::kIsFundamental) { m_branch = m_tree->Branch(col_name().c_str(), @@ -117,7 +118,7 @@ void ROOT_TBranch_ContainerImp::commit() return; } -bool ROOT_TBranch_ContainerImp::read(int id, void const** data, std::string const& type) +bool ROOT_TBranch_ContainerImp::read(int id, void const** data, std::type_info const& type) { if (m_tfile == nullptr) { throw std::runtime_error("ROOT_TBranch_ContainerImp::read no file attached"); @@ -138,18 +139,27 @@ bool ROOT_TBranch_ContainerImp::read(int id, void const** data, std::string cons return false; void* branchBuffer = nullptr; - auto dictInfo = TClass::GetClass(type.c_str()); + auto dictInfo = TDictionary::GetDictionary(type); int branchStatus = 0; - if (dictInfo) { - branchBuffer = dictInfo->New(); - branchStatus = m_tree->SetBranchAddress( - col_name().c_str(), &branchBuffer, TClass::GetClass(type.c_str()), EDataType::kOther_t, true); - } else { - //Assume this is a fundamental type like int or double - auto fundInfo = static_cast(TDictionary::GetDictionary(type.c_str())); + if (!dictInfo) { + throw std::runtime_error(std::string{"ROOT_TBranch_ContainerImp::read unsupported type: "} + + type.name()); + } + + if (dictInfo->Property() & EProperty::kIsFundamental) { + auto fundInfo = static_cast(dictInfo); branchBuffer = new char[fundInfo->Size()]; branchStatus = m_tree->SetBranchAddress( col_name().c_str(), &branchBuffer, nullptr, EDataType(fundInfo->GetType()), true); + } else { + auto klass = TClass::GetClass(type); + if (!klass) { + throw std::runtime_error(std::string{"ROOT_TBranch_ContainerImp::read missing TClass for type: "} + + type.name()); + } + branchBuffer = klass->New(); + branchStatus = + m_tree->SetBranchAddress(col_name().c_str(), &branchBuffer, klass, EDataType::kOther_t, true); } if (branchStatus < 0) { diff --git a/form/root_storage/root_tbranch_container.hpp b/form/root_storage/root_tbranch_container.hpp index 085ce9a0..1fd21ebd 100644 --- a/form/root_storage/root_tbranch_container.hpp +++ b/form/root_storage/root_tbranch_container.hpp @@ -7,6 +7,7 @@ #include #include +#include class TFile; class TTree; @@ -24,10 +25,10 @@ namespace form::detail::experimental { void setFile(std::shared_ptr file) override; void setParent(std::shared_ptr parent) override; - void setupWrite(std::string const& type = "") override; + void setupWrite(std::type_info const& type = typeid(void)) override; void fill(void const* data) override; void commit() override; - bool read(int id, void const** data, std::string const& type) override; + bool read(int id, void const** data, std::type_info const& type) override; private: std::shared_ptr m_tfile; diff --git a/form/root_storage/root_ttree_container.cpp b/form/root_storage/root_ttree_container.cpp index 990ad851..53d71839 100644 --- a/form/root_storage/root_ttree_container.cpp +++ b/form/root_storage/root_ttree_container.cpp @@ -38,7 +38,7 @@ void ROOT_TTree_ContainerImp::setFile(std::shared_ptr file) return; } -void ROOT_TTree_ContainerImp::setupWrite(std::string const& /* type*/) +void ROOT_TTree_ContainerImp::setupWrite(std::type_info const& /*type*/) { if (m_tfile == nullptr) { throw std::runtime_error("ROOT_TTree_ContainerImp::setupWrite no file attached"); @@ -69,7 +69,7 @@ void ROOT_TTree_ContainerImp::commit() throw std::runtime_error("ROOT_TTree_ContainerImp::commit not implemented"); } -bool ROOT_TTree_ContainerImp::read(int /* id*/, void const** /* data*/, std::string const& /* type*/) +bool ROOT_TTree_ContainerImp::read(int /* id*/, void const** /* data*/, std::type_info const& /* type*/) { throw std::runtime_error("ROOT_TTree_ContainerImp::read not implemented"); } diff --git a/form/root_storage/root_ttree_container.hpp b/form/root_storage/root_ttree_container.hpp index c1d65b41..077558f6 100644 --- a/form/root_storage/root_ttree_container.hpp +++ b/form/root_storage/root_ttree_container.hpp @@ -7,6 +7,7 @@ #include #include +#include class TFile; class TTree; @@ -22,10 +23,10 @@ namespace form::detail::experimental { ROOT_TTree_ContainerImp& operator=(ROOT_TTree_ContainerImp& other) = delete; void setFile(std::shared_ptr file) override; - void setupWrite(std::string const& type = "") override; + void setupWrite(std::type_info const& type = typeid(void)) override; void fill(void const* data) override; void commit() override; - bool read(int id, void const** data, std::string const& type) override; + bool read(int id, void const** data, std::type_info const& type) override; TTree* getTTree(); diff --git a/form/storage/istorage.hpp b/form/storage/istorage.hpp index f59357cf..f109b1f2 100644 --- a/form/storage/istorage.hpp +++ b/form/storage/istorage.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace form::detail::experimental { @@ -20,11 +21,11 @@ namespace form::detail::experimental { virtual ~IStorage() = default; virtual void createContainers( - std::map, std::string> const& containers, + std::map, std::type_info const*> const& containers, form::experimental::config::tech_setting_config const& settings) = 0; virtual void fillContainer(Placement const& plcmnt, void const* data, - std::string const& type) = 0; + std::type_info const& type) = 0; virtual void commitContainers(Placement const& plcmnt) = 0; virtual int getIndex(Token const& token, @@ -32,7 +33,7 @@ namespace form::detail::experimental { form::experimental::config::tech_setting_config const& settings) = 0; virtual void readContainer(Token const& token, void const** data, - std::string& type, + std::type_info const& type, form::experimental::config::tech_setting_config const& settings) = 0; }; @@ -55,10 +56,10 @@ namespace form::detail::experimental { virtual std::string const& name() = 0; virtual void setFile(std::shared_ptr file) = 0; - virtual void setupWrite(std::string const& type = "") = 0; + virtual void setupWrite(std::type_info const& type = typeid(void)) = 0; virtual void fill(void const* data) = 0; virtual void commit() = 0; - virtual bool read(int id, void const** data, std::string const& type) = 0; + virtual bool read(int id, void const** data, std::type_info const& type) = 0; virtual void setAttribute(std::string const& name, std::string const& value) = 0; }; diff --git a/form/storage/storage.cpp b/form/storage/storage.cpp index b93b39ee..eaafbd5b 100644 --- a/form/storage/storage.cpp +++ b/form/storage/storage.cpp @@ -7,6 +7,10 @@ #include "util/factories.hpp" +#include +#include +#include + using namespace form::detail::experimental; // Factory function implementation @@ -14,8 +18,9 @@ namespace form::detail::experimental { std::unique_ptr createStorage() { return std::unique_ptr(new Storage()); } } -void Storage::createContainers(std::map, std::string> const& containers, - form::experimental::config::tech_setting_config const& settings) +void Storage::createContainers( + std::map, std::type_info const*> const& containers, + form::experimental::config::tech_setting_config const& settings) { for (auto const& [plcmnt, type] : containers) { // Use file+container as composite key @@ -36,7 +41,8 @@ void Storage::createContainers(std::map, std::string> auto container = createContainer(plcmnt->technology(), plcmnt->containerName()); m_containers.insert({key, container}); // For associative container, create association layer - auto associative_container = dynamic_pointer_cast(container); + auto associative_container = + std::dynamic_pointer_cast(container); if (associative_container) { auto parent_key = std::make_pair(plcmnt->fileName(), associative_container->top_name()); auto parent = m_containers.find(parent_key); @@ -56,13 +62,17 @@ void Storage::createContainers(std::map, std::string> settings.getContainerTable(plcmnt->technology(), plcmnt->containerName())) container->setAttribute(key, value); container->setFile(file->second); - container->setupWrite(type); + if (!type) { + throw std::runtime_error("Storage::createContainers got nullptr type for container: " + + plcmnt->containerName()); + } + container->setupWrite(*type); } } return; } -void Storage::fillContainer(Placement const& plcmnt, void const* data, std::string const& /* type*/) +void Storage::fillContainer(Placement const& plcmnt, void const* data, std::type_info const& /* type*/) { // Use file+container as composite key auto key = std::make_pair(plcmnt.fileName(), plcmnt.containerName()); @@ -107,9 +117,8 @@ int Storage::getIndex(Token const& token, cont->second->setFile(file->second); } void const* data; - std::string type = "std::string"; int entry = 1; - while (cont->second->read(entry, &data, type)) { + while (cont->second->read(entry, &data, typeid(std::string))) { m_indexMaps[token.containerName()].insert( std::make_pair(*(static_cast(data)), entry)); delete static_cast( @@ -123,7 +132,7 @@ int Storage::getIndex(Token const& token, void Storage::readContainer(Token const& token, void const** data, - std::string& type, + std::type_info const& type, form::experimental::config::tech_setting_config const& settings) { auto key = std::make_pair(token.fileName(), token.containerName()); diff --git a/form/storage/storage.hpp b/form/storage/storage.hpp index 730f7c7b..bda404f2 100644 --- a/form/storage/storage.hpp +++ b/form/storage/storage.hpp @@ -30,9 +30,9 @@ namespace form::detail::experimental { ~Storage() = default; using table_t = form::experimental::config::tech_setting_config::table_t; - void createContainers(std::map, std::string> const& containers, + void createContainers(std::map, std::type_info const*> const& containers, form::experimental::config::tech_setting_config const& settings) override; - void fillContainer(Placement const& plcmnt, void const* data, std::string const& type) override; + void fillContainer(Placement const& plcmnt, void const* data, std::type_info const& type) override; void commitContainers(Placement const& plcmnt) override; int getIndex(Token const& token, @@ -40,7 +40,7 @@ namespace form::detail::experimental { form::experimental::config::tech_setting_config const& settings) override; void readContainer(Token const& token, void const** data, - std::string& type, + std::type_info const& type, form::experimental::config::tech_setting_config const& settings) override; private: diff --git a/form/storage/storage_container.cpp b/form/storage/storage_container.cpp index 7ceb599c..e3c61416 100644 --- a/form/storage/storage_container.cpp +++ b/form/storage/storage_container.cpp @@ -13,13 +13,13 @@ std::string const& Storage_Container::name() { return m_name; } void Storage_Container::setFile(std::shared_ptr file) { m_file = file; } -void Storage_Container::setupWrite(std::string const& /* type*/) { return; } +void Storage_Container::setupWrite(std::type_info const& /*type*/) { return; } void Storage_Container::fill(void const* /* data*/) { return; } void Storage_Container::commit() { return; } -bool Storage_Container::read(int /* id*/, void const** /*data*/, std::string const& /* type*/) +bool Storage_Container::read(int /* id*/, void const** /*data*/, std::type_info const& /* type*/) { return false; } diff --git a/form/storage/storage_container.hpp b/form/storage/storage_container.hpp index b5a63dea..5a2b24bd 100644 --- a/form/storage/storage_container.hpp +++ b/form/storage/storage_container.hpp @@ -7,6 +7,7 @@ #include #include +#include namespace form::detail::experimental { @@ -19,10 +20,10 @@ namespace form::detail::experimental { void setFile(std::shared_ptr file) override; - void setupWrite(std::string const& type = "") override; + void setupWrite(std::type_info const& type = typeid(void)) override; void fill(void const* data) override; void commit() override; - bool read(int id, void const** data, std::string const& type) override; + bool read(int id, void const** data, std::type_info const& type) override; void setAttribute(std::string const& name, std::string const& value) override; diff --git a/test/form/reader.cpp b/test/form/reader.cpp index aa30ceb2..16f51832 100644 --- a/test/form/reader.cpp +++ b/test/form/reader.cpp @@ -50,8 +50,8 @@ int main(int argc, char** argv) std::string const creator = "Toy_Tracker"; form::experimental::product_with_name pb = { - "trackStart", track_start_x, std::type_index{typeid(std::vector)}}; - type_map->names[std::type_index(typeid(std::vector))] = "std::vector"; + "trackStart", track_start_x, &typeid(std::vector)}; + type_map->names[typeid(std::vector).name()] = "std::vector"; form.read(creator, segment_id, pb); track_start_x = @@ -60,8 +60,8 @@ int main(int argc, char** argv) std::vector const* track_n_hits = nullptr; form::experimental::product_with_name pb_int = { - "trackNumberHits", track_n_hits, std::type_index{typeid(std::vector)}}; - type_map->names[std::type_index(typeid(std::vector))] = "std::vector"; + "trackNumberHits", track_n_hits, &typeid(std::vector)}; + type_map->names[typeid(std::vector).name()] = "std::vector"; form.read(creator, segment_id, pb_int); track_n_hits = static_cast const*>(pb_int.data); @@ -69,8 +69,8 @@ int main(int argc, char** argv) std::vector const* start_points = nullptr; form::experimental::product_with_name pb_points = { - "trackStartPoints", start_points, std::type_index{typeid(std::vector)}}; - type_map->names[std::type_index(typeid(std::vector))] = "std::vector"; + "trackStartPoints", start_points, &typeid(std::vector)}; + type_map->names[typeid(std::vector).name()] = "std::vector"; form.read(creator, segment_id, pb_points); start_points = static_cast const*>(pb_points.data); @@ -102,8 +102,8 @@ int main(int argc, char** argv) std::string const creator = "Toy_Tracker_Event"; form::experimental::product_with_name pb = { - "trackStartX", track_x, std::type_index{typeid(std::vector)}}; - type_map->names[std::type_index(typeid(std::vector))] = "std::vector"; + "trackStartX", track_x, &typeid(std::vector)}; + type_map->names[typeid(std::vector).name()] = "std::vector"; form.read(creator, event_id, pb); track_x = static_cast const*>(pb.data); //FIXME: Can this be done by FORM? diff --git a/test/form/test_helpers.hpp b/test/form/test_helpers.hpp index c17ba03e..91660233 100644 --- a/test/form/test_helpers.hpp +++ b/test/form/test_helpers.hpp @@ -6,7 +6,6 @@ #include #include -#include namespace form::experimental { @@ -14,15 +13,15 @@ namespace form::experimental { template void registerType(product_type_names& map, std::string const& name) { - map.names[std::type_index(typeid(T))] = name; + map.names[typeid(T).name()] = name; } // Register vector types automatically template void registerVectorType(product_type_names& map, std::string const& base_name) { - map.names[std::type_index(typeid(T))] = base_name; - map.names[std::type_index(typeid(std::vector))] = "std::vector<" + base_name + ">"; + map.names[typeid(T).name()] = base_name; + map.names[typeid(std::vector).name()] = "std::vector<" + base_name + ">"; } inline std::shared_ptr createTypeMap() diff --git a/test/form/writer.cpp b/test/form/writer.cpp index 954dbbd9..82a1e52c 100644 --- a/test/form/writer.cpp +++ b/test/form/writer.cpp @@ -80,8 +80,8 @@ int main(int argc, char** argv) std::string const creator = "Toy_Tracker"; form::experimental::product_with_name pb = { - "trackStart", &track_start_x, std::type_index{typeid(std::vector)}}; - type_map->names[std::type_index(typeid(std::vector))] = "std::vector"; + "trackStart", &track_start_x, &typeid(std::vector)}; + type_map->names[typeid(std::vector).name()] = "std::vector"; products.push_back(pb); std::vector track_n_hits; @@ -94,8 +94,8 @@ int main(int argc, char** argv) << ", check = " << check << std::endl; form::experimental::product_with_name pb_int = { - "trackNumberHits", &track_n_hits, std::type_index{typeid(std::vector)}}; - type_map->names[std::type_index(typeid(std::vector))] = "std::vector"; + "trackNumberHits", &track_n_hits, &typeid(std::vector)}; + type_map->names[typeid(std::vector).name()] = "std::vector"; products.push_back(pb_int); std::vector start_points = tracker(); @@ -106,8 +106,8 @@ int main(int argc, char** argv) << ", checkPoints = " << checkPoints << std::endl; form::experimental::product_with_name pb_points = { - "trackStartPoints", &start_points, std::type_index{typeid(std::vector)}}; - type_map->names[std::type_index(typeid(std::vector))] = "std::vector"; + "trackStartPoints", &start_points, &typeid(std::vector)}; + type_map->names[typeid(std::vector).name()] = "std::vector"; products.push_back(pb_points); form.write(creator, segment_id, products); @@ -129,8 +129,8 @@ int main(int argc, char** argv) std::string const creator = "Toy_Tracker_Event"; form::experimental::product_with_name pb = { - "trackStartX", &track_x, std::type_index{typeid(std::vector)}}; - type_map->names[std::type_index(typeid(std::vector))] = "std::vector"; + "trackStartX", &track_x, &typeid(std::vector)}; + type_map->names[typeid(std::vector).name()] = "std::vector"; std::cout << "PHLEX: Event = " << nevent << ": evt_id_text = " << evt_id_text << ", check = " << check << std::endl; From 7c7d4afe8aaa59e60ab994d93e387f1a7f75546a Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Mon, 12 Jan 2026 21:42:13 +0000 Subject: [PATCH 5/9] FORM: Remove type_map --- form/form/form.cpp | 13 ++----------- form/form/form.hpp | 9 +-------- form/form_module.cpp | 23 ++++------------------- test/form/reader.cpp | 9 +-------- test/form/test_helpers.hpp | 31 ------------------------------- test/form/writer.cpp | 8 +------- 6 files changed, 9 insertions(+), 84 deletions(-) diff --git a/form/form/form.cpp b/form/form/form.cpp index 5193ba1f..70fa7853 100644 --- a/form/form/form.cpp +++ b/form/form/form.cpp @@ -7,10 +7,9 @@ namespace form::experimental { - form_interface::form_interface(std::shared_ptr tm, - config::output_item_config const& output_config, + form_interface::form_interface(config::output_item_config const& output_config, config::tech_setting_config const& tech_config) : - m_pers(nullptr), m_type_map(tm) + m_pers(nullptr) { for (auto const& item : output_config.getItems()) { m_product_to_config.emplace(item.product_name, @@ -33,8 +32,6 @@ namespace form::experimental { throw std::runtime_error("No configuration found for product: " + pb.label); } - (void)m_type_map->names.at(pb.type->name()); - std::map products = {{pb.label, pb.type}}; m_pers->createContainers(creator, products); @@ -65,7 +62,6 @@ namespace form::experimental { m_pers->createContainers(creator, product_types); for (auto const& pb : products) { - (void)m_type_map->names.at(pb.type->name()); // FIXME: We could consider checking id to be identical for all product bases here m_pers->registerWrite(creator, pb.label, pb.data, *pb.type); } @@ -83,11 +79,6 @@ namespace form::experimental { throw std::runtime_error("No configuration found for product: " + pb.label); } - std::string type; m_pers->read(creator, pb.label, segment_id, &pb.data, *pb.type); - - // Validate that we know how to map this runtime string back to the expected C++ type. - // (This keeps the previous "type must be known" check behavior.) - (void)m_type_map->names.at(pb.type->name()); } } diff --git a/form/form/form.hpp b/form/form/form.hpp index 0c47780e..2983a9ca 100644 --- a/form/form/form.hpp +++ b/form/form/form.hpp @@ -10,15 +10,10 @@ #include #include #include -#include #include namespace form::experimental { - struct product_type_names { - std::unordered_map names; - }; - struct product_with_name { std::string label; void const* data; @@ -27,8 +22,7 @@ namespace form::experimental { class form_interface { public: - form_interface(std::shared_ptr tm, - config::output_item_config const& output_config, + form_interface(config::output_item_config const& output_config, config::tech_setting_config const& tech_config); ~form_interface() = default; @@ -46,7 +40,6 @@ namespace form::experimental { private: std::unique_ptr m_pers; - std::shared_ptr m_type_map; std::map m_product_to_config; }; } diff --git a/form/form_module.cpp b/form/form_module.cpp index 25cab344..ff641e3c 100644 --- a/form/form_module.cpp +++ b/form/form_module.cpp @@ -14,11 +14,10 @@ namespace { class FormOutputModule { public: - FormOutputModule(std::shared_ptr type_map, - std::string output_file, + FormOutputModule(std::string output_file, int technology, std::vector const& products_to_save) : - m_type_map(type_map), m_output_file(std::move(output_file)), m_technology(technology) + m_output_file(std::move(output_file)), m_technology(technology) { std::cout << "FormOutputModule initialized\n"; std::cout << " Output file: " << m_output_file << "\n"; @@ -40,7 +39,7 @@ namespace { // Initialize FORM interface m_form_interface = - std::make_unique(type_map, output_cfg, tech_cfg); + std::make_unique(output_cfg, tech_cfg); } // This method is called by Phlex - signature must be: void(product_store const&) @@ -96,7 +95,6 @@ namespace { } private: - std::shared_ptr m_type_map; std::string m_output_file; int m_technology; std::unique_ptr m_form_interface; @@ -108,19 +106,6 @@ PHLEX_REGISTER_ALGORITHMS(m, config) { std::cout << "Registering FORM output module...\n"; - // Create type map - auto type_map = std::make_shared(); - - // Register some fundamental type for simple products - type_map->names[typeid(int).name()] = "int"; - type_map->names[typeid(long).name()] = "long"; - type_map->names[typeid(float).name()] = "float"; - type_map->names[typeid(double).name()] = "double"; - type_map->names[typeid(std::vector).name()] = "std::vector"; - type_map->names[typeid(std::vector).name()] = "std::vector"; - type_map->names[typeid(std::vector).name()] = "std::vector"; - type_map->names[typeid(std::vector).name()] = "std::vector"; - // Extract configuration from Phlex config std::string output_file = config.get("output_file", "output.root"); std::string tech_string = config.get("technology", "ROOT_TTREE"); @@ -146,7 +131,7 @@ PHLEX_REGISTER_ALGORITHMS(m, config) // Phlex needs an OBJECT // Create the FORM output module - auto form_output = m.make(type_map, output_file, technology, products_to_save); + auto form_output = m.make(output_file, technology, products_to_save); // Phlex needs a MEMBER FUNCTION to call // Register the callback that Phlex will invoke diff --git a/test/form/reader.cpp b/test/form/reader.cpp index 16f51832..e27569ba 100644 --- a/test/form/reader.cpp +++ b/test/form/reader.cpp @@ -20,9 +20,6 @@ int main(int argc, char** argv) std::string const filename = (argc > 1) ? argv[1] : "toy.root"; - std::shared_ptr type_map = - form::experimental::createTypeMap(); - // TODO: Read configuration from config file instead of hardcoding form::experimental::config::output_item_config output_config; output_config.addItem("trackStart", filename, form::technology::ROOT_TTREE); @@ -32,7 +29,7 @@ int main(int argc, char** argv) form::experimental::config::tech_setting_config tech_config; - form::experimental::form_interface form(type_map, output_config, tech_config); + form::experimental::form_interface form(output_config, tech_config); for (int nevent = 0; nevent < NUMBER_EVENT; nevent++) { std::cout << "PHLEX: Read Event No. " << nevent << std::endl; @@ -51,7 +48,6 @@ int main(int argc, char** argv) form::experimental::product_with_name pb = { "trackStart", track_start_x, &typeid(std::vector)}; - type_map->names[typeid(std::vector).name()] = "std::vector"; form.read(creator, segment_id, pb); track_start_x = @@ -61,7 +57,6 @@ int main(int argc, char** argv) form::experimental::product_with_name pb_int = { "trackNumberHits", track_n_hits, &typeid(std::vector)}; - type_map->names[typeid(std::vector).name()] = "std::vector"; form.read(creator, segment_id, pb_int); track_n_hits = static_cast const*>(pb_int.data); @@ -70,7 +65,6 @@ int main(int argc, char** argv) form::experimental::product_with_name pb_points = { "trackStartPoints", start_points, &typeid(std::vector)}; - type_map->names[typeid(std::vector).name()] = "std::vector"; form.read(creator, segment_id, pb_points); start_points = static_cast const*>(pb_points.data); @@ -103,7 +97,6 @@ int main(int argc, char** argv) form::experimental::product_with_name pb = { "trackStartX", track_x, &typeid(std::vector)}; - type_map->names[typeid(std::vector).name()] = "std::vector"; form.read(creator, event_id, pb); track_x = static_cast const*>(pb.data); //FIXME: Can this be done by FORM? diff --git a/test/form/test_helpers.hpp b/test/form/test_helpers.hpp index 91660233..7a831766 100644 --- a/test/form/test_helpers.hpp +++ b/test/form/test_helpers.hpp @@ -4,35 +4,4 @@ #include "data_products/track_start.hpp" #include "form/form.hpp" -#include -#include - -namespace form::experimental { - - // Helper to register a single type - template - void registerType(product_type_names& map, std::string const& name) - { - map.names[typeid(T).name()] = name; - } - - // Register vector types automatically - template - void registerVectorType(product_type_names& map, std::string const& base_name) - { - map.names[typeid(T).name()] = base_name; - map.names[typeid(std::vector).name()] = "std::vector<" + base_name + ">"; - } - - inline std::shared_ptr createTypeMap() - { - auto type_map = std::make_shared(); - registerVectorType(*type_map, "TrackStart"); - - // Register all your data product types here - // Easy to add more in the future: - return type_map; - } -} - #endif diff --git a/test/form/writer.cpp b/test/form/writer.cpp index 82a1e52c..b23d9457 100644 --- a/test/form/writer.cpp +++ b/test/form/writer.cpp @@ -36,8 +36,6 @@ int main(int argc, char** argv) std::string const filename = (argc > 1) ? argv[1] : "toy.root"; - std::shared_ptr type_map = - form::experimental::createTypeMap(); // TODO: Read configuration from config file instead of hardcoding form::experimental::config::output_item_config output_config; @@ -54,7 +52,7 @@ int main(int argc, char** argv) tech_config.container_settings[form::technology::ROOT_RNTUPLE]["Toy_Tracker/trackStartPoints"] .emplace_back("force_streamer_field", "true"); - form::experimental::form_interface form(type_map, output_config, tech_config); + form::experimental::form_interface form(output_config, tech_config); ToyTracker tracker(4 * 1024); @@ -81,7 +79,6 @@ int main(int argc, char** argv) form::experimental::product_with_name pb = { "trackStart", &track_start_x, &typeid(std::vector)}; - type_map->names[typeid(std::vector).name()] = "std::vector"; products.push_back(pb); std::vector track_n_hits; @@ -95,7 +92,6 @@ int main(int argc, char** argv) form::experimental::product_with_name pb_int = { "trackNumberHits", &track_n_hits, &typeid(std::vector)}; - type_map->names[typeid(std::vector).name()] = "std::vector"; products.push_back(pb_int); std::vector start_points = tracker(); @@ -107,7 +103,6 @@ int main(int argc, char** argv) form::experimental::product_with_name pb_points = { "trackStartPoints", &start_points, &typeid(std::vector)}; - type_map->names[typeid(std::vector).name()] = "std::vector"; products.push_back(pb_points); form.write(creator, segment_id, products); @@ -130,7 +125,6 @@ int main(int argc, char** argv) form::experimental::product_with_name pb = { "trackStartX", &track_x, &typeid(std::vector)}; - type_map->names[typeid(std::vector).name()] = "std::vector"; std::cout << "PHLEX: Event = " << nevent << ": evt_id_text = " << evt_id_text << ", check = " << check << std::endl; From 7db6270f4ad40bba3422b99211063bac09146d81 Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Tue, 13 Jan 2026 20:28:00 +0000 Subject: [PATCH 6/9] FORM: Demangle type_info before printing name --- form/root_storage/root_tbranch_container.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/form/root_storage/root_tbranch_container.cpp b/form/root_storage/root_tbranch_container.cpp index ac9a04a7..b27631a8 100644 --- a/form/root_storage/root_tbranch_container.cpp +++ b/form/root_storage/root_tbranch_container.cpp @@ -8,10 +8,24 @@ #include "TFile.h" #include "TLeaf.h" #include "TTree.h" +#include "TClassEdit.h" #include namespace { + // Return the demangled type name + std::string DemangleName(const std::type_info& type) { + int errorCode; + // The TClassEdit version works on both linux and Windows. + char* demangledName = TClassEdit::DemangleTypeIdName(type, errorCode); + if (errorCode != 0) { + // NOTE: Instead of throwing, we could return the mangled name as a fallback. + throw std::runtime_error("Failed to demangle type name"); + } + std::string result(demangledName); + std::free(demangledName); + return result; + } //Type name conversion based on https://root.cern.ch/doc/master/classTTree.html#ac1fa9466ce018d4aa739b357f981c615 //An empty leaf list defaults to Float_t std::unordered_map typeNameToLeafList = {{"int", "/I"}, @@ -73,7 +87,7 @@ void ROOT_TBranch_ContainerImp::setupWrite(std::type_info const& type) if (m_branch == nullptr) { if (!dictInfo) { throw std::runtime_error(std::string{"ROOT_TBranch_ContainerImp::setupWrite unsupported type: "} + - type.name()); + DemangleName(type)); } if (dictInfo->Property() & EProperty::kIsFundamental) { m_branch = m_tree->Branch(col_name().c_str(), @@ -143,7 +157,7 @@ bool ROOT_TBranch_ContainerImp::read(int id, void const** data, std::type_info c int branchStatus = 0; if (!dictInfo) { throw std::runtime_error(std::string{"ROOT_TBranch_ContainerImp::read unsupported type: "} + - type.name()); + DemangleName(type)); } if (dictInfo->Property() & EProperty::kIsFundamental) { @@ -155,7 +169,7 @@ bool ROOT_TBranch_ContainerImp::read(int id, void const** data, std::type_info c auto klass = TClass::GetClass(type); if (!klass) { throw std::runtime_error(std::string{"ROOT_TBranch_ContainerImp::read missing TClass for type: "} + - type.name()); + DemangleName(type)); } branchBuffer = klass->New(); branchStatus = From b734bc2386c49f560acf34487a7d9c4642c9f357 Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Tue, 13 Jan 2026 20:51:27 +0000 Subject: [PATCH 7/9] FORM: Add more information to exception msg --- form/root_storage/root_tbranch_container.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/form/root_storage/root_tbranch_container.cpp b/form/root_storage/root_tbranch_container.cpp index b27631a8..8eac7995 100644 --- a/form/root_storage/root_tbranch_container.cpp +++ b/form/root_storage/root_tbranch_container.cpp @@ -168,8 +168,9 @@ bool ROOT_TBranch_ContainerImp::read(int id, void const** data, std::type_info c } else { auto klass = TClass::GetClass(type); if (!klass) { - throw std::runtime_error(std::string{"ROOT_TBranch_ContainerImp::read missing TClass for type: "} + - DemangleName(type)); + throw std::runtime_error( + std::string{"ROOT_TBranch_ContainerImp::read missing TClass"} + + " (col_name='" + col_name() + "', type='" + DemangleName(type) + "')"); } branchBuffer = klass->New(); branchStatus = @@ -178,8 +179,9 @@ bool ROOT_TBranch_ContainerImp::read(int id, void const** data, std::type_info c if (branchStatus < 0) { throw std::runtime_error( - "ROOT_TBranch_ContainerImp::read SetBranchAddress() failed with error code " + - std::to_string(branchStatus)); + std::string{"ROOT_TBranch_ContainerImp::read SetBranchAddress() failed"} + + " (col_name='" + col_name() + "', type='" + DemangleName(type) + "')" + + " with error code " + std::to_string(branchStatus)); } Long64_t tentry = m_tree->LoadTree(id); From c9327bbc3b032444bb0cd169f2423bf3bb6d2bd0 Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Wed, 14 Jan 2026 17:03:08 -0600 Subject: [PATCH 8/9] East const Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- form/persistence/ipersistence.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/form/persistence/ipersistence.hpp b/form/persistence/ipersistence.hpp index 5bd3b764..4d0b7386 100644 --- a/form/persistence/ipersistence.hpp +++ b/form/persistence/ipersistence.hpp @@ -38,7 +38,7 @@ namespace form::detail::experimental { std::string const& label, std::string const& id, void const** data, - const std::type_info& type) = 0; + std::type_info const& type) = 0; }; std::unique_ptr createPersistence(); From 50533c26aee474ae4a3765263be32a9c9ba840cc Mon Sep 17 00:00:00 2001 From: Philippe Canal Date: Thu, 15 Jan 2026 16:22:14 +0000 Subject: [PATCH 9/9] FORM: apply clang-format to last set of changes --- form/form_module.cpp | 3 +-- form/persistence/persistence.cpp | 2 +- form/persistence/persistence.hpp | 2 +- form/root_storage/root_tbranch_container.cpp | 22 +++++++++++--------- form/root_storage/root_ttree_container.cpp | 4 +++- form/storage/storage.cpp | 4 +++- form/storage/storage.hpp | 9 +++++--- test/form/writer.cpp | 3 +-- 8 files changed, 28 insertions(+), 21 deletions(-) diff --git a/form/form_module.cpp b/form/form_module.cpp index ff641e3c..3578c323 100644 --- a/form/form_module.cpp +++ b/form/form_module.cpp @@ -38,8 +38,7 @@ namespace { } // Initialize FORM interface - m_form_interface = - std::make_unique(output_cfg, tech_cfg); + m_form_interface = std::make_unique(output_cfg, tech_cfg); } // This method is called by Phlex - signature must be: void(product_store const&) diff --git a/form/persistence/persistence.cpp b/form/persistence/persistence.cpp index 1092d509..9c52798a 100644 --- a/form/persistence/persistence.cpp +++ b/form/persistence/persistence.cpp @@ -67,7 +67,7 @@ void Persistence::read(std::string const& creator, std::string const& label, std::string const& id, void const** data, - const std::type_info& type) + std::type_info const& type) { std::unique_ptr token = getToken(creator, label, id); m_store->readContainer(*token, data, type, m_tech_settings); diff --git a/form/persistence/persistence.hpp b/form/persistence/persistence.hpp index 397faca9..d7ff4598 100644 --- a/form/persistence/persistence.hpp +++ b/form/persistence/persistence.hpp @@ -43,7 +43,7 @@ namespace form::detail::experimental { std::string const& label, std::string const& id, void const** data, - const std::type_info& type) override; + std::type_info const& type) override; private: std::unique_ptr getPlacement(std::string const& creator, std::string const& label); diff --git a/form/root_storage/root_tbranch_container.cpp b/form/root_storage/root_tbranch_container.cpp index 8eac7995..9c0c6f69 100644 --- a/form/root_storage/root_tbranch_container.cpp +++ b/form/root_storage/root_tbranch_container.cpp @@ -5,16 +5,17 @@ #include "root_ttree_container.hpp" #include "TBranch.h" +#include "TClassEdit.h" #include "TFile.h" #include "TLeaf.h" #include "TTree.h" -#include "TClassEdit.h" #include namespace { // Return the demangled type name - std::string DemangleName(const std::type_info& type) { + std::string DemangleName(std::type_info const& type) + { int errorCode; // The TClassEdit version works on both linux and Windows. char* demangledName = TClassEdit::DemangleTypeIdName(type, errorCode); @@ -86,8 +87,9 @@ void ROOT_TBranch_ContainerImp::setupWrite(std::type_info const& type) auto dictInfo = TDictionary::GetDictionary(type); if (m_branch == nullptr) { if (!dictInfo) { - throw std::runtime_error(std::string{"ROOT_TBranch_ContainerImp::setupWrite unsupported type: "} + - DemangleName(type)); + throw std::runtime_error( + std::string{"ROOT_TBranch_ContainerImp::setupWrite unsupported type: "} + + DemangleName(type)); } if (dictInfo->Property() & EProperty::kIsFundamental) { m_branch = m_tree->Branch(col_name().c_str(), @@ -168,9 +170,9 @@ bool ROOT_TBranch_ContainerImp::read(int id, void const** data, std::type_info c } else { auto klass = TClass::GetClass(type); if (!klass) { - throw std::runtime_error( - std::string{"ROOT_TBranch_ContainerImp::read missing TClass"} + - " (col_name='" + col_name() + "', type='" + DemangleName(type) + "')"); + throw std::runtime_error(std::string{"ROOT_TBranch_ContainerImp::read missing TClass"} + + " (col_name='" + col_name() + "', type='" + DemangleName(type) + + "')"); } branchBuffer = klass->New(); branchStatus = @@ -179,9 +181,9 @@ bool ROOT_TBranch_ContainerImp::read(int id, void const** data, std::type_info c if (branchStatus < 0) { throw std::runtime_error( - std::string{"ROOT_TBranch_ContainerImp::read SetBranchAddress() failed"} + - " (col_name='" + col_name() + "', type='" + DemangleName(type) + "')" + - " with error code " + std::to_string(branchStatus)); + std::string{"ROOT_TBranch_ContainerImp::read SetBranchAddress() failed"} + " (col_name='" + + col_name() + "', type='" + DemangleName(type) + "')" + " with error code " + + std::to_string(branchStatus)); } Long64_t tentry = m_tree->LoadTree(id); diff --git a/form/root_storage/root_ttree_container.cpp b/form/root_storage/root_ttree_container.cpp index 53d71839..adc529ba 100644 --- a/form/root_storage/root_ttree_container.cpp +++ b/form/root_storage/root_ttree_container.cpp @@ -69,7 +69,9 @@ void ROOT_TTree_ContainerImp::commit() throw std::runtime_error("ROOT_TTree_ContainerImp::commit not implemented"); } -bool ROOT_TTree_ContainerImp::read(int /* id*/, void const** /* data*/, std::type_info const& /* type*/) +bool ROOT_TTree_ContainerImp::read(int /* id*/, + void const** /* data*/, + std::type_info const& /* type*/) { throw std::runtime_error("ROOT_TTree_ContainerImp::read not implemented"); } diff --git a/form/storage/storage.cpp b/form/storage/storage.cpp index eaafbd5b..5d67ad73 100644 --- a/form/storage/storage.cpp +++ b/form/storage/storage.cpp @@ -72,7 +72,9 @@ void Storage::createContainers( return; } -void Storage::fillContainer(Placement const& plcmnt, void const* data, std::type_info const& /* type*/) +void Storage::fillContainer(Placement const& plcmnt, + void const* data, + std::type_info const& /* type*/) { // Use file+container as composite key auto key = std::make_pair(plcmnt.fileName(), plcmnt.containerName()); diff --git a/form/storage/storage.hpp b/form/storage/storage.hpp index bda404f2..e0d1f9f1 100644 --- a/form/storage/storage.hpp +++ b/form/storage/storage.hpp @@ -30,9 +30,12 @@ namespace form::detail::experimental { ~Storage() = default; using table_t = form::experimental::config::tech_setting_config::table_t; - void createContainers(std::map, std::type_info const*> const& containers, - form::experimental::config::tech_setting_config const& settings) override; - void fillContainer(Placement const& plcmnt, void const* data, std::type_info const& type) override; + void createContainers( + std::map, std::type_info const*> const& containers, + form::experimental::config::tech_setting_config const& settings) override; + void fillContainer(Placement const& plcmnt, + void const* data, + std::type_info const& type) override; void commitContainers(Placement const& plcmnt) override; int getIndex(Token const& token, diff --git a/test/form/writer.cpp b/test/form/writer.cpp index b23d9457..91a74fef 100644 --- a/test/form/writer.cpp +++ b/test/form/writer.cpp @@ -36,7 +36,6 @@ int main(int argc, char** argv) std::string const filename = (argc > 1) ? argv[1] : "toy.root"; - // TODO: Read configuration from config file instead of hardcoding form::experimental::config::output_item_config output_config; output_config.addItem("trackStart", filename, form::technology::ROOT_TTREE); @@ -52,7 +51,7 @@ int main(int argc, char** argv) tech_config.container_settings[form::technology::ROOT_RNTUPLE]["Toy_Tracker/trackStartPoints"] .emplace_back("force_streamer_field", "true"); - form::experimental::form_interface form(output_config, tech_config); + form::experimental::form_interface form(output_config, tech_config); ToyTracker tracker(4 * 1024);