BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnConverterTools.h
Go to the documentation of this file.
1
#ifndef BMNCONVERTERTOOLS_H
2
#define BMNCONVERTERTOOLS_H 1
3
4
#include <bitset>
5
// #include <chrono>
6
// #include <map>
7
#include <string>
8
// Nlohmann
9
#include <
nlohmann/json.hpp
>
10
// ROOT
11
#include <
TClonesArray.h
>
12
#include <
TPRegexp.h
>
13
#include <
TString.h
>
14
#include <
TTimeStamp.h
>
15
#include <
TTree.h
>
16
// FairRoot
17
#include <FairLogger.h>
18
// BmnRoot
19
#include <BmnADCDigit.h>
20
#include <BmnEnums.h>
21
#include <BmnFileProp.h>
22
#include <BmnT0Raw.h>
23
#include <BmnTrigConfig.h>
24
#include <RawTypes.h>
25
#include <SpillStatus.h>
26
27
using
std::bitset;
28
using
std::map;
29
using
std::vector;
30
31
using
json =
nlohmann::json
;
32
33
class
BmnConverterTools
34
{
35
public
:
36
static
BmnStatus
ParseComplexTLV
(
const
uint32_t* buf,
UInt_t
& len,
UInt_t
& runId);
37
static
SpillStatus
ParseJsonStatus
(json& j,
Int_t
tai_utc_dif = 0);
38
static
BmnStatus
ParseJsonConfig
(json& j,
BmnTrigConfig
& trig_conf);
39
static
SysPoint
ParseTAI
(json& j,
Int_t
tai_utc_dif = 0);
40
static
BmnStatus
ParseRawT0TextConfig
(
string
& s,
BmnT0Raw
* rt0dig);
41
static
BmnStatus
ParseRawFileName
(
const
TString
& s,
BmnFileProp
& prop);
42
static
BmnStatus
ParseRawFileName
(
const
string
& s,
BmnFileProp
& prop);
43
static
TString
GetSubNameAfterRunId
(
TString
name);
44
// template<UInt_t counters_cnt = kT0_BIN_BLOCK_WORDS>
45
static
BmnT0Raw
*
Process_T0Raw
(
const
uint32_t* d, uint32_t len,
TClonesArray
* t0raw =
nullptr
);
46
47
/**
48
* Parse ADC64
49
* format Mstream Waveform V2 from https://afi.jinr.ru/MStreamWaveformDigitizer
50
* @param d Data array ptr
51
* @param len payload length
52
* @param serial Serial number
53
* @param arr_selector Function for appropriate TClonesArray selection
54
* @return kBMNSUCCESS
55
*/
56
template
<
typename
IntType,
typename
LamType>
57
static
BmnStatus
Process_ADC64
(
const
uint32_t* d,
UInt_t
len,
UInt_t
serial, LamType arr_selector)
58
{
59
UInt_t
index = 0;
60
TClonesArray
* arr =
nullptr
;
61
UInt_t
nSmpl = 0;
62
vector<IntType> valI;
63
while
(index < len) {
64
const
MStreamHeader* ms =
reinterpret_cast<
const
MStreamHeader*
>
(d + index);
65
// LOGF(info, "ADC64[%3u/%u] %08x:", index, len ,d[index]);
66
index +=
sizeof
(MStreamHeader) /
kNBYTESINWORD
;
67
// ms->Print();
68
UInt_t
blockLen = ms->Len;
69
switch
(ms->Subtype) {
70
case
0: {
71
auto
* ms0 =
reinterpret_cast<
const
MStream0*
>
(d + index);
72
index +=
sizeof
(MStream0) /
kNBYTESINWORD
;
73
LOGF(debug2,
"MS0 taiFlags %u TAI: %s"
, ms0->Tai.Flags,
74
TTimeStamp
(time_t(ms0->Tai.Sec), ms0->Tai.NSec).
AsString
());
75
UInt_t
nCh =
static_cast<
bitset<kNBYTESINWORD * 8>
>
(ms0->MaskHi).count()
76
+
static_cast<
bitset<kNBYTESINWORD * 8>
>
(ms0->MaskLo).count();
77
UInt_t
payload = len - (
sizeof
(MStreamHeader) +
sizeof
(MStream0)) /
kNBYTESINWORD
;
78
LOGF(debug2,
"serial %08X payload %6d nCh %u"
, serial, payload, nCh);
79
if
((nCh == 0) || (payload == 0))
80
continue
;
81
// if (ms0->Tai.valid())
82
// FillWR(serial, fEventId, ms0->Tai.Sec, ms0->Tai.NSec);
83
if
((payload % nCh != 0)
84
|| (payload / nCh <= (
sizeof
(MStreamHeader) +
sizeof
(MStreamTAI)) /
kNBYTESINWORD
))
85
return
kBMNERROR
;
86
nSmpl = 2 * (payload / nCh - (
sizeof
(MStreamHeader) +
sizeof
(MStreamTAI)) /
kNBYTESINWORD
);
87
LOGF(debug2,
"serial %08X payload %6d nCh %u nSmpl %u"
, serial, payload, nCh, nSmpl);
88
arr = arr_selector(nSmpl);
89
valI.resize(nSmpl, 0);
90
}
break
;
91
case
1: {
92
if
(arr) {
93
if
(valI.size() == 0)
94
valI.resize(nSmpl, 0);
95
const
MStreamTAI* mst =
reinterpret_cast<
const
MStreamTAI*
>
(d + index);
96
LOGF(debug2,
"MS0 taiFlags %u TAI: %s"
, mst->Flags,
97
TTimeStamp
(time_t(mst->Sec), mst->NSec).
AsString
());
98
index +=
sizeof
(MStreamTAI) /
kNBYTESINWORD
;
99
uint8_t iCh = ms->CustomBits;
100
TakeDataWords
(nSmpl, d + index, valI);
101
new
((*arr)[arr->
GetEntriesFast
()])
BmnADCDigit
(serial, iCh, move(valI));
102
index += nSmpl / 2 + nSmpl % 2;
103
}
else
104
index += blockLen;
105
}
break
;
106
default
:
107
LOGF(warning,
"Wrong ADC64:Mstream data type %u !"
, ms->Subtype);
108
index += blockLen;
109
break
;
110
}
111
}
112
return
kBMNSUCCESS
;
113
}
114
115
private
:
116
enum
T0Config
117
{
118
Comment
,
119
Discriminators
,
120
DelayLines
,
121
Switches
,
122
LV
,
123
BDMult
,
124
ExtraDelaysMask
,
125
Undefined
126
};
127
128
template
<
typename
ArrType>
129
static
void
TakeDataWords
(
UInt_t
n
,
const
uint32_t* d, ArrType& valI)
130
{
131
for
(
UInt_t
iWord = 0; iWord <
n
/ 2; ++iWord) {
132
valI[2 * iWord + 1] =
133
d[iWord] & 0xFFFF;
// take 16 lower bits and put them into corresponded cell of data-array
134
valI[2 * iWord] =
135
(d[iWord] >> 16) & 0xFFFF;
// take 16 higher bits and put them into corresponded cell of data-array
136
}
137
}
138
139
static
T0Config
GetT0Cfg
(
string
str);
140
141
ClassDef
(
BmnConverterTools
, 1);
142
};
143
144
#endif
Int_t
int Int_t
UInt_t
unsigned int UInt_t
ClassDef
#define ClassDef(name, id)
TClonesArray.h
TPRegexp.h
TString.h
TTimeStamp.h
TTree.h
BmnStatus
BmnStatus
Define status code.
Definition
BmnEnums.h:93
kBMNERROR
@ kBMNERROR
Error.
Definition
BmnEnums.h:95
kBMNSUCCESS
@ kBMNSUCCESS
Success.
Definition
BmnEnums.h:94
SysPoint
std::chrono::time_point< SysClock > SysPoint
Definition
BmnFunctionSet.h:18
kNBYTESINWORD
const uint32_t kNBYTESINWORD
Definition
RawTypes.h:19
BmnADCDigit
Definition
BmnADCDigit.h:12
BmnConverterTools
Definition
BmnConverterTools.h:34
BmnConverterTools::TakeDataWords
static void TakeDataWords(UInt_t n, const uint32_t *d, ArrType &valI)
Definition
BmnConverterTools.h:129
BmnConverterTools::Process_ADC64
static BmnStatus Process_ADC64(const uint32_t *d, UInt_t len, UInt_t serial, LamType arr_selector)
Parse ADC64 format Mstream Waveform V2 from https://afi.jinr.ru/MStreamWaveformDigitizer.
Definition
BmnConverterTools.h:57
BmnConverterTools::Process_T0Raw
static BmnT0Raw * Process_T0Raw(const uint32_t *d, uint32_t len, TClonesArray *t0raw=nullptr)
Definition
BmnConverterTools.cxx:45
BmnConverterTools::GetSubNameAfterRunId
static TString GetSubNameAfterRunId(TString name)
Definition
BmnConverterTools.cxx:488
BmnConverterTools::ParseRawT0TextConfig
static BmnStatus ParseRawT0TextConfig(string &s, BmnT0Raw *rt0dig)
Definition
BmnConverterTools.cxx:130
BmnConverterTools::GetT0Cfg
static T0Config GetT0Cfg(string str)
Definition
BmnConverterTools.cxx:18
BmnConverterTools::ParseRawFileName
static BmnStatus ParseRawFileName(const TString &s, BmnFileProp &prop)
Definition
BmnConverterTools.cxx:506
BmnConverterTools::ParseTAI
static SysPoint ParseTAI(json &j, Int_t tai_utc_dif=0)
BmnConverterTools::ParseJsonConfig
static BmnStatus ParseJsonConfig(json &j, BmnTrigConfig &trig_conf)
Definition
BmnConverterTools.cxx:388
BmnConverterTools::ParseComplexTLV
static BmnStatus ParseComplexTLV(const uint32_t *buf, UInt_t &len, UInt_t &runId)
BmnConverterTools::ParseJsonStatus
static SpillStatus ParseJsonStatus(json &j, Int_t tai_utc_dif=0)
BmnConverterTools::T0Config
T0Config
Definition
BmnConverterTools.h:117
BmnConverterTools::BDMult
@ BDMult
Definition
BmnConverterTools.h:123
BmnConverterTools::DelayLines
@ DelayLines
Definition
BmnConverterTools.h:120
BmnConverterTools::LV
@ LV
Definition
BmnConverterTools.h:122
BmnConverterTools::ExtraDelaysMask
@ ExtraDelaysMask
Definition
BmnConverterTools.h:124
BmnConverterTools::Undefined
@ Undefined
Definition
BmnConverterTools.h:125
BmnConverterTools::Discriminators
@ Discriminators
Definition
BmnConverterTools.h:119
BmnConverterTools::Comment
@ Comment
Definition
BmnConverterTools.h:118
BmnConverterTools::Switches
@ Switches
Definition
BmnConverterTools.h:121
BmnFileProp
Definition
BmnFileProp.h:11
BmnT0Raw
T0 module spill settings and counts.
Definition
BmnT0Raw.h:70
BmnTrigConfig
Class BmnTrigConfig Trigger DAQ config.
Definition
BmnTrigConfig.h:18
TClonesArray
TObjArray::GetEntriesFast
Int_t GetEntriesFast() const
TString
TTimeStamp
TTimeStamp::AsString
const char * AsString(const Option_t *option="") const
json.hpp
n
*brief user defined string literal for JSON values *sa std::size_t n
Definition
json.hpp:20362
nlohmann::json
basic_json<> json
default specialization
Definition
json.hpp:3365
SpillStatus
Class SpillStatus raw spill status from JSON block.
Definition
SpillStatus.h:20
decoder
BmnConverterTools.h
Generated on
for BmnRoot by
1.17.0