11 #define ON_DEBUG if (msgLevel(MSG::DEBUG))
12 #define ON_VERBOSE if (msgLevel(MSG::VERBOSE))
25 void set_bit(
int& f,
const unsigned int& b) {
29 bool get_bit(
const int& f,
const unsigned int& b) {
35 constexpr
struct to_name_t {
40 constexpr
struct select1st_t {
41 template <
typename T,
typename S>
42 const T& operator()(
const std::pair<T,S>& p)
const {
return p.first; }
45 constexpr
struct select2nd_t {
46 template <
typename T,
typename S>
47 const S& operator()(
const std::pair<T,S>& p)
const {
return p.second; }
50 template <
typename InputIterator,
typename OutputIterator,
typename UnaryOperation,
typename UnaryPredicate>
51 OutputIterator transform_if( InputIterator first, InputIterator last,
52 OutputIterator result,
54 UnaryPredicate pred) {
55 while (first != last) {
56 if (pred(*first)) *result++ = op(*first);
62 template <
typename InputIterator,
typename OutputIterator,
typename UnaryOperation,
typename UnaryPredicate>
63 OutputIterator transform_copy_if( InputIterator first, InputIterator last,
64 OutputIterator result,
66 UnaryPredicate pred) {
67 while (first != last) {
110 const auto *props = ( jos ? jos->getProperties(
name() ) : nullptr );
114 return p->
name() ==
"OutputLevel";
126 debug() <<
"Failed to initialize the base class (Service)"
146 return rfh->openRootFile(n, f, desc, fd, ptr);
149 return rfh->closeRootFile(ptr);
152 return rfh->reopenRootFile(ptr, f);
157 <<
"unable to register ROOT file handler with FileMgr"
174 return pfh->openPOSIXFile(n, f, desc, fd, ptr);
177 return pfh->closePOSIXFile(fd);
180 return pfh->reopenPOSIXFile(fd, f);
185 <<
"unable to register ROOT file handler with FileMgr"
214 log <<
"At finalize, the following files remained open:" <<
endl;
215 for (
const auto& itr :
m_files)
log << *(itr.second) << endl;
230 for (
const auto& itr :
m_files) {
231 ofs << itr.second->name() <<
" " << itr.second->tech() <<
" "
232 << itr.second->desc() <<
" " << itr.second->iflags() <<
endl;
237 for (
const auto& it3 : fs ) {
238 ofs << it3.name() <<
" " << it3.tech() <<
" " << it3.desc()
239 <<
" " << it3.iflags()
240 << ( it3.isShared() ?
" SHARED" :
"" )
258 debug() <<
"Service finalised successfully" <<
endmsg;
280 <<
"Handler for IoTech " << tech <<
" already registered. Ignoring."
287 <<
"open handler for tech " << tech <<
" is NULL"
294 <<
"no close handler for tech " << tech <<
" registered"
301 <<
"no reopen handler for tech " << tech <<
" registered"
309 <<
"Successfully registered handler for tech \"" << tech <<
"\""
326 error() <<
"Can't de-register tech " << tech
327 <<
" as it hasn't been registered!"
351 const IoFlags& flags,
Fd& fd,
void*& ptr,
354 return open(tech, caller, fname, desc, flags, fd, ptr, sh);
366 return open(tech, caller, fname, desc, flags, fd, dummy, sh);
378 return open(tech, caller, fname, desc, flags, dummy, ptr, sh);
388 const IoFlags& flags,
Fd& fd,
void*& ptr,
bool shared) {
407 verbose() <<
"open(" << tech <<
","
409 <<
",\"" << fname <<
"\",\""
412 << ( shared ?
",shared" :
",unshared")
425 auto itr =
std::find_if( fitr.first, fitr.second, [&](fileMap::const_reference
i) { return i.second->tech()!=tech; } );
426 if (itr != fitr.second) {
427 error() <<
"when calling open on " << fname
428 <<
" with tech " << tech
429 <<
", file already opened with different tech "
430 << itr->second->tech()
441 bool shareable(
true);
443 for (
auto itr=fitr.first; itr != fitr.second; ++itr) {
446 if (! fa->
isShared()) shareable =
false;
449 if ( shareable && fa->
flags().
match(flags,
false) ) {
452 debug() <<
" found shared file: "
475 error() <<
"when calling open handler for " << tech
477 << fname <<
" caught " << err.
what() <<
endmsg;
480 error() <<
"when calling open handler for " << tech
482 << fname <<
" caught an unknown exception." <<
endmsg;
488 <<
"open of file \"" << fname <<
"\", tech: \"" << tech
489 <<
"\", flags: \"" << flags <<
"\" requested by "
491 <<
" failed. return code: " << r
494 FileAttr xfa(-1,fname,desc,tech,flags,0,
false);
511 if (fd == -1 && ptr == 0) {
512 warning() <<
"when opening " << *fa <<
" both File Descriptor"
513 <<
" and File Ptr are invalid" <<
endmsg;
518 for (
auto itr = fitr.first; itr != fitr.second; ++itr) {
521 }
else if (*fa == *(itr->second) ) {
522 warning() <<
"open call for file \"" << fname
523 <<
"\" returned a pre-existing file with identical"
524 <<
" FileAttributes: " << *fa <<
endmsg;
527 warning() <<
"open call for file \"" << fname
528 <<
"\" returned a pre-existing file with different"
529 <<
" FileAttributes -"
530 <<
endl <<
"old: " << *(itr->second)
531 << endl <<
"new: " << *fa << endmsg;
541 <<
"at least one open callback action failed"
562 verbose() <<
"close(" << fd <<
")"
569 [&](fileMap::const_reference
i) {
return i.second->fd() ==
fd; } );
573 error() <<
"unknown file descriptor \"" << fd
574 <<
"\" when calling close()"
580 IoTech tech = itr->second->tech();
589 error() <<
"no close(" << tech <<
",Fd) function registered"
598 int i =
std::count_if(fitr.first, fitr.second, [&](fileMap::const_reference f) {
599 return f.second->fd()==fd; } );
602 verbose() <<
" ref count: " << i
609 debug() <<
"closing file " << fa->
name() <<
" opened "
610 << i <<
" times with Fd " << fd <<
endmsg;
615 }
else if (i == 1 || (i>1 && !fa->
isShared()) ) {
623 error() <<
"when calling close handler for " << tech
624 <<
" on file descriptor "
629 error() <<
"when calling close handler for " << tech
630 <<
" on file descriptor "
631 << fd <<
" caught an unknown exception." <<
endmsg;
638 <<
"close of file with FD \"" << fd
639 <<
"\", name: \"" << fa->
name()
640 <<
"\", tech: \"" << tech <<
"\" failed"
653 <<
"ref count < 0 when closing " << fa
654 <<
". This should never happen"
670 <<
"at least one close callback action failed"
690 verbose() <<
"close(" << vp <<
")"
696 [&](fileMap::const_reference i ) {
return i.second->fptr()==vp; } );
699 error() <<
"unknown file ptr \"" << vp
700 <<
"\" when calling close()"
705 IoTech tech = itr->second->tech();
713 error() <<
"no close(" << tech <<
",void*) function registered"
724 int i =
std::count_if( fitr.first, fitr.second, [&](fileMap::const_reference f)
725 { return f.second->fptr()==vp; } );
728 verbose() <<
" ref count: " << i
734 debug() <<
"closing file " << fa->
name() <<
" opened "
735 << i <<
" times with fptr " << vp <<
endmsg;
740 }
else if (i == 1 || (i>1 && !fa->
isShared()) ) {
747 error() <<
"when calling close handler for " << tech
748 <<
" on file " << fa->
name()
753 error() <<
"when calling close handler for " << tech
754 <<
" on file " << fa->
name()
755 <<
" caught an unknown exception." <<
endmsg;
762 <<
"close of file with ptr \"" << vp
763 <<
"\", name: \"" << fa->
name()
764 <<
"\", tech: \"" << tech <<
"\" failed"
775 <<
"ref count: " << i <<
" < 0 when closing " << fa
776 <<
". This should never happen"
792 <<
"at least one close callback action failed"
806 verbose() <<
"reopen(" << fd <<
"," << flags
807 <<
"," << caller <<
")"
814 {
return f.second->fd() ==
fd; } );
817 error() <<
"unregistered FD \"" << fd
818 <<
"\" when calling reopen()"
835 error() <<
"no reopen(" << tech <<
",Fd) function registered"
846 error() <<
"when calling reopen handler for " << tech
847 <<
" on file descriptor " << fd <<
" with flags "
852 error() <<
"when calling reopen handler for " << tech
853 <<
" on file descriptor " << fd <<
" with flags "
855 <<
" caught an unknown exception." <<
endmsg;
861 <<
"reopen of file with FD \"" << fd
862 <<
"\", name: \"" << fa->
name()
863 <<
"\", tech: \"" << tech
864 <<
"\", flags: \"" << flags <<
"\" failed"
879 <<
"at least one reopen callback action failed"
892 verbose() <<
"reopen(" << vp <<
"," << flags
893 <<
"," << caller <<
")"
899 [&](fileMap::const_reference f) {
900 return f.second->fptr() == vp ; } );
903 <<
"unregistered file ptr \"" << vp
904 <<
"\" when calling reopen()"
918 error() <<
"no reopen(" << tech <<
",void*) function registered"
926 error() <<
"when calling reopen handler for " << tech
927 <<
" on file " << fa->
name() <<
" with flags "
932 error() <<
"when calling reopen handler for " << tech
933 <<
" on file " << fa->
name() <<
" with flags "
935 <<
" caught an unknown exception." <<
endmsg;
941 <<
"reopen of file with ptr \"" << vp
942 <<
"\", name: \"" << fa->
name()
943 <<
"\", tech: \"" << tech
944 <<
"\", flags: \"" << flags <<
"\" failed"
959 <<
"at least one reopen callback action failed"
990 [&](fileMap::const_reference f ) {
return f.second->fd() ==
fd; } );
1013 [&](fileMap::const_reference f) {
return f.second->fptr() == vp; } );
1046 return files.
size();
1060 return files.
size();
1074 [&](fileMap::const_reference f) {
return f.second->tech() == tech &&
1083 return files.
size();
1095 auto matches_tech = [&](
const FileAttr* f) {
return f->
tech()==tech; } ;
1099 select2nd, matches_tech );
1105 return files.
size();
1119 auto matches_tech_and_flags = [&](
const FileAttr* f) {
return ( f->
tech() == tech || tech ==
UNKNOWN ) && f->
flags() == flags ; } ;
1123 [&](fileMap::const_reference f) {
return matches_tech_and_flags( f.second ) && not_in_files( f.first ); } );
1127 [&](
const FileAttr* f) {
return matches_tech_and_flags(f) && not_in_files(f->
name()); } );
1130 return files.
size();
1141 auto matches_tech_and_flags = [&](
const FileAttr* f) {
return ( f->
tech() == tech || tech ==
UNKNOWN )
1142 && f->
flags() == flags ; } ;
1146 matches_tech_and_flags );
1149 matches_tech_and_flags );
1152 return files.
size();
1199 return (d.second->tech() == tech || tech ==
UNKNOWN) &&
1200 ( d.second->flags() == flags );
1211 [&](fileMap::const_reference f) {
return f.second->fd() ==
fd; } );
1222 [&](fileMap::const_reference f) {
1223 return f.second->
fptr() == vp;
1234 auto itr =
std::find_if( fitr.first, fitr.second, [](fileMap::const_reference f) {
1235 return f.second->fd() != -1;
1237 return itr!=fitr.second ? itr->second->fd() : -1 ;
1256 auto itr =
std::find_if( fitr.first, fitr.second, [](fileMap::const_reference f) ->
bool {
1257 return f.second->fptr();
1259 return itr!=fitr.second ? itr->second->fptr() :
nullptr;
1268 return f.second->
fd() ==
fd;
1278 info() <<
"listing registered files ["
1306 <<
"no handler for tech " << tech <<
" registered"
1320 if (fitr.first == fitr.second) {
1322 <<
"no file \"" << fname <<
"\" registered. Cannot determine tech"
1327 auto itr = fitr.first;
1328 IoTech tech = itr->second->tech();
1331 while( itr != fitr.second ) {
1332 if ( itr->second->tech() != tech ) {
1334 <<
"multiple technologies registered for file \"" << fname
1335 <<
"\". Cannot determine handler" <<
endmsg;
1351 <<
"Listing registered handlers:" <<
endl;
1374 debug() <<
"registering " << a <<
" action "
1376 <<
" for tech " << t << endmsg;
1389 info() <<
"listing registered actions" <<
endl;
1396 info() <<
" --- Tech: ";
1402 for (
const auto& iia : m ) {
1403 for (
const auto& it2 : iia.second ) {
1404 info() <<
" " << iia.first <<
" "
1405 << it2.second <<
endl;
1425 if (itr !=
m_actions.end() && !itr->second.empty() ) {
1426 s1 =
execActs(fa, caller, a, itr->second);
1430 if (itr !=
m_actions.end() && !itr->second.empty() ) {
1431 s2 =
execActs(fa, caller, a, itr->second);
1444 auto mitr = m.
find(a);
1446 if (mitr == m.
end() || mitr->second.empty()) {
1452 <<
"executing " << mitr->second.size() <<
" " << a
1465 debug() <<
" --> suppressing callback action for "
1472 for (
const auto& itr : mitr->second ) {
1475 debug() <<
"executing "
1478 if ( (((itr.first))(fa,caller)).isFailure() ) {
1480 << itr.second <<
" on " << *fa
1481 <<
" failed during " << a <<
" action"
1499 verbose() <<
"accessMatch old: " << fold
1504 ( (fold &
Io::WRITE) != 0 && (fnew & Io::WRITE) != 0) ||
1505 ( (fold &
Io::RDWR) != 0 && (fnew & Io::RDWR) != 0) ) ;
1529 set_bit(it2->second, a);
1541 info() <<
"listing suppressed file actions" <<
endl;
1544 info() <<
" " << it2->first;
std::vector< std::unique_ptr< FileAttr > > m_attr
StatusCode regHandler(FileHdlr) override
StatusCode getHandler(const IoTech &, FileHdlr &) const override
Io::Fd fd(const std::string &) const override
StatusCode initialize() override
IntegerProperty m_outputLevel
Service output level.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
StatusCode finalize() override
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
const std::string & name() const
property name
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
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
constexpr struct select1st_t select1st
bfcn_reopen_t b_reopen_fcn
void suppressAction(const std::string &) override
bool isSuccess() const
Test for a status code of SUCCESS.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
StatusCode setProperty(const Property &p) override
int getLastError(std::string &) const override
StatusCode deregHandler(const IoTech &) override
StatusCode execAction(Io::FileAttr *, const std::string &, const Io::Action &) const
std::map< Fd, FileAttr * > m_descriptors
StatusCode hasHandler(const IoTech &) const override
bool isFailure() const
Test for a status code of FAILURE.
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
bool accessMatch(const Io::IoFlags &, const Io::IoFlags &, bool strict=false) const
std::unique_ptr< RootFileHandler > m_rfh
virtual void listActions() const
const std::string & name() const
std::map< IoTech, FileHdlr > m_handlers
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
const std::string & name() const override
Retrieve name of the service.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Main interface for the JobOptions service.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
void handle(const Incident &) override
This class is used for returning status codes from appropriate routines.
Io::reopen_t reopen(const Fd, const IoFlags &, const std::string &caller) override
StatusCode execActs(Io::FileAttr *, const std::string &, const Io::Action &, const actionMap &m) const
bfcn_closeP_t b_closeP_fcn
BooleanProperty m_printSummary
Io::close_t close(const Fd, const std::string &caller) override
std::unique_ptr< POSIXFileHandler > m_pfh
bfcn_reopenP_t b_reopenP_fcn
int getFileAttr(const std::string &, std::vector< const FileAttr * > &) const override
#define DECLARE_SERVICE_FACTORY(x)
const TYPE & value() const
explicit conversion
StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &desc="") override
FileMgr(const std::string &name, ISvcLocator *svc)
BooleanProperty m_loadRootHandler
std::vector< FileAttr * > m_oldFiles
Property base class allowing Property* collections to be "homogeneous".
const std::string & fname(const Io::Fd &) const override
BooleanProperty m_loadPosixHandler
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
virtual void listSuppression() const
bool match(const IoFlags &fa, bool strict=true) const
T back_inserter(T...args)
void * fptr(const std::string &) const override
StringProperty m_ssl_cert
Base class for all Incidents (computing events).
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
int getFiles(std::vector< std::string > &, bool onlyOpen=true) const override
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
void listFiles() const override
StringProperty m_ssl_proxy
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
void listHandlers() const override
int getFd(std::vector< Fd > &) const override
StatusCode finalize() override
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
virtual void setOutputLevel(int new_level)=0
Set new global output level threshold.
StatusCode initialize() override
std::map< IoTech, actionMap > m_actions