Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
psrdada_cpp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
MPIfR-BDG
psrdada_cpp
Commits
46506465
Commit
46506465
authored
2 years ago
by
Niclas Esser
Browse files
Options
Downloads
Plain Diff
Merge branch 'devel' into 'devel'
diskdb See merge request
!20
parents
e340bb11
ae965fea
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!20
diskdb
Pipeline
#137008
passed
2 years ago
Stage: build
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
psrdada_cpp/CMakeLists.txt
+5
-1
5 additions, 1 deletion
psrdada_cpp/CMakeLists.txt
psrdada_cpp/examples/diskdb.cpp
+121
-0
121 additions, 0 deletions
psrdada_cpp/examples/diskdb.cpp
with
126 additions
and
1 deletion
psrdada_cpp/CMakeLists.txt
+
5
−
1
View file @
46506465
...
...
@@ -78,7 +78,11 @@ target_link_libraries (dbreset ${PSRDADA_CPP_LIBRARIES})
#add_executable(dbdisk examples/dbdisk.cpp)
#target_link_libraries (dbdisk ${PSRDADA_CPP_LIBRARIES})
install
(
TARGETS junkdb dbnull syncdb dbreset fbfuse_output_db DESTINATION bin
)
#diskdb
add_executable
(
diskdb examples/diskdb.cpp
)
target_link_libraries
(
diskdb
${
PSRDADA_CPP_LIBRARIES
}
)
install
(
TARGETS junkdb dbnull syncdb dbreset fbfuse_output_db diskdb DESTINATION bin
)
install
(
TARGETS
${
CMAKE_PROJECT_NAME
}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
...
...
This diff is collapsed.
Click to expand it.
psrdada_cpp/examples/diskdb.cpp
0 → 100644
+
121
−
0
View file @
46506465
#include
"psrdada_cpp/multilog.hpp"
#include
"psrdada_cpp/raw_bytes.hpp"
#include
"psrdada_cpp/dada_output_stream.hpp"
#include
"psrdada_cpp/cli_utils.hpp"
#include
"boost/program_options.hpp"
#include
<sys/types.h>
#include
<iostream>
#include
<string>
#include
<ios>
#include
<vector>
#include
<fstream>
using
namespace
psrdada_cpp
;
namespace
{
const
size_t
ERROR_IN_COMMAND_LINE
=
1
;
const
size_t
SUCCESS
=
0
;
const
size_t
ERROR_UNHANDLED_EXCEPTION
=
2
;
}
// namespace
namespace
psrdada_cpp
{
template
<
class
Handler
>
void
diskdb
(
Handler
&
handler
,
std
::
size_t
header_size
,
std
::
size_t
block_size
,
std
::
size_t
nfile_read
,
std
::
string
header_file
,
std
::
string
data_file
)
{
std
::
vector
<
char
>
header
(
header_size
);
std
::
vector
<
char
>
data
(
block_size
);
std
::
ifstream
hinput
;
std
::
ifstream
dinput
;
hinput
.
open
(
header_file
,
std
::
ios
::
in
|
std
::
ios
::
binary
);
hinput
.
read
(
header
.
data
(),
header_size
);
dinput
.
open
(
data_file
,
std
::
ios
::
in
|
std
::
ios
::
binary
);
dinput
.
read
(
data
.
data
(),
block_size
);
RawBytes
header_bytes
(
header
.
data
(),
header_size
,
header_size
,
false
);
handler
.
init
(
header_bytes
);
for
(
std
::
size_t
i
=
0
;
i
<
nfile_read
;
i
++
)
{
RawBytes
data_bytes
(
data
.
data
(),
block_size
,
block_size
,
false
);
handler
(
data_bytes
);
}
}
}
int
main
(
int
argc
,
char
**
argv
)
{
try
{
std
::
size_t
reads
;
key_t
key
;
std
::
string
header_file
;
std
::
string
data_file
;
/** Define and parse the program options
*/
namespace
po
=
boost
::
program_options
;
po
::
options_description
desc
(
"Options"
);
desc
.
add_options
()
(
"help,h"
,
"Print help messages"
)
(
"data_file,d"
,
po
::
value
<
std
::
string
>
(
&
data_file
)
->
required
(),
"File containing the data to write to dada buffer"
)
(
"header_file,f"
,
po
::
value
<
std
::
string
>
(
&
header_file
)
->
required
(),
"Header file to write header block"
)
(
"reads,r"
,
po
::
value
<
std
::
size_t
>
(
&
reads
)
->
default_value
(
1
),
"Number of file reads"
)
(
"key,k"
,
po
::
value
<
std
::
string
>
()
->
default_value
(
"dada"
)
->
notifier
([
&
key
](
std
::
string
in
){
key
=
string_to_key
(
in
);}),
"The shared memory key for the dada buffer to connect to (hex string)"
)
(
"log_level"
,
po
::
value
<
std
::
string
>
()
->
default_value
(
"info"
)
->
notifier
([](
std
::
string
level
){
set_log_level
(
level
);}),
"The logging level to use (debug, info, warning, error)"
);
po
::
variables_map
vm
;
try
{
po
::
store
(
po
::
parse_command_line
(
argc
,
argv
,
desc
),
vm
);
if
(
vm
.
count
(
"help"
)
)
{
std
::
cout
<<
"diskdb -- write file contents into DADA ring buffer"
<<
std
::
endl
<<
desc
<<
std
::
endl
;
return
SUCCESS
;
}
po
::
notify
(
vm
);
}
catch
(
po
::
error
&
e
)
{
std
::
cerr
<<
"ERROR: "
<<
e
.
what
()
<<
std
::
endl
<<
std
::
endl
;
std
::
cerr
<<
desc
<<
std
::
endl
;
return
ERROR_IN_COMMAND_LINE
;
}
/**
* All the application code goes here
*/
MultiLog
log
(
"diskdb"
);
DadaOutputStream
out_stream
(
key
,
log
);
diskdb
<
decltype
(
out_stream
)
>
(
out_stream
,
out_stream
.
client
().
header_buffer_size
(),
out_stream
.
client
().
data_buffer_size
(),
reads
,
header_file
,
data_file
);
/**
* End of application code
*/
}
catch
(
std
::
exception
&
e
)
{
std
::
cerr
<<
"Unhandled Exception reached the top of main: "
<<
e
.
what
()
<<
", application will now exit"
<<
std
::
endl
;
return
ERROR_UNHANDLED_EXCEPTION
;
}
return
SUCCESS
;
}
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