| The Gaudi Framework v32r1 (f65d50dc)

FileMgr.h
Go to the documentation of this file.
1 // FileMgr.h
3 // Manages all file open/reopen/close
4 // implementation of IFileMgr
5 // Author: C.Leggett
7
8 #ifndef GAUDISVC_FILEMGR_H
9 #define GAUDISVC_FILEMGR_H 1
10
11 #include "GaudiKernel/ClassID.h"
12 #include "GaudiKernel/IFileMgr.h"
13 #include "GaudiKernel/IIncidentListener.h"
14 #include "GaudiKernel/Service.h"
15 #include "GaudiKernel/StatusCode.h"
16
17 #include "POSIXFileHandler.h"
18 #include "RootFileHandler.h"
19
20 #include <list>
21 #include <map>
22 #include <optional>
23 #include <string>
24
25 using Io::Fd;
26 using Io::FileAttr;
27 using Io::FileHdlr;
28 using Io::IoFlag;
29 using Io::IoFlags;
30 using Io::IoTech;
31
32 class RootFileHandler;
33 class POSIXFileHandler;
34
35 class FileMgr : public extends<Service, IFileMgr, IIncidentListener> {
36 public:
37 using extends::extends;
38 ~FileMgr() override;
39
40 StatusCode initialize() override;
41 StatusCode finalize() override;
42
43 void handle( const Incident& ) override;
44
45 StatusCode regHandler( FileHdlr ) override;
46 StatusCode hasHandler( const IoTech& ) const override;
47
48 StatusCode deregHandler( const IoTech& ) override;
49
50 StatusCode getHandler( const IoTech&, FileHdlr& ) const override;
51 StatusCode getHandler( const std::string&, FileHdlr& ) const override;
52
53 int getFileAttr( const std::string&, std::vector<const FileAttr*>& ) const override;
54 StatusCode getFileAttr( const Fd, const FileAttr*& ) const override;
55 StatusCode getFileAttr( void*, const FileAttr*& ) const override;
56
57 void listHandlers() const override;
58 void listFiles() const override;
59 virtual void listActions() const; // does not override...
60 virtual void listSuppression() const; // does not override...
61
62 int getFiles( std::vector<std::string>&, bool onlyOpen = true ) const override;
63 int getFiles( std::vector<const Io::FileAttr*>&, bool onlyOpen = true ) const override;
64 int getFiles( const Io::IoTech&, std::vector<std::string>&, bool onlyOpen = true ) const override;
65 int getFiles( const Io::IoTech&, std::vector<const Io::FileAttr*>&, bool onlyOpen = true ) const override;
66 int getFiles( const Io::IoTech&, const Io::IoFlags&, std::vector<std::string>&, bool onlyOpen = true ) const override;
67 int getFiles( const Io::IoTech&, const Io::IoFlags&, std::vector<const Io::FileAttr*>&,
68 bool onlyOpen = true ) const override;
69
70 int getFd( std::vector<Fd>& ) const override;
71 int getFd( const Io::IoTech&, std::vector<Io::Fd>& ) const override;
72 int getFd( const Io::IoTech&, const Io::IoFlags&, std::vector<Io::Fd>& ) const override;
73
74 // get file name given Fd or ptr
75 const std::string& fname( const Io::Fd& ) const override;
76 const std::string& fname( void* ) const override;
77
78 // get Fd or ptr given file name
79 Io::Fd fd( const std::string& ) const override;
80 Io::Fd fd( void* ) const override;
81
82 void* fptr( const std::string& ) const override;
83 void* fptr( const Io::Fd& ) const override;
84
85 int getLastError( std::string& ) const override;
86
87 // Open file, get Fd and ptr
88 Io::open_t open( const Io::IoTech&, const std::string& caller, const std::string& fname, const Io::IoFlags&,
89 Io::Fd& fd, void*& ptr, const std::string& desc = "", const bool shared = false ) override;
90
91 // Open file, get Fd
92 Io::open_t open( const Io::IoTech&, const std::string& caller, const std::string& fname, const Io::IoFlags&, Io::Fd&,
93 const std::string& desc = "", const bool shared = false ) override;
94
95 // Open file, get ptr
96 Io::open_t open( const Io::IoTech&, const std::string& caller, const std::string& fname, const Io::IoFlags&, void*&,
97 const std::string& desc = "", const bool shared = false ) override;
98
99 Io::close_t close( const Fd, const std::string& caller ) override;
100 Io::close_t close( void*, const std::string& caller ) override;
101
102 Io::reopen_t reopen( const Fd, const IoFlags&, const std::string& caller ) override;
103 Io::reopen_t reopen( void*, const IoFlags&, const std::string& caller ) override;
104
105 StatusCode regAction( Io::bfcn_action_t, const Io::Action&, const std::string& desc = "" ) override;
106 StatusCode regAction( Io::bfcn_action_t, const Io::Action&, const Io::IoTech&,
107 const std::string& desc = "" ) override;
108
109 void suppressAction( const std::string& ) override;
110 void suppressAction( const std::string&, const Io::Action& ) override;
111
112 private:
113 Gaudi::Property<std::string> m_logfile{this, "LogFile"};
114 Gaudi::Property<bool> m_printSummary{this, "PrintSummary", false};
115 Gaudi::Property<bool> m_loadRootHandler{this, "LoadROOTHandler", true};
116 Gaudi::Property<bool> m_loadPosixHandler{this, "LoadPOSIXHandler", true};
117
118 Gaudi::Property<std::string> m_ssl_proxy{this, "TSSL_UserProxy", "X509"};
119 Gaudi::Property<std::string> m_ssl_cert{this, "TSSL_CertDir", "X509"};
120
121 virtual Io::open_t open( const IoTech&, const std::string& caller, const std::string& fname, const std::string& desc,
122 const IoFlags&, Fd&, void*&,
123 const bool shared ); // does not override...
124
125 typedef std::pair<Io::bfcn_action_t, std::string> bfcn_desc_t;
126 typedef std::map<Io::Action, std::list<bfcn_desc_t>> actionMap;
127 StatusCode execAction( Io::FileAttr*, const std::string&, const Io::Action& ) const;
128 StatusCode execActs( Io::FileAttr*, const std::string&, const Io::Action&, const actionMap& m ) const;
129
130 bool accessMatch( const Io::IoFlags&, const Io::IoFlags&, bool strict = false ) const;
131 bool isShareable( const std::string& filename, const Io::IoFlags& ) const;
132
133 typedef std::multimap<std::string, FileAttr*> fileMap;
134
135 fileMap m_files;
136 std::map<IoTech, FileHdlr> m_handlers;
137 std::map<Fd, FileAttr*> m_descriptors;
138 std::vector<std::unique_ptr<FileAttr>> m_attr;
139
140 std::vector<FileAttr*> m_oldFiles;
141
142 std::map<IoTech, actionMap> m_actions;
143
144 std::map<std::string, Io::Action_bitmap> m_supMap;
145
146 std::string m_lastErrS;
147 int m_lastErr;
148
149 std::optional<RootFileHandler> m_rfh;
150 std::optional<POSIXFileHandler> m_pfh;
151 };
152
153 #endif
FileMgr::m_attr
std::vector< std::unique_ptr< FileAttr > > m_attr
Definition: FileMgr.h:138
FileMgr::regHandler
StatusCode regHandler(FileHdlr) override
Definition: FileMgr.cpp:177
FileMgr::getHandler
StatusCode getHandler(const IoTech &, FileHdlr &) const override
Io::IoTech
IoTech
Definition: IFileMgr.h:146
FileMgr::m_pfh
std::optional< POSIXFileHandler > m_pfh
Definition: FileMgr.h:150
FileMgr::fd
Io::Fd fd(const std::string &) const override
Definition: FileMgr.cpp:940
FileMgr::execActs
StatusCode execActs(Io::FileAttr *, const std::string &, const Io::Action &, const actionMap &m) const
Definition: FileMgr.cpp:1106
ClassID.h
FileMgr::bfcn_desc_t
std::pair< Io::bfcn_action_t, std::string > bfcn_desc_t
Definition: FileMgr.h:125
FileMgr::isShareable
bool isShareable(const std::string &filename, const Io::IoFlags &) const
std::function
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
Io::reopen_t
int reopen_t
Definition: IFileMgr.h:235
FileMgr::m_supMap
std::map< std::string, Io::Action_bitmap > m_supMap
Definition: FileMgr.h:144
Io::Fd
int Fd
Definition: IFileMgr.h:159
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:233
FileMgr::m_loadPosixHandler
Gaudi::Property< bool > m_loadPosixHandler
Definition: FileMgr.h:116
POSIXFileHandler.h
FileMgr::suppressAction
void suppressAction(const std::string &) override
Definition: FileMgr.cpp:1153
Io::IoFlag
IoFlag
Definition: IFileMgr.h:26
FileMgr::m_files
fileMap m_files
Definition: FileMgr.h:135
Io::open_t
int open_t
Definition: IFileMgr.h:233
FileMgr::actionMap
std::map< Io::Action, std::list< bfcn_desc_t > > actionMap
Definition: FileMgr.h:126
FileMgr::getLastError
int getLastError(std::string &) const override
Definition: FileMgr.cpp:988
FileMgr::deregHandler
StatusCode deregHandler(const IoTech &) override
Definition: FileMgr.cpp:211
graphanalysis.filename
string filename
Definition: graphanalysis.py:119
FileMgr::listSuppression
virtual void listSuppression() const
Definition: FileMgr.cpp:1161
FileMgr::m_descriptors
std::map< Fd, FileAttr * > m_descriptors
Definition: FileMgr.h:137
FileMgr::hasHandler
StatusCode hasHandler(const IoTech &) const override
Definition: FileMgr.cpp:225
std::map
STL class.
POSIXFileHandler
Definition: POSIXFileHandler.h:17
std::string
STL class.
Io::Action
Action
Definition: IFileMgr.h:268
Service.h
FileMgr
Definition: FileMgr.h:35
FileMgr::m_handlers
std::map< IoTech, FileHdlr > m_handlers
Definition: FileMgr.h:136
FileMgr::m_loadRootHandler
Gaudi::Property< bool > m_loadRootHandler
Definition: FileMgr.h:115
FileMgr::handle
void handle(const Incident &) override
Definition: FileMgr.cpp:173
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:92
Io::IoFlags
Definition: IFileMgr.h:40
FileMgr::execAction
StatusCode execAction(Io::FileAttr *, const std::string &, const Io::Action &) const
Definition: FileMgr.cpp:1088
FileMgr::reopen
Io::reopen_t reopen(const Fd, const IoFlags &, const std::string &caller) override
Io::FileHdlr
Definition: IFileMgr.h:244
RootFileHandler
Definition: RootFileHandler.h:17
FileMgr::close
Io::close_t close(const Fd, const std::string &caller) override
FileMgr::listActions
virtual void listActions() const
Definition: FileMgr.cpp:1063
FileMgr::getFileAttr
int getFileAttr(const std::string &, std::vector< const FileAttr * > &) const override
Definition: FileMgr.cpp:714
FileMgr::accessMatch
bool accessMatch(const Io::IoFlags &, const Io::IoFlags &, bool strict=false) const
Definition: FileMgr.cpp:1142
FileMgr::m_lastErrS
std::string m_lastErrS
Definition: FileMgr.h:146
FileMgr::regAction
StatusCode regAction(Io::bfcn_action_t, const Io::Action &, const std::string &desc="") override
Definition: FileMgr.cpp:1044
FileMgr::fileMap
std::multimap< std::string, FileAttr * > fileMap
Definition: FileMgr.h:133
std::multimap< std::string, FileAttr * >
std::pair
FileMgr::m_oldFiles
std::vector< FileAttr * > m_oldFiles
Definition: FileMgr.h:140
std::vector
STL class.
FileMgr::fname
const std::string & fname(const Io::Fd &) const override
Definition: FileMgr.cpp:922
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
FileMgr::fptr
void * fptr(const std::string &) const override
Definition: FileMgr.cpp:958
FileMgr::m_rfh
std::optional< RootFileHandler > m_rfh
Definition: FileMgr.h:149
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
FileMgr::m_ssl_proxy
Gaudi::Property< std::string > m_ssl_proxy
Definition: FileMgr.h:118
IFileMgr.h
IIncidentListener.h
FileMgr::m_actions
std::map< IoTech, actionMap > m_actions
Definition: FileMgr.h:142
FileMgr::m_lastErr
int m_lastErr
Definition: FileMgr.h:147
StatusCode.h
FileMgr::m_printSummary
Gaudi::Property< bool > m_printSummary
Definition: FileMgr.h:114
FileMgr::getFiles
int getFiles(std::vector< std::string > &, bool onlyOpen=true) const override
Definition: FileMgr.cpp:771
FileMgr::listFiles
void listFiles() const override
Definition: FileMgr.cpp:976
FileMgr::m_logfile
Gaudi::Property< std::string > m_logfile
Definition: FileMgr.h:113
FileMgr::listHandlers
void listHandlers() const override
Definition: FileMgr.cpp:1034
FileMgr::~FileMgr
~FileMgr() override
Definition: FileMgr.cpp:54
FileMgr::getFd
int getFd(std::vector< Fd > &) const override
FileMgr::finalize
StatusCode finalize() override
Definition: FileMgr.cpp:116
FileMgr::m_ssl_cert
Gaudi::Property< std::string > m_ssl_cert
Definition: FileMgr.h:119
Io::close_t
int close_t
Definition: IFileMgr.h:234
RootFileHandler.h
FileMgr::initialize
StatusCode initialize() override
Definition: FileMgr.cpp:62
Io::FileAttr
Definition: IFileMgr.h:161