BmnRoot
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 <TString.h>
13#include <TTimeStamp.h>
14#include <TTree.h>
15// FairRoot
16#include <FairLogger.h>
17// BmnRoot
18#include <BmnADCDigit.h>
19#include <BmnEnums.h>
20#include <BmnFileProp.h>
21#include <BmnT0Raw.h>
22#include <BmnTrigConfig.h>
23#include <RawTypes.h>
24#include <SpillStatus.h>
25
26using std::bitset;
27using std::map;
28using std::vector;
29
31
33{
34 public:
35 static BmnStatus ParseComplexTLV(UInt_t* buf, UInt_t& len, UInt_t& runId);
36 static SpillStatus ParseJsonStatus(json& j, Int_t tai_utc_dif = 0);
38 static SysPoint ParseTAI(json& j, Int_t tai_utc_dif = 0);
40 static BmnStatus ParseRawFileName(TString s, BmnFileProp& prop);
41 static BmnStatus ParseRawFileName(string s, BmnFileProp& prop);
42 static TString GetSubNameAfterRunId(TString name);
43
53 template<typename IntType, typename LamType>
54 static BmnStatus Process_ADC64(UInt_t* d, UInt_t len, UInt_t serial, LamType arr_selector)
55 {
56 UInt_t index = 0;
57 TClonesArray* arr = nullptr;
58 UInt_t nSmpl = 0;
59 vector<IntType> valI;
60 while (index < len) {
61 MStreamHeader* ms = reinterpret_cast<MStreamHeader*>(d + index);
62 // LOGF(info, "ADC64[%3u/%u] %08x:", index, len ,d[index]);
63 index += sizeof(MStreamHeader) / kNBYTESINWORD;
64 // ms->Print();
65 UInt_t blockLen = ms->Len;
66 // LOGF(info, "ADC64[%3u/%u] %08x:", index, len ,d[index]);
67 switch (ms->Subtype) {
68 case 0: {
69 MStream0* ms0 = reinterpret_cast<MStream0*>(d + index);
70 index += sizeof(MStream0) / kNBYTESINWORD;
71 LOGF(debug2, "MS0 taiFlags %u TAI: %s", ms0->Tai.Flags,
72 TTimeStamp(time_t(ms0->Tai.Sec), ms0->Tai.NSec).AsString());
73 UInt_t nCh = static_cast<bitset<kNBYTESINWORD * 8>>(ms0->MaskHi).count()
74 + static_cast<bitset<kNBYTESINWORD * 8>>(ms0->MaskLo).count();
75 UInt_t payload = len - (sizeof(MStreamHeader) + sizeof(MStream0)) / kNBYTESINWORD;
76 LOGF(debug2, "serial %08X payload %6d nCh %u", serial, payload, nCh);
77 if ((nCh == 0) || (payload == 0))
78 continue;
79 // if (ms0->Tai.valid())
80 // FillWR(serial, fEventId, ms0->Tai.Sec, ms0->Tai.NSec);
81 if ((payload % nCh != 0)
82 || (payload / nCh <= (sizeof(MStreamHeader) + sizeof(MStreamTAI)) / kNBYTESINWORD))
83 return kBMNERROR;
84 nSmpl = 2 * (payload / nCh - (sizeof(MStreamHeader) + sizeof(MStreamTAI)) / kNBYTESINWORD);
85 LOGF(debug2, "serial %08X payload %6d nCh %u nSmpl %u", serial, payload, nCh, nSmpl);
86 arr = arr_selector(nSmpl);
87 valI.resize(nSmpl, 0);
88 } break;
89 case 1: {
90 if (arr) {
91 MStreamTAI* mst = reinterpret_cast<MStreamTAI*>(d + index);
92 LOGF(debug2, "MS0 taiFlags %u TAI: %s", mst->Flags,
93 TTimeStamp(time_t(mst->Sec), mst->NSec).AsString());
94 index += sizeof(MStreamTAI) / kNBYTESINWORD;
95 uint8_t iCh = ms->CustomBits;
96 TakeDataWords(nSmpl, d + index, valI);
97 new ((*arr)[arr->GetEntriesFast()]) BmnADCDigit(serial, iCh, nSmpl, valI);
98 index += nSmpl / 2 + nSmpl % 2;
99 } else
100 index += blockLen;
101 } break;
102 default:
103 LOGF(warning, "Wrong ADC64:Mstream data type %u !", ms->Subtype);
104 index += blockLen;
105 break;
106 }
107 }
108 return kBMNSUCCESS;
109 }
110
111 private:
112 enum T0Config
113 {
114 Comment,
115 Discriminators,
116 DelayLines,
117 Switches,
118 LV,
119 BDMult,
120 ExtraDelaysMask,
121 Undefined
122 };
123
124 template<typename ArrType>
125 static void TakeDataWords(UInt_t n, UInt_t* d, ArrType& valI)
126 {
127 for (UInt_t iWord = 0; iWord < n / 2; ++iWord) {
128 valI[2 * iWord + 1] =
129 d[iWord] & 0xFFFF; // take 16 lower bits and put them into corresponded cell of data-array
130 valI[2 * iWord] =
131 (d[iWord] >> 16) & 0xFFFF; // take 16 higher bits and put them into corresponded cell of data-array
132 }
133 }
134
135 static T0Config GetT0Cfg(string str);
136
137 ClassDef(BmnConverterTools, 1);
138};
139
140#endif
const Float_t d
Z-ccordinate of the first GEM-station.
Definition BmnMwpcHit.cxx:7
BmnStatus
Definition BmnEnums.h:24
@ kBMNERROR
Definition BmnEnums.h:26
@ kBMNSUCCESS
Definition BmnEnums.h:25
std::chrono::time_point< SysClock > SysPoint
const uint32_t kNBYTESINWORD
Definition RawTypes.h:19
static BmnStatus ParseComplexTLV(UInt_t *buf, UInt_t &len, UInt_t &runId)
static BmnStatus ParseRawT0TextConfig(string &s, BmnT0Raw< kT0_BIN_BLOCK_WORDS > *rt0dig)
static BmnStatus ParseJsonConfig(json &j, BmnTrigConfig &trig_conf)
static BmnStatus ParseRawFileName(string s, BmnFileProp &prop)
static BmnStatus Process_ADC64(UInt_t *d, UInt_t len, UInt_t serial, LamType arr_selector)
static SysPoint ParseTAI(json &j, Int_t tai_utc_dif=0)
static SpillStatus ParseJsonStatus(json &j, Int_t tai_utc_dif=0)
static BmnStatus ParseRawFileName(TString s, BmnFileProp &prop)
static TString GetSubNameAfterRunId(TString name)
a class to store JSON values
Definition json.hpp:17282
Define enumerations used in tracking.
basic_json<> json
default specialization
Definition json.hpp:3337