The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
FileSvc Class Reference
Inheritance diagram for FileSvc:
Collaboration diagram for FileSvc:

Public Member Functions

 FileSvc (const std::string &name, ISvcLocator *svc)
 
StatusCode initialize () override
 
StatusCode finalize () override
 
std::shared_ptr< TFile > getFile (const std::string &identifier) override
 Get a TFile pointer based on an identifier.
 
bool hasIdentifier (const std::string &identifier) const override
 Check if a given identifier is known to the service.
 
- Public Member Functions inherited from extends< Service, Gaudi::Interfaces::IFileSvc >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
 
- Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service.
 
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.
 
StatusCode sysStart () override
 Initialize Service.
 
StatusCode sysStop () override
 Initialize Service.
 
StatusCode sysFinalize () override
 Finalize Service.
 
StatusCode sysReinitialize () override
 Re-initialize the Service.
 
StatusCode sysRestart () override
 Re-initialize the Service.
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
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.
 
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.
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
 
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.
 
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.
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
 
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)
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 

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, int compress)
 Open a file based on a specified path and opening mode.
 
StatusCode closeFiles ()
 Close all files.
 

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
 Typedef to this class.
 
using extend_interfaces_base
 Typedef to the base of this class.
 
- 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
 Typedef used to refer to this class from derived classes, as in.
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
 
- Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 
 ~Service () override
 
int outputLevel () const
 get the Service's output level
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches.
 
MSG::Level resetMessaging ()
 Reinitialize internal states.
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
 
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.
 

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 140 of file FileSvc.cpp.

140: base_class( name, svc ) {}
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333

Member Function Documentation

◆ closeFiles()

StatusCode FileSvc::closeFiles ( )
private

Close all files.

Returns
StatusCode indicating the success or failure of the operation.

Definition at line 191 of file FileSvc.cpp.

191 {
192 for ( const auto& file : m_files ) {
193 if ( file ) { file->Close(); }
194 }
195 m_files.clear();
196 m_identifiers.clear();
197 return StatusCode::SUCCESS;
198}
std::vector< std::shared_ptr< TFile > > m_files
Definition FileSvc.cpp:68
std::unordered_map< std::string, size_t > m_identifiers
Definition FileSvc.cpp:65
constexpr static const auto SUCCESS
Definition StatusCode.h:99

◆ finalize()

StatusCode FileSvc::finalize ( )
override

Definition at line 172 of file FileSvc.cpp.

172{ return closeFiles(); }
StatusCode closeFiles()
Close all files.
Definition FileSvc.cpp:191

◆ getFile()

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

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 174 of file FileSvc.cpp.

174 {
175 auto it = m_identifiers.find( boost::to_lower_copy( identifier ) );
176 if ( it != m_identifiers.end() && it->second < m_files.size() ) { return m_files[it->second]; }
177 error() << "No file associated with identifier: " << identifier << endmsg;
178 return nullptr;
179}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)

◆ hasIdentifier()

bool FileSvc::hasIdentifier ( const std::string & identifier) const
override

Check if a given identifier is known to the service.

Definition at line 181 of file FileSvc.cpp.

181 {
182 return m_identifiers.find( boost::to_lower_copy( identifier ) ) != m_identifiers.end();
183}

◆ initialize()

StatusCode FileSvc::initialize ( )
override

Definition at line 142 of file FileSvc.cpp.

142 {
143 return Service::initialize().andThen( [this]() {
144 if ( checkConfig( m_config, *this ).isFailure() ) { return StatusCode::FAILURE; }
145
146 for ( const auto& [identifier, path] : m_config ) {
147 auto params = parseFilePath( path );
148
149 // Check if this file is already opened and mapped
150 if ( auto fileIndex = findFileIndex( m_files, params["path"] ) ) {
151 // File already opened, just map the identifier to the existing index
152 m_identifiers[boost::to_lower_copy( identifier )] = *fileIndex;
153 } else {
154 // File not found, open a new one
155 int compress = ( params.find( "compress" ) != params.end() )
156 ? std::stoi( params["compress"] )
157 : ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault;
158 if ( auto file = openFile( path, params["mode"], compress ) ) {
159 m_files.push_back( std::move( file ) );
160 m_identifiers[boost::to_lower_copy( identifier )] = m_files.size() - 1;
161 } else {
162 error() << "Failed to open file: " << params["path"] << endmsg;
163 return StatusCode::FAILURE;
164 }
165 }
166 }
167
168 return StatusCode::SUCCESS;
169 } );
170}
Gaudi::Property< std::map< std::string, std::string > > m_config
Definition FileSvc.cpp:44
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.
Definition FileSvc.cpp:185
StatusCode initialize() override
Definition Service.cpp:118
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition StatusCode.h:163
constexpr static const auto FAILURE
Definition StatusCode.h:100
@ ROOT
Definition IFileMgr.h:147

◆ openFile()

std::shared_ptr< TFile > FileSvc::openFile ( const std::string & filePath,
const std::string & option,
int compress )
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").
compressThe compression level and algorithm to use for the file.
Returns
A shared_ptr to a newly opened TFile object, or null if the operation fails.

Definition at line 185 of file FileSvc.cpp.

185 {
186 auto file = std::make_shared<TFile>( filePath.c_str(), option.c_str(), "", compress );
187 if ( !file || file->IsZombie() ) { return nullptr; }
188 return file;
189}

Member Data Documentation

◆ m_config

Gaudi::Property<std::map<std::string, std::string> > FileSvc::m_config
Initial value:
{
this, "Config", {}, "Map of keywords to file paths for file access" }

Definition at line 44 of file FileSvc.cpp.

44 {
45 this, "Config", {}, "Map of keywords to file paths for file access" };

◆ m_files

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

Definition at line 68 of file FileSvc.cpp.

◆ m_identifiers

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

Definition at line 65 of file FileSvc.cpp.


The documentation for this class was generated from the following file: