BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnMetadataTest.C
Go to the documentation of this file.
1
2
#include <
ROOT/RDF/RInterface.hxx
>
3
#include <
ROOT/RDataFrame.hxx
>
4
#include <filesystem>
5
6
namespace
fs = std::filesystem;
7
using
SysClock
= std::chrono::system_clock;
8
using
SysPoint
= std::chrono::time_point<SysClock>;
9
10
SysPoint
fRunStartTime
;
11
SysPoint
fRunEndTime
;
12
UInt_t
fRunId
;
13
UInt_t
fPeriodId
;
14
bool
get_run_interval_from_file
=
false
;
15
unique_ptr<DigiRunHeader>
digiRunHeader
;
16
vector<string>
fDigiFileNames
;
17
18
void
GatherStatusBlocksFromDigis
()
19
{
20
// try get run interval from DB
21
if
(!
get_run_interval_from_file
) {
22
UniRun
* pRun =
UniRun::GetRun
(
fPeriodId
,
fRunId
);
23
if
(!pRun) {
24
get_run_interval_from_file
=
true
;
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
32
get_run_interval_from_file
=
true
;
33
printf(
"Set Run from DB:\n\tstart ts: %s\n\tstop ts: %s\n"
,
34
BmnFunctionSet::TimePoint2String
(
fRunStartTime
).c_str(),
35
BmnFunctionSet::TimePoint2String
(
fRunEndTime
).c_str());
36
delete
pRun;
37
}
38
}
39
}
40
41
void
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
}
77
GatherStatusBlocksFromDigis
();
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
}
RDataFrame.hxx
RInterface.hxx
UInt_t
unsigned int UInt_t
Double_t
double Double_t
ULong64_t
unsigned long long ULong64_t
BIT
#define BIT(n)
Form
char * Form(const char *fmt,...)
gSystem
R__EXTERN TSystem * gSystem
SysClock
std::chrono::system_clock SysClock
Definition
BmnFunctionSet.h:17
SysPoint
std::chrono::time_point< SysClock > SysPoint
Definition
BmnFunctionSet.h:18
BmnEventHeader
Definition
BmnEventHeader.h:24
BmnEventHeader::GetInputSignalsAR
UInt_t GetInputSignalsAR()
Get Input signal states, after reduction.
Definition
BmnEventHeader.h:127
BmnFunctionSet::TimePoint2String
static std::string TimePoint2String(SysPoint p)
Definition
BmnFunctionSet.cxx:618
BmnMetadataRaw
Class BmnMetadataRaw for the configuration and raw spill information.
Definition
BmnMetadataRaw.h:28
DigiRunHeader
Definition
DigiRunHeader.h:21
DigiRunHeader::GetNEvents
uint64_t GetNEvents()
Get the event count.
Definition
DigiRunHeader.h:79
DigiRunHeader::EventTriggerCnt
MapString2Cnt & EventTriggerCnt()
Definition
DigiRunHeader.h:123
DigiRunHeader::GetRawT0Counter
uint64_t GetRawT0Counter(string name, uint32_t ch=0)
Definition
DigiRunHeader.cxx:31
ROOT::RDataFrame
TDatime
TDatime::Convert
UInt_t Convert(Bool_t toGMT=kFALSE) const
TDirectoryFile::Get
T * Get(const char *namecycle)
TFile
TFile::IsOpen
virtual Bool_t IsOpen() const
TPRegexp
TPRegexp::MatchB
Bool_t MatchB(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
TStopwatch
TStopwatch::RealTime
Double_t RealTime()
TStopwatch::Start
void Start(Bool_t reset=kTRUE)
TStopwatch::CpuTime
Double_t CpuTime()
TStopwatch::Stop
void Stop()
TString
UniRun
UniRun.h Class for the table: run_.
Definition
UniRun.h:21
UniRun::GetRun
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition
UniRun.cxx:161
UniRun::GetEndDatetime
TDatime * GetEndDatetime()
get end datetime of the current run
Definition
UniRun.h:101
UniRun::GetStartDatetime
TDatime GetStartDatetime()
get start datetime of the current run
Definition
UniRun.h:99
get_run_interval_from_file
bool get_run_interval_from_file
Definition
BmnMetadataTest.C:14
fRunId
UInt_t fRunId
Definition
BmnMetadataTest.C:12
digiRunHeader
unique_ptr< DigiRunHeader > digiRunHeader
Definition
BmnMetadataTest.C:15
fDigiFileNames
vector< string > fDigiFileNames
Definition
BmnMetadataTest.C:16
fRunStartTime
SysPoint fRunStartTime
Definition
BmnMetadataTest.C:10
fRunEndTime
SysPoint fRunEndTime
Definition
BmnMetadataTest.C:11
fPeriodId
UInt_t fPeriodId
Definition
BmnMetadataTest.C:13
GatherStatusBlocksFromDigis
void GatherStatusBlocksFromDigis()
Definition
BmnMetadataTest.C:18
BmnMetadataTest
void BmnMetadataTest(vector< string > files, TString meta_file, UInt_t run_id, UInt_t period=8)
Definition
BmnMetadataTest.C:41
macro
raw
BmnMetadataTest.C
Generated on
for BmnRoot by
1.17.0