ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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 More...
 
 DiskWriterLocal (const std::string &val_path)
 standard constructor More...
 
 ~DiskWriterLocal ()
 standard destructor More...
 
std::string path () const
 the path where this file can be accessed or the empty string if it is not known (yet). More...
 
TFile * file ()
 the file we are writing to More...
 
void close ()
 closes the file we are writing to More...
 

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). More...
 
virtual TFile * getFile ()
 the file we are writing to More...
 
virtual void doClose ()
 closes the file we are writing to More...
 

Private Attributes

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

Detailed Description

an implementation of DiskWriter for local files

See also
DiskOutputLocal

Definition at line 20 of file DiskWriterLocal.h.

Constructor & Destructor Documentation

◆ DiskWriterLocal()

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  }

◆ ~DiskWriterLocal()

SH::DiskWriterLocal::~DiskWriterLocal ( )

standard destructor

Guarantee
no-fail

Definition at line 49 of file DiskWriterLocal.cxx.

51  {
52  RCU_DESTROY_INVARIANT (this);
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  }

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  {
69  RCU_CHANGE_INVARIANT (this);
70 
71  doClose ();
72  }

◆ 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  {
95  RCU_CHANGE_INVARIANT (this);
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  }

◆ 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  {
57  RCU_CHANGE_INVARIANT (this);
58 
59  TFile *result = getFile ();
60  RCU_REQUIRE (result != 0);
61  return result;
62  }

◆ 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  {
85  RCU_CHANGE_INVARIANT (this);
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  }

◆ 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  }

◆ 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 84 of file DiskWriterLocal.h.

◆ m_path

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

the path being used

Definition at line 80 of file DiskWriterLocal.h.


The documentation for this class was generated from the following files:
get_generator_info.result
result
Definition: get_generator_info.py:21
RCU_REQUIRE
#define RCU_REQUIRE(x)
Definition: Assert.h:208
SH::DiskWriter::getPath
virtual std::string getPath() const =0
the path where this file can be accessed or the empty string if it is not known (yet).
calibdata.exception
exception
Definition: calibdata.py:496
SH::DiskWriterLocal::m_file
TFile * m_file
the actual file object
Definition: DiskWriterLocal.h:84
beamspotman.dir
string dir
Definition: beamspotman.py:623
SH::DiskWriter::getFile
virtual TFile * getFile()=0
the file we are writing to
RCU_REQUIRE2_SOFT
#define RCU_REQUIRE2_SOFT(x, y)
Definition: Assert.h:155
SH::DiskWriterLocal::m_path
std::string m_path
the path being used
Definition: DiskWriterLocal.h:80
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition: Assert.h:235
SH::DiskWriter::doClose
virtual void doClose()=0
closes the file we are writing to
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
SH::DiskWriter::close
void close()
closes the file we are writing to
Definition: DiskWriter.cxx:67
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233