BmnRoot 26.10.0-233-gb9bbe585
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"
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>(fPeriodId, 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());
363 fDigiTreeSpills->Branch("T0Raw", &t0_copy);
364
365 size_t msc_entries_cnt_total(0); // all MSC times (to check presence of MSC outside spills)
366 size_t msc_entries_cnt(0); // MSC entries inside spills
367 // make map (time_point -> (i-tree entry,i-digit)) to sort and rearrange MSC by time
368 typedef pair<Long64_t, Int_t> Index_Pair; // (i-tree entry,i-digit)
369 map<SysPoint, vector<Index_Pair>> mts; // for period 8
370 // map<SysPoint, size_t> time2times_map_entry;
371 vector<pair<SysPoint, size_t>> vts_t0; // for period 8
372
373 // map<SysPoint, vector<uint8_t>> mts9; // for period 9
374
375 LOGF(info, "Start filling timestamp map");
376 timer.Start();
377 if (fPeriodId > 8) {
378 for (Long64_t iEntry = 0; iEntry < fInTreeSpills->GetEntries(); ++iEntry) {
379 fInTreeSpills->GetEntry(iEntry);
380 /** General time map (high memory usage) */
381 //// df_spills.Foreach(
382 //// [&](TClonesArray& msc_in) {
383 //// for (Int_t iDig = 0; iDig < msc_in.GetEntries(); ++iDig) {
384 //// BmnMSCZSDigit<uint8_t>* dig = static_cast<BmnMSCZSDigit<uint8_t>*>(msc_in.At(iDig));
385 // for (Int_t iDig = 0; iDig < msc->GetEntries(); ++iDig) {
386 // BmnMSCZSDigit<uint8_t>* dig = static_cast<BmnMSCZSDigit<uint8_t>*>(msc->At(iDig));
387 // auto index_it = scalers2index_map.find(make_pair(dig->GetSerial(), dig->GetChannel()));
388 // if (index_it == scalers2index_map.end())
389 // continue;
390 // uint8_t index = index_it->second;
391 // vector<SysPoint>& times = dig->GetTimes();
392 // vector<uint8_t>& values = dig->GetValues();
393 // vector<uint8_t>& excs = dig->GetExtCond();
394 // for (size_t iTime= 0; iTime< dig->GetNVals(); iTime++){
395 // SysPoint& time = times[iTime];
396 // auto it = mts9.find(time);
397 // if (it == mts9.end()){
398 // vector<uint8_t> tarr(scalers_ar_size+1, 0); // scalers + ext conditions
399 // tarr[index] = values[iTime];
400 // tarr[scalers_ar_size] = excs[iTime];
401 // mts9.insert(make_pair(time, move(tarr)));
402 // } else{
403 // vector<uint8_t>& tarr = it->second;
404 // tarr[index] += values[iTime];
405 // tarr[scalers_ar_size] = excs[iTime];
406 // }
407 // }
408 // }
409 //// },
410 //// {"MSC"});
411
412 Int_t ne_t0 = t0raw->GetEntries();
413 if (ne_t0 > 0) {
414 BmnT0Raw* dig = static_cast<BmnT0Raw*>(t0raw->At(0));
415 vts_t0.push_back(make_pair(dig->GetTime() - ((Long64_t)t0raw_shift_av) * 1ns - 1s,
416 iEntry)); // crutch to fit rough time inside the spill
417 LOG(info) << "T0 time " << BmnFunctionSet::TimePoint2String(dig->GetTime()) << " iEntry " << iEntry;
418 }
419 }
420 } else {
421 for (Long64_t iEntry = 0; iEntry < fInTreeSpills->GetEntries(); ++iEntry) {
422 fInTreeSpills->GetEntry(iEntry);
423 for (Int_t iDig = 0; iDig < msc->GetEntries(); ++iDig) {
424 BmnMSCDigit<UChar_t>* dig = static_cast<BmnMSCDigit<UChar_t>*>(msc->At(iDig));
425 mts[dig->GetTime()].push_back(make_pair(iEntry, iDig));
426 // msc_entries_cnt_total++;
427 }
428 Int_t ne_t0 = t0raw->GetEntries();
429 if (ne_t0 > 0) {
430 BmnT0Raw* dig = static_cast<BmnT0Raw*>(t0raw->At(0));
431 vts_t0.push_back(make_pair(dig->GetTime() - ((Long64_t)t0raw_shift_av) * 1ns - 1s,
432 iEntry)); // crutch to fit rough time inside the spill
433 LOG(info) << "T0 time " << BmnFunctionSet::TimePoint2String(dig->GetTime()) << " iEntry " << iEntry;
434 }
435 }
436 // size_t i_rec{0};
437 // for (auto &rec : mts)
438 // time2times_map_entry[rec.first] = i_rec++;
439 msc_entries_cnt_total = mts.size();
440 }
441 timer.Stop();
442 rtime = timer.RealTime();
443 ctime = timer.CpuTime();
444 LOGF(info, "Real time %f s, CPU time %f s timestamp map filling", rtime, ctime);
445
446 LOGF(info, "Run:\n\tstart ts: %s\n\tstop ts: %s", BmnFunctionSet::TimePoint2String(fRunStartTime),
448 UInt_t spillId = 0;
449 ULong64_t n_events_run(0);
450 for (auto& mapel : fSpillMap) {
452 BmnSpillInfo& si = mapel.second;
453 LOGF(info, "");
454 LOGF(info, "***********************************************************");
455 LOGF(info, "Spill:\n\tstart ts: %s\n\tstop ts: %s", BmnFunctionSet::TimePoint2String(si.start_ts),
457 if ((fRunStartTime > si.stop_ts) || (fRunEndTime < si.start_ts)) {
458 LOGF(warning, "Spill is outside the run! Skipping!");
459 continue;
460 }
461 // count activated triggers in events
462 timer.Start();
463 auto df_events_in_spill = df.Filter(
464 [&](BmnEventHeader& eh) {
465 return ((eh.GetEventTimeTP() >= si.start_ts) && (eh.GetEventTimeTP() <= si.stop_ts));
466 },
467 {"BmnEventHeader."});
468 ULong64_t cnt[32] = {};
469 UInt_t first_ev_id(kMaxUInt);
470 UInt_t last_ev_id(0);
471 SysPoint first_ev_tp;
472 SysPoint last_ev_tp;
473 // SysPoint first_trigger_tp{SysPoint::max()}; // first MSC trigger time in the spill
474 // SysPoint last_trigger_tp{SysPoint::min()}; // last MSC trigger time in the spill
475 // SysPoint first_trigger_tp_captured{SysPoint::max()}; // first MSC trigger time in the spill and the
476 // run SysPoint last_trigger_tp_captured{SysPoint::min()}; // last MSC trigger time in the spill and the
477 // run SysPoint first_l2_tp{SysPoint::max()}; // first MSC trigger time in the spill SysPoint
478 // last_l2_tp{SysPoint::min()}; // last MSC trigger time in the spill
479 auto df_events_in_spill_trig_cntr = df_events_in_spill.Filter(
480 [&](BmnEventHeader& eh) {
481 for (auto& el : digiRunHeader->GetTrcBitMap()) {
482 if (eh.GetInputSignalsAR() & BIT(el.second))
483 cnt[el.second]++;
484 }
485 if (first_ev_id > eh.GetEventId()) {
486 first_ev_id = eh.GetEventId();
487 first_ev_tp = eh.GetEventTimeTP();
488 }
489 if (last_ev_id < eh.GetEventId()) {
490 last_ev_id = eh.GetEventId();
491 last_ev_tp = eh.GetEventTimeTP();
492 }
493 return true;
494 },
495 {"BmnEventHeader."});
496 ULong64_t n_events = *(df_events_in_spill_trig_cntr.Count());
497 LOGF(info, "\tfirst ts: %s\n\tlast ts: %s", BmnFunctionSet::TimePoint2String(first_ev_tp),
499 n_events_run += n_events;
500 LOGF(info, "Events in the spill %7llu", n_events);
501 // cut entries outside run in the first and last spills
502 SysPoint spillRangeImposedStart; // set spill start time by hand
503 SysPoint spillRangeImposedStop; // set spill stop time by hand
504 if ((spillId == 0) || (spillId == fSpillMap.size() - 1)) {
505 spillRangeImposedStart = first_ev_tp;
506 spillRangeImposedStop = last_ev_tp;
507 } else {
508 spillRangeImposedStart = si.start_ts;
509 spillRangeImposedStop = si.stop_ts;
510 }
511 spillHeader->SetStartTime(si.start_ts);
512 spillHeader->SetStopTime(si.stop_ts);
513 spillHeader->SetSpillId(spillId++);
514 spillHeader->SetNEvents(n_events);
515 spillHeader->SetFirstEventId(first_ev_id);
516 spillHeader->SetLastEventId(last_ev_id);
517 spillHeader->SetFirstEventTime(first_ev_tp);
518 spillHeader->SetLastEventTime(last_ev_tp);
519 for (auto& el : digiRunHeader->GetTrcBitMap()) {
520 const string& tr_name = el.first;
521 spillHeader->EventTriggerCnt()[tr_name] = cnt[el.second];
522 digiRunHeader->EventTriggerCnt()[tr_name] += spillHeader->EventTriggerCnt()[tr_name];
523 LOGF(info, "Evt_cnt %-11s %7llu", tr_name.c_str(), cnt[el.second]);
524 }
525 timer.Stop();
526 rtime = timer.RealTime();
527 ctime = timer.CpuTime();
528 LOGF(info, "Real time %f s, CPU time %f s ev cnt calc", rtime, ctime);
529
530 // calc T0 count inside spill
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;
534 timer.Start();
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); });
537 timer.Stop();
538 rtime = timer.RealTime();
539 ctime = timer.CpuTime();
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);
542
543 LOGF(info, "Start scalers calc");
544 timer.Start();
545
546 // string ScalerNumeratorForEvalName = "L2_Trig";
547 // string ScalerDenominatorForEvalName = "BT'";
548 // uint16_t iScalerNumeratorForEval = scalers_name2index_map[ScalerNumeratorForEvalName];
549 // uint16_t iScalerDenominatorForEval = scalers_name2index_map[ScalerDenominatorForEvalName];
550 // double bt_cap_sum = 0; // count of the selected MSC trigger in the file event time range
551 // double msc_l2_count = 0; // MSC l2 trigger count (assuming all l2 triggers written as events)
552 vector<uint64_t> scalerVec(scalers_ar_size, 0); // spill scalers count vector
553
554 if (fPeriodId > 8) {
555 // calc MSC count inside spill
556 auto df_spill = df_spills.Filter(
557 [&](TClonesArray& tca) {
558 for (Int_t iDig = 0; iDig < tca.GetEntries(); ++iDig) {
559 BmnMSCZSDigit<uint8_t>* dig = static_cast<BmnMSCZSDigit<uint8_t>*>(tca.At(iDig));
560 auto index_it = scalers2index_map.find(make_pair(dig->GetSerial(), dig->GetChannel()));
561 if (index_it == scalers2index_map.end())
562 return false;
563 return ((dig->GetTime() >= si.start_ts) && (dig->GetTime() <= si.stop_ts));
564 }
565 return false;
566 },
567 {"MSC"});
568 /** Local time map (longer calculation, less memory use) */
569 uint32_t missing_hits = 0;
570 map<SysPoint, vector<uint8_t>> mts9; // for period 9
571 df_spill.Foreach(
572 [&](TClonesArray& tca) {
573 for (Int_t iDig = 0; iDig < tca.GetEntries(); ++iDig) {
574 BmnMSCZSDigit<uint8_t>* dig = static_cast<BmnMSCZSDigit<uint8_t>*>(tca.At(iDig));
575 auto index_it = scalers2index_map.find(make_pair(dig->GetSerial(), dig->GetChannel()));
576 if (index_it == scalers2index_map.end())
577 continue;
578 missing_hits += dig->GetMissingHits();
579 uint8_t index = index_it->second;
580 auto& times = dig->GetTimes();
581 vector<uint8_t>& values = dig->GetValues();
582 vector<uint8_t>& excs = dig->GetExtCond();
583 for (size_t iTime = 0; iTime < dig->GetNVals(); iTime++) {
584 // SysPoint& time = times[iTime];
585 SysPoint time = BmnFunctionSet::TimeStamp2TP(times[iTime]);
586 auto it = mts9.find(time);
587 if (it == mts9.end()) {
588 vector<uint8_t> tarr(scalers_ar_size + 1, 0); // scalers + ext conditions
589 tarr[index] = values[iTime];
590 tarr[scalers_ar_size] = excs[iTime];
591 mts9.insert(make_pair(time, move(tarr)));
592 } else {
593 vector<uint8_t>& tarr = it->second;
594 tarr[index] += values[iTime];
595 tarr[scalers_ar_size] = excs[iTime];
596 }
597 }
598 }
599 },
600 {"MSC"});
601
602 auto itLower = mts9.lower_bound(spillRangeImposedStart);
603 auto itUpper = mts9.upper_bound(spillRangeImposedStop);
604 size_t spillTimesCount = std::distance(itLower, itUpper);
605 // size_t spillTimesCount = mts9.size();
606 msc_entries_cnt += spillTimesCount;
607 msc_entries_cnt_total += mts9.size();
608 LOGF(info, "Spill times count %lld", spillTimesCount);
609 // create single MSC matrix object for spill
610 BmnMSCMatrix<uint8_t>* msc_matrix = new ((*msc_copy)[msc_copy->GetEntries()])
612 msc_matrix->SetMissingHits(missing_hits);
613 // spillHeader->ScalersVec().resize(scalers_ar_size, 0);
614 // Fill MSC matrix elements
615 size_t i_record{0};
616 boost::dynamic_bitset<> bitVecSpill(spillTimesCount, false);
617 boost::dynamic_bitset<> bitVecBusy(spillTimesCount, false);
618 // for (auto & [time, vals] : mts9) {
619 for (auto itTimes = itLower; itTimes != itUpper; itTimes++) {
620 auto& time = itTimes->first;
621 vector<uint8_t>& vals = itTimes->second;
622 // msc_matrix->Time(i_record) = time;
623 msc_matrix->SetTime(i_record, time);
624 uint8_t ext_cond = vals[scalers_ar_size];
625 bitVecSpill[i_record] = ext_cond & MSC_EC_SPILL;
626 bitVecBusy[i_record] = ext_cond & MSC_EC_BUSY;
627 // msc_matrix->IsSpillBitVec()[i_record] = ext_cond & MSC_EC_SPILL;
628 // msc_matrix->IsBusyBitVec()[i_record] = ext_cond & MSC_EC_BUSY;
629 for (uint16_t iScaler = 0; iScaler < scalers_ar_size; iScaler++) {
630 if (vals[iScaler] == 0)
631 continue;
632 msc_matrix->SetCount(i_record, iScaler, vals[iScaler]);
633 // msc_matrix->Counts()(i_record, iScaler) = vals[iScaler];
634 // spillHeader->Scalers()[name] += vals[iScaler];
635
636 // spillHeader->ScalersVec()[iScaler] += vals[iScaler];
637 scalerVec[iScaler] += vals[iScaler];
638 LOGF(debug, "el %8llu %2lu count %3u sp %u busy %u GC", i_record, iScaler,
639 (UChar_t)(msc_matrix->GetCount(i_record, iScaler)), (UInt_t)msc_matrix->GetIsSpill(time),
640 (UInt_t)msc_matrix->GetIsBusy(time));
641 // (UInt_t)msc_matrix->IsSpillBitVec()[i_record],
642 // (UInt_t)msc_matrix->IsBusyBitVec()[i_record]);
643 }
644 i_record++;
645 }
646 if (i_record > spillTimesCount)
647 LOGF(error, "\n\t ERROR!!! irec %lu spillTimesCount %lu\n", i_record, spillTimesCount);
648 GenerateBusyRanges(msc_matrix, bitVecSpill, bitVecBusy);
649 } else {
650 // calc MSC count inside spill
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);
655 // size_t spillTimesShift = std::distance(mts.begin(), itLower);
656 for (auto itTimes = itLower; itTimes != itUpper; itTimes++) {
657 vector<Index_Pair>& index_vec = itTimes->second;
658 spillEntriesCumulativeSize += index_vec.size();
659 }
660 // msc_entries_cnt += spillEntriesCumulativeSize;
661 msc_entries_cnt += spillTimesCount;
662 LOGF(info, "entriesCumulativeSize %lld", spillEntriesCumulativeSize);
663 LOGF(info, "Spill times count %lld", spillTimesCount);
664 // LOGF(info, "Spill times shift %lld", spillTimesShift);
665
666 // create single MSC matrix object for spill
667 BmnMSCMatrix<uint8_t>* msc_matrix = new ((*msc_copy)[msc_copy->GetEntries()])
669 // BmnMSCMatrix<UChar_t>(spillTimesCount, scalers_ar_size);
670 // spillHeader->ScalersVec().resize(scalers_ar_size, 0);
671
672 // Fill MSC matrix elements
673 size_t i_record{0};
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;
678 // msc_matrix->Time(i_record) = time;
679 msc_matrix->SetTime(i_record, time);
680 vector<Index_Pair>& index_vec = itTimes->second;
681 // msc_entries_cnt += index_vec.size();
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;
688 fInTreeSpills->GetEntry(iEntry);
689 if (iDig >= msc->GetEntries()) {
690 LOGF(error, "\n\t ERROR!!! iDig %d msc->GetEntries() %d\n", iDig, msc->GetEntries());
691 break;
692 }
693 BmnMSCDigit<UChar_t>* dig = static_cast<BmnMSCDigit<UChar_t>*>(msc->At(iDig));
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());
698 }
699 bitVecSpill[i_record] = dig->IsSpill();
700 bitVecBusy[i_record] = dig->IsBusy();
701 // msc_matrix->IsSpillBitVec()[i_record] = dig->IsSpill();
702 // msc_matrix->IsBusyBitVec()[i_record] = dig->IsBusy();
703 for (UInt_t iNum = 0; iNum < MSC_N_COUNTERS; iNum++) {
704 UInt_t val = dig->GetValue()[iNum];
705 // if (val == 0)
706 // continue;
707 // auto it = scalers2name_map.find(make_pair(dig->GetSerial(), iNum));
708 // if (it == scalers2name_map.end())
709 // continue;
710 // string& name = it->second;
711 auto it = scalers2index_map.find(make_pair(dig->GetSerial(), iNum));
712 if (it == scalers2index_map.end())
713 continue;
714 uint16_t iScaler = it->second;
715 // msc_matrix->Counts(i_record, iScaler) += val;
716 // msc_matrix->Counts()(i_record, iScaler) += val;
717 msc_matrix->SetCount(i_record, iScaler, val);
718 // 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,
721 dig->GetSerial(), (UChar_t)(msc_matrix->GetCount(i_record, iScaler)),
722 // (UChar_t)(msc_matrix->Counts()(i_record, iScaler)),
723 (UInt_t)msc_matrix->GetIsSpill(time), (UInt_t)msc_matrix->GetIsBusy(time));
724 // (UInt_t)msc_matrix->IsSpillBitVec()[i_record],
725 // (UInt_t)msc_matrix->IsBusyBitVec()[i_record]);
726 // spillHeader->Scalers()[name] += val;
727 // spillHeader->ScalersVec()[iScaler] += val;
728 scalerVec[iScaler] += val;
729 }
730 }
731 i_record++;
732 }
733 if (i_record > spillTimesCount)
734 LOGF(error, "\n\t ERROR!!! irec %lu spillTimesCount %lu\n", i_record, spillTimesCount);
735 GenerateBusyRanges(msc_matrix, bitVecSpill, bitVecBusy);
736 }
737
738 // for (Long64_t iEntry = 0; iEntry < fInTreeSpills->GetEntries(); ++iEntry) {
739 // fInTreeSpills->GetEntry(iEntry);
740 // for (Int_t iDig = 0; iDig < msc->GetEntries(); ++iDig) {
741 // BmnMSCDigit<UChar_t>* dig = static_cast<BmnMSCDigit<UChar_t>*>(msc->At(iDig));
742 // size_t i_record = time2times_map_entry[dig->GetTime()] - spillTimesShift;
743 // LOGF(info, "iEntry %7d iDig %3d el %8llu ", iEntry, iDig, i_record);
744 // msc_matrix->Time(i_record) = dig->GetTime();
745 // msc_matrix->IsSpillBitVec()[i_record] = dig->IsSpill();
746 // msc_matrix->IsBusyBitVec()[i_record] = dig->IsBusy();
747 // for (UInt_t iNum = 0; iNum < MSC_N_COUNTERS; iNum++) {
748 // UInt_t val = dig->GetValue()[iNum];
749 // if (val == 0)
750 // continue;
751 // // auto it = scalers2name_map.find(make_pair(dig->GetSerial(), iNum));
752 // // if (it == scalers2name_map.end())
753 // // continue;
754 // // string& name = it->second;
755 // auto it = scalers2index_map.find(make_pair(dig->GetSerial(), iNum));
756 // if (it == scalers2index_map.end())
757 // continue;
758 // uint16_t index = it->second;
759 // msc_matrix->Counts(i_record, index) += val;
760 // LOGF(debug, "el %8llu %2lu = %u sp %u busy %u",
761 // i_record,
762 // index,
763 // (UChar_t)(msc_matrix->Counts(i_record, index)),
764 // (UInt_t)msc_matrix->IsSpillBitVec()[i_record],
765 // (UInt_t)msc_matrix->IsBusyBitVec()[i_record]);
766 // // spillHeader->Scalers()[name] += val;
767 // spillHeader->ScalersVec()[index] += val;
768 // scalerVec[index] += val;
769 // }
770 // }
771 // }
772 for (auto& p : spillIds_t0) {
773 Long64_t iEntry = p.second;
774 fInTreeSpills->GetEntry(iEntry);
775 t0_copy->AbsorbObjects(t0raw);
776 }
777 for (int i = 0; i < scalers_ar_size; i++)
778 // digiRunHeader->ScalersVec()[i] += spillHeader->ScalersVec()[i];
779 digiRunHeader->ScalersVec()[i] += scalerVec[i];
780 // for (auto& scaler_map_el : spillHeader->Scalers()) {
781 // const string& sc_name = scaler_map_el.first;
782 // metadata.Scalers()[sc_name] += spillHeader->Scalers()[sc_name];
783 // }
784 timer.Stop();
785 rtime = timer.RealTime();
786 ctime = timer.CpuTime();
787 LOGF(info, "Real time %f s, CPU time %f s Scalers calc", rtime, ctime);
788
789 for (size_t iSc = 0; iSc < scalers_index2name_map.size(); iSc++) {
790 const string& name = scalers_index2name_map[iSc];
791 // uint64_t& val = spillHeader->ScalersVec()[iSc];
792 uint64_t& val = scalerVec[iSc];
793 spillHeader->Scalers()[name] = val;
794 LOGF(info, "MSC %-14s %10llu", name.c_str(), val);
795 }
796
797 if (t0_copy->GetEntries()) {
798 BmnT0Raw* t0r = static_cast<BmnT0Raw*>(t0_copy->At(0));
799 AddT0Raw2Headers(t0r);
800 if (t0_copy->GetEntries() > 1)
801 LOGF(error, "More than 1 T0 in the spill %lu ! %d records found", spillHeader->GetSpillId(),
802 t0_copy->GetEntries());
803 } else {
804 LOGF(warning, "No T0 in the spill %lu ! We'll try to recover it from the T0 storage file.",
805 spillHeader->GetSpillId());
806 if (fT0RawStorageTsMap) {
807 LOGF(info, "Searching for T0 in the storage");
808 TTimeStamp t0StopTS(BmnFunctionSet::TimePoint2TS(si.stop_ts - 1s + ((Long64_t)t0raw_shift_av) * 1ns));
809 auto itLower = fT0RawStorageTsMap->lower_bound(t0StopTS);
810 if (itLower != fT0RawStorageTsMap->end()) {
811 LOGF(info, "Found at timestamp %s entry %u", (itLower->first).AsString(), itLower->second);
812 fT0RawStorageTree->GetEntry(itLower->second);
813 t0_copy->AbsorbObjects(fT0RawStorageArr);
814 if (t0_copy->GetEntries()) {
815 BmnT0Raw* t0r = static_cast<BmnT0Raw*>(t0_copy->At(0));
816 AddT0Raw2Headers(t0r);
817 // AddT0Raw2Headers(t0r, bt_cap_frac);
818 }
819 } else
820 LOGF(error, "%s timestamp not found in the T0 storage!", t0StopTS.AsString());
821 } else
822 LOGF(error, "No T0 storage! Skipping");
823 }
824 fDigiTreeSpills->Fill();
825 }
826 digiRunHeader->SetNEvents(n_events_run);
827 // this warning is not informative if we cut entries outside run in the first/last spill
828 // if (msc_entries_cnt_total > msc_entries_cnt)
829 // LOGF(warning,
830 // "MSC branch entries %9llu total\n"
831 // "MSC branch entries %9llu in spills\n"
832 // "MSC branch entries %9llu outside spills!",
833 // msc_entries_cnt_total, msc_entries_cnt, msc_entries_cnt_total - msc_entries_cnt);
834 digiRunHeader->ScalersName2IndexMap() = move(scalers_name2index_map);
835 digiRunHeader->ScalersIndex2NameMap() = move(scalers_index2name_map);
836 digiRunHeader->TrcIndex2ScalerIndexMap() = move(trcIdx2scalerIdx);
837 LOGF(info, "Evt trigger count Total:");
838 LOGF(info, "All events %8llu", digiRunHeader->GetNEvents());
839 for (auto& el : digiRunHeader->GetTrcBitMap()) {
840 const string& tr_name = el.first;
841 LOGF(info, "%-12s %8llu", tr_name.c_str(), digiRunHeader->EventTriggerCnt()[tr_name]);
842 }
843 LOGF(info, "Raw T0 Total:");
844 for (auto& t0_map_el : fRawT0Map) {
845 const T0MapKey& key = t0_map_el.first;
846 if (key.first.find("BD") == 0)
847 continue;
848 LOGF(info, "T0 %-14s.%02u = %10llu", key.first.c_str(), key.second,
849 digiRunHeader->GetRawT0Counter(key.first.c_str(), key.second));
850 }
851 LOGF(info, "MSC Total:");
852 digiRunHeader->PrintScalers();
853 delete fInTreeSpills;
854 // ROOT::DisableImplicitMT();
855 return kBMNSUCCESS;
856}
857
859 boost::dynamic_bitset<>& bitVecSpill,
860 boost::dynamic_bitset<>& bitVecBusy)
861{
862 bool insideSpill = false;
863 bool insideBusy = false;
864 SysPoint SpillRangeStart;
865 SysPoint BusyRangeStart;
866 for (size_t i_record = 0; i_record < matrix->GetNRecords(); i_record++) {
867 SysPoint& curTime = matrix->GetTime(i_record);
868 if (bitVecSpill[i_record]) {
869 if (!insideSpill) {
870 SpillRangeStart = curTime;
871 insideSpill = true;
872 }
873 } else if (insideSpill) {
874 SysPoint& SpillRangeStop = curTime;
875 matrix->SpillRangeVec().push_back(make_pair(SpillRangeStart, SpillRangeStop));
876 insideSpill = false;
877 }
878 if (bitVecBusy[i_record]) {
879 if (!insideBusy) {
880 BusyRangeStart = curTime;
881 insideBusy = true;
882 }
883 } else if (insideBusy) {
884 SysPoint& BusyRangeStop = curTime;
885 matrix->BusyRangeVec().push_back(make_pair(BusyRangeStart, BusyRangeStop));
886 insideBusy = false;
887 }
888 }
889}
890
892{
893 for (UInt_t i = 0; i < kT0_BIN_BLOCK_WORDS; i++) {
894 spillHeader->RawT0Counters()[i] = t0r->Counters()[i];
895 digiRunHeader->RawT0Counters()[i] += spillHeader->RawT0Counters()[i];
896 }
897 LOGF(info, "T0 time %s", t0r->GetTS().AsString());
898 for (auto& t0_map_el : digiRunHeader->T0Map()) {
899 const T0MapKey& key = t0_map_el.first;
900 if (key.first.find("BD") == 0)
901 continue;
902 LOGF(info, "T0 %-14s.%02u = %9llu", key.first.c_str(), key.second,
903 spillHeader->RawT0Counters()[t0_map_el.second]);
904 }
905}
906
908{
910 // sort status blocks
911 std::sort(metadata.SpillStatusVec().begin(), metadata.SpillStatusVec().end(), [](SpillStatus& a, SpillStatus& b) {
912 return ((a.start_ts < b.start_ts) || ((a.start_ts == b.start_ts) && (a.cur_spill_time_ms < b.cur_spill_time_ms))
913 // ((a.start_ts == b.start_ts) && (a.stop_ts < b.stop_ts))
914 );
915 });
916 for (SpillStatus& ss : metadata.SpillStatusVec()) {
917 LOG(debug) << BmnFunctionSet::TimePoint2String(ss.start_ts) << " start";
918 LOG(debug) << BmnFunctionSet::TimePoint2String(ss.stop_ts) << " stop";
919 }
920 // make spill map
921 for (SpillStatus& ss : metadata.SpillStatusVec()) {
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);
925 if (spill_it == fSpillMap.end()) {
926 bool inserted;
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);
930 BmnSpillInfo& si = spill_it->second;
931 si.counters.ResizeTo(ss.counters);
932 }
933 BmnSpillInfo& info = spill_it->second;
934 if (info.stop_ts < ts_spill_stop)
935 info.stop_ts = ts_spill_stop;
936 info.vec_spill_status.push_back(ss);
937 }
938 for (auto& it : fSpillMap) {
939 BmnSpillInfo& info = it.second;
940 LOGF(info, "\tstart %s\n\tstop %s", BmnFunctionSet::TimePoint2String(info.start_ts),
942 }
943 if (fSpillMap.size() == 0) {
944 LOGF(error, "Spill map is empty!");
945 return kBMNERROR;
946 }
947 // calculate counters for each spill & sum total ones
948 auto& total_cntrs = metadata.SpillCounters();
949 total_cntrs.ResizeTo(fSpillMap.begin()->second.counters);
950 for (auto& it : fSpillMap) {
951 BmnSpillInfo& info = it.second;
952 size_t blocks_count = info.vec_spill_status.size();
953 if (blocks_count == 0)
954 continue;
955 auto& first_ss = info.vec_spill_status.front();
956 auto& last_ss = info.vec_spill_status.back();
957 info.counters = last_ss.counters;
958 auto& spill_cntrs = info.counters;
959 for (size_t i = 0; i < SpillStatus::counters_cnt; i++) {
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];
964 }
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];
972 for (size_t i = 0; i < SpillStatus::counters_cnt; i++) {
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];
977 // LOGF(info, "cntr %2u input %s total %lu", i, total_p_input.first.c_str(),
978 // total_p_input.second[i]);
979 }
980 }
981 }
982 metadata.SpillMap() = fSpillMap;
983 vector<string> trc_names{"pBT", "BT", "MBT", "NiT", "BT&nBUSY", "CCT1", "CCT2"};
984 // for (auto& it : metadata.SpillMap()) {
985 // BmnSpillInfo& info = it.second;
986 // auto& spill_cntrs = info.counters;
987 // LOGF(info, "\n\tstart %s\n\tstop %s", BmnFunctionSet::TimePoint2String(info.start_ts),
988 // BmnFunctionSet::TimePoint2String(info.stop_ts));
989 // if (spill_cntrs.cntr_input.size() <= 1) {
990 // LOGF(warning, "not enough data");
991 // continue;
992 // }
993 // for (string& name : trc_names) {
994 // uint16_t icntr = fTrigBitsMap[name];
995 // LOGF(info, "\t icntr %6u %8s", icntr, name.c_str());
996 // LOGF(info, "\t%8s before %8lu after %8lu ", name.c_str(),
997 // spill_cntrs.cntr_befor_err[icntr],
998 // spill_cntrs.cntr_after_err[icntr]);
999 // LOGF(info, "\t%8s BUSY input %8lu input_red %8lu ", name.c_str(),
1000 // spill_cntrs.cntr_input[6].second[icntr], spill_cntrs.cntr_input_after_red[6].second[icntr]);
1001 // LOGF(info, "\t%8s NOT_BUSY input %8lu input_red %8lu ", name.c_str(),
1002 // spill_cntrs.cntr_input[7].second[icntr], spill_cntrs.cntr_input_after_red[7].second[icntr]);
1003 // }
1004 // }
1005 LOGF(info, "\n\tTRC TOTAL:");
1006 for (string& name : trc_names) {
1007
1008 uint16_t icntr = fTrcBitMap[name];
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]);
1016 }
1017 // SaveData();
1018 // DisposeDecoder();
1019
1020 return kBMNSUCCESS;
1021}
1022
1024{
1025 LoadConfig();
1026
1027 return kBMNSUCCESS;
1028}
1029
1031{
1032 if (fTrigMapper)
1033 fTrigMapper->ClearArrays();
1034 inEventHeader->Clear();
1035}
1036
1038{
1039 if (spillHeader)
1040 spillHeader->Clear();
1041 if (msc_copy)
1042 msc_copy->Delete();
1043 if (t0_copy)
1044 t0_copy->Delete();
1045}
1046
1048{
1049 metadata.SpillStatusVec()
1050 .clear(); // !!! temporary remove raw trc statuses from file @TODO resolve the writing issue
1051 for (auto& it : metadata.SpillMap()) {
1052 BmnSpillInfo& info = it.second;
1053 info.vec_spill_status.clear();
1054 }
1055 // gDebug = 2;
1056 LOGF(debug, "Writing run header to file");
1057 Int_t wret = fDigiFileOut->WriteObject(digiRunHeader.get(), fDigiRunHdrName.Data());
1058 if (wret > 0)
1059 LOGF(debug, "Written bytes %d", wret);
1060 else
1061 DBGERR("WriteObject")
1062
1063 LOGF(debug, "Writing metadata to file");
1064 TStopwatch timer;
1065 Double_t rtime;
1066 Double_t ctime;
1067 timer.Start();
1068 wret = fDigiFileOut->WriteObject(&metadata, fMetadataName.Data());
1069 timer.Stop();
1070 rtime = timer.RealTime();
1071 ctime = timer.CpuTime();
1072 LOGF(debug, "Real time %f s, CPU time %f s WriteObject", rtime, ctime);
1073 if (wret > 0)
1074 LOGF(debug, "Written bytes %d", wret);
1075 else
1076 DBGERR("WriteObject")
1077
1078 LOGF(debug, "Flushing other data to file");
1079 fDigiFileOut->Write();
1080 LOGF(debug, "Closing the file");
1081 fDigiFileOut->Close();
1082
1083 return kBMNSUCCESS;
1084}
1085
1087{
1088 // if (fTrigMapper)
1089 // delete fTrigMapper;
1090 // if (fMSCMapper)
1091 // delete fMSCMapper;
1092
1093 if (msc_copy)
1094 delete msc_copy;
1095 if (t0_copy)
1096 delete t0_copy;
1097
1098 if (inEventHeader)
1099 delete inEventHeader;
1100 if (spillHeader)
1101 delete spillHeader;
1102
1103 return kBMNSUCCESS;
1104}
1105
1107{
1108 TPRegexp re_data(".*\\w+_\\w+_\\w+_(\\d+)([^/]*)\\.data");
1109 TPRegexp re_raw(".*\\w+_run(\\d+)([^/]*)_raw\\.root");
1110 TString str(name);
1111 if (re_data.MatchB(str))
1112 re_data.Substitute(str, "$2");
1113 else {
1114 if (re_raw.MatchB(str))
1115 re_raw.Substitute(str, "$2");
1116
1117 else
1118 return "";
1119 }
1120 return str;
1121}
1122
1124{
1125 LOGF(debug, "%s", __func__);
1126 if (fDecoderConfigFileName.length() == 0)
1127 fDecoderConfigFileName = string(getenv("VMCWORKDIR")) + "/config/bmnconf.json";
1128 pt::read_json(fDecoderConfigFileName, conf);
1129 return kBMNSUCCESS;
1130}
1131
1133{
1134 const string tree_name = "T0RAW_ALL";
1135 const string t0raw_branch_name = "T0RAW";
1136 const string ts_map_name = "T0TsMap";
1137 fT0RawStorageFile = make_unique<TFile>(fT0RawStorageFileName.data(), "read");
1138 if (fT0RawStorageFile->IsOpen() == false) {
1139 LOGF(error, "\n!!!!\nCannot open T0 storage file %s \n!!!!", fT0RawStorageFileName.data());
1140 return kBMNERROR;
1141 }
1142 fT0RawStorageTsMap.reset(
1143 static_cast<std::map<TTimeStamp, int64_t>*>(fT0RawStorageFile->GetObjectUnchecked(ts_map_name.data())));
1144 if (!fT0RawStorageTsMap) {
1145 LOGF(error, "T0 storage timestamp map not found!");
1146 return kBMNERROR;
1147 }
1148 fT0RawStorageTree.reset(static_cast<TTree*>(fT0RawStorageFile->Get(tree_name.data())));
1149 fT0RawStorageTree->SetBranchAddress(t0raw_branch_name.data(), &fT0RawStorageArr);
1150 // LOG(info) <<fT0RawStorageTree->GetEntries();
1151 // LOG(info) <<fT0RawStorageTree->GetEntry(0);
1152 // LOG(info) <<fT0RawStorageArr->GetEntries();
1153 if (!fT0RawStorageArr) {
1154 LOGF(error, "T0 storage branch %s not found!", t0raw_branch_name.data());
1155 return kBMNERROR;
1156 }
1157 LOG(info) << fT0RawStorageFile->GetName();
1158 LOGF(info, "T0 storage loaded successfully!");
1159 return kBMNSUCCESS;
1160}
1161
1162BmnStatus BmnMetadataDecoder::ReadSpillStat(const string& FileName, const vector<string>& evt_tr_names)
1163{
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;
1169 // map<string, UInt_t> rfs;
1170 // rfs["BT"] = 2000;
1171 // rfs["MBT"] = 35;
1172 // rfs["CCT1"] = 230;
1173 // rfs["CCT2"] = 1;
1174 gStyle->SetOptStat(2211);
1175
1176 unique_ptr<TFile> file = make_unique<TFile>(FileName.data(), "READ");
1177 if (file->IsOpen() == false) {
1178 LOG(error) << "Cannot open file " << FileName << " !" << endl;
1179 return kBMNERROR;
1180 }
1181 DigiRunHeader* rh = static_cast<DigiRunHeader*>(file->Get("DigiRunHeader"));
1182 BmnMetadataRaw* metadata = static_cast<BmnMetadataRaw*>(file->Get("RawRunMetadata"));
1183
1184 if (rh == nullptr) {
1185 LOG(error) << "No run header!" << endl;
1186 return kBMNERROR;
1187 }
1188 LOGF(info, "Run Header content:");
1189 UInt_t PeriodId = rh->GetPeriodId();
1190 UInt_t RunId = rh->GetRunId();
1191 LOGF(info, "\tPeriod: %u Run: %u", PeriodId, RunId);
1192 TTimeStamp RunStartTime = rh->GetRunStartTime();
1193 TTimeStamp RunEndTime = rh->GetRunEndTime();
1194 LOGF(info, "\tSTART : %s", RunStartTime.AsString());
1195 LOGF(info, "\tFINISH : %s", RunEndTime.AsString());
1196 auto& tcc = rh->GetTrigConfig().TrigChannelConfig();
1197 // map<SysPoint, BmnSpillInfo>& fSpillMap = metadata->SpillMap();
1198 NameChMap& fTrigBitsMap = metadata->TrcMap();
1199 // Name2SerCh& fScalersMap = metadata->ScalersMap();
1200 vector<string> trc_names{"pBT", "BT", "MBT", "NiT", "BT&nBUSY", "CCT1", "CCT2"};
1201 auto& total_cntrs = metadata->SpillCounters();
1202 if (print_trc) {
1203 if (print_by_spill) {
1204 for (auto& it : metadata->SpillMap()) {
1205 BmnSpillInfo& info = it.second;
1206 auto& spill_cntrs = info.counters;
1207 LOGF(info, "\n\tstart %s\n\tstop %s", BmnFunctionSet::TimePoint2String(info.start_ts).c_str(),
1209 if (spill_cntrs.cntr_input.size() <= 1) {
1210 printf("not enough data");
1211 continue;
1212 }
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]);
1222 }
1223 }
1224 }
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]);
1235 }
1236 }
1237
1238 TTree* tree = static_cast<TTree*>(file->Get("spill"));
1239 BmnSpillHeader* sh = nullptr;
1240 TClonesArray* msc = nullptr;
1241 TClonesArray* t0raw = nullptr;
1242 tree->SetBranchStatus("*", 0);
1243 tree->SetBranchStatus("BmnSpillHeader.*", 1);
1244 tree->SetBranchStatus("T0Raw*", 1);
1245 tree->SetBranchAddress("BmnSpillHeader.", &sh);
1246 // tree->SetBranchAddress("MSC", &msc);
1247 tree->SetBranchAddress("T0Raw", &t0raw);
1248 /** canvas for trig counters per 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++) {
1255 name = TString("SupressionFactor_") + TString(evt_tr_names[i]);
1256 evt_tr_hist.push_back(make_unique<TH1I>(name, name, 500, 0, (Double_t)1));
1257 }
1258 /** canvas for evt counter vs supression factor for spill */
1259 vector<unique_ptr<TH2I>> sup_evt_cnt;
1260 name = "SupEvtCnt";
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));
1266 }
1267
1268 map<string, uint64_t> runScalers;
1269 Long64_t NSpills = tree->GetEntries();
1270 for (Int_t iSpill = 0; iSpill < NSpills; iSpill++) {
1271 tree->GetEntry(iSpill);
1272 LOGF(info, "Spill:\n\tstart ts: %s\n\tstop ts: %s", sh->GetStartTS().AsString(), sh->GetStopTS().AsString());
1273 LOGF(info, "\tfirst ts: %s\n\tlast ts: %s", sh->GetFirstEventTS().AsString(), sh->GetLastEventTS().AsString());
1274 for (auto& sca : sh->Scalers()) {
1275 LOGF(info, "MSC %-10s %8lu", sca.first.c_str(), sca.second);
1276 }
1277 if (t0raw->GetEntries()) {
1278 LOGF(info, "T0 time %s",
1279 BmnFunctionSet::TimePoint2String((static_cast<BmnT0Raw*>(t0raw->At(0)))->GetTime()).c_str());
1280 for (auto& t0_map_el : rh->T0Map()) {
1281 const T0MapKey& key = t0_map_el.first;
1282 if (key.first.find("BD") == 0)
1283 continue;
1284 LOGF(info, "T0 %-14s.%02u = %7u", key.first.c_str(), key.second, sh->RawT0Counters()[t0_map_el.second]);
1285 }
1286 }
1287 LOGF(info, "Event spill counters:");
1288 for (size_t i = 0; i < trigCount; i++) {
1289 const string& tr_name = evt_tr_names[i];
1290 // string t0_name =
1291 // (tr_name == "nFD") ?
1292 // "FHCal_v2" :
1293 // (tr_name == "MBT") ?
1294 // "DAQ_Busy" :
1295 // tr_name;
1296 // LOGF(info,"t0_name %s", t0_name.data());
1297 // uint64_t tr_cnt = sh->RawT0Counters()[rh->T0Map()[make_pair(t0_name, 0)]];
1298
1299 uint64_t tr_cnt = sh->Scalers()[tr_name];
1300 if (trimScalersByLastEvent)
1301 if ((iSpill == 0)
1302 || (iSpill == NSpills - 1)) // for the first/last spill trim MSC by event timestamp range
1303 {
1304 if (msc->GetEntries()) {
1305 BmnMSCMatrix<uint8_t>* mscMatrix = static_cast<BmnMSCMatrix<uint8_t>*>(msc->At(0));
1306 auto& firstTP = sh->GetFirstEventTime();
1307 auto& lastTP = sh->GetLastEventTime();
1308 LOGF(info, "Events:\n\tfirst %s\n\tlast %s", BmnFunctionSet::TimePoint2String(firstTP).c_str(),
1309 BmnFunctionSet::TimePoint2String(lastTP).c_str());
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);
1313 tr_cnt = sum;
1314 }
1315 }
1316 runScalers[tr_name] += tr_cnt;
1317
1318 Double_t rf = tcc[tr_name].reduction_en ? (tcc[tr_name].reduction_factor + 1) : 1;
1319 // Double_t rf = rfs[tr_name];
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);
1323 // LOGF(info,"\tT0 %-14s = %10llu ; after reduction %10.2f", tr_name.c_str(), tr_cnt,
1324 // tr_cnt_ar);
1325 uint64_t ev_tr_cnt = sh->EventTriggerCnt()[tr_name];
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);
1329 sup_evt_cnt[i]->Fill(fract, sh->GetNEvents());
1330 }
1331 }
1332 LOGF(info, "Evt trigger count Total:");
1333 LOGF(info, "Total %8lu events", rh->GetNEvents());
1334 for (auto& el : rh->GetTrcBitMap()) {
1335 const string& tr_name = el.first;
1336 LOGF(info, "%-12s %8lu", tr_name.c_str(), rh->EventTriggerCnt()[tr_name]);
1337 }
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)
1342 continue;
1343 LOGF(info, "T0 %-14s.%02u = %10lu", key.first.c_str(), key.second,
1344 rh->GetRawT0Counter(key.first.c_str(), key.second));
1345 }
1346 LOGF(info, "MSC Total:");
1347 rh->PrintScalers();
1348 if (rh) {
1349 LOGF(info, "Total spill counters:");
1350 for (auto& tr_name : evt_tr_names) {
1351 // string t0_name =
1352 // (tr_name == "nFD") ?
1353 // "FHCal_v2" :
1354 // (tr_name == "MBT") ?
1355 // "DAQ_Busy" :
1356 // tr_name;
1357 // uint64_t tr_cnt = rh->GetRawT0Counter(t0_name);
1358 // uint64_t tr_cnt = rh->GetScaler(tr_name);
1359 uint64_t tr_cnt = runScalers[tr_name];
1360 Double_t rf = tcc[tr_name].reduction_en ? (tcc[tr_name].reduction_factor + 1) : 1;
1361 // Double_t rf = rfs[tr_name];
1362 Double_t tr_cnt_ar = tr_cnt / rf;
1363 LOGF(info, "\tT0 %-14s = %10lu ; after reduction %10.2f", tr_name.c_str(), tr_cnt, tr_cnt_ar);
1364 uint64_t ev_tr_cnt = rh->EventTriggerCnt()[tr_name];
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);
1367 }
1368 }
1369 for (size_t i = 0; i < trigCount; i++) {
1370 can->cd(i + 1);
1371 evt_tr_hist[i]->Draw();
1372 canSupEvnts->cd(i + 1);
1373 sup_evt_cnt[i]->Draw("colz");
1374 }
1375 can->SaveAs(Form("run%d_supFactor.png", RunId));
1376 canSupEvnts->SaveAs(Form("run%d_supFactor_EvtCnt.png", RunId));
1377 // file->Close();
1378 return kBMNSUCCESS;
1379}
std::unordered_map< std::string, uint16_t > NameChMap
Definition BmnAliases.h:7
std::pair< std::string, uint16_t > T0MapKey
Definition BmnAliases.h:5
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
#define DBGERR(a)
Definition BmnMath.h:25
TCanvas * can(nullptr)
int i
Definition P4_F32vec4.h:22
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition P4_F32vec4.h:30
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
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
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()
T0ChMap fRawT0Map
Raw T0 module map (from Sergeev txt).
vector< string > scalers_index2name_map
TClonesArray * fT0RawStorageArr
BmnSpillHeader * spillHeader
unique_ptr< TTree > fT0RawStorageTree
unique_ptr< std::map< TTimeStamp, int64_t > > fT0RawStorageTsMap
static BmnStatus ReadSpillStat(const string &FileName, const vector< string > &EvtTrNames={ "BT'", "MBT", "CCT1", "nFD"})
map< uint16_t, uint16_t > trcIdx2scalerIdx
BmnMetadataDecoder(vector< string > file={}, string outfile="", ULong_t period=8, BmnSetup setup=kBMNSETUP)
void GenerateBusyRanges(BmnMSCMatrix< uint8_t > *matrix, boost::dynamic_bitset<> &bitVecSpill, boost::dynamic_bitset<> &bitVecBusy)
BmnStatus SetTarDirectory(string DirName)
void AddT0Raw2Headers(BmnT0Raw *el)
BmnStatus SetDigiDirectory(string fDigiDir)
vector< string > fDigiFileNames
unique_ptr< DigiRunHeader > digiRunHeader
NameChMap fTrcBitMap
TRC bit map.
unique_ptr< TFile > fT0RawStorageFile
unique_ptr< BmnTrigRaw2Digit > fTrigMapper
map< SysPoint, BmnSpillInfo > fSpillMap
TString GetSubNameAfterRunId(TString name)
map< std::pair< uint32_t, uint16_t >, uint16_t > scalers2index_map
BmnEventHeader * inEventHeader
Name2SerCh fScalersMap
MSC map.
vector< string > fTarFileNames
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
SpillCntrs< SpillStatus::counters_cnt > counters
SysPoint start_ts
std::vector< SpillStatus > vec_spill_status
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