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(
311 if (array.GetEntries()) {
321 auto sum_ptr_dbl = df_spills_withT0Raw_in_run
324 return (array.GetEntries())
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());
364 size_t msc_entries_cnt_total(0);
365 size_t msc_entries_cnt(0);
367 typedef pair<Long64_t, Int_t> Index_Pair;
368 map<SysPoint, vector<Index_Pair>> mts;
370 vector<pair<SysPoint, size_t>> vts_t0;
374 LOGF(info,
"Start filling timestamp map");
414 vts_t0.push_back(make_pair(dig->
GetTime() - ((
Long64_t)t0raw_shift_av) * 1ns - 1s,
422 for (
Int_t iDig = 0; iDig <
msc->GetEntries(); ++iDig) {
424 mts[dig->
GetTime()].push_back(make_pair(iEntry, iDig));
430 vts_t0.push_back(make_pair(dig->
GetTime() - ((
Long64_t)t0raw_shift_av) * 1ns - 1s,
438 msc_entries_cnt_total = mts.size();
443 LOGF(info,
"Real time %f s, CPU time %f s timestamp map filling", rtime, ctime);
453 LOGF(info,
"***********************************************************");
457 LOGF(warning,
"Spill is outside the run! Skipping!");
462 auto df_events_in_spill = df.
Filter(
466 {
"BmnEventHeader."});
469 UInt_t last_ev_id(0);
478 auto df_events_in_spill_trig_cntr = df_events_in_spill.Filter(
494 {
"BmnEventHeader."});
495 ULong64_t n_events = *(df_events_in_spill_trig_cntr.Count());
498 n_events_run += n_events;
499 LOGF(info,
"Events in the spill %7llu", n_events);
503 if ((spillId == 0) || (spillId ==
fSpillMap.size() - 1)) {
504 spillRangeImposedStart = first_ev_tp;
505 spillRangeImposedStop = last_ev_tp;
507 spillRangeImposedStart = si.
start_ts;
508 spillRangeImposedStop = si.
stop_ts;
519 const string& tr_name = el.first;
520 spillHeader->EventTriggerCnt()[tr_name] = cnt[el.second];
522 LOGF(info,
"Evt_cnt %-11s %7llu", tr_name.c_str(), cnt[el.second]);
527 LOGF(info,
"Real time %f s, CPU time %f s ev cnt calc", rtime, ctime);
530 std::sort(vts_t0.begin(), vts_t0.end(),
531 [](pair<SysPoint, size_t>& a, pair<SysPoint, size_t>& b) { return (a.first < b.first); });
532 vector<pair<SysPoint, size_t>> spillIds_t0;
534 copy_if(begin(vts_t0), end(vts_t0), std::back_inserter(spillIds_t0),
535 [&si](pair<SysPoint, size_t> p) {
return (p.first >= si.
start_ts) && (p.first <= si.
stop_ts); });
539 LOGF(info,
"IDs entries T0:%d", spillIds_t0.size());
540 LOGF(debug,
"Real time %f s, CPU time %f s ids copy T0", rtime, ctime);
542 LOGF(info,
"Start scalers calc");
551 vector<uint64_t> scalerVec(scalers_ar_size, 0);
555 auto df_spill = df_spills.
Filter(
568 uint32_t missing_hits = 0;
569 map<SysPoint, vector<uint8_t>> mts9;
578 uint8_t index = index_it->second;
580 vector<uint8_t>& values = dig->
GetValues();
582 for (
size_t iTime = 0; iTime < dig->
GetNVals(); iTime++) {
585 auto it = mts9.find(time);
586 if (it == mts9.end()) {
587 vector<uint8_t> tarr(scalers_ar_size + 1, 0);
588 tarr[index] = values[iTime];
589 tarr[scalers_ar_size] = excs[iTime];
590 mts9.insert(make_pair(time, move(tarr)));
592 vector<uint8_t>& tarr = it->second;
593 tarr[index] += values[iTime];
594 tarr[scalers_ar_size] = excs[iTime];
601 auto itLower = mts9.lower_bound(spillRangeImposedStart);
602 auto itUpper = mts9.upper_bound(spillRangeImposedStop);
603 size_t spillTimesCount = std::distance(itLower, itUpper);
605 msc_entries_cnt += spillTimesCount;
606 msc_entries_cnt_total += mts9.size();
607 LOGF(info,
"Spill times count %lld", spillTimesCount);
615 boost::dynamic_bitset<> bitVecSpill(spillTimesCount,
false);
616 boost::dynamic_bitset<> bitVecBusy(spillTimesCount,
false);
618 for (
auto itTimes = itLower; itTimes != itUpper; itTimes++) {
619 auto& time = itTimes->first;
620 vector<uint8_t>& vals = itTimes->second;
622 msc_matrix->
SetTime(i_record, time);
623 uint8_t ext_cond = vals[scalers_ar_size];
628 for (uint16_t iScaler = 0; iScaler < scalers_ar_size; iScaler++) {
629 if (vals[iScaler] == 0)
631 msc_matrix->
SetCount(i_record, iScaler, vals[iScaler]);
636 scalerVec[iScaler] += vals[iScaler];
637 LOGF(debug,
"el %8llu %2lu count %3u sp %u busy %u GC", i_record, iScaler,
645 if (i_record > spillTimesCount)
646 LOGF(error,
"\n\t ERROR!!! irec %lu spillTimesCount %lu\n", i_record, spillTimesCount);
650 auto itLower = mts.lower_bound(spillRangeImposedStart);
651 auto itUpper = mts.upper_bound(spillRangeImposedStop);
652 Long64_t spillEntriesCumulativeSize{0};
653 size_t spillTimesCount = std::distance(itLower, itUpper);
655 for (
auto itTimes = itLower; itTimes != itUpper; itTimes++) {
656 vector<Index_Pair>& index_vec = itTimes->second;
657 spillEntriesCumulativeSize += index_vec.size();
660 msc_entries_cnt += spillTimesCount;
661 LOGF(info,
"entriesCumulativeSize %lld", spillEntriesCumulativeSize);
662 LOGF(info,
"Spill times count %lld", spillTimesCount);
673 boost::dynamic_bitset<> bitVecSpill(spillTimesCount,
false);
674 boost::dynamic_bitset<> bitVecBusy(spillTimesCount,
false);
675 for (
auto itTimes = itLower; itTimes != itUpper; itTimes++) {
676 auto& time = itTimes->first;
678 msc_matrix->
SetTime(i_record, time);
679 vector<Index_Pair>& index_vec = itTimes->second;
681 LOGF(debug2,
"index_vec.size() %8llu", index_vec.size());
682 if (index_vec.size() > 1)
683 LOGF(debug,
"new time");
684 for (Index_Pair& index_pair : index_vec) {
685 Long64_t& iEntry = index_pair.first;
686 Int_t& iDig = index_pair.second;
688 if (iDig >=
msc->GetEntries()) {
689 LOGF(error,
"\n\t ERROR!!! iDig %d msc->GetEntries() %d\n", iDig,
msc->GetEntries());
693 LOGF(debug2,
"iEntry %7d iDig %3d el %8llu ", iEntry, iDig, i_record);
694 if (index_vec.size() > 1) {
695 LOGF(debug,
"dig->IsSpill() %d", dig->
IsSpill());
696 LOGF(debug,
"dig->IsBusy() %d", dig->
IsBusy());
698 bitVecSpill[i_record] = dig->
IsSpill();
699 bitVecBusy[i_record] = dig->
IsBusy();
713 uint16_t iScaler = it->second;
716 msc_matrix->
SetCount(i_record, iScaler, val);
718 if (index_vec.size() > 1)
719 LOGF(debug,
"el %8llu %2lu ser 0x%8X = %u sp %u busy %u", i_record, iScaler,
727 scalerVec[iScaler] += val;
732 if (i_record > spillTimesCount)
733 LOGF(error,
"\n\t ERROR!!! irec %lu spillTimesCount %lu\n", i_record, spillTimesCount);
771 for (
auto& p : spillIds_t0) {
776 for (
int i = 0;
i < scalers_ar_size;
i++)
786 LOGF(info,
"Real time %f s, CPU time %f s Scalers calc", rtime, ctime);
791 uint64_t& val = scalerVec[iSc];
793 LOGF(info,
"MSC %-14s %10llu", name.c_str(), val);
800 LOGF(error,
"More than 1 T0 in the spill %lu ! %d records found",
spillHeader->GetSpillId(),
803 LOGF(error,
"No T0 in the spill %lu !",
spillHeader->GetSpillId());
805 LOGF(info,
"Searching for T0 in the storage");
809 LOGF(info,
"Found at timestamp %s entry %u", (itLower->first).AsString(), itLower->second);
818 LOGF(error,
"%s timestamp not found in the T0 storage!", t0StopTS.
AsString());
835 LOGF(info,
"Evt trigger count Total:");
838 const string& tr_name = el.first;
839 LOGF(info,
"%-12s %8llu", tr_name.c_str(),
digiRunHeader->EventTriggerCnt()[tr_name]);
841 LOGF(info,
"Raw T0 Total:");
843 const T0MapKey& key = t0_map_el.first;
844 if (key.first.find(
"BD") == 0)
846 LOGF(info,
"T0 %-14s.%02u = %10llu", key.first.c_str(), key.second,
847 digiRunHeader->GetRawT0Counter(key.first.c_str(), key.second));
849 LOGF(info,
"MSC Total:");
851 delete fInTreeSpills;
910 return ((a.start_ts < b.start_ts) || ((a.start_ts == b.start_ts) && (a.cur_spill_time_ms < b.cur_spill_time_ms))
920 SysPoint ts_spill_start = ss.start_ts;
921 SysPoint ts_spill_stop = ss.stop_ts;
922 auto spill_it =
fSpillMap.find(ts_spill_start);
925 std::tie(spill_it, inserted) =
fSpillMap.insert(
926 make_pair(ts_spill_start,
BmnSpillInfo{.start_ts = ts_spill_start, .stop_ts = ts_spill_start}));
927 LOGF(debug,
"spill record inserted %d", inserted);
932 if (info.
stop_ts < ts_spill_stop)
942 LOGF(error,
"Spill map is empty!");
946 auto& total_cntrs =
metadata.SpillCounters();
947 total_cntrs.ResizeTo(
fSpillMap.begin()->second.counters);
951 if (blocks_count == 0)
958 spill_cntrs.cntr_after_err[
i] -= first_ss.counters.cntr_after_err[
i];
959 spill_cntrs.cntr_befor_err[
i] -= first_ss.counters.cntr_befor_err[
i];
960 total_cntrs.cntr_after_err[
i] += spill_cntrs.cntr_after_err[
i];
961 total_cntrs.cntr_befor_err[
i] += spill_cntrs.cntr_befor_err[
i];
963 for (
size_t i_pair = 0; i_pair < spill_cntrs.cntr_input.size(); i_pair++) {
964 auto& spill_p_input = spill_cntrs.cntr_input[i_pair];
965 auto& first_p_input = first_ss.counters.cntr_input[i_pair];
966 auto& spill_p_input_ar = spill_cntrs.cntr_input_after_red[i_pair];
967 auto& first_p_input_ar = first_ss.counters.cntr_input_after_red[i_pair];
968 auto& total_p_input = total_cntrs.cntr_input[i_pair];
969 auto& total_p_input_ar = total_cntrs.cntr_input_after_red[i_pair];
971 spill_p_input.second[
i] -= first_p_input.second[
i];
972 spill_p_input_ar.second[
i] -= first_p_input_ar.second[
i];
973 total_p_input.second[
i] += spill_p_input.second[
i];
974 total_p_input_ar.second[
i] += spill_p_input_ar.second[
i];
981 vector<string> trc_names{
"pBT",
"BT",
"MBT",
"NiT",
"BT&nBUSY",
"CCT1",
"CCT2"};
1003 LOGF(info,
"\n\tTRC TOTAL:");
1004 for (
string& name : trc_names) {
1007 LOGF(info,
"\t icntr %6u %8s", icntr, name.c_str());
1008 LOGF(info,
"\t%8s before %8lu after %8lu ", name.c_str(), total_cntrs.cntr_befor_err[icntr],
1009 total_cntrs.cntr_after_err[icntr]);
1010 LOGF(info,
"\t%8s BUSY input %8lu input_red %8lu ", name.c_str(), total_cntrs.cntr_input[6].second[icntr],
1011 total_cntrs.cntr_input_after_red[6].second[icntr]);
1012 LOGF(info,
"\t%8s NOT_BUSY input %8lu input_red %8lu ", name.c_str(), total_cntrs.cntr_input[7].second[icntr],
1013 total_cntrs.cntr_input_after_red[7].second[icntr]);
1162 const int32_t PadWidth = 3840;
1163 const int32_t PadHeigth = 840;
1164 bool print_trc =
false;
1165 bool print_by_spill =
false;
1166 bool trimScalersByLastEvent =
false;
1172 gStyle->SetOptStat(2211);
1174 unique_ptr<TFile> file = make_unique<TFile>(FileName.data(),
"READ");
1175 if (file->IsOpen() ==
false) {
1176 LOG(error) <<
"Cannot open file " << FileName <<
" !" << endl;
1182 if (rh ==
nullptr) {
1183 LOG(error) <<
"No run header!" << endl;
1186 LOGF(info,
"Run Header content:");
1189 LOGF(info,
"\tPeriod: %u Run: %u", PeriodId, RunId);
1192 LOGF(info,
"\tSTART : %s", RunStartTime.
AsString());
1193 LOGF(info,
"\tFINISH : %s", RunEndTime.
AsString());
1198 vector<string> trc_names{
"pBT",
"BT",
"MBT",
"NiT",
"BT&nBUSY",
"CCT1",
"CCT2"};
1199 auto& total_cntrs =
metadata->SpillCounters();
1201 if (print_by_spill) {
1202 for (
auto& it :
metadata->SpillMap()) {
1207 if (spill_cntrs.cntr_input.size() <= 1) {
1208 printf(
"not enough data");
1211 for (
string& name : trc_names) {
1212 uint16_t icntr = fTrigBitsMap[name];
1213 LOGF(info,
"\t icntr %6u %8s", icntr, name.c_str());
1214 LOGF(info,
"\t%8s before %8llu after %8llu", name.c_str(),
1215 spill_cntrs.cntr_befor_err[icntr], spill_cntrs.cntr_after_err[icntr]);
1216 LOGF(info,
"\t%8s BUSY input %8llu input_red %8llu", name.c_str(),
1217 spill_cntrs.cntr_input[6].second[icntr], spill_cntrs.cntr_input_after_red[6].second[icntr]);
1218 LOGF(info,
"\t%8s NOT_BUSY input %8llu input_red %8llu", name.c_str(),
1219 spill_cntrs.cntr_input[7].second[icntr], spill_cntrs.cntr_input_after_red[7].second[icntr]);
1223 LOGF(info,
"\n\tTRC TOTAL:");
1224 for (
string& name : trc_names) {
1225 uint16_t icntr = fTrigBitsMap[name];
1226 printf(
"\t icntr %6u %8s", icntr, name.c_str());
1227 LOGF(info,
"\t%8s before %8llu after %8llu", name.c_str(), total_cntrs.cntr_befor_err[icntr],
1228 total_cntrs.cntr_after_err[icntr]);
1229 LOGF(info,
"\t%8s BUSY input %8llu input_red %8llu", name.c_str(),
1230 total_cntrs.cntr_input[6].second[icntr], total_cntrs.cntr_input_after_red[6].second[icntr]);
1231 LOGF(info,
"\t%8s NOT_BUSY input %8llu input_red %8llu", name.c_str(),
1232 total_cntrs.cntr_input[7].second[icntr], total_cntrs.cntr_input_after_red[7].second[icntr]);
1236 TTree* tree =
static_cast<TTree*
>(file->Get(
"spill"));
1247 vector<unique_ptr<TH1I>> evt_tr_hist;
1248 size_t trigCount = evt_tr_names.size();
1249 TString name =
"Evt_triggers";
1250 auto can{make_unique<TCanvas>(name, name, PadWidth * 1, PadHeigth * trigCount)};
1251 can->Divide(1, trigCount);
1252 for (
size_t i = 0;
i < trigCount;
i++) {
1254 evt_tr_hist.push_back(make_unique<TH1I>(name, name, 500, 0, (
Double_t)1));
1257 vector<unique_ptr<TH2I>> sup_evt_cnt;
1259 auto canSupEvnts{make_unique<TCanvas>(name, name, PadWidth * 1, PadHeigth * trigCount)};
1260 canSupEvnts->Divide(1, trigCount);
1261 for (
size_t i = 0;
i < trigCount;
i++) {
1262 name =
TString(
"SupressionFactor_vs_EventCount__") +
TString(evt_tr_names[
i]);
1263 sup_evt_cnt.push_back(make_unique<TH2I>(name, name, 500, 0.0, 1.0, 100, 0, 35000));
1266 map<string, uint64_t> runScalers;
1268 for (
Int_t iSpill = 0; iSpill < NSpills; iSpill++) {
1272 for (
auto& sca : sh->
Scalers()) {
1273 LOGF(info,
"MSC %-10s %8lu", sca.first.c_str(), sca.second);
1275 if (
t0raw->GetEntries()) {
1276 LOGF(info,
"T0 time %s",
1278 for (
auto& t0_map_el : rh->
T0Map()) {
1279 const T0MapKey& key = t0_map_el.first;
1280 if (key.first.find(
"BD") == 0)
1282 LOGF(info,
"T0 %-14s.%02u = %7u", key.first.c_str(), key.second, sh->
RawT0Counters()[t0_map_el.second]);
1285 LOGF(info,
"Event spill counters:");
1286 for (
size_t i = 0;
i < trigCount;
i++) {
1287 const string& tr_name = evt_tr_names[
i];
1297 uint64_t tr_cnt = sh->
Scalers()[tr_name];
1298 if (trimScalersByLastEvent)
1300 || (iSpill == NSpills - 1))
1302 if (
msc->GetEntries()) {
1308 uint64_t sum = mscMatrix->
GetCntInRange(tr_name, firstTP, lastTP);
1309 LOGF(info,
"\tMSC SH %-11s = %10lu ;", tr_name.c_str(), tr_cnt);
1310 LOGF(info,
"\tMSC sum %-11s = %10lu ;", tr_name.c_str(), sum);
1314 runScalers[tr_name] += tr_cnt;
1316 Double_t rf = tcc[tr_name].reduction_en ? (tcc[tr_name].reduction_factor + 1) : 1;
1318 Double_t tr_cnt_reduced = tr_cnt / rf;
1319 LOGF(info,
"\tMSC All %-11s = %10lu ; divided by red.factor = %10.2f Denom %1.2f", tr_name.c_str(),
1320 tr_cnt, tr_cnt_reduced, rf);
1324 Double_t fract = (tr_cnt > 0) ? ev_tr_cnt / tr_cnt_reduced : 0;
1325 LOGF(info,
"\tEvent trig cnt = %10lu ; (ev_tr_cnt/cnt_after_red) = %10.3f", ev_tr_cnt, fract);
1326 evt_tr_hist[
i]->Fill(fract);
1330 LOGF(info,
"Evt trigger count Total:");
1331 LOGF(info,
"Total %8lu events", rh->
GetNEvents());
1333 const string& tr_name = el.first;
1334 LOGF(info,
"%-12s %8lu", tr_name.c_str(), rh->
EventTriggerCnt()[tr_name]);
1336 LOGF(info,
"Raw T0 Total:");
1337 for (
auto& t0_map_el : rh->
T0Map()) {
1338 const T0MapKey& key = t0_map_el.first;
1339 if (key.first.find(
"BD") == 0)
1341 LOGF(info,
"T0 %-14s.%02u = %10lu", key.first.c_str(), key.second,
1344 LOGF(info,
"MSC Total:");
1347 LOGF(info,
"Total spill counters:");
1348 for (
auto& tr_name : evt_tr_names) {
1357 uint64_t tr_cnt = runScalers[tr_name];
1358 Double_t rf = tcc[tr_name].reduction_en ? (tcc[tr_name].reduction_factor + 1) : 1;
1361 LOGF(info,
"\tT0 %-14s = %10lu ; after reduction %10.2f", tr_name.c_str(), tr_cnt, tr_cnt_ar);
1363 Double_t fract = ev_tr_cnt / tr_cnt_ar;
1364 LOGF(info,
"\tEvt trig cnt = %10lu ; (ev_tr_cnt/cnt_after_red) = %10.3f", ev_tr_cnt, fract);
1367 for (
size_t i = 0;
i < trigCount;
i++) {
1369 evt_tr_hist[
i]->Draw();
1370 canSupEvnts->cd(
i + 1);
1371 sup_evt_cnt[
i]->Draw(
"colz");
1373 can->SaveAs(
Form(
"run%d_supFactor.png", RunId));
1374 canSupEvnts->SaveAs(
Form(
"run%d_supFactor_EvtCnt.png", RunId));