The Gaudi Framework  master (37c0b60a)
FileSvc Class Reference
Inheritance diagram for FileSvc:
Collaboration diagram for FileSvc:

Public Member Functions

 FileSvc (const std::string &name, ISvcLocator *svc)
 
virtual StatusCode initialize () override
 
virtual StatusCode finalize () override
 
virtual std::shared_ptr< TFile > getFile (const std::string &identifier) override
 Get a TFile pointer based on an identifier. More...
 
- Public Member Functions inherited from extends< Service, Gaudi::Interfaces::IFileSvc >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service
More...
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service
More...
 
StatusCode sysStart () override
 Initialize Service
More...
 
StatusCode sysStop () override
 Initialize Service
More...
 
StatusCode sysFinalize () override
 Finalize Service
More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor
More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator
More...
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool. More...
 
template<class T >
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
 
template<class T >
void addToolsArray (ToolHandleArray< T > &hndlArr)
 
const std::vector< IAlgTool * > & tools () const
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation. More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property. More...
 
virtual StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p)=0
 Set the property from a property with a different name. More...
 
virtual StatusCode setProperty (const std::string &s)=0
 Set the property by string. More...
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals. More...
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string. More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name More...
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string More...
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties More...
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name. More...
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected More...
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream) More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 

Public Attributes

Gaudi::Property< std::map< std::string, std::string > > m_config
 

Private Member Functions

std::shared_ptr< TFile > openFile (const std::string &filePath, const std::string &option)
 Open a file based on a specified path and opening mode. More...
 
StatusCode closeFiles ()
 Close all files. More...
 

Private Attributes

std::unordered_map< std::string, size_t > m_identifiers
 
std::vector< std::shared_ptr< TFile > > m_files
 

Additional Inherited Members

- Public Types inherited from extends< Service, Gaudi::Interfaces::IFileSvc >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces... >
 Typedef to the base of this class. More...
 
- Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory< IService *(const std::string &, ISvcLocator *)>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl = PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 Typedef used to refer to this class from derived classes, as in. More...
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 
 ~Service () override
 Standard Destructor
More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches. More...
 
MSG::Level resetMessaging ()
 Reinitialize internal states. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state
More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state
More...
 
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools More...
 
Gaudi::Property< bool > m_auditInit { this, "AuditServices", false, "[[deprecated]] unused" }
 
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
 
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
 
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
 
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
 
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
 
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
 
Gaudi::Property< bool > m_autoRetrieveTools
 
Gaudi::Property< bool > m_checkToolDeps
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service
More...
 

Detailed Description

Definition at line 23 of file FileSvc.cpp.

Constructor & Destructor Documentation

◆ FileSvc()

FileSvc::FileSvc ( const std::string name,
ISvcLocator svc 
)

Definition at line 136 of file FileSvc.cpp.

136 : base_class( name, svc ) {}

Member Function Documentation

◆ closeFiles()

StatusCode FileSvc::closeFiles ( )
private

Close all files.

Returns
StatusCode indicating the success or failure of the operation.

Definition at line 180 of file FileSvc.cpp.

180  {
181  for ( const auto& file : m_files ) {
182  if ( file ) { file->Close(); }
183  }
184  m_files.clear();
186  return StatusCode::SUCCESS;
187 }

◆ finalize()

StatusCode FileSvc::finalize ( )
overridevirtual

Definition at line 165 of file FileSvc.cpp.

165 { return closeFiles(); }

◆ getFile()

std::shared_ptr< TFile > FileSvc::getFile ( const std::string identifier)
overridevirtual

Get a TFile pointer based on an identifier.

Parameters
identifierA string identifying the file (2 identifiers can point to the same TFile).
Returns
An shared pointer to a TFile object corresponding to the specified identifier.

Definition at line 167 of file FileSvc.cpp.

167  {
168  auto it = m_identifiers.find( boost::to_lower_copy( identifier ) );
169  if ( it != m_identifiers.end() && it->second < m_files.size() ) { return m_files[it->second]; }
170  error() << "No file associated with identifier: " << identifier << endmsg;
171  return nullptr;
172 }

◆ initialize()

StatusCode FileSvc::initialize ( )
overridevirtual

Definition at line 138 of file FileSvc.cpp.

138  {
139  return Service::initialize().andThen( [this]() {
140  if ( checkConfig( m_config, *this ).isFailure() ) { return StatusCode::FAILURE; }
141 
142  for ( const auto& [identifier, path] : m_config ) {
143  auto params = parseFilePath( path );
144 
145  // Check if this file is already opened and mapped
146  if ( auto fileIndex = findFileIndex( m_files, params["path"] ) ) {
147  // File already opened, just map the identifier to the existing index
148  m_identifiers[boost::to_lower_copy( identifier )] = *fileIndex;
149  } else {
150  // File not found, open a new one
151  if ( auto file = openFile( path, params["mode"] ) ) {
152  m_files.push_back( std::move( file ) );
153  m_identifiers[boost::to_lower_copy( identifier )] = m_files.size() - 1;
154  } else {
155  error() << "Failed to open file: " << params["path"] << endmsg;
156  return StatusCode::FAILURE;
157  }
158  }
159  }
160 
161  return StatusCode::SUCCESS;
162  } );
163 }

◆ openFile()

std::shared_ptr< TFile > FileSvc::openFile ( const std::string filePath,
const std::string option 
)
private

Open a file based on a specified path and opening mode.

Parameters
filePathThe file path.
optionThe file opening options to pass to root ("NEW/CREATE", "RECREATE", "UPDATE").
Returns
A shared_ptr to a newly opened TFile object, or null if the operation fails.

Definition at line 174 of file FileSvc.cpp.

174  {
175  auto file = std::make_shared<TFile>( filePath.c_str(), option.c_str() );
176  if ( !file || file->IsZombie() ) { return nullptr; }
177  return file;
178 }

Member Data Documentation

◆ m_config

Initial value:
{
this, "Config", {}, "Map of keywords to file paths for file access" }

Definition at line 41 of file FileSvc.cpp.

◆ m_files

std::vector<std::shared_ptr<TFile> > FileSvc::m_files
private

Definition at line 64 of file FileSvc.cpp.

◆ m_identifiers

std::unordered_map<std::string, size_t> FileSvc::m_identifiers
private

Definition at line 61 of file FileSvc.cpp.


The documentation for this class was generated from the following file:
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:118
StatusCode::andThen
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition: StatusCode.h:163
std::move
T move(T... args)
AtlasMCRecoFullPrecedenceDump.path
path
Definition: AtlasMCRecoFullPrecedenceDump.py:49
FileSvc::closeFiles
StatusCode closeFiles()
Close all files.
Definition: FileSvc.cpp:180
std::unordered_map::find
T find(T... args)
std::vector::size
T size(T... args)
extends< Service, Gaudi::Interfaces::IFileSvc >::base_class
extends base_class
Typedef to this class.
Definition: extends.h:24
std::vector::clear
T clear(T... args)
std::vector::push_back
T push_back(T... args)
FileSvc::openFile
std::shared_ptr< TFile > openFile(const std::string &filePath, const std::string &option)
Open a file based on a specified path and opening mode.
Definition: FileSvc.cpp:174
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:332
std::string::c_str
T c_str(T... args)
FileSvc::m_config
Gaudi::Property< std::map< std::string, std::string > > m_config
Definition: FileSvc.cpp:41
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
std::unordered_map::end
T end(T... args)
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
FileSvc::m_identifiers
std::unordered_map< std::string, size_t > m_identifiers
Definition: FileSvc.cpp:61
FileSvc::m_files
std::vector< std::shared_ptr< TFile > > m_files
Definition: FileSvc.cpp:64