BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnMetadataDecoder.cxx
Go to the documentation of this file.
2// STL
3#include <chrono>
4#include <filesystem>
5#include <iostream>
6#include <regex>
7// Boost
8#include <boost/dynamic_bitset.hpp>
9// ROOT
10#include "TStopwatch.h"
11#include "TSystem.h"
12
14#include <ROOT/RDataFrame.hxx>
15// FairRoot
16#include "FairLogger.h"
17// BmnRoot
18#include "BmnADCDigit.h"
19#include "BmnConverterTools.h"
20#include "BmnGemStripDigit.h"
21#include "BmnHRBDigit.h"
22#include "BmnMSCDigit.h"
23#include "BmnMSCZSDigit.h"
24#include "BmnRawDataDecoder.h"
25#include "BmnSyncDigit.h"
26#include "BmnTDCDigit.h"
27#include "BmnTQDCADCDigit.h"
28#include "DigiRunHeader.h"
29#include "TangoData.h"
30#include "UniDetectorParameter.h"
31#include "UniRawFile.h"
32#include "UniRun.h"
33
34namespace fs = std::filesystem;
35using namespace std::chrono;
36
37BmnMetadataDecoder::BmnMetadataDecoder(vector<string> files, string outfile, ULong_t period, BmnSetup setup)
38 : fPeriodId(period)
39 , fTime_s(0)
40 , fTime_ns(0)
43 , fRawTree(nullptr)
44 , fDigiTree(nullptr)
45 , fDigiFileNames(files)
46 , fOutFileName(outfile)
47 , fDigiRunHdrName("DigiRunHeader")
48 , fRawRunHdrName("RawRunHeader")
49 , fMetadataName("RawRunMetadata")
50 , fDigiFileOut(nullptr)
51 , fCalibFile(nullptr)
52 , msc(nullptr)
53 , t0raw(nullptr)
54 , msc_copy(nullptr)
55 , t0_copy(nullptr)
56 , inEventHeader(nullptr)
57 , spillHeader(nullptr)
58 //, metadata(make_unique<BmnMetadataRaw>())
59 , fBmnSetup(setup)
60 , fPeriodSetupExt(Form("%d%s.txt", fPeriodId, ((fBmnSetup == kBMNSETUP) ? "" : "_SRC")))
61 //, fTrigMapper(make_unique(TString("Trig_map_Run") + fPeriodSetupExt))
62 // , fMSCMapper(nullptr)
63 , fT0RawStorageTsMap(nullptr)
64 , fT0RawStorageArr(nullptr)
65{
66 TTree::SetMaxTreeSize(1'000'000'000'000); // 932 GB
67 if (fOutFileName.length() == 0)
68 fOutFileName = string(Form("bmn_run%d_meta.root", fRunId));
69}
70
75
77{
78 fDigiDir = DirName;
79 // string re_str(Form(".*mpd_run_Top_%u(_ev\\d+_p\\d+)\\.root", fRunId));
80 string re_digi_str(Form(".*%u(_ev\\d+_p\\d+)[^\\/]*\\.root", fRunId));
81 string re_data_str("([^\\/]+).data");
82 // TPRegexp re_dig(re_str);
83 regex re_dig(re_digi_str);
84 regex re_data(re_data_str);
85 // Check if the path exists and is a directory
86 if (fs::exists(fDigiDir) && fs::is_directory(fDigiDir)) {
87 std::cout << "Target files in a directory: " << fDigiDir << std::endl;
88 // Get file names from the DB
91 if (run) {
92 TObjArray* arrNames = run->GetRawFiles();
93 for (const auto& j : *arrNames) {
94 UniRawFile* pRawFile = (UniRawFile*)j;
95 TString strFilePath = pRawFile->GetFilePath();
96 int32_t lastSlash = strFilePath.Last('/');
97 TString strFileName = (lastSlash == TString::kNPOS)
98 ? strFilePath
99 : TString(strFilePath(lastSlash + 1, strFilePath.Length()));
100 if (strFileName.Length() == 0)
101 continue;
102 if (regex_match(strFileName.Data(), re_data)) {
103 string name_digi = regex_replace(strFileName.Data(), re_data, "$1");
104 fDigiFileNames.push_back(fDigiDir + "/" + name_digi + ".root");
105 } else
106 continue;
107 }
108 delete run;
109 }
110 } else {
111 // Iterate through the directory
112 for (const auto& entry : fs::directory_iterator(fDigiDir)) {
113 string fileName = entry.path();
114 if (regex_match(fileName, re_dig)) {
115 // if (re_dig.MatchB(fileName)) {
116 std::cout << entry.path().filename() << std::endl;
117 fDigiFileNames.push_back(fileName.data());
118 }
119 }
120 }
121 if (fDigiFileNames.size() == 0) {
122 LOGF(error, "No valid files in te directory!");
123 return kBMNERROR;
124 }
125 return kBMNSUCCESS;
126 } else {
127 LOGF(error, "Wrong path.");
128 return kBMNERROR;
129 }
130}
131
133{
134 fTarDir = DirName;
135 // string re_str(Form(".*mpd_run_Top_%u(_ev\\d+_p\\d+)\\.root", fRunId));
136 string re_str(Form(".*mpd_run_Top_%u(_ev\\d+_p\\d+)\\.root.tar", fRunId));
137 TPRegexp re_tar(re_str);
138 // Check if the path exists and is a directory
139 if (fs::exists(fTarDir) && fs::is_directory(fTarDir)) {
140 std::cout << "Target files in the directory: " << fTarDir << std::endl;
141 // Iterate through the directory
142 for (const auto& entry : fs::directory_iterator(fTarDir)) {
143 string fileName = entry.path();
144 if (re_tar.MatchB(fileName)) {
145 std::cout << entry.path().filename() << std::endl;
146 fTarFileNames.push_back(fileName.data());
147 }
148 }
149 return kBMNSUCCESS;
150 } else {
151 LOGF(error, "Wrong path.");
152 return kBMNERROR;
153 }
154}
155
157{
158 // // try get run interval from DB
159 // if (!get_run_interval_from_file) {
160 // UniRun* pRun = UniRun::GetRun(fPeriodId, fRunId);
161 // if (!pRun) {
162 // get_run_interval_from_file = true;
163 // } else {
164 // TDatime fRunStartDate = pRun->GetStartDatetime();
165 // TDatime* fRunEndDate = pRun->GetEndDatetime();
166 // fRunStartTime = BmnFunctionSet::TDatime2GMT(fRunStartDate) - 3h; // crutch for zone shift
167 // if (fRunEndDate)
168 // fRunEndTime = BmnFunctionSet::TDatime2GMT(*fRunEndDate) - 3h;
169 // else
170 // get_run_interval_from_file = true;
171 // // LOGF(info, "Set Run from DB:\n\tstart ts: %s\n\tstop ts: %s",
172 // // fRunStartDate.AsString(), fRunEndDate->AsString());
173 // LOGF(info, "Set Run from DB:\n\tstart ts: %s\n\tstop ts: %s",
174 // BmnFunctionSet::TimePoint2String(fRunStartTime), BmnFunctionSet::TimePoint2String(fRunEndTime));
175 // delete pRun;
176 // }
177 // }
178 // get status blocks, maps and run interval from digi files
179 bool maps_recreate = true;
180 bool maps_set = false;
181 bool tr_conf_set = false;
182 BmnTrigConfig tc;
183 for (string& name : fDigiFileNames) {
184 unique_ptr<TFile> dig_in{TFile::Open(name.c_str(), "READ")};
185 if (dig_in->IsOpen() == false) {
186 LOGF(error, "\n!!!!\ncannot open file %s !\n", name.c_str());
187 // return kBMNERROR;
188 } else {
189 LOGF(info, "Starting to decode file %s", name.c_str());
190 digiRunHeader.reset(static_cast<DigiRunHeader*>(dig_in->Get(fDigiRunHdrName)));
191 if (!maps_set) {
192 fRawT0Map = digiRunHeader->T0Map();
193 fTrcBitMap = digiRunHeader->GetTrcBitMap();
194 fScalersMap = digiRunHeader->GetScalerMap();
196 fRunStartTime = digiRunHeader->GetRunStartTP();
197 fRunEndTime = digiRunHeader->GetRunEndTP();
198 LOGF(debug, "Set Run:\n\tstart ts: %s\n\tstop ts: %s",
201 }
202 maps_set = true;
203 } else {
205 if (fRunStartTime > digiRunHeader->GetRunStartTP())
206 fRunStartTime = digiRunHeader->GetRunStartTP();
207 if (fRunEndTime < digiRunHeader->GetRunEndTP())
208 fRunEndTime = digiRunHeader->GetRunEndTP();
209 LOGF(debug, "Upd Run:\n\tstart ts: %s\n\tstop ts: %s",
212 }
213 }
214 if (!tr_conf_set) {
215 if (digiRunHeader->GetTrigConfig().TrigChannelConfig().size() > 0) {
216 tc = digiRunHeader->GetTrigConfig();
217 tr_conf_set = true;
218 }
219 }
220 unique_ptr<BmnMetadataRaw> meta_f{static_cast<BmnMetadataRaw*>(dig_in->Get(fMetadataName))};
221 if (meta_f.get() == nullptr) {
222 LOGF(warning, "No metadata found in the %s!", name.c_str());
223 continue;
224 }
225 auto& src = meta_f->SpillStatusVec();
226 auto& dst = metadata.SpillStatusVec();
227 LOGF(debug, "vec size %u", src.size());
228 dst.reserve(dst.size() + src.size());
229 std::move(std::begin(src), std::end(src), std::back_inserter(dst));
230 }
231 }
232 LOGF(info, "Set Run:\n\tstart ts: %s\n\tstop ts: %s", BmnFunctionSet::TimePoint2String(fRunStartTime),
234 if (maps_recreate) {
235 TString PeriodSetupExt = Form("%d%s.txt", fPeriodId, ((fBmnSetup == kBMNSETUP) ? "" : "_SRC"));
236 fTrigMapper = make_unique<BmnTrigRaw2Digit>(TString("Trig_PlaceMap_Run") + PeriodSetupExt,
237 TString("Trig_map_Run") + PeriodSetupExt, nullptr);
238 digiRunHeader->T0Map() = fTrigMapper->T0Map();
239 digiRunHeader->GetTrcBitMap() = fTrigMapper->GetTrcMap();
240 digiRunHeader->GetScalerMap() = fTrigMapper->GetScalerMap();
241 scalers2name_map = fTrigMapper->GetScaler2NameMap();
242 scalers2index_map = fTrigMapper->GetScaler2IdxMap();
243 trcIdx2scalerIdx = fTrigMapper->GetTrcIdx2ScalerIdxMap();
244 scalers_name2index_map = fTrigMapper->GetScalerName2IdxMap();
245 scalers_index2name_map = fTrigMapper->GetScalerIdx2NameMap();
246 } else {
247 digiRunHeader->T0Map() = fRawT0Map;
248 digiRunHeader->GetTrcBitMap() = fTrcBitMap;
249 digiRunHeader->GetScalerMap() = fScalersMap;
250 }
251 digiRunHeader->SetRunStartTP(fRunStartTime);
252 digiRunHeader->SetRunEndTP(fRunEndTime);
253 digiRunHeader->SetTrigConfig(tc);
254}
255
257
259{
260 TStopwatch timer;
261 Double_t rtime;
262 Double_t ctime;
263 LoadT0Storage(); // load T0 raw storage
264 for (auto& mapel : fSpillMap) {
265 BmnSpillInfo& si = mapel.second;
266 if (si.stop_ts - si.start_ts < 1ms) {
267 si.stop_ts = si.start_ts + ((fPeriodId > 8) ? 8s : 5s);
268 LOGF(warning,
269 "LOST SPILL END! Making fake one!\n"
270 "Spill:\n\tstart ts: %s\n\tstop ts: %s",
272 }
273 }
274 metadata.SpillMap() = fSpillMap;
275 metadata.RawT0Map() = fRawT0Map;
276 metadata.TrcMap() = fTrcBitMap;
277 metadata.ScalersMap() = fScalersMap;
278 // /** Create scaler maps for name <--> (serial,channel) correspondence and navigation in the result matrix */
279 // // map: <serial, channel> -> name
280 // SerCh2Name scalers2name_map;
281 // // map: <serial, channel> -> index in the list (inside spillHeader->ScalersVec(), and MSC matrix)
282 // map<std::pair<uint32_t, uint16_t>, uint16_t> scalers2index_map;
283 // map<uint16_t, uint16_t> trcIdx2scalerIdx;
284 // // map: name -> index in the list
285 // NameChMap scalers_name2index_map;
286 // ChNameMap scalers_index2name_map;
287 // uint16_t scalers_ar_size(0); // MSC list size
288 // for (auto& map_el : fScalersMap) {
289 // const string& name = map_el.first;
290 // scalers2name_map.insert(make_pair(map_el.second, name));
291 // scalers_name2index_map.insert(make_pair(name, scalers_ar_size));
292 // scalers_index2name_map.insert(make_pair(scalers_ar_size, name));
293 // scalers2index_map.insert(make_pair(map_el.second, scalers_ar_size));
294 // auto it = fTrcBitMap.find(name);
295 // if (it != fTrcBitMap.end()) {
296 // trcIdx2scalerIdx.insert(make_pair(it->second, scalers_ar_size));
297 // }
298 // scalers_ar_size++;
299 // }
300 uint16_t scalers_ar_size = scalers_index2name_map.size(); // MSC list size
301 digiRunHeader->ScalersVec().resize(scalers_ar_size, 0);
302 LOGF(info, "scalers_ar_size %d", scalers_ar_size);
303 /** Start reading */
304 // ROOT::EnableImplicitMT();
305 RDataFrame df{"bmndata", fDigiFileNames};
306 RDataFrame df_spills{"spill", fDigiFileNames};
307 // calc the average time shift of raw T0 digits
308 timer.Start();
309 auto df_spills_withT0Raw_in_run = df_spills.Filter(
310 [&](TClonesArray& array) {
311 if (array.GetEntries()) {
312 BmnT0Raw* t0raw_dig = static_cast<BmnT0Raw*>(array.At(0));
313 LOGF(info, "T0 raw time %s tsle %10.2f ", BmnFunctionSet::TimePoint2String(t0raw_dig->GetTime()),
314 t0raw_dig->GetTimeSinceLastEvNs());
315 return ((t0raw_dig->GetTimeSinceLastEv() < duration_cast<nanoseconds>(24h))
316 && (t0raw_dig->GetTimeSinceLastEv() > duration_cast<nanoseconds>(-24h)));
317 } else
318 return false;
319 },
320 {"T0Raw"});
321 auto sum_ptr_dbl = df_spills_withT0Raw_in_run
322 .Define("sls",
323 [](TClonesArray& array) {
324 return (array.GetEntries())
325 ? static_cast<BmnT0Raw*>(array.At(0))->GetTimeSinceLastEvNs()
326 : (Double_t)0.0;
327 },
328 {"T0Raw"})
329 .Sum("sls");
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));
333 // printf("sum : %f\n", sum);
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);
336 timer.Stop();
337 rtime = timer.RealTime();
338 ctime = timer.CpuTime();
339 LOGF(info, "Real time %f s, CPU time %f s sum T0Raw timeshifts", rtime, ctime);
340 // TRaversing spill chain by hands and rearranging digits by spill time intervals
341 TChain* fInTreeSpills = new TChain("spill");
342 TChain* fInTreeEvents = new TChain("bmndata");
343 for (string& name : fDigiFileNames) {
344 LOGF(debug, "Filling tchain with a file %s", name.c_str());
345 fInTreeSpills->Add(name.c_str());
346 fInTreeEvents->Add(name.c_str());
347 }
348
349 fInTreeSpills->GetListOfBranches(); // ROOT magic for SetBranchAddress to work
350 fInTreeSpills->SetBranchAddress("MSC", &msc);
351 fInTreeSpills->SetBranchAddress("T0Raw", &t0raw);
352 fInTreeEvents->SetBranchAddress("BmnEventHeader.", &inEventHeader);
353 fDigiFileOut = new TFile(fOutFileName.data(), "recreate", "");
354 fDigiTreeSpills = new TTree("spill", "spill");
356 fDigiTreeSpills->Branch("BmnSpillHeader.", &spillHeader);
357 // fMSCMapper = new BmnMscRaw2Digit(fPeriodId, fRunId, fMSCMapFileName, fInTreeSpills, fDigiTreeSpills);
358 // msc_copy = new TClonesArray(msc->GetClass());
360 fDigiTreeSpills->Branch("MSC", &msc_copy);
361 t0_copy = new TClonesArray(t0raw->GetClass());
362 fDigiTreeSpills->Branch("T0Raw", &t0_copy);
363
364 size_t msc_entries_cnt_total(0); // all MSC times (to check presence of MSC outside spills)
365 size_t msc_entries_cnt(0); // MSC entries inside spills
366 // make map (time_point -> (i-tree entry,i-digit)) to sort and rearrange MSC by time
367 typedef pair<Long64_t, Int_t> Index_Pair; // (i-tree entry,i-digit)
368 map<SysPoint, vector<Index_Pair>> mts; // for period 8
369 // map<SysPoint, size_t> time2times_map_entry;
370 vector<pair<SysPoint, size_t>> vts_t0; // for period 8
371
372 // map<SysPoint, vector<uint8_t>> mts9; // for period 9
373
374 LOGF(info, "Start filling timestamp map");
375 timer.Start();
376 if (fPeriodId > 8) {
377 for (Long64_t iEntry = 0; iEntry < fInTreeSpills->GetEntries(); ++iEntry) {
378 fInTreeSpills->GetEntry(iEntry);
379 /** General time map (high memory usage) */
380 //// df_spills.Foreach(
381 //// [&](TClonesArray& msc_in) {
382 //// for (Int_t iDig = 0; iDig < msc_in.GetEntries(); ++iDig) {
383 //// BmnMSCZSDigit<uint8_t>* dig = static_cast<BmnMSCZSDigit<uint8_t>*>(msc_in.At(iDig));
384 // for (Int_t iDig = 0; iDig < msc->GetEntries(); ++iDig) {
385 // BmnMSCZSDigit<uint8_t>* dig = static_cast<BmnMSCZSDigit<uint8_t>*>(msc->At(iDig));
386 // auto index_it = scalers2index_map.find(make_pair(dig->GetSerial(), dig->GetChannel()));
387 // if (index_it == scalers2index_map.end())
388 // continue;
389 // uint8_t index = index_it->second;
390 // vector<SysPoint>& times = dig->GetTimes();
391 // vector<uint8_t>& values = dig->GetValues();
392 // vector<uint8_t>& excs = dig->GetExtCond();
393 // for (size_t iTime= 0; iTime< dig->GetNVals(); iTime++){
394 // SysPoint& time = times[iTime];
395 // auto it = mts9.find(time);
396 // if (it == mts9.end()){
397 // vector<uint8_t> tarr(scalers_ar_size+1, 0); // scalers + ext conditions
398 // tarr[index] = values[iTime];
399 // tarr[scalers_ar_size] = excs[iTime];
400 // mts9.insert(make_pair(time, move(tarr)));
401 // } else{
402 // vector<uint8_t>& tarr = it->second;
403 // tarr[index] += values[iTime];
404 // tarr[scalers_ar_size] = excs[iTime];
405 // }
406 // }
407 // }
408 //// },
409 //// {"MSC"});
410
411 Int_t ne_t0 = t0raw->GetEntries();
412 if (ne_t0 > 0) {
413 BmnT0Raw* dig = static_cast<BmnT0Raw*>(t0raw->At(0));
414 vts_t0.push_back(make_pair(dig->GetTime() - ((Long64_t)t0raw_shift_av) * 1ns - 1s,
415 iEntry)); // crutch to fit rough time inside the spill
416 LOG(info) << "T0 time " << BmnFunctionSet::TimePoint2String(dig->GetTime()) << " iEntry " << iEntry;
417 }
418 }
419 } else {
420 for (Long64_t iEntry = 0; iEntry < fInTreeSpills->GetEntries(); ++iEntry) {
421 fInTreeSpills->GetEntry(iEntry);
422 for (Int_t iDig = 0; iDig < msc->GetEntries(); ++iDig) {
423 BmnMSCDigit<UChar_t>* dig = static_cast<BmnMSCDigit<UChar_t>*>(msc->At(iDig));
424 mts[dig->GetTime()].push_back(make_pair(iEntry, iDig));
425 // msc_entries_cnt_total++;
426 }
427 Int_t ne_t0 = t0raw->GetEntries();
428 if (ne_t0 > 0) {
429 BmnT0Raw* dig = static_cast<BmnT0Raw*>(t0raw->At(0));
430 vts_t0.push_back(make_pair(dig->GetTime() - ((Long64_t)t0raw_shift_av) * 1ns - 1s,
431 iEntry)); // crutch to fit rough time inside the spill
432 LOG(info) << "T0 time " << BmnFunctionSet::TimePoint2String(dig->GetTime()) << " iEntry " << iEntry;
433 }
434 }
435 // size_t i_rec{0};
436 // for (auto &rec : mts)
437 // time2times_map_entry[rec.first] = i_rec++;
438 msc_entries_cnt_total = mts.size();
439 }
440 timer.Stop();
441 rtime = timer.RealTime();
442 ctime = timer.CpuTime();
443 LOGF(info, "Real time %f s, CPU time %f s timestamp map filling", rtime, ctime);
444
445 LOGF(info, "Run:\n\tstart ts: %s\n\tstop ts: %s", BmnFunctionSet::TimePoint2String(fRunStartTime),
447 UInt_t spillId = 0;
448 ULong64_t n_events_run(0);
449 for (auto& mapel : fSpillMap) {
451 BmnSpillInfo& si = mapel.second;
452 LOGF(info, "");
453 LOGF(info, "***********************************************************");
454 LOGF(info, "Spill:\n\tstart ts: %s\n\tstop ts: %s", BmnFunctionSet::TimePoint2String(si.start_ts),
456 if ((fRunStartTime > si.stop_ts) || (fRunEndTime < si.start_ts)) {
457 LOGF(warning, "Spill is outside the run! Skipping!");
458 continue;
459 }
460 // count activated triggers in events
461 timer.Start();
462 auto df_events_in_spill = df.Filter(
463 [&](BmnEventHeader& eh) {
464 return ((eh.GetEventTimeTP() >= si.start_ts) && (eh.GetEventTimeTP() <= si.stop_ts));
465 },
466 {"BmnEventHeader."});
467 ULong64_t cnt[32] = {};
468 UInt_t first_ev_id(kMaxUInt);
469 UInt_t last_ev_id(0);
470 SysPoint first_ev_tp;
471 SysPoint last_ev_tp;
472 // SysPoint first_trigger_tp{SysPoint::max()}; // first MSC trigger time in the spill
473 // SysPoint last_trigger_tp{SysPoint::min()}; // last MSC trigger time in the spill
474 // SysPoint first_trigger_tp_captured{SysPoint::max()}; // first MSC trigger time in the spill and the
475 // run SysPoint last_trigger_tp_captured{SysPoint::min()}; // last MSC trigger time in the spill and the
476 // run SysPoint first_l2_tp{SysPoint::max()}; // first MSC trigger time in the spill SysPoint
477 // last_l2_tp{SysPoint::min()}; // last MSC trigger time in the spill
478 auto df_events_in_spill_trig_cntr = df_events_in_spill.Filter(
479 [&](BmnEventHeader& eh) {
480 for (auto& el : digiRunHeader->GetTrcBitMap()) {
481 if (eh.GetInputSignalsAR() & BIT(el.second))
482 cnt[el.second]++;
483 }
484 if (first_ev_id > eh.GetEventId()) {
485 first_ev_id = eh.GetEventId();
486 first_ev_tp = eh.GetEventTimeTP();
487 }
488 if (last_ev_id < eh.GetEventId()) {
489 last_ev_id = eh.GetEventId();
490 last_ev_tp = eh.GetEventTimeTP();
491 }
492 return true;
493 },
494 {"BmnEventHeader."});
495 ULong64_t n_events = *(df_events_in_spill_trig_cntr.Count());
496 LOGF(info, "\tfirst ts: %s\n\tlast ts: %s", BmnFunctionSet::TimePoint2String(first_ev_tp),
498 n_events_run += n_events;
499 LOGF(info, "Events in the spill %7llu", n_events);
500 // cut entries outside run in the first and last spills
501 SysPoint spillRangeImposedStart; // set spill start time by hand
502 SysPoint spillRangeImposedStop; // set spill stop time by hand
503 if ((spillId == 0) || (spillId == fSpillMap.size() - 1)) {
504 spillRangeImposedStart = first_ev_tp;
505 spillRangeImposedStop = last_ev_tp;
506 } else {
507 spillRangeImposedStart = si.start_ts;
508 spillRangeImposedStop = si.stop_ts;
509 }
510 spillHeader->SetStartTime(si.start_ts);
511 spillHeader->SetStopTime(si.stop_ts);
512 spillHeader->SetSpillId(spillId++);
513 spillHeader->SetNEvents(n_events);
514 spillHeader->SetFirstEventId(first_ev_id);
515 spillHeader->SetLastEventId(last_ev_id);
516 spillHeader->SetFirstEventTime(first_ev_tp);
517 spillHeader->SetLastEventTime(last_ev_tp);
518 for (auto& el : digiRunHeader->GetTrcBitMap()) {
519 const string& tr_name = el.first;
520 spillHeader->EventTriggerCnt()[tr_name] = cnt[el.second];
521 digiRunHeader->EventTriggerCnt()[tr_name] += spillHeader->EventTriggerCnt()[tr_name];
522 LOGF(info, "Evt_cnt %-11s %7llu", tr_name.c_str(), cnt[el.second]);
523 }
524 timer.Stop();
525 rtime = timer.RealTime();
526 ctime = timer.CpuTime();
527 LOGF(info, "Real time %f s, CPU time %f s ev cnt calc", rtime, ctime);
528
529 // calc T0 count inside spill
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;
533 timer.Start();
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); });
536 timer.Stop();
537 rtime = timer.RealTime();
538 ctime = timer.CpuTime();
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);
541
542 LOGF(info, "Start scalers calc");
543 timer.Start();
544
545 // string ScalerNumeratorForEvalName = "L2_Trig";
546 // string ScalerDenominatorForEvalName = "BT'";
547 // uint16_t iScalerNumeratorForEval = scalers_name2index_map[ScalerNumeratorForEvalName];
548 // uint16_t iScalerDenominatorForEval = scalers_name2index_map[ScalerDenominatorForEvalName];
549 // double bt_cap_sum = 0; // count of the selected MSC trigger in the file event time range
550 // double msc_l2_count = 0; // MSC l2 trigger count (assuming all l2 triggers written as events)
551 vector<uint64_t> scalerVec(scalers_ar_size, 0); // spill scalers count vector
552
553 if (fPeriodId > 8) {
554 // calc MSC count inside spill
555 auto df_spill = df_spills.Filter(
556 [&](TClonesArray& tca) {
557 for (Int_t iDig = 0; iDig < tca.GetEntries(); ++iDig) {
558 BmnMSCZSDigit<uint8_t>* dig = static_cast<BmnMSCZSDigit<uint8_t>*>(tca.At(iDig));
559 auto index_it = scalers2index_map.find(make_pair(dig->GetSerial(), dig->GetChannel()));
560 if (index_it == scalers2index_map.end())
561 return false;
562 return ((dig->GetTime() >= si.start_ts) && (dig->GetTime() <= si.stop_ts));
563 }
564 return false;
565 },
566 {"MSC"});
567 /** Local time map (longer calculation, less memory use) */
568 uint32_t missing_hits = 0;
569 map<SysPoint, vector<uint8_t>> mts9; // for period 9
570 df_spill.Foreach(
571 [&](TClonesArray& tca) {
572 for (Int_t iDig = 0; iDig < tca.GetEntries(); ++iDig) {
573 BmnMSCZSDigit<uint8_t>* dig = static_cast<BmnMSCZSDigit<uint8_t>*>(tca.At(iDig));
574 auto index_it = scalers2index_map.find(make_pair(dig->GetSerial(), dig->GetChannel()));
575 if (index_it == scalers2index_map.end())
576 continue;
577 missing_hits += dig->GetMissingHits();
578 uint8_t index = index_it->second;
579 auto& times = dig->GetTimes();
580 vector<uint8_t>& values = dig->GetValues();
581 vector<uint8_t>& excs = dig->GetExtCond();
582 for (size_t iTime = 0; iTime < dig->GetNVals(); iTime++) {
583 // SysPoint& time = times[iTime];
584 SysPoint time = BmnFunctionSet::TimeStamp2TP(times[iTime]);
585 auto it = mts9.find(time);
586 if (it == mts9.end()) {
587 vector<uint8_t> tarr(scalers_ar_size + 1, 0); // scalers + ext conditions
588 tarr[index] = values[iTime];
589 tarr[scalers_ar_size] = excs[iTime];
590 mts9.insert(make_pair(time, move(tarr)));
591 } else {
592 vector<uint8_t>& tarr = it->second;
593 tarr[index] += values[iTime];
594 tarr[scalers_ar_size] = excs[iTime];
595 }
596 }
597 }
598 },
599 {"MSC"});
600
601 auto itLower = mts9.lower_bound(spillRangeImposedStart);
602 auto itUpper = mts9.upper_bound(spillRangeImposedStop);
603 size_t spillTimesCount = std::distance(itLower, itUpper);
604 // size_t spillTimesCount = mts9.size();
605 msc_entries_cnt += spillTimesCount;
606 msc_entries_cnt_total += mts9.size();
607 LOGF(info, "Spill times count %lld", spillTimesCount);
608 // create single MSC matrix object for spill
609 BmnMSCMatrix<uint8_t>* msc_matrix = new ((*msc_copy)[msc_copy->GetEntries()])
611 msc_matrix->SetMissingHits(missing_hits);
612 // spillHeader->ScalersVec().resize(scalers_ar_size, 0);
613 // Fill MSC matrix elements
614 size_t i_record{0};
615 boost::dynamic_bitset<> bitVecSpill(spillTimesCount, false);
616 boost::dynamic_bitset<> bitVecBusy(spillTimesCount, false);
617 // for (auto & [time, vals] : mts9) {
618 for (auto itTimes = itLower; itTimes != itUpper; itTimes++) {
619 auto& time = itTimes->first;
620 vector<uint8_t>& vals = itTimes->second;
621 // msc_matrix->Time(i_record) = time;
622 msc_matrix->SetTime(i_record, time);
623 uint8_t ext_cond = vals[scalers_ar_size];
624 bitVecSpill[i_record] = ext_cond & MSC_EC_SPILL;
625 bitVecBusy[i_record] = ext_cond & MSC_EC_BUSY;
626 // msc_matrix->IsSpillBitVec()[i_record] = ext_cond & MSC_EC_SPILL;
627 // msc_matrix->IsBusyBitVec()[i_record] = ext_cond & MSC_EC_BUSY;
628 for (uint16_t iScaler = 0; iScaler < scalers_ar_size; iScaler++) {
629 if (vals[iScaler] == 0)
630 continue;
631 msc_matrix->SetCount(i_record, iScaler, vals[iScaler]);
632 // msc_matrix->Counts()(i_record, iScaler) = vals[iScaler];
633 // spillHeader->Scalers()[name] += vals[iScaler];
634
635 // spillHeader->ScalersVec()[iScaler] += vals[iScaler];
636 scalerVec[iScaler] += vals[iScaler];
637 LOGF(debug, "el %8llu %2lu count %3u sp %u busy %u GC", i_record, iScaler,
638 (UChar_t)(msc_matrix->GetCount(i_record, iScaler)), (UInt_t)msc_matrix->GetIsSpill(time),
639 (UInt_t)msc_matrix->GetIsBusy(time));
640 // (UInt_t)msc_matrix->IsSpillBitVec()[i_record],
641 // (UInt_t)msc_matrix->IsBusyBitVec()[i_record]);
642 }
643 i_record++;
644 }
645 if (i_record > spillTimesCount)
646 LOGF(error, "\n\t ERROR!!! irec %lu spillTimesCount %lu\n", i_record, spillTimesCount);
647 GenerateBusyRanges(msc_matrix, bitVecSpill, bitVecBusy);
648 } else {
649 // calc MSC count inside spill
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);
654 // size_t spillTimesShift = std::distance(mts.begin(), itLower);
655 for (auto itTimes = itLower; itTimes != itUpper; itTimes++) {
656 vector<Index_Pair>& index_vec = itTimes->second;
657 spillEntriesCumulativeSize += index_vec.size();
658 }
659 // msc_entries_cnt += spillEntriesCumulativeSize;
660 msc_entries_cnt += spillTimesCount;
661 LOGF(info, "entriesCumulativeSize %lld", spillEntriesCumulativeSize);
662 LOGF(info, "Spill times count %lld", spillTimesCount);
663 // LOGF(info, "Spill times shift %lld", spillTimesShift);
664
665 // create single MSC matrix object for spill
666 BmnMSCMatrix<uint8_t>* msc_matrix = new ((*msc_copy)[msc_copy->GetEntries()])
668 // BmnMSCMatrix<UChar_t>(spillTimesCount, scalers_ar_size);
669 // spillHeader->ScalersVec().resize(scalers_ar_size, 0);
670
671 // Fill MSC matrix elements
672 size_t i_record{0};
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;
677 // msc_matrix->Time(i_record) = time;
678 msc_matrix->SetTime(i_record, time);
679 vector<Index_Pair>& index_vec = itTimes->second;
680 // msc_entries_cnt += index_vec.size();
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;
687 fInTreeSpills->GetEntry(iEntry);
688 if (iDig >= msc->GetEntries()) {
689 LOGF(error, "\n\t ERROR!!! iDig %d msc->GetEntries() %d\n", iDig, msc->GetEntries());
690 break;
691 }
692 BmnMSCDigit<UChar_t>* dig = static_cast<BmnMSCDigit<UChar_t>*>(msc->At(iDig));
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());
697 }
698 bitVecSpill[i_record] = dig->IsSpill();
699 bitVecBusy[i_record] = dig->IsBusy();
700 // msc_matrix->IsSpillBitVec()[i_record] = dig->IsSpill();
701 // msc_matrix->IsBusyBitVec()[i_record] = dig->IsBusy();
702 for (UInt_t iNum = 0; iNum < MSC_N_COUNTERS; iNum++) {
703 UInt_t val = dig->GetValue()[iNum];
704 // if (val == 0)
705 // continue;
706 // auto it = scalers2name_map.find(make_pair(dig->GetSerial(), iNum));
707 // if (it == scalers2name_map.end())
708 // continue;
709 // string& name = it->second;
710 auto it = scalers2index_map.find(make_pair(dig->GetSerial(), iNum));
711 if (it == scalers2index_map.end())
712 continue;
713 uint16_t iScaler = it->second;
714 // msc_matrix->Counts(i_record, iScaler) += val;
715 // msc_matrix->Counts()(i_record, iScaler) += val;
716 msc_matrix->SetCount(i_record, iScaler, val);
717 // 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,
720 dig->GetSerial(), (UChar_t)(msc_matrix->GetCount(i_record, iScaler)),
721 // (UChar_t)(msc_matrix->Counts()(i_record, iScaler)),
722 (UInt_t)msc_matrix->GetIsSpill(time), (UInt_t)msc_matrix->GetIsBusy(time));
723 // (UInt_t)msc_matrix->IsSpillBitVec()[i_record],
724 // (UInt_t)msc_matrix->IsBusyBitVec()[i_record]);
725 // spillHeader->Scalers()[name] += val;
726 // spillHeader->ScalersVec()[iScaler] += val;
727 scalerVec[iScaler] += val;
728 }
729 }
730 i_record++;
731 }
732 if (i_record > spillTimesCount)
733 LOGF(error, "\n\t ERROR!!! irec %lu spillTimesCount %lu\n", i_record, spillTimesCount);
734 GenerateBusyRanges(msc_matrix, bitVecSpill, bitVecBusy);
735 }
736
737 // for (Long64_t iEntry = 0; iEntry < fInTreeSpills->GetEntries(); ++iEntry) {
738 // fInTreeSpills->GetEntry(iEntry);
739 // for (Int_t iDig = 0; iDig < msc->GetEntries(); ++iDig) {
740 // BmnMSCDigit<UChar_t>* dig = static_cast<BmnMSCDigit<UChar_t>*>(msc->At(iDig));
741 // size_t i_record = time2times_map_entry[dig->GetTime()] - spillTimesShift;
742 // LOGF(info, "iEntry %7d iDig %3d el %8llu ", iEntry, iDig, i_record);
743 // msc_matrix->Time(i_record) = dig->GetTime();
744 // msc_matrix->IsSpillBitVec()[i_record] = dig->IsSpill();
745 // msc_matrix->IsBusyBitVec()[i_record] = dig->IsBusy();
746 // for (UInt_t iNum = 0; iNum < MSC_N_COUNTERS; iNum++) {
747 // UInt_t val = dig->GetValue()[iNum];
748 // if (val == 0)
749 // continue;
750 // // auto it = scalers2name_map.find(make_pair(dig->GetSerial(), iNum));
751 // // if (it == scalers2name_map.end())
752 // // continue;
753 // // string& name = it->second;
754 // auto it = scalers2index_map.find(make_pair(dig->GetSerial(), iNum));
755 // if (it == scalers2index_map.end())
756 // continue;
757 // uint16_t index = it->second;
758 // msc_matrix->Counts(i_record, index) += val;
759 // LOGF(debug, "el %8llu %2lu = %u sp %u busy %u",
760 // i_record,
761 // index,
762 // (UChar_t)(msc_matrix->Counts(i_record, index)),
763 // (UInt_t)msc_matrix->IsSpillBitVec()[i_record],
764 // (UInt_t)msc_matrix->IsBusyBitVec()[i_record]);
765 // // spillHeader->Scalers()[name] += val;
766 // spillHeader->ScalersVec()[index] += val;
767 // scalerVec[index] += val;
768 // }
769 // }
770 // }
771 for (auto& p : spillIds_t0) {
772 Long64_t iEntry = p.second;
773 fInTreeSpills->GetEntry(iEntry);
774 t0_copy->AbsorbObjects(t0raw);
775 }
776 for (int i = 0; i < scalers_ar_size; i++)
777 // digiRunHeader->ScalersVec()[i] += spillHeader->ScalersVec()[i];
778 digiRunHeader->ScalersVec()[i] += scalerVec[i];
779 // for (auto& scaler_map_el : spillHeader->Scalers()) {
780 // const string& sc_name = scaler_map_el.first;
781 // metadata.Scalers()[sc_name] += spillHeader->Scalers()[sc_name];
782 // }
783 timer.Stop();
784 rtime = timer.RealTime();
785 ctime = timer.CpuTime();
786 LOGF(info, "Real time %f s, CPU time %f s Scalers calc", rtime, ctime);
787
788 for (size_t iSc = 0; iSc < scalers_index2name_map.size(); iSc++) {
789 const string& name = scalers_index2name_map[iSc];
790 // uint64_t& val = spillHeader->ScalersVec()[iSc];
791 uint64_t& val = scalerVec[iSc];
792 spillHeader->Scalers()[name] = val;
793 LOGF(info, "MSC %-14s %10llu", name.c_str(), val);
794 }
795
796 if (t0_copy->GetEntries()) {
797 BmnT0Raw* t0r = static_cast<BmnT0Raw*>(t0_copy->At(0));
798 AddT0Raw2Headers(t0r);
799 if (t0_copy->GetEntries() > 1)
800 LOGF(error, "More than 1 T0 in the spill %lu ! %d records found", spillHeader->GetSpillId(),
801 t0_copy->GetEntries());
802 } else {
803 LOGF(error, "No T0 in the spill %lu !", spillHeader->GetSpillId());
804 if (fT0RawStorageTsMap->size()) {
805 LOGF(info, "Searching for T0 in the storage");
806 TTimeStamp t0StopTS(BmnFunctionSet::TimePoint2TS(si.stop_ts - 1s + ((Long64_t)t0raw_shift_av) * 1ns));
807 auto itLower = fT0RawStorageTsMap->lower_bound(t0StopTS);
808 if (itLower != fT0RawStorageTsMap->end()) {
809 LOGF(info, "Found at timestamp %s entry %u", (itLower->first).AsString(), itLower->second);
810 fT0RawStorageTree->GetEntry(itLower->second);
811 t0_copy->AbsorbObjects(fT0RawStorageArr);
812 if (t0_copy->GetEntries()) {
813 BmnT0Raw* t0r = static_cast<BmnT0Raw*>(t0_copy->At(0));
814 AddT0Raw2Headers(t0r);
815 // AddT0Raw2Headers(t0r, bt_cap_frac);
816 }
817 } else {
818 LOGF(error, "%s timestamp not found in the T0 storage!", t0StopTS.AsString());
819 }
820 }
821 }
822 fDigiTreeSpills->Fill();
823 }
824 digiRunHeader->SetNEvents(n_events_run);
825 // this warning is not informative if we cut entries outside run in the first/last spill
826 // if (msc_entries_cnt_total > msc_entries_cnt)
827 // LOGF(warning,
828 // "MSC branch entries %9llu total\n"
829 // "MSC branch entries %9llu in spills\n"
830 // "MSC branch entries %9llu outside spills!",
831 // msc_entries_cnt_total, msc_entries_cnt, msc_entries_cnt_total - msc_entries_cnt);
832 digiRunHeader->ScalersName2IndexMap() = move(scalers_name2index_map);
833 digiRunHeader->ScalersIndex2NameMap() = move(scalers_index2name_map);
834 digiRunHeader->TrcIndex2ScalerIndexMap() = move(trcIdx2scalerIdx);
835 LOGF(info, "Evt trigger count Total:");
836 LOGF(info, "All events %8llu", digiRunHeader->GetNEvents());
837 for (auto& el : digiRunHeader->GetTrcBitMap()) {
838 const string& tr_name = el.first;
839 LOGF(info, "%-12s %8llu", tr_name.c_str(), digiRunHeader->EventTriggerCnt()[tr_name]);
840 }
841 LOGF(info, "Raw T0 Total:");
842 for (auto& t0_map_el : fRawT0Map) {
843 const T0MapKey& key = t0_map_el.first;
844 if (key.first.find("BD") == 0)
845 continue;
846 LOGF(info, "T0 %-14s.%02u = %10llu", key.first.c_str(), key.second,
847 digiRunHeader->GetRawT0Counter(key.first.c_str(), key.second));
848 }
849 LOGF(info, "MSC Total:");
850 digiRunHeader->PrintScalers();
851 delete fInTreeSpills;
852 // ROOT::DisableImplicitMT();
853 return kBMNSUCCESS;
854}
855
857 boost::dynamic_bitset<>& bitVecSpill,
858 boost::dynamic_bitset<>& bitVecBusy)
859{
860 bool insideSpill = false;
861 bool insideBusy = false;
862 SysPoint SpillRangeStart;
863 SysPoint BusyRangeStart;
864 for (size_t i_record = 0; i_record < matrix->GetNRecords(); i_record++) {
865 SysPoint& curTime = matrix->GetTime(i_record);
866 if (bitVecSpill[i_record]) {
867 if (!insideSpill) {
868 SpillRangeStart = curTime;
869 insideSpill = true;
870 }
871 } else if (insideSpill) {
872 SysPoint& SpillRangeStop = curTime;
873 matrix->SpillRangeVec().push_back(make_pair(SpillRangeStart, SpillRangeStop));
874 insideSpill = false;
875 }
876 if (bitVecBusy[i_record]) {
877 if (!insideBusy) {
878 BusyRangeStart = curTime;
879 insideBusy = true;
880 }
881 } else if (insideBusy) {
882 SysPoint& BusyRangeStop = curTime;
883 matrix->BusyRangeVec().push_back(make_pair(BusyRangeStart, BusyRangeStop));
884 insideBusy = false;
885 }
886 }
887}
888
890{
891 for (UInt_t i = 0; i < kT0_BIN_BLOCK_WORDS; i++) {
892 spillHeader->RawT0Counters()[i] = t0r->Counters()[i];
893 digiRunHeader->RawT0Counters()[i] += spillHeader->RawT0Counters()[i];
894 }
895 LOGF(info, "T0 time %s", t0r->GetTS().AsString());
896 for (auto& t0_map_el : digiRunHeader->T0Map()) {
897 const T0MapKey& key = t0_map_el.first;
898 if (key.first.find("BD") == 0)
899 continue;
900 LOGF(info, "T0 %-14s.%02u = %9llu", key.first.c_str(), key.second,
901 spillHeader->RawT0Counters()[t0_map_el.second]);
902 }
903}
904
906{
908 // sort status blocks
909 std::sort(metadata.SpillStatusVec().begin(), metadata.SpillStatusVec().end(), [](SpillStatus& a, SpillStatus& b) {
910 return ((a.start_ts < b.start_ts) || ((a.start_ts == b.start_ts) && (a.cur_spill_time_ms < b.cur_spill_time_ms))
911 // ((a.start_ts == b.start_ts) && (a.stop_ts < b.stop_ts))
912 );
913 });
914 for (SpillStatus& ss : metadata.SpillStatusVec()) {
915 LOG(debug) << BmnFunctionSet::TimePoint2String(ss.start_ts) << " start";
916 LOG(debug) << BmnFunctionSet::TimePoint2String(ss.stop_ts) << " stop";
917 }
918 // make spill map
919 for (SpillStatus& ss : metadata.SpillStatusVec()) {
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);
923 if (spill_it == fSpillMap.end()) {
924 bool inserted;
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);
928 BmnSpillInfo& si = spill_it->second;
929 si.counters.ResizeTo(ss.counters);
930 }
931 BmnSpillInfo& info = spill_it->second;
932 if (info.stop_ts < ts_spill_stop)
933 info.stop_ts = ts_spill_stop;
934 info.vec_spill_status.push_back(ss);
935 }
936 for (auto& it : fSpillMap) {
937 BmnSpillInfo& info = it.second;
938 LOGF(info, "\tstart %s\n\tstop %s", BmnFunctionSet::TimePoint2String(info.start_ts),
940 }
941 if (fSpillMap.size() == 0) {
942 LOGF(error, "Spill map is empty!");
943 return kBMNERROR;
944 }
945 // calculate counters for each spill & sum total ones
946 auto& total_cntrs = metadata.SpillCounters();
947 total_cntrs.ResizeTo(fSpillMap.begin()->second.counters);
948 for (auto& it : fSpillMap) {
949 BmnSpillInfo& info = it.second;
950 size_t blocks_count = info.vec_spill_status.size();
951 if (blocks_count == 0)
952 continue;
953 auto& first_ss = info.vec_spill_status.front();
954 auto& last_ss = info.vec_spill_status.back();
955 info.counters = last_ss.counters;
956 auto& spill_cntrs = info.counters;
957 for (size_t i = 0; i < SpillStatus::counters_cnt; i++) {
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];
962 }
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];
970 for (size_t i = 0; i < SpillStatus::counters_cnt; i++) {
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];
975 // LOGF(info, "cntr %2u input %s total %lu", i, total_p_input.first.c_str(),
976 // total_p_input.second[i]);
977 }
978 }
979 }
980 metadata.SpillMap() = fSpillMap;
981 vector<string> trc_names{"pBT", "BT", "MBT", "NiT", "BT&nBUSY", "CCT1", "CCT2"};
982 // for (auto& it : metadata.SpillMap()) {
983 // BmnSpillInfo& info = it.second;
984 // auto& spill_cntrs = info.counters;
985 // LOGF(info, "\n\tstart %s\n\tstop %s", BmnFunctionSet::TimePoint2String(info.start_ts),
986 // BmnFunctionSet::TimePoint2String(info.stop_ts));
987 // if (spill_cntrs.cntr_input.size() <= 1) {
988 // LOGF(warning, "not enough data");
989 // continue;
990 // }
991 // for (string& name : trc_names) {
992 // uint16_t icntr = fTrigBitsMap[name];
993 // LOGF(info, "\t icntr %6u %8s", icntr, name.c_str());
994 // LOGF(info, "\t%8s before %8lu after %8lu ", name.c_str(),
995 // spill_cntrs.cntr_befor_err[icntr],
996 // spill_cntrs.cntr_after_err[icntr]);
997 // LOGF(info, "\t%8s BUSY input %8lu input_red %8lu ", name.c_str(),
998 // spill_cntrs.cntr_input[6].second[icntr], spill_cntrs.cntr_input_after_red[6].second[icntr]);
999 // LOGF(info, "\t%8s NOT_BUSY input %8lu input_red %8lu ", name.c_str(),
1000 // spill_cntrs.cntr_input[7].second[icntr], spill_cntrs.cntr_input_after_red[7].second[icntr]);
1001 // }
1002 // }
1003 LOGF(info, "\n\tTRC TOTAL:");
1004 for (string& name : trc_names) {
1005
1006 uint16_t icntr = fTrcBitMap[name];
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]);
1014 }
1015 // SaveData();
1016 // DisposeDecoder();
1017
1018 return kBMNSUCCESS;
1019}
1020
1022{
1023 LoadConfig();
1024
1025 return kBMNSUCCESS;
1026}
1027
1029{
1030 if (fTrigMapper)
1031 fTrigMapper->ClearArrays();
1032 inEventHeader->Clear();
1033}
1034
1036{
1037 if (spillHeader)
1038 spillHeader->Clear();
1039 if (msc_copy)
1040 msc_copy->Delete();
1041 if (t0_copy)
1042 t0_copy->Delete();
1043}
1044
1046{
1047 metadata.SpillStatusVec()
1048 .clear(); // !!! temporary remove raw trc statuses from file @TODO resolve the writing issue
1049 for (auto& it : metadata.SpillMap()) {
1050 BmnSpillInfo& info = it.second;
1051 info.vec_spill_status.clear();
1052 }
1053 // gDebug = 2;
1054 LOGF(debug, "Writing run header to file");
1055 Int_t wret = fDigiFileOut->WriteObject(digiRunHeader.get(), fDigiRunHdrName.Data());
1056 if (wret > 0)
1057 LOGF(debug, "Written bytes %d", wret);
1058 else
1059 DBGERR("WriteObject")
1060
1061 LOGF(debug, "Writing metadata to file");
1062 TStopwatch timer;
1063 Double_t rtime;
1064 Double_t ctime;
1065 timer.Start();
1066 wret = fDigiFileOut->WriteObject(&metadata, fMetadataName.Data());
1067 timer.Stop();
1068 rtime = timer.RealTime();
1069 ctime = timer.CpuTime();
1070 LOGF(debug, "Real time %f s, CPU time %f s WriteObject", rtime, ctime);
1071 if (wret > 0)
1072 LOGF(debug, "Written bytes %d", wret);
1073 else
1074 DBGERR("WriteObject")
1075
1076 LOGF(debug, "Flushing other data to file");
1077 fDigiFileOut->Write();
1078 LOGF(debug, "Closing the file");
1079 fDigiFileOut->Close();
1080
1081 return kBMNSUCCESS;
1082}
1083
1085{
1086 // if (fTrigMapper)
1087 // delete fTrigMapper;
1088 // if (fMSCMapper)
1089 // delete fMSCMapper;
1090
1091 if (msc_copy)
1092 delete msc_copy;
1093 if (t0_copy)
1094 delete t0_copy;
1095
1096 if (inEventHeader)
1097 delete inEventHeader;
1098 if (spillHeader)
1099 delete spillHeader;
1100
1101 return kBMNSUCCESS;
1102}
1103
1105{
1106 TPRegexp re_data(".*\\w+_\\w+_\\w+_(\\d+)([^/]*)\\.data");
1107 TPRegexp re_raw(".*\\w+_run(\\d+)([^/]*)_raw\\.root");
1108 TString str(name);
1109 if (re_data.MatchB(str))
1110 re_data.Substitute(str, "$2");
1111 else {
1112 if (re_raw.MatchB(str))
1113 re_raw.Substitute(str, "$2");
1114
1115 else
1116 return "";
1117 }
1118 return str;
1119}
1120
1122{
1123 LOGF(debug, "%s", __func__);
1124 if (fDecoderConfigFileName.length() == 0)
1125 fDecoderConfigFileName = string(getenv("VMCWORKDIR")) + "/config/bmnconf.json";
1126 pt::read_json(fDecoderConfigFileName, conf);
1127 return kBMNSUCCESS;
1128}
1129
1131{
1132 const string tree_name = "T0RAW_ALL";
1133 const string t0raw_branch_name = "T0RAW";
1134 const string ts_map_name = "T0TsMap";
1135 fT0RawStorageFile = make_unique<TFile>(fT0RawStorageFileName.data(), "read");
1136 if (fT0RawStorageFile->IsOpen() == false) {
1137 LOGF(error, "\n!!!!\nCannot open T0 storage file %s \n!!!!", fT0RawStorageFileName.data());
1138 return kBMNERROR;
1139 }
1140 fT0RawStorageTsMap.reset(
1141 static_cast<std::map<TTimeStamp, int64_t>*>(fT0RawStorageFile->GetObjectUnchecked(ts_map_name.data())));
1142 if (!fT0RawStorageTsMap) {
1143 LOGF(error, "T0 storage timestamp map not found!");
1144 return kBMNERROR;
1145 }
1146 fT0RawStorageTree.reset(static_cast<TTree*>(fT0RawStorageFile->Get(tree_name.data())));
1147 fT0RawStorageTree->SetBranchAddress(t0raw_branch_name.data(), &fT0RawStorageArr);
1148 // LOG(info) <<fT0RawStorageTree->GetEntries();
1149 // LOG(info) <<fT0RawStorageTree->GetEntry(0);
1150 // LOG(info) <<fT0RawStorageArr->GetEntries();
1151 if (!fT0RawStorageArr) {
1152 LOGF(error, "T0 storage branch %s not found!", t0raw_branch_name.data());
1153 return kBMNERROR;
1154 }
1155 LOG(info) << fT0RawStorageFile->GetName();
1156 LOGF(info, "T0 storage loaded successfully!");
1157 return kBMNSUCCESS;
1158}
1159
1160BmnStatus BmnMetadataDecoder::ReadSpillStat(const string& FileName, const vector<string>& evt_tr_names)
1161{
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;
1167 // map<string, UInt_t> rfs;
1168 // rfs["BT"] = 2000;
1169 // rfs["MBT"] = 35;
1170 // rfs["CCT1"] = 230;
1171 // rfs["CCT2"] = 1;
1172 gStyle->SetOptStat(2211);
1173
1174 unique_ptr<TFile> file = make_unique<TFile>(FileName.data(), "READ");
1175 if (file->IsOpen() == false) {
1176 LOG(error) << "Cannot open file " << FileName << " !" << endl;
1177 return kBMNERROR;
1178 }
1179 DigiRunHeader* rh = static_cast<DigiRunHeader*>(file->Get("DigiRunHeader"));
1180 BmnMetadataRaw* metadata = static_cast<BmnMetadataRaw*>(file->Get("RawRunMetadata"));
1181
1182 if (rh == nullptr) {
1183 LOG(error) << "No run header!" << endl;
1184 return kBMNERROR;
1185 }
1186 LOGF(info, "Run Header content:");
1187 UInt_t PeriodId = rh->GetPeriodId();
1188 UInt_t RunId = rh->GetRunId();
1189 LOGF(info, "\tPeriod: %u Run: %u", PeriodId, RunId);
1190 TTimeStamp RunStartTime = rh->GetRunStartTime();
1191 TTimeStamp RunEndTime = rh->GetRunEndTime();
1192 LOGF(info, "\tSTART : %s", RunStartTime.AsString());
1193 LOGF(info, "\tFINISH : %s", RunEndTime.AsString());
1194 auto& tcc = rh->GetTrigConfig().TrigChannelConfig();
1195 // map<SysPoint, BmnSpillInfo>& fSpillMap = metadata->SpillMap();
1196 NameChMap& fTrigBitsMap = metadata->TrcMap();
1197 // Name2SerCh& fScalersMap = metadata->ScalersMap();
1198 vector<string> trc_names{"pBT", "BT", "MBT", "NiT", "BT&nBUSY", "CCT1", "CCT2"};
1199 auto& total_cntrs = metadata->SpillCounters();
1200 if (print_trc) {
1201 if (print_by_spill) {
1202 for (auto& it : metadata->SpillMap()) {
1203 BmnSpillInfo& info = it.second;
1204 auto& spill_cntrs = info.counters;
1205 LOGF(info, "\n\tstart %s\n\tstop %s", BmnFunctionSet::TimePoint2String(info.start_ts).c_str(),
1207 if (spill_cntrs.cntr_input.size() <= 1) {
1208 printf("not enough data");
1209 continue;
1210 }
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]);
1220 }
1221 }
1222 }
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]);
1233 }
1234 }
1235
1236 TTree* tree = static_cast<TTree*>(file->Get("spill"));
1237 BmnSpillHeader* sh = nullptr;
1238 TClonesArray* msc = nullptr;
1239 TClonesArray* t0raw = nullptr;
1240 tree->SetBranchStatus("*", 0);
1241 tree->SetBranchStatus("BmnSpillHeader.*", 1);
1242 tree->SetBranchStatus("T0Raw*", 1);
1243 tree->SetBranchAddress("BmnSpillHeader.", &sh);
1244 // tree->SetBranchAddress("MSC", &msc);
1245 tree->SetBranchAddress("T0Raw", &t0raw);
1246 /** canvas for trig counters per 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++) {
1253 name = TString("SupressionFactor_") + TString(evt_tr_names[i]);
1254 evt_tr_hist.push_back(make_unique<TH1I>(name, name, 500, 0, (Double_t)1));
1255 }
1256 /** canvas for evt counter vs supression factor for spill */
1257 vector<unique_ptr<TH2I>> sup_evt_cnt;
1258 name = "SupEvtCnt";
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));
1264 }
1265
1266 map<string, uint64_t> runScalers;
1267 Long64_t NSpills = tree->GetEntries();
1268 for (Int_t iSpill = 0; iSpill < NSpills; iSpill++) {
1269 tree->GetEntry(iSpill);
1270 LOGF(info, "Spill:\n\tstart ts: %s\n\tstop ts: %s", sh->GetStartTS().AsString(), sh->GetStopTS().AsString());
1271 LOGF(info, "\tfirst ts: %s\n\tlast ts: %s", sh->GetFirstEventTS().AsString(), sh->GetLastEventTS().AsString());
1272 for (auto& sca : sh->Scalers()) {
1273 LOGF(info, "MSC %-10s %8lu", sca.first.c_str(), sca.second);
1274 }
1275 if (t0raw->GetEntries()) {
1276 LOGF(info, "T0 time %s",
1277 BmnFunctionSet::TimePoint2String((static_cast<BmnT0Raw*>(t0raw->At(0)))->GetTime()).c_str());
1278 for (auto& t0_map_el : rh->T0Map()) {
1279 const T0MapKey& key = t0_map_el.first;
1280 if (key.first.find("BD") == 0)
1281 continue;
1282 LOGF(info, "T0 %-14s.%02u = %7u", key.first.c_str(), key.second, sh->RawT0Counters()[t0_map_el.second]);
1283 }
1284 }
1285 LOGF(info, "Event spill counters:");
1286 for (size_t i = 0; i < trigCount; i++) {
1287 const string& tr_name = evt_tr_names[i];
1288 // string t0_name =
1289 // (tr_name == "nFD") ?
1290 // "FHCal_v2" :
1291 // (tr_name == "MBT") ?
1292 // "DAQ_Busy" :
1293 // tr_name;
1294 // LOGF(info,"t0_name %s", t0_name.data());
1295 // uint64_t tr_cnt = sh->RawT0Counters()[rh->T0Map()[make_pair(t0_name, 0)]];
1296
1297 uint64_t tr_cnt = sh->Scalers()[tr_name];
1298 if (trimScalersByLastEvent)
1299 if ((iSpill == 0)
1300 || (iSpill == NSpills - 1)) // for the first/last spill trim MSC by event timestamp range
1301 {
1302 if (msc->GetEntries()) {
1303 BmnMSCMatrix<uint8_t>* mscMatrix = static_cast<BmnMSCMatrix<uint8_t>*>(msc->At(0));
1304 auto& firstTP = sh->GetFirstEventTime();
1305 auto& lastTP = sh->GetLastEventTime();
1306 LOGF(info, "Events:\n\tfirst %s\n\tlast %s", BmnFunctionSet::TimePoint2String(firstTP).c_str(),
1307 BmnFunctionSet::TimePoint2String(lastTP).c_str());
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);
1311 tr_cnt = sum;
1312 }
1313 }
1314 runScalers[tr_name] += tr_cnt;
1315
1316 Double_t rf = tcc[tr_name].reduction_en ? (tcc[tr_name].reduction_factor + 1) : 1;
1317 // Double_t rf = rfs[tr_name];
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);
1321 // LOGF(info,"\tT0 %-14s = %10llu ; after reduction %10.2f", tr_name.c_str(), tr_cnt,
1322 // tr_cnt_ar);
1323 uint64_t ev_tr_cnt = sh->EventTriggerCnt()[tr_name];
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);
1327 sup_evt_cnt[i]->Fill(fract, sh->GetNEvents());
1328 }
1329 }
1330 LOGF(info, "Evt trigger count Total:");
1331 LOGF(info, "Total %8lu events", rh->GetNEvents());
1332 for (auto& el : rh->GetTrcBitMap()) {
1333 const string& tr_name = el.first;
1334 LOGF(info, "%-12s %8lu", tr_name.c_str(), rh->EventTriggerCnt()[tr_name]);
1335 }
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)
1340 continue;
1341 LOGF(info, "T0 %-14s.%02u = %10lu", key.first.c_str(), key.second,
1342 rh->GetRawT0Counter(key.first.c_str(), key.second));
1343 }
1344 LOGF(info, "MSC Total:");
1345 rh->PrintScalers();
1346 if (rh) {
1347 LOGF(info, "Total spill counters:");
1348 for (auto& tr_name : evt_tr_names) {
1349 // string t0_name =
1350 // (tr_name == "nFD") ?
1351 // "FHCal_v2" :
1352 // (tr_name == "MBT") ?
1353 // "DAQ_Busy" :
1354 // tr_name;
1355 // uint64_t tr_cnt = rh->GetRawT0Counter(t0_name);
1356 // uint64_t tr_cnt = rh->GetScaler(tr_name);
1357 uint64_t tr_cnt = runScalers[tr_name];
1358 Double_t rf = tcc[tr_name].reduction_en ? (tcc[tr_name].reduction_factor + 1) : 1;
1359 // Double_t rf = rfs[tr_name];
1360 Double_t tr_cnt_ar = tr_cnt / rf;
1361 LOGF(info, "\tT0 %-14s = %10lu ; after reduction %10.2f", tr_name.c_str(), tr_cnt, tr_cnt_ar);
1362 uint64_t ev_tr_cnt = rh->EventTriggerCnt()[tr_name];
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);
1365 }
1366 }
1367 for (size_t i = 0; i < trigCount; i++) {
1368 can->cd(i + 1);
1369 evt_tr_hist[i]->Draw();
1370 canSupEvnts->cd(i + 1);
1371 sup_evt_cnt[i]->Draw("colz");
1372 }
1373 can->SaveAs(Form("run%d_supFactor.png", RunId));
1374 canSupEvnts->SaveAs(Form("run%d_supFactor_EvtCnt.png", RunId));
1375 // file->Close();
1376 return kBMNSUCCESS;
1377}
TCanvas * can(nullptr)
int i
Definition P4_F32vec4.h:22
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition P4_F32vec4.h:30
int Int_t
unsigned char UChar_t
constexpr UInt_t kMaxUInt
double Double_t
long long Long64_t
unsigned long long ULong64_t
#define BIT(n)
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
BmnStatus
Define status code.
Definition BmnEnums.h:93
@ kBMNERROR
Error.
Definition BmnEnums.h:95
@ kBMNSUCCESS
Success.
Definition BmnEnums.h:94
@ kBMNSETUP
Definition BmnEnums.h:166
std::chrono::time_point< SysClock > SysPoint
std::unordered_map< std::string, uint16_t > NameChMap
Definition BmnAliases.h:7
std::pair< std::string, uint16_t > T0MapKey
Definition BmnAliases.h:5
#define DBGERR(a)
Definition BmnMath.h:25
const uint8_t MSC_EC_BUSY
Definition RawTypes.h:90
const uint32_t MSC_N_COUNTERS
Definition RawTypes.h:88
const uint8_t MSC_EC_SPILL
Definition RawTypes.h:89
const uint32_t kT0_BIN_BLOCK_WORDS
Definition RawTypes.h:93
SysPoint GetEventTimeTP()
UInt_t GetEventId()
Get the event ID for this event.
UInt_t GetInputSignalsAR()
Get Input signal states, after reduction.
static std::string TimePoint2String(SysPoint p)
static SysPoint TimeStamp2TP(TTimeStamp p)
static TTimeStamp TimePoint2TS(SysPoint p)
UInt_t GetSerial() const
Definition BmnMSCDigit.h:61
SysPoint GetTime() const
Definition BmnMSCDigit.h:67
bool IsSpill()
Definition BmnMSCDigit.h:73
bool IsBusy()
Definition BmnMSCDigit.h:75
std::array< IntType, MSC_N_COUNTERS > & GetValue()
Definition BmnMSCDigit.h:65
Storage for all MSC counters of the spill.
auto & SpillRangeVec()
const size_t GetNRecords()
void SetTime(const size_t &record_id, const SysPoint &time)
we assume the user is filling the timestamps in the chronological order on the basis of preliminary c...
void SetMissingHits(uint32_t val)
bool GetIsSpill(const SysPoint &time)
void SetCount(size_t record_id, uint16_t scaler_id, IntType val)
bool GetIsBusy(const SysPoint &time)
uint64_t GetCntInRange(const string &scaler_name, const SysPoint &timeBegin=SysPoint::min(), const SysPoint &timeEnd=SysPoint::max())
SysPoint & GetTime(const size_t &record_id)
const IntType GetCount(size_t record_id, const string &scaler_name)
auto & BusyRangeVec()
Raw MSC block with zero suppression and for one specific channel.
uint32_t GetMissingHits()
SysPoint GetTime() const
std::vector< IntType > & GetValues()
uint8_t GetChannel() const
uint32_t GetSerial() const
std::vector< TTimeStamp > & GetTimes()
std::vector< uint8_t > & GetExtCond()
size_t GetNVals()
unique_ptr< TFile > fT0RawStorageFile
unique_ptr< TTree > fT0RawStorageTree
T0ChMap fRawT0Map
Raw T0 module map (from Sergeev txt).
static BmnStatus ReadSpillStat(const string &FileName, const vector< string > &EvtTrNames={ "BT'", "MBT", "CCT1", "nFD"})
vector< string > fTarFileNames
vector< string > scalers_index2name_map
BmnMetadataDecoder(vector< string > file={}, string outfile="", ULong_t period=8, BmnSetup setup=kBMNSETUP)
vector< string > fDigiFileNames
void GenerateBusyRanges(BmnMSCMatrix< uint8_t > *matrix, boost::dynamic_bitset<> &bitVecSpill, boost::dynamic_bitset<> &bitVecBusy)
map< uint16_t, uint16_t > trcIdx2scalerIdx
BmnStatus SetTarDirectory(string DirName)
BmnEventHeader * inEventHeader
void AddT0Raw2Headers(BmnT0Raw *el)
BmnStatus SetDigiDirectory(string fDigiDir)
BmnSpillHeader * spillHeader
map< SysPoint, BmnSpillInfo > fSpillMap
NameChMap fTrcBitMap
TRC bit map.
unique_ptr< DigiRunHeader > digiRunHeader
map< std::pair< uint32_t, uint16_t >, uint16_t > scalers2index_map
TString GetSubNameAfterRunId(TString name)
unique_ptr< BmnTrigRaw2Digit > fTrigMapper
unique_ptr< std::map< TTimeStamp, int64_t > > fT0RawStorageTsMap
Name2SerCh fScalersMap
MSC map.
TClonesArray * fT0RawStorageArr
Class BmnMetadataRaw for the configuration and raw spill information.
const SysPoint GetFirstEventTime()
Get time the first event in the spill.
const TTimeStamp & GetFirstEventTS()
Get time the first event in the spill.
const TTimeStamp & GetStartTS()
Get the start TS.
const TTimeStamp & GetLastEventTS()
Get time the last event in the spill.
UInt_t GetNEvents()
Get the event count in the spill.
MapString2Cnt & EventTriggerCnt()
const SysPoint GetLastEventTime()
Get time the last event in the spill.
MapString2Cnt & Scalers()
array< UInt_t, kT0_BIN_BLOCK_WORDS > & RawT0Counters()
const TTimeStamp & GetStopTS()
Get the stop TS.
T0 module spill settings and counts.
Definition BmnT0Raw.h:70
std::array< uint32_t, kT0_BIN_BLOCK_WORDS > & Counters()
Definition BmnT0Raw.h:115
SysPoint GetTime()
Definition BmnT0Raw.h:92
TTimeStamp GetTS()
Definition BmnT0Raw.h:96
Dur_ns GetTimeSinceLastEv()
Definition BmnT0Raw.h:107
Double_t GetTimeSinceLastEvNs()
Definition BmnT0Raw.h:113
Class BmnTrigConfig Trigger DAQ config.
unordered_map< string, BmnTrigChannelConfig > & TrigChannelConfig()
NameChMap & GetTrcBitMap()
TRC bit map.
uint64_t GetPeriodId()
Get the period ID for this run.
uint64_t GetRunId()
Get the run ID.
T0ChMap & T0Map()
Ref to the T0 map.
TTimeStamp GetRunEndTime()
TTimeStamp GetRunStartTime()
BmnTrigConfig & GetTrigConfig()
Get DAQ trigger config.
uint64_t GetNEvents()
Get the event count.
MapString2Cnt & EventTriggerCnt()
uint64_t GetRawT0Counter(string name, uint32_t ch=0)
RInterface< RDFDetail::RFilter< F, Proxied >, DS_t > Filter(F f, const ColumnNames_t &columns={}, std::string_view name="")
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
TObjArray * GetListOfBranches() override
virtual Int_t Add(const char *name, Long64_t nentries=TTree::kMaxEntries)
Long64_t GetEntries() const override
Int_t GetEntry(Long64_t entry=0, Int_t getall=0) override
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
friend friend class TClonesArray
static TClass * Class()
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)
Double_t RealTime()
void Start(Bool_t reset=kTRUE)
Double_t CpuTime()
void Stop()
Ssiz_t Length() const
static constexpr Ssiz_t kNPOS
const char * Data() const
Ssiz_t Last(char c) const
const char * AsString(const Option_t *option="") const
virtual void SetBranchStatus(const char *bname, bool status=true, UInt_t *found=nullptr)
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
static void SetMaxTreeSize(Long64_t maxsize=100000000000LL)
virtual Long64_t GetEntries() const
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
/home/soul/bmnroot/database/uni_db1/UniRawFile.h Class for the table: raw_file
Definition UniRawFile.h:19
TString GetFilePath()
get file path of the current raw file
Definition UniRawFile.h:110
UniRun.h Class for the table: run_.
Definition UniRun.h:21
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition UniRun.cxx:161
TObjArray * GetRawFiles()
get array of raw files (UniRawFile*) corresponding to the run (return nullptr if an error occured)
Definition UniRun.cxx:798
SysPoint stop_ts
std::vector< SpillStatus > vec_spill_status
SysPoint start_ts
SpillCntrs< SpillStatus::counters_cnt > counters
void ResizeTo(const SpillCntrs &example)
Definition SpillCntrs.h:16
Class SpillStatus raw spill status from JSON block.
Definition SpillStatus.h:20
static const size_t counters_cnt
Definition SpillStatus.h:38