| The Gaudi Framework v28r2p1 (f1a77ff4)

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

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Private Attributes | List of all members
RootFileHandler Class Reference

`#include <src/FileMgr/RootFileHandler.h>`

Collaboration diagram for RootFileHandler:
[legend]

## Public Member Functions
| RootFileHandler (IMessageSvc *, const std::string &userProxy, const std::string &certDir)
Io::open_t | openRootFile (const std::string &n, const Io::IoFlags &f, const std::string &desc, Io::Fd &fd, void *&ptr)
Io::close_t | closeRootFile (void *ptr)
Io::reopen_t | reopenRootFile (void *, const Io::IoFlags &)
bool | setupSSL ()

## Private Attributes
MsgStream | m_log
int | m_level
std::string | m_userProxy
std::string | m_certDir
bool | m_ssl_setup = false

## Detailed Description

Definition at line 17 of file RootFileHandler.h.

## Constructor & Destructor Documentation

RootFileHandler::RootFileHandler | ( | IMessageSvc * | msg,
|  | const std::string & | userProxy,
|  | const std::string & | certDir
| ) |  |

Definition at line 15 of file RootFileHandler.cpp.

16 :
17 m_log(msg,"RootFileHandler"), m_userProxy(p), m_certDir(c)
18 {
19 // Protect against multiple instances of TROOT
20 if ( !gROOT ) {
21 static TROOT root("root","ROOT I/O");
22 }
23 m_level = msg->outputLevel("RootFileHandler");
24
25 }
gaudirun.c
c
Definition: gaudirun.py:391
RootFileHandler::m_userProxy
std::string m_userProxy
Definition: RootFileHandler.h:37
RootFileHandler::m_certDir
std::string m_certDir
Definition: RootFileHandler.h:37
RootFileHandler::m_level
int m_level
Definition: RootFileHandler.h:35
gaudiComponentHelp.root
root
Definition: gaudiComponentHelp.py:14
RootFileHandler::m_log
MsgStream m_log
Definition: RootFileHandler.h:34
IMessageSvc::outputLevel
virtual int outputLevel() const =0
Retrieve the current output level threshold.

## Member Function Documentation

Io::close_t RootFileHandler::closeRootFile | ( | void * | ptr | ) |

Definition at line 142 of file RootFileHandler.cpp.

142 {
143
144 if (m_log.level() <= MSG::DEBUG)
145 m_log << MSG::DEBUG << "closeRootFile(ptr:" << ptr << ")"
146 << endmsg;
147
148 if ( !ptr ) {
149 m_log << MSG::ERROR << "Unable to close file: ptr == 0"
150 << endmsg;
151 return -1;
152 }
153
154 TFile* tf = static_cast<TFile*>(ptr);
155
156 try {
157 tf->Close();
158 } catch (const std::exception& Exception) {
159 m_log << MSG::ERROR << "exception caught while trying to close root"
160 << " file" << Exception.what()
161 << endmsg;
162 return -1;
163 } catch (...) {
164 m_log << MSG::ERROR << "Problems closing ROOT file \"" << tf->GetName()
165 << "\"" << endmsg;
166 return -1;
167 }
168
169 return 0;
170
171 }
MsgStream::level
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MSG::DEBUG
Definition: IMessageSvc.h:18
std::exception::what
T what(T...args)
std::exception
STL class.
MSG::ERROR
Definition: IMessageSvc.h:21
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
RootFileHandler::m_log
MsgStream m_log
Definition: RootFileHandler.h:34

Io::open_t RootFileHandler::openRootFile | ( | const std::string & | n,
|  | const Io::IoFlags & | f,
|  | const std::string & | desc,
|  | Io::Fd & | fd,
|  | void *& | ptr
| ) |  |

Definition at line 30 of file RootFileHandler.cpp.

31 {
32
33 m_log.setLevel(m_level);
34
35 if (m_log.level() <= MSG::DEBUG)
36 m_log << MSG::DEBUG << "openRootFile(\"" << n << "\","
37 << f << "," << desc << ")"
38 << endmsg;
39
40 ptr = nullptr;
41 fd = -1;
42
43 std::string opt;
44
45
46 if (f == Io::READ) {
47 opt = "READ";
48 } else if ( f == (Io::WRITE | Io::CREATE | Io::EXCL) ) {
49 opt = "NEW";
50 } else if ( f == (Io::WRITE | Io::CREATE ) ) {
51 opt = "RECREATE";
52 } else if ( (f | Io::APPEND) != 0 ) {
53 opt = "UPDATE";
54 } else {
55 m_log << MSG::ERROR << "Don't know how to handle IoFlag "
56 << f << endmsg;
57 return 1;
58 }
59
60 std::unique_ptr<TFile> tf;
61
62 if (ba::starts_with(n,"https://",ba::is_iequal{}) ||
63 ba::starts_with(n,"http://",ba::is_iequal{})) {
64
65
66 if ( !f.isRead() ) {
67 m_log << MSG::ERROR << "can only open web files in READ mode. "
68 << "requested mode is: " << f
69 << endmsg;
70 return 1;
71 }
72
73 if (!m_ssl_setup && ba::starts_with(n,"https://",ba::is_iequal{}) ) {
74
75 if (!setupSSL()) {
76 m_log << MSG::ERROR
77 << "Unable to setup TSSLSocket for ROOT TWebFile access over https"
78 << endmsg;
79 }
80 }
81
82
83 try {
84 tf.reset( new TWebFile(n.c_str()));
85 } catch (const std::exception& Exception) {
86 m_log << MSG::ERROR << "exception caught while trying to open root"
87 << " file for reading: " << Exception.what() << std::endl
88 << " -> file probably corrupt." << endmsg;
89 return 1;
90 } catch (...) {
91 m_log << MSG::ERROR << "Problems opening input file \"" << n
92 << "\": probably corrupt" << endmsg;
93 return 1;
94 }
95
96 if (tf && tf->IsZombie()) {
97 m_log << MSG::ERROR << "Problems opening input file \"" << n
98 << "\": file does not exist or in not accessible" << endmsg;
99 tf.reset();
100 return 1;
101 }
102
103
104 } else {
105
106 try {
107 tf.reset( TFile::Open(n.c_str(),opt.c_str()) );
108 } catch (const std::exception& Exception) {
109 m_log << MSG::ERROR << "exception caught while trying to open root"
110 << " file for reading: " << Exception.what() << std::endl
111 << " -> file probably corrupt." << endmsg;
112 return 1;
113 } catch (...) {
114 m_log << MSG::ERROR << "Problems opening input file \"" << n
115 << "\": probably corrupt" << endmsg;
116 return 1;
117 }
118
119 }
120
121 if (!tf || !tf->IsOpen()) {
122 m_log << MSG::ERROR << "Unable to open ROOT file \"" << n
123 << "\" with options \"" << opt << "\"" << endmsg;
124
125 tf.reset();
126 return 1;
127 }
128
129 fd = tf->GetFd();
130
131 ptr = tf.release();
132
133 if (m_log.level() <= MSG::DEBUG)
134 m_log << MSG::DEBUG << "opened TFile " << ptr << " Fd: " << fd << endmsg;
135
136 return 0;
137 }
gaudirun.fd
fd
Definition: gaudirun.py:459
MsgStream::level
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MSG::DEBUG
Definition: IMessageSvc.h:18
std::endl
T endl(T...args)
RootFileHandler::setupSSL
bool setupSSL()
Definition: RootFileHandler.cpp:187
Io::EXCL
Definition: IFileMgr.h:31
std::unique_ptr::release
T release(T...args)
std::string
STL class.
std::exception::what
T what(T...args)
RootFileHandler::m_ssl_setup
bool m_ssl_setup
Definition: RootFileHandler.h:38
Io::WRITE
Definition: IFileMgr.h:27
Io::READ
Definition: IFileMgr.h:26
RootFileHandler::m_level
int m_level
Definition: RootFileHandler.h:35
std::unique_ptr::reset
T reset(T...args)
std::exception
STL class.
Io::APPEND
Definition: IFileMgr.h:34
std::unique_ptr< TFile >
Io::CREATE
Definition: IFileMgr.h:30
std::string::c_str
T c_str(T...args)
MsgStream::setLevel
void setLevel(int level)
Update outputlevel.
Definition: MsgStream.h:106
Io::IoFlags::isRead
bool isRead() const
Definition: IFileMgr.h:54
MSG::ERROR
Definition: IMessageSvc.h:21
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
RootFileHandler::m_log
MsgStream m_log
Definition: RootFileHandler.h:34

Io::reopen_t RootFileHandler::reopenRootFile | ( | void * | ,
|  | const Io::IoFlags & |
| ) |  |

Definition at line 177 of file RootFileHandler.cpp.

177 {
178
179 m_log << MSG::ERROR << "reopen not implemented" << endmsg;
180 return -1;
181
182 }
MSG::ERROR
Definition: IMessageSvc.h:21
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
RootFileHandler::m_log
MsgStream m_log
Definition: RootFileHandler.h:34

bool RootFileHandler::setupSSL | ( |  | ) |

Definition at line 187 of file RootFileHandler.cpp.

187 {
188
189 if (m_log.level() <= MSG::DEBUG)
190 m_log << MSG::DEBUG << "setupSSL"
191 << endmsg;
192
193 // don't set anything up
194 if (m_userProxy == "NONE" || m_certDir == "NONE") {
195 m_ssl_setup = true;
196 return true;
197 }
198
199 // get stuff from $X509_USER_PROXY and $X509_CERT_DIR env vars
200 if (m_userProxy == "X509") {
201 if (!System::getEnv("X509_USER_PROXY", m_userProxy)) {
202 m_log << MSG::ERROR << "env var X509_USER_PROXY not set" << endmsg;
203 return false;
204 }
205 }
206
207 if (m_certDir == "X509") {
208 if (!System::getEnv("X509_CERT_DIR", m_certDir)) {
209 m_log << MSG::ERROR << "env var X509_CERT_DIR not set" << endmsg;
210 return false;
211 }
212 }
213
214 if (m_log.level() <= MSG::DEBUG)
215 m_log << MSG::DEBUG << "userProxy: " << m_userProxy
216 << " certDir: " << m_certDir
217 << endmsg;
218
219
220 TSSLSocket::SetUpSSL(m_userProxy.c_str(), m_certDir.c_str(),
221 m_userProxy.c_str(), m_userProxy.c_str());
222
223 m_ssl_setup = true;
224
225 return true;
226
227 }
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:550
MsgStream::level
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
MSG::DEBUG
Definition: IMessageSvc.h:18
RootFileHandler::m_userProxy
std::string m_userProxy
Definition: RootFileHandler.h:37
RootFileHandler::m_certDir
std::string m_certDir
Definition: RootFileHandler.h:37
RootFileHandler::m_ssl_setup
bool m_ssl_setup
Definition: RootFileHandler.h:38
std::string::c_str
T c_str(T...args)
MSG::ERROR
Definition: IMessageSvc.h:21
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
RootFileHandler::m_log
MsgStream m_log
Definition: RootFileHandler.h:34

## Member Data Documentation

std::string RootFileHandler::m_certDir
| private

Definition at line 37 of file RootFileHandler.h.

int RootFileHandler::m_level
| private

Definition at line 35 of file RootFileHandler.h.

MsgStream RootFileHandler::m_log
| private

Definition at line 34 of file RootFileHandler.h.

bool RootFileHandler::m_ssl_setup = false
| private

Definition at line 38 of file RootFileHandler.h.

std::string RootFileHandler::m_userProxy
| private

Definition at line 37 of file RootFileHandler.h.

The documentation for this class was generated from the following files:

- GaudiSvc/src/FileMgr/RootFileHandler.h
- GaudiSvc/src/FileMgr/RootFileHandler.cpp