an implementation of DiskWriter for the XRD protocol
More...
#include <DiskWriterXRD.h>
|
| void | testInvariant () const |
| | test the invariant of this object
|
| | DiskWriterXRD (const std::string &val_path) |
| | standard constructor
|
| | ~DiskWriterXRD () |
| | standard destructor
|
| std::string | path () const |
| | the path where this file can be accessed or the empty string if it is not known (yet).
|
| TFile * | file () |
| | the file we are writing to
|
| void | close () |
| | closes the file we are writing to
|
|
| virtual std::string | getPath () const override |
| | the path where this file can be accessed or the empty string if it is not known (yet).
|
| virtual TFile * | getFile () override |
| | the file we are writing to
|
| virtual void | doClose () override |
| | closes the file we are writing to
|
|
| std::string | m_tmp |
| | the temporary path being used
|
| std::string | m_path |
| | the path being used
|
| std::unique_ptr< TFile > | m_file |
| | the actual file object
|
an implementation of DiskWriter for the XRD protocol
- See also
- DiskOutputXRD
Definition at line 21 of file DiskWriterXRD.h.
◆ DiskWriterXRD()
| SH::DiskWriterXRD::DiskWriterXRD |
( |
const std::string & | val_path | ) |
|
standard constructor
- Guarantee
- strong
- Failures
- out of memory I
- Precondition
- val_path.find ("root://") == 0
Definition at line 42 of file DiskWriterXRD.cxx.
45 {
47
50 boost::hash_combine (hash, std::hash<pid_t>() (getpid()));
51 std::size_t tries = 0;
53 {
54 if (++ tries == 10)
55 throw std::runtime_error ("infinite loop trying to create tempory file for DiskWriterXRD");
56
57 auto time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
58 boost::hash_combine (hash, std::hash<decltype(time)>() (time));
59 std::size_t hash16 {
hash};
60 while (hash16 > 0xffff)
61 hash16 = (hash16&0xffff) ^ (hash16 >> 16);
62
63 std::ostringstream
str;
64 if (tmpdir)
66 else
69 << "-" << std::format("{:04x}", hash16);
71 if (gSystem->AccessPathName (
m_tmp.c_str()) != 0)
72 m_file.reset (TFile::Open (
m_tmp.c_str(),
"CREATE"));
73 }
74
76 }
#define RCU_NEW_INVARIANT(x)
std::string m_tmp
the temporary path being used
std::string m_path
the path being used
std::unique_ptr< TFile > m_file
the actual file object
time(flags, cells_name, *args, **kw)
std::string getenv(const std::string &variableName)
get an environment variable
◆ ~DiskWriterXRD()
| SH::DiskWriterXRD::~DiskWriterXRD |
( |
| ) |
|
standard destructor
- Guarantee
- no-fail
Definition at line 80 of file DiskWriterXRD.cxx.
82 {
84
86 {
87 try
88 {
90 } catch (std::exception& e)
91 {
92 std::cerr <<
"exception closing file " <<
m_path <<
": "
93 <<
e.what() << std::endl;
94
95 } catch (...)
96 {
97 std::cerr <<
"unknown exception closing file " <<
m_path << std::endl;
98 }
99 }
100 }
#define RCU_DESTROY_INVARIANT(x)
void close()
closes the file we are writing to
◆ 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 {
70
72 }
#define RCU_CHANGE_INVARIANT(x)
virtual void doClose()=0
closes the file we are writing to
◆ doClose()
| void SH::DiskWriterXRD::doClose |
( |
| ) |
|
|
overrideprivatevirtual |
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 123 of file DiskWriterXRD.cxx.
125 {
128
130 {
134 }
135
136 std::random_device rd;
137 std::mt19937
gen (rd());
138 bool success = false;
140 while (!success)
141 {
142 try
143 {
144
145
146
147
148
150 success = true;
151 } catch (...)
152 {
153 std::cerr <<
"encountered error copying files to XRD path: \"" <<
m_path <<
"\"" << std::endl;
154 if (tries < 10u)
155 {
156 tries += 1;
157
158
159
160
161 unsigned seconds = std::uniform_int_distribution<>(30,60) (
gen);
162 std::cerr <<
"sleeping for " <<
seconds <<
" seconds before retrying" << std::endl;
163 std::this_thread::sleep_for (std::chrono::seconds(seconds));
164 } else
165 {
166 std::cerr <<
"giving up, leaving file at " <<
m_tmp << std::endl;
167 throw std::runtime_error ("failed to copy file to XRD");
168 }
169 }
170 }
173 }
#define RCU_REQUIRE2_SOFT(x, y)
#define RCU_THROW_MSG(message)
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
std::string quote(const std::string &name)
effects: quote the given name to protect it from the shell returns: the quoted name guarantee: strong...
@ u
Enums for curvilinear frames.
◆ 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 {
58
62 }
virtual TFile * getFile()=0
the file we are writing to
◆ getFile()
| TFile * SH::DiskWriterXRD::getFile |
( |
| ) |
|
|
overrideprivatevirtual |
◆ getPath()
| std::string SH::DiskWriterXRD::getPath |
( |
| ) |
const |
|
overrideprivatevirtual |
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 104 of file DiskWriterXRD.cxx.
106 {
109 }
#define RCU_READ_INVARIANT(x)
◆ 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 {
50 }
virtual std::string getPath() const =0
the path where this file can be accessed or the empty string if it is not known (yet).
◆ testInvariant()
| void SH::DiskWriterXRD::testInvariant |
( |
| ) |
const |
test the invariant of this object
- Guarantee
- no-fail
Definition at line 35 of file DiskWriterXRD.cxx.
◆ m_file
| std::unique_ptr<TFile> SH::DiskWriterXRD::m_file |
|
private |
◆ m_path
| std::string SH::DiskWriterXRD::m_path |
|
private |
◆ m_tmp
| std::string SH::DiskWriterXRD::m_tmp |
|
private |
The documentation for this class was generated from the following files: