18#include <boost/algorithm/string.hpp>
63 bool hasIdentifier(
const std::string& identifier )
const override;
68 this,
"Config", {},
"Map of keywords to file paths for file access" };
107 boost::split( parts, path, boost::is_any_of(
"?" ) );
109 if ( parts.
size() > 1 ) {
111 boost::split( params, parts[1], boost::is_any_of(
"&" ) );
112 for (
auto& param : params ) {
114 boost::split( kv, param, boost::is_any_of(
"=" ) );
115 if ( kv.
size() == 2 ) { result[boost::trim_copy( kv[0] )] = boost::trim_copy( kv[1] ); }
118 result[
"mode"] = ( result.
find(
"mode" ) == result.
end() ) ?
"CREATE" : result[
"mode"];
119 result[
"path"] = boost::trim_copy( parts[0] );
134 for (
const auto& [identifier, path] : configMap ) {
135 auto params = parseFilePath( path );
137 auto& existingParams = fileParams[params[
"path"]];
138 if ( !existingParams.empty() ) {
139 if ( existingParams != params ) {
140 svc.
error() <<
"Conflicting configurations for file path: " << params[
"path"] <<
endmsg;
159 [&filePath](
const auto& file ) { return file && file->GetName() == filePath; } );
160 if ( it != files.end() ) {
return std::distance( files.begin(), it ); }
171 for (
const auto& [identifier, path] :
m_config ) {
172 auto params = parseFilePath( path );
175 if (
auto fileIndex = findFileIndex(
m_files, params[
"path"] ) ) {
177 m_identifiers[boost::to_lower_copy( identifier )] = *fileIndex;
180 int compress = ( params.find(
"compress" ) != params.end() )
181 ? std::stoi( params[
"compress"] )
182 : ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault;
183 if (
auto file =
openFile( path, params[
"mode"], compress ) ) {
187 error() <<
"Failed to open file: " << params[
"path"] <<
endmsg;
204 for (
auto const& file :
m_files ) {
217 error() <<
"No file associated with identifier: " << identifier <<
endmsg;
226 auto file = std::make_shared<TFile>( filePath.
c_str(), option.
c_str(),
"", compress );
227 if ( !file || file->IsZombie() ) {
return nullptr; }
232 for (
const auto& file :
m_files ) {
233 if ( file ) { file->Close(); }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
#define DECLARE_COMPONENT(type)
constexpr _OI move(_II __first, _II __last, _OI __result)
constexpr _InputIterator find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
void call_once(once_flag &__once, _Callable &&__f, _Args &&... __args)
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
const _CharT * c_str() const noexcept
const_iterator end() const noexcept
iterator find(const key_type &__x)
constexpr void push_back(const value_type &__x)
constexpr size_type size() const noexcept
iterator find(const key_type &__x)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Implementation of the IFileSvc interface, allowing algorithms to access ROOT files via a centralized ...
Gaudi::Property< std::map< std::string, std::string > > m_config
StatusCode closeFiles()
Close all files.
StatusCode start() override
std::vector< std::shared_ptr< TFile > > m_files
StatusCode initialize() override
bool hasIdentifier(const std::string &identifier) const override
Check if a given identifier is known to the service.
StatusCode finalize() override
std::once_flag m_announceOutputs
std::unordered_map< std::string, size_t > m_identifiers
FileSvc(const std::string &name, ISvcLocator *svc)
std::shared_ptr< TFile > getFile(const std::string &identifier) override
Get a TFile pointer based on an identifier.
std::shared_ptr< TFile > openFile(const std::string &filePath, const std::string &option, int compress)
Open a file based on a specified path and opening mode.
Implementation of property with value of concrete type.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
const std::string & name() const override
Retrieve name of the service.
SmartIF< IFace > service(const std::string &name, bool createIf=true) const
StatusCode start() override
StatusCode initialize() override
This class is used for returning status codes from appropriate routines.
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
Base class used to extend a class implementing other interfaces.