BmnRoot
Loading...
Searching...
No Matches
BmnConverter.h
Go to the documentation of this file.
1#ifndef BMNCONVERTER_H
2#define BMNCONVERTER_H 1
3
4// #define MULTITHREAD true
5
6#include <bitset>
7#include <fstream>
8#include <map>
9#include <vector>
10// Boost
11// #pragma GCC system_header
12#include <boost/property_tree/json_parser.hpp>
13#include <boost/property_tree/ptree.hpp>
14// Nlohmann
15#include <nlohmann/json.hpp>
16// ROOT
17#include "TClonesArray.h"
18#include "TFile.h"
19#include "TPRegexp.h"
20#include "TROOT.h"
21#include "TString.h"
22#include "TTimeStamp.h"
23#include "TTree.h"
24
25#include <ROOT/TBufferMerger.hxx>
26// FairRoot
27#include "FairRootManager.h"
28#include "FairSource.h"
29// BmnRoot
30#include "BmnADCDigit.h"
31#include "BmnDetectorList.h"
32#include "BmnEventHeader.h"
33#include "BmnGemStripDigit.h"
34#include "BmnHRBDigit.h"
35#include "BmnMSCDigit.h"
36#include "BmnMath.h"
37#include "BmnMetadataRaw.h"
38#include "BmnSpillHeader.h"
39#include "BmnSyncDigit.h"
40#include "BmnTDCDigit.h"
41#include "BmnTQDCADCDigit.h"
42#include "BmnThreadManager.h"
43#include "BmnTrigConfig.h"
44#include "DigiRunHeader.h"
45#include "RawTypes.h"
46
47/********************************************************/
48// wait limit for input data (ms)
49#define WAIT_LIMIT 40000000
50
51typedef pair<uint32_t, uint64_t> TreePos;
52typedef pair<TTree*, uint64_t> TreePE;
53typedef multimap<SysPoint, TreePE> MapTP2TreePE;
54
55using std::map;
56using std::vector;
57namespace pt = boost::property_tree;
58
60
62{ //: public FairSource {
63 public:
64 vector<pair<int, pair<int, int>>> vecTree;
65 vector<pair<int, pair<int, int>>> vecTreeSpills;
66 // map<int32_t, multimap<SysPoint, TreePos>> treeMap; // spillId, time point, tree(thread) id, tree entry
67 // map<int32_t, multimap<SysPoint, TreePos>> treeMapSpills;
68 map<int32_t, map<int32_t, TreePos>> treeMap; // spillId, event Id, tree entry
69 map<int32_t, multimap<SysPoint, TreePos>> treeMapSpills; // spill Id, time point, tree entry
70 multimap<SysPoint, TreePE> treeTimeMap; // time point, tree ptr, tree entry
71 map<int32_t, MapTP2TreePE> treeTimeMapDiv;
73 uint32_t fThreadCnt;
74 BmnConverter(uint32_t threadCount = 0, uint32_t period = 8, TString outDir = ".", bool tempFileOnDisk = false);
75 virtual ~BmnConverter() {}
76
77 // Int_t ReadEvent(UInt_t i = 0);
78
79 static BmnStatus ParseComplexTLV(UInt_t* buf, UInt_t& len, UInt_t& runId);
80 BmnStatus ParseJsonTLV(UInt_t* buf, UInt_t& len);
81
82 void OutputSpills();
83 // BmnStatus FeedSpill(TString name, Bool_t getRunId = kTRUE, Bool_t getSubName = kTRUE);
84 BmnStatus FeedFile(TString name, Bool_t getRunId = kTRUE, Bool_t getSubName = kTRUE);
85 BmnStatus FeedEvent(UInt_t* buf, UInt_t len, Int_t type);
86
89 void ReproduceBranches(TTree* inTree, TTree* outTree);
90
91 void SetRunId(uint32_t v) { fRunId = v; }
92
93 void SetPeriod(uint32_t v) { fPeriodId = v; }
94
95 void SetSubName(TString v) { fSubName = v; }
96
97 void SetSpillMap(map<SysPoint, BmnSpillInfo> spillMap) { fSpillMap = spillMap; }
98
99 map<SysPoint, BmnSpillInfo> GetSpillMap() { return fSpillMap; }
100
101 bool GetTempFileOnDisk() { return temp_file_on_disk; }
102
103 void Close()
104 {
106 // if (fRootFileOut && fRootFileOut->IsOpen())
107 // fRootFileOut->Close();
108 }
109
110 void SetDecoderConfigFileName(string FileName) { fDecoderConfigFileName = FileName; }
111
112 void OutputTrees();
113
114 private:
115 const TTimeStamp TimeZero = TTimeStamp(time_t(0), 0);
116
117 pt::ptree conf;
118 bool temp_file_on_disk;
119 uint32_t fPeriodId;
120 uint32_t fRunId;
121 BmnEventType fCurEvType; // = kBMNPAYLOAD; // for converter
122 // BmnEventType fPrevEvType = kBMNPAYLOAD; // for converter
123 // bool isRawRootInputFile;
124 FILE* fRawFileIn;
125 TString fSubName;
126
127 uint32_t fEventId;
128
129 string fDecoderConfigFileName;
130 TString fRawRunHdrName;
131 TString fMetadataName;
132 TString fRawTreeName;
133 TString fRawTreeSpillName;
134 TString fRootFileName;
135 TString fRootDirPath;
136
137 // TFile* fRootFileOut;
138
139 // header array
140 BmnSpillHeader* spillHeader;
141 // Raw run header
142 unique_ptr<DigiRunHeader> runHeader;
143 unique_ptr<BmnMetadataRaw> metadata;
144 unique_ptr<ROOT::TBufferMerger> fMerger;
145
146 vector<TObject*> fNamVec;
147 vector<TClonesArray*> fArrVec;
148
149 uint32_t data[10000000];
150 // ULong_t fMaxEvent;
151
152 uint32_t fDat; // current 32-bits word
153 // UInt_t syncCounter;
154
155 // UInt_t nSpillEvents;
156 Bool_t fExportJsonBlocks;
157
158 map<TTimeStamp, Int_t> leaps;
159 TTimeStamp utc_valid;
160 Int_t tai_utc_dif;
161 Int_t cc = 0;
162 map<SysPoint, BmnSpillInfo> fSpillMap;
163 BmnConverterThread* fCurWaitingThread;
164 // Bool_t fSaveOutput;
165
166 Int_t GetSpillNumber(vector<SysPoint>* spillEnds, vector<SysPoint>* spillStarts, SysPoint time);
167 Int_t GetSpillNumber(vector<SysPoint>* spillEnds, vector<SysPoint>* spillStarts, TTimeStamp time);
168 BmnStatus ConvertRawToRootIterateFileRead();
169 void QuickProcessEvent(UInt_t* d, UInt_t& len);
170 void QuickConvertStatEvent(UInt_t* buf, UInt_t& len);
177 void QuickProcessEvent(BmnConverterThread*& tmp, UInt_t& len);
178 void QuickConvertStatEvent(BmnConverterThread*& tmp, UInt_t& len);
179 BmnStatus LoadConfig();
180 BmnStatus CreateTempFile();
181
182 BmnStatus InitUTCShift();
183 Int_t GetUTCShift(TTimeStamp t);
184
185 ClassDef(BmnConverter, 1);
186};
187
188#endif
const Float_t d
Z-ccordinate of the first GEM-station.
Definition BmnMwpcHit.cxx:7
__m128 v
Definition P4_F32vec4.h:1
BmnStatus
Definition BmnEnums.h:24
BmnEventType
Definition BmnEnums.h:69
std::chrono::time_point< SysClock > SysPoint
void SetDecoderConfigFileName(string FileName)
map< int32_t, MapTP2TreePE > treeTimeMapDiv
BmnStatus ParseJsonTLV(UInt_t *buf, UInt_t &len)
BmnStatus FeedEvent(UInt_t *buf, UInt_t len, Int_t type)
void SetSubName(TString v)
BmnStatus FeedFile(TString name, Bool_t getRunId=kTRUE, Bool_t getSubName=kTRUE)
multimap< SysPoint, TreePE > treeTimeMap
void ReproduceBranches(TTree *inTree, TTree *outTree)
BmnThreadManager< BmnConverterThread > * fThreads
uint32_t fThreadCnt
map< int32_t, multimap< SysPoint, TreePos > > treeMapSpills
void SeparateEventsBySpills()
map< int32_t, map< int32_t, TreePos > > treeMap
void SetSpillMap(map< SysPoint, BmnSpillInfo > spillMap)
void SetPeriod(uint32_t v)
virtual ~BmnConverter()
static BmnStatus ParseComplexTLV(UInt_t *buf, UInt_t &len, UInt_t &runId)
void SeparateEventsBySpillsTM()
bool GetTempFileOnDisk()
void SetRunId(uint32_t v)
map< SysPoint, BmnSpillInfo > GetSpillMap()
vector< pair< int, pair< int, int > > > vecTree
vector< pair< int, pair< int, int > > > vecTreeSpills
a class to store JSON values
Definition json.hpp:17282
multimap< SysPoint, TreePE > MapTP2TreePE
pair< uint32_t, uint64_t > TreePos
pair< TTree *, uint64_t > TreePE
basic_json<> json
default specialization
Definition json.hpp:3337