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
e0ea3fe1
Commit
e0ea3fe1
authored
2 years ago
by
Emilio Meschi
Committed by
Thomas Owen James
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
various fixes in the file handler thread
parent
be8af746
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/OutputFileHandler.cc
+16
-4
16 additions, 4 deletions
src/OutputFileHandler.cc
with
16 additions
and
4 deletions
src/OutputFileHandler.cc
+
16
−
4
View file @
e0ea3fe1
#include
"OutputFileHandler.h"
#include
"OutputFileHandler.h"
#include
<iomanip>
#include
<iomanip>
...
@@ -10,11 +11,17 @@ const std::string OutputFileHandler::journal_file_ = "index.journal";
...
@@ -10,11 +11,17 @@ const std::string OutputFileHandler::journal_file_ = "index.journal";
tbb
::
concurrent_bounded_queue
<
std
::
pair
<
std
::
string
,
FILE
*>>
OutputFileHandler
::
files_to_close_
=
tbb
::
concurrent_bounded_queue
<
std
::
pair
<
std
::
string
,
FILE
*>>
OutputFileHandler
::
files_to_close_
=
tbb
::
concurrent_bounded_queue
<
std
::
pair
<
std
::
string
,
FILE
*>>
();
tbb
::
concurrent_bounded_queue
<
std
::
pair
<
std
::
string
,
FILE
*>>
();
bool
OutputFileHandler
::
file_handler_running_
=
fals
e
;
bool
OutputFileHandler
::
file_handler_running_
=
tru
e
;
void
OutputFileHandler
::
enqueue_current_file_for_close_and_move_maybe
()
{
void
OutputFileHandler
::
enqueue_current_file_for_close_and_move_maybe
()
{
if
(
current_file_
!=
0
)
if
(
current_file_
!=
0
)
{
LOG
(
TRACE
)
<<
"queueing file: "
<<
current_filename_
<<
" for closing, queue size now "
<<
files_to_close_
.
size
();
files_to_close_
.
push
(
std
::
pair
<
std
::
string
,
FILE
*>
(
current_filename_
,
current_file_
));
files_to_close_
.
push
(
std
::
pair
<
std
::
string
,
FILE
*>
(
current_filename_
,
current_file_
));
current_file_
=
0
;
current_filename_
=
std
::
string
();
LOG
(
TRACE
)
<<
"queued "
<<
current_filename_
<<
" queue size now "
<<
files_to_close_
.
size
();
}
}
}
FILE
*
OutputFileHandler
::
getFile
(
uint32_t
run
,
uint32_t
index
)
{
FILE
*
OutputFileHandler
::
getFile
(
uint32_t
run
,
uint32_t
index
)
{
...
@@ -29,7 +36,7 @@ FILE *OutputFileHandler::getFile(uint32_t run, uint32_t index) {
...
@@ -29,7 +36,7 @@ FILE *OutputFileHandler::getFile(uint32_t run, uint32_t index) {
void
OutputFileHandler
::
create_output_directory_maybe
(
std
::
string
&
output_directory
)
{
void
OutputFileHandler
::
create_output_directory_maybe
(
std
::
string
&
output_directory
)
{
struct
stat
sb
;
struct
stat
sb
;
LOG
(
TRACE
)
<<
"checking if working directory "
<<
output_directory
<<
" exists "
;
/* check if path exists and is a directory */
/* check if path exists and is a directory */
if
(
stat
(
output_directory
.
c_str
(),
&
sb
)
==
0
)
{
if
(
stat
(
output_directory
.
c_str
(),
&
sb
)
==
0
)
{
if
(
S_ISDIR
(
sb
.
st_mode
))
{
// output directory already exists
if
(
S_ISDIR
(
sb
.
st_mode
))
{
// output directory already exists
...
@@ -69,7 +76,7 @@ void OutputFileHandler::open_new_file() {
...
@@ -69,7 +76,7 @@ void OutputFileHandler::open_new_file() {
std
::
string
OutputFileHandler
::
format_filename
(
uint32_t
run_number
,
uint32_t
index
)
{
std
::
string
OutputFileHandler
::
format_filename
(
uint32_t
run_number
,
uint32_t
index
)
{
std
::
ostringstream
ofilename
;
std
::
ostringstream
ofilename
;
ofilename
<<
filename_prefix_
<<
"_"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
run_number
<<
"_"
ofilename
<<
filename_prefix_
<<
"_"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
run_number
<<
"_"
<<
index
<<
".dat"
;
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
index
<<
".dat"
;
return
ofilename
.
str
();
return
ofilename
.
str
();
}
}
...
@@ -78,7 +85,10 @@ void OutputFileHandler::close_and_rename::operator()() const {
...
@@ -78,7 +85,10 @@ void OutputFileHandler::close_and_rename::operator()() const {
while
(
file_handler_running_
||
(
files_to_close_
.
size
()
>
0
))
{
while
(
file_handler_running_
||
(
files_to_close_
.
size
()
>
0
))
{
// std::cout << std::this_thread::get_id() << " try pop" <<
// std::cout << std::this_thread::get_id() << " try pop" <<
// files_to_close_.size() << std::endl;
// files_to_close_.size() << std::endl;
LOG
(
TRACE
)
<<
"try pop now. queue size now "
<<
files_to_close_
.
size
();
files_to_close_
.
pop
(
n
);
files_to_close_
.
pop
(
n
);
LOG
(
TRACE
)
<<
"popping file: "
<<
n
.
first
<<
" for closing, queue size now "
<<
files_to_close_
.
size
();
if
(
fclose
(
n
.
second
)
!=
0
)
{
if
(
fclose
(
n
.
second
)
!=
0
)
{
LOG
(
ERROR
)
<<
tools
::
strerror
(
"File close failed"
);
LOG
(
ERROR
)
<<
tools
::
strerror
(
"File close failed"
);
}
}
...
@@ -90,4 +100,6 @@ void OutputFileHandler::close_and_rename::operator()() const {
...
@@ -90,4 +100,6 @@ void OutputFileHandler::close_and_rename::operator()() const {
// std::cout << std::this_thread::get_id() << " popped " << n.first << "
// std::cout << std::this_thread::get_id() << " popped " << n.first << "
// size now " << files_to_close_.size() << std::endl;
// size now " << files_to_close_.size() << std::endl;
}
}
LOG
(
TRACE
)
<<
"exiting close_and_rename. file_handler_running_ now "
<<
file_handler_running_
<<
" queue size now "
<<
files_to_close_
.
size
();
}
}
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