BmnRoot
Loading...
Searching...
No Matches
BmnOnlineDecoder.h
Go to the documentation of this file.
1#ifndef BMNONLINEDECODER_H
2#define BMNONLINEDECODER_H 1
3#include <climits>
4// #include <regex>
5// FairSoft
6#include "TBuffer.h"
7#include "TChain.h"
8#include "TClonesArray.h"
9#include "TFile.h"
10#include "TMessage.h"
11#include "TNamed.h"
12#include "TObjString.h"
13#include "TServerSocket.h"
14#include "TSocket.h"
15#include "TString.h"
16
17// BmnRoot
18#include "BmnDataReceiver.h"
19#include "BmnEventHeader.h"
20#include "BmnHist.h"
21#include "BmnMath.h"
22
23#include <BmnRawDataDecoder.h>
24
25#define RAW_DECODER_SOCKET_PORT 5555
26#define RUN_FILE_CHECK_PERIOD 1e5
27#define INOTIF_BUF_LEN (255 * (sizeof(struct inotify_event) + 255))
28#define MIN_REMNANT_LEN 300 * 1024 // crutch actually, will be removed after parser improvement
29#define MPD_EVENT_HEAD_WORDS_OLD 3 // sync + payload lenght + iEv
30#define MPD_EVENT_HEAD_WORDS 2 // sync + payload lenght
31
32#define STRIP_COMP_COLS 2
33#define PAD_WIDTH_SIL 1120
34#define PAD_HEIGHT_SIL 630
35
36using std::unique_ptr;
37using std::vector;
38
39class BmnOnlineDecoder : public TNamed
40{
41 public:
43 virtual ~BmnOnlineDecoder();
44 BmnStatus Decode(TString dirname, TString startFile, Bool_t runCurrent);
46 void ProcessStream();
48 BmnStatus BatchDirectory(TString dirname);
49 BmnStatus BatchDirectoryToSocket(TString dirname);
50
51 void SetBmnSetup(BmnSetup v) { this->fBmnSetup = v; }
52
53 BmnSetup GetBmnSetup() const { return fBmnSetup; }
54
55 void SetPeriodID(uint32_t v) { this->fPeriodID = v; }
56
57 uint32_t GetPeriodID() const { return fPeriodID; }
58
59 void SetDetectorSetup(map<DetectorId, bool> setup) { fDetectorSetup = setup; }
60
61 void SetDaqAddress(TString addr) { fDAQAddr = addr; }
62
63 void SetProcessNormEvents(bool val = true) { _do_process_norm_ev = val; }
64 void SetProcessStatEvents(bool val = true) { _do_process_stat_ev = val; }
65
66 void SetDigiSocket(uint32_t val = RAW_DECODER_SOCKET_PORT) { _digi_socket = val; }
67
68 static void StripView(TString OrigFileName,
69 TString TestFileName,
70 uint32_t periodID = 8,
71 uint32_t runID = 0,
72 BmnSetup fSetup = kBMNSETUP,
73 bool FillOccupancy = true);
74
75 private:
76 template<typename SST>
77 static void InitCanvas(TString DetName,
78 unique_ptr<SST>& stationSet,
79 TCanvas*& canStrip,
80 vector<PadInfo*>& canStripPads,
81 vector<vector<vector<TH1F*>>>* histStrip)
82 {
83 Int_t sumMods = 0;
84 Int_t maxLayers = 0;
85 Bool_t isSil = (typeid(SST) == typeid(BmnSiliconStationSet));
86 for (Int_t iCol = 0; iCol < STRIP_COMP_COLS; iCol++) {
87 for (Int_t iStation = 0; iStation < stationSet->GetNStations(); iStation++) {
88 vector<vector<TH1F*>> rowGEM;
89 auto* st = stationSet->GetStation(iStation);
90 sumMods += st->GetNModules();
91 for (Int_t iModule = 0; iModule < st->GetNModules(); iModule++) {
92 vector<TH1F*> colGEM;
93 auto* mod = st->GetModule(iModule);
94 if (isSil)
95 maxLayers = 2;
96 else {
97 if (maxLayers < mod->GetNStripLayers())
98 maxLayers = mod->GetNStripLayers();
99 }
100 for (Int_t iLayer = 0; iLayer < (isSil ? 2 : mod->GetNStripLayers()); iLayer++) {
101 auto lay = mod->GetStripLayer(iLayer);
102 if (isSil && iStation != 0) {
103 auto& lay1 = mod->GetStripLayer(iLayer * 2);
104 auto& lay2 = mod->GetStripLayer(iLayer * 2 + 1);
105 if (lay1.GetLastStripNumber() > lay2.GetLastStripNumber())
106 lay = lay1;
107 else
108 lay = lay2;
109 }
110 TString name = Form("%s_%d_Station_%d_module_%d_layer_%d", DetName.Data(), iCol, iStation,
111 iModule, iLayer);
112 // cout<< name << endl;
113 TString title = Form("Station_%d_module_%d_layer_%d", iStation, iModule, iLayer);
114 TH1F* h;
115 if (isSil)
116 h = new TH1F(name, title, lay.GetLastStripNumber() + 1, 0, lay.GetLastStripNumber() + 1);
117 else
118 h = new TH1F(name, title, lay.GetNStrips(), 0, lay.GetNStrips());
119 h->GetXaxis()->SetTitle("Strip Number");
120 h->GetYaxis()->SetTitle("Activation Count");
122 colGEM.push_back(h);
123 }
124 rowGEM.push_back(colGEM);
125 }
126 histStrip[iCol].push_back(rowGEM);
127 }
128 }
129 sumMods = sumMods / STRIP_COMP_COLS;
130 TString name = DetName + "Canvas";
131 canStrip = new TCanvas(name, name, PAD_WIDTH_SIL * maxLayers, PAD_HEIGHT_SIL * sumMods);
132 canStrip->Divide(maxLayers, sumMods, 0.01 / maxLayers, 0.01 / sumMods);
133 Int_t modCtr = 0;
134 canStripPads.resize(sumMods * maxLayers, nullptr);
135 for (Int_t iStation = 0; iStation < stationSet->GetNStations(); iStation++) {
136 auto* st = stationSet->GetStation(iStation);
137 for (Int_t iModule = 0; iModule < st->GetNModules(); iModule++) {
138 auto* mod = st->GetModule(iModule);
139 for (Int_t iLayer = 0; iLayer < (isSil ? 2 : mod->GetNStripLayers()); iLayer++) {
140 Int_t iPad = modCtr * maxLayers + iLayer;
141 PadInfo* p = new PadInfo();
142 p->current = histStrip[0][iStation][iModule][iLayer];
143 p->ref = histStrip[1][iStation][iModule][iLayer];
144 p->ref->SetLineColor(kRed);
145 p->normalize = false;
146 canStripPads[iPad] = p;
147 canStrip->GetPad(iPad + 1)->SetGrid();
148 }
149 modCtr++;
150 }
151 }
152 }
153
154 template<typename DigiType>
155 static void FillHists(vector<vector<vector<TH1F*>>>& hist_vec, TClonesArray* digs, bool set_bin_content = false)
156 {
157 for (Int_t iDig = 0; iDig < digs->GetEntriesFast(); iDig++) {
158 DigiType* dig = (DigiType*)digs->UncheckedAt(iDig);
159 if (!(dig->IsGoodDigit()))
160 continue;
161 Int_t module = dig->GetModule();
162 Int_t station = dig->GetStation();
163 Int_t layer = dig->GetStripLayer();
164 Int_t strip = dig->GetStripNumber();
165 if (set_bin_content) {
166 hist_vec[station][module][layer]->SetBinContent(strip, dig->GetStripNoise());
167 } else {
168 hist_vec[station][module][layer]->Fill(strip);
169 }
170 }
171 }
172 // void signal_handler(int sig);
173 BmnStatus InitDecoder(string);
174 BmnStatus InitDecoder(TString);
175 BmnStatus InitDecoder(uint32_t runID);
176 BmnStatus ConnectDataSocket();
177 BmnStatus ConnectDigiSocket();
178 BmnStatus StartNewRun(uint32_t runID);
179 BmnStatus AddRun2DB();
180 void ProcessFileRun(TString digiName, UInt_t timeLimit = WAIT_LIMIT);
181 static TString WatchNext(TString dirname, TString filename, Int_t cycleWait);
182 static TString WatchNext(Int_t inotifDir, Int_t cycleWait);
183 static Int_t GetRunIdFromName(TString name);
184
185 void* _ctx;
186 void* _decoSocket;
187 TString fDAQAddr;
188 BmnSetup fBmnSetup;
189 BmnRawDataDecoder* rawDataDecoder;
190 map<DetectorId, bool> fDetectorSetup;
191 TString _curFile;
192 TString _curDir;
193 Int_t fEvents;
194 uint32_t fPeriodID;
195 uint32_t fRunID;
196 BmnDataReceiver* dataReceiver;
197 Int_t _inotifDir;
198 Int_t _inotifDirW;
199 Int_t _inotifFile;
200 Int_t _inotifFileW;
201
202 Bool_t fKeepWorking;
203
204 void* _socket_mcast;
205 void* _socket_data;
206 Byte_t buf[MAX_BUF_LEN];
207 // UInt_t buf[MAX_BUF_LEN];
208 bool _do_process_stat_ev;
209 bool _do_process_norm_ev;
210
211 uint32_t _digi_socket;
212
213 ClassDef(BmnOnlineDecoder, 1)
214};
215
216#endif /* BMNONLINEDECODER_H */
__m128 v
Definition P4_F32vec4.h:1
BmnStatus
Definition BmnEnums.h:24
BmnSetup
Definition BmnEnums.h:89
@ kBMNSETUP
Definition BmnEnums.h:90
static void SetHistStyleTH1(TH1 *h)
Definition BmnHist.cxx:195
uint32_t GetPeriodID() const
static void StripView(TString OrigFileName, TString TestFileName, uint32_t periodID=8, uint32_t runID=0, BmnSetup fSetup=kBMNSETUP, bool FillOccupancy=true)
void SetProcessNormEvents(bool val=true)
BmnStatus BatchDirectoryToSocket(TString dirname)
void SetPeriodID(uint32_t v)
BmnStatus Decode(TString dirname, TString startFile, Bool_t runCurrent)
void SetBmnSetup(BmnSetup v)
void SetDigiSocket(uint32_t val=RAW_DECODER_SOCKET_PORT)
void SetDetectorSetup(map< DetectorId, bool > setup)
void SetProcessStatEvents(bool val=true)
BmnSetup GetBmnSetup() const
BmnStatus BatchDirectory(TString dirname)
void SetDaqAddress(TString addr)
Storage for pad content and it's options.
Definition PadInfo.h:20
bool normalize
Definition PadInfo.h:87
TH1 * ref
Definition PadInfo.h:79
TH1 * current
Definition PadInfo.h:78
#define WAIT_LIMIT
#define MAX_BUF_LEN
#define PAD_WIDTH_SIL
#define STRIP_COMP_COLS
#define RAW_DECODER_SOCKET_PORT
#define PAD_HEIGHT_SIL
Definition setup.py:1
name
Definition setup.py:7