The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
FileMgr Class Reference

#include </builds/gaudi/Gaudi/GaudiSvc/src/FileMgr/FileMgr.h>

Inheritance diagram for FileMgr:
Collaboration diagram for FileMgr:

Public Member Functions

 ~FileMgr () override
 
StatusCode initialize () override
 
StatusCode finalize () override
 
void handle (const Incident &) override
 
StatusCode regHandler (FileHdlr) override
 
StatusCode hasHandler (const IoTech &) const override
 
StatusCode deregHandler (const IoTech &) override
 
StatusCode getHandler (const IoTech &, FileHdlr &) const override
 
StatusCode getHandler (const std::string &, FileHdlr &) const override
 
int getFileAttr (const std::string &, std::vector< const FileAttr * > &) const override
 
StatusCode getFileAttr (const Fd, const FileAttr *&) const override
 
StatusCode getFileAttr (void *, const FileAttr *&) const override
 
void listHandlers () const override
 
void listFiles () const override
 
virtual void listActions () const
 
virtual void listSuppression () const
 
int getFiles (std::vector< std::string > &, bool onlyOpen=true) const override
 
int getFiles (std::vector< const Io::FileAttr * > &, bool onlyOpen=true) const override
 
int getFiles (const Io::IoTech &, std::vector< std::string > &, bool onlyOpen=true) const override
 
int getFiles (const Io::IoTech &, std::vector< const Io::FileAttr * > &, bool onlyOpen=true) const override
 
int getFiles (const Io::IoTech &, const Io::IoFlags &, std::vector< std::string > &, bool onlyOpen=true) const override
 
int getFiles (const Io::IoTech &, const Io::IoFlags &, std::vector< const Io::FileAttr * > &, bool onlyOpen=true) const override
 
int getFd (std::vector< Fd > &) const override
 
int getFd (const Io::IoTech &, std::vector< Io::Fd > &) const override
 
int getFd (const Io::IoTech &, const Io::IoFlags &, std::vector< Io::Fd > &) const override
 
const std::string & fname (const Io::Fd &) const override
 
const std::string & fname (void *) const override
 
Io::Fd fd (const std::string &) const override
 
Io::Fd fd (void *) const override
 
void * fptr (const std::string &) const override
 
void * fptr (const Io::Fd &) const override
 
int getLastError (std::string &) const override
 
Io::open_t open (const Io::IoTech &, const std::string &caller, const std::string &fname, const Io::IoFlags &, Io::Fd &fd, void *&ptr, const std::string &desc="", const bool shared=false) override
 
Io::open_t open (const Io::IoTech &, const std::string &caller, const std::string &fname, const Io::IoFlags &, Io::Fd &, const std::string &desc="", const bool shared=false) override
 
Io::open_t open (const Io::IoTech &, const std::string &caller, const std::string &fname, const Io::IoFlags &, void *&, const std::string &desc="", const bool shared=false) override
 
Io::close_t close (const Fd, const std::string &caller) override
 
Io::close_t close (void *, const std::string &caller) override
 
Io::reopen_t reopen (const Fd, const IoFlags &, const std::string &caller) override
 
Io::reopen_t reopen (void *, const IoFlags &, const std::string &caller) override
 
StatusCode regAction (Io::bfcn_action_t, const Io::Action &, const std::string &desc="") override
 
StatusCode regAction (Io::bfcn_action_t, const Io::Action &, const Io::IoTech &, const std::string &desc="") override
 
void suppressAction (const std::string &) override
 
void suppressAction (const std::string &, const Io::Action &) override
 
- Public Member Functions inherited from extends< Service, IFileMgr, IIncidentListener >
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)
 

Private Types

typedef std::pair< Io::bfcn_action_t, std::string > bfcn_desc_t
 
typedef std::map< Io::Action, std::list< bfcn_desc_t > > actionMap
 
typedef std::multimap< std::string, FileAttr * > fileMap
 

Private Member Functions

virtual Io::open_t open (const IoTech &, const std::string &caller, const std::string &fname, const std::string &desc, const IoFlags &, Fd &, void *&, const bool shared)
 
StatusCode execAction (Io::FileAttr *, const std::string &, const Io::Action &) const
 
StatusCode execActs (Io::FileAttr *, const std::string &, const Io::Action &, const actionMap &m) const
 
bool accessMatch (const Io::IoFlags &, const Io::IoFlags &, bool strict=false) const
 
bool isShareable (const std::string &filename, const Io::IoFlags &) const
 

Private Attributes

Gaudi::Property< std::string > m_logfile { this, "LogFile" }
 
Gaudi::Property< bool > m_printSummary { this, "PrintSummary", false }
 
Gaudi::Property< bool > m_loadRootHandler { this, "LoadROOTHandler", true }
 
Gaudi::Property< bool > m_loadPosixHandler { this, "LoadPOSIXHandler", true }
 
Gaudi::Property< std::string > m_ssl_proxy { this, "TSSL_UserProxy", "X509" }
 
Gaudi::Property< std::string > m_ssl_cert { this, "TSSL_CertDir", "X509" }
 
fileMap m_files
 
std::map< IoTech, FileHdlrm_handlers
 
std::map< Fd, FileAttr * > m_descriptors
 
std::vector< std::unique_ptr< FileAttr > > m_attr
 
std::vector< FileAttr * > m_oldFiles
 
std::map< IoTech, actionMapm_actions
 
std::map< std::string, Io::Action_bitmapm_supMap
 
std::string m_lastErrS
 
int m_lastErr
 
std::optional< RootFileHandlerm_rfh
 
std::optional< POSIXFileHandlerm_pfh
 

Additional Inherited Members

- Public Types inherited from extends< Service, IFileMgr, IIncidentListener >
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 44 of file FileMgr.h.

Member Typedef Documentation

◆ actionMap

typedef std::map<Io::Action, std::list<bfcn_desc_t> > FileMgr::actionMap
private

Definition at line 135 of file FileMgr.h.

◆ bfcn_desc_t

typedef std::pair<Io::bfcn_action_t, std::string> FileMgr::bfcn_desc_t
private

Definition at line 134 of file FileMgr.h.

◆ fileMap

typedef std::multimap<std::string, FileAttr*> FileMgr::fileMap
private

Definition at line 142 of file FileMgr.h.

Constructor & Destructor Documentation

◆ ~FileMgr()

FileMgr::~FileMgr ( )
override

Definition at line 63 of file FileMgr.cpp.

63 {
64 // Where do the new-ed FileAttr get deleted?
65 // they get pushed into m_descriptors, but m_attr is presumably
66 // where they _also_ should be pushed in order to track ownership...
67}

Member Function Documentation

◆ accessMatch()

bool FileMgr::accessMatch ( const Io::IoFlags & fold,
const Io::IoFlags & fnew,
bool strict = false ) const
private

Definition at line 1151 of file FileMgr.cpp.

1151 {
1153 verbose() << "accessMatch old: " << fold << " new: " << fnew << endmsg;
1154
1155 return ( ( ( fold == Io::READ ) && ( fnew == Io::READ ) ) ||
1156 ( ( fold & Io::WRITE ) != 0 && ( fnew & Io::WRITE ) != 0 ) ||
1157 ( ( fold & Io::RDWR ) != 0 && ( fnew & Io::RDWR ) != 0 ) );
1158}
#define ON_VERBOSE
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
@ READ
Definition IFileMgr.h:30
@ RDWR
Definition IFileMgr.h:32
@ WRITE
Definition IFileMgr.h:31

◆ close() [1/2]

close_t FileMgr::close ( const Fd fd,
const std::string & caller )
override

Definition at line 402 of file FileMgr.cpp.

402 {
403
404 // return codes:
405 // < 0 : error condition
406 // 0 : actual close of one file
407 // > 0 : shared file, removed from list, no actual close, returns
408 // number of shared files still open.
409
411 verbose() << "close(" << fd << ")" << endmsg;
412
413 close_t r = -1;
414
415 auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
416 [&]( fileMap::const_reference i ) { return i.second->fd() == fd; } );
417
418 if ( itr == std::end( m_files ) ) {
419 error() << "unknown file descriptor \"" << fd << "\" when calling close()" << endmsg;
420 return r;
421 }
422
423 IoTech tech = itr->second->tech();
424
425 FileHdlr fh;
426
427 if ( getHandler( tech, fh ).isFailure() ) { return r; }
428
429 if ( !fh.b_close_fcn ) {
430 error() << "no close(" << tech << ",Fd) function registered" << endmsg;
431 return -1;
432 }
433
434 FileAttr* fa = itr->second;
435
436 // find how many times this file is open
437 auto fitr = m_files.equal_range( fa->name() );
438 int i = std::count_if( fitr.first, fitr.second, [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
439
441 verbose() << " ref count: " << i << endmsg;
442
443 if ( i > 1 && fa->isShared() ) {
444 // file open multiple times. don't do the actual close
446 debug() << "closing file " << fa->name() << " opened " << i << " times with Fd " << fd << endmsg;
447 m_files.erase( itr );
448
449 r = i - 1;
450
451 } else if ( i == 1 || ( i > 1 && !fa->isShared() ) ) {
453 debug() << "closing " << *fa << endmsg;
454
455 try {
456 r = fh.b_close_fcn( fd );
457 } catch ( const std::bad_function_call& err ) {
458 error() << "when calling close handler for " << tech << " on file descriptor " << fd << " caught " << err.what()
459 << endmsg;
460 execAction( fa, caller, Io::CLOSE_ERR ).ignore();
461 return -1;
462 } catch ( ... ) {
463 error() << "when calling close handler for " << tech << " on file descriptor " << fd
464 << " caught an unknown exception." << endmsg;
465 execAction( fa, caller, Io::CLOSE_ERR ).ignore();
466 return -1;
467 }
468
469 if ( r < 0 ) {
470 warning() << "close of file with FD \"" << fd << "\", name: \"" << fa->name() << "\", tech: \"" << tech
471 << "\" failed" << endmsg;
472
473 execAction( fa, caller, Io::CLOSE_ERR ).ignore();
474
475 return r;
476 }
477
478 m_files.erase( itr );
479
480 } else if ( i <= 0 ) {
481 // this should never happen!
482 error() << "ref count < 0 when closing " << fa << ". This should never happen" << endmsg;
483 return -1;
484 }
485
486 fa->fd( -1 );
487 fa->flags( INVALID );
488 fa->isOpen( false );
489 fa->fptr( 0 );
490 m_oldFiles.push_back( fa );
491
492 // exec all callbacks
493 if ( execAction( fa, caller, Io::CLOSE ).isFailure() ) {
494 warning() << "at least one close callback action failed" << endmsg;
495 }
496
497 return r;
498}
#define ON_DEBUG
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
std::vector< FileAttr * > m_oldFiles
Definition FileMgr.h:149
StatusCode execAction(Io::FileAttr *, const std::string &, const Io::Action &) const
Definition FileMgr.cpp:1097
fileMap m_files
Definition FileMgr.h:144
Io::Fd fd(const std::string &) const override
Definition FileMgr.cpp:949
StatusCode getHandler(const IoTech &, FileHdlr &) const override
Definition FileMgr.cpp:1005
void * fptr() const
Definition IFileMgr.h:180
bool isOpen() const
Definition IFileMgr.h:181
IoFlags flags() const
Definition IFileMgr.h:178
Fd fd() const
Definition IFileMgr.h:174
bool isShared() const
Definition IFileMgr.h:182
const std::string & name() const
Definition IFileMgr.h:175
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:139
@ CLOSE
Definition IFileMgr.h:263
@ CLOSE_ERR
Definition IFileMgr.h:263
IoTech
Definition IFileMgr.h:147
@ INVALID
Definition IFileMgr.h:40
int close_t
Definition IFileMgr.h:231
bfcn_close_t b_close_fcn
Definition IFileMgr.h:245

◆ close() [2/2]

close_t FileMgr::close ( void * vp,
const std::string & caller )
override

Definition at line 501 of file FileMgr.cpp.

501 {
502
503 // return codes:
504 // < 0 : error condition
505 // 0 : actual close of one file
506 // > 0 : shared file, removed from list, no actual close, returns
507 // number of shared files still open.
508
510 verbose() << "close(" << vp << ")" << endmsg;
511
512 close_t r = -1;
513
514 auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
515 [&]( fileMap::const_reference i ) { return i.second->fptr() == vp; } );
516
517 if ( itr == m_files.end() ) {
518 error() << "unknown file ptr \"" << vp << "\" when calling close()" << endmsg;
519 return r;
520 }
521
522 IoTech tech = itr->second->tech();
523
524 FileHdlr fh;
525
526 if ( getHandler( tech, fh ).isFailure() ) { return r; }
527 if ( !fh.b_closeP_fcn ) {
528 error() << "no close(" << tech << ",void*) function registered" << endmsg;
529 return -1;
530 }
531
532 FileAttr* fa = itr->second;
533
534 // find how many times this file is open
535 pair<fileMap::const_iterator, fileMap::const_iterator> fitr = m_files.equal_range( fa->name() );
536
537 int i =
538 std::count_if( fitr.first, fitr.second, [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
539
541 verbose() << " ref count: " << i << endmsg;
542
543 if ( i > 1 && fa->isShared() ) {
544 // file open multiple times in shared access. don't do the actual close
546 debug() << "closing file " << fa->name() << " opened " << i << " times with fptr " << vp << endmsg;
547 m_files.erase( itr );
548
549 r = i - 1;
550
551 } else if ( i == 1 || ( i > 1 && !fa->isShared() ) ) {
553 debug() << "closing: " << *fa << endmsg;
554
555 try {
556 r = fh.b_closeP_fcn( vp );
557 } catch ( const std::bad_function_call& err ) {
558 error() << "when calling close handler for " << tech << " on file " << fa->name() << " caught " << err.what()
559 << endmsg;
560 execAction( fa, caller, CLOSE_ERR ).ignore();
561 return -1;
562 } catch ( ... ) {
563 error() << "when calling close handler for " << tech << " on file " << fa->name()
564 << " caught an unknown exception." << endmsg;
565 execAction( fa, caller, CLOSE_ERR ).ignore();
566 return -1;
567 }
568
569 if ( r < 0 ) {
570 warning() << "close of file with ptr \"" << vp << "\", name: \"" << fa->name() << "\", tech: \"" << tech
571 << "\" failed" << endmsg;
572
573 return r;
574 }
575
576 m_files.erase( itr );
577
578 } else {
579 // this should never happen!
580 error() << "ref count: " << i << " < 0 when closing " << fa << ". This should never happen" << endmsg;
581 return -1;
582 }
583
584 fa->fd( -1 );
585 fa->flags( INVALID );
586 fa->isOpen( false );
587 fa->fptr( 0 );
588 m_oldFiles.push_back( fa );
589
590 // exec all callbacks
591 if ( execAction( fa, caller, CLOSE ).isFailure() ) {
592 warning() << "at least one close callback action failed" << endmsg;
593 }
594
595 return r;
596}
bfcn_closeP_t b_closeP_fcn
Definition IFileMgr.h:246

◆ deregHandler()

StatusCode FileMgr::deregHandler ( const IoTech & tech)
override

Definition at line 220 of file FileMgr.cpp.

220 {
221 FileHdlr hdlr;
222
223 auto itr = m_handlers.find( tech );
224 if ( itr == m_handlers.end() ) {
225 error() << "Can't de-register tech " << tech << " as it hasn't been registered!" << endmsg;
226 return StatusCode::FAILURE;
227 }
228
229 m_handlers.erase( itr );
230 return StatusCode::SUCCESS;
231}
std::map< IoTech, FileHdlr > m_handlers
Definition FileMgr.h:145
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100

◆ execAction()

StatusCode FileMgr::execAction ( Io::FileAttr * fa,
const std::string & caller,
const Io::Action & a ) const
private

Definition at line 1097 of file FileMgr.cpp.

1097 {
1098
1099 Io::IoTech tech = fa->tech();
1100
1101 StatusCode s1, s2;
1102
1103 auto itr = m_actions.find( Io::UNKNOWN );
1104
1105 if ( itr != m_actions.end() && !itr->second.empty() ) { s1 = execActs( fa, caller, a, itr->second ); }
1106
1107 itr = m_actions.find( tech );
1108 if ( itr != m_actions.end() && !itr->second.empty() ) { s2 = execActs( fa, caller, a, itr->second ); }
1109
1110 return ( s1.isFailure() || s2.isFailure() ) ? StatusCode::FAILURE : StatusCode::SUCCESS;
1111}
StatusCode execActs(Io::FileAttr *, const std::string &, const Io::Action &, const actionMap &m) const
Definition FileMgr.cpp:1115
std::map< IoTech, actionMap > m_actions
Definition FileMgr.h:151
IoTech tech() const
Definition IFileMgr.h:177
@ UNKNOWN
Definition IFileMgr.h:147

◆ execActs()

StatusCode FileMgr::execActs ( Io::FileAttr * fa,
const std::string & caller,
const Io::Action & a,
const actionMap & m ) const
private

Definition at line 1115 of file FileMgr.cpp.

1116 {
1117
1118 auto mitr = m.find( a );
1119 if ( mitr == m.end() || mitr->second.empty() ) return StatusCode::SUCCESS;
1120
1121 ON_DEBUG
1122 debug() << "executing " << mitr->second.size() << " " << a << " actions on " << *fa << " from " << caller << endmsg;
1123
1124 bool fail( false );
1125
1126 auto it2 = m_supMap.find( fa->name() );
1127 if ( it2 != m_supMap.end() ) {
1128 if ( it2->second[a] || it2->second[Io::INVALID_ACTION] ) {
1129 ON_DEBUG
1130 debug() << " --> suppressing callback action for " << a << endmsg;
1131 return StatusCode::SUCCESS;
1132 }
1133 }
1134
1135 for ( const auto& itr : mitr->second ) {
1136
1137 ON_DEBUG
1138 debug() << "executing " << itr.second << endmsg;
1139
1140 if ( ( ( ( itr.first ) )( fa, caller ) ).isFailure() ) {
1141 warning() << "execution of " << itr.second << " on " << *fa << " failed during " << a << " action" << endmsg;
1142 fail = true;
1143 }
1144 }
1145
1147}
std::map< std::string, Io::Action_bitmap > m_supMap
Definition FileMgr.h:153
constexpr double m
@ INVALID_ACTION
Definition IFileMgr.h:263

◆ fd() [1/2]

Io::Fd FileMgr::fd ( const std::string & fname) const
override

Definition at line 949 of file FileMgr.cpp.

949 {
950
951 auto fitr = m_files.equal_range( fname );
952 auto itr = std::find_if( fitr.first, fitr.second, []( fileMap::const_reference f ) { return f.second->fd() != -1; } );
953 return itr != fitr.second ? itr->second->fd() : -1;
954}
const std::string & fname(const Io::Fd &) const override
Definition FileMgr.cpp:931

◆ fd() [2/2]

Io::Fd FileMgr::fd ( void * fptr) const
override

Definition at line 958 of file FileMgr.cpp.

958 {
959
960 auto itr = std::find_if( m_files.begin(), m_files.end(),
961 [&]( fileMap::const_reference f ) { return f.second->fptr() == fptr; } );
962 return itr != m_files.end() ? itr->second->fd() : -1;
963}

◆ finalize()

StatusCode FileMgr::finalize ( )
override

Definition at line 125 of file FileMgr.cpp.

125 {
127 verbose() << "FileMgr::finalize()" << endmsg;
128
129 if ( m_printSummary || msgLevel( MSG::DEBUG ) ) {
130 listHandlers();
131 listFiles();
132 listActions();
134 }
135
136 if ( !m_files.empty() ) {
137 auto& log = warning();
138 log << "At finalize, the following files remained open:\n";
139 for ( const auto& itr : m_files ) log << *( itr.second ) << '\n';
140 log << endmsg;
141 }
142
143 if ( m_logfile.value() != "" ) {
144 std::ofstream ofs;
145 ofs.open( m_logfile.value().c_str() );
146 if ( !ofs ) {
147 error() << "Unable to open output file \"" << m_logfile.value() << "\" for writing" << endmsg;
148 } else {
150 debug() << "Saving log to \"" << m_logfile.value() << "\"" << endmsg;
151 for ( const auto& itr : m_files ) {
152 ofs << itr.second->name() << " " << itr.second->tech() << " " << itr.second->desc() << " "
153 << itr.second->iflags() << '\n';
154 }
155
156 set<FileAttr> fs;
157 for ( const auto& it2 : m_oldFiles ) fs.insert( *it2 );
158 for ( const auto& it3 : fs ) {
159 ofs << it3.name() << " " << it3.tech() << " " << it3.desc() << " " << it3.iflags()
160 << ( it3.isShared() ? " SHARED" : "" ) << '\n';
161 }
162 ofs.close();
163 }
164 }
165
166 // cleanup FileAttrs
167 m_attr.clear();
168
169 m_rfh.reset();
170 m_pfh.reset();
171
172 StatusCode status = Service::finalize();
173
175 if ( status.isSuccess() ) debug() << "Service finalised successfully" << endmsg;
176
177 return status;
178}
std::vector< std::unique_ptr< FileAttr > > m_attr
Definition FileMgr.h:147
Gaudi::Property< std::string > m_logfile
Definition FileMgr.h:122
Gaudi::Property< bool > m_printSummary
Definition FileMgr.h:123
virtual void listActions() const
Definition FileMgr.cpp:1072
std::optional< RootFileHandler > m_rfh
Definition FileMgr.h:158
void listHandlers() const override
Definition FileMgr.cpp:1043
virtual void listSuppression() const
Definition FileMgr.cpp:1170
std::optional< POSIXFileHandler > m_pfh
Definition FileMgr.h:159
void listFiles() const override
Definition FileMgr.cpp:985
StatusCode finalize() override
Definition Service.cpp:223
bool isSuccess() const
Definition StatusCode.h:314
@ DEBUG
Definition IMessageSvc.h:22

◆ fname() [1/2]

const std::string & FileMgr::fname ( const Io::Fd & fd) const
override

Definition at line 931 of file FileMgr.cpp.

931 {
932
933 auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
934 [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
935 return ( itr != std::end( m_files ) ) ? itr->second->name() : s_empty;
936}

◆ fname() [2/2]

const std::string & FileMgr::fname ( void * vp) const
override

Definition at line 940 of file FileMgr.cpp.

940 {
941
942 auto itr = std::find_if( m_files.begin(), m_files.end(),
943 [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
944 return itr != m_files.end() ? itr->second->name() : s_empty;
945}

◆ fptr() [1/2]

void * FileMgr::fptr ( const Io::Fd & fd) const
override

Definition at line 976 of file FileMgr.cpp.

976 {
977
978 auto itr = std::find_if( m_files.begin(), m_files.end(),
979 [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
980 return itr != m_files.end() ? itr->second->fptr() : nullptr;
981}

◆ fptr() [2/2]

void * FileMgr::fptr ( const std::string & fname) const
override

Definition at line 967 of file FileMgr.cpp.

967 {
968 auto fitr = m_files.equal_range( fname );
969 auto itr =
970 std::find_if( fitr.first, fitr.second, []( fileMap::const_reference f ) -> bool { return f.second->fptr(); } );
971 return itr != fitr.second ? itr->second->fptr() : nullptr;
972}

◆ getFd() [1/3]

int FileMgr::getFd ( const Io::IoTech & tech,
const Io::IoFlags & flags,
std::vector< Io::Fd > & fd ) const
override

Definition at line 919 of file FileMgr.cpp.

919 {
920
921 fd.clear();
922 transform_if( m_descriptors.begin(), m_descriptors.end(), std::back_inserter( fd ), select1st,
923 [&]( const std::pair<Fd, FileAttr*>& d ) {
924 return ( d.second->tech() == tech || tech == UNKNOWN ) && ( d.second->flags() == flags );
925 } );
926 return fd.size();
927}
std::map< Fd, FileAttr * > m_descriptors
Definition FileMgr.h:146

◆ getFd() [2/3]

int FileMgr::getFd ( const Io::IoTech & tech,
std::vector< Io::Fd > & fd ) const
override

Definition at line 904 of file FileMgr.cpp.

904 {
905
906 if ( tech == UNKNOWN ) return getFd( fd );
907
908 fd.clear();
909 transform_if( std::begin( m_descriptors ), std::end( m_descriptors ), std::back_inserter( fd ), select1st,
910 [&]( const std::pair<Fd, FileAttr*>& d ) { return d.second->tech() == tech; } );
911
912 return fd.size();
913}
int getFd(std::vector< Fd > &) const override
Definition FileMgr.cpp:893

◆ getFd() [3/3]

int FileMgr::getFd ( std::vector< Fd > & fd) const
override

Definition at line 893 of file FileMgr.cpp.

893 {
894
895 std::transform( std::begin( m_descriptors ), std::end( m_descriptors ), std::back_inserter( fd ), select1st );
896 return m_descriptors.size();
897}

◆ getFileAttr() [1/3]

StatusCode FileMgr::getFileAttr ( const Fd fd,
const FileAttr *& fa ) const
override

Definition at line 738 of file FileMgr.cpp.

738 {
739
740 auto i = std::find_if( std::begin( m_files ), std::end( m_files ),
741 [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
742 if ( i != std::end( m_files ) ) {
743 fa = i->second;
744 return StatusCode::SUCCESS;
745 }
746
747 auto j = std::find_if( std::begin( m_oldFiles ), std::end( m_oldFiles ),
748 [&]( const FileAttr* f ) { return f->fd() == fd; } );
749 if ( j != std::end( m_oldFiles ) ) {
750 fa = *j;
751 return StatusCode::SUCCESS;
752 }
753
754 return StatusCode::FAILURE;
755}

◆ getFileAttr() [2/3]

int FileMgr::getFileAttr ( const std::string & fname,
std::vector< const FileAttr * > & fa ) const
override

Definition at line 723 of file FileMgr.cpp.

723 {
724
725 fa.clear();
726
727 auto fitr = m_files.equal_range( fname );
728 std::transform( fitr.first, fitr.second, std::back_inserter( fa ), select2nd );
729
730 std::copy_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( fa ),
731 [&]( const FileAttr* f ) { return f->name() == fname; } );
732
733 return fa.size();
734}

◆ getFileAttr() [3/3]

StatusCode FileMgr::getFileAttr ( void * vp,
const FileAttr *& fa ) const
override

Definition at line 759 of file FileMgr.cpp.

759 {
760
761 auto i = std::find_if( std::begin( m_files ), std::end( m_files ),
762 [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
763 if ( i != std::end( m_files ) ) {
764 fa = i->second;
765 return StatusCode::SUCCESS;
766 }
767
768 auto j = std::find_if( std::begin( m_oldFiles ), std::end( m_oldFiles ),
769 [&]( const FileAttr* f ) { return f->fptr() == vp; } );
770 if ( j != std::end( m_oldFiles ) ) {
771 fa = *j;
772 return StatusCode::SUCCESS;
773 }
774
775 return StatusCode::FAILURE;
776}

◆ getFiles() [1/6]

int FileMgr::getFiles ( const Io::IoTech & tech,
const Io::IoFlags & flags,
std::vector< const Io::FileAttr * > & files,
bool onlyOpen = true ) const
override

Definition at line 870 of file FileMgr.cpp.

870 {
871
872 files.clear();
873
874 auto matches_tech_and_flags = [&]( const FileAttr* f ) {
875 return ( f->tech() == tech || tech == UNKNOWN ) && f->flags() == flags;
876 };
877
878 transform_copy_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), select2nd,
879 matches_tech_and_flags );
880 if ( !op ) {
881 std::copy_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ),
882 matches_tech_and_flags );
883 }
884
885 return files.size();
886}

◆ getFiles() [2/6]

int FileMgr::getFiles ( const Io::IoTech & tech,
const Io::IoFlags & flags,
std::vector< std::string > & files,
bool onlyOpen = true ) const
override

Definition at line 847 of file FileMgr.cpp.

847 {
848
849 files.clear();
850
851 auto not_in_files = [&]( const std::string& n ) {
852 return std::none_of( std::begin( files ), std::end( files ), [&]( const std::string& f ) { return f == n; } );
853 };
854 auto matches_tech_and_flags = [&]( const FileAttr* f ) {
855 return ( f->tech() == tech || tech == UNKNOWN ) && f->flags() == flags;
856 };
857
858 transform_if(
859 std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), to_name,
860 [&]( fileMap::const_reference f ) { return matches_tech_and_flags( f.second ) && not_in_files( f.first ); } );
861 if ( !op ) {
862 transform_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), to_name,
863 [&]( const FileAttr* f ) { return matches_tech_and_flags( f ) && not_in_files( f->name() ); } );
864 }
865
866 return files.size();
867}

◆ getFiles() [3/6]

int FileMgr::getFiles ( const Io::IoTech & tech,
std::vector< const Io::FileAttr * > & files,
bool onlyOpen = true ) const
override

Definition at line 830 of file FileMgr.cpp.

830 {
831
832 if ( tech == UNKNOWN ) return getFiles( files, op );
833
834 auto matches_tech = [&]( const FileAttr* f ) { return f->tech() == tech; };
835
836 files.clear();
837 transform_copy_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), select2nd, matches_tech );
838 if ( !op ) {
839 std::copy_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), matches_tech );
840 }
841
842 return files.size();
843}
int getFiles(std::vector< std::string > &, bool onlyOpen=true) const override
Definition FileMgr.cpp:780

◆ getFiles() [4/6]

int FileMgr::getFiles ( const Io::IoTech & tech,
std::vector< std::string > & files,
bool onlyOpen = true ) const
override

Definition at line 806 of file FileMgr.cpp.

806 {
807
808 if ( tech == UNKNOWN ) return getFiles( files, op );
809
810 files.clear();
811 transform_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), to_name,
812 [&]( fileMap::const_reference f ) {
813 return f.second->tech() == tech &&
814 std::none_of( std::begin( files ), std::end( files ),
815 [&]( const std::string& j ) { return j == f.first; } );
816 } );
817
818 if ( !op ) {
819 transform_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), to_name,
820 [&]( const FileAttr* f ) {
821 return f->tech() == tech && std::none_of( std::begin( files ), std::end( files ),
822 [&]( const std::string& j ) { return j == f->name(); } );
823 } );
824 }
825 return files.size();
826}

◆ getFiles() [5/6]

int FileMgr::getFiles ( std::vector< const Io::FileAttr * > & files,
bool onlyOpen = true ) const
override

Definition at line 796 of file FileMgr.cpp.

796 {
797
798 files.clear();
799 std::transform( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), select2nd );
800 if ( !op ) { std::copy( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ) ); }
801 return files.size();
802}

◆ getFiles() [6/6]

int FileMgr::getFiles ( std::vector< std::string > & files,
bool onlyOpen = true ) const
override

Definition at line 780 of file FileMgr.cpp.

780 {
781
782 files.clear();
783 auto not_in_files = [&]( const std::string& i ) {
784 return std::none_of( std::begin( files ), std::end( files ), [&]( const std::string& j ) { return j == i; } );
785 };
786 transform_copy_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), to_name, not_in_files );
787 if ( !op ) {
788 transform_copy_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), to_name,
789 not_in_files );
790 }
791 return files.size();
792}

◆ getHandler() [1/2]

StatusCode FileMgr::getHandler ( const IoTech & tech,
Io::FileHdlr & hdlr ) const
override

Definition at line 1005 of file FileMgr.cpp.

1005 {
1006
1007 auto itr = m_handlers.find( tech );
1008 if ( itr == m_handlers.end() ) {
1009 error() << "no handler for tech " << tech << " registered" << endmsg;
1010 return StatusCode::FAILURE;
1011 }
1012 hdlr = itr->second;
1013 return StatusCode::SUCCESS;
1014}

◆ getHandler() [2/2]

StatusCode FileMgr::getHandler ( const std::string & fname,
Io::FileHdlr & hdlr ) const
override

Definition at line 1018 of file FileMgr.cpp.

1018 {
1019
1020 auto fitr = m_files.equal_range( fname );
1021 if ( fitr.first == fitr.second ) {
1022 error() << "no file \"" << fname << "\" registered. Cannot determine tech" << endmsg;
1023 return StatusCode::FAILURE;
1024 }
1025
1026 auto itr = fitr.first;
1027 IoTech tech = itr->second->tech();
1028
1029 ++itr;
1030 while ( itr != fitr.second ) {
1031 if ( itr->second->tech() != tech ) {
1032 error() << "multiple technologies registered for file \"" << fname << "\". Cannot determine handler" << endmsg;
1033 return StatusCode::FAILURE;
1034 }
1035 ++itr;
1036 }
1037
1038 return getHandler( tech, hdlr );
1039}

◆ getLastError()

int FileMgr::getLastError ( std::string & err) const
override

Definition at line 997 of file FileMgr.cpp.

997 {
998
999 err = m_lastErrS;
1000 return m_lastErr;
1001}
std::string m_lastErrS
Definition FileMgr.h:155
int m_lastErr
Definition FileMgr.h:156

◆ handle()

void FileMgr::handle ( const Incident & )
override

Definition at line 182 of file FileMgr.cpp.

182{}

◆ hasHandler()

StatusCode FileMgr::hasHandler ( const IoTech & tech) const
override

Definition at line 234 of file FileMgr.cpp.

234 {
235
236 auto itr = m_handlers.find( tech );
237 return ( itr != m_handlers.end() ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
238}

◆ initialize()

StatusCode FileMgr::initialize ( )
override

Definition at line 71 of file FileMgr.cpp.

71 {
72 StatusCode status = Service::initialize();
73
74 if ( status.isFailure() ) {
75
77 debug() << "Failed to initialize the base class (Service)" << endmsg;
78 return status;
79 }
80
82 verbose() << "Initializing FileMgr" << endmsg;
83
84 if ( m_loadRootHandler.value() ) {
85
86 // setup file handler for ROOT
87
88 msgSvc()->setOutputLevel( "RootFileHandler", m_outputLevel.value() );
89 m_rfh.emplace( msgSvc(), m_ssl_proxy, m_ssl_cert );
90
91 auto& rfh = m_rfh.value(); // used in the lambdas to avoid capturing 'this'
92 Io::FileHdlr hdlr(
94 [&rfh]( const std::string& n, const Io::IoFlags& f, const std::string& desc, Io::Fd& fd,
95 void*& ptr ) -> Io::open_t { return rfh.openRootFile( n, f, desc, fd, ptr ); },
96 [&rfh]( void* ptr ) -> Io::close_t { return rfh.closeRootFile( ptr ); },
97 [&rfh]( void* ptr, const Io::IoFlags& f ) -> Io::reopen_t { return rfh.reopenRootFile( ptr, f ); } );
98
99 if ( regHandler( hdlr ).isFailure() ) { error() << "unable to register ROOT file handler with FileMgr" << endmsg; }
100 }
101
102 if ( m_loadPosixHandler.value() ) {
103
104 // setup file handler for POSIX
105
106 msgSvc()->setOutputLevel( "POSIXFileHandler", m_outputLevel.value() );
107 m_pfh.emplace( msgSvc() );
108
109 auto& pfh = m_pfh.value(); // used in the lambdas to avoid capturing 'this'
110 Io::FileHdlr hdlp(
111 Io::POSIX,
112 [&pfh]( const std::string& n, const Io::IoFlags& f, const std::string& desc, Io::Fd& fd,
113 void*& ptr ) -> Io::open_t { return pfh.openPOSIXFile( n, f, desc, fd, ptr ); },
114 [&pfh]( Io::Fd fd ) -> Io::close_t { return pfh.closePOSIXFile( fd ); },
115 [&pfh]( Io::Fd fd, const Io::IoFlags& f ) -> Io::reopen_t { return pfh.reopenPOSIXFile( fd, f ); } );
116
117 if ( regHandler( hdlp ).isFailure() ) { error() << "unable to register ROOT file handler with FileMgr" << endmsg; }
118 }
119
120 return StatusCode::SUCCESS;
121}
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Gaudi::Property< std::string > m_ssl_cert
Definition FileMgr.h:128
StatusCode regHandler(FileHdlr) override
Definition FileMgr.cpp:186
Gaudi::Property< bool > m_loadPosixHandler
Definition FileMgr.h:125
Gaudi::Property< std::string > m_ssl_proxy
Definition FileMgr.h:127
Gaudi::Property< bool > m_loadRootHandler
Definition FileMgr.h:124
virtual void setOutputLevel(int new_level)=0
Set new global output level threshold.
Gaudi::Property< int > m_outputLevel
flag indicating whether ToolHandle tools have been added to m_tools
Definition Service.h:184
StatusCode initialize() override
Definition Service.cpp:118
bool isFailure() const
Definition StatusCode.h:129
int reopen_t
Definition IFileMgr.h:232
@ ROOT
Definition IFileMgr.h:147
@ POSIX
Definition IFileMgr.h:147
int Fd
Definition IFileMgr.h:158
int open_t
Definition IFileMgr.h:230

◆ isShareable()

bool FileMgr::isShareable ( const std::string & filename,
const Io::IoFlags &  ) const
private

◆ listActions()

void FileMgr::listActions ( ) const
virtual

Definition at line 1072 of file FileMgr.cpp.

1072 {
1073
1074 info() << "listing registered actions\n";
1075
1076 for ( const auto& iit : m_actions ) {
1077 Io::IoTech t = iit.first;
1078 const actionMap& m = iit.second;
1079
1080 if ( !m.empty() ) {
1081 info() << " --- Tech: ";
1082 if ( t == Io::UNKNOWN ) {
1083 info() << "ALL ---\n";
1084 } else {
1085 info() << t << " ---\n";
1086 }
1087 for ( const auto& iia : m ) {
1088 for ( const auto& it2 : iia.second ) { info() << " " << iia.first << " " << it2.second << '\n'; }
1089 }
1090 }
1091 }
1092 info() << endmsg;
1093}
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
std::map< Io::Action, std::list< bfcn_desc_t > > actionMap
Definition FileMgr.h:135

◆ listFiles()

void FileMgr::listFiles ( ) const
override

Definition at line 985 of file FileMgr.cpp.

985 {
986
987 info() << "listing registered files [" << ( m_files.size() + m_oldFiles.size() ) << "]:\n";
988
989 for ( auto& itr : m_files ) info() << itr.second << '\n';
990 for ( auto& it2 : m_oldFiles ) info() << *it2 << '\n';
991
992 info() << endmsg;
993}

◆ listHandlers()

void FileMgr::listHandlers ( ) const
override

Definition at line 1043 of file FileMgr.cpp.

1043 {
1044
1045 info() << "Listing registered handlers:\n";
1046
1047 for ( const auto& itr : m_handlers ) info() << " " << itr.first << '\n';
1048 info() << endmsg;
1049}

◆ listSuppression()

void FileMgr::listSuppression ( ) const
virtual

Definition at line 1170 of file FileMgr.cpp.

1170 {
1171 if ( m_supMap.empty() ) return;
1172
1173 info() << "listing suppressed file actions\n";
1174
1175 for ( const auto& sup : m_supMap ) {
1176 info() << " " << sup.first;
1177 if ( sup.second[Io::INVALID_ACTION] ) {
1178 info() << " ALL\n";
1179 } else {
1180 for ( unsigned i = 0; i != sup.second.size(); ++i ) {
1181 if ( sup.second[i] ) info() << " " << (Io::Action)i;
1182 }
1183 info() << '\n';
1184 }
1185 }
1186 info() << endmsg;
1187}
Action
Definition IFileMgr.h:263

◆ open() [1/4]

open_t FileMgr::open ( const Io::IoTech & tech,
const std::string & caller,
const std::string & fname,
const Io::IoFlags & flags,
Io::Fd & fd,
const std::string & desc = "",
const bool shared = false )
override

Definition at line 249 of file FileMgr.cpp.

250 {
251
252 void* dummy( 0 );
253 return open( tech, caller, fname, desc, flags, fd, dummy, sh );
254}
Io::open_t open(const Io::IoTech &, const std::string &caller, const std::string &fname, const Io::IoFlags &, Io::Fd &fd, void *&ptr, const std::string &desc="", const bool shared=false) override
Definition FileMgr.cpp:242

◆ open() [2/4]

open_t FileMgr::open ( const Io::IoTech & tech,
const std::string & caller,
const std::string & fname,
const Io::IoFlags & flags,
Io::Fd & fd,
void *& ptr,
const std::string & desc = "",
const bool shared = false )
override

Definition at line 242 of file FileMgr.cpp.

243 {
244
245 return open( tech, caller, fname, desc, flags, fd, ptr, sh );
246}

◆ open() [3/4]

open_t FileMgr::open ( const Io::IoTech & tech,
const std::string & caller,
const std::string & fname,
const Io::IoFlags & flags,
void *& ptr,
const std::string & desc = "",
const bool shared = false )
override

Definition at line 257 of file FileMgr.cpp.

258 {
259
260 Fd dummy( -1 );
261 return open( tech, caller, fname, desc, flags, dummy, ptr, sh );
262}

◆ open() [4/4]

open_t FileMgr::open ( const IoTech & tech,
const std::string & caller,
const std::string & fname,
const std::string & desc,
const IoFlags & flags,
Fd & fd,
void *& ptr,
const bool shared )
privatevirtual

Definition at line 266 of file FileMgr.cpp.

267 {
268
269 // return codes: ok == 0, warning > 0, error < 0
270 // 0: ok
271 //
272 // WARNING:
273 // 1: file already open with existing FileAttributes
274 // 2: file already open with different FileAttributes
275 // 3: file opened, but fd and ptr are both invalid
276 //
277 // ERRORS:
278 // -1: no handler for TECH
279 // -2: file already open with different tech
280 // -3: file asked to be opened in shared mode, but other open file
281 // exist that are marked unshared
282 // -4: error calling tech specific open function
283
285 verbose() << "open(" << tech << "," << caller << ",\"" << fname << "\",\"" << desc << "\"," << flags
286 << ( shared ? ",shared" : ",unshared" ) << ")" << endmsg;
287
288 open_t r = -1;
289 FileHdlr fh;
290 if ( getHandler( tech, fh ).isFailure() ) return r;
291
292 auto fitr = m_files.equal_range( fname );
293
294 // make sure all files with same name have same tech
295
296 auto itr =
297 std::find_if( fitr.first, fitr.second, [&]( fileMap::const_reference i ) { return i.second->tech() != tech; } );
298 if ( itr != fitr.second ) {
299 error() << "when calling open on " << fname << " with tech " << tech << ", file already opened with different tech "
300 << itr->second->tech() << endmsg;
301 r = -1;
302 return r;
303 }
304
305 // check for sharing
306
307 if ( shared ) {
308
309 bool shareable( true );
310
311 for ( auto itr = fitr.first; itr != fitr.second; ++itr ) {
312 FileAttr* fa = itr->second;
313
314 if ( !fa->isShared() ) shareable = false;
315
316 // if ( shareable && accessMatch(fa->flags(),flags) )
317 if ( shareable && fa->flags().match( flags, false ) ) {
318
320 debug() << " found shared file: " << *fa << endmsg;
321
322 fd = fa->fd();
323 ptr = fa->fptr();
324 r = 0;
325 }
326 }
327
328 if ( !shareable ) {
329 // at least one of the other files was not marked shared.
330 fd = -1;
331 ptr = 0;
332 r = -1;
333 }
334 }
335
336 if ( r != 0 ) {
337
338 try {
339 r = fh.b_open_fcn( fname, flags, desc, fd, ptr );
340 } catch ( const std::bad_function_call& err ) {
341 error() << "when calling open handler for " << tech << " on file " << fname << " caught " << err.what() << endmsg;
342 return -4;
343 } catch ( ... ) {
344 error() << "when calling open handler for " << tech << " on file " << fname << " caught an unknown exception."
345 << endmsg;
346 return -4;
347 }
348
349 if ( r != 0 ) {
350 warning() << "open of file \"" << fname << "\", tech: \"" << tech << "\", flags: \"" << flags
351 << "\" requested by " << caller << " failed. return code: " << r << endmsg;
352
353 FileAttr xfa( -1, fname, desc, tech, flags, 0, false );
354 execAction( &xfa, caller, Io::OPEN_ERR ).ignore();
355
356 return r;
357 }
358 }
359
360 //@TODO/@FIXME: should this not be pushed into m_attr???
361 // eg. m_attr.emplace_back( new FileAttr(fd,fname,desc,tech,flags,ptr,true,shared) );
362 // FileAttr* fa = m_attr.back().get();
363 FileAttr* fa = new FileAttr( fd, fname, desc, tech, flags, ptr, true, shared );
364
366 debug() << "opened file " << *fa << endmsg;
367
368 if ( fd == -1 && ptr == 0 ) {
369 warning() << "when opening " << *fa << " both File Descriptor"
370 << " and File Ptr are invalid" << endmsg;
371 r = 3;
372 }
373
374 for ( auto itr = fitr.first; itr != fitr.second; ++itr ) {
375 if ( fa->flags() == Io::READ || shared ) {
376 // ok
377 } else if ( *fa == *( itr->second ) ) {
378 warning() << "open call for file \"" << fname << "\" returned a pre-existing file with identical"
379 << " FileAttributes: " << *fa << endmsg;
380 r = 1;
381 } else {
382 warning() << "open call for file \"" << fname << "\" returned a pre-existing file with different"
383 << " FileAttributes -\n"
384 << "old: " << *( itr->second ) << '\n'
385 << "new: " << *fa << endmsg;
386 r = 2;
387 }
388 }
389
390 m_files.emplace( fname, fa );
391
392 // execute all our open callbacks
393 if ( execAction( fa, caller, Io::OPEN ).isFailure() ) {
394 warning() << "at least one open callback action failed" << endmsg;
395 }
396
397 return r;
398}
bool match(const IoFlags &fa, bool strict=true) const
Definition IFileMgr.h:63
@ OPEN
Definition IFileMgr.h:263
@ OPEN_ERR
Definition IFileMgr.h:263
bfcn_open_t b_open_fcn
Definition IFileMgr.h:244

◆ regAction() [1/2]

StatusCode FileMgr::regAction ( Io::bfcn_action_t bf,
const Io::Action & a,
const Io::IoTech & t,
const std::string & desc = "" )
override

Definition at line 1060 of file FileMgr.cpp.

1060 {
1061
1062 ON_DEBUG
1063 debug() << "registering " << a << " action " << System::typeinfoName( bf.target_type() ) << " for tech " << t
1064 << endmsg;
1065
1066 m_actions[t][a].emplace_back( bf, ( !d.empty() ) ? d : System::typeinfoName( bf.target_type() ) );
1067 return StatusCode::SUCCESS;
1068}
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition System.cpp:260

◆ regAction() [2/2]

StatusCode FileMgr::regAction ( Io::bfcn_action_t bf,
const Io::Action & a,
const std::string & desc = "" )
override

Definition at line 1053 of file FileMgr.cpp.

1053 {
1054
1055 return regAction( bf, a, Io::UNKNOWN, d );
1056}
StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &desc="") override
Definition FileMgr.cpp:1053

◆ regHandler()

StatusCode FileMgr::regHandler ( FileHdlr fh)
override

Definition at line 186 of file FileMgr.cpp.

186 {
187
188 IoTech tech = fh.tech;
189
190 if ( m_handlers.find( tech ) != m_handlers.end() ) {
191 warning() << "Handler for IoTech " << tech << " already registered. Ignoring." << endmsg;
192 return StatusCode::SUCCESS;
193 }
194
195 if ( !fh.b_open_fcn ) {
196 error() << "open handler for tech " << tech << " is NULL" << endmsg;
197 return StatusCode::FAILURE;
198 }
199
200 if ( !fh.b_close_fcn && !fh.b_closeP_fcn ) {
201 error() << "no close handler for tech " << tech << " registered" << endmsg;
202 return StatusCode::FAILURE;
203 }
204
205 if ( !fh.b_reopen_fcn && !fh.b_reopenP_fcn ) {
206 error() << "no reopen handler for tech " << tech << " registered" << endmsg;
207 return StatusCode::FAILURE;
208 }
209
211 debug() << "Successfully registered handler for tech \"" << tech << "\"" << endmsg;
212
213 m_handlers[tech] = fh;
214
215 return StatusCode::SUCCESS;
216}
bfcn_reopen_t b_reopen_fcn
Definition IFileMgr.h:247
bfcn_reopenP_t b_reopenP_fcn
Definition IFileMgr.h:248
IoTech tech
Definition IFileMgr.h:242

◆ reopen() [1/2]

reopen_t FileMgr::reopen ( const Fd fd,
const IoFlags & flags,
const std::string & caller )
override

Definition at line 600 of file FileMgr.cpp.

600 {
601
603 verbose() << "reopen(" << fd << "," << flags << "," << caller << ")" << endmsg;
604
605 reopen_t r = -1;
606
607 auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
608 [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
609
610 if ( itr == m_files.end() ) {
611 error() << "unregistered FD \"" << fd << "\" when calling reopen()" << endmsg;
612 return r;
613 }
614
615 FileAttr* fa = itr->second;
616 IoTech tech = fa->tech();
617
618 FileHdlr fh;
619
620 if ( getHandler( tech, fh ).isFailure() ) { return r; }
621
622 fa->flags( flags );
623
624 if ( !fh.b_reopen_fcn ) {
625 error() << "no reopen(" << tech << ",Fd) function registered" << endmsg;
626 return -1;
627 }
628
629 // FIXME: what does it mean to call reopen on a shared file?
630
631 try {
632 r = fh.b_reopen_fcn( fd, flags );
633 } catch ( const std::bad_function_call& err ) {
634 error() << "when calling reopen handler for " << tech << " on file descriptor " << fd << " with flags " << flags
635 << " caught " << err.what() << endmsg;
636 return -1;
637 } catch ( ... ) {
638 error() << "when calling reopen handler for " << tech << " on file descriptor " << fd << " with flags " << flags
639 << " caught an unknown exception." << endmsg;
640 return -1;
641 }
642
643 if ( r < 0 ) {
644 warning() << "reopen of file with FD \"" << fd << "\", name: \"" << fa->name() << "\", tech: \"" << tech
645 << "\", flags: \"" << flags << "\" failed" << endmsg;
646
647 execAction( fa, caller, Io::REOPEN_ERR ).ignore();
648
649 return r;
650 }
651
652 fa->isOpen( true );
653 fa->flags( flags );
654
655 // exec all callbacks
656 if ( execAction( fa, caller, Io::REOPEN ).isFailure() ) {
657 warning() << "at least one reopen callback action failed" << endmsg;
658 }
659
660 return r;
661}
@ REOPEN
Definition IFileMgr.h:263
@ REOPEN_ERR
Definition IFileMgr.h:263

◆ reopen() [2/2]

reopen_t FileMgr::reopen ( void * vp,
const IoFlags & flags,
const std::string & caller )
override

Definition at line 665 of file FileMgr.cpp.

665 {
667 verbose() << "reopen(" << vp << "," << flags << "," << caller << ")" << endmsg;
668
669 reopen_t r = -1;
670
671 auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
672 [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
673 if ( itr == m_files.end() ) {
674 error() << "unregistered file ptr \"" << vp << "\" when calling reopen()" << endmsg;
675 return r;
676 }
677
678 FileAttr* fa = itr->second;
679 FileHdlr fh;
680 IoTech tech = fa->tech();
681
682 if ( getHandler( tech, fh ).isFailure() ) { return r; }
683
684 if ( !fh.b_reopenP_fcn ) {
685 error() << "no reopen(" << tech << ",void*) function registered" << endmsg;
686 return -1;
687 }
688
689 try {
690 r = fh.b_reopenP_fcn( vp, flags );
691 } catch ( const std::bad_function_call& err ) {
692 error() << "when calling reopen handler for " << tech << " on file " << fa->name() << " with flags " << flags
693 << " caught " << err.what() << endmsg;
694 return -1;
695 } catch ( ... ) {
696 error() << "when calling reopen handler for " << tech << " on file " << fa->name() << " with flags " << flags
697 << " caught an unknown exception." << endmsg;
698 return -1;
699 }
700
701 if ( r < 0 ) {
702 warning() << "reopen of file with ptr \"" << vp << "\", name: \"" << fa->name() << "\", tech: \"" << tech
703 << "\", flags: \"" << flags << "\" failed" << endmsg;
704
705 execAction( fa, caller, Io::REOPEN_ERR ).ignore();
706
707 return r;
708 }
709
710 fa->isOpen( true );
711 fa->flags( flags );
712
713 // exec all callbacks
714 if ( execAction( fa, caller, Io::REOPEN ).isFailure() ) {
715 warning() << "at least one reopen callback action failed" << endmsg;
716 }
717
718 return r;
719}

◆ suppressAction() [1/2]

void FileMgr::suppressAction ( const std::string & f)
override

Definition at line 1162 of file FileMgr.cpp.

1162{ return suppressAction( f, Io::INVALID_ACTION ); }
void suppressAction(const std::string &) override
Definition FileMgr.cpp:1162

◆ suppressAction() [2/2]

void FileMgr::suppressAction ( const std::string & f,
const Io::Action & a )
override

Definition at line 1166 of file FileMgr.cpp.

1166{ m_supMap[f].set( a ); }

Member Data Documentation

◆ m_actions

std::map<IoTech, actionMap> FileMgr::m_actions
private

Definition at line 151 of file FileMgr.h.

◆ m_attr

std::vector<std::unique_ptr<FileAttr> > FileMgr::m_attr
private

Definition at line 147 of file FileMgr.h.

◆ m_descriptors

std::map<Fd, FileAttr*> FileMgr::m_descriptors
private

Definition at line 146 of file FileMgr.h.

◆ m_files

fileMap FileMgr::m_files
private

Definition at line 144 of file FileMgr.h.

◆ m_handlers

std::map<IoTech, FileHdlr> FileMgr::m_handlers
private

Definition at line 145 of file FileMgr.h.

◆ m_lastErr

int FileMgr::m_lastErr
private

Definition at line 156 of file FileMgr.h.

◆ m_lastErrS

std::string FileMgr::m_lastErrS
private

Definition at line 155 of file FileMgr.h.

◆ m_loadPosixHandler

Gaudi::Property<bool> FileMgr::m_loadPosixHandler { this, "LoadPOSIXHandler", true }
private

Definition at line 125 of file FileMgr.h.

125{ this, "LoadPOSIXHandler", true };

◆ m_loadRootHandler

Gaudi::Property<bool> FileMgr::m_loadRootHandler { this, "LoadROOTHandler", true }
private

Definition at line 124 of file FileMgr.h.

124{ this, "LoadROOTHandler", true };

◆ m_logfile

Gaudi::Property<std::string> FileMgr::m_logfile { this, "LogFile" }
private

Definition at line 122 of file FileMgr.h.

122{ this, "LogFile" };

◆ m_oldFiles

std::vector<FileAttr*> FileMgr::m_oldFiles
private

Definition at line 149 of file FileMgr.h.

◆ m_pfh

std::optional<POSIXFileHandler> FileMgr::m_pfh
private

Definition at line 159 of file FileMgr.h.

◆ m_printSummary

Gaudi::Property<bool> FileMgr::m_printSummary { this, "PrintSummary", false }
private

Definition at line 123 of file FileMgr.h.

123{ this, "PrintSummary", false };

◆ m_rfh

std::optional<RootFileHandler> FileMgr::m_rfh
private

Definition at line 158 of file FileMgr.h.

◆ m_ssl_cert

Gaudi::Property<std::string> FileMgr::m_ssl_cert { this, "TSSL_CertDir", "X509" }
private

Definition at line 128 of file FileMgr.h.

128{ this, "TSSL_CertDir", "X509" };

◆ m_ssl_proxy

Gaudi::Property<std::string> FileMgr::m_ssl_proxy { this, "TSSL_UserProxy", "X509" }
private

Definition at line 127 of file FileMgr.h.

127{ this, "TSSL_UserProxy", "X509" };

◆ m_supMap

std::map<std::string, Io::Action_bitmap> FileMgr::m_supMap
private

Definition at line 153 of file FileMgr.h.


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