BmnRoot
Loading...
Searching...
No Matches
BmnRawSource.h
Go to the documentation of this file.
1#ifndef BMNRAWSOURCE_H
2#define BMNRAWSOURCE_H 1
3
4// #define MULTITHREAD true
5// STL
6#include <bitset>
7#include <fstream>
8#include <map>
9#include <vector>
10
11#pragma GCC system_header
12// Boost
13#include <boost/property_tree/json_parser.hpp>
14#include <boost/property_tree/ptree.hpp>
15// nlohmann
16#include <nlohmann/json.hpp>
17// ROOT
18#include "TClonesArray.h"
19#include "TFile.h"
20#include "TPRegexp.h"
21#include "TString.h"
22#include "TTimeStamp.h"
23#include "TTree.h"
24// FairRoot
25#include "FairRootManager.h"
26#include "FairSource.h"
27// BmnRoot
28#include "BmnDetectorList.h"
29#include "BmnEventHeader.h"
30#include "BmnMath.h"
31#include "BmnMetadataRaw.h"
32#include "BmnSpillHeader.h"
33#include "BmnT0Raw.h"
34#include "BmnThreadManager.h"
35#include "BmnTrigConfig.h"
36#include "DigiRunHeader.h"
37#include "RawTypes.h"
38
39/********************************************************/
40// wait limit for input data (ms)
41#define WAIT_LIMIT 40000000
42
43using std::map;
44using std::vector;
45namespace pt = boost::property_tree;
46
48
49class BmnRawSource : public FairSource
50{
51 public:
52 BmnRawSource(vector<TString> files, ULong_t period = 8);
53 BmnRawSource(TString file = "", TString outfile = "", ULong_t nEvents = 0, ULong_t period = 8, bool save = false);
54 virtual ~BmnRawSource();
55
56 bool Init();
57 Int_t ReadEvent(UInt_t i = 0);
58 void Close();
59 void Reset();
60
61 Bool_t SpecifyRunId() { return kTRUE; }
62
63 virtual Source_Type GetSourceType() { return kFILE; }
64
65 virtual void SetParUnpackers() { LOGF(debug, "%s", __func__); }
66
67 virtual Bool_t InitUnpackers()
68 {
69 LOGF(debug, "%s", __func__);
70 return kTRUE;
71 }
72
73 virtual Bool_t ReInitUnpackers()
74 {
75 LOGF(debug, "%s", __func__);
76 return kTRUE;
77 }
78
79 void FillEventHeader(FairEventHeader* feh)
80 {
81 LOGF(debug1, "FillEventHeader does nothing");
82 return;
83 }
84
85 BmnStatus ParseJsonTLV(UInt_t* buf, UInt_t& len);
86 BmnStatus ConvertStatEvent(UInt_t* buf, UInt_t& len);
88 BmnStatus ConvertRawToRootIterate(UInt_t* buf, UInt_t len);
94 BmnStatus InitConverter(TString FileName);
96 BmnStatus wait_file(Int_t len, UInt_t limit = WAIT_LIMIT);
97
98 void SetRunId(UInt_t v) { fRunId = v; }
99
100 void SetPeriodId(UInt_t v) { fPeriodId = v; }
101
102 UInt_t GetRunId() const { return fRunId; }
103
104 UInt_t GetPeriodId() const { return fPeriodId; }
105
106 UInt_t GetNevents() const { return fNTotalEvents; }
107
108 UInt_t GetEventId() const { return fEventId; }
109
110 TTimeStamp GetRunStartTime() const { return fRunStartTime; }
111
112 TTimeStamp GetRunEndTime() const { return fRunEndTime; }
113
114 TString GetRootFileName() { return fRootFileName; }
115
116 void SetVerbose(Int_t v) { fVerbose = v; }
117
118 Int_t GetVerbose() const { return fVerbose; }
119
120 UInt_t GetBoundaryRun(UInt_t nSmpl)
121 {
122 // format for SILICON data was changed during March 2017 seance (run 1542)
123 // format for GEM was changed after March 2017 seance (run 1992)
124 // so we have to use this crutch.
125 return (nSmpl == 128) ? 1542 : 1992;
126 }
127
128 void SetRawRootFile(TString filename) { fRootFileName = filename; }
129
131 {
132 fCurEvType = kBMNSTAT;
133 eventHeaderDAQ->SetEventType(fCurEvType);
134 }
135
136 void SetDecoderConfigFileName(string FileName)
137 {
138 fDecoderConfigFileName = FileName;
139 LoadConfig();
140 }
141
142 TTree* GetRawTree() { return fRawTree; }
143
144 TTree* GetRawTreeSpills() { return fRawTreeSpills; }
145
146 Int_t GetRunIdFromFile(TString name);
147
148 void SetSaveOutput(bool v) { fSaveOutput = v; }
149
150 bool GetSaveOutput() const { return fSaveOutput; }
151
152 void SetTaskMode(bool v = true) { isTaskMode = v; }
153
154 bool GetTaskMode() const { return isTaskMode; }
155
156 void SetForwardMode(bool v = true) { isForwardMode = v; }
157
158 bool GetForwardMode() const { return isForwardMode; }
159
160 private:
161 // static const Int_t T0_bin_block_words = 256;//BmnT0Raw::CountersCount();
163 const TTimeStamp TimeZero = TTimeStamp(time_t(0), 0);
164 Double_t workTime_cpu = 0.0;
165 Double_t workTime_real = 0.0;
166
167 pt::ptree conf;
168 bool isSpillStart;
169 bool isTaskMode;
170 bool isForwardMode;
171 UInt_t fSpillCntr;
172 BmnEventType fCurEvType = kBMNPAYLOAD; // for converter
173 BmnEventType fPrevEvType = kBMNPAYLOAD; // for converter
174 bool isRawRootInputFile;
175
176 UInt_t fRunId;
177 UInt_t fPeriodId;
178 UInt_t fEventId;
179 UInt_t fNTotalEvents;
180 UInt_t fNSignalEvents;
181 UInt_t fStartEventId;
182 // for event
183 Long64_t fTime_s;
184 Long64_t fTime_ns;
185 // for run
186 TTimeStamp fRunStartTime;
187 TTimeStamp fRunEndTime;
188
189 Long64_t fLengthRawFile;
190 Long64_t fCurentPositionRawFile;
191
192 TTree* fRawTree;
193 TTree* fRawTreeSpills;
194 string fDecoderConfigFileName;
195 TString fRootFileName;
196 TString fRawFileName;
197 TString fSubName;
198 TString fRawRunHdrName;
199 TString fMetadataName;
200
201 TFile* fRootFileIn;
202 TFile* fRootFileOut;
203 FILE* fRawFileIn;
204
205 // DAQ arrays
206 TClonesArray* sync;
207 TClonesArray* adc32; // gem
208 TClonesArray* adc64; // SiBT
209 TClonesArray* adc128; // sts
210 TClonesArray* adc; // zdc & ecal & scwall & fhcal
211 TClonesArray* vsp;
212 TClonesArray* hrb;
213 TClonesArray* tdc;
214 TClonesArray* tqdc_tdc;
215 TClonesArray* tqdc_adc;
216 TClonesArray* tdc_hgnd; // hgnd
217 // Spill tree arrays
218 TClonesArray* msc;
219 TClonesArray* t0raw;
220 BmnEventHeader* eventHeaderDAQ;
221
222 // header array
223 BmnSpillHeader* spillHeader;
224 // Raw run header
225 unique_ptr<DigiRunHeader> runHeader;
226
227 unique_ptr<BmnMetadataRaw> metadata;
228
229 UInt_t data[10000000];
230 ULong_t fMaxEvent;
231
232 UInt_t fDat; // current 32-bits word
233 UInt_t syncCounter;
234
235 UInt_t nSpillEvents;
236 Bool_t fExportJsonBlocks;
237 Bool_t fExportExternalSpillStat;
238
239 UInt_t n_msc_spill = 0;
240 UInt_t n_msc_spill_ar[16] = {};
241
242 std::map<uint8_t, uint32_t*> time_slice_map;
243
244 map<TTimeStamp, Int_t> leaps;
245 TTimeStamp utc_valid;
246 Int_t tai_utc_dif;
247 Int_t fVerbose;
248 map<SysPoint, BmnSpillInfo> fSpillMap;
249 // map<TTimeStamp, BmnSpillInfo> fSpillMap;
250 Bool_t fSaveOutput;
251
252 template<typename BrType>
253 void BranchRegFun(TString name, BrType** ar, TTree* tree = nullptr)
254 {
255 if (isTaskMode) {
256 FairRootManager* frm = FairRootManager::Instance();
257 frm->Register(name, name + "_dir", (*ar), fSaveOutput);
258 } else {
259 TBranch* b = tree->Branch(name, ar);
260 LOGF(debug, "Register branch %p for obj %p : %s", (void*)b, (void*)ar, name.Data());
261 }
262 return;
263 }
264
265 BmnStatus InitUTCShift();
266 Int_t GetUTCShift(TTimeStamp t);
267 BmnStatus GetT0Info(Double_t& t0time, Double_t& t0width);
268 BmnStatus ProcessEvent(UInt_t* data, UInt_t len);
269 void QuickProcessEvent(UInt_t* d, UInt_t len);
273 void FinalizeStat();
274
275 BmnStatus Process_FVME(UInt_t* data, UInt_t len, UInt_t serial, BmnTrigInfo& spillInfo);
276 BmnStatus Process_HRB(UInt_t* data, UInt_t len, UInt_t serial);
277 BmnStatus FillU40VE(UInt_t* d, UInt_t slot, UInt_t& idx, BmnTrigInfo& spillInfo);
278 BmnStatus FillBlockTDC(UInt_t* d, UInt_t serial, uint16_t& len, TClonesArray* ar, UInt_t modid);
279 BmnStatus FillBlockADC(UInt_t* d, UInt_t serial, uint8_t channel, uint16_t& len, TClonesArray* ar);
280 BmnStatus FillTDC(UInt_t* d, UInt_t serial, UInt_t slot, UInt_t modId, UInt_t& idx);
281 BmnStatus FillTQDC(UInt_t* d, UInt_t serial, UInt_t slot, UInt_t modId, UInt_t& idx);
290 BmnStatus FillTQDC_E(UInt_t* d, UInt_t serial, UInt_t& len);
299 BmnStatus FillMSC16VE_E(UInt_t* d, DeviceHeader* dev_hdr);
303 BmnStatus FillTDC72VXS(UInt_t* d, UInt_t serial, UInt_t& len, UInt_t modid);
307 BmnStatus FillTTVXS(UInt_t* d, UInt_t serial, UInt_t& len);
308 BmnStatus ProcessGenericDevice(UInt_t* d, DeviceHeader* dev_hdr);
312 BmnStatus FillTDC250HGND(UInt_t* d, UInt_t serial, UInt_t len);
316 BmnStatus MapVSP(UInt_t* d, DeviceHeader* dev_hdr);
317 BmnStatus FillVSP(TClonesArray* ar);
327 BmnStatus FillUT24VE_TRC(UInt_t* d, UInt_t& serial, UInt_t& len);
328 BmnStatus FillVirtualDevice(UInt_t* d, DeviceHeader* dh);
329 BmnStatus FillFVME2TMWR(UInt_t* d, UInt_t serial, UInt_t& idx, UInt_t& len);
330 inline BmnSyncDigit* FillWR(UInt_t iSerial, ULong64_t iEvent, Long64_t t_sec, Long64_t t_ns);
331
332 BmnStatus FillMSC(UInt_t* d, UInt_t serial, UInt_t slot, UInt_t& idx);
333 BmnStatus LoadConfig();
334 void RegisterBranches(); // std::function<void(TString, TObject**) > branch_reg_fun);
335 void RegisterSpillBranches(); // std::function<void(TTree* tree, TString, TObject*)> branch_reg_fun);
336 // void RegisterBranches(bool save = true);
337
338 ClassDef(BmnRawSource, 1);
339};
340
341#endif
const Float_t d
Z-ccordinate of the first GEM-station.
Definition BmnMwpcHit.cxx:7
__m128 v
Definition P4_F32vec4.h:1
int i
Definition P4_F32vec4.h:22
BmnStatus
Definition BmnEnums.h:24
BmnEventType
Definition BmnEnums.h:69
@ kBMNSTAT
Definition BmnEnums.h:73
@ kBMNPAYLOAD
Definition BmnEnums.h:71
void SetEventType(BmnEventType event_type)
Bool_t SpecifyRunId()
BmnStatus FinishRun()
BmnStatus ConvertRawToRoot()
UInt_t GetBoundaryRun(UInt_t nSmpl)
void SetPeriodId(UInt_t v)
void SetRawEventStat()
void SetRawRootFile(TString filename)
void SetSaveOutput(bool v)
void SetDecoderConfigFileName(string FileName)
BmnStatus InitConverter(TString FileName)
virtual Bool_t InitUnpackers()
BmnStatus ConvertRawToRootIterateFile(UInt_t limit=WAIT_LIMIT)
Int_t ReadEvent(UInt_t i=0)
virtual ~BmnRawSource()
bool GetSaveOutput() const
UInt_t GetPeriodId() const
TString GetRootFileName()
Int_t GetVerbose() const
BmnRawSource(TString file="", TString outfile="", ULong_t nEvents=0, ULong_t period=8, bool save=false)
BmnStatus ParseJsonTLV(UInt_t *buf, UInt_t &len)
TTree * GetRawTreeSpills()
virtual void SetParUnpackers()
virtual Bool_t ReInitUnpackers()
void ClearRawSpillArrays()
bool GetForwardMode() const
BmnStatus ConvertRawToRootIterate(UInt_t *buf, UInt_t len)
void SetVerbose(Int_t v)
BmnStatus InitConverter()
void SetTaskMode(bool v=true)
void SetForwardMode(bool v=true)
void SetRunId(UInt_t v)
BmnRawSource(vector< TString > files, ULong_t period=8)
BmnStatus ConvertRawToRootIterateFileRead()
BmnStatus ConvertStatEvent(UInt_t *buf, UInt_t &len)
void ClearRawArrays()
BmnStatus wait_file(Int_t len, UInt_t limit=WAIT_LIMIT)
virtual Source_Type GetSourceType()
bool GetTaskMode() const
TTimeStamp GetRunEndTime() const
Int_t GetRunIdFromFile(TString name)
TTimeStamp GetRunStartTime() const
UInt_t GetEventId() const
void FillEventHeader(FairEventHeader *feh)
TTree * GetRawTree()
UInt_t GetRunId() const
UInt_t GetNevents() const
a class to store JSON values
Definition json.hpp:17282
Defines unique identifiers (enum) for all BM@N detector systems.
#define WAIT_LIMIT
basic_json<> json
default specialization
Definition json.hpp:3337
name
Definition setup.py:7