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 <<
" "
1619 if (m[a].size() == 0) {
1625 <<
"executing " << m[a].size() <<
" " << a
1634 supMap::const_iterator it2 =
m_supMap.find(fa->
name());
1645 for (list<bfcn_desc_t>::iterator itr = m[a].begin();
1646 itr != m[a].end(); ++itr) {
1650 << itr->second <<
endmsg;
1652 if ( (((itr->first))(fa,caller)).isFailure() ) {
1654 << itr->second <<
" on " << *fa
1655 <<
" failed during " << a <<
" action"
1683 ((fold &
Io::WRITE) != 0 && (fnew & Io::WRITE) != 0) ||
1684 ((fold &
Io::RDWR) != 0 && (fnew & Io::RDWR) != 0) ) {
1706 supMap::iterator it2 =
m_supMap.find(f);
1726 supMap::const_iterator it2;
1728 m_log <<
" " << it2->first;
1730 m_log <<
" ALL" << endl;