| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

FileMgr.cpp
Go to the documentation of this file.
1 #include "FileMgr.h"
2
3 #include <fstream>
4
5 #include "GaudiKernel/ISvcLocator.h"
6 #include "GaudiKernel/IJobOptionsSvc.h"
7
8 #include "RootFileHandler.h"
9 #include "POSIXFileHandler.h"
10
11 #define ON_DEBUG if (msgLevel(MSG::DEBUG))
12 #define ON_VERBOSE if (msgLevel(MSG::VERBOSE))
13
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 DECLARE_SERVICE_FACTORY(FileMgr)
16
17 using namespace std;
18 using namespace Io;
19
20
21 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
23 namespace {
24
25 void set_bit(int& f, const unsigned int& b) {
26 f |= 1 << b;
27 }
28
29 bool get_bit(const int& f, const unsigned int& b) {
30 return f & (1 << b);
31 }
32
33 static const std::string s_empty = "";
34
35 constexpr struct to_name_t {
36 std::string operator()(const FileAttr* f) const { return f->name(); }
37 std::string operator()(const std::pair<std::string, FileAttr*>& f) const { return f.first; }
38 } to_name {} ;
39
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; }
43 } select1st {} ;
44
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; }
48 } select2nd {} ;
49
50 template <typename InputIterator, typename OutputIterator, typename UnaryOperation, typename UnaryPredicate>
51 OutputIterator transform_if( InputIterator first, InputIterator last,
52 OutputIterator result,
53 UnaryOperation op,
54 UnaryPredicate pred) {
55 while (first != last) {
56 if (pred(*first)) *result++ = op(*first);
57 ++first;
58 }
59 return result;
60 }
61
62 template <typename InputIterator, typename OutputIterator, typename UnaryOperation, typename UnaryPredicate>
63 OutputIterator transform_copy_if( InputIterator first, InputIterator last,
64 OutputIterator result,
65 UnaryOperation op,
66 UnaryPredicate pred) {
67 while (first != last) {
68 auto t = op(*first);
69 if (pred(t)) *result++ = std::move(t);
70 ++first;
71 }
72 return result;
73 }
74
75 }
76 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
77
78 FileMgr::FileMgr(const std::string& name, ISvcLocator* svc)
79 : base_class( name, svc )
80 {
81
82 declareProperty("LogFile",m_logfile="");
83 declareProperty("PrintSummary",m_printSummary=false);
84 declareProperty("LoadROOTHandler", m_loadRootHandler=true);
85 declareProperty("LoadPOSIXHandler", m_loadPosixHandler=true);
86
87 declareProperty("TSSL_UserProxy", m_ssl_proxy="X509");
88 declareProperty("TSSL_CertDir", m_ssl_cert="X509");
89
90 m_lastErrS = "";
91
92 }
93
94 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
95
96 FileMgr::~FileMgr() {
97 // Where do the new-ed FileAttr get deleted?
98 // they get pushed into m_descriptors, but m_attr is presumably
99 // where they _also_ should be pushed in order to track ownership...
100 }
101
102 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
103
104 StatusCode
105 FileMgr::initialize() {
106
107 // Super ugly hack to make sure we have the OutputLevel set first, so we
108 // can see DEBUG printouts in update handlers.
109 auto jos = serviceLocator()->service<IJobOptionsSvc>( "JobOptionsSvc", true );
110 const auto *props = ( jos ? jos->getProperties( name() ) : nullptr );
111 if (props) {
112 auto prop = std::find_if( std::begin(*props), std::end(*props),
113 [&](const Property* p) {
114 return p->name() == "OutputLevel";
115 });
116 if (prop!=std::end(*props)) {
117 setProperty( **prop ).ignore();
118 }
119 }
120
121 StatusCode status = Service::initialize();
122
123 if (status.isFailure()) {
124
125 ON_DEBUG
126 debug() << "Failed to initialize the base class (Service)"
127 << endmsg;
128 return status;
129 }
130
131 ON_VERBOSE
132 verbose() << "Initializing FileMgr" << endmsg;
133
134 if (m_loadRootHandler.value()) {
135
136 // setup file handler for ROOT
137
138 msgSvc()->setOutputLevel( "RootFileHandler", m_outputLevel.value());
139 m_rfh.reset( new RootFileHandler(msgSvc(), m_ssl_proxy, m_ssl_cert) );
140
141 auto rfh = m_rfh.get(); // used in the lambdas to avoid capturing 'this'
142 Io::FileHdlr hdlr(Io::ROOT,
143 [rfh](const std::string& n, const Io::IoFlags& f,
144 const std::string& desc, Io::Fd& fd,
145 void*& ptr) -> Io::open_t {
146 return rfh->openRootFile(n, f, desc, fd, ptr);
147 },
148 [rfh](void* ptr) -> Io::close_t {
149 return rfh->closeRootFile(ptr);
150 },
151 [rfh](void* ptr, const Io::IoFlags& f) -> Io::reopen_t {
152 return rfh->reopenRootFile(ptr, f);
153 });
154
155 if (regHandler(hdlr).isFailure()) {
156 error()
157 << "unable to register ROOT file handler with FileMgr"
158 << endmsg;
159 }
160 }
161
162 if (m_loadPosixHandler.value()) {
163
164 // setup file handler for POSIX
165
166 msgSvc()->setOutputLevel( "POSIXFileHandler", m_outputLevel.value());
167 m_pfh.reset( new POSIXFileHandler(msgSvc()) );
168
169 auto pfh = m_pfh.get(); // used in the lambdas to avoid capturing 'this'
170 Io::FileHdlr hdlp(Io::POSIX,
171 [pfh](const std::string& n, const Io::IoFlags& f,
172 const std::string& desc, Io::Fd& fd,
173 void*& ptr) -> Io::open_t {
174 return pfh->openPOSIXFile(n, f, desc, fd, ptr);
175 },
176 [pfh](Io::Fd fd) -> Io::close_t {
177 return pfh->closePOSIXFile(fd);
178 },
179 [pfh](Io::Fd fd, const Io::IoFlags& f) -> Io::reopen_t {
180 return pfh->reopenPOSIXFile(fd, f);
181 });
182
183 if (regHandler(hdlp).isFailure()) {
184 error()
185 << "unable to register ROOT file handler with FileMgr"
186 << endmsg;
187 }
188 }
189
190
191
192 return StatusCode::SUCCESS;
193
194 }
195
196 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
197
198 StatusCode
199 FileMgr::finalize() {
200 ON_VERBOSE
201 verbose() << "FileMgr::finalize()" << endmsg;
202
203
204 if (m_printSummary || msgLevel(MSG::DEBUG)) {
205 listHandlers();
206 listFiles();
207 listActions();
208 listSuppression();
209 }
210
211
212 if (!m_files.empty()) {
213 auto& log = warning();
214 log << "At finalize, the following files remained open:" << endl;
215 for (const auto& itr : m_files) log << *(itr.second) << endl;
216 log << endmsg;
217 }
218
219 if (m_logfile.value() != "") {
220 std::ofstream ofs;
221 ofs.open(m_logfile.value().c_str());
222 if (!ofs) {
223 error() << "Unable to open output file \"" << m_logfile.value()
224 << "\" for writing"
225 << endmsg;
226 } else {
227 ON_DEBUG
228 debug() << "Saving log to \"" << m_logfile.value() << "\""
229 << endmsg;
230 for (const auto& itr : m_files) {
231 ofs << itr.second->name() << " " << itr.second->tech() << " "
232 << itr.second->desc() << " " << itr.second->iflags() << endl;
233 }
234
235 set<FileAttr> fs;
236 for (const auto& it2 : m_oldFiles) fs.insert(*it2);
237 for (const auto& it3 : fs ) {
238 ofs << it3.name() << " " << it3.tech() << " " << it3.desc()
239 << " " << it3.iflags()
240 << ( it3.isShared() ? " SHARED" : "" )
241 << endl;
242 }
243 ofs.close();
244 }
245 }
246
247 // cleanup FileAttrs
248 m_attr.clear();
249
250 m_rfh.reset();
251 m_pfh.reset();
252
253
254 StatusCode status = Service::finalize();
255
256 ON_DEBUG
257 if ( status.isSuccess() )
258 debug() << "Service finalised successfully" << endmsg;
259
260 return status;
261
262 }
263
264 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
265
266 void
267 FileMgr::handle(const Incident& /*inc*/) {
268
269 }
270
271 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
272
273 StatusCode
274 FileMgr::regHandler(FileHdlr fh) {
275
276 IoTech tech = fh.tech;
277
278 if (m_handlers.find(tech) != m_handlers.end()) {
279 warning()
280 << "Handler for IoTech " << tech << " already registered. Ignoring."
281 << endmsg;
282 return StatusCode::SUCCESS;
283 }
284
285 if ( ! fh.b_open_fcn ) {
286 error()
287 << "open handler for tech " << tech << " is NULL"
288 << endmsg;
289 return StatusCode::FAILURE;
290 }
291
292 if ( ! fh.b_close_fcn && ! fh.b_closeP_fcn ) {
293 error()
294 << "no close handler for tech " << tech << " registered"
295 << endmsg;
296 return StatusCode::FAILURE;
297 }
298
299 if ( ! fh.b_reopen_fcn && ! fh.b_reopenP_fcn) {
300 error()
301 << "no reopen handler for tech " << tech << " registered"
302 << endmsg;
303 return StatusCode::FAILURE;
304 }
305
306
307 ON_DEBUG
308 debug()
309 << "Successfully registered handler for tech \"" << tech << "\""
310 << endmsg;
311
312 m_handlers[tech] = fh;
313
314 return StatusCode::SUCCESS;
315
316 }
317
318 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
319
320 StatusCode
321 FileMgr::deregHandler( const IoTech& tech ) {
322 FileHdlr hdlr;
323
324 auto itr = m_handlers.find(tech);
325 if (itr == m_handlers.end()) {
326 error() << "Can't de-register tech " << tech
327 << " as it hasn't been registered!"
328 << endmsg;
329 return StatusCode::FAILURE;
330 }
331
332 m_handlers.erase(itr);
333 return StatusCode::SUCCESS;
334
335 }
336 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
337
338 StatusCode
339 FileMgr::hasHandler( const IoTech& tech ) const {
340
341 auto itr = m_handlers.find(tech);
342 return (itr != m_handlers.end()) ? StatusCode::SUCCESS : StatusCode::FAILURE;
343
344 }
345
346 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
347
348 open_t
349 FileMgr::open( const IoTech& tech, const std::string& caller,
350 const std::string& fname,
351 const IoFlags& flags, Fd& fd, void*& ptr,
352 const std::string& desc, bool sh) {
353
354 return open(tech, caller, fname, desc, flags, fd, ptr, sh);
355
356 }
357
358 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
359 open_t
360 FileMgr::open( const IoTech& tech, const std::string& caller,
361 const std::string& fname,
362 const IoFlags& flags, Fd& fd, const std::string& desc,
363 bool sh) {
364
365 void* dummy(0);
366 return open(tech, caller, fname, desc, flags, fd, dummy, sh);
367
368 }
369
370 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
371 open_t
372 FileMgr::open( const IoTech& tech, const std::string& caller,
373 const std::string& fname,
374 const IoFlags& flags, void*& ptr, const std::string& desc,
375 bool sh) {
376
377 Fd dummy(-1);
378 return open(tech, caller, fname, desc, flags, dummy, ptr, sh);
379
380 }
381
382 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
383
384 open_t
385 FileMgr::open( const IoTech& tech, const std::string& caller,
386 const std::string& fname,
387 const std::string& desc,
388 const IoFlags& flags, Fd& fd, void*& ptr, bool shared) {
389
390 // return codes: ok == 0, warning > 0, error < 0
391 // 0: ok
392 //
393 // WARNING:
394 // 1: file already open with existing FileAttributes
395 // 2: file already open with different FileAttributes
396 // 3: file opened, but fd and ptr are both invalid
397 //
398 // ERRORS:
399 // -1: no handler for TECH
400 // -2: file already open with different tech
401 // -3: file asked to be opened in shared mode, but other open file
402 // exist that are marked unshared
403 // -4: error calling tech specific open function
404
405
406 ON_VERBOSE
407 verbose() << "open(" << tech << ","
408 << caller
409 << ",\"" << fname << "\",\""
410 << desc << "\","
411 << flags
412 << ( shared ? ",shared" : ",unshared")
413 << ")"
414 << endmsg;
415
416 open_t r = -1;
417 FileHdlr fh;
418 if (getHandler(tech,fh).isFailure()) return r;
419
420
421 auto fitr = m_files.equal_range(fname);
422
423 // make sure all files with same name have same tech
424
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()
431 << endmsg;
432 r = -1;
433 return r;
434 }
435
436
437 // check for sharing
438
439 if (shared) {
440
441 bool shareable(true);
442
443 for (auto itr=fitr.first; itr != fitr.second; ++itr) {
444 FileAttr* fa = itr->second;
445
446 if (! fa->isShared()) shareable = false;
447
448 // if ( shareable && accessMatch(fa->flags(),flags) )
449 if ( shareable && fa->flags().match(flags,false) ) {
450
451 ON_DEBUG
452 debug() << " found shared file: "
453 << *fa << endmsg;
454
455 fd = fa->fd();
456 ptr = fa->fptr();
457 r = 0;
458 }
459 }
460
461 if (!shareable) {
462 // at least one of the other files was not marked shared.
463 fd = -1;
464 ptr = 0;
465 r = -1;
466 }
467 }
468
469
470 if (r != 0) {
471
472 try {
473 r = fh.b_open_fcn(fname,flags,desc,fd,ptr);
474 } catch (const std::bad_function_call& err) {
475 error() << "when calling open handler for " << tech
476 << " on file "
477 << fname << " caught " << err.what() << endmsg;
478 return -4;
479 } catch (...) {
480 error() << "when calling open handler for " << tech
481 << " on file "
482 << fname << " caught an unknown exception." << endmsg;
483 return -4;
484 }
485
486 if (r != 0) {
487 warning()
488 << "open of file \"" << fname << "\", tech: \"" << tech
489 << "\", flags: \"" << flags << "\" requested by "
490 << caller
491 << " failed. return code: " << r
492 << endmsg;
493
494 FileAttr xfa(-1,fname,desc,tech,flags,0,false);
495 execAction( &xfa, caller, Io::OPEN_ERR ).ignore();
496
497 return r;
498 }
499 }
500
501
502 //@TODO/@FIXME: should this not be pushed into m_attr???
503 // eg. m_attr.emplace_back( new FileAttr(fd,fname,desc,tech,flags,ptr,true,shared) );
504 // FileAttr* fa = m_attr.back().get();
505 FileAttr* fa = new FileAttr(fd,fname,desc,tech,flags,ptr,true,shared);
506
507 ON_DEBUG
508 debug() << "opened file " << *fa << endmsg;
509
510
511 if (fd == -1 && ptr == 0) {
512 warning() << "when opening " << *fa << " both File Descriptor"
513 << " and File Ptr are invalid" << endmsg;
514 r = 3;
515 }
516
517
518 for (auto itr = fitr.first; itr != fitr.second; ++itr) {
519 if (fa->flags() == Io::READ || shared) {
520 // ok
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;
525 r = 1;
526 } else {
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;
532 r = 2;
533 }
534 }
535
536 m_files.emplace( fname,fa );
537
538 // execute all our open callbacks
539 if (execAction( fa, caller, Io::OPEN ).isFailure()) {
540 warning()
541 << "at least one open callback action failed"
542 << endmsg;
543 }
544
545
546 return r;
547
548 }
549
550 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
551
552 close_t
553 FileMgr::close( Fd fd, const std::string& caller ) {
554
555 // return codes:
556 // < 0 : error condition
557 // 0 : actual close of one file
558 // > 0 : shared file, removed from list, no actual close, returns
559 // number of shared files still open.
560
561 ON_VERBOSE
562 verbose() << "close(" << fd << ")"
563 << endmsg;
564
565 close_t r = -1;
566
567
568 auto itr = std::find_if( std::begin(m_files), std::end(m_files),
569 [&](fileMap::const_reference i) { return i.second->fd() == fd; } );
570
571
572 if (itr == std::end(m_files)) {
573 error() << "unknown file descriptor \"" << fd
574 << "\" when calling close()"
575 << endmsg;
576 return r;
577 }
578
579
580 IoTech tech = itr->second->tech();
581
582 FileHdlr fh;
583
584 if (getHandler(tech,fh).isFailure()) {
585 return r;
586 }
587
588 if (! fh.b_close_fcn) {
589 error() << "no close(" << tech << ",Fd) function registered"
590 << endmsg;
591 return -1;
592 }
593
594 FileAttr* fa = itr->second;
595
596 // find how many times this file is open
597 auto fitr = m_files.equal_range(fa->name());
598 int i = std::count_if(fitr.first, fitr.second, [&](fileMap::const_reference f) {
599 return f.second->fd()==fd; } );
600
601 ON_VERBOSE
602 verbose() << " ref count: " << i
603 << endmsg;
604
605
606 if (i > 1 && fa->isShared()) {
607 // file open multiple times. don't do the actual close
608 ON_DEBUG
609 debug() << "closing file " << fa->name() << " opened "
610 << i << " times with Fd " << fd << endmsg;
611 m_files.erase(itr);
612
613 r = i-1;
614
615 } else if (i == 1 || (i>1 && !fa->isShared()) ) {
616 ON_DEBUG
617 debug() << "closing " << *fa << endmsg;
618
619
620 try {
621 r = fh.b_close_fcn(fd);
622 } catch (const std::bad_function_call& err) {
623 error() << "when calling close handler for " << tech
624 << " on file descriptor "
625 << fd << " caught " << err.what() << endmsg;
626 execAction(fa, caller, Io::CLOSE_ERR ).ignore();
627 return -1;
628 } catch (...) {
629 error() << "when calling close handler for " << tech
630 << " on file descriptor "
631 << fd << " caught an unknown exception." << endmsg;
632 execAction(fa, caller, Io::CLOSE_ERR ).ignore();
633 return -1;
634 }
635
636 if (r < 0) {
637 warning()
638 << "close of file with FD \"" << fd
639 << "\", name: \"" << fa->name()
640 << "\", tech: \"" << tech << "\" failed"
641 << endmsg;
642
643 execAction(fa, caller, Io::CLOSE_ERR ).ignore();
644
645 return r;
646 }
647
648 m_files.erase(itr);
649
650 } else if (i <= 0) {
651 // this should never happen!
652 error()
653 << "ref count < 0 when closing " << fa
654 << ". This should never happen"
655 << endmsg;
656 return -1;
657
658 }
659
660 fa->fd(-1);
661 fa->flags(INVALID);
662 fa->isOpen(false);
663 fa->fptr(0);
664 m_oldFiles.push_back( fa );
665
666
667 // exec all callbacks
668 if (execAction(fa, caller, Io::CLOSE).isFailure()) {
669 warning()
670 << "at least one close callback action failed"
671 << endmsg;
672 }
673
674
675 return r;
676
677 }
678 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
679
680 close_t
681 FileMgr::close(void* vp, const std::string& caller) {
682
683 // return codes:
684 // < 0 : error condition
685 // 0 : actual close of one file
686 // > 0 : shared file, removed from list, no actual close, returns
687 // number of shared files still open.
688
689 ON_VERBOSE
690 verbose() << "close(" << vp << ")"
691 << endmsg;
692
693 close_t r = -1;
694
695 auto itr = std::find_if( std::begin(m_files), std::end(m_files),
696 [&](fileMap::const_reference i ) { return i.second->fptr()==vp; } );
697
698 if (itr == m_files.end()) {
699 error() << "unknown file ptr \"" << vp
700 << "\" when calling close()"
701 << endmsg;
702 return r;
703 }
704
705 IoTech tech = itr->second->tech();
706
707 FileHdlr fh;
708
709 if (getHandler(tech,fh).isFailure()) {
710 return r;
711 }
712 if (! fh.b_closeP_fcn) {
713 error() << "no close(" << tech << ",void*) function registered"
714 << endmsg;
715 return -1;
716 }
717
718 FileAttr *fa = itr->second;
719
720 // find how many times this file is open
721 pair<fileMap::const_iterator, fileMap::const_iterator> fitr =
722 m_files.equal_range(fa->name());
723
724 int i = std::count_if( fitr.first, fitr.second, [&](fileMap::const_reference f)
725 { return f.second->fptr()==vp; } );
726
727 ON_VERBOSE
728 verbose() << " ref count: " << i
729 << endmsg;
730
731 if (i > 1 && fa->isShared()) {
732 // file open multiple times in shared access. don't do the actual close
733 ON_DEBUG
734 debug() << "closing file " << fa->name() << " opened "
735 << i << " times with fptr " << vp << endmsg;
736 m_files.erase(itr);
737
738 r = i-1;
739
740 } else if (i == 1 || (i>1 && !fa->isShared()) ) {
741 ON_DEBUG
742 debug() << "closing: " << *fa << endmsg;
743
744 try {
745 r = fh.b_closeP_fcn(vp);
746 } catch (const std::bad_function_call& err) {
747 error() << "when calling close handler for " << tech
748 << " on file " << fa->name()
749 << " caught " << err.what() << endmsg;
750 execAction(fa, caller, CLOSE_ERR ).ignore();
751 return -1;
752 } catch (...) {
753 error() << "when calling close handler for " << tech
754 << " on file " << fa->name()
755 << " caught an unknown exception." << endmsg;
756 execAction(fa, caller, CLOSE_ERR ).ignore();
757 return -1;
758 }
759
760 if (r < 0) {
761 warning()
762 << "close of file with ptr \"" << vp
763 << "\", name: \"" << fa->name()
764 << "\", tech: \"" << tech << "\" failed"
765 << endmsg;
766
767 return r;
768 }
769
770 m_files.erase(itr);
771
772 } else {
773 // this should never happen!
774 error()
775 << "ref count: " << i << " < 0 when closing " << fa
776 << ". This should never happen"
777 << endmsg;
778 return -1;
779
780 }
781
782 fa->fd(-1);
783 fa->flags(INVALID);
784 fa->isOpen(false);
785 fa->fptr(0);
786 m_oldFiles.push_back( fa );
787
788
789 // exec all callbacks
790 if (execAction(fa, caller, CLOSE).isFailure()) {
791 warning()
792 << "at least one close callback action failed"
793 << endmsg;
794 }
795
796 return r;
797
798 }
799
800 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
801
802 reopen_t
803 FileMgr::reopen(Fd fd, const IoFlags& flags, const std::string& caller) {
804
805 ON_VERBOSE
806 verbose() << "reopen(" << fd << "," << flags
807 << "," << caller << ")"
808 << endmsg;
809
810 reopen_t r = -1;
811
812
813 auto itr = std::find_if( std::begin(m_files), std::end(m_files), [&](fileMap::const_reference f)
814 { return f.second->fd() == fd; } );
815
816 if (itr == m_files.end()) {
817 error() << "unregistered FD \"" << fd
818 << "\" when calling reopen()"
819 << endmsg;
820 return r;
821 }
822
823 FileAttr *fa = itr->second;
824 IoTech tech = fa->tech();
825
826 FileHdlr fh;
827
828 if (getHandler(tech,fh).isFailure()) {
829 return r;
830 }
831
832 fa->flags( flags );
833
834 if ( ! fh.b_reopen_fcn ) {
835 error() << "no reopen(" << tech << ",Fd) function registered"
836 << endmsg;
837 return -1;
838 }
839
840 // FIXME: what does it mean to call reopen on a shared file?
841
842
843 try {
844 r = fh.b_reopen_fcn(fd,flags);
845 } catch (const std::bad_function_call& err) {
846 error() << "when calling reopen handler for " << tech
847 << " on file descriptor " << fd << " with flags "
848 << flags
849 << " caught " << err.what() << endmsg;
850 return -1;
851 } catch (...) {
852 error() << "when calling reopen handler for " << tech
853 << " on file descriptor " << fd << " with flags "
854 << flags
855 << " caught an unknown exception." << endmsg;
856 return -1;
857 }
858
859 if (r < 0) {
860 warning()
861 << "reopen of file with FD \"" << fd
862 << "\", name: \"" << fa->name()
863 << "\", tech: \"" << tech
864 << "\", flags: \"" << flags << "\" failed"
865 << endmsg;
866
867 execAction(fa, caller, Io::REOPEN_ERR ).ignore();
868
869 return r;
870
871 }
872
873 fa->isOpen(true);
874 fa->flags(flags);
875
876 // exec all callbacks
877 if (execAction(fa, caller, Io::REOPEN).isFailure()) {
878 warning()
879 << "at least one reopen callback action failed"
880 << endmsg;
881 }
882
883 return r;
884
885 }
886
887 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
888
889 reopen_t
890 FileMgr::reopen(void* vp, const IoFlags& flags, const std::string& caller) {
891 ON_VERBOSE
892 verbose() << "reopen(" << vp << "," << flags
893 << "," << caller << ")"
894 << endmsg;
895
896 reopen_t r = -1;
897
898 auto itr = std::find_if( std::begin(m_files), std::end(m_files),
899 [&](fileMap::const_reference f) {
900 return f.second->fptr() == vp ; } );
901 if (itr == m_files.end()) {
902 error()
903 << "unregistered file ptr \"" << vp
904 << "\" when calling reopen()"
905 << endmsg;
906 return r;
907 }
908
909 FileAttr *fa = itr->second;
910 FileHdlr fh;
911 IoTech tech = fa->tech();
912
913 if (getHandler(tech,fh).isFailure()) {
914 return r;
915 }
916
917 if ( ! fh.b_reopenP_fcn ) {
918 error() << "no reopen(" << tech << ",void*) function registered"
919 << endmsg;
920 return -1;
921 }
922
923 try {
924 r = fh.b_reopenP_fcn(vp,flags);
925 } catch (const std::bad_function_call& err) {
926 error() << "when calling reopen handler for " << tech
927 << " on file " << fa->name() << " with flags "
928 << flags
929 << " caught " << err.what() << endmsg;
930 return -1;
931 } catch (...) {
932 error() << "when calling reopen handler for " << tech
933 << " on file " << fa->name() << " with flags "
934 << flags
935 << " caught an unknown exception." << endmsg;
936 return -1;
937 }
938
939 if (r < 0) {
940 warning()
941 << "reopen of file with ptr \"" << vp
942 << "\", name: \"" << fa->name()
943 << "\", tech: \"" << tech
944 << "\", flags: \"" << flags << "\" failed"
945 << endmsg;
946
947 execAction(fa, caller, Io::REOPEN_ERR ).ignore();
948
949 return r;
950
951 }
952
953 fa->isOpen(true);
954 fa->flags(flags);
955
956 // exec all callbacks
957 if (execAction(fa, caller, Io::REOPEN).isFailure()) {
958 warning()
959 << "at least one reopen callback action failed"
960 << endmsg;
961 }
962
963 return r;
964
965 }
966
967 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
968
969 int
970 FileMgr::getFileAttr(const std::string& fname, vector<const FileAttr*>& fa) const {
971
972 fa.clear();
973
974 auto fitr = m_files.equal_range(fname);
975 std::transform( fitr.first, fitr.second, std::back_inserter(fa), select2nd );
976
977 std::copy_if( std::begin(m_oldFiles), std::end(m_oldFiles),
978 std::back_inserter(fa), [&](const FileAttr* f ) { return f->name() == fname; } );
979
980 return fa.size();
981
982 }
983
984 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
985
986 StatusCode
987 FileMgr::getFileAttr(const Fd fd, const FileAttr*& fa) const {
988
989 auto i = std::find_if( std::begin(m_files), std::end(m_files),
990 [&](fileMap::const_reference f ) { return f.second->fd() == fd; } );
991 if (i != std::end(m_files)) {
992 fa = i->second;
993 return StatusCode::SUCCESS;
994 }
995
996 auto j = std::find_if( std::begin(m_oldFiles), std::end(m_oldFiles),
997 [&](const FileAttr* f) { return f->fd() == fd; } );
998 if (j != std::end(m_oldFiles)) {
999 fa = *j;
1000 return StatusCode::SUCCESS;
1001 }
1002
1003 return StatusCode::FAILURE;
1004
1005 }
1006
1007 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1008
1009 StatusCode
1010 FileMgr::getFileAttr(void* vp, const FileAttr*& fa) const {
1011
1012 auto i = std::find_if( std::begin(m_files), std::end(m_files),
1013 [&](fileMap::const_reference f) { return f.second->fptr() == vp; } );
1014 if (i != std::end(m_files)) {
1015 fa = i->second;
1016 return StatusCode::SUCCESS;
1017 }
1018
1019 auto j = std::find_if( std::begin(m_oldFiles), std::end(m_oldFiles),
1020 [&](const FileAttr* f) { return f->fptr() == vp; } );
1021 if (j != std::end(m_oldFiles)) {
1022 fa = *j;
1023 return StatusCode::SUCCESS;
1024 }
1025
1026 return StatusCode::FAILURE;
1027
1028 }
1029
1030 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1031
1032 int
1033 FileMgr::getFiles(std::vector<std::string>& files, bool op) const {
1034
1035 files.clear();
1036 auto not_in_files = [&](const std::string& i) { return std::none_of( std::begin(files), std::end(files),
1037 [&](const std::string& j) { return j==i; } ); };
1038 transform_copy_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1039 to_name,
1040 not_in_files );
1041 if (!op) {
1042 transform_copy_if( std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files),
1043 to_name,
1044 not_in_files );
1045 }
1046 return files.size();
1047 }
1048
1049 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1050
1051 int
1052 FileMgr::getFiles(vector<const Io::FileAttr*>& files, bool op) const {
1053
1054 files.clear();
1055 std::transform(std::begin(m_files), std::end(m_files), std::back_inserter(files),
1056 select2nd );
1057 if (!op) {
1058 std::copy(std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files));
1059 }
1060 return files.size();
1061
1062 }
1063
1064 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1065
1066 int
1067 FileMgr::getFiles(const IoTech& tech, vector<string>& files, bool op) const {
1068
1069 if (tech == UNKNOWN) return getFiles(files,op);
1070
1071 files.clear();
1072 transform_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1073 to_name,
1074 [&](fileMap::const_reference f) { return f.second->tech() == tech &&
1075 std::none_of( std::begin(files), std::end(files), [&](const std::string& j) { return j==f.first; } ); } );
1076
1077 if (!op) {
1078 transform_if( std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files),
1079 to_name,
1080 [&](const FileAttr* f) { return f->tech() == tech &&
1081 std::none_of( std::begin(files), std::end(files), [&](const std::string& j) { return j == f->name(); } ) ; } );
1082 }
1083 return files.size();
1084
1085 }
1086
1087 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1088
1089 int
1090 FileMgr::getFiles(const IoTech& tech, vector<const Io::FileAttr*>& files,
1091 bool op) const {
1092
1093 if (tech == UNKNOWN) return getFiles(files,op);
1094
1095 auto matches_tech = [&](const FileAttr* f) { return f->tech()==tech; } ;
1096
1097 files.clear();
1098 transform_copy_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1099 select2nd, matches_tech );
1100 if (!op) {
1101 std::copy_if( std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files),
1102 matches_tech );
1103 }
1104
1105 return files.size();
1106
1107 }
1108
1109 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1110
1111 int
1112 FileMgr::getFiles(const IoTech& tech, const IoFlags& flags,
1113 vector<string>& files, bool op) const {
1114
1115 files.clear();
1116
1117 auto not_in_files = [&](const std::string& n) { return std::none_of( std::begin(files), std::end(files),
1118 [&](const std::string& f) { return f==n; } ); };
1119 auto matches_tech_and_flags = [&](const FileAttr* f) { return ( f->tech() == tech || tech == UNKNOWN ) && f->flags() == flags ; } ;
1120
1121 transform_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1122 to_name,
1123 [&](fileMap::const_reference f) { return matches_tech_and_flags( f.second ) && not_in_files( f.first ); } );
1124 if (!op) {
1125 transform_if( std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files),
1126 to_name,
1127 [&](const FileAttr* f) { return matches_tech_and_flags(f) && not_in_files(f->name()); } );
1128 }
1129
1130 return files.size();
1131
1132 }
1133 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1134
1135 int
1136 FileMgr::getFiles(const IoTech& tech, const IoFlags& flags,
1137 vector<const Io::FileAttr*>& files, bool op) const {
1138
1139 files.clear();
1140
1141 auto matches_tech_and_flags = [&](const FileAttr* f) { return ( f->tech() == tech || tech == UNKNOWN )
1142 && f->flags() == flags ; } ;
1143
1144 transform_copy_if( std::begin(m_files), std::end(m_files), std::back_inserter(files),
1145 select2nd,
1146 matches_tech_and_flags );
1147 if (!op) {
1148 std::copy_if( std::begin(m_oldFiles), std::end(m_oldFiles), std::back_inserter(files),
1149 matches_tech_and_flags );
1150 }
1151
1152 return files.size();
1153 }
1154
1155 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1156
1157 // get all descriptors known
1158 // return number found
1159
1160 int
1161 FileMgr::getFd(vector<Fd>& fd) const {
1162
1163 std::transform( std::begin(m_descriptors), std::end(m_descriptors),
1164 std::back_inserter(fd), select1st );
1165 return m_descriptors.size();
1166
1167 }
1168
1169 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1170
1171 // get all descriptors given tech
1172 // return number found
1173
1174 int
1175 FileMgr::getFd(const IoTech& tech, vector<Fd>& fd) const {
1176
1177 if (tech == UNKNOWN) return getFd( fd );
1178
1179 fd.clear();
1180 transform_if( std::begin(m_descriptors), std::end(m_descriptors), std::back_inserter(fd),
1181 select1st,
1182 [&](const std::pair<Fd,FileAttr*>& d) { return d.second->tech()==tech; } );
1183
1184 return fd.size();
1185
1186 }
1187 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1188
1189 // get all descriptors of given tech and flags
1190 // return number found
1191
1192 int
1193 FileMgr::getFd(const IoTech& tech, const IoFlags& flags, vector<Fd>& fd) const {
1194
1195 fd.clear();
1196 transform_if( m_descriptors.begin(), m_descriptors.end(),
1197 std::back_inserter(fd), select1st,
1198 [&](const std::pair<Fd,FileAttr*>& d) {
1199 return (d.second->tech() == tech || tech == UNKNOWN) &&
1200 ( d.second->flags() == flags );
1201 } );
1202 return fd.size();
1203 }
1204
1205 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1206
1207 const std::string&
1208 FileMgr::fname(const Io::Fd& fd) const {
1209
1210 auto itr = std::find_if( std::begin(m_files), std::end(m_files),
1211 [&](fileMap::const_reference f) { return f.second->fd() == fd; } );
1212 return (itr!=std::end(m_files)) ? itr->second->name() : s_empty;
1213
1214 }
1215
1216 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1217
1218 const std::string&
1219 FileMgr::fname(void* vp) const {
1220
1221 auto itr = std::find_if( m_files.begin(), m_files.end(),
1222 [&](fileMap::const_reference f) {
1223 return f.second->fptr() == vp;
1224 });
1225 return itr!=m_files.end() ? itr->second->name() : s_empty;
1226 }
1227
1228 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1229
1230 Io::Fd
1231 FileMgr::fd(const std::string& fname) const {
1232
1233 auto fitr = m_files.equal_range(fname);
1234 auto itr = std::find_if( fitr.first, fitr.second, [](fileMap::const_reference f) {
1235 return f.second->fd() != -1;
1236 } );
1237 return itr!=fitr.second ? itr->second->fd() : -1 ;
1238 }
1239
1240 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1241
1242 Io::Fd
1243 FileMgr::fd(void* fptr) const {
1244
1245 auto itr = std::find_if(m_files.begin(),m_files.end(),[&](fileMap::const_reference f) {
1246 return f.second->fptr() == fptr;
1247 } );
1248 return itr!=m_files.end() ? itr->second->fd() : -1 ;
1249 }
1250
1251 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1252
1253 void*
1254 FileMgr::fptr(const std::string& fname) const {
1255 auto fitr = m_files.equal_range(fname);
1256 auto itr = std::find_if( fitr.first, fitr.second, [](fileMap::const_reference f) -> bool {
1257 return f.second->fptr();
1258 } );
1259 return itr!=fitr.second ? itr->second->fptr() : nullptr;
1260 }
1261
1262 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1263
1264 void*
1265 FileMgr::fptr(const Io::Fd& fd) const {
1266
1267 auto itr = std::find_if(m_files.begin(),m_files.end(),[&](fileMap::const_reference f) {
1268 return f.second->fd() == fd;
1269 } );
1270 return itr!=m_files.end() ? itr->second->fptr() : nullptr;
1271 }
1272
1273 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1274
1275 void
1276 FileMgr::listFiles() const {
1277
1278 info() << "listing registered files ["
1279 << (m_files.size() + m_oldFiles.size() )
1280 << "]:" << endl;
1281
1282 for (auto& itr : m_files ) info() << itr.second << endl;
1283 for (auto& it2 : m_oldFiles ) info() << *it2 << endl;
1284
1285 info() << endmsg;
1286 }
1287
1288 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1289
1290 int
1291 FileMgr::getLastError(std::string& err) const {
1292
1293 err = m_lastErrS;
1294 return m_lastErr;
1295
1296 }
1297
1298 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1299
1300 StatusCode
1301 FileMgr::getHandler(const Io::IoTech& tech, Io::FileHdlr& hdlr) const {
1302
1303 auto itr = m_handlers.find(tech);
1304 if (itr == m_handlers.end()) {
1305 error()
1306 << "no handler for tech " << tech << " registered"
1307 << endmsg;
1308 return StatusCode::FAILURE;
1309 }
1310 hdlr = itr->second;
1311 return StatusCode::SUCCESS;
1312 }
1313
1314 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1315
1316 StatusCode
1317 FileMgr::getHandler(const std::string& fname, Io::FileHdlr& hdlr) const {
1318
1319 auto fitr = m_files.equal_range(fname);
1320 if (fitr.first == fitr.second) {
1321 error()
1322 << "no file \"" << fname << "\" registered. Cannot determine tech"
1323 << endmsg;
1324 return StatusCode::FAILURE;
1325 }
1326
1327 auto itr = fitr.first;
1328 IoTech tech = itr->second->tech();
1329
1330 ++itr;
1331 while( itr != fitr.second ) {
1332 if ( itr->second->tech() != tech ) {
1333 error()
1334 << "multiple technologies registered for file \"" << fname
1335 << "\". Cannot determine handler" << endmsg;
1336 return StatusCode::FAILURE;
1337 }
1338 ++itr;
1339 }
1340
1341 return getHandler(tech,hdlr);
1342
1343 }
1344
1345 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1346
1347 void
1348 FileMgr::listHandlers() const {
1349
1350 info()
1351 << "Listing registered handlers:" << endl;
1352
1353 for (const auto& itr : m_handlers ) info() << " " << itr.first << endl;
1354 info() << endmsg;
1355
1356 }
1357
1358 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1359
1360 StatusCode
1361 FileMgr::regAction(bfcn_action_t bf, const Io::Action& a, const std::string& d) {
1362
1363 return regAction(bf,a,Io::UNKNOWN,d);
1364
1365 }
1366
1367 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1368
1369 StatusCode
1370 FileMgr::regAction(bfcn_action_t bf, const Io::Action& a, const Io::IoTech& t,
1371 const std::string& d) {
1372
1373 ON_DEBUG
1374 debug() << "registering " << a << " action "
1375 << System::typeinfoName(bf.target_type())
1376 << " for tech " << t << endmsg;
1377
1378 m_actions[t][a].emplace_back(bf, (!d.empty()) ? d
1379 : System::typeinfoName(bf.target_type()));
1380 return StatusCode::SUCCESS;
1381
1382 }
1383
1384 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1385
1386 void
1387 FileMgr::listActions() const {
1388
1389 info() << "listing registered actions" << endl;
1390
1391 for (const auto& iit : m_actions) {
1392 Io::IoTech t = iit.first;
1393 const actionMap& m = iit.second;
1394
1395 if (!m.empty()) {
1396 info() << " --- Tech: ";
1397 if (t == Io::UNKNOWN) {
1398 info() << "ALL ---" << endl;
1399 } else {
1400 info() << t << " ---" << endl;
1401 }
1402 for (const auto& iia : m ) {
1403 for (const auto& it2 : iia.second ) {
1404 info() << " " << iia.first << " "
1405 << it2.second << endl;
1406 }
1407 }
1408 }
1409 }
1410 info() << endmsg;
1411 }
1412
1413 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1414
1415 StatusCode
1416 FileMgr::execAction( Io::FileAttr* fa, const std::string& caller,
1417 const Io::Action& a) const {
1418
1419 Io::IoTech tech = fa->tech();
1420
1421 StatusCode s1,s2;
1422
1423 auto itr = m_actions.find(Io::UNKNOWN);
1424
1425 if (itr != m_actions.end() && !itr->second.empty() ) {
1426 s1 = execActs(fa, caller, a, itr->second);
1427 }
1428
1429 itr = m_actions.find(tech);
1430 if (itr != m_actions.end() && !itr->second.empty() ) {
1431 s2 = execActs(fa, caller, a, itr->second);
1432 }
1433
1434 return (s1.isFailure() || s2.isFailure()) ? StatusCode::FAILURE
1435 : StatusCode::SUCCESS;
1436 }
1437
1438 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1439
1440 StatusCode
1441 FileMgr::execActs(Io::FileAttr* fa, const std::string& caller,
1442 const Io::Action& a, const actionMap& m) const {
1443
1444 auto mitr = m.find(a);
1445
1446 if (mitr == m.end() || mitr->second.empty()) {
1447 return StatusCode::SUCCESS;
1448 }
1449
1450 ON_DEBUG
1451 debug()
1452 << "executing " << mitr->second.size() << " " << a
1453 << " actions on "
1454 << *fa << " from "
1455 << caller
1456 << endmsg;
1457
1458
1459 bool fail(false);
1460
1461 auto it2 = m_supMap.find(fa->name());
1462 if (it2 != m_supMap.end()) {
1463 if (get_bit(it2->second,a) || get_bit(it2->second,Io::INVALID_ACTION)) {
1464 ON_DEBUG
1465 debug() << " --> suppressing callback action for "
1466 << a
1467 << endmsg;
1468 return StatusCode::SUCCESS;
1469 }
1470 }
1471
1472 for (const auto& itr : mitr->second ) {
1473
1474 ON_DEBUG
1475 debug() << "executing "
1476 << itr.second << endmsg;
1477
1478 if ( (((itr.first))(fa,caller)).isFailure() ) {
1479 warning() << "execution of "
1480 << itr.second << " on " << *fa
1481 << " failed during " << a << " action"
1482 << endmsg;
1483 fail = true;
1484 }
1485
1486 }
1487
1488 return fail ? StatusCode::FAILURE : StatusCode::SUCCESS;
1489
1490 }
1491
1492 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1493
1494 bool
1495 FileMgr::accessMatch(const Io::IoFlags& fold, const Io::IoFlags& fnew,
1496 bool /*strict*/) const {
1497
1498 ON_VERBOSE
1499 verbose() << "accessMatch old: " << fold
1500 << " new: " << fnew
1501 << endmsg;
1502
1503 return ( ((fold == Io::READ) && (fnew == Io::READ)) ||
1504 ( (fold & Io::WRITE) != 0 && (fnew & Io::WRITE) != 0) ||
1505 ( (fold & Io::RDWR) != 0 && (fnew & Io::RDWR) != 0) ) ;
1506
1507 }
1508
1509 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1510
1511 void
1512 FileMgr::suppressAction(const std::string& f) {
1513
1514 return suppressAction(f,Io::INVALID_ACTION);
1515
1516 }
1517
1518 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1519
1520 void
1521 FileMgr::suppressAction(const std::string& f, const Io::Action& a) {
1522
1523 auto it2 = m_supMap.find(f);
1524 if (it2 == m_supMap.end()) {
1525 int b(0);
1526 set_bit(b,a);
1527 m_supMap[f] = b;
1528 } else {
1529 set_bit(it2->second, a);
1530 }
1531
1532 }
1533
1534 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1535
1536 void
1537 FileMgr::listSuppression() const {
1538
1539 if (m_supMap.empty()) return;
1540
1541 info() << "listing suppressed file actions" << endl;
1542
1543 for (auto it2=m_supMap.begin(); it2 != m_supMap.end(); ++it2) {
1544 info() << " " << it2->first;
1545 if (get_bit(it2->second, Io::INVALID_ACTION)) {
1546 info() << " ALL" << endl;
1547 } else {
1548 for (int i=0; i<Io::INVALID_ACTION; ++i) {
1549 if (get_bit(it2->second,i)) { info() << " " << (Io::Action)i; }
1550 }
1551 info() << endl;
1552 }
1553 }
1554
1555 info() << endmsg;
1556 }
FileMgr::m_attr
std::vector< std::unique_ptr< FileAttr > > m_attr
Definition: FileMgr.h:158
FileMgr::regHandler
StatusCode regHandler(FileHdlr) override
Definition: FileMgr.cpp:274
FileMgr::getHandler
StatusCode getHandler(const IoTech &, FileHdlr &) const override
Io::IoTech
IoTech
Definition: IFileMgr.h:150
FileMgr::fd
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:1231
FileMgr::m_logfile
StringProperty m_logfile
Definition: FileMgr.h:133
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:68
Service::m_outputLevel
IntegerProperty m_outputLevel
Service output level.
Definition: Service.h:309
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
std::multimap::empty
T empty(T...args)
Io
Definition: IFileMgr.h:19
std::copy_if
T copy_if(T...args)
Io::ROOT
Definition: IFileMgr.h:153
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
std::ofstream::open
T open(T...args)
Io::REOPEN
Definition: IFileMgr.h:293
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:193
std::function
Io::OPEN
Definition: IFileMgr.h:291
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:124
Property::name
const std::string & name() const
property name
Definition: Property.h:45
Io::reopen_t
int reopen_t
Definition: IFileMgr.h:254
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:297
Gaudi.Configuration.log
tuple log
Definition: Configuration.py:13
Io::Fd
int Fd
Definition: IFileMgr.h:172
FileMgr::open
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:349
Io::INVALID
Definition: IFileMgr.h:36
select1st
constexpr struct select1st_t select1st
Io::FileHdlr::b_reopen_fcn
bfcn_reopen_t b_reopen_fcn
Definition: IFileMgr.h:269
POSIXFileHandler.h
FileMgr::suppressAction
void suppressAction(const std::string &) override
Definition: FileMgr.cpp:1512
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
FileMgr::m_supMap
supMap m_supMap
Definition: FileMgr.h:165
Io::FileAttr::fptr
void * fptr() const
Definition: IFileMgr.h:190
FileMgr::m_files
fileMap m_files
Definition: FileMgr.h:155
CommonMessagingBase::verbose
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Definition: CommonMessaging.h:130
MSG::DEBUG
Definition: IMessageSvc.h:18
std::endl
T endl(T...args)
FileMgr.h
Service::setProperty
StatusCode setProperty(const Property &p) override
Definition: Service.cpp:330
Io::open_t
int open_t
Definition: IFileMgr.h:252
std
STL namespace.
Io::FileAttr::isOpen
bool isOpen() const
Definition: IFileMgr.h:191
Io::RDWR
Definition: IFileMgr.h:28
FileMgr::getLastError
int getLastError(std::string &) const override
Definition: FileMgr.cpp:1291
FileMgr::deregHandler
StatusCode deregHandler(const IoTech &) override
Definition: FileMgr.cpp:321
FileMgr::execAction
StatusCode execAction(Io::FileAttr *, const std::string &, const Io::Action &) const
Definition: FileMgr.cpp:1416
std::end
T end(T...args)
FileMgr::m_descriptors
std::map< Fd, FileAttr * > m_descriptors
Definition: FileMgr.h:157
Io::FileAttr::fd
Fd fd() const
Definition: IFileMgr.h:184
FileMgr::hasHandler
StatusCode hasHandler(const IoTech &) const override
Definition: FileMgr.cpp:339
Io::INVALID_ACTION
Definition: IFileMgr.h:297
Io::REOPEN_ERR
Definition: IFileMgr.h:296
std::map
STL class.
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
CommonMessagingBase::err
MsgStream & err() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:115
POSIXFileHandler
Definition: POSIXFileHandler.h:17
FileMgr::accessMatch
bool accessMatch(const Io::IoFlags &, const Io::IoFlags &, bool strict=false) const
Definition: FileMgr.cpp:1495
FileMgr::m_rfh
std::unique_ptr< RootFileHandler > m_rfh
Definition: FileMgr.h:170
FileMgr::listActions
virtual void listActions() const
Definition: FileMgr.cpp:1387
std::string
STL class.
Io::CLOSE
Definition: IFileMgr.h:292
Io::Action
Action
Definition: IFileMgr.h:290
FileMgr
Definition: FileMgr.h:31
Io::CLOSE_ERR
Definition: IFileMgr.h:295
Io::FileAttr::name
const std::string & name() const
Definition: IFileMgr.h:185
FileMgr::m_handlers
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:156
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
std::vector::push_back
T push_back(T...args)
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
std::ofstream
STL class.
std::bad_function_call
Io::POSIX
Definition: IFileMgr.h:152
HiveAlgSequencer.s2
tuple s2
Definition: HiveAlgSequencer.py:28
IJobOptionsSvc
Main interface for the JobOptions service.
Definition: IJobOptionsSvc.h:20
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:121
Io::FileAttr::isShared
bool isShared() const
Definition: IFileMgr.h:192
StatusCode::FAILURE
Definition: StatusCode.h:29
std::bad_function_call::what
T what(T...args)
Io::WRITE
Definition: IFileMgr.h:27
FileMgr::handle
void handle(const Incident &) override
Definition: FileMgr.cpp:267
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:93
Io::IoFlags
Definition: IFileMgr.h:39
Io::FileHdlr::b_close_fcn
bfcn_close_t b_close_fcn
Definition: IFileMgr.h:267
std::ofstream::close
T close(T...args)
FileMgr::reopen
Io::reopen_t reopen(const Fd, const IoFlags &, const std::string &caller) override
std::map::erase
T erase(T...args)
FileMgr::execActs
StatusCode execActs(Io::FileAttr *, const std::string &, const Io::Action &, const actionMap &m) const
Definition: FileMgr.cpp:1441
Io::FileHdlr
Definition: IFileMgr.h:263
Io::FileHdlr::b_closeP_fcn
bfcn_closeP_t b_closeP_fcn
Definition: IFileMgr.h:268
RootFileHandler
Definition: RootFileHandler.h:17
HiveAlgSequencer.s1
tuple s1
Definition: HiveAlgSequencer.py:27
FileMgr::m_printSummary
BooleanProperty m_printSummary
Definition: FileMgr.h:134
FileMgr::close
Io::close_t close(const Fd, const std::string &caller) override
Io::READ
Definition: IFileMgr.h:26
FileMgr::m_pfh
std::unique_ptr< POSIXFileHandler > m_pfh
Definition: FileMgr.h:171
Io::FileHdlr::b_reopenP_fcn
bfcn_reopenP_t b_reopenP_fcn
Definition: IFileMgr.h:270
FileMgr::getFileAttr
int getFileAttr(const std::string &, std::vector< const FileAttr * > &) const override
Definition: FileMgr.cpp:970
std::unique_ptr::reset
T reset(T...args)
DECLARE_SERVICE_FACTORY
#define DECLARE_SERVICE_FACTORY(x)
Definition: Service.h:361
std::vector::clear
T clear(T...args)
std::move
T move(T...args)
PropertyWithValue::value
const TYPE & value() const
explicit conversion
Definition: Property.h:341
FileMgr::m_lastErrS
std::string m_lastErrS
Definition: FileMgr.h:167
FileMgr::regAction
StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &desc="") override
Definition: FileMgr.cpp:1361
FileMgr::FileMgr
FileMgr(const std::string &name, ISvcLocator *svc)
Definition: FileMgr.cpp:78
std::count_if
T count_if(T...args)
std::function::target_type
T target_type(T...args)
std::pair
FileMgr::m_loadRootHandler
BooleanProperty m_loadRootHandler
Definition: FileMgr.h:134
std::unique_ptr::get
T get(T...args)
std::set::insert
T insert(T...args)
FileMgr::m_oldFiles
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:160
std::find_if
T find_if(T...args)
std::vector::size
T size(T...args)
Io::FileHdlr::b_open_fcn
bfcn_open_t b_open_fcn
Definition: IFileMgr.h:266
std::set
STL class.
Property
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
std::vector
STL class.
FileMgr::fname
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:1208
FileMgr::m_loadPosixHandler
BooleanProperty m_loadPosixHandler
Definition: FileMgr.h:134
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
FileMgr::listSuppression
virtual void listSuppression() const
Definition: FileMgr.cpp:1537
Io::FileAttr::tech
IoTech tech() const
Definition: IFileMgr.h:187
std::begin
T begin(T...args)
Io::IoFlags::match
bool match(const IoFlags &fa, bool strict=true) const
Definition: IFileMgr.h:59
std::back_inserter
T back_inserter(T...args)
std::none_of
T none_of(T...args)
FileMgr::fptr
void * fptr(const std::string &) const override
Definition: FileMgr.cpp:1254
FileMgr::m_ssl_cert
StringProperty m_ssl_cert
Definition: FileMgr.h:135
std::string::c_str
T c_str(T...args)
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
std::multimap::emplace
T emplace(T...args)
CommonMessaging
Definition: CommonMessaging.h:58
CommonMessagingBase::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: CommonMessaging.h:73
std::transform
T transform(T...args)
FileMgr::m_lastErr
int m_lastErr
Definition: FileMgr.h:168
FileMgr::getFiles
int getFiles(std::vector< std::string > &, bool onlyOpen=true) const override
Definition: FileMgr.cpp:1033
ON_DEBUG
#define ON_DEBUG
Definition: FileMgr.cpp:11
Io::UNKNOWN
Definition: IFileMgr.h:151
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:108
Service::declareProperty
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
FileMgr::listFiles
void listFiles() const override
Definition: FileMgr.cpp:1276
FileMgr::m_ssl_proxy
StringProperty m_ssl_proxy
Definition: FileMgr.h:135
CommonMessagingBase::msgLevel
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
Definition: CommonMessaging.h:136
FileMgr::listHandlers
void listHandlers() const override
Definition: FileMgr.cpp:1348
FileMgr::~FileMgr
~FileMgr() override
Definition: FileMgr.cpp:96
ana.i
list i
Definition: ana.py:128
Io::FileAttr::flags
IoFlags flags() const
Definition: IFileMgr.h:188
FileMgr::getFd
int getFd(std::vector< Fd > &) const override
FileMgr::finalize
StatusCode finalize() override
Definition: FileMgr.cpp:199
ISvcLocator.h
ON_VERBOSE
#define ON_VERBOSE
Definition: FileMgr.cpp:12
Io::FileHdlr::tech
IoTech tech
Definition: IFileMgr.h:264
Io::OPEN_ERR
Definition: IFileMgr.h:294
std::multimap::equal_range
T equal_range(T...args)
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Io::close_t
int close_t
Definition: IFileMgr.h:253
IMessageSvc::setOutputLevel
virtual void setOutputLevel(int new_level)=0
Set new global output level threshold.
RootFileHandler.h
FileMgr::initialize
StatusCode initialize() override
Definition: FileMgr.cpp:105
IJobOptionsSvc.h
Io::FileAttr
Definition: IFileMgr.h:174
FileMgr::m_actions
std::map< IoTech, actionMap > m_actions
Definition: FileMgr.h:162