Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
scdaq
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
scouting-demonstrator
scdaq
Commits
7f977dff
Commit
7f977dff
authored
2 years ago
by
Emilio Meschi
Committed by
Thomas Owen James
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
make file opening and filename calculation more robust in separate class
parent
211f8fa9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/OutputFileHandler.cc
+12
-16
12 additions, 16 deletions
src/OutputFileHandler.cc
src/OutputFileHandler.h
+11
-25
11 additions, 25 deletions
src/OutputFileHandler.h
with
23 additions
and
41 deletions
src/OutputFileHandler.cc
+
12
−
16
View file @
7f977dff
#include
"OutputFileHandler.h"
#include
"OutputFileHandler.h"
#include
<iomanip>
#include
"log.h"
#include
"log.h"
void
OutputFileHandler
::
create_output_directory_maybe
(
std
::
string
&
output_directory
)
{
void
OutputFileHandler
::
create_output_directory_maybe
(
std
::
string
&
output_directory
)
{
...
@@ -28,30 +30,24 @@ void OutputFileHandler::create_output_directory_maybe(std::string &output_direct
...
@@ -28,30 +30,24 @@ void OutputFileHandler::create_output_directory_maybe(std::string &output_direct
void
OutputFileHandler
::
open_file
(
uint32_t
index
,
uint32_t
run
)
{
void
OutputFileHandler
::
open_file
(
uint32_t
index
,
uint32_t
run
)
{
// Create a new file
// Create a new file
create_output_directory_maybe
(
working_files_basepath_
);
create_output_directory_maybe
(
working_files_basepath_
);
std
::
string
current_filename_a
=
output_directory
+
"/"
+
format_run_file_stem
(
my_output_filename_prefix
,
current_run_number
,
index_
);
std
::
string
filename
=
std
::
string
filename
=
output_directory
+
"/"
+
working_files_base_path_
+
"/"
+
format_filename
(
control
.
run_number
,
index
);
format_run_file_stem
(
my_output_filename_prefix
,
control
.
run_number
,
index_
);
LOG
(
TRACE
)
<<
"opening file with index "
<<
index
;
LOG
(
INFO
)
<<
"opening file with index "
<<
index_
;
current_file_
=
fopen
(
filename
.
c_str
(),
"wbx"
));
outFile
.
setFile
(
fopen
(
filename
.
c_str
(),
"w"
));
if
(
current_file_
==
NULL
)
{
outFile
.
setIndex
(
index_
);
if
(
outFile
.
getFile
()
==
NULL
)
{
std
::
string
err
=
tools
::
strerror
(
"ERROR when creating file '"
+
current_filename_a
+
"'"
);
std
::
string
err
=
tools
::
strerror
(
"ERROR when creating file '"
+
current_filename_a
+
"'"
);
LOG
(
ERROR
)
<<
err
;
LOG
(
ERROR
)
<<
err
;
throw
std
::
runtime_error
(
err
);
throw
std
::
runtime_error
(
err
);
}
}
current_index_
=
index
;
}
}
/*
/*
* Create a properly formatted file name
* Create a properly formatted file name
* TODO: Change to C++
*/
*/
std
::
string
OutputFileHandler
::
format_filename
(
std
::
string
&
path
,
uint32_t
run_number
,
std
::
string
OutputFileHandler
::
format_filename
(
uint32_t
run_number
,
uint32_t
index
)
{
uint32_t
index
)
{
std
::
ostringstream
ofilename
;
char
run_order_stem
[
PATH_MAX
];
ofilename
<<
filename_prefix_
<<
"_"
<<
std
::
setfill
(
0
)
<<
std
::
setw
(
6
)
<<
run_number
<<
"_"
snprintf
(
run_order_stem
,
sizeof
(
run_order_stem
),
"%s_%06d_%06d.dat"
,
filename_prefix
.
c_str
(),
<<
index
<<
".dat"
;
run_number
,
file_count
);
return
ofilename
.
str
();
return
std
::
string
(
run_order_stem
);
}
}
This diff is collapsed.
Click to expand it.
src/OutputFileHandler.h
+
11
−
25
View file @
7f977dff
...
@@ -7,35 +7,21 @@
...
@@ -7,35 +7,21 @@
class
OutputFileHandler
{
class
OutputFileHandler
{
public:
public:
OutputFileHandler
(
const
std
::
string
filename_
base_path
,
const
std
::
string
filename_prefix
)
OutputFileHandler
(
const
std
::
string
base_path
,
const
std
::
string
filename_prefix
)
:
filename_
base_path_
(
filename_
base_path
),
:
base_path_
(
base_path
),
filename_prefix_
(
filename_prefix
),
filename_prefix_
(
filename_prefix
),
working_files_basepath_
(
filename_base_path_
+
"/"
+
working_dir_
)
{
working_files_base_path_
(
filename_base_path_
+
"/"
+
working_dir_
),
create_output_directory_maybe
(
working_files_basepath_
);
current_run_number_
(
0
),
current_file_
(
0
),
current_index_
(
-
1
)
{
create_output_directory_maybe
(
working_files_base_path_
);
}
}
virtual
~
OutputFileHandler
()
{}
virtual
~
OutputFileHandler
()
{}
void
open_file
(
uint32_t
index
,
void
open_file
(
uint32_t
index
,
uint32_t
run
);
// Used for fixedNorbits per file option
uint32_t
run
);
// Used for fixedNorbits per file option
{
// Create a new file
std
::
string
format_filename
(
uint32_t
run_number
,
uint32_t
index
);
std
::
string
output_directory
=
my_output_filename_base
+
"/"
+
working_dir
;
create_output_directory
(
output_directory
);
std
::
string
current_filename_a
=
output_directory
+
"/"
+
format_run_file_stem
(
my_output_filename_prefix
,
current_run_number
,
index_
);
std
::
string
filename
=
output_directory
+
"/"
+
format_run_file_stem
(
my_output_filename_prefix
,
control
.
run_number
,
index_
);
LOG
(
INFO
)
<<
"opening file with index "
<<
index_
;
outFile
.
setFile
(
fopen
(
filename
.
c_str
(),
"w"
));
outFile
.
setIndex
(
index_
);
if
(
outFile
.
getFile
()
==
NULL
)
{
std
::
string
err
=
tools
::
strerror
(
"ERROR when creating file '"
+
current_filename_a
+
"'"
);
LOG
(
ERROR
)
<<
err
;
throw
std
::
runtime_error
(
err
);
}
}
private
:
private
:
void
create_output_directory_maybe
(
std
::
string
&
output_directory
);
void
create_output_directory_maybe
(
std
::
string
&
output_directory
);
...
@@ -47,9 +33,9 @@ class OutputFileHandler {
...
@@ -47,9 +33,9 @@ class OutputFileHandler {
// filename
// filename
static
constexpr
std
::
string
journal_file_
{
"index.journal"
};
static
constexpr
std
::
string
journal_file_
{
"index.journal"
};
std
::
string
filename_
base_path_
;
std
::
string
base_path_
;
std
::
string
filename_prefix_
;
std
::
string
filename_prefix_
;
std
::
string
working_files_basepath_
;
std
::
string
working_files_base
_
path_
;
uint32_t
current_run_number_
;
uint32_t
current_run_number_
;
FILE
*
current_file_
;
FILE
*
current_file_
;
int32_t
current_index_
;
int32_t
current_index_
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment