BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
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
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
59using json = nlohmann::json;
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
96
97 void SetSpillMap(map<SysPoint, BmnSpillInfo> spillMap) { fSpillMap = spillMap; }
98
99 map<SysPoint, BmnSpillInfo> GetSpillMap() { return fSpillMap; }
100
102
103 void Close()
104 {
105 fThreads->Terminate();
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;
119 uint32_t fPeriodId;
120 uint32_t fRunId;
121 BmnEventType fCurEvType; // = kBMNPAYLOAD; // for converter
122 // BmnEventType fPrevEvType = kBMNPAYLOAD; // for converter
123 // bool isRawRootInputFile;
126
127 uint32_t fEventId;
128
136
137 // TFile* fRootFileOut;
138
139 // header array
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;
157
158 map<TTimeStamp, Int_t> leaps;
162 map<SysPoint, BmnSpillInfo> fSpillMap;
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);
169 void QuickProcessEvent(UInt_t* d, UInt_t& len);
170 void QuickConvertStatEvent(UInt_t* buf, UInt_t& len);
171 /**
172 * QuickProcessEvent reduced version in order to skip additional memcpy
173 * and read raw data directly into the thread's buffer
174 * @param tmp thread pointer
175 * @param len data length
176 */
177 void QuickProcessEvent(BmnConverterThread*& tmp, UInt_t& len);
178 void QuickConvertStatEvent(BmnConverterThread*& tmp, UInt_t& len);
181
184
186};
187
188#endif
__m128 v
Definition P4_F32vec4.h:1
bool Bool_t
int Int_t
constexpr Bool_t kTRUE
#define ClassDef(name, id)
BmnStatus
Define status code.
Definition BmnEnums.h:93
std::chrono::time_point< SysClock > SysPoint
void SetDecoderConfigFileName(string FileName)
uint32_t fRunId
void QuickProcessEvent(UInt_t *d, UInt_t &len)
map< int32_t, MapTP2TreePE > treeTimeMapDiv
BmnStatus ParseJsonTLV(UInt_t *buf, UInt_t &len)
Bool_t fExportJsonBlocks
TString fRawRunHdrName
uint32_t data[10000000]
BmnConverterThread * fCurWaitingThread
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)
TString fRootDirPath
multimap< SysPoint, TreePE > treeTimeMap
const TTimeStamp TimeZero
void ReproduceBranches(TTree *inTree, TTree *outTree)
uint32_t fPeriodId
BmnThreadManager< BmnConverterThread > * fThreads
vector< TClonesArray * > fArrVec
uint32_t fThreadCnt
void QuickConvertStatEvent(UInt_t *buf, UInt_t &len)
BmnStatus LoadConfig()
map< int32_t, multimap< SysPoint, TreePos > > treeMapSpills
vector< TObject * > fNamVec
unique_ptr< DigiRunHeader > runHeader
void SeparateEventsBySpills()
unique_ptr< BmnMetadataRaw > metadata
map< int32_t, map< int32_t, TreePos > > treeMap
void SetSpillMap(map< SysPoint, BmnSpillInfo > spillMap)
void SetPeriod(uint32_t v)
TString fRawTreeName
BmnConverter(uint32_t threadCount=0, uint32_t period=8, TString outDir=".", bool tempFileOnDisk=false)
BmnStatus CreateTempFile()
TString fMetadataName
map< SysPoint, BmnSpillInfo > fSpillMap
uint32_t fEventId
virtual ~BmnConverter()
BmnEventType fCurEvType
static BmnStatus ParseComplexTLV(UInt_t *buf, UInt_t &len, UInt_t &runId)
BmnStatus ConvertRawToRootIterateFileRead()
pt::ptree conf
void SeparateEventsBySpillsTM()
TString fRawTreeSpillName
TTimeStamp utc_valid
bool GetTempFileOnDisk()
bool temp_file_on_disk
void SetRunId(uint32_t v)
TString fSubName
map< TTimeStamp, Int_t > leaps
FILE * fRawFileIn
map< SysPoint, BmnSpillInfo > GetSpillMap()
BmnSpillHeader * spillHeader
uint32_t fDat
vector< pair< int, pair< int, int > > > vecTree
Int_t GetUTCShift(TTimeStamp t)
Int_t GetSpillNumber(vector< SysPoint > *spillEnds, vector< SysPoint > *spillStarts, SysPoint time)
BmnStatus InitUTCShift()
TString fRootFileName
unique_ptr< ROOT::TBufferMerger > fMerger
string fDecoderConfigFileName
vector< pair< int, pair< int, int > > > vecTreeSpills
multimap< SysPoint, TreePE > MapTP2TreePE
pair< uint32_t, uint64_t > TreePos
pair< TTree *, uint64_t > TreePE
basic_json<> json
default specialization
Definition json.hpp:3365