The Gaudi Framework  master (37c0b60a)
FileMgr.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
12 // FileMgr.h
13 // Manages all file open/reopen/close
14 // implementation of IFileMgr
15 // Author: C.Leggett
17 
18 #ifndef GAUDISVC_FILEMGR_H
19 #define GAUDISVC_FILEMGR_H 1
20 
21 #include <GaudiKernel/ClassID.h>
22 #include <GaudiKernel/IFileMgr.h>
24 #include <GaudiKernel/Service.h>
25 #include <GaudiKernel/StatusCode.h>
26 
27 #include "POSIXFileHandler.h"
28 #include "RootFileHandler.h"
29 
30 #include <list>
31 #include <map>
32 #include <optional>
33 #include <string>
34 
35 using Io::Fd;
36 using Io::FileAttr;
37 using Io::FileHdlr;
38 using Io::IoFlag;
39 using Io::IoFlags;
40 using Io::IoTech;
41 
42 class RootFileHandler;
43 class POSIXFileHandler;
44 
45 class FileMgr : public extends<Service, IFileMgr, IIncidentListener> {
46 public:
47  using extends::extends;
48  ~FileMgr() override;
49 
50  StatusCode initialize() override;
51  StatusCode finalize() override;
52 
53  void handle( const Incident& ) override;
54 
55  StatusCode regHandler( FileHdlr ) override;
56  StatusCode hasHandler( const IoTech& ) const override;
57 
58  StatusCode deregHandler( const IoTech& ) override;
59 
60  StatusCode getHandler( const IoTech&, FileHdlr& ) const override;
61  StatusCode getHandler( const std::string&, FileHdlr& ) const override;
62 
63  int getFileAttr( const std::string&, std::vector<const FileAttr*>& ) const override;
64  StatusCode getFileAttr( const Fd, const FileAttr*& ) const override;
65  StatusCode getFileAttr( void*, const FileAttr*& ) const override;
66 
67  void listHandlers() const override;
68  void listFiles() const override;
69  virtual void listActions() const; // does not override...
70  virtual void listSuppression() const; // does not override...
71 
72  int getFiles( std::vector<std::string>&, bool onlyOpen = true ) const override;
73  int getFiles( std::vector<const Io::FileAttr*>&, bool onlyOpen = true ) const override;
74  int getFiles( const Io::IoTech&, std::vector<std::string>&, bool onlyOpen = true ) const override;
75  int getFiles( const Io::IoTech&, std::vector<const Io::FileAttr*>&, bool onlyOpen = true ) const override;
76  int getFiles( const Io::IoTech&, const Io::IoFlags&, std::vector<std::string>&, bool onlyOpen = true ) const override;
78  bool onlyOpen = true ) const override;
79 
80  int getFd( std::vector<Fd>& ) const override;
81  int getFd( const Io::IoTech&, std::vector<Io::Fd>& ) const override;
82  int getFd( const Io::IoTech&, const Io::IoFlags&, std::vector<Io::Fd>& ) const override;
83 
84  // get file name given Fd or ptr
85  const std::string& fname( const Io::Fd& ) const override;
86  const std::string& fname( void* ) const override;
87 
88  // get Fd or ptr given file name
89  Io::Fd fd( const std::string& ) const override;
90  Io::Fd fd( void* ) const override;
91 
92  void* fptr( const std::string& ) const override;
93  void* fptr( const Io::Fd& ) const override;
94 
95  int getLastError( std::string& ) const override;
96 
97  // Open file, get Fd and ptr
98  Io::open_t open( const Io::IoTech&, const std::string& caller, const std::string& fname, const Io::IoFlags&,
99  Io::Fd& fd, void*& ptr, const std::string& desc = "", const bool shared = false ) override;
100 
101  // Open file, get Fd
102  Io::open_t open( const Io::IoTech&, const std::string& caller, const std::string& fname, const Io::IoFlags&, Io::Fd&,
103  const std::string& desc = "", const bool shared = false ) override;
104 
105  // Open file, get ptr
106  Io::open_t open( const Io::IoTech&, const std::string& caller, const std::string& fname, const Io::IoFlags&, void*&,
107  const std::string& desc = "", const bool shared = false ) override;
108 
109  Io::close_t close( const Fd, const std::string& caller ) override;
110  Io::close_t close( void*, const std::string& caller ) override;
111 
112  Io::reopen_t reopen( const Fd, const IoFlags&, const std::string& caller ) override;
113  Io::reopen_t reopen( void*, const IoFlags&, const std::string& caller ) override;
114 
115  StatusCode regAction( Io::bfcn_action_t, const Io::Action&, const std::string& desc = "" ) override;
117  const std::string& desc = "" ) override;
118 
119  void suppressAction( const std::string& ) override;
120  void suppressAction( const std::string&, const Io::Action& ) override;
121 
122 private:
124  Gaudi::Property<bool> m_printSummary{ this, "PrintSummary", false };
125  Gaudi::Property<bool> m_loadRootHandler{ this, "LoadROOTHandler", true };
126  Gaudi::Property<bool> m_loadPosixHandler{ this, "LoadPOSIXHandler", true };
127 
128  Gaudi::Property<std::string> m_ssl_proxy{ this, "TSSL_UserProxy", "X509" };
129  Gaudi::Property<std::string> m_ssl_cert{ this, "TSSL_CertDir", "X509" };
130 
131  virtual Io::open_t open( const IoTech&, const std::string& caller, const std::string& fname, const std::string& desc,
132  const IoFlags&, Fd&, void*&,
133  const bool shared ); // does not override...
134 
137  StatusCode execAction( Io::FileAttr*, const std::string&, const Io::Action& ) const;
138  StatusCode execActs( Io::FileAttr*, const std::string&, const Io::Action&, const actionMap& m ) const;
139 
140  bool accessMatch( const Io::IoFlags&, const Io::IoFlags&, bool strict = false ) const;
141  bool isShareable( const std::string& filename, const Io::IoFlags& ) const;
142 
144 
149 
151 
153 
155 
158 
159  std::optional<RootFileHandler> m_rfh;
160  std::optional<POSIXFileHandler> m_pfh;
161 };
162 
163 #endif
FileMgr::m_rfh
std::optional< RootFileHandler > m_rfh
Definition: FileMgr.h:159
Io::IoTech
IoTech
Definition: IFileMgr.h:156
FileMgr::execActs
StatusCode execActs(Io::FileAttr *, const std::string &, const Io::Action &, const actionMap &m) const
Definition: FileMgr.cpp:1115
FileMgr::m_pfh
std::optional< POSIXFileHandler > m_pfh
Definition: FileMgr.h:160
FileMgr::isShareable
bool isShareable(const std::string &filename, const Io::IoFlags &) const
FileMgr::getFiles
int getFiles(std::vector< std::string > &, bool onlyOpen=true) const override
Definition: FileMgr.cpp:780
FileMgr::m_oldFiles
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:150
std::string
STL class.
RootFileHandler.h
FileMgr::m_loadPosixHandler
Gaudi::Property< bool > m_loadPosixHandler
Definition: FileMgr.h:126
FileMgr::m_ssl_proxy
Gaudi::Property< std::string > m_ssl_proxy
Definition: FileMgr.h:128
Io::open_t
int open_t
Definition: IFileMgr.h:243
FileMgr::fptr
void * fptr(const std::string &) const override
Definition: FileMgr.cpp:967
FileMgr::fd
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:949
FileMgr::suppressAction
void suppressAction(const std::string &) override
Definition: FileMgr.cpp:1162
FileMgr::handle
void handle(const Incident &) override
Definition: FileMgr.cpp:182
std::pair
FileMgr::m_supMap
std::map< std::string, Io::Action_bitmap > m_supMap
Definition: FileMgr.h:154
FileMgr::m_loadRootHandler
Gaudi::Property< bool > m_loadRootHandler
Definition: FileMgr.h:125
std::vector
STL class.
ClassID.h
FileMgr::open
virtual Io::open_t open(const IoTech &, const std::string &caller, const std::string &fname, const std::string &desc, const IoFlags &, Fd &, void *&, const bool shared)
FileMgr::getFileAttr
StatusCode getFileAttr(const Fd, const FileAttr *&) const override
FileMgr
Definition: FileMgr.h:45
FileMgr::hasHandler
StatusCode hasHandler(const IoTech &) const override
Definition: FileMgr.cpp:234
FileMgr::listActions
virtual void listActions() const
Definition: FileMgr.cpp:1072
POSIXFileHandler.h
IFileMgr.h
std::function
FileMgr::getHandler
StatusCode getHandler(const IoTech &, FileHdlr &) const override
StatusCode.h
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:242
Io::reopen_t
int reopen_t
Definition: IFileMgr.h:245
FileMgr::initialize
StatusCode initialize() override
Definition: FileMgr.cpp:71
FileMgr::close
Io::close_t close(const Fd, const std::string &caller) override
FileMgr::getFileAttr
int getFileAttr(const std::string &, std::vector< const FileAttr * > &) const override
Definition: FileMgr.cpp:723
FileMgr::fname
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:931
FileMgr::regHandler
StatusCode regHandler(FileHdlr) override
Definition: FileMgr.cpp:186
FileMgr::fileMap
std::multimap< std::string, FileAttr * > fileMap
Definition: FileMgr.h:143
StatusCode
Definition: StatusCode.h:65
FileMgr::m_handlers
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:146
FileMgr::execAction
StatusCode execAction(Io::FileAttr *, const std::string &, const Io::Action &) const
Definition: FileMgr.cpp:1097
FileMgr::deregHandler
StatusCode deregHandler(const IoTech &) override
Definition: FileMgr.cpp:220
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
FileMgr::m_logfile
Gaudi::Property< std::string > m_logfile
Definition: FileMgr.h:123
Io::FileAttr
Definition: IFileMgr.h:171
FileMgr::m_descriptors
std::map< Fd, FileAttr * > m_descriptors
Definition: FileMgr.h:147
FileMgr::m_ssl_cert
Gaudi::Property< std::string > m_ssl_cert
Definition: FileMgr.h:129
FileMgr::m_lastErrS
std::string m_lastErrS
Definition: FileMgr.h:156
FileMgr::accessMatch
bool accessMatch(const Io::IoFlags &, const Io::IoFlags &, bool strict=false) const
Definition: FileMgr.cpp:1151
std::map
STL class.
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
Io::Fd
int Fd
Definition: IFileMgr.h:169
Io::close_t
int close_t
Definition: IFileMgr.h:244
FileMgr::listSuppression
virtual void listSuppression() const
Definition: FileMgr.cpp:1170
FileMgr::finalize
StatusCode finalize() override
Definition: FileMgr.cpp:125
FileMgr::getLastError
int getLastError(std::string &) const override
Definition: FileMgr.cpp:997
POSIXFileHandler
Definition: POSIXFileHandler.h:27
FileMgr::m_printSummary
Gaudi::Property< bool > m_printSummary
Definition: FileMgr.h:124
Service.h
FileMgr::regAction
StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &desc="") override
Definition: FileMgr.cpp:1053
FileMgr::listFiles
void listFiles() const override
Definition: FileMgr.cpp:985
RootFileHandler
Definition: RootFileHandler.h:27
Io::IoFlag
IoFlag
Definition: IFileMgr.h:36
FileMgr::actionMap
std::map< Io::Action, std::list< bfcn_desc_t > > actionMap
Definition: FileMgr.h:136
IIncidentListener.h
FileMgr::m_actions
std::map< IoTech, actionMap > m_actions
Definition: FileMgr.h:152
FileMgr::listHandlers
void listHandlers() const override
Definition: FileMgr.cpp:1043
FileMgr::getFd
int getFd(std::vector< Fd > &) const override
Io::FileHdlr
Definition: IFileMgr.h:254
std::multimap< std::string, FileAttr * >
FileMgr::~FileMgr
~FileMgr() override
Definition: FileMgr.cpp:63
Io::Action
Action
Definition: IFileMgr.h:278
FileMgr::reopen
Io::reopen_t reopen(const Fd, const IoFlags &, const std::string &caller) override
FileMgr::bfcn_desc_t
std::pair< Io::bfcn_action_t, std::string > bfcn_desc_t
Definition: FileMgr.h:135
Incident
Definition: Incident.h:27
graphanalysis.filename
filename
Definition: graphanalysis.py:130
Io::IoFlags
Definition: IFileMgr.h:50
FileMgr::m_files
fileMap m_files
Definition: FileMgr.h:145
Gaudi::Property< std::string >
FileMgr::m_lastErr
int m_lastErr
Definition: FileMgr.h:157
FileMgr::m_attr
std::vector< std::unique_ptr< FileAttr > > m_attr
Definition: FileMgr.h:148