The Gaudi Framework  v33r0 (d5ea422b)
FileMgr Class Reference

#include <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::stringfname (const Io::Fd &) const override
 
const std::stringfname (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 * 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...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. 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 >
StatusCode declareTool (ToolHandle< T > &handle, std::string toolTypeAndName, bool createIf=true)
 Declare used tool. More...
 
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 Gaudi::Details::PropertyBase &p) override
 set the property form another property More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 set the property from name and the value More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (const std::string &name) const override
 get the property by name More...
 
StatusCode getProperty (const std::string &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 (const std::string &name) const override
 Return true if we have a property with the given name. More...
 
 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...
 
MSG::Level outputLevel () const
 Backward compatibility function for getting the output level. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 

Private Types

typedef std::pair< Io::bfcn_action_t, std::stringbfcn_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::stringm_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::stringm_ssl_proxy {this, "TSSL_UserProxy", "X509"}
 
Gaudi::Property< std::stringm_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 = 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
 ~Service () override
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
Gaudi::Details::PropertyBaseproperty (const std::string &name) const
 
- 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"}
 
Gaudi::Property< bool > m_auditInit {this, "AuditServices", false, " 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()"}
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service. More...
 

Detailed Description

Definition at line 45 of file FileMgr.h.

Member Typedef Documentation

◆ actionMap

Definition at line 136 of file FileMgr.h.

◆ bfcn_desc_t

Definition at line 135 of file FileMgr.h.

◆ fileMap

Definition at line 143 of file FileMgr.h.

Constructor & Destructor Documentation

◆ ~FileMgr()

FileMgr::~FileMgr ( )
override

Definition at line 64 of file FileMgr.cpp.

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

Member Function Documentation

◆ accessMatch()

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

Definition at line 1152 of file FileMgr.cpp.

1152  {
1153  ON_VERBOSE
1154  verbose() << "accessMatch old: " << fold << " new: " << fnew << endmsg;
1155 
1156  return ( ( ( fold == Io::READ ) && ( fnew == Io::READ ) ) ||
1157  ( ( fold & Io::WRITE ) != 0 && ( fnew & Io::WRITE ) != 0 ) ||
1158  ( ( fold & Io::RDWR ) != 0 && ( fnew & Io::RDWR ) != 0 ) );
1159 }
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
#define ON_VERBOSE
Definition: FileMgr.cpp:19
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ close() [1/2]

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

◆ close() [2/2]

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

Definition at line 502 of file FileMgr.cpp.

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

◆ deregHandler()

StatusCode FileMgr::deregHandler ( const IoTech )
override

Definition at line 221 of file FileMgr.cpp.

221  {
222  FileHdlr hdlr;
223 
224  auto itr = m_handlers.find( tech );
225  if ( itr == m_handlers.end() ) {
226  error() << "Can't de-register tech " << tech << " as it hasn't been registered!" << endmsg;
227  return StatusCode::FAILURE;
228  }
229 
230  m_handlers.erase( itr );
231  return StatusCode::SUCCESS;
232 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T end(T... args)
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:146
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T erase(T... args)
T find(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ execAction()

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

Definition at line 1098 of file FileMgr.cpp.

1098  {
1099 
1100  Io::IoTech tech = fa->tech();
1101 
1102  StatusCode s1, s2;
1103 
1104  auto itr = m_actions.find( Io::UNKNOWN );
1105 
1106  if ( itr != m_actions.end() && !itr->second.empty() ) { s1 = execActs( fa, caller, a, itr->second ); }
1107 
1108  itr = m_actions.find( tech );
1109  if ( itr != m_actions.end() && !itr->second.empty() ) { s2 = execActs( fa, caller, a, itr->second ); }
1110 
1111  return ( s1.isFailure() || s2.isFailure() ) ? StatusCode::FAILURE : StatusCode::SUCCESS;
1112 }
IoTech
Definition: IFileMgr.h:156
StatusCode execActs(Io::FileAttr *, const std::string &, const Io::Action &, const actionMap &m) const
Definition: FileMgr.cpp:1116
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
IoTech tech() const
Definition: IFileMgr.h:188
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
constexpr static const auto FAILURE
Definition: StatusCode.h:97
std::map< IoTech, actionMap > m_actions
Definition: FileMgr.h:152
bool isFailure() const
Definition: StatusCode.h:141

◆ execActs()

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

Definition at line 1116 of file FileMgr.cpp.

1117  {
1118 
1119  auto mitr = m.find( a );
1120  if ( mitr == m.end() || mitr->second.empty() ) return StatusCode::SUCCESS;
1121 
1122  ON_DEBUG
1123  debug() << "executing " << mitr->second.size() << " " << a << " actions on " << *fa << " from " << caller << endmsg;
1124 
1125  bool fail( false );
1126 
1127  auto it2 = m_supMap.find( fa->name() );
1128  if ( it2 != m_supMap.end() ) {
1129  if ( it2->second[a] || it2->second[Io::INVALID_ACTION] ) {
1130  ON_DEBUG
1131  debug() << " --> suppressing callback action for " << a << endmsg;
1132  return StatusCode::SUCCESS;
1133  }
1134  }
1135 
1136  for ( const auto& itr : mitr->second ) {
1137 
1138  ON_DEBUG
1139  debug() << "executing " << itr.second << endmsg;
1140 
1141  if ( ( ( ( itr.first ) )( fa, caller ) ).isFailure() ) {
1142  warning() << "execution of " << itr.second << " on " << *fa << " failed during " << a << " action" << endmsg;
1143  fail = true;
1144  }
1145  }
1146 
1147  return fail ? StatusCode::FAILURE : StatusCode::SUCCESS;
1148 }
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
std::map< std::string, Io::Action_bitmap > m_supMap
Definition: FileMgr.h:154
const std::string & name() const
Definition: IFileMgr.h:186
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
constexpr double m
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
constexpr static const auto FAILURE
Definition: StatusCode.h:97
#define ON_DEBUG
Definition: FileMgr.cpp:18
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ fd() [1/2]

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

Definition at line 950 of file FileMgr.cpp.

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

◆ fd() [2/2]

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

Definition at line 959 of file FileMgr.cpp.

959  {
960 
961  auto itr = std::find_if( m_files.begin(), m_files.end(),
962  [&]( fileMap::const_reference f ) { return f.second->fptr() == fptr; } );
963  return itr != m_files.end() ? itr->second->fd() : -1;
964 }
fileMap m_files
Definition: FileMgr.h:145
void * fptr() const
Definition: IFileMgr.h:191
T end(T... args)
Fd fd() const
Definition: IFileMgr.h:185
T find_if(T... args)
T begin(T... args)
void * fptr(const std::string &) const override
Definition: FileMgr.cpp:968

◆ finalize()

StatusCode FileMgr::finalize ( )
override

Definition at line 126 of file FileMgr.cpp.

126  {
127  ON_VERBOSE
128  verbose() << "FileMgr::finalize()" << endmsg;
129 
130  if ( m_printSummary || msgLevel( MSG::DEBUG ) ) {
131  listHandlers();
132  listFiles();
133  listActions();
134  listSuppression();
135  }
136 
137  if ( !m_files.empty() ) {
138  auto& log = warning();
139  log << "At finalize, the following files remained open:\n";
140  for ( const auto& itr : m_files ) log << *( itr.second ) << '\n';
141  log << endmsg;
142  }
143 
144  if ( m_logfile.value() != "" ) {
145  std::ofstream ofs;
146  ofs.open( m_logfile.value().c_str() );
147  if ( !ofs ) {
148  error() << "Unable to open output file \"" << m_logfile.value() << "\" for writing" << endmsg;
149  } else {
150  ON_DEBUG
151  debug() << "Saving log to \"" << m_logfile.value() << "\"" << endmsg;
152  for ( const auto& itr : m_files ) {
153  ofs << itr.second->name() << " " << itr.second->tech() << " " << itr.second->desc() << " "
154  << itr.second->iflags() << '\n';
155  }
156 
157  set<FileAttr> fs;
158  for ( const auto& it2 : m_oldFiles ) fs.insert( *it2 );
159  for ( const auto& it3 : fs ) {
160  ofs << it3.name() << " " << it3.tech() << " " << it3.desc() << " " << it3.iflags()
161  << ( it3.isShared() ? " SHARED" : "" ) << '\n';
162  }
163  ofs.close();
164  }
165  }
166 
167  // cleanup FileAttrs
168  m_attr.clear();
169 
170  m_rfh.reset();
171  m_pfh.reset();
172 
173  StatusCode status = Service::finalize();
174 
175  ON_DEBUG
176  if ( status.isSuccess() ) debug() << "Service finalised successfully" << endmsg;
177 
178  return status;
179 }
std::vector< std::unique_ptr< FileAttr > > m_attr
Definition: FileMgr.h:148
std::optional< POSIXFileHandler > m_pfh
Definition: FileMgr.h:160
T empty(T... args)
T open(T... args)
StatusCode finalize() override
Definition: Service.cpp:174
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
fileMap m_files
Definition: FileMgr.h:145
virtual void listSuppression() const
Definition: FileMgr.cpp:1171
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
T close(T... args)
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
virtual void listActions() const
Definition: FileMgr.cpp:1073
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T clear(T... args)
bool isSuccess() const
Definition: StatusCode.h:361
T insert(T... args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:150
STL class.
std::optional< RootFileHandler > m_rfh
Definition: FileMgr.h:159
Gaudi::Property< bool > m_printSummary
Definition: FileMgr.h:124
#define ON_DEBUG
Definition: FileMgr.cpp:18
void listFiles() const override
Definition: FileMgr.cpp:986
Gaudi::Property< std::string > m_logfile
Definition: FileMgr.h:123
void listHandlers() const override
Definition: FileMgr.cpp:1044
#define ON_VERBOSE
Definition: FileMgr.cpp:19
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ fname() [1/2]

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

Definition at line 932 of file FileMgr.cpp.

932  {
933 
934  auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
935  [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
936  return ( itr != std::end( m_files ) ) ? itr->second->name() : s_empty;
937 }
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:950
fileMap m_files
Definition: FileMgr.h:145
T end(T... args)
T find_if(T... args)
T begin(T... args)

◆ fname() [2/2]

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

Definition at line 941 of file FileMgr.cpp.

941  {
942 
943  auto itr = std::find_if( m_files.begin(), m_files.end(),
944  [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
945  return itr != m_files.end() ? itr->second->name() : s_empty;
946 }
fileMap m_files
Definition: FileMgr.h:145
const std::string & name() const
Definition: IFileMgr.h:186
void * fptr() const
Definition: IFileMgr.h:191
T end(T... args)
T find_if(T... args)
T begin(T... args)

◆ fptr() [1/2]

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

Definition at line 968 of file FileMgr.cpp.

968  {
969  auto fitr = m_files.equal_range( fname );
970  auto itr =
971  std::find_if( fitr.first, fitr.second, []( fileMap::const_reference f ) -> bool { return f.second->fptr(); } );
972  return itr != fitr.second ? itr->second->fptr() : nullptr;
973 }
fileMap m_files
Definition: FileMgr.h:145
T find_if(T... args)
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:932
T equal_range(T... args)

◆ fptr() [2/2]

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

Definition at line 977 of file FileMgr.cpp.

977  {
978 
979  auto itr = std::find_if( m_files.begin(), m_files.end(),
980  [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
981  return itr != m_files.end() ? itr->second->fptr() : nullptr;
982 }
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:950
fileMap m_files
Definition: FileMgr.h:145
void * fptr() const
Definition: IFileMgr.h:191
T end(T... args)
Fd fd() const
Definition: IFileMgr.h:185
T find_if(T... args)
T begin(T... args)

◆ getFd() [1/3]

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

◆ getFd() [2/3]

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

Definition at line 905 of file FileMgr.cpp.

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

◆ getFd() [3/3]

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

Definition at line 920 of file FileMgr.cpp.

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

◆ getFileAttr() [1/3]

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

Definition at line 724 of file FileMgr.cpp.

724  {
725 
726  fa.clear();
727 
728  auto fitr = m_files.equal_range( fname );
729  std::transform( fitr.first, fitr.second, std::back_inserter( fa ), select2nd );
730 
732  [&]( const FileAttr* f ) { return f->name() == fname; } );
733 
734  return fa.size();
735 }
T copy_if(T... args)
fileMap m_files
Definition: FileMgr.h:145
const std::string & name() const
Definition: IFileMgr.h:186
T end(T... args)
T clear(T... args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:150
T size(T... args)
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:932
T begin(T... args)
T back_inserter(T... args)
T transform(T... args)
T equal_range(T... args)

◆ getFileAttr() [2/3]

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

◆ getFileAttr() [3/3]

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

Definition at line 760 of file FileMgr.cpp.

760  {
761 
763  [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
764  if ( i != std::end( m_files ) ) {
765  fa = i->second;
766  return StatusCode::SUCCESS;
767  }
768 
770  [&]( const FileAttr* f ) { return f->fptr() == vp; } );
771  if ( j != std::end( m_oldFiles ) ) {
772  fa = *j;
773  return StatusCode::SUCCESS;
774  }
775 
776  return StatusCode::FAILURE;
777 }
fileMap m_files
Definition: FileMgr.h:145
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
void * fptr() const
Definition: IFileMgr.h:191
T end(T... args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:150
T find_if(T... args)
T begin(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ getFiles() [1/6]

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

Definition at line 781 of file FileMgr.cpp.

781  {
782 
783  files.clear();
784  auto not_in_files = [&]( const std::string& i ) {
785  return std::none_of( std::begin( files ), std::end( files ), [&]( const std::string& j ) { return j == i; } );
786  };
787  transform_copy_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), to_name, not_in_files );
788  if ( !op ) {
789  transform_copy_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), to_name,
790  not_in_files );
791  }
792  return files.size();
793 }
fileMap m_files
Definition: FileMgr.h:145
T end(T... args)
STL class.
T clear(T... args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:150
T size(T... args)
T begin(T... args)
T back_inserter(T... args)
T none_of(T... args)

◆ getFiles() [2/6]

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

Definition at line 797 of file FileMgr.cpp.

797  {
798 
799  files.clear();
800  std::transform( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), select2nd );
801  if ( !op ) { std::copy( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ) ); }
802  return files.size();
803 }
T copy(T... args)
fileMap m_files
Definition: FileMgr.h:145
T end(T... args)
T clear(T... args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:150
T size(T... args)
T begin(T... args)
T back_inserter(T... args)
T transform(T... args)

◆ getFiles() [3/6]

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

Definition at line 807 of file FileMgr.cpp.

807  {
808 
809  if ( tech == UNKNOWN ) return getFiles( files, op );
810 
811  files.clear();
812  transform_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), to_name,
813  [&]( fileMap::const_reference f ) {
814  return f.second->tech() == tech &&
815  std::none_of( std::begin( files ), std::end( files ),
816  [&]( const std::string& j ) { return j == f.first; } );
817  } );
818 
819  if ( !op ) {
820  transform_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), to_name,
821  [&]( const FileAttr* f ) {
822  return f->tech() == tech && std::none_of( std::begin( files ), std::end( files ),
823  [&]( const std::string& j ) { return j == f->name(); } );
824  } );
825  }
826  return files.size();
827 }
fileMap m_files
Definition: FileMgr.h:145
const std::string & name() const
Definition: IFileMgr.h:186
IoTech tech() const
Definition: IFileMgr.h:188
T end(T... args)
STL class.
T clear(T... args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:150
T size(T... args)
T begin(T... args)
T back_inserter(T... args)
T none_of(T... args)
int getFiles(std::vector< std::string > &, bool onlyOpen=true) const override
Definition: FileMgr.cpp:781

◆ getFiles() [4/6]

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

Definition at line 831 of file FileMgr.cpp.

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

◆ getFiles() [5/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 848 of file FileMgr.cpp.

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

◆ getFiles() [6/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 871 of file FileMgr.cpp.

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

◆ getHandler() [1/2]

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

◆ getHandler() [2/2]

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

Definition at line 1019 of file FileMgr.cpp.

1019  {
1020 
1021  auto fitr = m_files.equal_range( fname );
1022  if ( fitr.first == fitr.second ) {
1023  error() << "no file \"" << fname << "\" registered. Cannot determine tech" << endmsg;
1024  return StatusCode::FAILURE;
1025  }
1026 
1027  auto itr = fitr.first;
1028  IoTech tech = itr->second->tech();
1029 
1030  ++itr;
1031  while ( itr != fitr.second ) {
1032  if ( itr->second->tech() != tech ) {
1033  error() << "multiple technologies registered for file \"" << fname << "\". Cannot determine handler" << endmsg;
1034  return StatusCode::FAILURE;
1035  }
1036  ++itr;
1037  }
1038 
1039  return getHandler( tech, hdlr );
1040 }
StatusCode getHandler(const IoTech &, FileHdlr &) const override
IoTech
Definition: IFileMgr.h:156
fileMap m_files
Definition: FileMgr.h:145
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:932
constexpr static const auto FAILURE
Definition: StatusCode.h:97
T equal_range(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ getLastError()

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

Definition at line 998 of file FileMgr.cpp.

998  {
999 
1000  err = m_lastErrS;
1001  return m_lastErr;
1002 }
std::string m_lastErrS
Definition: FileMgr.h:156
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
int m_lastErr
Definition: FileMgr.h:157

◆ handle()

void FileMgr::handle ( const Incident )
override

Definition at line 183 of file FileMgr.cpp.

183 {}

◆ hasHandler()

StatusCode FileMgr::hasHandler ( const IoTech ) const
override

Definition at line 235 of file FileMgr.cpp.

235  {
236 
237  auto itr = m_handlers.find( tech );
238  return ( itr != m_handlers.end() ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
239 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T end(T... args)
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:146
T find(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97

◆ initialize()

StatusCode FileMgr::initialize ( )
override

Definition at line 72 of file FileMgr.cpp.

72  {
74 
75  if ( status.isFailure() ) {
76 
77  ON_DEBUG
78  debug() << "Failed to initialize the base class (Service)" << endmsg;
79  return status;
80  }
81 
83  verbose() << "Initializing FileMgr" << endmsg;
84 
85  if ( m_loadRootHandler.value() ) {
86 
87  // setup file handler for ROOT
88 
89  msgSvc()->setOutputLevel( "RootFileHandler", m_outputLevel.value() );
90  m_rfh.emplace( msgSvc(), m_ssl_proxy, m_ssl_cert );
91 
92  auto& rfh = m_rfh.value(); // used in the lambdas to avoid capturing 'this'
93  Io::FileHdlr hdlr(
94  Io::ROOT,
95  [&rfh]( const std::string& n, const Io::IoFlags& f, const std::string& desc, Io::Fd& fd,
96  void*& ptr ) -> Io::open_t { return rfh.openRootFile( n, f, desc, fd, ptr ); },
97  [&rfh]( void* ptr ) -> Io::close_t { return rfh.closeRootFile( ptr ); },
98  [&rfh]( void* ptr, const Io::IoFlags& f ) -> Io::reopen_t { return rfh.reopenRootFile( ptr, f ); } );
99 
100  if ( regHandler( hdlr ).isFailure() ) { error() << "unable to register ROOT file handler with FileMgr" << endmsg; }
101  }
102 
103  if ( m_loadPosixHandler.value() ) {
104 
105  // setup file handler for POSIX
106 
107  msgSvc()->setOutputLevel( "POSIXFileHandler", m_outputLevel.value() );
108  m_pfh.emplace( msgSvc() );
109 
110  auto& pfh = m_pfh.value(); // used in the lambdas to avoid capturing 'this'
111  Io::FileHdlr hdlp(
112  Io::POSIX,
113  [&pfh]( const std::string& n, const Io::IoFlags& f, const std::string& desc, Io::Fd& fd,
114  void*& ptr ) -> Io::open_t { return pfh.openPOSIXFile( n, f, desc, fd, ptr ); },
115  [&pfh]( Io::Fd fd ) -> Io::close_t { return pfh.closePOSIXFile( fd ); },
116  [&pfh]( Io::Fd fd, const Io::IoFlags& f ) -> Io::reopen_t { return pfh.reopenPOSIXFile( fd, f ); } );
117 
118  if ( regHandler( hdlp ).isFailure() ) { error() << "unable to register ROOT file handler with FileMgr" << endmsg; }
119  }
120 
121  return StatusCode::SUCCESS;
122 }
Gaudi::Property< int > m_outputLevel
Definition: Service.h:186
StatusCode regHandler(FileHdlr) override
Definition: FileMgr.cpp:187
std::optional< POSIXFileHandler > m_pfh
Definition: FileMgr.h:160
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:950
StatusCode initialize() override
Definition: Service.cpp:70
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
int reopen_t
Definition: IFileMgr.h:245
int Fd
Definition: IFileMgr.h:169
Gaudi::Property< bool > m_loadPosixHandler
Definition: FileMgr.h:126
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
int open_t
Definition: IFileMgr.h:243
STL class.
Gaudi::Property< bool > m_loadRootHandler
Definition: FileMgr.h:125
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
std::optional< RootFileHandler > m_rfh
Definition: FileMgr.h:159
Gaudi::Property< std::string > m_ssl_proxy
Definition: FileMgr.h:128
bool isFailure() const
Definition: StatusCode.h:141
#define ON_DEBUG
Definition: FileMgr.cpp:18
#define ON_VERBOSE
Definition: FileMgr.cpp:19
Gaudi::Property< std::string > m_ssl_cert
Definition: FileMgr.h:129
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
int close_t
Definition: IFileMgr.h:244
virtual void setOutputLevel(int new_level)=0
Set new global output level threshold.

◆ isShareable()

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

◆ listActions()

void FileMgr::listActions ( ) const
virtual

Definition at line 1073 of file FileMgr.cpp.

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

◆ listFiles()

void FileMgr::listFiles ( ) const
override

Definition at line 986 of file FileMgr.cpp.

986  {
987 
988  info() << "listing registered files [" << ( m_files.size() + m_oldFiles.size() ) << "]:\n";
989 
990  for ( auto& itr : m_files ) info() << itr.second << '\n';
991  for ( auto& it2 : m_oldFiles ) info() << *it2 << '\n';
992 
993  info() << endmsg;
994 }
fileMap m_files
Definition: FileMgr.h:145
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:150
T size(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ listHandlers()

void FileMgr::listHandlers ( ) const
override

Definition at line 1044 of file FileMgr.cpp.

1044  {
1045 
1046  info() << "Listing registered handlers:\n";
1047 
1048  for ( const auto& itr : m_handlers ) info() << " " << itr.first << '\n';
1049  info() << endmsg;
1050 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:146
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ listSuppression()

void FileMgr::listSuppression ( ) const
virtual

Definition at line 1171 of file FileMgr.cpp.

1171  {
1172  if ( m_supMap.empty() ) return;
1173 
1174  info() << "listing suppressed file actions\n";
1175 
1176  for ( const auto& sup : m_supMap ) {
1177  info() << " " << sup.first;
1178  if ( sup.second[Io::INVALID_ACTION] ) {
1179  info() << " ALL\n";
1180  } else {
1181  for ( unsigned i = 0; i != sup.second.size(); ++i ) {
1182  if ( sup.second[i] ) info() << " " << (Io::Action)i;
1183  }
1184  info() << '\n';
1185  }
1186  }
1187  info() << endmsg;
1188 }
std::map< std::string, Io::Action_bitmap > m_supMap
Definition: FileMgr.h:154
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Action
Definition: IFileMgr.h:278
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ 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,
void *&  ptr,
const std::string desc = "",
const bool  shared = false 
)
override

Definition at line 243 of file FileMgr.cpp.

244  {
245 
246  return open( tech, caller, fname, desc, flags, fd, ptr, sh );
247 }
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:950
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:243
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:932

◆ 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,
const std::string desc = "",
const bool  shared = false 
)
override

Definition at line 250 of file FileMgr.cpp.

251  {
252 
253  void* dummy( 0 );
254  return open( tech, caller, fname, desc, flags, fd, dummy, sh );
255 }
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:950
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:243
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:932

◆ 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 258 of file FileMgr.cpp.

259  {
260 
261  Fd dummy( -1 );
262  return open( tech, caller, fname, desc, flags, dummy, ptr, sh );
263 }
int Fd
Definition: IFileMgr.h:169
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:243
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:932

◆ open() [4/4]

virtual Io::open_t FileMgr::open ( const IoTech &  ,
const std::string caller,
const std::string fname,
const std::string desc,
const IoFlags ,
Fd &  ,
void *&  ,
const bool  shared 
)
privatevirtual

◆ regAction() [1/2]

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

Definition at line 1054 of file FileMgr.cpp.

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

◆ regAction() [2/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 1061 of file FileMgr.cpp.

1061  {
1062 
1063  ON_DEBUG
1064  debug() << "registering " << a << " action " << System::typeinfoName( bf.target_type() ) << " for tech " << t
1065  << endmsg;
1066 
1067  m_actions[t][a].emplace_back( bf, ( !d.empty() ) ? d : System::typeinfoName( bf.target_type() ) );
1068  return StatusCode::SUCCESS;
1069 }
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:308
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T target_type(T... args)
std::map< IoTech, actionMap > m_actions
Definition: FileMgr.h:152
#define ON_DEBUG
Definition: FileMgr.cpp:18
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ regHandler()

StatusCode FileMgr::regHandler ( FileHdlr  fh)
override

Definition at line 187 of file FileMgr.cpp.

187  {
188 
189  IoTech tech = fh.tech;
190 
191  if ( m_handlers.find( tech ) != m_handlers.end() ) {
192  warning() << "Handler for IoTech " << tech << " already registered. Ignoring." << endmsg;
193  return StatusCode::SUCCESS;
194  }
195 
196  if ( !fh.b_open_fcn ) {
197  error() << "open handler for tech " << tech << " is NULL" << endmsg;
198  return StatusCode::FAILURE;
199  }
200 
201  if ( !fh.b_close_fcn && !fh.b_closeP_fcn ) {
202  error() << "no close handler for tech " << tech << " registered" << endmsg;
203  return StatusCode::FAILURE;
204  }
205 
206  if ( !fh.b_reopen_fcn && !fh.b_reopenP_fcn ) {
207  error() << "no reopen handler for tech " << tech << " registered" << endmsg;
208  return StatusCode::FAILURE;
209  }
210 
211  ON_DEBUG
212  debug() << "Successfully registered handler for tech \"" << tech << "\"" << endmsg;
213 
214  m_handlers[tech] = fh;
215 
216  return StatusCode::SUCCESS;
217 }
IoTech
Definition: IFileMgr.h:156
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
bfcn_reopen_t b_reopen_fcn
Definition: IFileMgr.h:260
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
T end(T... args)
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:146
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
bfcn_close_t b_close_fcn
Definition: IFileMgr.h:258
bfcn_closeP_t b_closeP_fcn
Definition: IFileMgr.h:259
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
bfcn_reopenP_t b_reopenP_fcn
Definition: IFileMgr.h:261
T find(T... args)
bfcn_open_t b_open_fcn
Definition: IFileMgr.h:257
constexpr static const auto FAILURE
Definition: StatusCode.h:97
#define ON_DEBUG
Definition: FileMgr.cpp:18
IoTech tech
Definition: IFileMgr.h:255
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ reopen() [1/2]

Io::reopen_t FileMgr::reopen ( const  Fd,
const IoFlags ,
const std::string caller 
)
override

◆ reopen() [2/2]

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

Definition at line 666 of file FileMgr.cpp.

666  {
667  ON_VERBOSE
668  verbose() << "reopen(" << vp << "," << flags << "," << caller << ")" << endmsg;
669 
670  reopen_t r = -1;
671 
672  auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
673  [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
674  if ( itr == m_files.end() ) {
675  error() << "unregistered file ptr \"" << vp << "\" when calling reopen()" << endmsg;
676  return r;
677  }
678 
679  FileAttr* fa = itr->second;
680  FileHdlr fh;
681  IoTech tech = fa->tech();
682 
683  if ( getHandler( tech, fh ).isFailure() ) { return r; }
684 
685  if ( !fh.b_reopenP_fcn ) {
686  error() << "no reopen(" << tech << ",void*) function registered" << endmsg;
687  return -1;
688  }
689 
690  try {
691  r = fh.b_reopenP_fcn( vp, flags );
692  } catch ( const std::bad_function_call& err ) {
693  error() << "when calling reopen handler for " << tech << " on file " << fa->name() << " with flags " << flags
694  << " caught " << err.what() << endmsg;
695  return -1;
696  } catch ( ... ) {
697  error() << "when calling reopen handler for " << tech << " on file " << fa->name() << " with flags " << flags
698  << " caught an unknown exception." << endmsg;
699  return -1;
700  }
701 
702  if ( r < 0 ) {
703  warning() << "reopen of file with ptr \"" << vp << "\", name: \"" << fa->name() << "\", tech: \"" << tech
704  << "\", flags: \"" << flags << "\" failed" << endmsg;
705 
706  execAction( fa, caller, Io::REOPEN_ERR ).ignore();
707 
708  return r;
709  }
710 
711  fa->isOpen( true );
712  fa->flags( flags );
713 
714  // exec all callbacks
715  if ( execAction( fa, caller, Io::REOPEN ).isFailure() ) {
716  warning() << "at least one reopen callback action failed" << endmsg;
717  }
718 
719  return r;
720 }
StatusCode getHandler(const IoTech &, FileHdlr &) const override
IoTech
Definition: IFileMgr.h:156
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
int reopen_t
Definition: IFileMgr.h:245
fileMap m_files
Definition: FileMgr.h:145
const std::string & name() const
Definition: IFileMgr.h:186
IoTech tech() const
Definition: IFileMgr.h:188
T end(T... args)
IoFlags flags() const
Definition: IFileMgr.h:189
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
StatusCode execAction(Io::FileAttr *, const std::string &, const Io::Action &) const
Definition: FileMgr.cpp:1098
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
bfcn_reopenP_t b_reopenP_fcn
Definition: IFileMgr.h:261
bool isOpen() const
Definition: IFileMgr.h:192
T find_if(T... args)
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:164
T begin(T... args)
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
#define ON_VERBOSE
Definition: FileMgr.cpp:19
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202

◆ suppressAction() [1/2]

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

Definition at line 1163 of file FileMgr.cpp.

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

◆ suppressAction() [2/2]

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

Definition at line 1167 of file FileMgr.cpp.

1167 { m_supMap[f].set( a ); }
std::map< std::string, Io::Action_bitmap > m_supMap
Definition: FileMgr.h:154

Member Data Documentation

◆ m_actions

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

Definition at line 152 of file FileMgr.h.

◆ m_attr

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

Definition at line 148 of file FileMgr.h.

◆ m_descriptors

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

Definition at line 147 of file FileMgr.h.

◆ m_files

fileMap FileMgr::m_files
private

Definition at line 145 of file FileMgr.h.

◆ m_handlers

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

Definition at line 146 of file FileMgr.h.

◆ m_lastErr

int FileMgr::m_lastErr
private

Definition at line 157 of file FileMgr.h.

◆ m_lastErrS

std::string FileMgr::m_lastErrS
private

Definition at line 156 of file FileMgr.h.

◆ m_loadPosixHandler

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

Definition at line 126 of file FileMgr.h.

◆ m_loadRootHandler

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

Definition at line 125 of file FileMgr.h.

◆ m_logfile

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

Definition at line 123 of file FileMgr.h.

◆ m_oldFiles

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

Definition at line 150 of file FileMgr.h.

◆ m_pfh

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

Definition at line 160 of file FileMgr.h.

◆ m_printSummary

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

Definition at line 124 of file FileMgr.h.

◆ m_rfh

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

Definition at line 159 of file FileMgr.h.

◆ m_ssl_cert

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

Definition at line 129 of file FileMgr.h.

◆ m_ssl_proxy

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

Definition at line 128 of file FileMgr.h.

◆ m_supMap

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

Definition at line 154 of file FileMgr.h.


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