BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnMetadataTest.C
Go to the documentation of this file.
1
3#include <ROOT/RDataFrame.hxx>
4#include <filesystem>
5
6namespace fs = std::filesystem;
7using SysClock = std::chrono::system_clock;
8using SysPoint = std::chrono::time_point<SysClock>;
9
15unique_ptr<DigiRunHeader> digiRunHeader;
16vector<string> fDigiFileNames;
17
19{
20 // try get run interval from DB
23 if (!pRun) {
25 } else {
26 TDatime fRunStartDate = pRun->GetStartDatetime();
27 TDatime* fRunEndDate = pRun->GetEndDatetime();
28 fRunStartTime = SysClock::from_time_t(fRunStartDate.Convert(true)) - 3h; // crutch for zone shift
29 if (fRunEndDate)
30 fRunEndTime = SysClock::from_time_t(fRunEndDate->Convert(true)) - 3h;
31 else
33 printf("Set Run from DB:\n\tstart ts: %s\n\tstop ts: %s\n",
36 delete pRun;
37 }
38 }
39}
40
41void BmnMetadataTest(vector<string> files, TString meta_file, UInt_t run_id, UInt_t period = 8)
42{
43 gSystem->ExpandPathName(meta_file);
44 // ROOT::EnableImplicitMT();
45 FairLogger::GetLogger()->SetLogToScreen(true);
46 FairLogger::GetLogger()->SetLogScreenLevel("info"); // for info write "INFO"
47
48 TStopwatch timer;
49 timer.Start();
50 fDigiFileNames = files;
51 fRunId = run_id;
52 fPeriodId = period;
53 string tar_dir = "/ncx/eos/nica/bmn/exp/digi/run8/24.04.0/0_technichal_info/";
54 // string dig_dir = "/ncx/eos/nica/bmn/exp/digi/run8/24.04.0/";
55 // string dig_dir = "/home/ilnur/filesbmn/";
56 // string dig_dir = "/ncx/eos/nica/bmn/users/ilnur/spill_test/";
57 string dig_dir = "/home/ilnur/spill_test/";
58 // string dig_dir = "/data/spill_test/";
59 // string dig_dir = "/mnt/ddc/ceph/bmn/work/ilnur/spill_test/";
60 // string dig_dir = "/mnt/ddc/eos/lpp/nica/bmn/users/ilnur/spill_test/";
61
62 if (files.size() == 0) {
63 string re_str(Form(".*%d(_ev\\d+_p\\d+)[^\\/]*\\.root", run_id));
64 TPRegexp re_dig(re_str);
65 // Check if the path exists and is a directory
66 // if (fs::exists(dig_dir) && fs::is_directory(dig_dir)) {
67 std::cout << "Target files in a directory: " << dig_dir << std::endl;
68 // Iterate through the directory
69 for (const auto& entry : std::filesystem::directory_iterator(dig_dir)) {
70 string fileName = entry.path();
71 if (re_dig.MatchB(fileName)) {
72 std::cout << entry.path().filename() << std::endl;
73 files.push_back(fileName.data());
74 }
75 }
76 }
78 // count activated triggers in events
79 TFile* file = new TFile(meta_file, "READ");
80 if (file->IsOpen() == false) {
81 cout << "Cannot open file " << meta_file << " !" << endl;
82 return;
83 }
84 DigiRunHeader* rh = static_cast<DigiRunHeader*>(file->Get("DigiRunHeader"));
85 BmnMetadataRaw* metadata = static_cast<BmnMetadataRaw*>(file->Get("RawRunMetadata"));
86 map<string, uint16_t>& tr_map = rh->TrcBitMap();
87 // map<string, uint16_t> tr_map = {
88 // std::pair("BC1L", 0),
89 // std::pair("pBT", 1),
90 // std::pair("BT", 2),
91 // std::pair("NiT", 3),
92 // std::pair("CCT1", 4),
93 // std::pair("MBT", 5),
94 // std::pair("BT&nBUSY", 6),
95 // std::pair("CCT2", 7)
96 // };
97 ROOT::RDataFrame df{"bmndata", files};
98 ROOT::RDataFrame df_spill{"spill", meta_file};
99 auto df_run = df;
100 auto df_spill_run = df_spill;
101 printf("Evt_cnt total %7u\n", rh->GetNEvents());
102 for (auto& el : tr_map) {
103 const string& tr_name = el.first;
104 printf("Evt_cnt %-12s %7lu\n", tr_name.c_str(), rh->EventTriggerCnt()[tr_name]);
105 }
106 auto df_sp_BT_CCT2 = df_run.Filter(
107 [&](BmnEventHeader& eh) {
108 return ((eh.GetInputSignalsAR() & BIT(tr_map["BT"])) && (eh.GetInputSignalsAR() & BIT(tr_map["CCT2"])));
109 },
110 {"BmnEventHeader."});
111 ULong64_t df_sp_BT_CCT2_cnt = *(df_sp_BT_CCT2.Count());
112 printf("Evt_cnt BT_CCT2 %7llu \n", df_sp_BT_CCT2_cnt);
113 printf("Evt_cnt (BT_CCT2/BT) %5.4f \n", df_sp_BT_CCT2_cnt / (Double_t)rh->EventTriggerCnt()["BT"]);
114
115 printf("T0 CCT2 = %10llu\n", rh->GetRawT0Counter("CCT2"));
116 printf("T0 BT = %10llu\n", rh->GetRawT0Counter("BT"));
117 printf("T0 (CCT2/BT) %5.4f \n", rh->GetRawT0Counter("CCT2") / (Double_t)rh->GetRawT0Counter("BT"));
118
119 timer.Stop();
120 printf("\tMacro finished successfully!\n\n"); // marker of successfully execution
121 Double_t rtime = timer.RealTime();
122 Double_t ctime = timer.CpuTime();
123 printf("All steps: Real time %f s, CPU time %f s\n", rtime, ctime);
124}
unsigned int UInt_t
double Double_t
unsigned long long ULong64_t
#define BIT(n)
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
std::chrono::system_clock SysClock
std::chrono::time_point< SysClock > SysPoint
UInt_t GetInputSignalsAR()
Get Input signal states, after reduction.
static std::string TimePoint2String(SysPoint p)
Class BmnMetadataRaw for the configuration and raw spill information.
uint64_t GetNEvents()
Get the event count.
MapString2Cnt & EventTriggerCnt()
uint64_t GetRawT0Counter(string name, uint32_t ch=0)
UInt_t Convert(Bool_t toGMT=kFALSE) const
T * Get(const char *namecycle)
virtual Bool_t IsOpen() const
Bool_t MatchB(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
Double_t RealTime()
void Start(Bool_t reset=kTRUE)
Double_t CpuTime()
void Stop()
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
TDatime * GetEndDatetime()
get end datetime of the current run
Definition UniRun.h:101
TDatime GetStartDatetime()
get start datetime of the current run
Definition UniRun.h:99
bool get_run_interval_from_file
UInt_t fRunId
unique_ptr< DigiRunHeader > digiRunHeader
void GatherStatusBlocksFromDigis()
void BmnMetadataTest(vector< string > files, TString meta_file, UInt_t run_id, UInt_t period=8)
vector< string > fDigiFileNames
SysPoint fRunStartTime
SysPoint fRunEndTime
UInt_t fPeriodId