The Gaudi Framework  master (3c045658)
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 *)
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 &)

Private Attributes

MsgStream m_log
int m_level

Detailed Description

Definition at line 26 of file RootFileHandler.h.

Constructor & Destructor Documentation

◆ RootFileHandler()

RootFileHandler::RootFileHandler ( IMessageSvc * msg)

Definition at line 19 of file RootFileHandler.cpp.

19 : m_log( msg, "RootFileHandler" ) {
20 // Protect against multiple instances of TROOT
21 if ( !gROOT ) { static TROOT root( "root", "ROOT I/O" ); }
22 m_level = msg->outputLevel( "RootFileHandler" );
23}

Member Function Documentation

◆ closeRootFile()

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

Definition at line 85 of file RootFileHandler.cpp.

85 {
86
87 if ( m_log.level() <= MSG::DEBUG ) m_log << MSG::DEBUG << "closeRootFile(ptr:" << ptr << ")" << endmsg;
88
89 if ( !ptr ) {
90 m_log << MSG::ERROR << "Unable to close file: ptr == 0" << endmsg;
91 return -1;
92 }
93
94 TFile* tf = static_cast<TFile*>( ptr );
95
96 try {
97 tf->Close();
98 } catch ( const std::exception& Exception ) {
99 m_log << MSG::ERROR << "exception caught while trying to close root"
100 << " file" << Exception.what() << endmsg;
101 return -1;
102 } catch ( ... ) {
103 m_log << MSG::ERROR << "Problems closing ROOT file \"" << tf->GetName() << "\"" << endmsg;
104 return -1;
105 }
106
107 return 0;
108}
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 27 of file RootFileHandler.cpp.

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

112 {
113
114 m_log << MSG::ERROR << "reopen not implemented" << endmsg;
115 return -1;
116}

Member Data Documentation

◆ m_level

int RootFileHandler::m_level
private

Definition at line 39 of file RootFileHandler.h.

◆ m_log

MsgStream RootFileHandler::m_log
private

Definition at line 38 of file RootFileHandler.h.


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