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
if
(gSystem->mkdir (dir.c_str(),
true
) != 0 &&
42
gSystem->AccessPathName (dir.c_str()) != 0)
43
throw
std::runtime_error (
"failed to create directory: "
+ dir);
44
m_file
= std::make_unique<TFile> (val_path.c_str(),
"RECREATE"
);
45
if
(
m_file
->IsZombie() || !
m_file
->IsOpen())
46
{
47
m_file
.reset();
48
throw
std::runtime_error (
"failed to create file: "
+ val_path);
49
}
50
51
RCU_NEW_INVARIANT
(
this
);
52
}
53
54
55
56
DiskWriterLocal ::
57
~DiskWriterLocal ()
58
{
59
RCU_DESTROY_INVARIANT
(
this
);
60
61
if
(
m_file
)
62
{
63
try
64
{
65
close
();
66
}
catch
(std::exception& e)
67
{
68
std::cerr <<
"exception closing file "
<<
m_path
<<
": "
69
<< e.what() << std::endl;
70
71
}
catch
(...)
72
{
73
std::cerr <<
"unknown exception closing file "
<<
m_path
<< std::endl;
74
}
75
}
76
}
77
78
79
80
std::string DiskWriterLocal ::
81
getPath ()
const
82
{
83
RCU_READ_INVARIANT
(
this
);
84
return
m_path
;
85
}
86
87
88
89
TFile *DiskWriterLocal ::
90
getFile ()
91
{
92
RCU_CHANGE_INVARIANT
(
this
);
93
RCU_REQUIRE2_SOFT
(
m_file
!=
nullptr
,
"file already closed"
);
94
return
m_file
.get();
95
}
96
97
98
99
void
DiskWriterLocal ::
100
doClose ()
101
{
102
RCU_CHANGE_INVARIANT
(
this
);
103
RCU_REQUIRE2_SOFT
(
m_file
!=
nullptr
,
"file already closed"
);
104
105
m_file
->Write ();
106
if
(
m_file
->TestBit (TFile::kWriteError))
107
throw
std::runtime_error (
"failed to write to file: "
+
m_path
);
108
m_file
->Close ();
109
m_file
.reset();
110
}
111
}
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
std::unique_ptr< TFile > m_file
the actual file object
Definition
DiskWriterLocal.h:89
SH::DiskWriterLocal::m_path
std::string m_path
the path being used
Definition
DiskWriterLocal.h:85
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