BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
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
27using std::bitset;
28using std::map;
29using std::vector;
30
31using json = nlohmann::json;
32
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);
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:
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
142};
143
144#endif
int Int_t
unsigned int UInt_t
#define ClassDef(name, id)
BmnStatus
Define status code.
Definition BmnEnums.h:93
@ kBMNERROR
Error.
Definition BmnEnums.h:95
@ kBMNSUCCESS
Success.
Definition BmnEnums.h:94
std::chrono::time_point< SysClock > SysPoint
const uint32_t kNBYTESINWORD
Definition RawTypes.h:19
static void TakeDataWords(UInt_t n, const uint32_t *d, ArrType &valI)
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.
static BmnT0Raw * Process_T0Raw(const uint32_t *d, uint32_t len, TClonesArray *t0raw=nullptr)
static TString GetSubNameAfterRunId(TString name)
static BmnStatus ParseRawT0TextConfig(string &s, BmnT0Raw *rt0dig)
static T0Config GetT0Cfg(string str)
static BmnStatus ParseRawFileName(const TString &s, BmnFileProp &prop)
static SysPoint ParseTAI(json &j, Int_t tai_utc_dif=0)
static BmnStatus ParseJsonConfig(json &j, BmnTrigConfig &trig_conf)
static BmnStatus ParseComplexTLV(const uint32_t *buf, UInt_t &len, UInt_t &runId)
static SpillStatus ParseJsonStatus(json &j, Int_t tai_utc_dif=0)
T0 module spill settings and counts.
Definition BmnT0Raw.h:70
Class BmnTrigConfig Trigger DAQ config.
Int_t GetEntriesFast() const
const char * AsString(const Option_t *option="") const
*brief user defined string literal for JSON values *sa std::size_t n
Definition json.hpp:20362
basic_json<> json
default specialization
Definition json.hpp:3365
Class SpillStatus raw spill status from JSON block.
Definition SpillStatus.h:20