269 "LOST SPILL END! Making fake one!\n"
270 "Spill:\n\tstart ts: %s\n\tstop ts: %s",
302 LOGF(info,
"scalers_ar_size %d", scalers_ar_size);
309 auto df_spills_withT0Raw_in_run = df_spills.
Filter(
321 auto sum_ptr_dbl = df_spills_withT0Raw_in_run
330 Double_t sum = sum_ptr_dbl ? *sum_ptr_dbl : 0.0;
331 auto df_spills_in_run_cnt_ptr = df_spills_withT0Raw_in_run.Count();
332 LOGF(info,
"Raw T0 count : %lld", (*df_spills_in_run_cnt_ptr));
334 auto t0raw_shift_av = df_spills_in_run_cnt_ptr ? sum / (*df_spills_in_run_cnt_ptr) : 0.0;
335 LOGF(info,
"Average raw T0 TimeSinceLastEv %10.3f ns", t0raw_shift_av);
339 LOGF(info,
"Real time %f s, CPU time %f s sum T0Raw timeshifts", rtime, ctime);
344 LOGF(debug,
"Filling tchain with a file %s", name.c_str());
345 fInTreeSpills->
Add(name.c_str());
346 fInTreeEvents->
Add(name.c_str());
365 size_t msc_entries_cnt_total(0);
366 size_t msc_entries_cnt(0);
368 typedef pair<Long64_t, Int_t> Index_Pair;
369 map<SysPoint, vector<Index_Pair>> mts;
371 vector<pair<SysPoint, size_t>> vts_t0;
375 LOGF(info,
"Start filling timestamp map");
415 vts_t0.push_back(make_pair(dig->
GetTime() - ((
Long64_t)t0raw_shift_av) * 1ns - 1s,
423 for (
Int_t iDig = 0; iDig <
msc->GetEntries(); ++iDig) {
425 mts[dig->
GetTime()].push_back(make_pair(iEntry, iDig));
431 vts_t0.push_back(make_pair(dig->
GetTime() - ((
Long64_t)t0raw_shift_av) * 1ns - 1s,
439 msc_entries_cnt_total = mts.size();
444 LOGF(info,
"Real time %f s, CPU time %f s timestamp map filling", rtime, ctime);
454 LOGF(info,
"***********************************************************");
458 LOGF(warning,
"Spill is outside the run! Skipping!");
463 auto df_events_in_spill = df.
Filter(
467 {
"BmnEventHeader."});
470 UInt_t last_ev_id(0);
479 auto df_events_in_spill_trig_cntr = df_events_in_spill.Filter(
495 {
"BmnEventHeader."});
496 ULong64_t n_events = *(df_events_in_spill_trig_cntr.Count());
499 n_events_run += n_events;
500 LOGF(info,
"Events in the spill %7llu", n_events);
504 if ((spillId == 0) || (spillId ==
fSpillMap.size() - 1)) {
505 spillRangeImposedStart = first_ev_tp;
506 spillRangeImposedStop = last_ev_tp;
508 spillRangeImposedStart = si.
start_ts;
509 spillRangeImposedStop = si.
stop_ts;
520 const string& tr_name = el.first;
521 spillHeader->EventTriggerCnt()[tr_name] = cnt[el.second];
523 LOGF(info,
"Evt_cnt %-11s %7llu", tr_name.c_str(), cnt[el.second]);
528 LOGF(info,
"Real time %f s, CPU time %f s ev cnt calc", rtime, ctime);
531 std::sort(vts_t0.begin(), vts_t0.end(),
532 [](pair<SysPoint, size_t>& a, pair<SysPoint, size_t>& b) { return (a.first < b.first); });
533 vector<pair<SysPoint, size_t>> spillIds_t0;
535 copy_if(begin(vts_t0), end(vts_t0), std::back_inserter(spillIds_t0),
536 [&si](pair<SysPoint, size_t> p) {
return (p.first >= si.
start_ts) && (p.first <= si.
stop_ts); });
540 LOGF(info,
"IDs entries T0:%d", spillIds_t0.size());
541 LOGF(debug,
"Real time %f s, CPU time %f s ids copy T0", rtime, ctime);
543 LOGF(info,
"Start scalers calc");
552 vector<uint64_t> scalerVec(scalers_ar_size, 0);
556 auto df_spill = df_spills.
Filter(
569 uint32_t missing_hits = 0;
570 map<SysPoint, vector<uint8_t>> mts9;
579 uint8_t index = index_it->second;
581 vector<uint8_t>& values = dig->
GetValues();
583 for (
size_t iTime = 0; iTime < dig->
GetNVals(); iTime++) {
586 auto it = mts9.find(time);
587 if (it == mts9.end()) {
588 vector<uint8_t> tarr(scalers_ar_size + 1, 0);
589 tarr[index] = values[iTime];
590 tarr[scalers_ar_size] = excs[iTime];
591 mts9.insert(make_pair(time, move(tarr)));
593 vector<uint8_t>& tarr = it->second;
594 tarr[index] += values[iTime];
595 tarr[scalers_ar_size] = excs[iTime];
602 auto itLower = mts9.lower_bound(spillRangeImposedStart);
603 auto itUpper = mts9.upper_bound(spillRangeImposedStop);
604 size_t spillTimesCount = std::distance(itLower, itUpper);
606 msc_entries_cnt += spillTimesCount;
607 msc_entries_cnt_total += mts9.size();
608 LOGF(info,
"Spill times count %lld", spillTimesCount);
616 boost::dynamic_bitset<> bitVecSpill(spillTimesCount,
false);
617 boost::dynamic_bitset<> bitVecBusy(spillTimesCount,
false);
619 for (
auto itTimes = itLower; itTimes != itUpper; itTimes++) {
620 auto& time = itTimes->first;
621 vector<uint8_t>& vals = itTimes->second;
623 msc_matrix->
SetTime(i_record, time);
624 uint8_t ext_cond = vals[scalers_ar_size];
629 for (uint16_t iScaler = 0; iScaler < scalers_ar_size; iScaler++) {
630 if (vals[iScaler] == 0)
632 msc_matrix->
SetCount(i_record, iScaler, vals[iScaler]);
637 scalerVec[iScaler] += vals[iScaler];
638 LOGF(debug,
"el %8llu %2lu count %3u sp %u busy %u GC", i_record, iScaler,
646 if (i_record > spillTimesCount)
647 LOGF(error,
"\n\t ERROR!!! irec %lu spillTimesCount %lu\n", i_record, spillTimesCount);
651 auto itLower = mts.lower_bound(spillRangeImposedStart);
652 auto itUpper = mts.upper_bound(spillRangeImposedStop);
653 Long64_t spillEntriesCumulativeSize{0};
654 size_t spillTimesCount = std::distance(itLower, itUpper);
656 for (
auto itTimes = itLower; itTimes != itUpper; itTimes++) {
657 vector<Index_Pair>& index_vec = itTimes->second;
658 spillEntriesCumulativeSize += index_vec.size();
661 msc_entries_cnt += spillTimesCount;
662 LOGF(info,
"entriesCumulativeSize %lld", spillEntriesCumulativeSize);
663 LOGF(info,
"Spill times count %lld", spillTimesCount);
674 boost::dynamic_bitset<> bitVecSpill(spillTimesCount,
false);
675 boost::dynamic_bitset<> bitVecBusy(spillTimesCount,
false);
676 for (
auto itTimes = itLower; itTimes != itUpper; itTimes++) {
677 auto& time = itTimes->first;
679 msc_matrix->
SetTime(i_record, time);
680 vector<Index_Pair>& index_vec = itTimes->second;
682 LOGF(debug2,
"index_vec.size() %8llu", index_vec.size());
683 if (index_vec.size() > 1)
684 LOGF(debug,
"new time");
685 for (Index_Pair& index_pair : index_vec) {
686 Long64_t& iEntry = index_pair.first;
687 Int_t& iDig = index_pair.second;
689 if (iDig >=
msc->GetEntries()) {
690 LOGF(error,
"\n\t ERROR!!! iDig %d msc->GetEntries() %d\n", iDig,
msc->GetEntries());
694 LOGF(debug2,
"iEntry %7d iDig %3d el %8llu ", iEntry, iDig, i_record);
695 if (index_vec.size() > 1) {
696 LOGF(debug,
"dig->IsSpill() %d", dig->
IsSpill());
697 LOGF(debug,
"dig->IsBusy() %d", dig->
IsBusy());
699 bitVecSpill[i_record] = dig->
IsSpill();
700 bitVecBusy[i_record] = dig->
IsBusy();
714 uint16_t iScaler = it->second;
717 msc_matrix->
SetCount(i_record, iScaler, val);
719 if (index_vec.size() > 1)
720 LOGF(debug,
"el %8llu %2lu ser 0x%8X = %u sp %u busy %u", i_record, iScaler,
728 scalerVec[iScaler] += val;
733 if (i_record > spillTimesCount)
734 LOGF(error,
"\n\t ERROR!!! irec %lu spillTimesCount %lu\n", i_record, spillTimesCount);
772 for (
auto& p : spillIds_t0) {
777 for (
int i = 0;
i < scalers_ar_size;
i++)
787 LOGF(info,
"Real time %f s, CPU time %f s Scalers calc", rtime, ctime);
792 uint64_t& val = scalerVec[iSc];
794 LOGF(info,
"MSC %-14s %10llu", name.c_str(), val);
801 LOGF(error,
"More than 1 T0 in the spill %lu ! %d records found",
spillHeader->GetSpillId(),
804 LOGF(warning,
"No T0 in the spill %lu ! We'll try to recover it from the T0 storage file.",
807 LOGF(info,
"Searching for T0 in the storage");
811 LOGF(info,
"Found at timestamp %s entry %u", (itLower->first).AsString(), itLower->second);
820 LOGF(error,
"%s timestamp not found in the T0 storage!", t0StopTS.
AsString());
822 LOGF(error,
"No T0 storage! Skipping");
837 LOGF(info,
"Evt trigger count Total:");
840 const string& tr_name = el.first;
841 LOGF(info,
"%-12s %8llu", tr_name.c_str(),
digiRunHeader->EventTriggerCnt()[tr_name]);
843 LOGF(info,
"Raw T0 Total:");
845 const T0MapKey& key = t0_map_el.first;
846 if (key.first.find(
"BD") == 0)
848 LOGF(info,
"T0 %-14s.%02u = %10llu", key.first.c_str(), key.second,
849 digiRunHeader->GetRawT0Counter(key.first.c_str(), key.second));
851 LOGF(info,
"MSC Total:");
853 delete fInTreeSpills;
912 return ((a.start_ts < b.start_ts) || ((a.start_ts == b.start_ts) && (a.cur_spill_time_ms < b.cur_spill_time_ms))
922 SysPoint ts_spill_start = ss.start_ts;
923 SysPoint ts_spill_stop = ss.stop_ts;
924 auto spill_it =
fSpillMap.find(ts_spill_start);
927 std::tie(spill_it, inserted) =
fSpillMap.insert(
928 make_pair(ts_spill_start,
BmnSpillInfo{.start_ts = ts_spill_start, .stop_ts = ts_spill_start}));
929 LOGF(debug,
"spill record inserted %d", inserted);
934 if (info.
stop_ts < ts_spill_stop)
944 LOGF(error,
"Spill map is empty!");
948 auto& total_cntrs =
metadata.SpillCounters();
949 total_cntrs.ResizeTo(
fSpillMap.begin()->second.counters);
953 if (blocks_count == 0)
960 spill_cntrs.cntr_after_err[
i] -= first_ss.counters.cntr_after_err[
i];
961 spill_cntrs.cntr_befor_err[
i] -= first_ss.counters.cntr_befor_err[
i];
962 total_cntrs.cntr_after_err[
i] += spill_cntrs.cntr_after_err[
i];
963 total_cntrs.cntr_befor_err[
i] += spill_cntrs.cntr_befor_err[
i];
965 for (
size_t i_pair = 0; i_pair < spill_cntrs.cntr_input.size(); i_pair++) {
966 auto& spill_p_input = spill_cntrs.cntr_input[i_pair];
967 auto& first_p_input = first_ss.counters.cntr_input[i_pair];
968 auto& spill_p_input_ar = spill_cntrs.cntr_input_after_red[i_pair];
969 auto& first_p_input_ar = first_ss.counters.cntr_input_after_red[i_pair];
970 auto& total_p_input = total_cntrs.cntr_input[i_pair];
971 auto& total_p_input_ar = total_cntrs.cntr_input_after_red[i_pair];
973 spill_p_input.second[
i] -= first_p_input.second[
i];
974 spill_p_input_ar.second[
i] -= first_p_input_ar.second[
i];
975 total_p_input.second[
i] += spill_p_input.second[
i];
976 total_p_input_ar.second[
i] += spill_p_input_ar.second[
i];
983 vector<string> trc_names{
"pBT",
"BT",
"MBT",
"NiT",
"BT&nBUSY",
"CCT1",
"CCT2"};
1005 LOGF(info,
"\n\tTRC TOTAL:");
1006 for (
string& name : trc_names) {
1009 LOGF(info,
"\t icntr %6u %8s", icntr, name.c_str());
1010 LOGF(info,
"\t%8s before %8lu after %8lu ", name.c_str(), total_cntrs.cntr_befor_err[icntr],
1011 total_cntrs.cntr_after_err[icntr]);
1012 LOGF(info,
"\t%8s BUSY input %8lu input_red %8lu ", name.c_str(), total_cntrs.cntr_input[6].second[icntr],
1013 total_cntrs.cntr_input_after_red[6].second[icntr]);
1014 LOGF(info,
"\t%8s NOT_BUSY input %8lu input_red %8lu ", name.c_str(), total_cntrs.cntr_input[7].second[icntr],
1015 total_cntrs.cntr_input_after_red[7].second[icntr]);
1164 const int32_t PadWidth = 3840;
1165 const int32_t PadHeigth = 840;
1166 bool print_trc =
false;
1167 bool print_by_spill =
false;
1168 bool trimScalersByLastEvent =
false;
1174 gStyle->SetOptStat(2211);
1176 unique_ptr<TFile> file = make_unique<TFile>(FileName.data(),
"READ");
1177 if (file->IsOpen() ==
false) {
1178 LOG(error) <<
"Cannot open file " << FileName <<
" !" << endl;
1184 if (rh ==
nullptr) {
1185 LOG(error) <<
"No run header!" << endl;
1188 LOGF(info,
"Run Header content:");
1191 LOGF(info,
"\tPeriod: %u Run: %u", PeriodId, RunId);
1194 LOGF(info,
"\tSTART : %s", RunStartTime.
AsString());
1195 LOGF(info,
"\tFINISH : %s", RunEndTime.
AsString());
1200 vector<string> trc_names{
"pBT",
"BT",
"MBT",
"NiT",
"BT&nBUSY",
"CCT1",
"CCT2"};
1201 auto& total_cntrs =
metadata->SpillCounters();
1203 if (print_by_spill) {
1204 for (
auto& it :
metadata->SpillMap()) {
1209 if (spill_cntrs.cntr_input.size() <= 1) {
1210 printf(
"not enough data");
1213 for (
string& name : trc_names) {
1214 uint16_t icntr = fTrigBitsMap[name];
1215 LOGF(info,
"\t icntr %6u %8s", icntr, name.c_str());
1216 LOGF(info,
"\t%8s before %8llu after %8llu", name.c_str(),
1217 spill_cntrs.cntr_befor_err[icntr], spill_cntrs.cntr_after_err[icntr]);
1218 LOGF(info,
"\t%8s BUSY input %8llu input_red %8llu", name.c_str(),
1219 spill_cntrs.cntr_input[6].second[icntr], spill_cntrs.cntr_input_after_red[6].second[icntr]);
1220 LOGF(info,
"\t%8s NOT_BUSY input %8llu input_red %8llu", name.c_str(),
1221 spill_cntrs.cntr_input[7].second[icntr], spill_cntrs.cntr_input_after_red[7].second[icntr]);
1225 LOGF(info,
"\n\tTRC TOTAL:");
1226 for (
string& name : trc_names) {
1227 uint16_t icntr = fTrigBitsMap[name];
1228 printf(
"\t icntr %6u %8s", icntr, name.c_str());
1229 LOGF(info,
"\t%8s before %8llu after %8llu", name.c_str(), total_cntrs.cntr_befor_err[icntr],
1230 total_cntrs.cntr_after_err[icntr]);
1231 LOGF(info,
"\t%8s BUSY input %8llu input_red %8llu", name.c_str(),
1232 total_cntrs.cntr_input[6].second[icntr], total_cntrs.cntr_input_after_red[6].second[icntr]);
1233 LOGF(info,
"\t%8s NOT_BUSY input %8llu input_red %8llu", name.c_str(),
1234 total_cntrs.cntr_input[7].second[icntr], total_cntrs.cntr_input_after_red[7].second[icntr]);
1238 TTree* tree =
static_cast<TTree*
>(file->Get(
"spill"));
1249 vector<unique_ptr<TH1I>> evt_tr_hist;
1250 size_t trigCount = evt_tr_names.size();
1251 TString name =
"Evt_triggers";
1252 auto can{make_unique<TCanvas>(name, name, PadWidth * 1, PadHeigth * trigCount)};
1253 can->Divide(1, trigCount);
1254 for (
size_t i = 0;
i < trigCount;
i++) {
1256 evt_tr_hist.push_back(make_unique<TH1I>(name, name, 500, 0, (
Double_t)1));
1259 vector<unique_ptr<TH2I>> sup_evt_cnt;
1261 auto canSupEvnts{make_unique<TCanvas>(name, name, PadWidth * 1, PadHeigth * trigCount)};
1262 canSupEvnts->Divide(1, trigCount);
1263 for (
size_t i = 0;
i < trigCount;
i++) {
1264 name =
TString(
"SupressionFactor_vs_EventCount__") +
TString(evt_tr_names[
i]);
1265 sup_evt_cnt.push_back(make_unique<TH2I>(name, name, 500, 0.0, 1.0, 100, 0, 35000));
1268 map<string, uint64_t> runScalers;
1270 for (
Int_t iSpill = 0; iSpill < NSpills; iSpill++) {
1274 for (
auto& sca : sh->
Scalers()) {
1275 LOGF(info,
"MSC %-10s %8lu", sca.first.c_str(), sca.second);
1277 if (
t0raw->GetEntries()) {
1278 LOGF(info,
"T0 time %s",
1280 for (
auto& t0_map_el : rh->
T0Map()) {
1281 const T0MapKey& key = t0_map_el.first;
1282 if (key.first.find(
"BD") == 0)
1284 LOGF(info,
"T0 %-14s.%02u = %7u", key.first.c_str(), key.second, sh->
RawT0Counters()[t0_map_el.second]);
1287 LOGF(info,
"Event spill counters:");
1288 for (
size_t i = 0;
i < trigCount;
i++) {
1289 const string& tr_name = evt_tr_names[
i];
1299 uint64_t tr_cnt = sh->
Scalers()[tr_name];
1300 if (trimScalersByLastEvent)
1302 || (iSpill == NSpills - 1))
1304 if (
msc->GetEntries()) {
1310 uint64_t sum = mscMatrix->
GetCntInRange(tr_name, firstTP, lastTP);
1311 LOGF(info,
"\tMSC SH %-11s = %10lu ;", tr_name.c_str(), tr_cnt);
1312 LOGF(info,
"\tMSC sum %-11s = %10lu ;", tr_name.c_str(), sum);
1316 runScalers[tr_name] += tr_cnt;
1318 Double_t rf = tcc[tr_name].reduction_en ? (tcc[tr_name].reduction_factor + 1) : 1;
1320 Double_t tr_cnt_reduced = tr_cnt / rf;
1321 LOGF(info,
"\tMSC All %-11s = %10lu ; divided by red.factor = %10.2f Denom %1.2f", tr_name.c_str(),
1322 tr_cnt, tr_cnt_reduced, rf);
1326 Double_t fract = (tr_cnt > 0) ? ev_tr_cnt / tr_cnt_reduced : 0;
1327 LOGF(info,
"\tEvent trig cnt = %10lu ; (ev_tr_cnt/cnt_after_red) = %10.3f", ev_tr_cnt, fract);
1328 evt_tr_hist[
i]->Fill(fract);
1332 LOGF(info,
"Evt trigger count Total:");
1333 LOGF(info,
"Total %8lu events", rh->
GetNEvents());
1335 const string& tr_name = el.first;
1336 LOGF(info,
"%-12s %8lu", tr_name.c_str(), rh->
EventTriggerCnt()[tr_name]);
1338 LOGF(info,
"Raw T0 Total:");
1339 for (
auto& t0_map_el : rh->
T0Map()) {
1340 const T0MapKey& key = t0_map_el.first;
1341 if (key.first.find(
"BD") == 0)
1343 LOGF(info,
"T0 %-14s.%02u = %10lu", key.first.c_str(), key.second,
1346 LOGF(info,
"MSC Total:");
1349 LOGF(info,
"Total spill counters:");
1350 for (
auto& tr_name : evt_tr_names) {
1359 uint64_t tr_cnt = runScalers[tr_name];
1360 Double_t rf = tcc[tr_name].reduction_en ? (tcc[tr_name].reduction_factor + 1) : 1;
1363 LOGF(info,
"\tT0 %-14s = %10lu ; after reduction %10.2f", tr_name.c_str(), tr_cnt, tr_cnt_ar);
1365 Double_t fract = ev_tr_cnt / tr_cnt_ar;
1366 LOGF(info,
"\tEvt trig cnt = %10lu ; (ev_tr_cnt/cnt_after_red) = %10.3f", ev_tr_cnt, fract);
1369 for (
size_t i = 0;
i < trigCount;
i++) {
1371 evt_tr_hist[
i]->Draw();
1372 canSupEvnts->cd(
i + 1);
1373 sup_evt_cnt[
i]->Draw(
"colz");
1375 can->SaveAs(
Form(
"run%d_supFactor.png", RunId));
1376 canSupEvnts->SaveAs(
Form(
"run%d_supFactor_EvtCnt.png", RunId));