9#include "BmnFunctionSet.h"
15using namespace std::chrono_literals;
16using namespace std::chrono;
20 if (str.rfind(
"Comment", 0) == 0)
21 return T0Config::Comment;
22 if (str.rfind(
"Discriminators", 0) == 0)
23 return T0Config::Discriminators;
24 if (str.rfind(
"Delay lines", 0) == 0)
25 return T0Config::DelayLines;
26 if (str.rfind(
"Switches", 0) == 0)
27 return T0Config::Switches;
28 if (str.rfind(
"LV", 0) == 0)
30 if (str.rfind(
"BD_multiplicity", 0) == 0)
31 return T0Config::BDMult;
32 if (str.rfind(
"Extra delays mask", 0) == 0)
33 return T0Config::ExtraDelaysMask;
34 return T0Config::Undefined;
39 uint32_t nans =
static_cast<uint32_t
>(jt[
"ns"]);
40 uint32_t sec =
static_cast<uint32_t
>(jt[
"sec"]) - tai_utc_dif;
41 bool valid =
static_cast<uint32_t
>(jt[
"valid"]);
42 return valid ?
SysPoint{sec * 1s + nans * 1ns} : SysPoint::min();
53 LOGF(debug2,
"cntr[%3d]: %8u",
i, d[
i]);
58 for (uint32_t
i = 0;
i < str.length();
i++) {
59 LOGF(debug2,
"str[%3d]: 0x%02X",
i, str[
i]);
61 regex re_str_cfg_t0_h2d(
"\\D*(\\d{2})\\.(\\d{2})\\.(\\d{4})\\s(\\d{2}:\\d{2}:\\d{2})\\D*");
62 regex re_str_cfg_t0_h1d(
"\\D*(\\d{2})\\.(\\d{2})\\.(\\d{4})\\s(\\d{1}:\\d{2}:\\d{2})\\D*");
63 bool re_subst_ret =
false;
65 if (regex_match(str, re_str_cfg_t0_h2d)) {
66 str_TDatime = regex_replace(str, re_str_cfg_t0_h2d,
"$3-$2-$1 $4");
68 }
else if (regex_match(str, re_str_cfg_t0_h1d)) {
69 str_TDatime = regex_replace(str, re_str_cfg_t0_h1d,
"$3-$2-$1 0$4");
80 LOGF(debug,
"unix ts: %s", ts_unix_sec.
AsString());
81 LOGF(debug,
"2020 ts: %s", ts_2020_sec.
AsString());
84 bitset<32> trig_bit_conf_bs(trig_bit_conf);
85 LOGF(debug,
"trig bitset %u", trig_bit_conf);
86 LOGF(debug,
"trig bitset %s", trig_bit_conf_bs.to_string());
88 string tcfg(
reinterpret_cast<const char*
>(d) + pos, len - pos);
100 lastT0->
SetTS(ts_unix_sec);
102 if (re_subst_ret > 0) {
110 istringstream ss(str_TDatime);
112 ss >> std::get_time(&tm,
"%Y-%m-%d %H:%M:%S");
113 std::time_t time_t_time = std::mktime(&tm);
114 SysPoint time_point = SysClock::from_time_t(time_t_time);
121 if (t_2020_sec > 0) {
122 lastT0->
SetTS(ts_2020_sec);
124 LOGF(warning,
"Unable to find raw T0 block timestamp!");
134 regex rempty(
"[\\s\r]*\n*");
135 regex re_cfg(
".+\\.BMNCfg.*[\r\n]*");
136 istringstream iss(str);
138 bool cfg_found =
false;
139 uint8_t empty_found = 0;
140 while (std::getline(iss, line)) {
141 if (regex_match(line, rempty)) {
146 if (regex_match(line, re_cfg)) {
148 LOG(debug2) <<
"CFG found";
154 LOG(error) <<
"Error: Raw T0 header not found!";
157 std::getline(iss, line);
160 auto& ch =
n.children;
162 case T0Config::Comment: {
167 case T0Config::Discriminators: {
168 regex re(
"Discriminator(\\d+)\\r*");
169 for (
const auto& node_par : ch) {
170 string snum = regex_replace(node_par.value, re,
"$1");
171 uint32_t idis = std::stoul(snum.data());
173 auto& disc = dvec[idis];
174 for (
const auto& node_chan : node_par.children) {
175 if (node_chan.value.rfind(
"Polarity", 0) == 0) {
176 if (node_chan.children.size() > 0) {
177 const auto& str_field = node_chan.children[0].value;
178 if (str_field.rfind(
"Positive", 0) == 0)
185 regex rthr(
"Threshold,\\s+(\\w+)\\r*");
186 if (regex_match(node_chan.value, rthr)) {
187 string unit = regex_replace(node_chan.value, rthr,
"$1");
188 if (node_chan.children.size() > 0) {
189 const auto& str_field = node_chan.children[0].value;
190 disc.threshold = std::atoi(str_field.data());
191 disc.threshold_unit = move(unit);
199 case T0Config::DelayLines: {
200 regex re(
"Delay(\\d+)\\r*");
201 for (
const auto& node_par : ch) {
202 string snum = regex_replace(node_par.value, re,
"$1");
203 uint32_t idis = std::stoul(snum.data());
205 if (node_par.children.size() > 0) {
206 const auto& str_field = node_par.children[0].value;
207 delvec[idis] = std::atoi(str_field.data());
211 case T0Config::Switches: {
212 regex re(
"Switch(\\d+)\\r*");
213 for (
const auto& node_par : ch) {
214 string snum = regex_replace(node_par.value, re,
"$1");
215 uint32_t idis = std::stoul(snum.data());
217 if (node_par.children.size() > 0) {
218 const auto& str_field = node_par.children[0].value;
219 swvec[idis] = (str_field.rfind(
"On", 0) == 0) ? true :
false;
224 regex re(
"Channel(\\d+)\\r*");
225 for (
const auto& node_par : ch) {
226 string snum = regex_replace(node_par.value, re,
"$1");
227 uint32_t idis = std::stoul(snum.data());
229 auto& cfg = dvec[idis];
230 for (
const auto& node_chan : node_par.children) {
231 if (node_chan.value.rfind(
"Active", 0) == 0) {
232 if (node_chan.children.size() > 0) {
233 const auto& str_field = node_chan.children[0].value;
234 cfg.active = (str_field.rfind(
"1", 0) == 0) ? true :
false;
238 if (node_chan.value.rfind(
"Channel name", 0) == 0) {
239 if (node_chan.children.size() > 0)
240 cfg.name = node_chan.children[0].value;
243 if (node_chan.value.rfind(
"V_P1", 0) == 0) {
244 if (node_chan.children.size() > 0) {
245 const auto& str_field = node_chan.children[0].value;
246 cfg.V_P1 = std::atoi(str_field.data());
250 if (node_chan.value.rfind(
"V_P2", 0) == 0) {
251 if (node_chan.children.size() > 0) {
252 const auto& str_field = node_chan.children[0].value;
253 cfg.V_P2 = std::atoi(str_field.data());
257 if (node_chan.value.rfind(
"State", 0) == 0) {
258 if (node_chan.children.size() > 0) {
259 const auto& str_field = node_chan.children[0].value;
260 cfg.state = (str_field.rfind(
"On", 0) == 0) ? true :
false;
268 case T0Config::BDMult: {
269 regex re(
"BDM_(\\w+)\\r*");
270 for (
const auto& node_par : ch) {
271 string spar = regex_replace(node_par.value, re,
"$1");
272 if (node_par.children.size() > 0) {
273 const auto& str_field = node_par.children[0].value;
274 uint32_t thr = std::atoi(str_field.data());
284 case T0Config::ExtraDelaysMask: {
285 regex re(
"\\$([0-9a-fA-F]+)\\r*");
286 for (
const auto& node_par : ch) {
287 string snum = regex_replace(node_par.value, re,
"$1");
288 uint32_t num = std::stoul(snum.data(),
nullptr, 16);
297 }
catch (
const std::exception& e) {
298 LOG(error) <<
"Error: " << e.what();
307 auto& j_runtime = jv[
"runTime"];
308 auto& j_spill = j_runtime[
"spill"];
309 ss.
phase =
static_cast<uint32_t
>(j_spill[
"phase"]);
311 ss.
spill_cnt =
static_cast<uint32_t
>(j_spill[
"count"]);
312 auto j_device_time = j_runtime[
"time"];
313 ss.
app_ts = SysClock::from_time_t(
static_cast<uint32_t
>(j_device_time[
"app"]));
314 auto j_device_time_WR = j_device_time[
"WR"];
316 auto j_spill_start = j_spill[
"spillStartTaiWrStat"];
318 auto j_spill_stop = j_spill[
"spillStopTaiWrStat"];
321 auto& j_counters = j_runtime[
"counters"];
322 if (j_counters.contains(
"input_afterReduc")) {
324 auto& j_cnt_input = j_counters[
"input"];
325 uint32_t size_input = j_cnt_input.size();
328 for (
auto& [key, val] : j_cnt_input.items()) {
329 string name =
static_cast<string>(
key);
332 for (
size_t i = 0;
i < size;
i++)
338 auto& j_cnt_input = j_counters[
"input_afterReduc"];
339 uint32_t size_input = j_cnt_input.size();
342 for (
auto& [key, val] : j_cnt_input.items()) {
343 string name =
static_cast<string>(
key);
346 for (
size_t i = 0;
i < size;
i++)
353 auto& j_cnt_input = j_counters[
"input"];
357 for (
size_t i = 0;
i < size;
i++)
361 auto& j_cnt_input = j_counters[
"after_reduc"];
365 for (
size_t i = 0;
i < size;
i++)
370 auto& j_cnt_ae = j_counters[
"after_err"];
372 for (
size_t i = 0;
i < size;
i++)
376 auto& j_cnt_ae = j_counters[
"befor_err"];
378 for (
size_t i = 0;
i < size;
i++)
391 auto ph_trig_setups = j[
"programs"][
"Trc#T0"][
"knownSetups"];
392 if (ph_trig_setups.size()) {
393 auto ph_trig = ph_trig_setups.begin().value()[
"trc"][
"phyTrig"];
394 uint32_t match_win = ph_trig[
"matchWin"];
395 uint32_t trig_delay = ph_trig[
"trigDelay"];
396 uint32_t read_chan_mask = ph_trig[
"readChMask"];
397 uint32_t start_chan_mask = ph_trig[
"startChMask"];
398 uint32_t calib_cnt = ph_trig[
"calibTrigger"][
"count"];
399 uint32_t calib_en = (bool)ph_trig[
"calibTrigger"][
"en"];
406 LOGF(debug,
"start_chan_mask %u", start_chan_mask);
407 LOGF(debug,
"read_chan_mask %u", read_chan_mask);
408 auto ch_conf = ph_trig[
"chCfg"];
409 unordered_map<string, BmnTrigChannelConfig>& tcc = trig_conf.
TrigChannelConfig();
410 for (
auto& trig_chan_conf : ch_conf) {
411 LOG(debug2) << trig_chan_conf.dump();
412 string name = trig_chan_conf[
"name"];
413 if (name.length() == 0)
416 tcc_el.
after_protect_en = (bool)trig_chan_conf[
"reg"][
"after_protect_en"].get<int>();
417 uint32_t ap_clocks = trig_chan_conf[
"reg"][
"after_protect_time"];
419 tcc_el.
before_protect_en = (bool)trig_chan_conf[
"reg"][
"before_protect_en"].get<int>();
420 uint32_t bp_clocks = trig_chan_conf[
"reg"][
"before_protect_time"];
422 tcc_el.
delay = trig_chan_conf[
"reg"][
"delay"];
423 tcc_el.
reduction_en = (bool)trig_chan_conf[
"reg"][
"reduction_en"].get<int>();
425 tcc.insert(make_pair(name, tcc_el));
436 uint32_t word = d[iWord++];
442 LOGF(error,
"Wrong RunId length %u", idLen);
446 LOGF(info,
"\tRun Id: %u", runId);
451 LOGF(error,
"Wrong event order length %u", idLen);
454 uint32_t event_order = d[iWord];
455 LOGF(info,
"\tEvent Order: %u", event_order);
461 LOGF(error,
"Wrong FileId length %u", idLen);
464 uint32_t file_id = d[iWord];
465 LOGF(info,
"\tFile Id: %u", file_id);
471 LOGF(error,
"Wrong RunIndex length %u", idLen);
475 TString runIndex(
reinterpret_cast<const char*
>(d + iWord), idLen);
476 LOGF(info,
"\tRun Index: %s", runIndex.Data());
480 LOGF(warning,
"Unknown record %08X", word);
491 TPRegexp re_data(
".+_(\\d+)([^/]*)\\.data");
492 TPRegexp re_raw(
".+_(\\d+)([^/]*)_raw\\.root");
513 int32_t lastSlash = path.rfind(
'/');
514 string name(path.substr(lastSlash + 1, path.length() - lastSlash));
515 LOGF(debug,
"name: %s", name.data());
518 regex re6(
"(.+)_(\\d+)_ev(\\d+)_p(\\d+)\\.(\\w+)([\\.\\w]+)\\r*");
519 regex re5(
"(.+)_(\\d+)_ev(\\d+)(_p\\d+){0,1}\\.(\\w+)([\\.\\w]+)\\r*");
520 if (!regex_match(name, re5)) {
521 LOGF(error,
"regex doesn't match: %s", name.data());
529 string str_run_id = regex_replace(name, re5,
"$2");
530 string str_ev_ord = regex_replace(name, re5,
"$3");
531 uint32_t run_id = std::stoul(str_run_id.data());
532 uint32_t ev_ord = std::stoul(str_ev_ord.data());
537 uint32_t part_id = 0;
538 if (regex_match(name, re6)) {
539 string str_part = regex_replace(name, re6,
"$4");
540 part_id = std::stoul(str_part.data());
544 string str_pre_id = regex_replace(name, re5,
"$1");
545 regex re_names(
"((\\w+)_)*([^_]+)_(\\w+)");
546 if (regex_match(str_pre_id, re_names)) {
547 string str_exp = regex_replace(str_pre_id, re_names,
"$2");
548 string str_run = regex_replace(str_pre_id, re_names,
"$3");
549 string str_run_in = regex_replace(str_pre_id, re_names,
"$4");
550 LOGF(debug,
"exp %s", str_exp.data());
551 LOGF(debug,
"run %s", str_run.data());
552 LOGF(debug,
"run_in %s", str_run_in.data());
555 LOGF(debug,
"run_id %d", prop.
GetRunId());
557 LOGF(debug,
"part_id %d", prop.
GetFileId());
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
BmnStatus
Define status code.
std::chrono::time_point< SysClock > SysPoint
const uint32_t RECORD_FILE_ID
const uint32_t RECORD_RUN_NUMBER
const uint32_t RECORD_EVENT_ORDER
const uint32_t kT0_BIN_BLOCK_2020_SEC
const uint32_t kT0_BIN_BLOCK_TIME_TXT
const uint32_t kNBYTESINWORD
const uint32_t kT0_BIN_BLOCK_UNIX_SEC
const uint32_t kT0_BIN_BLOCK_BYTES
const double TRC_CLOCK_NS
const uint32_t RECORD_RUN_INDEX
const uint32_t kT0_BIN_BLOCK_WORDS
uint32_t GetFileId() const
void SetFileId(uint32_t fid)
void SetRunIndex(string index)
uint32_t GetRunId() const
void SetEventOrder(uint32_t order)
void SetRunId(uint32_t v)
uint32_t GetEventOrder() const
static std::string TimePoint2String(SysPoint p)
T0 module spill settings and counts.
map< uint32_t, Discriminator_Config > & Discriminators()
void SetBDMultH(uint32_t val)
void SetBDMultL(uint32_t val)
map< uint32_t, bool > & Switches()
void SetComment(string str)
map< uint32_t, LV_Channel_Config > & LVChannelConfig()
void SetTime(SysPoint point)
void SetTS(TTimeStamp ts)
void SetTriggerMask(uint32_t val)
map< uint32_t, int32_t > & DelayLines()
void SetExtraDelaysMask(uint32_t val)
Class BmnTrigConfig Trigger DAQ config.
void SetTrigDelay(uint32_t v)
void SetReadChannelMask(uint32_t v)
void SetStartChannelMask(uint32_t v)
void SetCalibCount(uint32_t v)
unordered_map< string, BmnTrigChannelConfig > & TrigChannelConfig()
void SetMatchWindow(uint32_t v)
TObject * Remove(TObject *obj) override
Int_t GetEntriesFast() const
Bool_t MatchB(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
Int_t Substitute(TString &s, const TString &replace, const TString &mods="", Int_t start=0, Int_t nMatchMax=10)
const char * Data() const
const char * AsString(const Option_t *option="") const
*brief user defined string literal for JSON values *sa std::size_t n
void ParseIStringStream(istringstream &iss, Node &root)
Class BmnTrigChannelConfig Trigger channel configuration (count reduction, time protection).
uint32_t reduction_factor
uint32_t before_protect_time
uint32_t after_protect_time
std::array< ULong64_t, counters_cnt > cntr_after_err
std::vector< std::pair< std::string, std::array< ULong64_t, counters_cnt > > > cntr_input
std::vector< std::pair< std::string, std::array< ULong64_t, counters_cnt > > > cntr_input_after_red
std::array< ULong64_t, counters_cnt > cntr_befor_err
Class SpillStatus raw spill status from JSON block.
SpillCntrs< counters_cnt > counters
static const size_t counters_cnt