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
25 changes: 23 additions & 2 deletions form/form/form_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ namespace form::experimental {
std::map<std::string, std::type_info const*> products = {{pb.label, pb.type}};
m_pers_writer->createContainers(creator, products);

m_pers_writer->registerWrite(creator, pb.label, pb.data, *pb.type);
auto declared_it = m_label_to_product_name.find(pb.label);
std::string const& declared_name =
(declared_it != m_label_to_product_name.end()) ? declared_it->second : std::string{};
m_pers_writer->registerWrite(creator, pb.label, pb.data, *pb.type, declared_name);

m_pers_writer->commitOutput(creator, segment_id);
}
Expand Down Expand Up @@ -66,10 +69,28 @@ namespace form::experimental {

for (auto const& pb : products) {
// FIXME: We could consider checking id to be identical for all product bases here
m_pers_writer->registerWrite(creator, pb.label, pb.data, *pb.type);
auto declared_it = m_label_to_product_name.find(pb.label);
std::string const& declared_name =
(declared_it != m_label_to_product_name.end()) ? declared_it->second : std::string{};
m_pers_writer->registerWrite(creator, pb.label, pb.data, *pb.type, declared_name);
}

m_pers_writer->commitOutput(creator, segment_id);
}

void form_writer_interface::declare_product_name(std::string const& routing_label,
std::string const& product_name)
{
m_label_to_product_name[routing_label] = product_name;
}

void form_writer_interface::finalize()
{
if (m_finalized) {
return;
}
m_finalized = true;
m_pers_writer->finalize();
}

}
8 changes: 8 additions & 0 deletions form/form/form_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ namespace form::experimental {
std::string const& segment_id,
std::vector<product_with_name> const& products);

void finalize();

// Explicitly declare the logical ProductName for a given routing label.
// If not called, ProductName defaults to the creator name at write time.
void declare_product_name(std::string const& routing_label, std::string const& product_name);

private:
std::unique_ptr<form::detail::experimental::IPersistenceWriter> m_pers_writer;
std::map<std::string, form::experimental::config::PersistenceItem> m_product_to_config;
std::map<std::string, std::string> m_label_to_product_name;
bool m_finalized = false;
};
}

Expand Down
21 changes: 21 additions & 0 deletions form/form_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ namespace {
// Initialize FORM interface
m_form_interface =
std::make_unique<form::experimental::form_writer_interface>(output_cfg, tech_cfg);

// Explicitly declare ProductNames from user config (products list in jsonnet)
for (auto const& product : products_to_save) {
m_form_interface->declare_product_name(product, product);
}
}

~FormOutputModule()
{
if (m_form_interface) {
std::cout << "FormOutputModule destructor: calling finalize() to write metadata\n";
try {
m_form_interface->finalize();
std::cout << "FormOutputModule destructor: finalize() completed\n";
} catch (std::exception const& e) {
std::cerr << "ERROR: FormOutputModule destructor: finalize() failed: " << e.what()
<< std::endl;
} catch (...) {
std::cerr << "Unknown error in FormOutputModule destructor during finalize.\n";
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

// This method is called by Phlex - signature must be: void(product_store const&)
Expand Down
4 changes: 3 additions & 1 deletion form/persistence/ipersistence_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ namespace form::detail::experimental {
virtual void registerWrite(std::string const& creator,
std::string const& label,
void const* data,
std::type_info const& type) = 0;
std::type_info const& type,
std::string const& product_name = "") = 0;
virtual void commitOutput(std::string const& creator, std::string const& id) = 0;
virtual void finalize() = 0;
};

std::unique_ptr<IPersistenceWriter> createPersistenceWriter();
Expand Down
11 changes: 8 additions & 3 deletions form/persistence/persistence_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,20 @@ void PersistenceWriter::createContainers(
void PersistenceWriter::registerWrite(std::string const& creator,
std::string const& label,
void const* data,
std::type_info const& type)
std::type_info const& type,
std::string const& product_name)
{
m_current_creator = creator; // Cache creator for use in commitOutput
std::unique_ptr<Placement> plcmnt = getPlacement(creator, label);
m_store_writer->fillContainer(*plcmnt, data, type);
m_store_writer->fillContainer(*plcmnt, data, type, product_name);
return;
}

void PersistenceWriter::commitOutput(std::string const& creator, std::string const& id)
{
std::unique_ptr<Placement> plcmnt = getPlacement(creator, "index");
m_store_writer->fillContainer(*plcmnt, &id, typeid(std::string));
// Pass m_current_creator as product_name for IndexRegistry
m_store_writer->fillContainer(*plcmnt, &id, typeid(std::string), m_current_creator);
m_store_writer->commitContainers(*plcmnt);
return;
}
Expand All @@ -80,3 +83,5 @@ std::unique_ptr<Placement> PersistenceWriter::getPlacement(std::string const& cr
std::string const full_label = buildFullLabel(creator, label);
return std::make_unique<Placement>(config_item->file_name, full_label, config_item->technology);
}

void PersistenceWriter::finalize() { m_store_writer->finalize(m_tech_settings); }
5 changes: 4 additions & 1 deletion form/persistence/persistence_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ namespace form::detail::experimental {
void registerWrite(std::string const& creator,
std::string const& label,
void const* data,
std::type_info const& type) override;
std::type_info const& type,
std::string const& product_name = "") override;
void commitOutput(std::string const& creator, std::string const& id) override;
void finalize() override;

private:
std::unique_ptr<Placement> getPlacement(std::string const& creator, std::string const& label);
Expand All @@ -44,6 +46,7 @@ namespace form::detail::experimental {
std::unique_ptr<IStorageWriter> m_store_writer;
form::experimental::config::ItemConfig m_config_items;
form::experimental::config::tech_setting_config m_tech_settings;
std::string m_current_creator;
};

} // namespace form::detail::experimental
Expand Down
8 changes: 8 additions & 0 deletions form/root_storage/root_tbranch_write_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,11 @@ void ROOT_TBranch_Write_ContainerImp::commit()
m_tree->SetEntries(m_branch->GetEntries());
return;
}

std::uint64_t ROOT_TBranch_Write_ContainerImp::getEntryCount()
{
if (m_branch == nullptr) {
return 0;
}
return m_branch->GetEntries();
}
Comment thread
wwuoneway marked this conversation as resolved.
2 changes: 2 additions & 0 deletions form/root_storage/root_tbranch_write_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace form::detail::experimental {
void fill(void const* data) override;
void commit() override;

std::uint64_t getEntryCount() override;

private:
std::shared_ptr<TFile> m_tfile;
TTree* m_tree{nullptr};
Expand Down
21 changes: 19 additions & 2 deletions form/root_storage/root_tfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,31 @@

#include "TFile.h"

#include <filesystem>
#include <stdexcept>

using namespace form::detail::experimental;
ROOT_TFileImp::ROOT_TFileImp(std::string const& name, char mode) :
Storage_File(name, mode), m_file(nullptr)
{
if (mode == 'c' || mode == 'r' || mode == 'o') {
if (mode == 'c' || mode == 'o') {
// Preserve existing semantics: 'o' recreates the file, matching prior behavior
m_file.reset(TFile::Open(name.c_str(), "RECREATE"));
} else {
} else if (mode == 'u') {
// 'u' explicitly means reopen/update an existing file while preserving metadata.
if (std::filesystem::exists(name)) {
m_file.reset(TFile::Open(name.c_str(), "UPDATE"));
} else {
m_file.reset(TFile::Open(name.c_str(), "RECREATE"));
}
} else if (mode == 'r' || mode == 'i') {
m_file.reset(TFile::Open(name.c_str(), "READ"));
} else {
throw std::runtime_error(std::string("Unsupported ROOT file open mode: ") + mode);
}
Comment thread
wwuoneway marked this conversation as resolved.

if (!m_file || m_file->IsZombie()) {
throw std::runtime_error("Failed to open ROOT file: " + name);
}
}

Expand Down
8 changes: 8 additions & 0 deletions form/root_storage/root_ttree_write_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ void ROOT_TTree_Write_ContainerImp::commit()

TTree* ROOT_TTree_Write_ContainerImp::getTTree() { return m_tree.get(); }

std::uint64_t ROOT_TTree_Write_ContainerImp::getEntryCount()
{
if (m_tree == nullptr) {
return 0;
}
return m_tree->GetEntries();
}

void ROOT_TTree_Write_ContainerImp::TTreeDeleter::operator()(gsl::owner<TTree*> t) const
{
if (t) {
Expand Down
1 change: 1 addition & 0 deletions form/root_storage/root_ttree_write_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace form::detail::experimental {
void commit() override;

TTree* getTTree();
std::uint64_t getEntryCount() override;

private:
// Be absolutely explicit about the ownership semantics of TTree*,
Expand Down
5 changes: 4 additions & 1 deletion form/storage/istorage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ namespace form::detail::experimental {
form::experimental::config::tech_setting_config const& settings) = 0;
virtual void fillContainer(Placement const& plcmnt,
void const* data,
std::type_info const& type) = 0;
std::type_info const& type,
std::string const& product_name = "") = 0;
virtual void commitContainers(Placement const& plcmnt) = 0;
virtual void finalize(form::experimental::config::tech_setting_config const& settings) = 0;
};

class IStorage_File {
Expand All @@ -66,6 +68,7 @@ namespace form::detail::experimental {
virtual void commit() = 0;

virtual void setAttribute(std::string const& name, std::string const& value) = 0;
virtual std::uint64_t getEntryCount() = 0;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
};

class IStorage_Read_Container {
Expand Down
2 changes: 2 additions & 0 deletions form/storage/storage_write_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ void Storage_Write_Container::setAttribute(std::string const& /*name*/,
"Storage_Write_Container::setAttribute does not accept any attributes for a container named " +
m_name);
}

std::uint64_t Storage_Write_Container::getEntryCount() { return 0; }
1 change: 1 addition & 0 deletions form/storage/storage_write_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace form::detail::experimental {
void commit() override;

void setAttribute(std::string const& name, std::string const& value) override;
std::uint64_t getEntryCount() override;

private:
std::string m_name;
Expand Down
Loading
Loading