The Gaudi Framework  v30r3 (a5ef0a68)
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
 
boost::optional< RootFileHandlerm_rfh
 
boost::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, "[[deprecated]] unused"}
 
Gaudi::Property< bool > m_auditorInitialize {this, "AuditInitialize", false, "trigger auditor on initialize()"}
 
Gaudi::Property< bool > m_auditorStart {this, "AuditStart", false, "trigger auditor on start()"}
 
Gaudi::Property< bool > m_auditorStop {this, "AuditStop", false, "trigger auditor on stop()"}
 
Gaudi::Property< bool > m_auditorFinalize {this, "AuditFinalize", false, "trigger auditor on finalize()"}
 
Gaudi::Property< bool > m_auditorReinitialize {this, "AuditReinitialize", false, "trigger auditor on reinitialize()"}
 
Gaudi::Property< bool > m_auditorRestart {this, "AuditRestart", false, "trigger auditor on restart()"}
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service. More...
 

Detailed Description

Definition at line 36 of file FileMgr.h.

Member Typedef Documentation

Definition at line 128 of file FileMgr.h.

Definition at line 127 of file FileMgr.h.

Definition at line 135 of file FileMgr.h.

Constructor & Destructor Documentation

FileMgr::~FileMgr ( )
override

Definition at line 57 of file FileMgr.cpp.

58 {
59  // Where do the new-ed FileAttr get deleted?
60  // they get pushed into m_descriptors, but m_attr is presumably
61  // where they _also_ should be pushed in order to track ownership...
62 }

Member Function Documentation

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

Definition at line 1205 of file FileMgr.cpp.

1206 {
1207  ON_VERBOSE
1208  verbose() << "accessMatch old: " << fold << " new: " << fnew << endmsg;
1209 
1210  return ( ( ( fold == Io::READ ) && ( fnew == Io::READ ) ) ||
1211  ( ( fold & Io::WRITE ) != 0 && ( fnew & Io::WRITE ) != 0 ) ||
1212  ( ( fold & Io::RDWR ) != 0 && ( fnew & Io::RDWR ) != 0 ) );
1213 }
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
#define ON_VERBOSE
Definition: FileMgr.cpp:9
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
Io::close_t FileMgr::close ( const Fd  ,
const std::string caller 
)
override
close_t FileMgr::close ( void *  vp,
const std::string caller 
)
override

Definition at line 510 of file FileMgr.cpp.

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

Definition at line 220 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 FAILURE
Definition: StatusCode.h:88
T end(T...args)
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:138
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T erase(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T find(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode FileMgr::execAction ( Io::FileAttr fa,
const std::string caller,
const Io::Action a 
) const
private

Definition at line 1145 of file FileMgr.cpp.

1146 {
1147 
1148  Io::IoTech tech = fa->tech();
1149 
1150  StatusCode s1, s2;
1151 
1152  auto itr = m_actions.find( Io::UNKNOWN );
1153 
1154  if ( itr != m_actions.end() && !itr->second.empty() ) {
1155  s1 = execActs( fa, caller, a, itr->second );
1156  }
1157 
1158  itr = m_actions.find( tech );
1159  if ( itr != m_actions.end() && !itr->second.empty() ) {
1160  s2 = execActs( fa, caller, a, itr->second );
1161  }
1162 
1163  return ( s1.isFailure() || s2.isFailure() ) ? StatusCode::FAILURE : StatusCode::SUCCESS;
1164 }
IoTech
Definition: IFileMgr.h:158
constexpr static const auto FAILURE
Definition: StatusCode.h:88
bool isFailure() const
Definition: StatusCode.h:139
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
StatusCode execActs(Io::FileAttr *, const std::string &, const Io::Action &, const actionMap &m) const
Definition: FileMgr.cpp:1168
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
IoTech tech() const
Definition: IFileMgr.h:192
std::map< IoTech, actionMap > m_actions
Definition: FileMgr.h:144
StatusCode FileMgr::execActs ( Io::FileAttr fa,
const std::string caller,
const Io::Action a,
const actionMap m 
) const
private

Definition at line 1168 of file FileMgr.cpp.

1170 {
1171 
1172  auto mitr = m.find( a );
1173  if ( mitr == m.end() || mitr->second.empty() ) return StatusCode::SUCCESS;
1174 
1175  ON_DEBUG
1176  debug() << "executing " << mitr->second.size() << " " << a << " actions on " << *fa << " from " << caller << endmsg;
1177 
1178  bool fail( false );
1179 
1180  auto it2 = m_supMap.find( fa->name() );
1181  if ( it2 != m_supMap.end() ) {
1182  if ( it2->second[a] || it2->second[Io::INVALID_ACTION] ) {
1183  ON_DEBUG
1184  debug() << " --> suppressing callback action for " << a << endmsg;
1185  return StatusCode::SUCCESS;
1186  }
1187  }
1188 
1189  for ( const auto& itr : mitr->second ) {
1190 
1191  ON_DEBUG
1192  debug() << "executing " << itr.second << endmsg;
1193 
1194  if ( ( ( ( itr.first ) )( fa, caller ) ).isFailure() ) {
1195  warning() << "execution of " << itr.second << " on " << *fa << " failed during " << a << " action" << endmsg;
1196  fail = true;
1197  }
1198  }
1199 
1200  return fail ? StatusCode::FAILURE : StatusCode::SUCCESS;
1201 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
std::map< std::string, Io::Action_bitmap > m_supMap
Definition: FileMgr.h:146
T end(T...args)
const std::string & name() const
Definition: IFileMgr.h:190
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
constexpr double m
Definition: SystemOfUnits.h:94
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
#define ON_DEBUG
Definition: FileMgr.cpp:8
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
Io::Fd FileMgr::fd ( const std::string fname) const
override

Definition at line 983 of file FileMgr.cpp.

984 {
985 
986  auto fitr = m_files.equal_range( fname );
987  auto itr = std::find_if( fitr.first, fitr.second, []( fileMap::const_reference f ) { return f.second->fd() != -1; } );
988  return itr != fitr.second ? itr->second->fd() : -1;
989 }
fileMap m_files
Definition: FileMgr.h:137
T find_if(T...args)
T equal_range(T...args)
Io::Fd FileMgr::fd ( void *  fptr) const
override

Definition at line 993 of file FileMgr.cpp.

994 {
995 
996  auto itr = std::find_if( m_files.begin(), m_files.end(),
997  [&]( fileMap::const_reference f ) { return f.second->fptr() == fptr; } );
998  return itr != m_files.end() ? itr->second->fd() : -1;
999 }
void * fptr() const
Definition: IFileMgr.h:195
fileMap m_files
Definition: FileMgr.h:137
T end(T...args)
Fd fd() const
Definition: IFileMgr.h:189
T find_if(T...args)
T begin(T...args)
void * fptr(const std::string &) const override
Definition: FileMgr.cpp:1003
StatusCode FileMgr::finalize ( )
override

Definition at line 123 of file FileMgr.cpp.

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

Definition at line 963 of file FileMgr.cpp.

964 {
965 
966  auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
967  [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
968  return ( itr != std::end( m_files ) ) ? itr->second->name() : s_empty;
969 }
fileMap m_files
Definition: FileMgr.h:137
T end(T...args)
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:983
T find_if(T...args)
T begin(T...args)
const std::string & FileMgr::fname ( void *  vp) const
override

Definition at line 973 of file FileMgr.cpp.

974 {
975 
976  auto itr = std::find_if( m_files.begin(), m_files.end(),
977  [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
978  return itr != m_files.end() ? itr->second->name() : s_empty;
979 }
void * fptr() const
Definition: IFileMgr.h:195
fileMap m_files
Definition: FileMgr.h:137
T end(T...args)
const std::string & name() const
Definition: IFileMgr.h:190
T find_if(T...args)
T begin(T...args)
void * FileMgr::fptr ( const std::string fname) const
override

Definition at line 1003 of file FileMgr.cpp.

1004 {
1005  auto fitr = m_files.equal_range( fname );
1006  auto itr =
1007  std::find_if( fitr.first, fitr.second, []( fileMap::const_reference f ) -> bool { return f.second->fptr(); } );
1008  return itr != fitr.second ? itr->second->fptr() : nullptr;
1009 }
fileMap m_files
Definition: FileMgr.h:137
T find_if(T...args)
T equal_range(T...args)
void * FileMgr::fptr ( const Io::Fd fd) const
override

Definition at line 1013 of file FileMgr.cpp.

1014 {
1015 
1016  auto itr = std::find_if( m_files.begin(), m_files.end(),
1017  [&]( fileMap::const_reference f ) { return f.second->fd() == fd; } );
1018  return itr != m_files.end() ? itr->second->fptr() : nullptr;
1019 }
void * fptr() const
Definition: IFileMgr.h:195
fileMap m_files
Definition: FileMgr.h:137
T end(T...args)
Fd fd() const
Definition: IFileMgr.h:189
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:983
T find_if(T...args)
T begin(T...args)
int FileMgr::getFd ( std::vector< Fd > &  ) const
override
int FileMgr::getFd ( const Io::IoTech tech,
std::vector< Io::Fd > &  fd 
) const
override

Definition at line 934 of file FileMgr.cpp.

935 {
936 
937  if ( tech == UNKNOWN ) return getFd( fd );
938 
939  fd.clear();
940  transform_if( std::begin( m_descriptors ), std::end( m_descriptors ), std::back_inserter( fd ), select1st,
941  [&]( const std::pair<Fd, FileAttr*>& d ) { return d.second->tech() == tech; } );
942 
943  return fd.size();
944 }
T end(T...args)
std::map< Fd, FileAttr * > m_descriptors
Definition: FileMgr.h:139
T clear(T...args)
T size(T...args)
T begin(T...args)
T back_inserter(T...args)
int getFd(std::vector< Fd > &) const override
int FileMgr::getFd ( const Io::IoTech tech,
const Io::IoFlags flags,
std::vector< Io::Fd > &  fd 
) const
override

Definition at line 950 of file FileMgr.cpp.

951 {
952 
953  fd.clear();
954  transform_if( m_descriptors.begin(), m_descriptors.end(), std::back_inserter( fd ), select1st,
955  [&]( const std::pair<Fd, FileAttr*>& d ) {
956  return ( d.second->tech() == tech || tech == UNKNOWN ) && ( d.second->flags() == flags );
957  } );
958  return fd.size();
959 }
T end(T...args)
std::map< Fd, FileAttr * > m_descriptors
Definition: FileMgr.h:139
T clear(T...args)
T size(T...args)
T begin(T...args)
T back_inserter(T...args)
int FileMgr::getFileAttr ( const std::string fname,
std::vector< const FileAttr * > &  fa 
) const
override

Definition at line 741 of file FileMgr.cpp.

742 {
743 
744  fa.clear();
745 
746  auto fitr = m_files.equal_range( fname );
747  std::transform( fitr.first, fitr.second, std::back_inserter( fa ), select2nd );
748 
750  [&]( const FileAttr* f ) { return f->name() == fname; } );
751 
752  return fa.size();
753 }
T copy_if(T...args)
fileMap m_files
Definition: FileMgr.h:137
T end(T...args)
const std::string & name() const
Definition: IFileMgr.h:190
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:142
T size(T...args)
T begin(T...args)
T back_inserter(T...args)
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:963
T transform(T...args)
T equal_range(T...args)
StatusCode FileMgr::getFileAttr ( const Fd  ,
const FileAttr *&   
) const
override
StatusCode FileMgr::getFileAttr ( void *  vp,
const FileAttr *&  fa 
) const
override

Definition at line 779 of file FileMgr.cpp.

780 {
781 
783  [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
784  if ( i != std::end( m_files ) ) {
785  fa = i->second;
786  return StatusCode::SUCCESS;
787  }
788 
790  [&]( const FileAttr* f ) { return f->fptr() == vp; } );
791  if ( j != std::end( m_oldFiles ) ) {
792  fa = *j;
793  return StatusCode::SUCCESS;
794  }
795 
796  return StatusCode::FAILURE;
797 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
void * fptr() const
Definition: IFileMgr.h:195
fileMap m_files
Definition: FileMgr.h:137
T end(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:142
T find_if(T...args)
T begin(T...args)
int FileMgr::getFiles ( std::vector< std::string > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 801 of file FileMgr.cpp.

802 {
803 
804  files.clear();
805  auto not_in_files = [&]( const std::string& i ) {
806  return std::none_of( std::begin( files ), std::end( files ), [&]( const std::string& j ) { return j == i; } );
807  };
808  transform_copy_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), to_name, not_in_files );
809  if ( !op ) {
810  transform_copy_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), to_name,
811  not_in_files );
812  }
813  return files.size();
814 }
fileMap m_files
Definition: FileMgr.h:137
T end(T...args)
STL class.
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:142
T size(T...args)
T begin(T...args)
T back_inserter(T...args)
T none_of(T...args)
int FileMgr::getFiles ( std::vector< const Io::FileAttr * > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 818 of file FileMgr.cpp.

819 {
820 
821  files.clear();
822  std::transform( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), select2nd );
823  if ( !op ) {
825  }
826  return files.size();
827 }
T copy(T...args)
fileMap m_files
Definition: FileMgr.h:137
T end(T...args)
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:142
T size(T...args)
T begin(T...args)
T back_inserter(T...args)
T transform(T...args)
int FileMgr::getFiles ( const Io::IoTech tech,
std::vector< std::string > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 831 of file FileMgr.cpp.

832 {
833 
834  if ( tech == UNKNOWN ) return getFiles( files, op );
835 
836  files.clear();
837  transform_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), to_name,
838  [&]( fileMap::const_reference f ) {
839  return f.second->tech() == tech &&
840  std::none_of( std::begin( files ), std::end( files ),
841  [&]( const std::string& j ) { return j == f.first; } );
842  } );
843 
844  if ( !op ) {
845  transform_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), to_name,
846  [&]( const FileAttr* f ) {
847  return f->tech() == tech && std::none_of( std::begin( files ), std::end( files ),
848  [&]( const std::string& j ) { return j == f->name(); } );
849  } );
850  }
851  return files.size();
852 }
int getFiles(std::vector< std::string > &, bool onlyOpen=true) const override
Definition: FileMgr.cpp:801
fileMap m_files
Definition: FileMgr.h:137
T end(T...args)
STL class.
const std::string & name() const
Definition: IFileMgr.h:190
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:142
T size(T...args)
IoTech tech() const
Definition: IFileMgr.h:192
T begin(T...args)
T back_inserter(T...args)
T none_of(T...args)
int FileMgr::getFiles ( const Io::IoTech tech,
std::vector< const Io::FileAttr * > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 856 of file FileMgr.cpp.

857 {
858 
859  if ( tech == UNKNOWN ) return getFiles( files, op );
860 
861  auto matches_tech = [&]( const FileAttr* f ) { return f->tech() == tech; };
862 
863  files.clear();
864  transform_copy_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), select2nd, matches_tech );
865  if ( !op ) {
866  std::copy_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), matches_tech );
867  }
868 
869  return files.size();
870 }
T copy_if(T...args)
int getFiles(std::vector< std::string > &, bool onlyOpen=true) const override
Definition: FileMgr.cpp:801
fileMap m_files
Definition: FileMgr.h:137
T end(T...args)
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:142
T size(T...args)
T begin(T...args)
T back_inserter(T...args)
int FileMgr::getFiles ( const Io::IoTech tech,
const Io::IoFlags flags,
std::vector< std::string > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 874 of file FileMgr.cpp.

875 {
876 
877  files.clear();
878 
879  auto not_in_files = [&]( const std::string& n ) {
880  return std::none_of( std::begin( files ), std::end( files ), [&]( const std::string& f ) { return f == n; } );
881  };
882  auto matches_tech_and_flags = [&]( const FileAttr* f ) {
883  return ( f->tech() == tech || tech == UNKNOWN ) && f->flags() == flags;
884  };
885 
886  transform_if(
887  std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), to_name,
888  [&]( fileMap::const_reference f ) { return matches_tech_and_flags( f.second ) && not_in_files( f.first ); } );
889  if ( !op ) {
890  transform_if( std::begin( m_oldFiles ), std::end( m_oldFiles ), std::back_inserter( files ), to_name,
891  [&]( const FileAttr* f ) { return matches_tech_and_flags( f ) && not_in_files( f->name() ); } );
892  }
893 
894  return files.size();
895 }
fileMap m_files
Definition: FileMgr.h:137
T end(T...args)
STL class.
const std::string & name() const
Definition: IFileMgr.h:190
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:142
T size(T...args)
T begin(T...args)
T back_inserter(T...args)
T none_of(T...args)
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 898 of file FileMgr.cpp.

899 {
900 
901  files.clear();
902 
903  auto matches_tech_and_flags = [&]( const FileAttr* f ) {
904  return ( f->tech() == tech || tech == UNKNOWN ) && f->flags() == flags;
905  };
906 
907  transform_copy_if( std::begin( m_files ), std::end( m_files ), std::back_inserter( files ), select2nd,
908  matches_tech_and_flags );
909  if ( !op ) {
911  matches_tech_and_flags );
912  }
913 
914  return files.size();
915 }
T copy_if(T...args)
fileMap m_files
Definition: FileMgr.h:137
T end(T...args)
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:142
T size(T...args)
T begin(T...args)
T back_inserter(T...args)
StatusCode FileMgr::getHandler ( const IoTech &  ,
FileHdlr  
) const
override
StatusCode FileMgr::getHandler ( const std::string fname,
Io::FileHdlr hdlr 
) const
override

Definition at line 1059 of file FileMgr.cpp.

1060 {
1061 
1062  auto fitr = m_files.equal_range( fname );
1063  if ( fitr.first == fitr.second ) {
1064  error() << "no file \"" << fname << "\" registered. Cannot determine tech" << endmsg;
1065  return StatusCode::FAILURE;
1066  }
1067 
1068  auto itr = fitr.first;
1069  IoTech tech = itr->second->tech();
1070 
1071  ++itr;
1072  while ( itr != fitr.second ) {
1073  if ( itr->second->tech() != tech ) {
1074  error() << "multiple technologies registered for file \"" << fname << "\". Cannot determine handler" << endmsg;
1075  return StatusCode::FAILURE;
1076  }
1077  ++itr;
1078  }
1079 
1080  return getHandler( tech, hdlr );
1081 }
IoTech
Definition: IFileMgr.h:158
constexpr static const auto FAILURE
Definition: StatusCode.h:88
fileMap m_files
Definition: FileMgr.h:137
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
StatusCode getHandler(const IoTech &, FileHdlr &) const override
T equal_range(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
int FileMgr::getLastError ( std::string err) const
override

Definition at line 1036 of file FileMgr.cpp.

1037 {
1038 
1039  err = m_lastErrS;
1040  return m_lastErr;
1041 }
std::string m_lastErrS
Definition: FileMgr.h:148
int m_lastErr
Definition: FileMgr.h:149
void FileMgr::handle ( const Incident )
override

Definition at line 181 of file FileMgr.cpp.

181 {}
StatusCode FileMgr::hasHandler ( const IoTech ) const
override

Definition at line 235 of file FileMgr.cpp.

236 {
237 
238  auto itr = m_handlers.find( tech );
239  return ( itr != m_handlers.end() ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
240 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
T end(T...args)
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:138
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T find(T...args)
StatusCode FileMgr::initialize ( )
override

Definition at line 66 of file FileMgr.cpp.

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

Definition at line 1117 of file FileMgr.cpp.

1118 {
1119 
1120  info() << "listing registered actions\n";
1121 
1122  for ( const auto& iit : m_actions ) {
1123  Io::IoTech t = iit.first;
1124  const actionMap& m = iit.second;
1125 
1126  if ( !m.empty() ) {
1127  info() << " --- Tech: ";
1128  if ( t == Io::UNKNOWN ) {
1129  info() << "ALL ---\n";
1130  } else {
1131  info() << t << " ---\n";
1132  }
1133  for ( const auto& iia : m ) {
1134  for ( const auto& it2 : iia.second ) {
1135  info() << " " << iia.first << " " << it2.second << '\n';
1136  }
1137  }
1138  }
1139  }
1140  info() << endmsg;
1141 }
IoTech
Definition: IFileMgr.h:158
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
std::map< Io::Action, std::list< bfcn_desc_t > > actionMap
Definition: FileMgr.h:128
constexpr double m
Definition: SystemOfUnits.h:94
std::map< IoTech, actionMap > m_actions
Definition: FileMgr.h:144
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void FileMgr::listFiles ( ) const
override

Definition at line 1023 of file FileMgr.cpp.

1024 {
1025 
1026  info() << "listing registered files [" << ( m_files.size() + m_oldFiles.size() ) << "]:\n";
1027 
1028  for ( auto& itr : m_files ) info() << itr.second << '\n';
1029  for ( auto& it2 : m_oldFiles ) info() << *it2 << '\n';
1030 
1031  info() << endmsg;
1032 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
fileMap m_files
Definition: FileMgr.h:137
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:142
T size(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void FileMgr::listHandlers ( ) const
override

Definition at line 1085 of file FileMgr.cpp.

1086 {
1087 
1088  info() << "Listing registered handlers:\n";
1089 
1090  for ( const auto& itr : m_handlers ) info() << " " << itr.first << '\n';
1091  info() << endmsg;
1092 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:138
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void FileMgr::listSuppression ( ) const
virtual

Definition at line 1225 of file FileMgr.cpp.

1226 {
1227  if ( m_supMap.empty() ) return;
1228 
1229  info() << "listing suppressed file actions\n";
1230 
1231  for ( const auto& sup : m_supMap ) {
1232  info() << " " << sup.first;
1233  if ( sup.second[Io::INVALID_ACTION] ) {
1234  info() << " ALL\n";
1235  } else {
1236  for ( unsigned i = 0; i != sup.second.size(); ++i ) {
1237  if ( sup.second[i] ) info() << " " << (Io::Action)i;
1238  }
1239  info() << '\n';
1240  }
1241  }
1242  info() << endmsg;
1243 }
T empty(T...args)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
std::map< std::string, Io::Action_bitmap > m_supMap
Definition: FileMgr.h:146
Action
Definition: IFileMgr.h:285
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
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 244 of file FileMgr.cpp.

246 {
247 
248  return open( tech, caller, fname, desc, flags, fd, ptr, sh );
249 }
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:244
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:983
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 252 of file FileMgr.cpp.

254 {
255 
256  void* dummy( 0 );
257  return open( tech, caller, fname, desc, flags, fd, dummy, sh );
258 }
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:244
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:983
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 261 of file FileMgr.cpp.

263 {
264 
265  Fd dummy( -1 );
266  return open( tech, caller, fname, desc, flags, dummy, ptr, sh );
267 }
int Fd
Definition: IFileMgr.h:172
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:244
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
StatusCode FileMgr::regAction ( Io::bfcn_action_t  bf,
const Io::Action a,
const std::string desc = "" 
)
override

Definition at line 1096 of file FileMgr.cpp.

1097 {
1098 
1099  return regAction( bf, a, Io::UNKNOWN, d );
1100 }
StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &desc="") override
Definition: FileMgr.cpp:1096
StatusCode FileMgr::regAction ( Io::bfcn_action_t  bf,
const Io::Action a,
const Io::IoTech t,
const std::string desc = "" 
)
override

Definition at line 1104 of file FileMgr.cpp.

1105 {
1106 
1107  ON_DEBUG
1108  debug() << "registering " << a << " action " << System::typeinfoName( bf.target_type() ) << " for tech " << t
1109  << endmsg;
1110 
1111  m_actions[t][a].emplace_back( bf, ( !d.empty() ) ? d : System::typeinfoName( bf.target_type() ) );
1112  return StatusCode::SUCCESS;
1113 }
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:332
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T target_type(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
std::map< IoTech, actionMap > m_actions
Definition: FileMgr.h:144
#define ON_DEBUG
Definition: FileMgr.cpp:8
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode FileMgr::regHandler ( FileHdlr  fh)
override

Definition at line 185 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 
210  ON_DEBUG
211  debug() << "Successfully registered handler for tech \"" << tech << "\"" << endmsg;
212 
213  m_handlers[tech] = fh;
214 
215  return StatusCode::SUCCESS;
216 }
IoTech
Definition: IFileMgr.h:158
constexpr static const auto FAILURE
Definition: StatusCode.h:88
bfcn_reopen_t b_reopen_fcn
Definition: IFileMgr.h:267
T end(T...args)
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:138
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
bfcn_close_t b_close_fcn
Definition: IFileMgr.h:265
bfcn_closeP_t b_closeP_fcn
Definition: IFileMgr.h:266
bfcn_reopenP_t b_reopenP_fcn
Definition: IFileMgr.h:268
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T find(T...args)
bfcn_open_t b_open_fcn
Definition: IFileMgr.h:264
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
#define ON_DEBUG
Definition: FileMgr.cpp:8
IoTech tech
Definition: IFileMgr.h:262
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
Io::reopen_t FileMgr::reopen ( const Fd  ,
const IoFlags ,
const std::string caller 
)
override
reopen_t FileMgr::reopen ( void *  vp,
const IoFlags flags,
const std::string caller 
)
override

Definition at line 680 of file FileMgr.cpp.

681 {
682  ON_VERBOSE
683  verbose() << "reopen(" << vp << "," << flags << "," << caller << ")" << endmsg;
684 
685  reopen_t r = -1;
686 
687  auto itr = std::find_if( std::begin( m_files ), std::end( m_files ),
688  [&]( fileMap::const_reference f ) { return f.second->fptr() == vp; } );
689  if ( itr == m_files.end() ) {
690  error() << "unregistered file ptr \"" << vp << "\" when calling reopen()" << endmsg;
691  return r;
692  }
693 
694  FileAttr* fa = itr->second;
695  FileHdlr fh;
696  IoTech tech = fa->tech();
697 
698  if ( getHandler( tech, fh ).isFailure() ) {
699  return r;
700  }
701 
702  if ( !fh.b_reopenP_fcn ) {
703  error() << "no reopen(" << tech << ",void*) function registered" << endmsg;
704  return -1;
705  }
706 
707  try {
708  r = fh.b_reopenP_fcn( vp, flags );
709  } catch ( const std::bad_function_call& err ) {
710  error() << "when calling reopen handler for " << tech << " on file " << fa->name() << " with flags " << flags
711  << " caught " << err.what() << endmsg;
712  return -1;
713  } catch ( ... ) {
714  error() << "when calling reopen handler for " << tech << " on file " << fa->name() << " with flags " << flags
715  << " caught an unknown exception." << endmsg;
716  return -1;
717  }
718 
719  if ( r < 0 ) {
720  warning() << "reopen of file with ptr \"" << vp << "\", name: \"" << fa->name() << "\", tech: \"" << tech
721  << "\", flags: \"" << flags << "\" failed" << endmsg;
722 
723  execAction( fa, caller, Io::REOPEN_ERR ).ignore();
724 
725  return r;
726  }
727 
728  fa->isOpen( true );
729  fa->flags( flags );
730 
731  // exec all callbacks
732  if ( execAction( fa, caller, Io::REOPEN ).isFailure() ) {
733  warning() << "at least one reopen callback action failed" << endmsg;
734  }
735 
736  return r;
737 }
IoTech
Definition: IFileMgr.h:158
int reopen_t
Definition: IFileMgr.h:252
fileMap m_files
Definition: FileMgr.h:137
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
bool isOpen() const
Definition: IFileMgr.h:196
StatusCode execAction(Io::FileAttr *, const std::string &, const Io::Action &) const
Definition: FileMgr.cpp:1145
T end(T...args)
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
const std::string & name() const
Definition: IFileMgr.h:190
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
StatusCode getHandler(const IoTech &, FileHdlr &) const override
bfcn_reopenP_t b_reopenP_fcn
Definition: IFileMgr.h:268
T find_if(T...args)
IoTech tech() const
Definition: IFileMgr.h:192
T begin(T...args)
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:165
IoFlags flags() const
Definition: IFileMgr.h:193
#define ON_VERBOSE
Definition: FileMgr.cpp:9
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void FileMgr::suppressAction ( const std::string f)
override

Definition at line 1217 of file FileMgr.cpp.

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

Definition at line 1221 of file FileMgr.cpp.

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

Member Data Documentation

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

Definition at line 144 of file FileMgr.h.

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

Definition at line 140 of file FileMgr.h.

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

Definition at line 139 of file FileMgr.h.

fileMap FileMgr::m_files
private

Definition at line 137 of file FileMgr.h.

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

Definition at line 138 of file FileMgr.h.

int FileMgr::m_lastErr
private

Definition at line 149 of file FileMgr.h.

std::string FileMgr::m_lastErrS
private

Definition at line 148 of file FileMgr.h.

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

Definition at line 118 of file FileMgr.h.

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

Definition at line 117 of file FileMgr.h.

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

Definition at line 115 of file FileMgr.h.

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

Definition at line 142 of file FileMgr.h.

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

Definition at line 152 of file FileMgr.h.

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

Definition at line 116 of file FileMgr.h.

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

Definition at line 151 of file FileMgr.h.

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

Definition at line 121 of file FileMgr.h.

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

Definition at line 120 of file FileMgr.h.

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

Definition at line 146 of file FileMgr.h.


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