The Gaudi Framework  v32r2 (46d42edc)
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::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  // Protect against multiple instances of TROOT
18  if ( !gROOT ) { static TROOT root( "root", "ROOT I/O" ); }
19  m_level = msg->outputLevel( "RootFileHandler" );
20 }
std::string m_userProxy
std::string m_certDir

Member Function Documentation

◆ closeRootFile()

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

Definition at line 119 of file RootFileHandler.cpp.

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

◆ openRootFile()

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

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

◆ reopenRootFile()

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

Definition at line 146 of file RootFileHandler.cpp.

146  {
147 
148  m_log << MSG::ERROR << "reopen not implemented" << endmsg;
149  return -1;
150 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ setupSSL()

bool RootFileHandler::setupSSL ( )

Definition at line 154 of file RootFileHandler.cpp.

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

Member Data Documentation

◆ m_certDir

std::string RootFileHandler::m_certDir
private

Definition at line 34 of file RootFileHandler.h.

◆ m_level

int RootFileHandler::m_level
private

Definition at line 32 of file RootFileHandler.h.

◆ m_log

MsgStream RootFileHandler::m_log
private

Definition at line 31 of file RootFileHandler.h.

◆ m_ssl_setup

bool RootFileHandler::m_ssl_setup = false
private

Definition at line 35 of file RootFileHandler.h.

◆ m_userProxy

std::string RootFileHandler::m_userProxy
private

Definition at line 34 of file RootFileHandler.h.


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