| The Gaudi Framework v29r0 (ff2e7097)

- 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 : m_log( msg, "RootFileHandler" ), m_userProxy( p ), m_certDir( c )
17 {
18 // Protect against multiple instances of TROOT
19 if ( !gROOT ) {
20 static TROOT root( "root", "ROOT I/O" );
21 }
22 m_level = msg->outputLevel( "RootFileHandler" );
23 }
gaudirun.c
c
Definition: gaudirun.py:407
RootFileHandler::m_userProxy
std::string m_userProxy
Definition: RootFileHandler.h:35
RootFileHandler::m_certDir
std::string m_certDir
Definition: RootFileHandler.h:35
RootFileHandler::m_level
int m_level
Definition: RootFileHandler.h:33
gaudiComponentHelp.root
root
Definition: gaudiComponentHelp.py:18
RootFileHandler::m_log
MsgStream m_log
Definition: RootFileHandler.h:32
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 123 of file RootFileHandler.cpp.

124 {
125
126 if ( m_log.level() <= MSG::DEBUG ) m_log << MSG::DEBUG << "closeRootFile(ptr:" << ptr << ")" << endmsg;
127
128 if ( !ptr ) {
129 m_log << MSG::ERROR << "Unable to close file: ptr == 0" << endmsg;
130 return -1;
131 }
132
133 TFile* tf = static_cast<TFile*>( ptr );
134
135 try {
136 tf->Close();
137 } catch ( const std::exception& Exception ) {
138 m_log << MSG::ERROR << "exception caught while trying to close root"
139 << " file" << Exception.what() << endmsg;
140 return -1;
141 } catch ( ... ) {
142 m_log << MSG::ERROR << "Problems closing ROOT file \"" << tf->GetName() << "\"" << endmsg;
143 return -1;
144 }
145
146 return 0;
147 }
MSG::DEBUG
Definition: IMessageSvc.h:16
std::exception::what
T what(T...args)
std::exception
STL class.
MSG::ERROR
Definition: IMessageSvc.h:16
MsgStream::level
MSG::Level level() const
Retrieve output level.
Definition: MsgStream.h:108
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
RootFileHandler::m_log
MsgStream m_log
Definition: RootFileHandler.h:32

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 27 of file RootFileHandler.cpp.

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

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

Definition at line 151 of file RootFileHandler.cpp.

152 {
153
154 m_log << MSG::ERROR << "reopen not implemented" << endmsg;
155 return -1;
156 }
MSG::ERROR
Definition: IMessageSvc.h:16
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
RootFileHandler::m_log
MsgStream m_log
Definition: RootFileHandler.h:32

bool RootFileHandler::setupSSL | ( |  | ) |

Definition at line 160 of file RootFileHandler.cpp.

161 {
162
163 if ( m_log.level() <= MSG::DEBUG ) m_log << MSG::DEBUG << "setupSSL" << endmsg;
164
165 // don't set anything up
166 if ( m_userProxy == "NONE" || m_certDir == "NONE" ) {
167 m_ssl_setup = true;
168 return true;
169 }
170
171 // get stuff from $X509_USER_PROXY and $X509_CERT_DIR env vars
172 if ( m_userProxy == "X509" ) {
173 if ( !System::getEnv( "X509_USER_PROXY", m_userProxy ) ) {
174 m_log << MSG::ERROR << "env var X509_USER_PROXY not set" << endmsg;
175 return false;
176 }
177 }
178
179 if ( m_certDir == "X509" ) {
180 if ( !System::getEnv( "X509_CERT_DIR", m_certDir ) ) {
181 m_log << MSG::ERROR << "env var X509_CERT_DIR not set" << endmsg;
182 return false;
183 }
184 }
185
186 if ( m_log.level() <= MSG::DEBUG )
187 m_log << MSG::DEBUG << "userProxy: " << m_userProxy << " certDir: " << m_certDir << endmsg;
188
189 TSSLSocket::SetUpSSL( m_userProxy.c_str(), m_certDir.c_str(), m_userProxy.c_str(), m_userProxy.c_str() );
190
191 m_ssl_setup = true;
192
193 return true;
194 }
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:581
MSG::DEBUG
Definition: IMessageSvc.h:16
RootFileHandler::m_userProxy
std::string m_userProxy
Definition: RootFileHandler.h:35
RootFileHandler::m_certDir
std::string m_certDir
Definition: RootFileHandler.h:35
RootFileHandler::m_ssl_setup
bool m_ssl_setup
Definition: RootFileHandler.h:36
std::string::c_str
T c_str(T...args)
MSG::ERROR
Definition: IMessageSvc.h:16
MsgStream::level
MSG::Level level() const
Retrieve output level.
Definition: MsgStream.h:108
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
RootFileHandler::m_log
MsgStream m_log
Definition: RootFileHandler.h:32

## Member Data Documentation

std::string RootFileHandler::m_certDir
| private

Definition at line 35 of file RootFileHandler.h.

int RootFileHandler::m_level
| private

Definition at line 33 of file RootFileHandler.h.

MsgStream RootFileHandler::m_log
| private

Definition at line 32 of file RootFileHandler.h.

bool RootFileHandler::m_ssl_setup = false
| private

Definition at line 36 of file RootFileHandler.h.

std::string RootFileHandler::m_userProxy
| private

Definition at line 35 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