The Gaudi Framework  master (2e52acd2)
Loading...
Searching...
No Matches
RootFileHandler Class Reference

#include </builds/gaudi/Gaudi/GaudiSvc/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 26 of file RootFileHandler.h.

Constructor & Destructor Documentation

◆ RootFileHandler()

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

Definition at line 22 of file RootFileHandler.cpp.

23 : m_log( msg, "RootFileHandler" ), m_userProxy( p ), m_certDir( c ) {
24 // Protect against multiple instances of TROOT
25 if ( !gROOT ) { static TROOT root( "root", "ROOT I/O" ); }
26 m_level = msg->outputLevel( "RootFileHandler" );
27}
std::string m_certDir
std::string m_userProxy

Member Function Documentation

◆ closeRootFile()

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

Definition at line 89 of file RootFileHandler.cpp.

89 {
90
91 if ( m_log.level() <= MSG::DEBUG ) m_log << MSG::DEBUG << "closeRootFile(ptr:" << ptr << ")" << endmsg;
92
93 if ( !ptr ) {
94 m_log << MSG::ERROR << "Unable to close file: ptr == 0" << endmsg;
95 return -1;
96 }
97
98 TFile* tf = static_cast<TFile*>( ptr );
99
100 try {
101 tf->Close();
102 } catch ( const std::exception& Exception ) {
103 m_log << MSG::ERROR << "exception caught while trying to close root"
104 << " file" << Exception.what() << endmsg;
105 return -1;
106 } catch ( ... ) {
107 m_log << MSG::ERROR << "Problems closing ROOT file \"" << tf->GetName() << "\"" << endmsg;
108 return -1;
109 }
110
111 return 0;
112}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
@ DEBUG
Definition IMessageSvc.h:22
@ ERROR
Definition IMessageSvc.h:22

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

32 {
33
34 m_log.setLevel( m_level );
35
36 if ( m_log.level() <= MSG::DEBUG )
37 m_log << MSG::DEBUG << "openRootFile(\"" << n << "\"," << f << "," << desc << ")" << endmsg;
38
39 ptr = nullptr;
40 fd = -1;
41
42 std::string opt;
43
44 if ( f == Io::READ ) {
45 opt = "READ";
46 } else if ( f == ( Io::WRITE | Io::CREATE | Io::EXCL ) ) {
47 opt = "NEW";
48 } else if ( f == ( Io::WRITE | Io::CREATE ) ) {
49 opt = "RECREATE";
50 } else if ( f | Io::APPEND ) {
51 opt = "UPDATE";
52 } else {
53 m_log << MSG::ERROR << "Don't know how to handle IoFlag " << f << endmsg;
54 return 1;
55 }
56
57 std::unique_ptr<TFile> tf;
58
59 try {
60 tf.reset( TFile::Open( n.c_str(), opt.c_str() ) );
61 } catch ( const std::exception& Exception ) {
62 m_log << MSG::ERROR << "exception caught while trying to open root"
63 << " file for reading: " << Exception.what() << std::endl
64 << " -> file probably corrupt." << endmsg;
65 return 1;
66 } catch ( ... ) {
67 m_log << MSG::ERROR << "Problems opening input file \"" << n << "\": probably corrupt" << endmsg;
68 return 1;
69 }
70
71 if ( !tf || !tf->IsOpen() ) {
72 m_log << MSG::ERROR << "Unable to open ROOT file \"" << n << "\" with options \"" << opt << "\"" << endmsg;
73
74 tf.reset();
75 return 1;
76 }
77
78 fd = tf->GetFd();
79
80 ptr = tf.release();
81
82 if ( m_log.level() <= MSG::DEBUG ) m_log << MSG::DEBUG << "opened TFile " << ptr << " Fd: " << fd << endmsg;
83
84 return 0;
85}
@ READ
Definition IFileMgr.h:30
@ CREATE
Definition IFileMgr.h:34
@ WRITE
Definition IFileMgr.h:31
@ EXCL
Definition IFileMgr.h:35
@ APPEND
Definition IFileMgr.h:38

◆ reopenRootFile()

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

Definition at line 116 of file RootFileHandler.cpp.

116 {
117
118 m_log << MSG::ERROR << "reopen not implemented" << endmsg;
119 return -1;
120}

◆ setupSSL()

bool RootFileHandler::setupSSL ( )

Definition at line 124 of file RootFileHandler.cpp.

124 {
125
126 if ( m_log.level() <= MSG::DEBUG ) m_log << MSG::DEBUG << "setupSSL" << endmsg;
127
128 // don't set anything up
129 if ( m_userProxy == "NONE" || m_certDir == "NONE" ) {
130 m_ssl_setup = true;
131 return true;
132 }
133
134 // get stuff from $X509_USER_PROXY and $X509_CERT_DIR env vars
135 if ( m_userProxy == "X509" ) {
136 if ( !System::getEnv( "X509_USER_PROXY", m_userProxy ) ) {
137 m_log << MSG::ERROR << "env var X509_USER_PROXY not set" << endmsg;
138 return false;
139 }
140 }
141
142 if ( m_certDir == "X509" ) {
143 if ( !System::getEnv( "X509_CERT_DIR", m_certDir ) ) {
144 m_log << MSG::ERROR << "env var X509_CERT_DIR not set" << endmsg;
145 return false;
146 }
147 }
148
149 if ( m_log.level() <= MSG::DEBUG )
150 m_log << MSG::DEBUG << "userProxy: " << m_userProxy << " certDir: " << m_certDir << endmsg;
151
152 TSSLSocket::SetUpSSL( m_userProxy.c_str(), m_certDir.c_str(), m_userProxy.c_str(), m_userProxy.c_str() );
153
154 m_ssl_setup = true;
155
156 return true;
157}
GAUDI_API std::vector< std::string > getEnv()
get all environment variables
Definition System.cpp:356

Member Data Documentation

◆ m_certDir

std::string RootFileHandler::m_certDir
private

Definition at line 43 of file RootFileHandler.h.

◆ m_level

int RootFileHandler::m_level
private

Definition at line 41 of file RootFileHandler.h.

◆ m_log

MsgStream RootFileHandler::m_log
private

Definition at line 40 of file RootFileHandler.h.

◆ m_ssl_setup

bool RootFileHandler::m_ssl_setup = false
private

Definition at line 44 of file RootFileHandler.h.

◆ m_userProxy

std::string RootFileHandler::m_userProxy
private

Definition at line 43 of file RootFileHandler.h.


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