Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Lst
lst-data-process-128
Commits
18f53656
Commit
18f53656
authored
Dec 16, 2020
by
legoc
Browse files
Modified Cameo apps to us JSON data
parent
0ec202f7
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/lstdpp128/apps/cameo/CameoLiveCoincidence.cpp
View file @
18f53656
...
...
@@ -152,17 +152,17 @@ int main(int argc, char * argv[]) {
time_t
t1
=
time
(
0
);
time_t
last
=
time
(
0
);
//
string data;
//
while (subscriber->receiveBinary(data)) {
string
data
;
while
(
subscriber
->
receiveBinary
(
data
))
{
while
(
true
)
{
std
::
optional
<
string
>
data
=
subscriber
->
receiveBinary
();
if
(
!
data
.
has_value
())
{
break
;
}
//
while (true) {
//
std::optional<string> data = subscriber->receiveBinary();
//
if (!data.has_value()) {
//
break;
//
}
int32_t
blockSize
=
data
.
value
().
size
()
/
sizeof
(
int32_t
);
int32_t
*
block
=
const_cast
<
int32_t
*>
(
reinterpret_cast
<
const
int32_t
*>
(
data
.
value
().
c_str
()));
int32_t
blockSize
=
data
.
size
()
/
sizeof
(
int32_t
);
int32_t
*
block
=
const_cast
<
int32_t
*>
(
reinterpret_cast
<
const
int32_t
*>
(
data
.
c_str
()));
// processing block
algorithm
.
process
(
block
,
blockSize
,
blocks
);
...
...
@@ -172,16 +172,16 @@ int main(int argc, char * argv[]) {
cout
<<
"#events read "
<<
algorithm
.
processor
().
numberOfGoodEvents
()
<<
endl
;
// publish results
//
publisher->send(algorithm.processor().getChannelRates(), algorithm.processor().getTotalNumberOfChannels());
//
publisher->send(algorithm.processor().getCoincidenceRates(), algorithm.processor().getNumberOfCoincidenceRates());
publisher
->
send
(
toJSONArray
(
algorithm
.
processor
().
getChannelRates
(),
algorithm
.
processor
().
getTotalNumberOfChannels
())
)
;
publisher
->
send
(
toJSONArray
(
algorithm
.
processor
().
getCoincidenceRates
(),
algorithm
.
processor
().
getNumberOfCoincidenceRates
())
)
;
last
=
current
;
}
}
// publish results at the end
//
publisher->send(algorithm.processor().getChannelRates(), algorithm.processor().getTotalNumberOfChannels());
//
publisher->send(algorithm.processor().getCoincidenceRates(), algorithm.processor().getNumberOfCoincidenceRates());
publisher
->
send
(
toJSONArray
(
algorithm
.
processor
().
getChannelRates
(),
algorithm
.
processor
().
getTotalNumberOfChannels
())
)
;
publisher
->
send
(
toJSONArray
(
algorithm
.
processor
().
getCoincidenceRates
(),
algorithm
.
processor
().
getNumberOfCoincidenceRates
())
)
;
time_t
t2
=
time
(
0
);
...
...
src/lstdpp128/apps/cameo/CameoLiveHistogram.cpp
View file @
18f53656
...
...
@@ -135,17 +135,17 @@ int main(int argc, char * argv[]) {
time_t
t1
=
time
(
0
);
time_t
last
=
time
(
0
);
//
string data;
//
while (subscriber->receiveBinary(data)) {
string
data
;
while
(
subscriber
->
receiveBinary
(
data
))
{
while
(
true
)
{
std
::
optional
<
string
>
data
=
subscriber
->
receiveBinary
();
if
(
!
data
.
has_value
())
{
break
;
}
//
while (true) {
//
std::optional<string> data = subscriber->receiveBinary();
//
if (!data.has_value()) {
//
break;
//
}
int32_t
blockSize
=
data
.
value
().
size
()
/
sizeof
(
int32_t
);
int32_t
*
block
=
const_cast
<
int32_t
*>
(
reinterpret_cast
<
const
int32_t
*>
(
data
.
value
().
c_str
()));
int32_t
blockSize
=
data
.
size
()
/
sizeof
(
int32_t
);
int32_t
*
block
=
const_cast
<
int32_t
*>
(
reinterpret_cast
<
const
int32_t
*>
(
data
.
c_str
()));
// processing block
algorithm
.
process
(
block
,
blockSize
,
blocks
);
...
...
@@ -155,16 +155,16 @@ int main(int argc, char * argv[]) {
cout
<<
"#events read "
<<
algorithm
.
processor
().
numberOfGoodEvents
()
<<
endl
;
// publish results
//
publisher->send(algorithm.processor().getChannelRates(), algorithm.processor().getTotalNumberOfChannels());
//
publisher->send(algorithm.processor().getHistograms(), algorithm.processor().getTotalHistogramSize());
publisher
->
send
(
toJSONArray
(
algorithm
.
processor
().
getChannelRates
(),
algorithm
.
processor
().
getTotalNumberOfChannels
())
)
;
publisher
->
send
(
toJSONArray
(
algorithm
.
processor
().
getHistograms
(),
algorithm
.
processor
().
getTotalHistogramSize
())
)
;
last
=
current
;
}
}
// publish results at the end
//
publisher->send(algorithm.processor().getChannelRates(), algorithm.processor().getTotalNumberOfChannels());
//
publisher->send(algorithm.processor().getHistograms(), algorithm.processor().getTotalHistogramSize());
publisher
->
send
(
toJSONArray
(
algorithm
.
processor
().
getChannelRates
(),
algorithm
.
processor
().
getTotalNumberOfChannels
())
)
;
publisher
->
send
(
toJSONArray
(
algorithm
.
processor
().
getHistograms
(),
algorithm
.
processor
().
getTotalHistogramSize
())
)
;
time_t
t2
=
time
(
0
);
...
...
src/lstdpp128/apps/cameo/Utils.cpp
View file @
18f53656
...
...
@@ -67,4 +67,36 @@ void readListModeContextFromPropertyTree(ListModeContext & listModeContext, cons
}
}
std
::
string
toJSONArray
(
double
*
data
,
int
size
)
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartArray
();
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
writer
.
Double
(
data
[
i
]);
}
writer
.
EndArray
();
return
buffer
.
GetString
();
}
std
::
string
toJSONArray
(
int32_t
*
data
,
int
size
)
{
rapidjson
::
StringBuffer
buffer
;
rapidjson
::
Writer
<
rapidjson
::
StringBuffer
>
writer
(
buffer
);
writer
.
StartArray
();
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
writer
.
Int
(
data
[
i
]);
}
writer
.
EndArray
();
return
buffer
.
GetString
();
}
}
src/lstdpp128/apps/cameo/Utils.h
View file @
18f53656
...
...
@@ -22,6 +22,12 @@
#include
"../../CrateBoard.h"
#include
<boost/property_tree/ptree.hpp>
#include
<rapidjson/rapidjson.h>
#include
<rapidjson/writer.h>
#include
<rapidjson/stringbuffer.h>
#include
<rapidjson/reader.h>
#include
<rapidjson/document.h>
namespace
lstdpp128
{
/**
...
...
@@ -29,6 +35,16 @@ namespace lstdpp128 {
*/
void
readListModeContextFromPropertyTree
(
ListModeContext
&
listModeContext
,
const
boost
::
property_tree
::
ptree
&
data
);
/**
* Converts a double array into a JSON array.
*/
std
::
string
toJSONArray
(
double
*
data
,
int
size
);
/**
* Converts an integer array into a JSON array.
*/
std
::
string
toJSONArray
(
int32_t
*
data
,
int
size
);
}
#endif
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment