16#include <FairRootManager.h>
22#include <boost/core/span.hpp>
27#include <ext_data_client.h>
28#include <fairlogger/Logger.h>
30#include <fmt/chrono.h>
32#include <fmt/format.h>
33#include <fmt/ranges.h>
44 void print_uint32_with_size(
const uint32_t* data, ssize_t size)
47 constexpr auto column_size = 8;
48 using SubDataType =
const std::array<uint32_t, column_size>;
50 auto data_span = boost::span<SubDataType>(
reinterpret_cast<SubDataType*
>(data), size / column_size);
51 LOGP(info,
"Raw data:");
52 auto index = uint32_t{};
53 for (
const auto& row_data : data_span)
55 fmt::println(
"RAW{0:04x}: {1:08x}", index, fmt::join(row_data,
" "));
65 std::string_view ntuple_options,
66 std::string_view ucesb_path,
68 size_t event_struct_size)
91 command_string = fmt::format(
"{} --max-events={}", command_string,
max_event_num_);
93 LOGP(info,
"Calling ucesb with command: {}", command_string);
101 if (
auto* frm = FairRootManager::Instance(); frm !=
nullptr)
103 LOGP(debug,
"Checking the register of R3BEventHeader");
109 LOGP(debug,
"EventHeader. was defined properly");
122 auto is_struct_map_success = uint32_t{};
123 LOGP(info,
"Setting up ucesb client...");
131 LOGP(error,
"ext_data_clnt::setup() failed");
144 catch (std::exception& ex)
158 else if (ret_val == 0)
160 LOGP(info,
"Reached the maximal event num on the ucesb server.");
170 LOGP(error,
"ext_data_clnt::fetch_event() failed");
180 const void* raw_data =
nullptr;
181 ssize_t raw_data_size = 0;
182 auto ret_val =
ucesb_client_.get_raw_data(&raw_data, &raw_data_size);
186 if (raw_data !=
nullptr)
188 const auto* data =
reinterpret_cast<const uint32_t*
>(raw_data);
189 print_uint32_with_size(data, raw_data_size);
194 LOGP(error,
"ext_data_clnt::get_raw_data()");
201 auto* run = FairRun::Instance();
209 LOGP(info,
"Setting the run ID of the FairRun to be {} from FairSource",
run_id_);
212 else if (
auto run_id = run->GetRunId(); run_id != 0)
214 LOGP(info,
"Setting the run ID of the FairSource to be {} from FairRun", run_id);
219 LOGP(warn,
"Run ID of neither FairRun nor FairSource is set!");
251 if (!reader->ReInit())
262 LOGP(info,
"Trying to restart ucesb server...");
269 constexpr auto minimum_duration = std::chrono::minutes{ 30 };
270 constexpr auto max_waiting_time = std::chrono::minutes{ 600 };
271 constexpr auto waiting_time_increment = std::chrono::minutes{ 30 };
272 auto time_now = std::chrono::system_clock::now();
273 auto duration = std::chrono::duration_cast<std::chrono::minutes>(time_now -
last_start_time_);
274 if (duration < minimum_duration)
276 LOGP(info,
"The program has been running shortly for {}", duration);
282 LOGP(info,
"The program has been running for {}", duration);
constexpr auto UCESB_NULL_STR_MSG
EXT_STR_h101_t EventStructType
std::string ntuple_options_
std::chrono::time_point< std::chrono::system_clock > last_start_time_
R3BEventHeader * event_header_
ext_data_clnt ucesb_client_
std::unique_ptr< UcesbServerLauncher > ucesb_server_launcher_
std::mutex event_reader_mutex_
void restart_ucesb_server()
bool InitUnpackers() override
void RestartUcesbServer()
bool ReInitUnpackers() override
UcesbStructInfo ucesb_client_struct_info_
void FillEventHeader(FairEventHeader *feh) override
std::string lmdfile_name_
size_t event_struct_size_
int ReadEvent(unsigned int eventID=0) override
void restart_ucesb_server_delayed()
int CheckMaxEventNo(int EvtEnd=0) override
std::chrono::minutes waiting_time_
void ForEachReader(UnaryOp opt)
EventStructType * event_struct_