All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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::string & fname (const Io::Fd &) const override
 
const std::string & fname (void *) const override
 
Io::Fd fd (const std::string &) const override
 
Io::Fd fd (void *) const override
 
void * fptr (const std::string &) const override
 
void * fptr (const Io::Fd &) const override
 
int getLastError (std::string &) const override
 
Io::open_t open (const Io::IoTech &, const std::string &caller, const std::string &fname, const Io::IoFlags &, Io::Fd &fd, void *&ptr, const std::string &desc="", const bool shared=false) override
 
Io::open_t open (const Io::IoTech &, const std::string &caller, const std::string &fname, const Io::IoFlags &, Io::Fd &, const std::string &desc="", const bool shared=false) override
 
Io::open_t open (const Io::IoTech &, const std::string &caller, const std::string &fname, const Io::IoFlags &, void *&, const std::string &desc="", const bool shared=false) override
 
Io::close_t close (const Fd, const std::string &caller) override
 
Io::close_t close (void *, const std::string &caller) override
 
Io::reopen_t reopen (const Fd, const IoFlags &, const std::string &caller) override
 
Io::reopen_t reopen (void *, const IoFlags &, const std::string &caller) override
 
StatusCode regAction (Io::bfcn_action_t, const Io::Action &, const std::string &desc="") override
 
StatusCode regAction (Io::bfcn_action_t, const Io::Action &, const Io::IoTech &, const std::string &desc="") override
 
void suppressAction (const std::string &) override
 
void suppressAction (const std::string &, const Io::Action &) override
 
- Public Member Functions inherited from extends< BASE, Interfaces >
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::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
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::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Types

typedef std::pair< Io::bfcn_action_t, std::string > bfcn_desc_t
 
typedef std::map< Io::Action, std::list< bfcn_desc_t > > actionMap
 
typedef std::multimap< std::string, FileAttr * > fileMap
 
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
 
MsgStream m_log
 

Additional Inherited Members

- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
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 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...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Detailed Description

Definition at line 32 of file FileMgr.h.

Member Typedef Documentation

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

Definition at line 142 of file FileMgr.h.

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

Definition at line 141 of file FileMgr.h.

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

Definition at line 152 of file FileMgr.h.

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

Definition at line 163 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  m_log(msgSvc(), name )
81  {
82 
83  declareProperty("LogFile",m_logfile="");
84  declareProperty("PrintSummary",m_printSummary=false);
85  declareProperty("LoadROOTHandler", m_loadRootHandler=true);
86  declareProperty("LoadPOSIXHandler", m_loadPosixHandler=true);
87 
88  declareProperty("TSSL_UserProxy", m_ssl_proxy="X509");
89  declareProperty("TSSL_CertDir", m_ssl_cert="X509");
90 
91  m_lastErrS = "";
92 
93 }
StringProperty m_logfile
Definition: FileMgr.h:132
MsgStream m_log
Definition: FileMgr.h:171
extends base_class
Typedef to this class.
Definition: extends.h:14
BooleanProperty m_printSummary
Definition: FileMgr.h:133
std::string m_lastErrS
Definition: FileMgr.h:166
BooleanProperty m_loadRootHandler
Definition: FileMgr.h:133
BooleanProperty m_loadPosixHandler
Definition: FileMgr.h:133
StringProperty m_ssl_cert
Definition: FileMgr.h:134
StringProperty m_ssl_proxy
Definition: FileMgr.h:134
FileMgr::~FileMgr ( )
override

Definition at line 97 of file FileMgr.cpp.

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

Member Function Documentation

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

Definition at line 1499 of file FileMgr.cpp.

1500  {
1501 
1502  ON_VERBOSE
1503  m_log << MSG::VERBOSE << "accessMatch old: " << fold
1504  << " new: " << fnew
1505  << endmsg;
1506 
1507  return ( ((fold == Io::READ) && (fnew == Io::READ)) ||
1508  ( (fold & Io::WRITE) != 0 && (fnew & Io::WRITE) != 0) ||
1509  ( (fold & Io::RDWR) != 0 && (fnew & Io::RDWR) != 0) ) ;
1510 
1511 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MsgStream m_log
Definition: FileMgr.h:171
#define ON_VERBOSE
Definition: FileMgr.cpp:12
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 685 of file FileMgr.cpp.

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

Definition at line 325 of file FileMgr.cpp.

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

Definition at line 1420 of file FileMgr.cpp.

1421  {
1422 
1423  Io::IoTech tech = fa->tech();
1424 
1425  StatusCode s1,s2;
1426 
1427  auto itr = m_actions.find(Io::UNKNOWN);
1428 
1429  if (itr != m_actions.end() && !itr->second.empty() ) {
1430  s1 = execActs(fa, caller, a, itr->second);
1431  }
1432 
1433  itr = m_actions.find(tech);
1434  if (itr != m_actions.end() && !itr->second.empty() ) {
1435  s2 = execActs(fa, caller, a, itr->second);
1436  }
1437 
1438  return (s1.isFailure() || s2.isFailure()) ? StatusCode::FAILURE
1440 }
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:1445
IoTech tech() const
Definition: IFileMgr.h:187
std::map< IoTech, actionMap > m_actions
Definition: FileMgr.h:161
StatusCode FileMgr::execActs ( Io::FileAttr fa,
const std::string &  caller,
const Io::Action a,
const actionMap m 
) const
private

Definition at line 1445 of file FileMgr.cpp.

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

Definition at line 1235 of file FileMgr.cpp.

1235  {
1236 
1237  auto fitr = m_files.equal_range(fname);
1238  auto itr = std::find_if( fitr.first, fitr.second, [](fileMap::const_reference f) {
1239  return f.second->fd() != -1;
1240  } );
1241  return itr!=fitr.second ? itr->second->fd() : -1 ;
1242 }
fileMap m_files
Definition: FileMgr.h:154
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:1212
Io::Fd FileMgr::fd ( void *  fptr) const
override

Definition at line 1247 of file FileMgr.cpp.

1247  {
1248 
1249  auto itr = std::find_if(m_files.begin(),m_files.end(),[&](fileMap::const_reference f) {
1250  return f.second->fptr() == fptr;
1251  } );
1252  return itr!=m_files.end() ? itr->second->fd() : -1 ;
1253 }
fileMap m_files
Definition: FileMgr.h:154
void * fptr(const std::string &) const override
Definition: FileMgr.cpp:1258
StatusCode FileMgr::finalize ( )
override

Definition at line 202 of file FileMgr.cpp.

202  {
203  ON_VERBOSE
204  m_log << MSG::VERBOSE << "FileMgr::finalize()" << endmsg;
205 
206 
207  if (m_printSummary || outputLevel() <= MSG::DEBUG) {
208  listHandlers();
209  listFiles();
210  listActions();
211  listSuppression();
212  }
213 
214 
215  if (!m_files.empty()) {
217  << "At finalize, the following files remained open:"
218  << endl;
219  for (const auto& itr : m_files) m_log << *(itr.second) << endl;
220  m_log << endmsg;
221  }
222 
223  if (m_logfile.value() != "") {
224  std::ofstream ofs;
225  ofs.open(m_logfile.value().c_str());
226  if (!ofs) {
227  m_log << MSG::ERROR << "Unable to open output file \"" << m_logfile.value()
228  << "\" for writing"
229  << endmsg;
230  } else {
231  ON_DEBUG
232  m_log << MSG::DEBUG << "Saving log to \"" << m_logfile.value() << "\""
233  << endmsg;
234  for (const auto& itr : m_files) {
235  ofs << itr.second->name() << " " << itr.second->tech() << " "
236  << itr.second->desc() << " " << itr.second->iflags() << endl;
237  }
238 
239  set<FileAttr> fs;
240  for (const auto& it2 : m_oldFiles) fs.insert(*it2);
241  for (const auto& it3 : fs ) {
242  ofs << it3.name() << " " << it3.tech() << " " << it3.desc()
243  << " " << it3.iflags()
244  << ( it3.isShared() ? " SHARED" : "" )
245  << endl;
246  }
247  ofs.close();
248  }
249  }
250 
251  // cleanup FileAttrs
252  m_attr.clear();
253 
254  m_rfh.reset();
255  m_pfh.reset();
256 
257 
258  StatusCode status = Service::finalize();
259 
260  ON_DEBUG
261  if ( status.isSuccess() )
262  m_log << MSG::DEBUG << "Service finalised successfully" << endmsg;
263 
264  return status;
265 
266 }
std::vector< std::unique_ptr< FileAttr > > m_attr
Definition: FileMgr.h:157
StringProperty m_logfile
Definition: FileMgr.h:132
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode finalize() override
Definition: Service.cpp:188
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
MsgStream m_log
Definition: FileMgr.h:171
fileMap m_files
Definition: FileMgr.h:154
std::unique_ptr< RootFileHandler > m_rfh
Definition: FileMgr.h:169
virtual void listActions() const
Definition: FileMgr.cpp:1391
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
BooleanProperty m_printSummary
Definition: FileMgr.h:133
std::unique_ptr< POSIXFileHandler > m_pfh
Definition: FileMgr.h:170
const TYPE & value() const
explicit conversion
Definition: Property.h:341
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:159
virtual void listSuppression() const
Definition: FileMgr.cpp:1541
#define ON_DEBUG
Definition: FileMgr.cpp:11
void listFiles() const override
Definition: FileMgr.cpp:1280
void listHandlers() const override
Definition: FileMgr.cpp:1352
#define ON_VERBOSE
Definition: FileMgr.cpp:12
const std::string & FileMgr::fname ( const Io::Fd fd) const
override

Definition at line 1212 of file FileMgr.cpp.

1212  {
1213 
1214  auto itr = std::find_if( std::begin(m_files), std::end(m_files),
1215  [&](fileMap::const_reference f) { return f.second->fd() == fd; } );
1216  return (itr!=std::end(m_files)) ? itr->second->name() : s_empty;
1217 
1218 }
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:1235
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
fileMap m_files
Definition: FileMgr.h:154
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
const std::string & FileMgr::fname ( void *  vp) const
override

Definition at line 1223 of file FileMgr.cpp.

1223  {
1224 
1225  auto itr = std::find_if( m_files.begin(), m_files.end(),
1226  [&](fileMap::const_reference f) {
1227  return f.second->fptr() == vp;
1228  });
1229  return itr!=m_files.end() ? itr->second->name() : s_empty;
1230 }
fileMap m_files
Definition: FileMgr.h:154
void * FileMgr::fptr ( const std::string &  fname) const
override

Definition at line 1258 of file FileMgr.cpp.

1258  {
1259  auto fitr = m_files.equal_range(fname);
1260  auto itr = std::find_if( fitr.first, fitr.second, [](fileMap::const_reference f) -> bool {
1261  return f.second->fptr();
1262  } );
1263  return itr!=fitr.second ? itr->second->fptr() : nullptr;
1264 }
fileMap m_files
Definition: FileMgr.h:154
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:1212
void * FileMgr::fptr ( const Io::Fd fd) const
override

Definition at line 1269 of file FileMgr.cpp.

1269  {
1270 
1271  auto itr = std::find_if(m_files.begin(),m_files.end(),[&](fileMap::const_reference f) {
1272  return f.second->fd() == fd;
1273  } );
1274  return itr!=m_files.end() ? itr->second->fptr() : nullptr;
1275 }
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:1235
fileMap m_files
Definition: FileMgr.h:154
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 1179 of file FileMgr.cpp.

1179  {
1180 
1181  if (tech == UNKNOWN) return getFd( fd );
1182 
1183  fd.clear();
1184  transform_if( std::begin(m_descriptors), std::end(m_descriptors), std::back_inserter(fd),
1185  select1st,
1186  [&](const std::pair<Fd,FileAttr*>& d) { return d.second->tech()==tech; } );
1187 
1188  return fd.size();
1189 
1190 }
constexpr struct select1st_t select1st
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
std::map< Fd, FileAttr * > m_descriptors
Definition: FileMgr.h:156
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
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 1197 of file FileMgr.cpp.

1197  {
1198 
1199  fd.clear();
1200  transform_if( m_descriptors.begin(), m_descriptors.end(),
1201  std::back_inserter(fd), select1st,
1202  [&](const std::pair<Fd,FileAttr*>& d) {
1203  return (d.second->tech() == tech || tech == UNKNOWN) &&
1204  ( d.second->flags() == flags );
1205  } );
1206  return fd.size();
1207 }
constexpr struct select1st_t select1st
std::map< Fd, FileAttr * > m_descriptors
Definition: FileMgr.h:156
int FileMgr::getFileAttr ( const std::string &  fname,
std::vector< const FileAttr * > &  fa 
) const
override

Definition at line 974 of file FileMgr.cpp.

974  {
975 
976  fa.clear();
977 
978  auto fitr = m_files.equal_range(fname);
979  std::transform( fitr.first, fitr.second, std::back_inserter(fa), select2nd );
980 
981  std::copy_if( std::begin(m_oldFiles), std::end(m_oldFiles),
982  std::back_inserter(fa), [&](const FileAttr* f ) { return f->name() == fname; } );
983 
984  return fa.size();
985 
986 }
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
fileMap m_files
Definition: FileMgr.h:154
const std::string & name() const
Definition: IFileMgr.h:185
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:159
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:1212
StatusCode FileMgr::getFileAttr ( const Fd  ,
const FileAttr *&   
) const
override
StatusCode FileMgr::getFileAttr ( void *  vp,
const FileAttr *&  fa 
) const
override

Definition at line 1014 of file FileMgr.cpp.

1014  {
1015 
1016  auto i = std::find_if( std::begin(m_files), std::end(m_files),
1017  [&](fileMap::const_reference f) { return f.second->fptr() == vp; } );
1018  if (i != std::end(m_files)) {
1019  fa = i->second;
1020  return StatusCode::SUCCESS;
1021  }
1022 
1023  auto j = std::find_if( std::begin(m_oldFiles), std::end(m_oldFiles),
1024  [&](const FileAttr* f) { return f->fptr() == vp; } );
1025  if (j != std::end(m_oldFiles)) {
1026  fa = *j;
1027  return StatusCode::SUCCESS;
1028  }
1029 
1030  return StatusCode::FAILURE;
1031 
1032 }
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
void * fptr() const
Definition: IFileMgr.h:190
fileMap m_files
Definition: FileMgr.h:154
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:159
list i
Definition: ana.py:128
int FileMgr::getFiles ( std::vector< std::string > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 1037 of file FileMgr.cpp.

1037  {
1038 
1039  files.clear();
1040  auto not_in_files = [&](const std::string& i) { return std::none_of( std::begin(files), std::end(files),
1041  [&](const std::string& j) { return j==i; } ); };
1042  transform_copy_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1043  to_name,
1044  not_in_files );
1045  if (!op) {
1046  transform_copy_if( std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files),
1047  to_name,
1048  not_in_files );
1049  }
1050  return files.size();
1051 }
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
fileMap m_files
Definition: FileMgr.h:154
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:159
list i
Definition: ana.py:128
int FileMgr::getFiles ( std::vector< const Io::FileAttr * > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 1056 of file FileMgr.cpp.

1056  {
1057 
1058  files.clear();
1059  std::transform(std::begin(m_files), std::end(m_files), std::back_inserter(files),
1060  select2nd );
1061  if (!op) {
1062  std::copy(std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files));
1063  }
1064  return files.size();
1065 
1066 }
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
fileMap m_files
Definition: FileMgr.h:154
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:159
int FileMgr::getFiles ( const Io::IoTech tech,
std::vector< std::string > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 1071 of file FileMgr.cpp.

1071  {
1072 
1073  if (tech == UNKNOWN) return getFiles(files,op);
1074 
1075  files.clear();
1076  transform_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1077  to_name,
1078  [&](fileMap::const_reference f) { return f.second->tech() == tech &&
1079  std::none_of( std::begin(files), std::end(files), [&](const std::string& j) { return j==f.first; } ); } );
1080 
1081  if (!op) {
1082  transform_if( std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files),
1083  to_name,
1084  [&](const FileAttr* f) { return f->tech() == tech &&
1085  std::none_of( std::begin(files), std::end(files), [&](const std::string& j) { return j == f->name(); } ) ; } );
1086  }
1087  return files.size();
1088 
1089 }
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
fileMap m_files
Definition: FileMgr.h:154
const std::string & name() const
Definition: IFileMgr.h:185
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:159
IoTech tech() const
Definition: IFileMgr.h:187
int getFiles(std::vector< std::string > &, bool onlyOpen=true) const override
Definition: FileMgr.cpp:1037
int FileMgr::getFiles ( const Io::IoTech tech,
std::vector< const Io::FileAttr * > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 1094 of file FileMgr.cpp.

1095  {
1096 
1097  if (tech == UNKNOWN) return getFiles(files,op);
1098 
1099  auto matches_tech = [&](const FileAttr* f) { return f->tech()==tech; } ;
1100 
1101  files.clear();
1102  transform_copy_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1103  select2nd, matches_tech );
1104  if (!op) {
1105  std::copy_if( std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files),
1106  matches_tech );
1107  }
1108 
1109  return files.size();
1110 
1111 }
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
fileMap m_files
Definition: FileMgr.h:154
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:159
int getFiles(std::vector< std::string > &, bool onlyOpen=true) const override
Definition: FileMgr.cpp:1037
int FileMgr::getFiles ( const Io::IoTech tech,
const Io::IoFlags flags,
std::vector< std::string > &  files,
bool  onlyOpen = true 
) const
override

Definition at line 1116 of file FileMgr.cpp.

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

1141  {
1142 
1143  files.clear();
1144 
1145  auto matches_tech_and_flags = [&](const FileAttr* f) { return ( f->tech() == tech || tech == UNKNOWN )
1146  && f->flags() == flags ; } ;
1147 
1148  transform_copy_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1149  select2nd,
1150  matches_tech_and_flags );
1151  if (!op) {
1152  std::copy_if( std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files),
1153  matches_tech_and_flags );
1154  }
1155 
1156  return files.size();
1157 }
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
fileMap m_files
Definition: FileMgr.h:154
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:159
StatusCode FileMgr::getHandler ( const IoTech &  ,
FileHdlr  
) const
override
StatusCode FileMgr::getHandler ( const std::string &  fname,
Io::FileHdlr hdlr 
) const
override

Definition at line 1321 of file FileMgr.cpp.

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

Definition at line 1295 of file FileMgr.cpp.

1295  {
1296 
1297  err = m_lastErrS;
1298  return m_lastErr;
1299 
1300 }
std::string m_lastErrS
Definition: FileMgr.h:166
int m_lastErr
Definition: FileMgr.h:167
void FileMgr::handle ( const Incident )
override

Definition at line 271 of file FileMgr.cpp.

271  {
272 
273 }
StatusCode FileMgr::hasHandler ( const IoTech ) const
override

Definition at line 343 of file FileMgr.cpp.

343  {
344 
345  auto itr = m_handlers.find(tech);
346  return (itr != m_handlers.end()) ? StatusCode::SUCCESS : StatusCode::FAILURE;
347 
348 }
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:155
StatusCode FileMgr::initialize ( )
override

Definition at line 106 of file FileMgr.cpp.

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

Definition at line 1391 of file FileMgr.cpp.

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

Definition at line 1280 of file FileMgr.cpp.

1280  {
1281 
1282  m_log << MSG::INFO << "listing registered files ["
1283  << (m_files.size() + m_oldFiles.size() )
1284  << "]:" << endl;
1285 
1286  for (auto& itr : m_files ) m_log << itr.second << endl;
1287  for (auto& it2 : m_oldFiles ) m_log << *it2 << endl;
1288 
1289  m_log << endmsg;
1290 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MsgStream m_log
Definition: FileMgr.h:171
fileMap m_files
Definition: FileMgr.h:154
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:159
void FileMgr::listHandlers ( ) const
override

Definition at line 1352 of file FileMgr.cpp.

1352  {
1353 
1354  m_log << MSG::INFO
1355  << "Listing registered handlers:" << endl;
1356 
1357  for (const auto& itr : m_handlers ) m_log << " " << itr.first << endl;
1358  m_log << endmsg;
1359 
1360 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
MsgStream m_log
Definition: FileMgr.h:171
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:155
void FileMgr::listSuppression ( ) const
virtual

Definition at line 1541 of file FileMgr.cpp.

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

356  {
357 
358  return open(tech, caller, fname, desc, flags, fd, ptr, sh);
359 
360 }
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:1235
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:353
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:1212
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 364 of file FileMgr.cpp.

367  {
368 
369  void* dummy(0);
370  return open(tech, caller, fname, desc, flags, fd, dummy, sh);
371 
372 }
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:1235
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:353
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:1212
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 376 of file FileMgr.cpp.

379  {
380 
381  Fd dummy(-1);
382  return open(tech, caller, fname, desc, flags, dummy, ptr, sh);
383 
384 }
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:353
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:1212
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 1365 of file FileMgr.cpp.

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

Definition at line 1374 of file FileMgr.cpp.

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

Definition at line 278 of file FileMgr.cpp.

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

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

Definition at line 1516 of file FileMgr.cpp.

1516  {
1517 
1519 
1520 }
void suppressAction(const std::string &) override
Definition: FileMgr.cpp:1516
void FileMgr::suppressAction ( const std::string &  f,
const Io::Action a 
)
override

Definition at line 1525 of file FileMgr.cpp.

1525  {
1526 
1527  auto it2 = m_supMap.find(f);
1528  if (it2 == m_supMap.end()) {
1529  int b(0);
1530  set_bit(b,a);
1531  m_supMap[f] = b;
1532  } else {
1533  set_bit(it2->second, a);
1534  }
1535 
1536 }
supMap m_supMap
Definition: FileMgr.h:164

Member Data Documentation

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

Definition at line 161 of file FileMgr.h.

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

Definition at line 157 of file FileMgr.h.

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

Definition at line 156 of file FileMgr.h.

fileMap FileMgr::m_files
private

Definition at line 154 of file FileMgr.h.

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

Definition at line 155 of file FileMgr.h.

int FileMgr::m_lastErr
private

Definition at line 167 of file FileMgr.h.

std::string FileMgr::m_lastErrS
private

Definition at line 166 of file FileMgr.h.

BooleanProperty FileMgr::m_loadPosixHandler
private

Definition at line 133 of file FileMgr.h.

BooleanProperty FileMgr::m_loadRootHandler
private

Definition at line 133 of file FileMgr.h.

MsgStream FileMgr::m_log
mutableprivate

Definition at line 171 of file FileMgr.h.

StringProperty FileMgr::m_logfile
private

Definition at line 132 of file FileMgr.h.

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

Definition at line 159 of file FileMgr.h.

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

Definition at line 170 of file FileMgr.h.

BooleanProperty FileMgr::m_printSummary
private

Definition at line 133 of file FileMgr.h.

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

Definition at line 169 of file FileMgr.h.

StringProperty FileMgr::m_ssl_cert
private

Definition at line 134 of file FileMgr.h.

StringProperty FileMgr::m_ssl_proxy
private

Definition at line 134 of file FileMgr.h.

supMap FileMgr::m_supMap
private

Definition at line 164 of file FileMgr.h.


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