2#define BMNRAWSOURCE_H 1
11#pragma GCC system_header
13#include <boost/property_tree/json_parser.hpp>
14#include <boost/property_tree/ptree.hpp>
16#include <nlohmann/json.hpp>
18#include "TClonesArray.h"
22#include "TTimeStamp.h"
25#include "FairRootManager.h"
26#include "FairSource.h"
41#define WAIT_LIMIT 40000000
45namespace pt = boost::property_tree;
53 BmnRawSource(TString file =
"", TString outfile =
"", ULong_t nEvents = 0, ULong_t period = 8,
bool save =
false);
69 LOGF(debug,
"%s", __func__);
75 LOGF(debug,
"%s", __func__);
81 LOGF(debug1,
"FillEventHeader does nothing");
125 return (nSmpl == 128) ? 1542 : 1992;
138 fDecoderConfigFileName = FileName;
163 const TTimeStamp TimeZero = TTimeStamp(time_t(0), 0);
164 Double_t workTime_cpu = 0.0;
165 Double_t workTime_real = 0.0;
174 bool isRawRootInputFile;
179 UInt_t fNTotalEvents;
180 UInt_t fNSignalEvents;
181 UInt_t fStartEventId;
186 TTimeStamp fRunStartTime;
187 TTimeStamp fRunEndTime;
189 Long64_t fLengthRawFile;
190 Long64_t fCurentPositionRawFile;
193 TTree* fRawTreeSpills;
194 string fDecoderConfigFileName;
195 TString fRootFileName;
196 TString fRawFileName;
198 TString fRawRunHdrName;
199 TString fMetadataName;
209 TClonesArray* adc128;
214 TClonesArray* tqdc_tdc;
215 TClonesArray* tqdc_adc;
216 TClonesArray* tdc_hgnd;
225 unique_ptr<DigiRunHeader> runHeader;
227 unique_ptr<BmnMetadataRaw> metadata;
229 UInt_t data[10000000];
236 Bool_t fExportJsonBlocks;
237 Bool_t fExportExternalSpillStat;
239 UInt_t n_msc_spill = 0;
240 UInt_t n_msc_spill_ar[16] = {};
242 std::map<uint8_t, uint32_t*> time_slice_map;
244 map<TTimeStamp, Int_t> leaps;
245 TTimeStamp utc_valid;
248 map<SysPoint, BmnSpillInfo> fSpillMap;
252 template<
typename BrType>
253 void BranchRegFun(TString name, BrType** ar, TTree* tree =
nullptr)
256 FairRootManager* frm = FairRootManager::Instance();
257 frm->Register(name, name +
"_dir", (*ar), fSaveOutput);
259 TBranch* b = tree->Branch(name, ar);
260 LOGF(debug,
"Register branch %p for obj %p : %s", (
void*)b, (
void*)ar,
name.Data());
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);
276 BmnStatus Process_HRB(UInt_t* data, UInt_t len, UInt_t serial);
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);
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);
332 BmnStatus FillMSC(UInt_t*
d, UInt_t serial, UInt_t slot, UInt_t& idx);
334 void RegisterBranches();
335 void RegisterSpillBranches();
const Float_t d
Z-ccordinate of the first GEM-station.
BmnStatus ConvertRawToRoot()
UInt_t GetBoundaryRun(UInt_t nSmpl)
void SetPeriodId(UInt_t v)
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)
bool GetSaveOutput() const
UInt_t GetPeriodId() const
TString GetRootFileName()
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)
BmnStatus InitConverter()
void SetTaskMode(bool v=true)
void SetForwardMode(bool v=true)
BmnRawSource(vector< TString > files, ULong_t period=8)
BmnStatus ConvertRawToRootIterateFileRead()
BmnStatus ConvertStatEvent(UInt_t *buf, UInt_t &len)
BmnStatus wait_file(Int_t len, UInt_t limit=WAIT_LIMIT)
virtual Source_Type GetSourceType()
TTimeStamp GetRunEndTime() const
Int_t GetRunIdFromFile(TString name)
TTimeStamp GetRunStartTime() const
UInt_t GetEventId() const
void FillEventHeader(FairEventHeader *feh)
UInt_t GetNevents() const
a class to store JSON values
Defines unique identifiers (enum) for all BM@N detector systems.
basic_json<> json
default specialization