ATLAS Offline Software
Loading...
Searching...
No Matches
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>
20
21//
22// method implementations
23//
24
25namespace SH
26{
27 void DiskWriterLocal ::
28 testInvariant () const
29 {
30 }
31
32
33
34 DiskWriterLocal ::
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
49 DiskWriterLocal ::
50 ~DiskWriterLocal ()
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 }
70
71
72
73 std::string DiskWriterLocal ::
74 getPath () const
75 {
76 RCU_READ_INVARIANT (this);
77 return m_path;
78 }
79
80
81
82 TFile *DiskWriterLocal ::
83 getFile ()
84 {
86 RCU_REQUIRE2_SOFT (m_file != 0, "file already closed");
87 return m_file;
88 }
89
90
91
92 void DiskWriterLocal ::
93 doClose ()
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 }
104}
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:235
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
#define RCU_REQUIRE2_SOFT(x, y)
Definition Assert.h:155
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
#define RCU_REQUIRE(x)
Definition Assert.h:208
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
TFile * m_file
the actual file object
std::string m_path
the path being used
void close()
closes the file we are writing to
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition PrunDriver.h:15