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
b675037f
Commit
b675037f
authored
1 year ago
by
Giovanna Lazzari Miotto
Browse files
Options
Downloads
Patches
Plain Diff
Refactor string formatters, move member string to function scope
parent
5e285a7e
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
-14
12 additions, 14 deletions
src/OutputFileHandler.cc
src/OutputFileHandler.h
+23
-4
23 additions, 4 deletions
src/OutputFileHandler.h
with
35 additions
and
18 deletions
src/OutputFileHandler.cc
+
12
−
14
View file @
b675037f
...
@@ -111,11 +111,12 @@ void OutputFileHandler::create_output_directory_maybe(std::string& output_direct
...
@@ -111,11 +111,12 @@ void OutputFileHandler::create_output_directory_maybe(std::string& output_direct
}
}
void
OutputFileHandler
::
open_new_file
()
{
void
OutputFileHandler
::
open_new_file
()
{
std
::
string
working_files_base_path
=
run_dir_
+
"/"
+
working_dir_
;
// Create a new file
// Create a new file
uint32_t
ls
=
1
+
static_cast
<
uint32_t
>
(
current_index_
/
(
max_index_per_ls_
+
1
));
uint32_t
ls
=
1
+
static_cast
<
uint32_t
>
(
current_index_
/
(
max_index_per_ls_
+
1
));
create_output_directory_maybe
(
working_files_base_path
_
);
create_output_directory_maybe
(
working_files_base_path
);
std
::
string
filename
=
format_filename
(
current_run_number_
,
current_index_
,
ls
);
std
::
string
filename
=
format_filename
(
current_run_number_
,
current_index_
,
ls
);
std
::
string
full_filename
=
working_files_base_path
_
+
"/"
+
filename
;
std
::
string
full_filename
=
working_files_base_path
+
"/"
+
filename
;
LOG
(
FATAL
)
<<
"opening file with index "
<<
current_index_
<<
", in lumisection "
<<
ls
;
LOG
(
FATAL
)
<<
"opening file with index "
<<
current_index_
<<
", in lumisection "
<<
ls
;
outputFile_
=
outputFile_
=
...
@@ -132,9 +133,8 @@ std::string OutputFileHandler::format_filename(uint32_t run_number, uint32_t ind
...
@@ -132,9 +133,8 @@ std::string OutputFileHandler::format_filename(uint32_t run_number, uint32_t ind
std
::
ostringstream
ofilename
;
std
::
ostringstream
ofilename
;
if
(
this
->
OutputFileHandler
::
getCMSSWHeaders
())
{
if
(
this
->
OutputFileHandler
::
getCMSSWHeaders
())
{
ofilename
<<
"run"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
run_number
<<
"_ls"
ofilename
<<
GetRunFormatted
(
run_number
)
<<
"_"
<<
GetLumiFormatted
(
ls
)
<<
"_"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
4
)
<<
ls
<<
"_index"
<<
std
::
setfill
(
'0'
)
<<
GetFileIndexFormatted
(
index
%
(
max_index_per_ls_
+
1
))
<<
filename_suffix_
;
<<
std
::
setw
(
6
)
<<
index
%
(
max_index_per_ls_
+
1
)
<<
filename_suffix_
;
}
else
{
}
else
{
ofilename
<<
filename_prefix_
<<
"_"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
run_number
<<
"_"
ofilename
<<
filename_prefix_
<<
"_"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
run_number
<<
"_"
...
@@ -174,8 +174,8 @@ void OutputFileHandler::close_and_rename::operator()() const {
...
@@ -174,8 +174,8 @@ void OutputFileHandler::close_and_rename::operator()() const {
void
OutputFileHandler
::
write_EoLS_file
(
uint32_t
ls
)
{
void
OutputFileHandler
::
write_EoLS_file
(
uint32_t
ls
)
{
std
::
stringstream
EoLS_filename_stringstream
;
std
::
stringstream
EoLS_filename_stringstream
;
EoLS_filename_stringstream
<<
"run"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
current_run_number_
EoLS_filename_stringstream
<<
GetRunFormatted
(
current_run_number_
)
<<
"_"
<<
GetLumiFormatted
(
ls
)
<<
"_ls"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
4
)
<<
ls
<<
"_EoLS.jsn"
;
<<
"_EoLS.jsn"
;
std
::
string
EoLS_filename
=
EoLS_filename_stringstream
.
str
();
std
::
string
EoLS_filename
=
EoLS_filename_stringstream
.
str
();
std
::
string
full_filename
=
run_dir_
+
"/"
+
EoLS_filename
;
std
::
string
full_filename
=
run_dir_
+
"/"
+
EoLS_filename
;
std
::
stringstream
EoLS_file_string_stream
;
std
::
stringstream
EoLS_file_string_stream
;
...
@@ -189,8 +189,8 @@ void OutputFileHandler::write_EoLS_file(uint32_t ls) {
...
@@ -189,8 +189,8 @@ void OutputFileHandler::write_EoLS_file(uint32_t ls) {
<<
constants
::
N_orbits_per_lumisection
<<
"
\"
,"
// Total Events
<<
constants
::
N_orbits_per_lumisection
<<
"
\"
,"
// Total Events
<<
"
\"
0
\"
,
\"
"
// NLost Events
<<
"
\"
0
\"
,
\"
"
// NLost Events
<<
ls_file_size_
<<
"
\"
],
\n
\"
definition
\"
:
\"
"
// NBytes
<<
ls_file_size_
<<
"
\"
],
\n
\"
definition
\"
:
\"
"
// NBytes
<<
"/fff/ramdisk/
run
"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
"/fff/ramdisk/"
<<
GetRunFormatted
(
current_run_number_
)
<<
current_run_number_
<<
"/jsd/EoLS.jsd
\"
,
\n
\"
source
\"
:
\"
l1scout
\"\n
}"
;
<<
"/jsd/EoLS.jsd
\"
,
\n
\"
source
\"
:
\"
l1scout
\"\n
}"
;
ls_file_size_
=
0
;
ls_file_size_
=
0
;
run_NOrbits_
+=
ls_NOrbits_
;
run_NOrbits_
+=
ls_NOrbits_
;
...
@@ -203,9 +203,7 @@ void OutputFileHandler::write_EoR_file() {
...
@@ -203,9 +203,7 @@ void OutputFileHandler::write_EoR_file() {
assert
(
current_index_
>
0
&&
nOrbitsPerFile_
>
0
);
assert
(
current_index_
>
0
&&
nOrbitsPerFile_
>
0
);
int
ls
=
int
(
1
)
+
(
current_index_
*
nOrbitsPerFile_
)
/
constants
::
N_orbits_per_lumisection
;
int
ls
=
int
(
1
)
+
(
current_index_
*
nOrbitsPerFile_
)
/
constants
::
N_orbits_per_lumisection
;
std
::
stringstream
EoR_filename
;
std
::
stringstream
EoR_filename
;
EoR_filename
<<
run_dir_
<<
"/"
EoR_filename
<<
run_dir_
<<
"/"
<<
GetRunFormatted
(
current_run_number_
)
<<
"_ls0000_EoR.jsn"
;
<<
"run"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
current_run_number_
<<
"_ls0000_EoR.jsn"
;
LOG
(
TRACE
)
<<
"Writing EoR file "
<<
EoR_filename
.
str
();
LOG
(
TRACE
)
<<
"Writing EoR file "
<<
EoR_filename
.
str
();
std
::
fstream
EoR_file
;
std
::
fstream
EoR_file
;
EoR_file
.
open
(
EoR_filename
.
str
().
c_str
(),
std
::
ios_base
::
out
);
EoR_file
.
open
(
EoR_filename
.
str
().
c_str
(),
std
::
ios_base
::
out
);
...
@@ -216,8 +214,8 @@ void OutputFileHandler::write_EoR_file() {
...
@@ -216,8 +214,8 @@ void OutputFileHandler::write_EoR_file() {
(
nOrbitsPerFile_
*
current_index_
)
// NFiles
(
nOrbitsPerFile_
*
current_index_
)
// NFiles
<<
"
\"
,
\"
"
<<
ls
<<
"
\"
,
\"
"
// NLumis
<<
"
\"
,
\"
"
<<
ls
<<
"
\"
,
\"
"
// NLumis
<<
ls
<<
"
\"
],
\n
\"
definition
\"
:
\"
"
// LastLumi
<<
ls
<<
"
\"
],
\n
\"
definition
\"
:
\"
"
// LastLumi
<<
"/fff/ramdisk/
run
"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
"/fff/ramdisk/"
<<
GetRunFormatted
(
current_run_number_
)
<<
current_run_number_
<<
"/jsd/EoR.jsd
\"
,
\n
\"
source
\"
:
\"
l1scout
\"\n
}"
;
<<
"/jsd/EoR.jsd
\"
,
\n
\"
source
\"
:
\"
l1scout
\"\n
}"
;
EoR_file
<<
EoR_file_string_stream
.
str
();
EoR_file
<<
EoR_file_string_stream
.
str
();
EoR_file
.
close
();
EoR_file
.
close
();
}
}
This diff is collapsed.
Click to expand it.
src/OutputFileHandler.h
+
23
−
4
View file @
b675037f
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include
<atomic>
#include
<atomic>
#include
<cstdint>
#include
<cstdint>
#include
<cstdio>
#include
<cstdio>
#include
<iostream>
#include
<memory>
#include
<memory>
#include
<string>
#include
<string>
#include
<thread>
#include
<thread>
...
@@ -15,15 +16,33 @@
...
@@ -15,15 +16,33 @@
#include
"cmssw/FRDFileHeader_v2.h"
#include
"cmssw/FRDFileHeader_v2.h"
#include
"format.h"
#include
"format.h"
// Refactoring common strings out
inline
std
::
string
GetRunFormatted
(
uint64_t
run_number
)
{
std
::
ostringstream
ss
;
ss
<<
"run"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
run_number
;
return
ss
.
str
();
}
inline
std
::
string
GetFileIndexFormatted
(
uint64_t
file_index
)
{
std
::
ostringstream
ss
;
ss
<<
"index"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
6
)
<<
file_index
;
return
ss
.
str
();
}
inline
std
::
string
GetLumiFormatted
(
uint32_t
ls
)
{
std
::
ostringstream
ss
;
ss
<<
"ls"
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
4
)
<<
ls
;
return
ss
.
str
();
}
class
OutputFileHandler
{
class
OutputFileHandler
{
public:
public:
OutputFileHandler
(
std
::
string
base_path
,
std
::
string
filename_prefix
,
std
::
string
filename_suffix
,
OutputFileHandler
(
std
::
string
base_path
,
std
::
string
filename_prefix
,
std
::
string
filename_suffix
,
int
num_orbits_per_file
,
const
bool
has_cmssw_headers
,
int
source_id
)
int
num_orbits_per_file
,
const
bool
has_cmssw_headers
,
int
source_id
)
:
base_path_
(
std
::
move
(
base_path
)
)
,
:
base_path_
(
base_path
),
run_dir_
(
base_path
_
+
"/
run000000"
),
run_dir_
(
base_path
+
"/
"
+
GetRunFormatted
(
0
)
),
filename_prefix_
(
std
::
move
(
filename_prefix
)
)
,
filename_prefix_
(
filename_prefix
),
filename_suffix_
(
std
::
move
(
filename_suffix
)),
filename_suffix_
(
std
::
move
(
filename_suffix
)),
working_files_base_path_
(
base_path_
+
"/"
+
working_dir_
),
current_run_number_
(
-
1
),
current_run_number_
(
-
1
),
current_index_
(
-
1
),
current_index_
(
-
1
),
close_and_rename_
(
base_path_
,
num_orbits_per_file
),
close_and_rename_
(
base_path_
,
num_orbits_per_file
),
...
...
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