5 #include "GaudiKernel/SvcFactory.h"
6 #include "GaudiKernel/ISvcLocator.h"
7 #include "GaudiKernel/IJobOptionsSvc.h"
11 #include "boost/bind.hpp"
12 #include "boost/function.hpp"
14 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
15 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
27 void set_bit(
int& f, const
unsigned int& b) {
31 bool get_bit(
const int& f,
const unsigned int& b) {
40 m_log(msgSvc(), name )
73 for ( std::vector<const Property*>::const_iterator cur = props->begin();
74 cur != props->end(); cur++) {
75 if ( (*cur)->name() ==
"OutputLevel" ) {
108 const std::string& desc,
Io::Fd&
fd,
110 return rfh->openRootFile(n, f, desc, fd, ptr);
113 return rfh->closeRootFile(ptr);
116 return rfh->reopenRootFile(ptr, f);
121 <<
"unable to register ROOT file handler with FileMgr"
136 const std::string& desc,
Io::Fd&
fd,
138 return pfh->openPOSIXFile(n, f, desc, fd, ptr);
141 return pfh->closePOSIXFile(fd);
144 return pfh->reopenPOSIXFile(fd, f);
149 <<
"unable to register ROOT file handler with FileMgr"
178 <<
"At finalize, the following files remained open:"
180 map<string,FileAttr*>::const_iterator itr;
182 m_log << *(itr->second) << endl;
200 fileMap::const_iterator itr;
202 ofs << itr->second->name() <<
" " << itr->second->tech() <<
" "
203 << itr->second->desc() <<
" " << itr->second->iflags() << endl;
207 set<FileAttr>::const_iterator it3;
208 list<FileAttr*>::const_iterator it2;
213 for (it3=fs.begin(); it3!=fs.end(); ++it3) {
214 ofs << (it3)->
name() <<
" " << (it3)->tech() <<
" " << (it3)->desc()
215 <<
" " << (it3)->iflags()
216 << ( (it3->isShared()) ?
" SHARED" :
"" )
225 for (vector<FileAttr*>::iterator itr =
m_attr.begin(); itr !=
m_attr.end();
261 <<
"Handler for IoTech " << tech <<
" already registered. Ignoring."
268 <<
"open handler for tech " << tech <<
" is NULL"
275 <<
"no close handler for tech " << tech <<
" registered"
282 <<
"no reopen handler for tech " << tech <<
" registered"
290 <<
"Successfully registered handler for tech \"" << tech <<
"\""
305 map<IoTech,FileHdlr>::iterator itr =
m_handlers.find(tech);
308 <<
" as it hasn't been registered!"
323 map<IoTech,FileHdlr>::const_iterator itr =
m_handlers.find(tech);
336 const std::string& fname,
337 const IoFlags& flags,
Fd& fd,
void*& ptr,
338 const std::string& desc,
bool sh) {
340 return open(tech, caller, fname, desc, flags, fd, ptr, sh);
347 const std::string& fname,
348 const IoFlags& flags,
Fd& fd,
const std::string& desc,
352 return open(tech, caller, fname, desc, flags, fd, dummy, sh);
359 const std::string& fname,
360 const IoFlags& flags,
void*& ptr,
const std::string& desc,
364 return open(tech, caller, fname, desc, flags, dummy, ptr, sh);
372 const std::string& fname,
373 const std::string& desc,
374 const IoFlags& flags,
Fd& fd,
void*& ptr,
bool shared) {
395 <<
",\"" << fname <<
"\",\""
398 << ( shared ?
",shared" :
",unshared")
410 pair<fileMap::const_iterator,fileMap::const_iterator> fitr =
412 fileMap::const_iterator itr;
417 for (itr=fitr.first; itr != fitr.second; ++itr) {
418 if (itr->second->tech() != tech) {
421 <<
" with tech " << tech
422 <<
", file already opened with different tech "
423 << itr->second->tech()
437 bool shareable(
true);
439 for (itr=fitr.first; itr != fitr.second; ++itr) {
447 if ( shareable && fa->
flags().
match(flags,
false) ) {
472 }
catch (
const boost::bad_function_call&
err) {
475 << fname <<
" caught " << err.what() <<
endmsg;
480 << fname <<
" caught an unknown exception." <<
endmsg;
487 <<
"open of file \"" << fname <<
"\", tech: \"" << tech
488 <<
"\", flags: \"" << flags <<
"\" requested by "
490 <<
" failed. return code: " << r
493 FileAttr xfa(-1,fname,desc,tech,flags,0,
false);
507 if (fd == -1 && ptr == 0) {
509 <<
" and File Ptr are invalid" <<
endmsg;
514 for (itr = fitr.first; itr != fitr.second; ++itr) {
517 }
else if (*fa == *(itr->second) ) {
519 <<
"\" returned a pre-existing file with identical"
520 <<
" FileAttributes: " << *fa <<
endmsg;
524 <<
"\" returned a pre-existing file with different"
525 <<
" FileAttributes -"
526 << endl <<
"old: " << *(itr->second)
527 << endl <<
"new: " << *fa << endmsg;
532 m_files.insert( pair<string,FileAttr*>(fname,fa) );
537 <<
"at least one open callback action failed"
564 fileMap::iterator itr;
566 if (itr->second->fd() ==
fd) {
573 <<
"\" when calling close()"
579 IoTech tech = itr->second->tech();
588 m_log <<
MSG::ERROR <<
"no close(" << tech <<
",Fd) function registered"
596 pair<fileMap::const_iterator, fileMap::const_iterator> fitr =
600 for (fileMap::const_iterator it=fitr.first; it != fitr.second; ++it) {
601 if (it->second->fd() ==
fd) {
615 <<
i <<
" times with Fd " << fd <<
endmsg;
620 }
else if (
i == 1 || (
i>1 && !fa->
isShared()) ) {
627 }
catch (
const boost::bad_function_call& err) {
629 <<
" on file descriptor "
630 << fd <<
" caught " << err.what() <<
endmsg;
635 <<
" on file descriptor "
636 << fd <<
" caught an unknown exception." <<
endmsg;
643 <<
"close of file with FD \"" << fd
644 <<
"\", name: \"" << fa->
name()
645 <<
"\", tech: \"" << tech <<
"\" failed"
658 <<
"ref count < 0 when closing " << fa
659 <<
". This should never happen"
675 <<
"at least one close callback action failed"
700 fileMap::iterator itr;
702 if (itr->second->fptr() == vp) {
709 <<
"\" when calling close()"
714 IoTech tech = itr->second->tech();
722 m_log <<
MSG::ERROR <<
"no close(" << tech <<
",void*) function registered"
730 pair<fileMap::const_iterator, fileMap::const_iterator> fitr =
734 for (fileMap::const_iterator it=fitr.first; it != fitr.second; ++it) {
735 if (it->second->fptr() == vp) {
748 << i <<
" times with fptr " << vp <<
endmsg;
753 }
else if (i == 1 || (i>1 && !fa->
isShared()) ) {
759 }
catch (
const boost::bad_function_call& err) {
761 <<
" on file " << fa->
name()
762 <<
" caught " << err.what() <<
endmsg;
767 <<
" on file " << fa->
name()
768 <<
" caught an unknown exception." <<
endmsg;
775 <<
"close of file with ptr \"" << vp
776 <<
"\", name: \"" << fa->
name()
777 <<
"\", tech: \"" << tech <<
"\" failed"
788 <<
"ref count: " << i <<
" < 0 when closing " << fa
789 <<
". This should never happen"
805 <<
"at least one close callback action failed"
820 <<
"," << caller <<
")"
826 fileMap::iterator itr;
828 if (itr->second->fd() ==
fd) {
835 <<
"\" when calling reopen()"
852 m_log <<
MSG::ERROR <<
"no reopen(" << tech <<
",Fd) function registered"
862 }
catch (
const boost::bad_function_call& err) {
864 <<
" on file descriptor " << fd <<
" with flags "
866 <<
" caught " << err.what() <<
endmsg;
870 <<
" on file descriptor " << fd <<
" with flags "
872 <<
" caught an unknown exception." <<
endmsg;
878 <<
"reopen of file with FD \"" << fd
879 <<
"\", name: \"" << fa->
name()
880 <<
"\", tech: \"" << tech
881 <<
"\", flags: \"" << flags <<
"\" failed"
896 <<
"at least one reopen callback action failed"
910 <<
"," << caller <<
")"
915 fileMap::iterator itr;
917 if (itr->second->fptr() == vp) {
924 <<
"unregistered file ptr \"" << vp
925 <<
"\" when calling reopen()"
939 m_log <<
MSG::ERROR <<
"no reopen(" << tech <<
",void*) function registered"
946 }
catch (
const boost::bad_function_call& err) {
948 <<
" on file " << fa->
name() <<
" with flags "
950 <<
" caught " << err.what() <<
endmsg;
954 <<
" on file " << fa->
name() <<
" with flags "
956 <<
" caught an unknown exception." <<
endmsg;
962 <<
"reopen of file with ptr \"" << vp
963 <<
"\", name: \"" << fa->
name()
964 <<
"\", tech: \"" << tech
965 <<
"\", flags: \"" << flags <<
"\" failed"
980 <<
"at least one reopen callback action failed"
994 pair<fileMap::const_iterator,fileMap::const_iterator> fitr =
997 fileMap::const_iterator itr;
998 for (itr=fitr.first; itr != fitr.second; ++itr) {
999 fa.push_back( (itr->second) );
1002 fileList::const_iterator it2;
1004 if ( (*it2)->name() ==
fname ) {
1005 fa.push_back( *it2 );
1019 fileMap::const_iterator itr;
1021 if (itr->second->fd() ==
fd) {
1027 fileList::const_iterator it2;
1029 if ( (*it2)->fd() ==
fd ) {
1044 fileMap::const_iterator itr;
1046 if (itr->second->fptr() == vp) {
1052 fileList::const_iterator it2;
1054 if ( (*it2)->fptr() == vp ) {
1071 map<string,FileAttr*>::const_iterator itr;
1073 if (find( files.begin(), files.end(), itr->first) == files.end()) {
1074 files.push_back(itr->first);
1079 std::list<FileAttr*>::const_iterator it2;
1081 if (find(files.begin(), files.end(), (*it2)->name()) == files.end()) {
1082 files.push_back( (*it2)->name());
1087 return files.size();
1098 map<string,FileAttr*>::const_iterator itr;
1100 files.push_back( (itr->second) );
1104 std::list<FileAttr*>::const_iterator it2;
1106 files.push_back( *it2 );
1110 return files.size();
1125 map<string,FileAttr*>::const_iterator itr;
1127 if (itr->second->tech() == tech &&
1128 find(files.begin(),files.end(),itr->first) == files.end()) {
1129 files.push_back(itr->first);
1134 std::list<FileAttr*>::const_iterator it2;
1136 if ( (*it2)->tech() == tech &&
1137 find(files.begin(), files.end(), (*it2)->name()) == files.end()) {
1138 files.push_back( (*it2)->name());
1143 return files.size();
1159 map<string,FileAttr*>::const_iterator itr;
1161 if (itr->second->tech() == tech) {
1162 files.push_back( (itr->second) );
1167 std::list<FileAttr*>::const_iterator it2;
1169 if ( (*it2)->tech() == tech) {
1170 files.push_back( *it2 );
1175 return files.size();
1183 vector<string>& files,
bool op)
const {
1187 map<string,FileAttr*>::const_iterator itr;
1189 if (itr->second->tech() == tech || tech ==
UNKNOWN) {
1190 if ( itr->second->flags() == flags ) {
1191 if (find( files.begin(), files.end(), itr->first ) == files.end()) {
1192 files.push_back(itr->first);
1199 std::list<FileAttr*>::const_iterator it2;
1201 if ( (*it2)->tech() == tech || tech ==
UNKNOWN) {
1202 if ( (*it2)->flags() == flags ) {
1203 if (find(files.begin(), files.end(), (*it2)->name()) == files.end()){
1204 files.push_back( (*it2)->name());
1211 return files.size();
1218 vector<const Io::FileAttr*>& files,
bool op)
const {
1222 map<string,FileAttr*>::const_iterator itr;
1224 if (itr->second->tech() == tech || tech ==
UNKNOWN) {
1225 if ( itr->second->flags() == flags ) {
1226 files.push_back( (itr->second) );
1232 std::list<FileAttr*>::const_iterator it2;
1234 if ( (*it2)->tech() == tech || tech ==
UNKNOWN) {
1235 if ( (*it2)->flags() == flags ) {
1236 files.push_back( *it2);
1242 return files.size();
1254 map<Fd,FileAttr*>::const_iterator itr;
1256 fd.push_back(itr->first);
1276 map<Fd,FileAttr*>::const_iterator itr;
1278 if (itr->second->tech() == tech) {
1279 fd.push_back(itr->first);
1295 map<Fd,FileAttr*>::const_iterator itr;
1297 if (itr->second->tech() == tech || tech ==
UNKNOWN) {
1298 if ( itr->second->flags() == flags ) {
1299 fd.push_back(itr->first);
1313 fileMap::const_iterator itr;
1315 if (itr->second->fd() ==
fd) {
1316 return itr->second->name();
1320 static const std::string s_empty =
"";
1330 fileMap::const_iterator itr;
1332 if (itr->second->fptr() == vp) {
1333 return itr->second->name();
1337 static const std::string s_empty =
"";
1347 pair<fileMap::const_iterator,fileMap::const_iterator> fitr =
1350 fileMap::const_iterator itr;
1351 for (itr=fitr.first; itr != fitr.second; ++itr) {
1352 if (itr->second->fd() != -1) {
1353 return itr->second->fd();
1366 fileMap::const_iterator itr;
1368 if (itr->second->fptr() ==
fptr) {
1369 return itr->second->fd();
1381 pair<fileMap::const_iterator,fileMap::const_iterator> fitr =
1384 fileMap::const_iterator itr;
1385 for (itr=fitr.first; itr != fitr.second; ++itr) {
1386 if (itr->second->fptr() != 0) {
1387 return itr->second->fptr();
1400 fileMap::const_iterator itr;
1402 if (itr->second->fd() ==
fd) {
1403 return itr->second->fptr();
1420 fileMap::const_iterator itr;
1422 m_log << *(itr->second) << endl;
1425 for (list<FileAttr*>::const_iterator it2=
m_oldFiles.begin();
1427 m_log << **it2 << endl;
1450 std::map<IoTech,FileHdlr>::const_iterator itr =
m_handlers.find(tech);
1456 <<
"no handler for tech " << tech <<
" registered"
1468 pair<fileMap::const_iterator,fileMap::const_iterator> fitr =
1471 if (fitr.first == fitr.second) {
1473 <<
"no file \"" << fname <<
"\" registered. Cannot determine tech"
1478 fileMap::const_iterator itr = fitr.first;
1479 IoTech tech = itr->second->tech();
1482 while( itr != fitr.second ) {
1483 if ( itr->second->tech() != tech ) {
1485 <<
"multiple technologies registered for file \"" << fname
1486 <<
"\". Cannot determine handler" <<
endmsg;
1502 <<
"Listing registered handlers:" << endl;
1504 map<IoTech,FileHdlr>::const_iterator itr;
1507 m_log <<
" " << itr->first << endl;
1538 const std::string& d) {
1543 <<
" for tech " << t << endmsg;
1549 m_actions[t][a].push_back(make_pair(bf,d));
1563 actionMap::const_iterator itr;
1565 map<Io::IoTech, actionMap>::const_iterator iit;
1570 if (m.size() != 0) {
1571 m_log <<
" --- Tech: ";
1573 m_log <<
"ALL ---" << endl;
1575 m_log << t <<
" ---" << endl;
1578 actionMap::const_iterator iia;
1579 for (iia = m.begin() ; iia != m.end(); ++iia) {
1580 if (iia->second.size() != 0) {
1583 for (list<bfcn_desc_t>::const_iterator it2 = iia->second.begin();
1584 it2 != iia->second.end(); ++it2) {
1586 m_log <<
" " << iia->first <<
" "
1611 std::map<IoTech, actionMap>::const_iterator itr;
1614 if (itr !=
m_actions.end() && itr->second.size() != 0) {
1620 if (itr !=
m_actions.end() && itr->second.size() != 0) {
1639 actionMap::const_iterator mitr = m.find(a);
1641 if (mitr == m.end() || mitr->second.size() == 0) {
1647 <<
"executing " << mitr->second.size() <<
" " << a
1656 supMap::const_iterator it2 =
m_supMap.find(fa->
name());
1667 for (list<bfcn_desc_t>::const_iterator itr = mitr->second.begin();
1668 itr != mitr->second.end(); ++itr) {
1672 << itr->second <<
endmsg;
1674 if ( (((itr->first))(fa,caller)).isFailure() ) {
1676 << itr->second <<
" on " << *fa
1677 <<
" failed during " << a <<
" action"
1705 ((fold &
Io::WRITE) != 0 && (fnew & Io::WRITE) != 0) ||
1706 ((fold &
Io::RDWR) != 0 && (fnew & Io::RDWR) != 0) ) {
1728 supMap::iterator it2 =
m_supMap.find(f);
1748 supMap::const_iterator it2;
1750 m_log <<
" " << it2->first;
1752 m_log <<
" ALL" << endl;
IntegerProperty m_outputLevel
Service output level.
virtual const std::vector< const Property * > * getProperties(const std::string &client) const =0
Get the properties associated to a given client.
virtual void listFiles() const
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
virtual Io::reopen_t reopen(const Fd, const IoFlags &, const std::string &caller)
virtual 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)
std::function< StatusCode(FILEMGR_CALLBACK_ARGS) > bfcn_action_t
virtual StatusCode setProperty(const Property &p)
Set the property by property.
virtual StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &desc="")
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
bfcn_reopen_t b_reopen_fcn
bool isSuccess() const
Test for a status code of SUCCESS.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
virtual int getFileAttr(const std::string &, std::vector< const FileAttr * > &) const
int outputLevel() const
get the Service's output level
std::map< Io::Action, std::list< bfcn_desc_t > > actionMap
StatusCode execAction(Io::FileAttr *, const std::string &, const Io::Action &) const
virtual int getFiles(std::vector< std::string > &, bool onlyOpen=true) const
void set_bit(int &f, const unsigned int &b)
virtual StatusCode getHandler(const IoTech &, FileHdlr &) const
std::map< Fd, FileAttr * > m_descriptors
virtual StatusCode regHandler(FileHdlr)
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
virtual void handle(const Incident &)
Inform that a new incident has occurred.
bool isFailure() const
Test for a status code of FAILURE.
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
bool accessMatch(const Io::IoFlags &, const Io::IoFlags &, bool strict=false) const
virtual void suppressAction(const std::string &)
virtual void listActions() const
virtual const std::string & fname(const Io::Fd &) const
const std::string & name() const
std::map< IoTech, FileHdlr > m_handlers
virtual Io::close_t close(const Fd, const std::string &caller)
std::vector< FileAttr * > m_attr
Main interface for the JobOptions service.
virtual StatusCode deregHandler(const IoTech &)
This class is used for returning status codes from appropriate routines.
StatusCode execActs(Io::FileAttr *, const std::string &, const Io::Action &, const actionMap &m) const
bfcn_closeP_t b_closeP_fcn
BooleanProperty m_printSummary
bfcn_reopenP_t b_reopenP_fcn
const TYPE & value() const
explicit conversion
virtual const std::string & name() const
Retrieve name of the service.
bool get_bit(const int &f, const unsigned int &b)
FileMgr(const std::string &name, ISvcLocator *svc)
BooleanProperty m_loadRootHandler
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
BooleanProperty m_loadPosixHandler
#define DECLARE_SERVICE_FACTORY(x)
virtual void listSuppression() const
bool match(const IoFlags &fa, bool strict=true) const
StringProperty m_ssl_cert
Base class for all Incidents (computing events).
void setLevel(int level)
Update outputlevel.
virtual Io::Fd fd(const std::string &) const
Templated class to add the standard messaging functionalities.
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.
virtual StatusCode hasHandler(const IoTech &) const
virtual void * fptr(const std::string &) const
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
StringProperty m_ssl_proxy
virtual void listHandlers() const
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
virtual void setOutputLevel(int new_level)=0
Set new global output level threshold.
virtual int getFd(std::vector< Fd > &) const
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
std::map< IoTech, actionMap > m_actions
virtual int getLastError(std::string &) const