BmnRoot
Loading...
Searching...
No Matches
BmnConverterThread.h
Go to the documentation of this file.
1#ifndef BMNCONVERTERTHREAD_H
2#define BMNCONVERTERTHREAD_H 1
3
4#include <queue>
5#include <vector>
6// ROOT
7#include "TClonesArray.h"
8#include "TPRegexp.h"
9#include "TROOT.h"
10#include "TString.h"
11#include "TTree.h"
12
13#include <ROOT/TBufferMerger.hxx>
14// FairRoot
15#include "FairLogger.h"
16// BmnRoot
17#include "BmnAbstractThread.h"
18#include "BmnEnums.h"
19#include "BmnEventHeader.h"
20#include "BmnSyncDigit.h"
21#include "RawTypes.h"
22
23using namespace ROOT;
24
26{
27 public:
28 TTree* fRawTree;
29 TTree* fRawTreeSpills;
30 TBufferMerger* merger;
31 std::shared_ptr<TBufferMergerFile> mergerFile;
32 UInt_t rawData[10000000];
33
34 // DAQ arrays
35 TClonesArray* sync;
36 TClonesArray* adc32; // gem
37 TClonesArray* adc64; // SiBT
38 TClonesArray* adc128; // sts
39 TClonesArray* adc; // zdc & ecal & scwall & fhcal
40 TClonesArray* vsp;
41 TClonesArray* hrb;
42 TClonesArray* tdc;
43 TClonesArray* tqdc_tdc;
44 TClonesArray* tqdc_adc;
45 TClonesArray* tdc_hgnd; // hgnd
46 TClonesArray* msc;
47 TClonesArray* t0raw; // Sergeev's txt spill statistics
49
50 std::map<uint8_t, uint32_t*> time_slice_map;
51
52 struct BmnEventData
53 {
55 UInt_t fRunId;
56 UInt_t fEventId;
57 Long64_t fTime_s;
58 Long64_t fTime_ns;
59 };
60
61 BmnConverterThread(queue<Int_t>* thread_queue,
62 std::mutex* queue_access,
63 std::condition_variable* queue_wait,
64 Int_t id,
65 Bool_t measure_time = kFALSE)
66 : BmnAbstractThread(thread_queue, queue_access, queue_wait, id, measure_time)
67 , fRawTree(nullptr)
68 , fRawTreeSpills(nullptr)
69 , merger(nullptr)
70 , sync(nullptr)
71 , adc32(nullptr)
72 , adc64(nullptr)
73 , adc128(nullptr)
74 , adc(nullptr)
75 , vsp(nullptr)
76 , hrb(nullptr)
77 , tdc(nullptr)
78 , tqdc_tdc(nullptr)
79 , tqdc_adc(nullptr)
80 , tdc_hgnd(nullptr)
81 , msc(nullptr)
82 , t0raw(nullptr)
83 , eventHeaderDAQ(nullptr)
84 , tai_utc_dif(0)
85 {
86 InitUTCShift();
87 // CreateTrees();
88 }
89
93 {
94 delete fRawTree;
95 delete fRawTreeSpills;
96 }
97
103
104 void SpillEnd();
105 void SetTrees(TTree* tree, TTree* treeSpills);
106
107 void SetPeriod(UInt_t v) { fPeriodId = v; }
108
109 void SetData(Int_t taskId,
110 Int_t len = 0,
111 UInt_t* data = nullptr,
112 BmnEventType fCurEvType = kBMNEMPTY,
113 UInt_t fRunId = 7444,
114 UInt_t fEventId = -1);
115
116 void SetInitData(vector<pair<int, pair<int, int>>>* vec_tree, vector<pair<int, pair<int, int>>>* vec_tree_spills)
117 { // map<TTimeStamp, Int_t>* leaps, TTimeStamp utc_valid, Int_t tai_utc_dif){
118 this->vecTree = vec_tree;
119 this->vecTreeSpills = vec_tree_spills;
120 // this->leaps = leaps;
121 // this->utc_valid = utc_valid;
122 // this->tai_utc_dif = tai_utc_dif;
123 }
124 void SetMerger(TBufferMerger* m) { merger = m; }
126 {
127 taskId = -1;
128 Execute();
129 delete sync;
130 delete adc32;
131 delete adc64;
132 delete adc128;
133 delete adc;
134 delete vsp;
135 delete hrb;
136 delete tdc;
137 delete tqdc_tdc;
138 delete tqdc_adc;
139 delete tdc_hgnd;
140 delete msc;
141 delete t0raw;
142 delete eventHeaderDAQ;
143 // LOGF(info, "Closing converter thread %d; Waiting time: %.3fs, Calculation time: %.3fs",
144 // threadId, GetWaitingTime(), GetCalculationTime());
145 LOGF(info, "Closing converter thread %d; Waiting time: %.3fs, Calculation time: %.3fs", threadId,
146 GetWaitingCTime().count(), GetCalculationCTime().count());
147 }
148
149 void WriteTree();
152 void SetExportExternalSpillStat(bool v) { fExportExternalSpillStat = v; }
153
154 private:
155 Bool_t fExportExternalSpillStat; // export Sergeev's spill log from virtual device
156 UInt_t fPeriodId;
157
158 void WriteSpill(Int_t spillId);
159 void Calculate();
160 template<typename BrType>
161 void BranchRegFun(TString name, BrType** ar)
162 {
163 /*if (isTaskMode) {
164 cout << "Hmm";
165 FairRootManager* frm = FairRootManager::Instance();
166 frm->Register(name, name + "_dir", (*ar), fSaveOutput);
167 // TClass *cl = TClass::GetClass((*ar)->ClassName());
168 // if (cl == TClonesArray::Class())
169 // frm->Register(name, name + "_dir", static_cast<TClonesArray*> ((*ar)), fSaveOutput);
170 // else
171 // frm->Register(name, name + "_dir", static_cast<TNamed*> ((*ar)), fSaveOutput);
172 // LOG(debug1) << "Register by class " << cl->GetName() << " : " << name;
173 } else {*/
174 TBranch* b = fRawTree->Branch(name, ar);
175 LOGF(debug1, "Register branch %p : %s", (void*)b, name.Data());
176 //}
177 return;
178 }
179
180 // BmnStatus result;
181 BmnEventData fCurEvent;
182 UInt_t dataLen;
183
184 vector<pair<int, pair<int, int>>>* vecTree;
185 vector<pair<int, pair<int, int>>>* vecTreeSpills;
186
187 // Bool_t isTaskMode, fSaveOutput;
188
189 // Map to store pairs <Crate serial> - <crate time - T0 time>
190 map<TTimeStamp, Int_t> leaps;
191 TTimeStamp utc_valid;
192 Int_t tai_utc_dif;
193
194 BmnStatus InitUTCShift();
195 Int_t GetUTCShift(TTimeStamp t);
196 BmnStatus ProcessEvent(UInt_t* data, UInt_t len);
197 BmnStatus ConvertStatEvent(UInt_t* d, UInt_t& len);
198
199 BmnStatus Process_FVME(UInt_t* data, UInt_t len, UInt_t serial, BmnTrigInfo& spillInfo);
200 BmnStatus Process_HRB(UInt_t* data, UInt_t len, UInt_t serial);
201 BmnStatus FillU40VE(UInt_t* d, UInt_t slot, UInt_t& idx, BmnTrigInfo& spillInfo);
202 BmnStatus FillBlockTDC(UInt_t* d, UInt_t serial, uint16_t& len, TClonesArray* ar, UInt_t modid);
203 BmnStatus FillBlockADC(UInt_t* d, UInt_t serial, uint8_t channel, uint16_t& len, TClonesArray* ar);
204 BmnStatus FillTDC(UInt_t* d, UInt_t serial, UInt_t slot, UInt_t modId, UInt_t& idx);
205 BmnStatus FillTQDC(UInt_t* d, UInt_t serial, UInt_t slot, UInt_t modId, UInt_t& idx);
214 BmnStatus FillTQDC_E(UInt_t* d, UInt_t serial, UInt_t& len);
223 BmnStatus FillMSC16VE_E(UInt_t* d, DeviceHeader* dev_hdr);
227 BmnStatus FillTDC72VXS(UInt_t* d, UInt_t serial, UInt_t& len, UInt_t modid);
231 BmnStatus FillTTVXS(UInt_t* d, UInt_t serial, UInt_t& len);
232 BmnStatus ProcessGenericDevice(UInt_t* d, DeviceHeader* dev_hdr);
236 BmnStatus FillTDC250HGND(UInt_t* d, UInt_t serial, UInt_t len);
240 BmnStatus MapVSP(UInt_t* d, DeviceHeader* dev_hdr);
241 BmnStatus FillVSP(TClonesArray* ar);
251 BmnStatus FillUT24VE_TRC(UInt_t* d, UInt_t& serial, UInt_t& len);
252 BmnStatus FillVirtualDevice(UInt_t* d, DeviceHeader* dh);
253 BmnStatus FillFVME2TMWR(UInt_t* d, UInt_t serial, UInt_t& idx, UInt_t& len);
254 BmnStatus FillMSC(UInt_t* d, UInt_t serial, UInt_t slot, UInt_t& idx);
255 inline BmnSyncDigit* FillWR(UInt_t iSerial, ULong64_t iEvent, Long64_t t_sec, Long64_t t_ns);
256
257 ClassDef(BmnConverterThread, 1);
258};
259
260#endif
const Float_t d
Z-ccordinate of the first GEM-station.
Definition BmnMwpcHit.cxx:7
__m128 v
Definition P4_F32vec4.h:1
__m128 m
Definition P4_F32vec4.h:27
BmnStatus
Definition BmnEnums.h:24
BmnEventType
Definition BmnEnums.h:69
@ kBMNEMPTY
Definition BmnEnums.h:74
CDuration GetCalculationCTime()
CDuration GetWaitingCTime()
void SetMerger(TBufferMerger *m)
UInt_t rawData[10000000]
void SetInitData(vector< pair< int, pair< int, int > > > *vec_tree, vector< pair< int, pair< int, int > > > *vec_tree_spills)
BmnConverterThread(BmnConverterThread const &)=delete
void ClearRawSpillArrays()
TClonesArray * tqdc_tdc
BmnConverterThread(queue< Int_t > *thread_queue, std::mutex *queue_access, std::condition_variable *queue_wait, Int_t id, Bool_t measure_time=kFALSE)
void SetTrees(TTree *tree, TTree *treeSpills)
std::map< uint8_t, uint32_t * > time_slice_map
std::shared_ptr< TBufferMergerFile > mergerFile
TBufferMerger * merger
void SetExportExternalSpillStat(bool v)
TClonesArray * tqdc_adc
BmnEventHeader * eventHeaderDAQ
TClonesArray * tdc_hgnd
BmnConverterThread & operator=(BmnConverterThread const &)=delete
void SetData(Int_t taskId, Int_t len=0, UInt_t *data=nullptr, BmnEventType fCurEvType=kBMNEMPTY, UInt_t fRunId=7444, UInt_t fEventId=-1)
void RegisterSpillBranches()
Define enumerations used in tracking.