Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v28r2p1 (f1a77ff4)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
RootFileHandler Class Reference

#include <src/FileMgr/RootFileHandler.h>

Collaboration diagram for RootFileHandler:

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 }
std::string m_userProxy
std::string m_certDir
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 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
T what(T...args)
STL class.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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 
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 
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 }
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
T endl(T...args)
T release(T...args)
STL class.
T what(T...args)
T reset(T...args)
STL class.
T c_str(T...args)
void setLevel(int level)
Update outputlevel.
Definition: MsgStream.h:106
bool isRead() const
Definition: IFileMgr.h:54
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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(),
222 
223  m_ssl_setup = true;
224 
225  return true;
226 
227 }
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:550
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
std::string m_userProxy
std::string m_certDir
T c_str(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

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: