ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
SampleHandler
Root
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
12
#include <
SampleHandler/DiskWriterLocal.h
>
13
14
#include <exception>
15
#include <iostream>
16
#include <stdexcept>
17
#include <TFile.h>
18
#include <TSystem.h>
19
#include <
RootCoreUtils/Assert.h
>
20
21
//
22
// method implementations
23
//
24
25
namespace
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
{
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
82
TFile *DiskWriterLocal ::
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
92
void
DiskWriterLocal ::
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
throw
std::runtime_error (
"failed to write to file: "
+
m_path
);
100
m_file
->Close ();
101
delete
m_file
;
102
m_file
= 0;
103
}
104
}
Assert.h
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition
Assert.h:223
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition
Assert.h:219
RCU_REQUIRE2_SOFT
#define RCU_REQUIRE2_SOFT(x, y)
Definition
Assert.h:143
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition
Assert.h:221
RCU_REQUIRE
#define RCU_REQUIRE(x)
Definition
Assert.h:196
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition
Assert.h:217
DiskWriterLocal.h
SH::DiskWriterLocal::m_file
TFile * m_file
the actual file object
Definition
DiskWriterLocal.h:87
SH::DiskWriterLocal::m_path
std::string m_path
the path being used
Definition
DiskWriterLocal.h:83
SH::DiskWriter::close
void close()
closes the file we are writing to
Definition
DiskWriter.cxx:67
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition
PrunDriver.h:15
Generated on
for ATLAS Offline Software by
1.17.0