Skip to content

Commit dd0ff11

Browse files
YanzhaoWjose-luis-rs
authored andcommitted
change to boost::process::v2 in UcesbLauncher
- Add cdash website to a badge
1 parent 5118f3c commit dd0ff11

9 files changed

Lines changed: 109 additions & 53 deletions

File tree

.clangd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Diagnostics:
2+
UnusedIncludes: Strict
3+
MissingIncludes: Strict
4+
AnalyzeAngledIncludes: Yes

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
# R3BRoot Software [![license](https://alfa-ci.gsi.de/shields/badge/license-GPL--3.0-orange.svg)](COPYRIGHT)
2-
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5549469.svg)](https://doi.org/10.5281/zenodo.5549469) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/9851/badge)](https://www.bestpractices.dev/projects/9851) [![fair-software.eu](https://img.shields.io/badge/fair--software.eu-%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8B%20%20%E2%97%8F%20%20%E2%97%8B-yellow)](https://fair-software.eu)
3-
4-
[![CI-CD](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/main.yml/badge.svg)](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/main.yml) [![Static Analysis](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/static_analysis.yml/badge.svg)](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/static_analysis.yml) [![Validate Codemeta](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/codemeta_validate.yaml/badge.svg)](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/codemeta_validate.yaml) [![Cleanup Caches on PR Close](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/cleanup_cache.yml/badge.svg)](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/cleanup_cache.yml)
1+
# R3BRoot Software [![license](https://img.shields.io/badge/License-GPLv3-blue.svg)](COPYRIGHT)
2+
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5549469.svg)](https://doi.org/10.5281/zenodo.5549469)
3+
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/9851/badge)](https://www.bestpractices.dev/projects/9851)
4+
[![fair-software.eu](https://img.shields.io/badge/fair--software.eu-%E2%97%8F%20%20%E2%97%8F%20%20%E2%97%8B%20%20%E2%97%8F%20%20%E2%97%8B-yellow)](https://fair-software.eu)
5+
[![CI-CD](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/main.yml/badge.svg)](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/main.yml)
6+
[![Static Analysis](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/static_analysis.yml/badge.svg)](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/static_analysis.yml)
7+
[![Validate Codemeta](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/codemeta_validate.yaml/badge.svg)](https://github.com/R3BRootGroup/R3BRoot/actions/workflows/codemeta_validate.yaml)
8+
[![dashboard](https://img.shields.io/badge/dashboard-r3broot-blue?labelColor=gray&style=flat)](https://cdash.gsi.de/index.php?project=R3BRoot)
59

610
## The R3BRoot Framework
711

califa/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ add_library_with_dictionary(
3939
calibration
4040
ana
4141
DEPENDENCIES
42-
Spectrum
42+
ROOT::Spectrum
4343
R3BPassive)
4444

4545
if(BUILD_GEOMETRY)

r3bsource/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ set(STRUCT_HEADERS
190190

191191
set(HEADERS
192192
base/R3BUcesbSource.h
193+
base/R3BUcesbSource2.h
193194
base/R3BReader.h
194195
base/R3BUnpackReader.h
195196
base/utils/R3BUcesbDecl.h

r3bsource/SourceLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#pragma link off all functions;
2121

2222
#pragma link C++ class R3BUcesbSource+;
23+
#pragma link C++ class R3B::UcesbSource+;
2324
#pragma link C++ class R3BReader+;
2425
#pragma link C++ class R3BUnpackReader+;
2526
#pragma link C++ class R3BWhiterabbitNeulandReader+;

r3bsource/base/R3BUcesbSource2.cxx

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,46 @@
1212
******************************************************************************/
1313

1414
#include "R3BUcesbSource2.h"
15+
#include "R3BUcesbLauncher.h"
1516
#include <FairRootManager.h>
1617
#include <FairRun.h>
1718
#include <R3BEventHeader.h>
1819
#include <R3BException.h>
19-
#include <R3BLogger.h>
2020
#include <R3BUcesbDecl.h>
21+
#include <array>
2122
#include <boost/core/span.hpp>
23+
#include <cstddef>
24+
#include <cstdint>
2225
#include <ext_data_client.h>
26+
#include <fairlogger/Logger.h>
27+
#include <fmt/core.h>
2328
#include <fmt/format.h>
29+
#include <string_view>
30+
#include <sys/types.h>
31+
#include <utility>
2432

2533
namespace R3B
2634
{
35+
namespace
36+
{
37+
void print_uint32_with_size(const uint32_t* data, ssize_t size)
38+
{
39+
// TODO: use ranges library instead of reinterpret_cast
40+
constexpr auto column_size = 8;
41+
using SubDataType = const std::array<uint32_t, column_size>;
42+
43+
auto data_span = boost::span<SubDataType>(reinterpret_cast<SubDataType*>(data), size / column_size);
44+
LOGP(info, "Raw data:");
45+
auto index = uint32_t{};
46+
for (const auto& row_data : data_span)
47+
{
48+
fmt::print("RAW{0:04x}: {1:08x}\n", index, fmt::join(row_data, " "));
49+
index += column_size;
50+
}
51+
}
52+
53+
} // namespace
54+
2755
UcesbSource::UcesbSource(std::string_view lmdfile_name,
2856
std::string_view ntuple_options,
2957
std::string_view ucesb_path,
@@ -53,7 +81,7 @@ namespace R3B
5381
{
5482
command_string = fmt::format("{} --max-events={}", command_string, max_event_num_);
5583
}
56-
R3BLOG(info, fmt::format("Calling ucesb with command: {}", command_string));
84+
LOGP(info, "Calling ucesb with command: {}", command_string);
5785

5886
ucesb_server_launcher_.Launch(std::move(command_string));
5987
}
@@ -62,13 +90,13 @@ namespace R3B
6290
{
6391
if (auto* frm = FairRootManager::Instance(); frm != nullptr)
6492
{
65-
R3BLOG(debug, "Checking the register of R3BEventHeader");
93+
LOGP(debug, "Checking the register of R3BEventHeader");
6694
if (event_header_ = dynamic_cast<R3BEventHeader*>(frm->GetObject("EventHeader.")); event_header_ == nullptr)
6795
{
6896
throw R3B::runtime_error("EventHeader. was not defined properly!");
6997
}
7098
}
71-
R3BLOG(debug, "EventHeader. was defined properly");
99+
LOGP(debug, "EventHeader. was defined properly");
72100

73101
init_readers();
74102
setup_ucesb();
@@ -89,7 +117,7 @@ namespace R3B
89117
}
90118
else
91119
{
92-
R3BLOG(error, "ext_data_clnt::setup() failed");
120+
LOGP(error, "ext_data_clnt::setup() failed");
93121
const auto* msg = (ucesb_client_.last_error() == nullptr) ? UCESB_NULL_STR_MSG : ucesb_client_.last_error();
94122
throw R3B::runtime_error(fmt::format("UCESB error: {}", msg));
95123
}
@@ -104,36 +132,20 @@ namespace R3B
104132
}
105133
else if (ret_val == 0)
106134
{
107-
R3BLOG(info, "Reached the maximal event num on the ucesb server.");
135+
LOGP(info, "Reached the maximal event num on the ucesb server.");
108136
// ending event loop here
109137
return 1;
110138
}
111139
else
112140
{
113-
R3BLOG(error, "ext_data_clnt::fetch_event() failed");
141+
LOGP(error, "ext_data_clnt::fetch_event() failed");
114142
const auto* msg = (ucesb_client_.last_error() == nullptr) ? UCESB_NULL_STR_MSG : ucesb_client_.last_error();
115143
throw R3B::runtime_error(fmt::format("UCESB error: {}", msg));
116144
}
117145

118146
return 0;
119147
}
120148

121-
void print_uint32_with_size(const uint32_t* data, ssize_t size)
122-
{
123-
// TODO: use ranges library instead of reinterpret_cast
124-
constexpr auto column_size = 8;
125-
using SubDataType = const std::array<uint32_t, column_size>;
126-
127-
auto data_span = std::span<SubDataType>(reinterpret_cast<SubDataType*>(data), size / column_size);
128-
R3BLOG(info, "Raw data:");
129-
auto index = uint32_t{};
130-
for (const auto& row_data : data_span)
131-
{
132-
fmt::print("RAW{0:04x}: {1:08x}\n", index, fmt::join(row_data, " "));
133-
index += column_size;
134-
}
135-
}
136-
137149
void UcesbSource::print_raw_data()
138150
{
139151
// TODO: what's the best way to deal with this void** monstrosity
@@ -151,7 +163,7 @@ namespace R3B
151163
}
152164
else
153165
{
154-
R3BLOG(error, "ext_data_clnt::get_raw_data()");
166+
LOGP(error, "ext_data_clnt::get_raw_data()");
155167
throw R3B::runtime_error("Failed to get raw data.");
156168
}
157169
}
@@ -166,17 +178,17 @@ namespace R3B
166178

167179
if (run_id_ != 0)
168180
{
169-
R3BLOG(info, fmt::format("Setting the run ID of the FairRun to be {} from FairSource", run_id_));
181+
LOGP(info, "Setting the run ID of the FairRun to be {} from FairSource", run_id_);
170182
run->SetRunId(run_id_);
171183
}
172184
else if (auto run_id = run->GetRunId(); run_id != 0)
173185
{
174-
R3BLOG(info, fmt::format("Setting the run ID of the FairSource to be {} from FairRun", run_id));
186+
LOGP(info, "Setting the run ID of the FairSource to be {} from FairRun", run_id);
175187
run_id_ = run_id;
176188
}
177189
else
178190
{
179-
R3BLOG(warn, "Run ID of neither FairRun nor FairSource is set!");
191+
LOGP(warn, "Run ID of neither FairRun nor FairSource is set!");
180192
}
181193
}
182194

r3bsource/base/R3BUcesbSource2.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
#include <R3BUcesbLauncher.h>
1919
#include <R3BUcesbMappingFlag.h>
2020
#include <R3BUcesbStructInfo.h>
21+
#include <Rtypes.h>
22+
#include <cstddef>
2123
#include <ext_data_clnt.hh>
24+
#include <memory>
25+
#include <string>
26+
#include <string_view>
27+
#include <vector>
2228

2329
struct EXT_STR_h101_t;
2430
using EventStructType = EXT_STR_h101_t;
@@ -59,10 +65,10 @@ namespace R3B
5965
auto AddReader(Args&&... args) -> ReaderType*;
6066
// TODO: C++20 concepts
6167
template <typename UnaryOp>
62-
void ForEachReader(UnaryOp&& opt);
68+
void ForEachReader(UnaryOp opt);
6369

6470
template <typename Predicate>
65-
auto FindReaderIf(Predicate&& pred) -> R3BReader*;
71+
auto FindReaderIf(Predicate pred) -> R3BReader*;
6672

6773
// deprecate the old API because of bad memory managerment
6874
[[deprecated("Please use smart pointer method to add a reader")]] auto* AddReader(R3BReader* a_reader)
@@ -115,7 +121,7 @@ namespace R3B
115121
Source_Type GetSourceType() override { return kONLINE; }
116122

117123
public:
118-
ClassDefInlineOverride(R3B::UcesbSource, 1);
124+
ClassDefOverride(R3B::UcesbSource, 1);
119125
};
120126

121127
template <typename ReaderType>
@@ -133,7 +139,7 @@ namespace R3B
133139
}
134140

135141
template <typename UnaryOp>
136-
void UcesbSource::ForEachReader(UnaryOp&& opt)
142+
void UcesbSource::ForEachReader(UnaryOp opt)
137143
{
138144
for (auto& reader : readers_)
139145
{
@@ -142,7 +148,7 @@ namespace R3B
142148
}
143149

144150
template <typename Predicate>
145-
auto UcesbSource::FindReaderIf(Predicate&& pred) -> R3BReader*
151+
auto UcesbSource::FindReaderIf(Predicate pred) -> R3BReader*
146152
{
147153
auto res = std::find_if(readers_.begin(), readers_.end(), [&pred](auto& reader) { return pred(reader.get()); });
148154
return (res == readers_.end()) ? nullptr : res->get();

r3bsource/base/utils/R3BUcesbLauncher.cxx

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,30 @@
1414
#include "R3BUcesbLauncher.h"
1515
#include <R3BException.h>
1616
#include <R3BLogger.h>
17+
#include <algorithm>
1718
#include <boost/algorithm/string.hpp>
19+
#include <boost/algorithm/string/classification.hpp>
20+
#include <boost/algorithm/string/constants.hpp>
21+
#include <boost/algorithm/string/split.hpp>
22+
#include <boost/algorithm/string/trim.hpp>
23+
#include <boost/process/v2/process.hpp>
24+
#include <boost/process/v2/stdio.hpp>
25+
#include <chrono>
26+
#include <cstddef>
27+
#include <fairlogger/Logger.h>
1828
#include <filesystem>
29+
#include <fmt/core.h>
30+
#include <fmt/format.h>
1931
#include <fmt/os.h>
32+
#include <memory>
2033
#include <regex>
2134

2235
#include <ext_data_clnt.hh>
36+
#include <string>
37+
#include <string_view>
38+
#include <system_error>
39+
#include <utility>
40+
#include <vector>
2341

2442
constexpr auto CHILD_CLOSE_WAITING_TIME = std::chrono::seconds(5);
2543

@@ -162,9 +180,12 @@ namespace R3B
162180
launch_strings.executable,
163181
fmt::join(launch_args, " ")));
164182

165-
ucesb_server_ = std::make_unique<boost::process::child>(
166-
launch_strings.executable, boost::process::args(launch_args), boost::process::std_out > server_pipe_);
167-
if (auto is_status_ok = client_->connect(server_pipe_.native_source()); not is_status_ok)
183+
ucesb_server_ =
184+
std::make_unique<bpv2::process>(ios_,
185+
launch_strings.executable,
186+
launch_args,
187+
bpv2::process_stdio{ .in = nullptr, .out = server_pipe_, .err = stdout });
188+
if (auto is_status_ok = client_->connect(server_pipe_.native_handle()); not is_status_ok)
168189
{
169190
R3BLOG(error, "ext_data_clnt::connect() failed");
170191
const auto* msg = (client_->last_error() == nullptr) ? UCESB_NULL_STR_MSG : client_->last_error();
@@ -181,15 +202,15 @@ namespace R3B
181202
throw R3B::runtime_error("ext_data_clnt::close() failed");
182203
}
183204
auto err_code = std::error_code{};
184-
if (not ucesb_server_->wait_for(CHILD_CLOSE_WAITING_TIME, err_code))
185-
{
186-
R3BLOG(warn, fmt::format("Failed to close Ucesb server! Error code: {}", err_code.value()));
187-
ucesb_server_->terminate(err_code);
188-
R3BLOG(warn, "Killing Ucesb server");
189-
}
190-
else
191-
{
192-
R3BLOG(info, "Ucesb server is closed successfully");
193-
}
205+
ucesb_server_->async_wait(
206+
[](const std::error_code& err, int ret)
207+
{
208+
if (err)
209+
{
210+
LOGP(error, "Error occured from ucesb server. Error message: {}", err.message());
211+
}
212+
LOGP(info, "Ucesb server is closed successfully with the return value: {}", ret);
213+
});
214+
ios_.run_for(CHILD_CLOSE_WAITING_TIME);
194215
}
195216
} // namespace R3B

r3bsource/base/utils/R3BUcesbLauncher.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@
1313
* or submit itself to any jurisdiction. *
1414
******************************************************************************/
1515
#include <boost/asio.hpp>
16-
#include <boost/process.hpp>
16+
#include <boost/asio/io_service.hpp>
17+
#include <boost/asio/readable_pipe.hpp>
18+
#include <boost/process/v2/process.hpp>
19+
#include <cstddef>
1720
#include <ext_data_clnt.hh>
21+
#include <memory>
22+
#include <string>
1823

1924
constexpr auto UCESB_NULL_STR_MSG = "Can't retrieve error message as last_error returns nullptr!";
2025

26+
namespace bpv2 = boost::process::v2;
27+
2128
namespace R3B
2229
{
2330
class UcesbServerLauncher
@@ -33,9 +40,9 @@ namespace R3B
3340

3441
private:
3542
ext_data_clnt* client_ = nullptr;
36-
std::unique_ptr<boost::process::child> ucesb_server_;
43+
std::unique_ptr<bpv2::process> ucesb_server_;
3744
boost::asio::io_service ios_;
38-
boost::process::async_pipe server_pipe_{ ios_ };
45+
boost::asio::readable_pipe server_pipe_{ ios_ };
3946
};
4047

4148
} // namespace R3B

0 commit comments

Comments
 (0)