49 regex rempty(
"\\s+\n*");
50 istringstream iss(str);
52 bool main_found =
false;
53 bool cfg_found =
false;
54 while (std::getline(iss, line)) {
55 if (regex_match(line, rempty)) {
62 regex rSpillTime(
"(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})\\.BMNCfg\n*");
63 if (regex_search(line, sm, rSpillTime)) {
65 int32_t year = std::stoi(sm[1]);
66 int32_t month = std::stoi(sm[2]);
67 int32_t day = std::stoi(sm[3]);
68 int32_t hour = std::stoi(sm[4]);
69 int32_t
min = std::stoi(sm[5]);
70 int32_t sec = std::stoi(sm[6]);
71 TTimeStamp ts(year, month, day, hour,
min, sec);
72 LOGF(debug,
"ts cfg: %s", ts.AsString());
82 for (
const auto& n : node.children) {
83 auto& ch = n.children;
84 switch (GetT0Cfg(n.value)) {
85 case T0Config::Comment: {
90 case T0Config::Discriminators: {
91 regex re(
"Discriminator(\\d+)\\r*");
92 for (
const auto& node_par : ch) {
93 string snum = regex_replace(node_par.value, re,
"$1");
94 uint32_t idis = std::stoul(snum.data());
98 auto& disc = dvec[idis];
99 for (
const auto& node_chan : node_par.children) {
100 if (node_chan.value.rfind(
"Polarity", 0) == 0) {
101 if (node_chan.children.size() > 0) {
102 const auto& str_field = node_chan.children[0].value;
103 if (str_field.rfind(
"Positive", 0) == 0)
110 regex rthr(
"Threshold,\\s+(\\w+)\\r*");
111 if (regex_match(node_chan.value, rthr)) {
112 string unit = regex_replace(node_chan.value, rthr,
"$1");
113 if (node_chan.children.size() > 0) {
114 const auto& str_field = node_chan.children[0].value;
115 disc.threshold = std::atoi(str_field.data());
116 disc.threshold_unit = move(unit);
124 case T0Config::DelayLines: {
125 regex re(
"Delay(\\d+)\\r*");
126 for (
const auto& node_par : ch) {
127 string snum = regex_replace(node_par.value, re,
"$1");
128 uint32_t idis = std::stoul(snum.data());
132 if (node_par.children.size() > 0) {
133 const auto& str_field = node_par.children[0].value;
134 delvec[idis] = std::atoi(str_field.data());
138 case T0Config::Switches: {
139 regex re(
"Switch(\\d+)\\r*");
140 for (
const auto& node_par : ch) {
141 string snum = regex_replace(node_par.value, re,
"$1");
142 uint32_t idis = std::stoul(snum.data());
146 if (node_par.children.size() > 0) {
147 const auto& str_field = node_par.children[0].value;
148 swvec[idis] = (str_field.rfind(
"On", 0) == 0) ?
true :
false;
153 regex re(
"Channel(\\d+)\\r*");
154 for (
const auto& node_par : ch) {
155 string snum = regex_replace(node_par.value, re,
"$1");
156 uint32_t idis = std::stoul(snum.data());
160 auto& cfg = dvec[idis];
161 for (
const auto& node_chan : node_par.children) {
162 if (node_chan.value.rfind(
"Active", 0) == 0) {
163 if (node_chan.children.size() > 0) {
164 const auto& str_field = node_chan.children[0].value;
165 cfg.active = (str_field.rfind(
"1", 0) == 0) ?
true :
false;
169 if (node_chan.value.rfind(
"Channel name", 0) == 0) {
170 if (node_chan.children.size() > 0)
171 cfg.name = node_chan.children[0].value;
174 if (node_chan.value.rfind(
"V_P1", 0) == 0) {
175 if (node_chan.children.size() > 0) {
176 const auto& str_field = node_chan.children[0].value;
177 cfg.V_P1 = std::atoi(str_field.data());
181 if (node_chan.value.rfind(
"V_P2", 0) == 0) {
182 if (node_chan.children.size() > 0) {
183 const auto& str_field = node_chan.children[0].value;
184 cfg.V_P1 = std::atoi(str_field.data());
188 if (node_chan.value.rfind(
"State", 0) == 0) {
189 if (node_chan.children.size() > 0) {
190 const auto& str_field = node_chan.children[0].value;
191 cfg.state = (str_field.rfind(
"On", 0) == 0) ?
true :
false;
199 case T0Config::BDMult: {
200 regex re(
"BDM_(\\w+)\\r*");
201 for (
const auto& node_par : ch) {
202 string spar = regex_replace(node_par.value, re,
"$1");
203 if (node_par.children.size() > 0) {
204 const auto& str_field = node_par.children[0].value;
205 uint32_t
thr = std::atoi(str_field.data());
215 case T0Config::ExtraDelaysMask: {
216 regex re(
"\\$([0-9a-fA-F]+)\\r*");
217 for (
const auto& node_par : ch) {
218 string snum = regex_replace(node_par.value, re,
"$1");
219 uint32_t num = std::stoul(snum.data(),
nullptr, 16);
228 }
catch (
const std::exception& e) {
229 LOG(error) <<
"Error: " << e.what();
238 auto& j_runtime = jv[
"runTime"];
239 auto& j_spill = j_runtime[
"spill"];
240 ss.phase =
static_cast<UInt_t
>(j_spill[
"phase"]);
241 ss.cur_spill_time_ms =
static_cast<UInt_t
>(j_spill[
"curSpillTimeMs"]);
242 ss.spill_cnt =
static_cast<UInt_t
>(j_spill[
"count"]);
243 auto j_device_time = j_runtime[
"time"];
244 ss.app_ts = SysClock::from_time_t(
static_cast<UInt_t
>(j_device_time[
"app"]));
245 auto j_device_time_WR = j_device_time[
"WR"];
246 ss.device_ts =
ParseTAI(j_device_time_WR, tai_utc_dif);
247 auto j_spill_start = j_spill[
"spillStartTaiWrStat"];
248 ss.start_ts =
ParseTAI(j_spill_start, tai_utc_dif);
249 auto j_spill_stop = j_spill[
"spillStopTaiWrStat"];
250 ss.stop_ts =
ParseTAI(j_spill_stop, tai_utc_dif);
252 auto& j_counters = j_runtime[
"counters"];
253 if (j_counters.contains(
"input_afterReduc")) {
255 auto& j_cnt_input = j_counters[
"input"];
256 UInt_t size_input = j_cnt_input.size();
257 ss.counters.cntr_input.resize(size_input);
259 for (
auto& [key, val] : j_cnt_input.items()) {
260 string name =
static_cast<string>(key);
261 ss.counters.cntr_input[iInput].first = move(name);
263 for (
size_t i = 0;
i < size;
i++)
264 ss.counters.cntr_input[iInput].second[
i] =
static_cast<UInt_t
>(val[
i]);
269 auto& j_cnt_input = j_counters[
"input_afterReduc"];
270 UInt_t size_input = j_cnt_input.size();
271 ss.counters.cntr_input_after_red.resize(size_input);
273 for (
auto& [key, val] : j_cnt_input.items()) {
274 string name =
static_cast<string>(key);
275 ss.counters.cntr_input_after_red[iInput].first = move(name);
277 for (
size_t i = 0;
i < size;
i++)
278 ss.counters.cntr_input_after_red[iInput].second[
i] =
static_cast<UInt_t
>(val[
i]);
284 auto& j_cnt_input = j_counters[
"input"];
286 ss.counters.cntr_input.resize(1);
287 ss.counters.cntr_input[0].first =
"7: ~xOff & Run & Spill";
288 for (
size_t i = 0;
i < size;
i++)
289 ss.counters.cntr_input[0].second[
i] =
static_cast<UInt_t
>(j_cnt_input[
i]);
292 auto& j_cnt_input = j_counters[
"after_reduc"];
294 ss.counters.cntr_input_after_red.resize(1);
295 ss.counters.cntr_input_after_red[0].first =
"7: ~xOff & Run & Spill";
296 for (
size_t i = 0;
i < size;
i++)
297 ss.counters.cntr_input_after_red[0].second[
i] =
static_cast<UInt_t
>(j_cnt_input[
i]);
301 auto& j_cnt_ae = j_counters[
"after_err"];
303 for (
size_t i = 0;
i < size;
i++)
304 ss.counters.cntr_after_err[
i] =
static_cast<UInt_t
>(j_cnt_ae[
i]);
307 auto& j_cnt_ae = j_counters[
"befor_err"];
309 for (
size_t i = 0;
i < size;
i++)
310 ss.counters.cntr_befor_err[
i] =
static_cast<UInt_t
>(j_cnt_ae[
i]);
322 auto ph_trig_setups = j[
"programs"][
"Trc#T0"][
"knownSetups"];
323 if (ph_trig_setups.size()) {
324 auto ph_trig = ph_trig_setups.
begin().value()[
"trc"][
"phyTrig"];
325 UInt_t match_win = ph_trig[
"matchWin"];
326 UInt_t trig_delay = ph_trig[
"trigDelay"];
327 UInt_t read_chan_mask = ph_trig[
"readChMask"];
328 UInt_t start_chan_mask = ph_trig[
"startChMask"];
329 UInt_t calib_cnt = ph_trig[
"calibTrigger"][
"count"];
330 UInt_t calib_en = (bool)ph_trig[
"calibTrigger"][
"en"];
337 LOGF(debug,
"start_chan_mask %u", start_chan_mask);
338 LOGF(debug,
"read_chan_mask %u", read_chan_mask);
339 auto ch_conf = ph_trig[
"chCfg"];
340 unordered_map<string, BmnTrigChannelConfig>& tcc = trig_conf.
TrigChannelConfig();
341 for (
auto& trig_chan_conf : ch_conf) {
342 LOG(debug2) << trig_chan_conf.dump();
343 string name = trig_chan_conf[
"name"];
344 if (name.length() == 0)
347 tcc_el.
after_protect_en = (bool)trig_chan_conf[
"reg"][
"after_protect_en"].get<int>();
348 uint32_t ap_clocks = trig_chan_conf[
"reg"][
"after_protect_time"];
350 tcc_el.
before_protect_en = (bool)trig_chan_conf[
"reg"][
"before_protect_en"].get<int>();
351 uint32_t bp_clocks = trig_chan_conf[
"reg"][
"before_protect_time"];
353 tcc_el.
delay = trig_chan_conf[
"reg"][
"delay"];
354 tcc_el.
reduction_en = (bool)trig_chan_conf[
"reg"][
"reduction_en"].get<int>();
356 tcc.insert(make_pair(name, tcc_el));
444 int32_t lastSlash = path.rfind(
'/');
445 string name(path.substr(lastSlash + 1, path.length() - lastSlash));
446 LOGF(debug,
"name: %s", name.data());
447 regex re6(
"(\\w+)_(\\w+)_(\\w+)_(\\d+)_ev(\\d+)_p(\\d+)\\.(\\w+)\\r*");
448 regex re5(
"(\\w+)_(\\w+)_(\\w+)_(\\d+)_ev(\\d+)(_p\\d+){0,1}\\.(\\w+)\\r*");
449 if (!regex_match(name, re5)) {
450 LOGF(error,
"regex doesn't match: %s", name.data());
453 string str_exp = regex_replace(name, re5,
"$1");
454 string str_run = regex_replace(name, re5,
"$2");
455 string str_run_in = regex_replace(name, re5,
"$3");
456 string str_run_id = regex_replace(name, re5,
"$4");
457 string str_ev_ord = regex_replace(name, re5,
"$5");
458 uint32_t run_id = std::stoul(str_run_id.data());
459 uint32_t ev_ord = std::stoul(str_ev_ord.data());
465 uint32_t part_id = 0;
466 if (regex_match(name, re6)) {
467 string str_part = regex_replace(name, re6,
"$6");
468 part_id = std::stoul(str_part.data());
472 LOGF(debug,
"exp %s", str_exp.data());
473 LOGF(debug,
"run %s", str_run.data());
474 LOGF(debug,
"run_in %s", prop.
GetRunIndex().data());
475 LOGF(debug,
"run_id %d", prop.
GetRunId());
477 LOGF(debug,
"part_id %d", prop.
GetFileId());