FileMgr Class Reference

#include <src/FileMgr/FileMgr.h>

Inheritance diagram for FileMgr:
Collaboration diagram for FileMgr:

Public Member Functions

 FileMgr (const std::string &name, ISvcLocator *svc)
 
 ~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...
 
 ~extends () override=default
 Virtual destructor. 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...
 
StatusCode setProperty (const Property &p) override
 
StatusCode setProperty (const std::string &s) override
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 
StatusCode getProperty (Property *p) const override
 
const PropertygetProperty (const std::string &name) const override
 
StatusCode getProperty (const std::string &n, std::string &v) const override
 
const std::vector< Property * > & getProperties () const override
 
bool hasProperty (const std::string &name) const override
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value 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 >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties. More...
 
template<class T >
StatusCode declarePrivateTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Private tool. More...
 
template<class T >
StatusCode declarePublicTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Public 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 CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
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...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const __attribute__((deprecated))
 Backward compatibility function for getting the output level. More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. 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
 
typedef std::map< std::string, int > supMap
 

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

StringProperty m_logfile
 
BooleanProperty m_printSummary
 
BooleanProperty m_loadRootHandler
 
BooleanProperty m_loadPosixHandler
 
StringProperty m_ssl_proxy
 
StringProperty m_ssl_cert
 
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
 
supMap m_supMap
 
std::string m_lastErrS
 
int m_lastErr
 
std::unique_ptr< RootFileHandlerm_rfh
 
std::unique_ptr< 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
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
 
- 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 CommonMessaging< implements< IService, IProperty, IStateful > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel = MSG::NIL
 Service output level. More...
 
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. More...
 

Detailed Description

Definition at line 31 of file FileMgr.h.

Member Typedef Documentation

Definition at line 143 of file FileMgr.h.

Definition at line 142 of file FileMgr.h.

Definition at line 153 of file FileMgr.h.

typedef std::map<std::string, int> FileMgr::supMap
private

Definition at line 164 of file FileMgr.h.

Constructor & Destructor Documentation

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

Definition at line 78 of file FileMgr.cpp.

79  : base_class( name, svc )
80 {
81 
82  declareProperty("LogFile",m_logfile="");
83  declareProperty("PrintSummary",m_printSummary=false);
84  declareProperty("LoadROOTHandler", m_loadRootHandler=true);
85  declareProperty("LoadPOSIXHandler", m_loadPosixHandler=true);
86 
87  declareProperty("TSSL_UserProxy", m_ssl_proxy="X509");
88  declareProperty("TSSL_CertDir", m_ssl_cert="X509");
89 
90  m_lastErrS = "";
91 
92 }
StringProperty m_logfile
Definition: FileMgr.h:133
extends base_class
Typedef to this class.
Definition: extends.h:14
BooleanProperty m_printSummary
Definition: FileMgr.h:134
std::string m_lastErrS
Definition: FileMgr.h:167
BooleanProperty m_loadRootHandler
Definition: FileMgr.h:134
BooleanProperty m_loadPosixHandler
Definition: FileMgr.h:134
StringProperty m_ssl_cert
Definition: FileMgr.h:135
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
StringProperty m_ssl_proxy
Definition: FileMgr.h:135
FileMgr::~FileMgr ( )
override

Definition at line 96 of file FileMgr.cpp.

96  {
97  // Where do the new-ed FileAttr get deleted?
98  // they get pushed into m_descriptors, but m_attr is presumably
99  // where they _also_ should be pushed in order to track ownership...
100 }

Member Function Documentation

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

Definition at line 1495 of file FileMgr.cpp.

1496  {
1497 
1498  ON_VERBOSE
1499  verbose() << "accessMatch old: " << fold
1500  << " new: " << fnew
1501  << endmsg;
1502 
1503  return ( ((fold == Io::READ) && (fnew == Io::READ)) ||
1504  ( (fold & Io::WRITE) != 0 && (fnew & Io::WRITE) != 0) ||
1505  ( (fold & Io::RDWR) != 0 && (fnew & Io::RDWR) != 0) ) ;
1506 
1507 }
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
#define ON_VERBOSE
Definition: FileMgr.cpp:12
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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 681 of file FileMgr.cpp.

681  {
682 
683  // return codes:
684  // < 0 : error condition
685  // 0 : actual close of one file
686  // > 0 : shared file, removed from list, no actual close, returns
687  // number of shared files still open.
688 
689  ON_VERBOSE
690  verbose() << "close(" << vp << ")"
691  << endmsg;
692 
693  close_t r = -1;
694 
696  [&](fileMap::const_reference i ) { return i.second->fptr()==vp; } );
697 
698  if (itr == m_files.end()) {
699  error() << "unknown file ptr \"" << vp
700  << "\" when calling close()"
701  << endmsg;
702  return r;
703  }
704 
705  IoTech tech = itr->second->tech();
706 
707  FileHdlr fh;
708 
709  if (getHandler(tech,fh).isFailure()) {
710  return r;
711  }
712  if (! fh.b_closeP_fcn) {
713  error() << "no close(" << tech << ",void*) function registered"
714  << endmsg;
715  return -1;
716  }
717 
718  FileAttr *fa = itr->second;
719 
720  // find how many times this file is open
722  m_files.equal_range(fa->name());
723 
724  int i = std::count_if( fitr.first, fitr.second, [&](fileMap::const_reference f)
725  { return f.second->fptr()==vp; } );
726 
727  ON_VERBOSE
728  verbose() << " ref count: " << i
729  << endmsg;
730 
731  if (i > 1 && fa->isShared()) {
732  // file open multiple times in shared access. don't do the actual close
733  ON_DEBUG
734  debug() << "closing file " << fa->name() << " opened "
735  << i << " times with fptr " << vp << endmsg;
736  m_files.erase(itr);
737 
738  r = i-1;
739 
740  } else if (i == 1 || (i>1 && !fa->isShared()) ) {
741  ON_DEBUG
742  debug() << "closing: " << *fa << endmsg;
743 
744  try {
745  r = fh.b_closeP_fcn(vp);
746  } catch (const std::bad_function_call& err) {
747  error() << "when calling close handler for " << tech
748  << " on file " << fa->name()
749  << " caught " << err.what() << endmsg;
750  execAction(fa, caller, CLOSE_ERR ).ignore();
751  return -1;
752  } catch (...) {
753  error() << "when calling close handler for " << tech
754  << " on file " << fa->name()
755  << " caught an unknown exception." << endmsg;
756  execAction(fa, caller, CLOSE_ERR ).ignore();
757  return -1;
758  }
759 
760  if (r < 0) {
761  warning()
762  << "close of file with ptr \"" << vp
763  << "\", name: \"" << fa->name()
764  << "\", tech: \"" << tech << "\" failed"
765  << endmsg;
766 
767  return r;
768  }
769 
770  m_files.erase(itr);
771 
772  } else {
773  // this should never happen!
774  error()
775  << "ref count: " << i << " < 0 when closing " << fa
776  << ". This should never happen"
777  << endmsg;
778  return -1;
779 
780  }
781 
782  fa->fd(-1);
783  fa->flags(INVALID);
784  fa->isOpen(false);
785  fa->fptr(0);
786  m_oldFiles.push_back( fa );
787 
788 
789  // exec all callbacks
790  if (execAction(fa, caller, CLOSE).isFailure()) {
791  warning()
792  << "at least one close callback action failed"
793  << endmsg;
794  }
795 
796  return r;
797 
798 }
StatusCode getHandler(const IoTech &, FileHdlr &) const override
IoTech
Definition: IFileMgr.h:150
void * fptr() const
Definition: IFileMgr.h:190
fileMap m_files
Definition: FileMgr.h:155
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
bool isOpen() const
Definition: IFileMgr.h:191
StatusCode execAction(Io::FileAttr *, const std::string &, const Io::Action &) const
Definition: FileMgr.cpp:1416
T end(T...args)
Fd fd() const
Definition: IFileMgr.h:184
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
const std::string & name() const
Definition: IFileMgr.h:185
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:192
T erase(T...args)
bfcn_closeP_t b_closeP_fcn
Definition: IFileMgr.h:268
T count_if(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:160
T find_if(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T begin(T...args)
#define ON_DEBUG
Definition: FileMgr.cpp:11
void ignore() const
Definition: StatusCode.h:108
list i
Definition: ana.py:128
IoFlags flags() const
Definition: IFileMgr.h:188
#define ON_VERBOSE
Definition: FileMgr.cpp:12
T equal_range(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
int close_t
Definition: IFileMgr.h:253
StatusCode FileMgr::deregHandler ( const IoTech )
override

Definition at line 321 of file FileMgr.cpp.

321  {
322  FileHdlr hdlr;
323 
324  auto itr = m_handlers.find(tech);
325  if (itr == m_handlers.end()) {
326  error() << "Can't de-register tech " << tech
327  << " as it hasn't been registered!"
328  << endmsg;
329  return StatusCode::FAILURE;
330  }
331 
332  m_handlers.erase(itr);
333  return StatusCode::SUCCESS;
334 
335 }
T end(T...args)
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:156
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T erase(T...args)
T find(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode FileMgr::execAction ( Io::FileAttr fa,
const std::string caller,
const Io::Action a 
) const
private

Definition at line 1416 of file FileMgr.cpp.

1417  {
1418 
1419  Io::IoTech tech = fa->tech();
1420 
1421  StatusCode s1,s2;
1422 
1423  auto itr = m_actions.find(Io::UNKNOWN);
1424 
1425  if (itr != m_actions.end() && !itr->second.empty() ) {
1426  s1 = execActs(fa, caller, a, itr->second);
1427  }
1428 
1429  itr = m_actions.find(tech);
1430  if (itr != m_actions.end() && !itr->second.empty() ) {
1431  s2 = execActs(fa, caller, a, itr->second);
1432  }
1433 
1434  return (s1.isFailure() || s2.isFailure()) ? StatusCode::FAILURE
1436 }
IoTech
Definition: IFileMgr.h:150
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode execActs(Io::FileAttr *, const std::string &, const Io::Action &, const actionMap &m) const
Definition: FileMgr.cpp:1441
IoTech tech() const
Definition: IFileMgr.h:187
std::map< IoTech, actionMap > m_actions
Definition: FileMgr.h:162
StatusCode FileMgr::execActs ( Io::FileAttr fa,
const std::string caller,
const Io::Action a,
const actionMap m 
) const
private

Definition at line 1441 of file FileMgr.cpp.

1442  {
1443 
1444  auto mitr = m.find(a);
1445 
1446  if (mitr == m.end() || mitr->second.empty()) {
1447  return StatusCode::SUCCESS;
1448  }
1449 
1450  ON_DEBUG
1451  debug()
1452  << "executing " << mitr->second.size() << " " << a
1453  << " actions on "
1454  << *fa << " from "
1455  << caller
1456  << endmsg;
1457 
1458 
1459  bool fail(false);
1460 
1461  auto it2 = m_supMap.find(fa->name());
1462  if (it2 != m_supMap.end()) {
1463  if (get_bit(it2->second,a) || get_bit(it2->second,Io::INVALID_ACTION)) {
1464  ON_DEBUG
1465  debug() << " --> suppressing callback action for "
1466  << a
1467  << endmsg;
1468  return StatusCode::SUCCESS;
1469  }
1470  }
1471 
1472  for (const auto& itr : mitr->second ) {
1473 
1474  ON_DEBUG
1475  debug() << "executing "
1476  << itr.second << endmsg;
1477 
1478  if ( (((itr.first))(fa,caller)).isFailure() ) {
1479  warning() << "execution of "
1480  << itr.second << " on " << *fa
1481  << " failed during " << a << " action"
1482  << endmsg;
1483  fail = true;
1484  }
1485 
1486  }
1487 
1488  return fail ? StatusCode::FAILURE : StatusCode::SUCCESS;
1489 
1490 }
supMap m_supMap
Definition: FileMgr.h:165
T end(T...args)
const std::string & name() const
Definition: IFileMgr.h:185
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
constexpr double m
Definition: SystemOfUnits.h:93
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
#define ON_DEBUG
Definition: FileMgr.cpp:11
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Io::Fd FileMgr::fd ( const std::string fname) const
override

Definition at line 1231 of file FileMgr.cpp.

1231  {
1232 
1233  auto fitr = m_files.equal_range(fname);
1234  auto itr = std::find_if( fitr.first, fitr.second, [](fileMap::const_reference f) {
1235  return f.second->fd() != -1;
1236  } );
1237  return itr!=fitr.second ? itr->second->fd() : -1 ;
1238 }
fileMap m_files
Definition: FileMgr.h:155
T find_if(T...args)
T equal_range(T...args)
Io::Fd FileMgr::fd ( void *  fptr) const
override

Definition at line 1243 of file FileMgr.cpp.

1243  {
1244 
1245  auto itr = std::find_if(m_files.begin(),m_files.end(),[&](fileMap::const_reference f) {
1246  return f.second->fptr() == fptr;
1247  } );
1248  return itr!=m_files.end() ? itr->second->fd() : -1 ;
1249 }
void * fptr() const
Definition: IFileMgr.h:190
fileMap m_files
Definition: FileMgr.h:155
T end(T...args)
Fd fd() const
Definition: IFileMgr.h:184
T find_if(T...args)
T begin(T...args)
void * fptr(const std::string &) const override
Definition: FileMgr.cpp:1254
StatusCode FileMgr::finalize ( )
override

Definition at line 199 of file FileMgr.cpp.

199  {
200  ON_VERBOSE
201  verbose() << "FileMgr::finalize()" << endmsg;
202 
203 
205  listHandlers();
206  listFiles();
207  listActions();
208  listSuppression();
209  }
210 
211 
212  if (!m_files.empty()) {
213  auto& log = warning();
214  log << "At finalize, the following files remained open:" << endl;
215  for (const auto& itr : m_files) log << *(itr.second) << endl;
216  log << endmsg;
217  }
218 
219  if (m_logfile.value() != "") {
220  std::ofstream ofs;
221  ofs.open(m_logfile.value().c_str());
222  if (!ofs) {
223  error() << "Unable to open output file \"" << m_logfile.value()
224  << "\" for writing"
225  << endmsg;
226  } else {
227  ON_DEBUG
228  debug() << "Saving log to \"" << m_logfile.value() << "\""
229  << endmsg;
230  for (const auto& itr : m_files) {
231  ofs << itr.second->name() << " " << itr.second->tech() << " "
232  << itr.second->desc() << " " << itr.second->iflags() << endl;
233  }
234 
235  set<FileAttr> fs;
236  for (const auto& it2 : m_oldFiles) fs.insert(*it2);
237  for (const auto& it3 : fs ) {
238  ofs << it3.name() << " " << it3.tech() << " " << it3.desc()
239  << " " << it3.iflags()
240  << ( it3.isShared() ? " SHARED" : "" )
241  << endl;
242  }
243  ofs.close();
244  }
245  }
246 
247  // cleanup FileAttrs
248  m_attr.clear();
249 
250  m_rfh.reset();
251  m_pfh.reset();
252 
253 
254  StatusCode status = Service::finalize();
255 
256  ON_DEBUG
257  if ( status.isSuccess() )
258  debug() << "Service finalised successfully" << endmsg;
259 
260  return status;
261 
262 }
std::vector< std::unique_ptr< FileAttr > > m_attr
Definition: FileMgr.h:158
StringProperty m_logfile
Definition: FileMgr.h:133
T empty(T...args)
T open(T...args)
StatusCode finalize() override
Definition: Service.cpp:193
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
fileMap m_files
Definition: FileMgr.h:155
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
T endl(T...args)
std::unique_ptr< RootFileHandler > m_rfh
Definition: FileMgr.h:170
virtual void listActions() const
Definition: FileMgr.cpp:1387
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:26
T close(T...args)
BooleanProperty m_printSummary
Definition: FileMgr.h:134
std::unique_ptr< POSIXFileHandler > m_pfh
Definition: FileMgr.h:171
T reset(T...args)
T clear(T...args)
const TYPE & value() const
explicit conversion
Definition: Property.h:341
T insert(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:160
STL class.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
virtual void listSuppression() const
Definition: FileMgr.cpp:1537
T c_str(T...args)
#define ON_DEBUG
Definition: FileMgr.cpp:11
void listFiles() const override
Definition: FileMgr.cpp:1276
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
void listHandlers() const override
Definition: FileMgr.cpp:1348
#define ON_VERBOSE
Definition: FileMgr.cpp:12
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
const std::string & FileMgr::fname ( const Io::Fd fd) const
override

Definition at line 1208 of file FileMgr.cpp.

1208  {
1209 
1211  [&](fileMap::const_reference f) { return f.second->fd() == fd; } );
1212  return (itr!=std::end(m_files)) ? itr->second->name() : s_empty;
1213 
1214 }
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:1231
fileMap m_files
Definition: FileMgr.h:155
T end(T...args)
T find_if(T...args)
T begin(T...args)
const std::string & FileMgr::fname ( void *  vp) const
override

Definition at line 1219 of file FileMgr.cpp.

1219  {
1220 
1221  auto itr = std::find_if( m_files.begin(), m_files.end(),
1222  [&](fileMap::const_reference f) {
1223  return f.second->fptr() == vp;
1224  });
1225  return itr!=m_files.end() ? itr->second->name() : s_empty;
1226 }
void * fptr() const
Definition: IFileMgr.h:190
fileMap m_files
Definition: FileMgr.h:155
T end(T...args)
const std::string & name() const
Definition: IFileMgr.h:185
T find_if(T...args)
T begin(T...args)
void * FileMgr::fptr ( const std::string fname) const
override

Definition at line 1254 of file FileMgr.cpp.

1254  {
1255  auto fitr = m_files.equal_range(fname);
1256  auto itr = std::find_if( fitr.first, fitr.second, [](fileMap::const_reference f) -> bool {
1257  return f.second->fptr();
1258  } );
1259  return itr!=fitr.second ? itr->second->fptr() : nullptr;
1260 }
fileMap m_files
Definition: FileMgr.h:155
T find_if(T...args)
T equal_range(T...args)
void * FileMgr::fptr ( const Io::Fd fd) const
override

Definition at line 1265 of file FileMgr.cpp.

1265  {
1266 
1267  auto itr = std::find_if(m_files.begin(),m_files.end(),[&](fileMap::const_reference f) {
1268  return f.second->fd() == fd;
1269  } );
1270  return itr!=m_files.end() ? itr->second->fptr() : nullptr;
1271 }
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:1231
void * fptr() const
Definition: IFileMgr.h:190
fileMap m_files
Definition: FileMgr.h:155
T end(T...args)
Fd fd() const
Definition: IFileMgr.h:184
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 1175 of file FileMgr.cpp.

1175  {
1176 
1177  if (tech == UNKNOWN) return getFd( fd );
1178 
1179  fd.clear();
1181  select1st,
1182  [&](const std::pair<Fd,FileAttr*>& d) { return d.second->tech()==tech; } );
1183 
1184  return fd.size();
1185 
1186 }
constexpr struct select1st_t select1st
T end(T...args)
std::map< Fd, FileAttr * > m_descriptors
Definition: FileMgr.h:157
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 1193 of file FileMgr.cpp.

1193  {
1194 
1195  fd.clear();
1196  transform_if( m_descriptors.begin(), m_descriptors.end(),
1198  [&](const std::pair<Fd,FileAttr*>& d) {
1199  return (d.second->tech() == tech || tech == UNKNOWN) &&
1200  ( d.second->flags() == flags );
1201  } );
1202  return fd.size();
1203 }
constexpr struct select1st_t select1st
T end(T...args)
std::map< Fd, FileAttr * > m_descriptors
Definition: FileMgr.h:157
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 970 of file FileMgr.cpp.

970  {
971 
972  fa.clear();
973 
974  auto fitr = m_files.equal_range(fname);
975  std::transform( fitr.first, fitr.second, std::back_inserter(fa), select2nd );
976 
978  std::back_inserter(fa), [&](const FileAttr* f ) { return f->name() == fname; } );
979 
980  return fa.size();
981 
982 }
T copy_if(T...args)
fileMap m_files
Definition: FileMgr.h:155
T end(T...args)
const std::string & name() const
Definition: IFileMgr.h:185
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:160
T size(T...args)
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:1208
T begin(T...args)
T back_inserter(T...args)
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 1010 of file FileMgr.cpp.

1010  {
1011 
1013  [&](fileMap::const_reference f) { return f.second->fptr() == vp; } );
1014  if (i != std::end(m_files)) {
1015  fa = i->second;
1016  return StatusCode::SUCCESS;
1017  }
1018 
1020  [&](const FileAttr* f) { return f->fptr() == vp; } );
1021  if (j != std::end(m_oldFiles)) {
1022  fa = *j;
1023  return StatusCode::SUCCESS;
1024  }
1025 
1026  return StatusCode::FAILURE;
1027 
1028 }
void * fptr() const
Definition: IFileMgr.h:190
fileMap m_files
Definition: FileMgr.h:155
T end(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:160
T find_if(T...args)
T begin(T...args)
list i
Definition: ana.py:128
int FileMgr::getFiles ( std::vector< std::string > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 1033 of file FileMgr.cpp.

1033  {
1034 
1035  files.clear();
1036  auto not_in_files = [&](const std::string& i) { return std::none_of( std::begin(files), std::end(files),
1037  [&](const std::string& j) { return j==i; } ); };
1038  transform_copy_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1039  to_name,
1040  not_in_files );
1041  if (!op) {
1042  transform_copy_if( std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files),
1043  to_name,
1044  not_in_files );
1045  }
1046  return files.size();
1047 }
fileMap m_files
Definition: FileMgr.h:155
T end(T...args)
STL class.
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:160
T size(T...args)
T begin(T...args)
T back_inserter(T...args)
T none_of(T...args)
list i
Definition: ana.py:128
int FileMgr::getFiles ( std::vector< const Io::FileAttr * > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 1052 of file FileMgr.cpp.

1052  {
1053 
1054  files.clear();
1056  select2nd );
1057  if (!op) {
1059  }
1060  return files.size();
1061 
1062 }
T copy(T...args)
fileMap m_files
Definition: FileMgr.h:155
T end(T...args)
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:160
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 1067 of file FileMgr.cpp.

1067  {
1068 
1069  if (tech == UNKNOWN) return getFiles(files,op);
1070 
1071  files.clear();
1072  transform_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1073  to_name,
1074  [&](fileMap::const_reference f) { return f.second->tech() == tech &&
1075  std::none_of( std::begin(files), std::end(files), [&](const std::string& j) { return j==f.first; } ); } );
1076 
1077  if (!op) {
1078  transform_if( std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files),
1079  to_name,
1080  [&](const FileAttr* f) { return f->tech() == tech &&
1081  std::none_of( std::begin(files), std::end(files), [&](const std::string& j) { return j == f->name(); } ) ; } );
1082  }
1083  return files.size();
1084 
1085 }
fileMap m_files
Definition: FileMgr.h:155
T end(T...args)
STL class.
const std::string & name() const
Definition: IFileMgr.h:185
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:160
T size(T...args)
IoTech tech() const
Definition: IFileMgr.h:187
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:1033
int FileMgr::getFiles ( const Io::IoTech tech,
std::vector< const Io::FileAttr * > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 1090 of file FileMgr.cpp.

1091  {
1092 
1093  if (tech == UNKNOWN) return getFiles(files,op);
1094 
1095  auto matches_tech = [&](const FileAttr* f) { return f->tech()==tech; } ;
1096 
1097  files.clear();
1098  transform_copy_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1099  select2nd, matches_tech );
1100  if (!op) {
1102  matches_tech );
1103  }
1104 
1105  return files.size();
1106 
1107 }
T copy_if(T...args)
fileMap m_files
Definition: FileMgr.h:155
T end(T...args)
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:160
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:1033
int FileMgr::getFiles ( const Io::IoTech tech,
const Io::IoFlags flags,
std::vector< std::string > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 1112 of file FileMgr.cpp.

1113  {
1114 
1115  files.clear();
1116 
1117  auto not_in_files = [&](const std::string& n) { return std::none_of( std::begin(files), std::end(files),
1118  [&](const std::string& f) { return f==n; } ); };
1119  auto matches_tech_and_flags = [&](const FileAttr* f) { return ( f->tech() == tech || tech == UNKNOWN ) && f->flags() == flags ; } ;
1120 
1121  transform_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1122  to_name,
1123  [&](fileMap::const_reference f) { return matches_tech_and_flags( f.second ) && not_in_files( f.first ); } );
1124  if (!op) {
1125  transform_if( std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files),
1126  to_name,
1127  [&](const FileAttr* f) { return matches_tech_and_flags(f) && not_in_files(f->name()); } );
1128  }
1129 
1130  return files.size();
1131 
1132 }
fileMap m_files
Definition: FileMgr.h:155
T end(T...args)
STL class.
const std::string & name() const
Definition: IFileMgr.h:185
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:160
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 1136 of file FileMgr.cpp.

1137  {
1138 
1139  files.clear();
1140 
1141  auto matches_tech_and_flags = [&](const FileAttr* f) { return ( f->tech() == tech || tech == UNKNOWN )
1142  && f->flags() == flags ; } ;
1143 
1144  transform_copy_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1145  select2nd,
1146  matches_tech_and_flags );
1147  if (!op) {
1149  matches_tech_and_flags );
1150  }
1151 
1152  return files.size();
1153 }
T copy_if(T...args)
fileMap m_files
Definition: FileMgr.h:155
T end(T...args)
T clear(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:160
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 1317 of file FileMgr.cpp.

1317  {
1318 
1319  auto fitr = m_files.equal_range(fname);
1320  if (fitr.first == fitr.second) {
1321  error()
1322  << "no file \"" << fname << "\" registered. Cannot determine tech"
1323  << endmsg;
1324  return StatusCode::FAILURE;
1325  }
1326 
1327  auto itr = fitr.first;
1328  IoTech tech = itr->second->tech();
1329 
1330  ++itr;
1331  while( itr != fitr.second ) {
1332  if ( itr->second->tech() != tech ) {
1333  error()
1334  << "multiple technologies registered for file \"" << fname
1335  << "\". Cannot determine handler" << endmsg;
1336  return StatusCode::FAILURE;
1337  }
1338  ++itr;
1339  }
1340 
1341  return getHandler(tech,hdlr);
1342 
1343 }
StatusCode getHandler(const IoTech &, FileHdlr &) const override
IoTech
Definition: IFileMgr.h:150
fileMap m_files
Definition: FileMgr.h:155
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T equal_range(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
int FileMgr::getLastError ( std::string err) const
override

Definition at line 1291 of file FileMgr.cpp.

1291  {
1292 
1293  err = m_lastErrS;
1294  return m_lastErr;
1295 
1296 }
std::string m_lastErrS
Definition: FileMgr.h:167
int m_lastErr
Definition: FileMgr.h:168
void FileMgr::handle ( const Incident )
override

Definition at line 267 of file FileMgr.cpp.

267  {
268 
269 }
StatusCode FileMgr::hasHandler ( const IoTech ) const
override

Definition at line 339 of file FileMgr.cpp.

339  {
340 
341  auto itr = m_handlers.find(tech);
343 
344 }
T end(T...args)
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:156
T find(T...args)
StatusCode FileMgr::initialize ( )
override

Definition at line 105 of file FileMgr.cpp.

105  {
106 
107  // Super ugly hack to make sure we have the OutputLevel set first, so we
108  // can see DEBUG printouts in update handlers.
109  auto jos = serviceLocator()->service<IJobOptionsSvc>( "JobOptionsSvc", true );
110  const auto *props = ( jos ? jos->getProperties( name() ) : nullptr );
111  if (props) {
112  auto prop = std::find_if( std::begin(*props), std::end(*props),
113  [&](const Property* p) {
114  return p->name() == "OutputLevel";
115  });
116  if (prop!=std::end(*props)) {
117  setProperty( **prop ).ignore();
118  }
119  }
120 
121  StatusCode status = Service::initialize();
122 
123  if (status.isFailure()) {
124 
125  ON_DEBUG
126  debug() << "Failed to initialize the base class (Service)"
127  << endmsg;
128  return status;
129  }
130 
131  ON_VERBOSE
132  verbose() << "Initializing FileMgr" << endmsg;
133 
134  if (m_loadRootHandler.value()) {
135 
136  // setup file handler for ROOT
137 
138  msgSvc()->setOutputLevel( "RootFileHandler", m_outputLevel.value());
140 
141  auto rfh = m_rfh.get(); // used in the lambdas to avoid capturing 'this'
142  Io::FileHdlr hdlr(Io::ROOT,
143  [rfh](const std::string& n, const Io::IoFlags& f,
144  const std::string& desc, Io::Fd& fd,
145  void*& ptr) -> Io::open_t {
146  return rfh->openRootFile(n, f, desc, fd, ptr);
147  },
148  [rfh](void* ptr) -> Io::close_t {
149  return rfh->closeRootFile(ptr);
150  },
151  [rfh](void* ptr, const Io::IoFlags& f) -> Io::reopen_t {
152  return rfh->reopenRootFile(ptr, f);
153  });
154 
155  if (regHandler(hdlr).isFailure()) {
156  error()
157  << "unable to register ROOT file handler with FileMgr"
158  << endmsg;
159  }
160  }
161 
162  if (m_loadPosixHandler.value()) {
163 
164  // setup file handler for POSIX
165 
166  msgSvc()->setOutputLevel( "POSIXFileHandler", m_outputLevel.value());
168 
169  auto pfh = m_pfh.get(); // used in the lambdas to avoid capturing 'this'
170  Io::FileHdlr hdlp(Io::POSIX,
171  [pfh](const std::string& n, const Io::IoFlags& f,
172  const std::string& desc, Io::Fd& fd,
173  void*& ptr) -> Io::open_t {
174  return pfh->openPOSIXFile(n, f, desc, fd, ptr);
175  },
176  [pfh](Io::Fd fd) -> Io::close_t {
177  return pfh->closePOSIXFile(fd);
178  },
179  [pfh](Io::Fd fd, const Io::IoFlags& f) -> Io::reopen_t {
180  return pfh->reopenPOSIXFile(fd, f);
181  });
182 
183  if (regHandler(hdlp).isFailure()) {
184  error()
185  << "unable to register ROOT file handler with FileMgr"
186  << endmsg;
187  }
188  }
189 
190 
191 
192  return StatusCode::SUCCESS;
193 
194 }
StatusCode regHandler(FileHdlr) override
Definition: FileMgr.cpp:274
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:1231
StatusCode initialize() override
Definition: Service.cpp:68
IntegerProperty m_outputLevel
Service output level.
Definition: Service.h:309
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
const std::string & name() const
property name
Definition: Property.h:45
int reopen_t
Definition: IFileMgr.h:254
int Fd
Definition: IFileMgr.h:172
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
StatusCode setProperty(const Property &p) override
Definition: Service.cpp:330
int open_t
Definition: IFileMgr.h:252
T end(T...args)
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
std::unique_ptr< RootFileHandler > m_rfh
Definition: FileMgr.h:170
STL class.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Main interface for the JobOptions service.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::unique_ptr< POSIXFileHandler > m_pfh
Definition: FileMgr.h:171
T reset(T...args)
const TYPE & value() const
explicit conversion
Definition: Property.h:341
BooleanProperty m_loadRootHandler
Definition: FileMgr.h:134
T get(T...args)
T find_if(T...args)
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
BooleanProperty m_loadPosixHandler
Definition: FileMgr.h:134
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
T begin(T...args)
StringProperty m_ssl_cert
Definition: FileMgr.h:135
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
#define ON_DEBUG
Definition: FileMgr.cpp:11
void ignore() const
Definition: StatusCode.h:108
StringProperty m_ssl_proxy
Definition: FileMgr.h:135
#define ON_VERBOSE
Definition: FileMgr.cpp:12
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
int close_t
Definition: IFileMgr.h:253
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 1387 of file FileMgr.cpp.

1387  {
1388 
1389  info() << "listing registered actions" << endl;
1390 
1391  for (const auto& iit : m_actions) {
1392  Io::IoTech t = iit.first;
1393  const actionMap& m = iit.second;
1394 
1395  if (!m.empty()) {
1396  info() << " --- Tech: ";
1397  if (t == Io::UNKNOWN) {
1398  info() << "ALL ---" << endl;
1399  } else {
1400  info() << t << " ---" << endl;
1401  }
1402  for (const auto& iia : m ) {
1403  for (const auto& it2 : iia.second ) {
1404  info() << " " << iia.first << " "
1405  << it2.second << endl;
1406  }
1407  }
1408  }
1409  }
1410  info() << endmsg;
1411 }
IoTech
Definition: IFileMgr.h:150
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
T endl(T...args)
std::map< Io::Action, std::list< bfcn_desc_t > > actionMap
Definition: FileMgr.h:143
constexpr double m
Definition: SystemOfUnits.h:93
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::map< IoTech, actionMap > m_actions
Definition: FileMgr.h:162
void FileMgr::listFiles ( ) const
override

Definition at line 1276 of file FileMgr.cpp.

1276  {
1277 
1278  info() << "listing registered files ["
1279  << (m_files.size() + m_oldFiles.size() )
1280  << "]:" << endl;
1281 
1282  for (auto& itr : m_files ) info() << itr.second << endl;
1283  for (auto& it2 : m_oldFiles ) info() << *it2 << endl;
1284 
1285  info() << endmsg;
1286 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
fileMap m_files
Definition: FileMgr.h:155
T endl(T...args)
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:160
T size(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void FileMgr::listHandlers ( ) const
override

Definition at line 1348 of file FileMgr.cpp.

1348  {
1349 
1350  info()
1351  << "Listing registered handlers:" << endl;
1352 
1353  for (const auto& itr : m_handlers ) info() << " " << itr.first << endl;
1354  info() << endmsg;
1355 
1356 }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
T endl(T...args)
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:156
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void FileMgr::listSuppression ( ) const
virtual

Definition at line 1537 of file FileMgr.cpp.

1537  {
1538 
1539  if (m_supMap.empty()) return;
1540 
1541  info() << "listing suppressed file actions" << endl;
1542 
1543  for (auto it2=m_supMap.begin(); it2 != m_supMap.end(); ++it2) {
1544  info() << " " << it2->first;
1545  if (get_bit(it2->second, Io::INVALID_ACTION)) {
1546  info() << " ALL" << endl;
1547  } else {
1548  for (int i=0; i<Io::INVALID_ACTION; ++i) {
1549  if (get_bit(it2->second,i)) { info() << " " << (Io::Action)i; }
1550  }
1551  info() << endl;
1552  }
1553  }
1554 
1555  info() << endmsg;
1556 }
T empty(T...args)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
supMap m_supMap
Definition: FileMgr.h:165
T endl(T...args)
T end(T...args)
Action
Definition: IFileMgr.h:290
T begin(T...args)
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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 349 of file FileMgr.cpp.

352  {
353 
354  return open(tech, caller, fname, desc, flags, fd, ptr, sh);
355 
356 }
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:1231
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:349
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 360 of file FileMgr.cpp.

363  {
364 
365  void* dummy(0);
366  return open(tech, caller, fname, desc, flags, fd, dummy, sh);
367 
368 }
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:1231
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:349
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 372 of file FileMgr.cpp.

375  {
376 
377  Fd dummy(-1);
378  return open(tech, caller, fname, desc, flags, dummy, ptr, sh);
379 
380 }
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:349
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 1361 of file FileMgr.cpp.

1361  {
1362 
1363  return regAction(bf,a,Io::UNKNOWN,d);
1364 
1365 }
StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &desc="") override
Definition: FileMgr.cpp:1361
StatusCode FileMgr::regAction ( Io::bfcn_action_t  bf,
const Io::Action a,
const Io::IoTech t,
const std::string desc = "" 
)
override

Definition at line 1370 of file FileMgr.cpp.

1371  {
1372 
1373  ON_DEBUG
1374  debug() << "registering " << a << " action "
1376  << " for tech " << t << endmsg;
1377 
1378  m_actions[t][a].emplace_back(bf, (!d.empty()) ? d
1380  return StatusCode::SUCCESS;
1381 
1382 }
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:297
T target_type(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
#define ON_DEBUG
Definition: FileMgr.cpp:11
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::map< IoTech, actionMap > m_actions
Definition: FileMgr.h:162
StatusCode FileMgr::regHandler ( FileHdlr  fh)
override

Definition at line 274 of file FileMgr.cpp.

274  {
275 
276  IoTech tech = fh.tech;
277 
278  if (m_handlers.find(tech) != m_handlers.end()) {
279  warning()
280  << "Handler for IoTech " << tech << " already registered. Ignoring."
281  << endmsg;
282  return StatusCode::SUCCESS;
283  }
284 
285  if ( ! fh.b_open_fcn ) {
286  error()
287  << "open handler for tech " << tech << " is NULL"
288  << endmsg;
289  return StatusCode::FAILURE;
290  }
291 
292  if ( ! fh.b_close_fcn && ! fh.b_closeP_fcn ) {
293  error()
294  << "no close handler for tech " << tech << " registered"
295  << endmsg;
296  return StatusCode::FAILURE;
297  }
298 
299  if ( ! fh.b_reopen_fcn && ! fh.b_reopenP_fcn) {
300  error()
301  << "no reopen handler for tech " << tech << " registered"
302  << endmsg;
303  return StatusCode::FAILURE;
304  }
305 
306 
307  ON_DEBUG
308  debug()
309  << "Successfully registered handler for tech \"" << tech << "\""
310  << endmsg;
311 
312  m_handlers[tech] = fh;
313 
314  return StatusCode::SUCCESS;
315 
316 }
IoTech
Definition: IFileMgr.h:150
bfcn_reopen_t b_reopen_fcn
Definition: IFileMgr.h:269
T end(T...args)
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:156
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:267
bfcn_closeP_t b_closeP_fcn
Definition: IFileMgr.h:268
bfcn_reopenP_t b_reopenP_fcn
Definition: IFileMgr.h:270
T find(T...args)
bfcn_open_t b_open_fcn
Definition: IFileMgr.h:266
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
#define ON_DEBUG
Definition: FileMgr.cpp:11
IoTech tech
Definition: IFileMgr.h:264
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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 890 of file FileMgr.cpp.

890  {
891  ON_VERBOSE
892  verbose() << "reopen(" << vp << "," << flags
893  << "," << caller << ")"
894  << endmsg;
895 
896  reopen_t r = -1;
897 
899  [&](fileMap::const_reference f) {
900  return f.second->fptr() == vp ; } );
901  if (itr == m_files.end()) {
902  error()
903  << "unregistered file ptr \"" << vp
904  << "\" when calling reopen()"
905  << endmsg;
906  return r;
907  }
908 
909  FileAttr *fa = itr->second;
910  FileHdlr fh;
911  IoTech tech = fa->tech();
912 
913  if (getHandler(tech,fh).isFailure()) {
914  return r;
915  }
916 
917  if ( ! fh.b_reopenP_fcn ) {
918  error() << "no reopen(" << tech << ",void*) function registered"
919  << endmsg;
920  return -1;
921  }
922 
923  try {
924  r = fh.b_reopenP_fcn(vp,flags);
925  } catch (const std::bad_function_call& err) {
926  error() << "when calling reopen handler for " << tech
927  << " on file " << fa->name() << " with flags "
928  << flags
929  << " caught " << err.what() << endmsg;
930  return -1;
931  } catch (...) {
932  error() << "when calling reopen handler for " << tech
933  << " on file " << fa->name() << " with flags "
934  << flags
935  << " caught an unknown exception." << endmsg;
936  return -1;
937  }
938 
939  if (r < 0) {
940  warning()
941  << "reopen of file with ptr \"" << vp
942  << "\", name: \"" << fa->name()
943  << "\", tech: \"" << tech
944  << "\", flags: \"" << flags << "\" failed"
945  << endmsg;
946 
947  execAction(fa, caller, Io::REOPEN_ERR ).ignore();
948 
949  return r;
950 
951  }
952 
953  fa->isOpen(true);
954  fa->flags(flags);
955 
956  // exec all callbacks
957  if (execAction(fa, caller, Io::REOPEN).isFailure()) {
958  warning()
959  << "at least one reopen callback action failed"
960  << endmsg;
961  }
962 
963  return r;
964 
965 }
StatusCode getHandler(const IoTech &, FileHdlr &) const override
IoTech
Definition: IFileMgr.h:150
int reopen_t
Definition: IFileMgr.h:254
fileMap m_files
Definition: FileMgr.h:155
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
bool isOpen() const
Definition: IFileMgr.h:191
StatusCode execAction(Io::FileAttr *, const std::string &, const Io::Action &) const
Definition: FileMgr.cpp:1416
T end(T...args)
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
const std::string & name() const
Definition: IFileMgr.h:185
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
bfcn_reopenP_t b_reopenP_fcn
Definition: IFileMgr.h:270
T find_if(T...args)
IoTech tech() const
Definition: IFileMgr.h:187
T begin(T...args)
void ignore() const
Definition: StatusCode.h:108
IoFlags flags() const
Definition: IFileMgr.h:188
#define ON_VERBOSE
Definition: FileMgr.cpp:12
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void FileMgr::suppressAction ( const std::string f)
override

Definition at line 1512 of file FileMgr.cpp.

1512  {
1513 
1515 
1516 }
void suppressAction(const std::string &) override
Definition: FileMgr.cpp:1512
void FileMgr::suppressAction ( const std::string f,
const Io::Action a 
)
override

Definition at line 1521 of file FileMgr.cpp.

1521  {
1522 
1523  auto it2 = m_supMap.find(f);
1524  if (it2 == m_supMap.end()) {
1525  int b(0);
1526  set_bit(b,a);
1527  m_supMap[f] = b;
1528  } else {
1529  set_bit(it2->second, a);
1530  }
1531 
1532 }
supMap m_supMap
Definition: FileMgr.h:165
T end(T...args)
T find(T...args)

Member Data Documentation

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

Definition at line 162 of file FileMgr.h.

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

Definition at line 158 of file FileMgr.h.

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

Definition at line 157 of file FileMgr.h.

fileMap FileMgr::m_files
private

Definition at line 155 of file FileMgr.h.

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

Definition at line 156 of file FileMgr.h.

int FileMgr::m_lastErr
private

Definition at line 168 of file FileMgr.h.

std::string FileMgr::m_lastErrS
private

Definition at line 167 of file FileMgr.h.

BooleanProperty FileMgr::m_loadPosixHandler
private

Definition at line 134 of file FileMgr.h.

BooleanProperty FileMgr::m_loadRootHandler
private

Definition at line 134 of file FileMgr.h.

StringProperty FileMgr::m_logfile
private

Definition at line 133 of file FileMgr.h.

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

Definition at line 160 of file FileMgr.h.

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

Definition at line 171 of file FileMgr.h.

BooleanProperty FileMgr::m_printSummary
private

Definition at line 134 of file FileMgr.h.

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

Definition at line 170 of file FileMgr.h.

StringProperty FileMgr::m_ssl_cert
private

Definition at line 135 of file FileMgr.h.

StringProperty FileMgr::m_ssl_proxy
private

Definition at line 135 of file FileMgr.h.

supMap FileMgr::m_supMap
private

Definition at line 165 of file FileMgr.h.


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