Skip to content
Snippets Groups Projects
Commit 48d18f24 authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Allow Root Sinks to write to a common file

This is done by only updating the potentially existing file when writing and droping the file at initialization to not mix data from 2 rounds.
There is no thread safety issue for now as we write in the stop method
parent 973b94b4
No related branches found
No related tags found
1 merge request!1401Switching from histogramPersistencySvc to new Sinks
......@@ -16,6 +16,7 @@
#include <nlohmann/json.hpp>
#include <filesystem>
#include <map>
#include <string>
#include <vector>
......@@ -39,9 +40,21 @@ namespace Gaudi::Histograming::Sink {
.orThrow( "Unable to set typesToSaveProperty", "Histograming::Sink::Base" );
}
StatusCode initialize() override {
return BaseSink::initialize().andThen( [&] {
// empty output file if it exists, as we will update it at the end
// This allows multiple Sinks to write to the same ROOT file
std::filesystem::remove( m_fileName.value() );
} );
}
StatusCode stop() override {
return Service::stop().andThen( [&] {
TFile histoFile( m_fileName.value().c_str(), "RECREATE" );
// File is updated so that multiple sinks can write to the same file
// As we are in stop, there is no multithreading so it is safe
// As we dropped the file at initialization, no old data from a previous
// run may be mixed with new one
TFile histoFile( m_fileName.value().c_str(), "UPDATE" );
applytoAllEntities(
[&histoFile, this]( auto& ent ) {
auto j = ent.toJSON();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment