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" ) {
112 <<
"unable to register ROOT file handler with FileMgr"
131 <<
"unable to register ROOT file handler with FileMgr"
160 <<
"At finalize, the following files remained open:"
162 map<string,FileAttr*>::const_iterator itr;
164 m_log << *(itr->second) << endl;
182 fileMap::const_iterator itr;
184 ofs << itr->second->name() <<
" " << itr->second->tech() <<
" "
185 << itr->second->desc() <<
" " << itr->second->iflags() << endl;
189 set<FileAttr>::const_iterator it3;
190 list<FileAttr*>::const_iterator it2;
195 for (it3=fs.begin(); it3!=fs.end(); ++it3) {
196 ofs << (it3)->
name() <<
" " << (it3)->tech() <<
" " << (it3)->desc()
197 <<
" " << (it3)->iflags()
198 << ( (it3->isShared()) ?
" SHARED" :
"" )
207 for (vector<FileAttr*>::iterator itr =
m_attr.begin(); itr !=
m_attr.end();
243 <<
"Handler for IoTech " << tech <<
" already registered. Ignoring."
250 <<
"open handler for tech " << tech <<
" is NULL"
257 <<
"no close handler for tech " << tech <<
" registered"
264 <<
"no reopen handler for tech " << tech <<
" registered"
272 <<
"Successfully registered handler for tech \"" << tech <<
"\""
287 map<IoTech,FileHdlr>::iterator itr =
m_handlers.find(tech);
290 <<
" as it hasn't been registered!"
305 map<IoTech,FileHdlr>::const_iterator itr =
m_handlers.find(tech);
318 const std::string& fname,
319 const IoFlags& flags,
Fd& fd,
void*& ptr,
320 const std::string& desc,
bool sh) {
322 return open(tech, caller, fname, desc, flags, fd, ptr, sh);
329 const std::string& fname,
330 const IoFlags& flags,
Fd& fd,
const std::string& desc,
334 return open(tech, caller, fname, desc, flags, fd, dummy, sh);
341 const std::string& fname,
342 const IoFlags& flags,
void*& ptr,
const std::string& desc,
346 return open(tech, caller, fname, desc, flags, dummy, ptr, sh);
354 const std::string& fname,
355 const std::string& desc,
356 const IoFlags& flags,
Fd& fd,
void*& ptr,
bool shared) {
377 <<
",\"" << fname <<
"\",\""
380 << ( shared ?
",shared" :
",unshared")
392 pair<fileMap::const_iterator,fileMap::const_iterator> fitr =
394 fileMap::const_iterator itr;
399 for (itr=fitr.first; itr != fitr.second; ++itr) {
400 if (itr->second->tech() != tech) {
403 <<
" with tech " << tech
404 <<
", file already opened with different tech "
405 << itr->second->tech()
419 bool shareable(
true);
421 for (itr=fitr.first; itr != fitr.second; ++itr) {
429 if ( shareable && fa->
flags().
match(flags,
false) ) {
454 }
catch (
const boost::bad_function_call&
err) {
457 << fname <<
" caught " << err.what() <<
endmsg;
462 << fname <<
" caught an unknown exception." <<
endmsg;
469 <<
"open of file \"" << fname <<
"\", tech: \"" << tech
470 <<
"\", flags: \"" << flags <<
"\" requested by "
472 <<
" failed. return code: " << r
475 FileAttr xfa(-1,fname,desc,tech,flags,0,
false);
489 if (fd == -1 && ptr == 0) {
491 <<
" and File Ptr are invalid" <<
endmsg;
496 for (itr = fitr.first; itr != fitr.second; ++itr) {
499 }
else if (*fa == *(itr->second) ) {
501 <<
"\" returned a pre-existing file with identical"
502 <<
" FileAttributes: " << *fa <<
endmsg;
506 <<
"\" returned a pre-existing file with different"
507 <<
" FileAttributes -"
508 << endl <<
"old: " << *(itr->second)
509 << endl <<
"new: " << *fa << endmsg;
514 m_files.insert( pair<string,FileAttr*>(fname,fa) );
519 <<
"at least one open callback action failed"
546 fileMap::iterator itr;
548 if (itr->second->fd() ==
fd) {
555 <<
"\" when calling close()"
561 IoTech tech = itr->second->tech();
570 m_log <<
MSG::ERROR <<
"no close(" << tech <<
",Fd) function registered"
578 pair<fileMap::const_iterator, fileMap::const_iterator> fitr =
582 for (fileMap::const_iterator it=fitr.first; it != fitr.second; ++it) {
583 if (it->second->fd() ==
fd) {
597 <<
i <<
" times with Fd " << fd <<
endmsg;
602 }
else if (
i == 1 || (
i>1 && !fa->
isShared()) ) {
609 }
catch (
const boost::bad_function_call& err) {
611 <<
" on file descriptor "
612 << fd <<
" caught " << err.what() <<
endmsg;
617 <<
" on file descriptor "
618 << fd <<
" caught an unknown exception." <<
endmsg;
625 <<
"close of file with FD \"" << fd
626 <<
"\", name: \"" << fa->
name()
627 <<
"\", tech: \"" << tech <<
"\" failed"
640 <<
"ref count < 0 when closing " << fa
641 <<
". This should never happen"
657 <<
"at least one close callback action failed"
682 fileMap::iterator itr;
684 if (itr->second->fptr() == vp) {
691 <<
"\" when calling close()"
696 IoTech tech = itr->second->tech();
704 m_log <<
MSG::ERROR <<
"no close(" << tech <<
",void*) function registered"
712 pair<fileMap::const_iterator, fileMap::const_iterator> fitr =
716 for (fileMap::const_iterator it=fitr.first; it != fitr.second; ++it) {
717 if (it->second->fptr() == vp) {
730 << i <<
" times with fptr " << vp <<
endmsg;
735 }
else if (i == 1 || (i>1 && !fa->
isShared()) ) {
741 }
catch (
const boost::bad_function_call& err) {
743 <<
" on file " << fa->
name()
744 <<
" caught " << err.what() <<
endmsg;
749 <<
" on file " << fa->
name()
750 <<
" caught an unknown exception." <<
endmsg;
757 <<
"close of file with ptr \"" << vp
758 <<
"\", name: \"" << fa->
name()
759 <<
"\", tech: \"" << tech <<
"\" failed"
770 <<
"ref count: " << i <<
" < 0 when closing " << fa
771 <<
". This should never happen"
787 <<
"at least one close callback action failed"
802 <<
"," << caller <<
")"
808 fileMap::iterator itr;
810 if (itr->second->fd() ==
fd) {
817 <<
"\" when calling reopen()"
834 m_log <<
MSG::ERROR <<
"no reopen(" << tech <<
",Fd) function registered"
844 }
catch (
const boost::bad_function_call& err) {
846 <<
" on file descriptor " << fd <<
" with flags "
848 <<
" caught " << err.what() <<
endmsg;
852 <<
" on file descriptor " << fd <<
" with flags "
854 <<
" caught an unknown exception." <<
endmsg;
860 <<
"reopen of file with FD \"" << fd
861 <<
"\", name: \"" << fa->
name()
862 <<
"\", tech: \"" << tech
863 <<
"\", flags: \"" << flags <<
"\" failed"
878 <<
"at least one reopen callback action failed"
892 <<
"," << caller <<
")"
897 fileMap::iterator itr;
899 if (itr->second->fptr() == vp) {
906 <<
"unregistered file ptr \"" << vp
907 <<
"\" when calling reopen()"
921 m_log <<
MSG::ERROR <<
"no reopen(" << tech <<
",void*) function registered"
928 }
catch (
const boost::bad_function_call& err) {
930 <<
" on file " << fa->
name() <<
" with flags "
932 <<
" caught " << err.what() <<
endmsg;
936 <<
" on file " << fa->
name() <<
" with flags "
938 <<
" caught an unknown exception." <<
endmsg;
944 <<
"reopen of file with ptr \"" << vp
945 <<
"\", name: \"" << fa->
name()
946 <<
"\", tech: \"" << tech
947 <<
"\", flags: \"" << flags <<
"\" failed"
962 <<
"at least one reopen callback action failed"
976 pair<fileMap::const_iterator,fileMap::const_iterator> fitr =
979 fileMap::const_iterator itr;
980 for (itr=fitr.first; itr != fitr.second; ++itr) {
981 fa.push_back( (itr->second) );
984 fileList::const_iterator it2;
986 if ( (*it2)->name() ==
fname ) {
987 fa.push_back( *it2 );
1001 fileMap::const_iterator itr;
1003 if (itr->second->fd() ==
fd) {
1009 fileList::const_iterator it2;
1011 if ( (*it2)->fd() ==
fd ) {
1026 fileMap::const_iterator itr;
1028 if (itr->second->fptr() == vp) {
1034 fileList::const_iterator it2;
1036 if ( (*it2)->fptr() == vp ) {
1053 map<string,FileAttr*>::const_iterator itr;
1055 if (find( files.begin(), files.end(), itr->first) == files.end()) {
1056 files.push_back(itr->first);
1061 std::list<FileAttr*>::const_iterator it2;
1063 if (find(files.begin(), files.end(), (*it2)->name()) == files.end()) {
1064 files.push_back( (*it2)->name());
1069 return files.size();
1080 map<string,FileAttr*>::const_iterator itr;
1082 files.push_back( (itr->second) );
1086 std::list<FileAttr*>::const_iterator it2;
1088 files.push_back( *it2 );
1092 return files.size();
1107 map<string,FileAttr*>::const_iterator itr;
1109 if (itr->second->tech() == tech &&
1110 find(files.begin(),files.end(),itr->first) == files.end()) {
1111 files.push_back(itr->first);
1116 std::list<FileAttr*>::const_iterator it2;
1118 if ( (*it2)->tech() == tech &&
1119 find(files.begin(), files.end(), (*it2)->name()) == files.end()) {
1120 files.push_back( (*it2)->name());
1125 return files.size();
1141 map<string,FileAttr*>::const_iterator itr;
1143 if (itr->second->tech() == tech) {
1144 files.push_back( (itr->second) );
1149 std::list<FileAttr*>::const_iterator it2;
1151 if ( (*it2)->tech() == tech) {
1152 files.push_back( *it2 );
1157 return files.size();
1165 vector<string>& files,
bool op)
const {
1169 map<string,FileAttr*>::const_iterator itr;
1171 if (itr->second->tech() == tech || tech ==
UNKNOWN) {
1172 if ( itr->second->flags() == flags ) {
1173 if (find( files.begin(), files.end(), itr->first ) == files.end()) {
1174 files.push_back(itr->first);
1181 std::list<FileAttr*>::const_iterator it2;
1183 if ( (*it2)->tech() == tech || tech ==
UNKNOWN) {
1184 if ( (*it2)->flags() == flags ) {
1185 if (find(files.begin(), files.end(), (*it2)->name()) == files.end()){
1186 files.push_back( (*it2)->name());
1193 return files.size();
1200 vector<const Io::FileAttr*>& files,
bool op)
const {
1204 map<string,FileAttr*>::const_iterator itr;
1206 if (itr->second->tech() == tech || tech ==
UNKNOWN) {
1207 if ( itr->second->flags() == flags ) {
1208 files.push_back( (itr->second) );
1214 std::list<FileAttr*>::const_iterator it2;
1216 if ( (*it2)->tech() == tech || tech ==
UNKNOWN) {
1217 if ( (*it2)->flags() == flags ) {
1218 files.push_back( *it2);
1224 return files.size();
1236 map<Fd,FileAttr*>::const_iterator itr;
1238 fd.push_back(itr->first);
1258 map<Fd,FileAttr*>::const_iterator itr;
1260 if (itr->second->tech() == tech) {
1261 fd.push_back(itr->first);
1277 map<Fd,FileAttr*>::const_iterator itr;
1279 if (itr->second->tech() == tech || tech ==
UNKNOWN) {
1280 if ( itr->second->flags() == flags ) {
1281 fd.push_back(itr->first);
1295 fileMap::const_iterator itr;
1297 if (itr->second->fd() ==
fd) {
1298 return itr->second->name();
1302 static const std::string s_empty =
"";
1312 fileMap::const_iterator itr;
1314 if (itr->second->fptr() == vp) {
1315 return itr->second->name();
1319 static const std::string s_empty =
"";
1329 pair<fileMap::const_iterator,fileMap::const_iterator> fitr =
1332 fileMap::const_iterator itr;
1333 for (itr=fitr.first; itr != fitr.second; ++itr) {
1334 if (itr->second->fd() != -1) {
1335 return itr->second->fd();
1348 fileMap::const_iterator itr;
1350 if (itr->second->fptr() ==
fptr) {
1351 return itr->second->fd();
1363 pair<fileMap::const_iterator,fileMap::const_iterator> fitr =
1366 fileMap::const_iterator itr;
1367 for (itr=fitr.first; itr != fitr.second; ++itr) {
1368 if (itr->second->fptr() != 0) {
1369 return itr->second->fptr();
1382 fileMap::const_iterator itr;
1384 if (itr->second->fd() ==
fd) {
1385 return itr->second->fptr();
1402 fileMap::const_iterator itr;
1404 m_log << *(itr->second) << endl;
1407 for (list<FileAttr*>::const_iterator it2=
m_oldFiles.begin();
1409 m_log << **it2 << endl;
1432 std::map<IoTech,FileHdlr>::const_iterator itr =
m_handlers.find(tech);
1438 <<
"no handler for tech " << tech <<
" registered"
1450 pair<fileMap::const_iterator,fileMap::const_iterator> fitr =
1453 if (fitr.first == fitr.second) {
1455 <<
"no file \"" << fname <<
"\" registered. Cannot determine tech"
1460 fileMap::const_iterator itr = fitr.first;
1461 IoTech tech = itr->second->tech();
1464 while( itr != fitr.second ) {
1465 if ( itr->second->tech() != tech ) {
1467 <<
"multiple technologies registered for file \"" << fname
1468 <<
"\". Cannot determine handler" <<
endmsg;
1484 <<
"Listing registered handlers:" << endl;
1486 map<IoTech,FileHdlr>::const_iterator itr;
1489 m_log <<
" " << itr->first << endl;
1520 const std::string& d) {
1525 <<
" for tech " << t << endmsg;
1531 m_actions[t][a].push_back(make_pair(bf,d));
1545 actionMap::const_iterator itr;
1549 map<Io::IoTech, actionMap>::const_iterator iit;
1554 if (m.size() != 0) {
1555 m_log <<
" --- Tech: ";
1557 m_log <<
"ALL ---" << endl;
1559 m_log << t <<
" ---" << endl;
1562 actionMap::const_iterator iia;
1563 for (iia = m.begin() ; iia != m.end(); ++iia) {
1564 if (iia->second.size() != 0) {
1567 for (list<bfcn_desc_t>::const_iterator it2 = iia->second.begin();
1568 it2 != iia->second.end(); ++it2) {
1570 m_log <<
" " << iia->first <<
" "
1595 std::map<IoTech, actionMap>::const_iterator itr;
1598 if (itr !=
m_actions.end() && itr->second.size() != 0) {
1604 if (itr !=
m_actions.end() && itr->second.size() != 0) {
1623 actionMap::const_iterator mitr = m.find(a);
1625 if (mitr == m.end() || mitr->second.size() == 0) {
1631 <<
"executing " << mitr->second.size() <<
" " << a
1640 supMap::const_iterator it2 =
m_supMap.find(fa->
name());
1651 for (list<bfcn_desc_t>::const_iterator itr = mitr->second.begin();
1652 itr != mitr->second.end(); ++itr) {
1656 << itr->second <<
endmsg;
1658 if ( (((itr->first))(fa,caller)).isFailure() ) {
1660 << itr->second <<
" on " << *fa
1661 <<
" failed during " << a <<
" action"
1689 ((fold &
Io::WRITE) != 0 && (fnew & Io::WRITE) != 0) ||
1690 ((fold &
Io::RDWR) != 0 && (fnew & Io::RDWR) != 0) ) {
1712 supMap::iterator it2 =
m_supMap.find(f);
1732 supMap::const_iterator it2;
1734 m_log <<
" " << it2->first;
1736 m_log <<
" ALL" << endl;
Io::close_t closePOSIXFile(Io::Fd fd)
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
Io::reopen_t reopenPOSIXFile(Io::Fd fd, const Io::IoFlags &)
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)
boost::function< Io::close_t(void *)> bfcn_closeP_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="")
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
bfcn_reopen_t b_reopen_fcn
bool isSuccess() const
Test for a status code of SUCCESS.
boost::function< Io::close_t(Io::Fd)> bfcn_close_t
virtual int getFileAttr(const std::string &, std::vector< const FileAttr * > &) const
int outputLevel() const
get the Service's output level
Io::open_t openRootFile(const std::string &n, const Io::IoFlags &f, const std::string &desc, Io::Fd &fd, void *&ptr)
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.
Io::close_t closeRootFile(void *ptr)
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
Io::reopen_t reopenRootFile(void *, const Io::IoFlags &)
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 &)
boost::function< StatusCode(FILEMGR_CALLBACK_ARGS) > bfcn_action_t
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
#define DECLARE_SERVICE_FACTORY(x)
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)
Io::open_t openPOSIXFile(const std::string &n, const Io::IoFlags &f, const std::string &desc, Io::Fd &fd, void *&ptr)
BooleanProperty m_loadRootHandler
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
BooleanProperty m_loadPosixHandler
virtual void listSuppression() const
bool match(const IoFlags &fa, bool strict=true) const
StringProperty m_ssl_cert
Base class for all Incidents (computing events).
std
AIDA -> ROTO converter.
void setLevel(int level)
Update outputlevel.
virtual Io::Fd fd(const std::string &) const
boost::function< Io::reopen_t(Io::Fd, Io::IoFlags)> bfcn_reopen_t
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
boost::function< Io::reopen_t(void *, Io::IoFlags)> bfcn_reopenP_t
virtual void listHandlers() const
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
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