ATLAS Offline Software
DiskWriterLocal.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
8 //
9 // includes
10 //
11 
13 
14 #include <exception>
15 #include <iostream>
16 #include <TFile.h>
17 #include <TSystem.h>
18 #include <RootCoreUtils/Assert.h>
19 #include <RootCoreUtils/ThrowMsg.h>
20 
21 //
22 // method implementations
23 //
24 
25 namespace SH
26 {
28  testInvariant () const
29  {
30  }
31 
32 
33 
35  DiskWriterLocal (const std::string& val_path)
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  }
46 
47 
48 
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  }
70 
71 
72 
73  std::string DiskWriterLocal ::
74  getPath () const
75  {
76  RCU_READ_INVARIANT (this);
77  return m_path;
78  }
79 
80 
81 
83  getFile ()
84  {
85  RCU_CHANGE_INVARIANT (this);
86  RCU_REQUIRE2_SOFT (m_file != 0, "file already closed");
87  return m_file;
88  }
89 
90 
91 
93  doClose ()
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  }
104 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
RCU_REQUIRE
#define RCU_REQUIRE(x)
Definition: Assert.h:208
SH::DiskWriterLocal::doClose
virtual void doClose()
closes the file we are writing to
Definition: DiskWriterLocal.cxx:93
Assert.h
SH::DiskWriterLocal::getFile
virtual TFile * getFile()
the file we are writing to
Definition: DiskWriterLocal.cxx:83
m_path
std::string m_path
the path being used
Definition: OutputStreamData.cxx:88
calibdata.exception
exception
Definition: calibdata.py:496
SH::DiskWriterLocal::m_file
TFile * m_file
the actual file object
Definition: DiskWriterLocal.h:84
SH::DiskWriterLocal::testInvariant
void testInvariant() const
test the invariant of this object
Definition: DiskWriterLocal.cxx:28
DiskWriterLocal.h
beamspotman.dir
string dir
Definition: beamspotman.py:623
SH::DiskWriterLocal::~DiskWriterLocal
~DiskWriterLocal()
standard destructor
Definition: DiskWriterLocal.cxx:50
ThrowMsg.h
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
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition: Assert.h:235
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
SH::DiskWriterLocal::getPath
virtual std::string getPath() const
the path where this file can be accessed or the empty string if it is not known (yet).
Definition: DiskWriterLocal.cxx:74
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition: PrunDriver.h:15
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
SH::DiskWriterLocal::DiskWriterLocal
DiskWriterLocal(const std::string &val_path)
standard constructor
Definition: DiskWriterLocal.cxx:35
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