ATLAS Offline Software
Loading...
Searching...
No Matches
SH::DiskWriterLocal Class Reference

an implementation of DiskWriter for local files More...

#include <DiskWriterLocal.h>

Inheritance diagram for SH::DiskWriterLocal:
Collaboration diagram for SH::DiskWriterLocal:

Public Member Functions

void testInvariant () const
 test the invariant of this object
 DiskWriterLocal (const std::string &val_path)
 standard constructor
 DiskWriterLocal (const DiskWriterLocal &)=delete
DiskWriterLocaloperator= (const DiskWriterLocal &)=delete
 ~DiskWriterLocal ()
 standard destructor
std::string path () const
 the path where this file can be accessed or the empty string if it is not known (yet).
TFile * file ()
 the file we are writing to
void close ()
 closes the file we are writing to

Private Member Functions

virtual std::string getPath () const
 the path where this file can be accessed or the empty string if it is not known (yet).
virtual TFile * getFile ()
 the file we are writing to
virtual void doClose ()
 closes the file we are writing to

Private Attributes

std::string m_path
 the path being used
TFile * m_file
 the actual file object

Detailed Description

an implementation of DiskWriter for local files

See also
DiskOutputLocal

Definition at line 20 of file DiskWriterLocal.h.

Constructor & Destructor Documentation

◆ DiskWriterLocal() [1/2]

SH::DiskWriterLocal::DiskWriterLocal ( const std::string & val_path)

standard constructor

Guarantee
strong
Failures
out of memory I
Precondition
!val_path.empty()

Definition at line 34 of file DiskWriterLocal.cxx.

36 : m_path (val_path)
37 {
38 RCU_REQUIRE (!val_path.empty());
39
40 std::string dir = gSystem->DirName (val_path.c_str());
41 gSystem->mkdir (dir.c_str(), true);
42 m_file = new TFile (val_path.c_str(), "RECREATE");
43
44 RCU_NEW_INVARIANT (this);
45 }
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
#define RCU_REQUIRE(x)
Definition Assert.h:208
TFile * m_file
the actual file object
std::string m_path
the path being used

◆ DiskWriterLocal() [2/2]

SH::DiskWriterLocal::DiskWriterLocal ( const DiskWriterLocal & )
delete

◆ ~DiskWriterLocal()

SH::DiskWriterLocal::~DiskWriterLocal ( )

standard destructor

Guarantee
no-fail

Definition at line 49 of file DiskWriterLocal.cxx.

51 {
53
54 if (m_file != 0)
55 {
56 try
57 {
58 close ();
59 } catch (std::exception& e)
60 {
61 std::cerr << "exception closing file " << m_path << ": "
62 << e.what() << std::endl;
63
64 } catch (...)
65 {
66 std::cerr << "unknown exception closing file " << m_path << std::endl;
67 }
68 }
69 }
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:235
void close()
closes the file we are writing to

Member Function Documentation

◆ close()

void SH::DiskWriter::close ( )
inherited

closes the file we are writing to

Guarantee
basic
Failures
i/o errors
file already closed

Definition at line 66 of file DiskWriter.cxx.

68 {
70
71 doClose ();
72 }
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
virtual void doClose()=0
closes the file we are writing to

◆ doClose()

void SH::DiskWriterLocal::doClose ( )
privatevirtual

closes the file we are writing to

Guarantee
basic
Failures
i/o errors
file already closed
Rationale
the virtual part of DiskWriter::close

Implements SH::DiskWriter.

Definition at line 92 of file DiskWriterLocal.cxx.

94 {
96 RCU_REQUIRE2_SOFT (m_file != 0, "file already closed");
97
98 if (m_file->Write () < 0)
99 RCU_THROW_MSG ("failed to write to file: " + m_path);
100 m_file->Close ();
101 delete m_file;
102 m_file = 0;
103 }
#define RCU_REQUIRE2_SOFT(x, y)
Definition Assert.h:155
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58

◆ file()

TFile * SH::DiskWriter::file ( )
inherited

the file we are writing to

Guarantee
strong
Failures
file already closed
Postcondition
result != 0

Definition at line 54 of file DiskWriter.cxx.

56 {
58
59 TFile *result = getFile ();
60 RCU_REQUIRE (result != 0);
61 return result;
62 }
virtual TFile * getFile()=0
the file we are writing to

◆ getFile()

TFile * SH::DiskWriterLocal::getFile ( )
privatevirtual

the file we are writing to

Guarantee
strong
Failures
file already closed
Postcondition
result != 0
Rationale
the virtual part of DiskWriter::file

Implements SH::DiskWriter.

Definition at line 82 of file DiskWriterLocal.cxx.

84 {
86 RCU_REQUIRE2_SOFT (m_file != 0, "file already closed");
87 return m_file;
88 }

◆ getPath()

std::string SH::DiskWriterLocal::getPath ( ) const
privatevirtual

the path where this file can be accessed or the empty string if it is not known (yet).

Rationale
while it is not guaranteed that every writer will know how to handle this, most writers will, and it can be useful. however, not every writer will know this until after the file is closed.
Rationale
the virtual part of DiskWriter::path

Implements SH::DiskWriter.

Definition at line 73 of file DiskWriterLocal.cxx.

75 {
76 RCU_READ_INVARIANT (this);
77 return m_path;
78 }
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229

◆ operator=()

DiskWriterLocal & SH::DiskWriterLocal::operator= ( const DiskWriterLocal & )
delete

◆ path()

std::string SH::DiskWriter::path ( ) const
inherited

the path where this file can be accessed or the empty string if it is not known (yet).

Rationale
while it is not guaranteed that every writer will know how to handle this, most writers will, and it can be useful. however, not every writer will know this until after the file is closed.

Definition at line 45 of file DiskWriter.cxx.

47 {
48 RCU_READ_INVARIANT (this);
49 return getPath ();
50 }
virtual std::string getPath() const =0
the path where this file can be accessed or the empty string if it is not known (yet).

◆ testInvariant()

void SH::DiskWriterLocal::testInvariant ( ) const

test the invariant of this object

Guarantee
no-fail

Definition at line 27 of file DiskWriterLocal.cxx.

29 {
30 }

Member Data Documentation

◆ m_file

TFile* SH::DiskWriterLocal::m_file
private

the actual file object

Definition at line 87 of file DiskWriterLocal.h.

◆ m_path

std::string SH::DiskWriterLocal::m_path
private

the path being used

Definition at line 83 of file DiskWriterLocal.h.


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