Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
FileIO Class Reference

#include <ored/utilities/fileio.hpp>

+ Collaboration diagram for FileIO:

Public Member Functions

 FileIO ()=delete
 

Static Public Member Functions

static QuantLib::Size maxRetries ()
 The maximum number of retries, defaults to 7. More...
 
static QuantLib::Real backoff ()
 
static QuantLib::Real maxBackoff ()
 
static void setMaxRetries (QuantLib::Size)
 
static void setBackoff (QuantLib::Real)
 
static void setMaxBackoff (QuantLib::Real)
 
static FILE * fopen (const char *, const char *)
 Retry wrapper for std::fopen. More...
 
static bool create_directories (const path &)
 Retry wrapper for boost::filesystem::create_directories. More...
 
static bool remove_all (const path &)
 Retry wrapper for boost::filesystem::remove_all. More...
 

Detailed Description

Definition at line 35 of file fileio.hpp.

Constructor & Destructor Documentation

◆ FileIO()

FileIO ( )
delete

Member Function Documentation

◆ maxRetries()

Size maxRetries ( )
static

The maximum number of retries, defaults to 7.

Definition at line 43 of file fileio.cpp.

43{ return _s_maxRetries; }
+ Here is the caller graph for this function:

◆ backoff()

Real backoff ( )
static

Definition at line 45 of file fileio.cpp.

45{ return _s_backoff; }
+ Here is the caller graph for this function:

◆ maxBackoff()

Real maxBackoff ( )
static

Definition at line 47 of file fileio.cpp.

47{ return _s_maxBackoff; }
+ Here is the caller graph for this function:

◆ setMaxRetries()

void setMaxRetries ( QuantLib::Size  )
static

Definition at line 49 of file fileio.cpp.

49 {
50 LOG("Setting FileOpen max retries to " << n);
51 _s_maxRetries = n;
52}
#define LOG(text)
Logging Macro (Level = Notice)
Definition: log.hpp:552

◆ setBackoff()

void setBackoff ( QuantLib::Real  )
static

Definition at line 54 of file fileio.cpp.

54 {
55 LOG("Setting FileOpen backoff to " << b);
56 _s_backoff = b;
57}

◆ setMaxBackoff()

void setMaxBackoff ( QuantLib::Real  )
static

Definition at line 59 of file fileio.cpp.

59 {
60 LOG("Setting FileOpen max backoff to " << m);
61 _s_maxBackoff = m;
62}

◆ fopen()

FILE * fopen ( const char *  filename,
const char *  mode 
)
static

Retry wrapper for std::fopen.

Definition at line 64 of file fileio.cpp.

64 {
65 FILE* fp;
66 Real currentBackoff = backoff();
67
68 for (Size i = 0; i <= maxRetries(); i++) {
69 if (i > 0) {
70 auto em = EventMessage("Error opening file '" + std::string(filename) + "'. Retrying...", "exception_message");
71 em.set("retry_count", i);
72 Real backoffMillis = currentBackoff * 1000;
73 em.set("retry_interval", backoffMillis);
74 em.log();
75 std::this_thread::sleep_for(std::chrono::duration<Real>(currentBackoff));
76 Real nextBackoff = currentBackoff * 2;
77 currentBackoff = (nextBackoff >= maxBackoff()) ? maxBackoff() : nextBackoff;
78 }
79
80 fp = std::fopen(filename, mode);
81 if (fp)
82 break;
83 }
84
85 return fp;
86}
static QuantLib::Real backoff()
Definition: fileio.cpp:45
static QuantLib::Real maxBackoff()
Definition: fileio.cpp:47
static QuantLib::Size maxRetries()
The maximum number of retries, defaults to 7.
Definition: fileio.cpp:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create_directories()

bool create_directories ( const path &  p)
static

Retry wrapper for boost::filesystem::create_directories.

Definition at line 88 of file fileio.cpp.

88 {
89 bool res = false;
90 Real currentBackoff = backoff();
91
92 for (Size i = 0; i <= maxRetries(); i++) {
93 if (i > 0) {
94 auto em = EventMessage("Error creating directory '" + p.string() + "'. Retrying...", "exception_message");
95 em.set("retry_count", i);
96 Real backoffMillis = currentBackoff * 1000;
97 em.set("retry_interval", backoffMillis);
98 em.log();
99 std::this_thread::sleep_for(std::chrono::duration<Real>(currentBackoff));
100 Real nextBackoff = currentBackoff * 2;
101 currentBackoff = (nextBackoff >= maxBackoff()) ? maxBackoff() : nextBackoff;
102 }
103
104 try {
105 res = boost::filesystem::create_directories(p);
106 if (res)
107 break;
108 } catch (...) {
109 }
110 }
111
112 return res;
113}
+ Here is the call graph for this function:

◆ remove_all()

bool remove_all ( const path &  p)
static

Retry wrapper for boost::filesystem::remove_all.

Definition at line 115 of file fileio.cpp.

115 {
116 bool res = false;
117 Real currentBackoff = backoff();
118
119 for (Size i = 0; i <= maxRetries(); i++) {
120 if (i > 0) {
121 auto em = EventMessage("Error emptying directory '" + p.string() + "'. Retrying...", "exception_message");
122 em.set("retry_count", i);
123 Real backoffMillis = currentBackoff * 1000;
124 em.set("retry_interval", backoffMillis);
125 em.log();
126 std::this_thread::sleep_for(std::chrono::duration<Real>(currentBackoff));
127 Real nextBackoff = currentBackoff * 2;
128 currentBackoff = (nextBackoff >= maxBackoff()) ? maxBackoff() : nextBackoff;
129 }
130
131 try {
132 res = boost::filesystem::remove_all(p);
133 if (res)
134 break;
135 } catch (...) {
136 }
137 }
138
139 return res;
140}
+ Here is the call graph for this function: