stream  0.10.0
stream analysis framework
TrbProcessor.h
1 #ifndef HADAQ_TRBPROCESSOR_H
2 #define HADAQ_TRBPROCESSOR_H
3 
4 #include "base/StreamProc.h"
5 //#include "base/Profiler.h"
6 #include "hadaq/definess.h"
7 #include "hadaq/TdcProcessor.h"
8 #include "hadaq/SubProcessor.h"
9 
10 #include <vector>
11 
12 namespace hadaq {
13 
14  class HldProcessor;
15 
17  struct TrbMessage {
19  unsigned fTrigSyncId;
20  unsigned fTrigSyncIdStatus;
21  uint64_t fTrigTm;
22  unsigned fSyncPulsePeriod;
23  unsigned fSyncPulseLength;
24 
26  void Reset()
27  {
28  fTrigSyncIdFound = false;
29  fTrigSyncId = 0;
30  fTrigTm = 0;
32  fSyncPulsePeriod = 0;
33  fSyncPulseLength = 0;
34  }
35  };
36 
46  class TrbProcessor : public base::StreamProc {
47 
48  friend class TdcProcessor;
49  friend class SubProcessor;
50  friend class HldProcessor;
51 
52  protected:
53 
54  HldProcessor *fHldProc{nullptr};
55 
56  SubProcMap fMap;
57 
58  unsigned fHadaqCTSId{0};
59  std::vector<unsigned> fHadaqHUBId;
60 
61  unsigned fLastTriggerId{0};
62  unsigned fLostTriggerCnt{0};
63  unsigned fTakenTriggerCnt{0};
64 
65  base::H1handle fEvSize{nullptr};
66  unsigned fSubevHLen{0};
67  unsigned fSubevHDiv{0};
68  base::H1handle fSubevSize{nullptr};
69  base::H1handle fLostRate{nullptr};
70  base::H1handle fTrigType{nullptr};
71  base::H1handle fErrBits{nullptr};
72 
73  base::H1handle fMsgPerBrd{nullptr};
74  base::H1handle fErrPerBrd{nullptr};
75  base::H1handle fHitsPerBrd{nullptr};
76  base::H2handle fCalHitsPerBrd{nullptr};
77  base::H2handle fToTPerBrd{nullptr};
78 
79 
83 
84  unsigned fSyncTrigMask;
85  unsigned fSyncTrigValue;
86  unsigned fCalibrTriggerMask;
87 
89 
91 
92  bool fAutoCreate;
93 
95  TrbMessage* pMsg{nullptr};
96 
97 // base::Profiler fProfiler; ///< profiler
98 
99  unsigned fMinTdc;
100  unsigned fMaxTdc;
101  std::vector<hadaq::TdcProcessor*> fTdcsVect;
102 
104  unsigned fCurrentRunId;
105  unsigned fCurrentEventId;
106 
107  static unsigned gNumChannels;
108  static unsigned gEdgesMask;
109  static bool gIgnoreSync;
110 
111  static unsigned gTDCMin;
112  static unsigned gTDCMax;
113 
114  static unsigned gHUBMin;
115  static unsigned gHUBMax;
116 
119  virtual bool doTriggerSelection() const { return false; }
120 
121  void AccountTriggerId(unsigned id);
122 
124  void AddSub(SubProcessor* tdc, unsigned id);
125 
127  virtual void ScanSubEvent(hadaqs::RawSubevent* sub, unsigned trb3runid, unsigned trb3seqid);
128 
129  void BeforeEventScan();
130 
131  void AfterEventScan();
132  void AfterEventFill();
133 
134  void BuildFastTDCVector();
135 
136  virtual void CreateBranch(TTree* t);
137 
138  void EventError(const char *msg);
139  void EventLog(const char *msg);
140 
141  void SetCrossProcessAll();
142 
143  public:
144 
145  TrbProcessor(unsigned brdid = 0, HldProcessor *hld = nullptr, int hfill = -1);
146  virtual ~TrbProcessor();
147 
149  HldProcessor *GetHLD() const { return fHldProc; }
150 
152  void SetAutoCreate(bool on = true) { fAutoCreate = on; }
153 
155  void SetHadaqCTSId(unsigned id) { fHadaqCTSId = id; }
156 
158  void AddHadaqHUBId(unsigned id) { fHadaqHUBId.emplace_back(id); }
159 
161  void SetHadaqHUBId(unsigned id1, unsigned id2=0, unsigned id3=0, unsigned id4=0)
162  {
163  fHadaqHUBId.clear();
164  AddHadaqHUBId(id1);
165  if (id2!=0) AddHadaqHUBId(id2);
166  if (id3!=0) AddHadaqHUBId(id3);
167  if (id4!=0) AddHadaqHUBId(id4);
168  }
169 
171  void SetHadaqTDCId(unsigned) {}
173  void SetHadaqSUBId(unsigned) {}
174 
175  virtual void UserPreLoop();
176  virtual void UserPostLoop();
177 
178  virtual void SetTriggerWindow(double left, double right);
179 
180  virtual void SetStoreKind(unsigned kind = 1);
181 
182  virtual bool FirstBufferScan(const base::Buffer& buf);
183 
185  void SetPrintRawData(bool on = true) { fPrintRawData = on; }
186 
188  bool IsPrintRawData() const { return fPrintRawData; }
189 
191  void SetPrintErrors(int cnt = 100) { fPrintErrCnt = cnt; }
192  bool CheckPrintError();
193 
194  void SetCrossProcess(bool on = true);
196  bool IsCrossProcess() const { return fCrossProcess; }
197 
198  void SetCh0Enabled(bool on = true);
199 
204  void SetSyncIds(unsigned mask, unsigned value)
205  {
206  fSyncTrigMask = mask;
207  fSyncTrigValue = value;
208  }
209 
212  void SetUseTriggerAsSync(bool on = true) { fUseTriggerAsSync = on; }
214  bool IsUseTriggerAsSync() const { return fUseTriggerAsSync; }
215 
217  void SetCompensateEpochReset(bool on = true) { fCompensateEpochReset = on; }
218 
220  unsigned NumSubProc() const { return fMap.size(); }
221 
223  SubProcessor* GetSubProc(unsigned indx) const
224  {
225  for (SubProcMap::const_iterator iter = fMap.begin(); iter!=fMap.end(); iter++) {
226  if (indx==0) return iter->second;
227  indx--;
228  }
229  return 0;
230  }
231 
233  TdcProcessor* GetTDC(unsigned tdcid, bool fullid = false) const
234  {
235  SubProcMap::const_iterator iter = fMap.find(tdcid);
236 
237  // for old analysis, where IDs are only last 8 bit
238  if ((iter == fMap.end()) && !fullid) iter = fMap.find(tdcid & 0xff);
239 
240  // ignore integrated TDCs, they have upper 16bits set
241  return ((iter != fMap.end()) && ((iter->first >> 16) == 0) && iter->second->IsTDC()) ? (TdcProcessor*) iter->second : 0;
242  }
243 
245  unsigned NumberOfTDC() const
246  {
247  unsigned num = 0;
248  for (SubProcMap::const_iterator iter = fMap.begin(); iter!=fMap.end(); iter++) {
249  if (iter->second->IsTDC()) num++;
250  }
251  return num;
252  }
253 
255  TdcProcessor* GetTDCWithIndex(unsigned indx) const
256  {
257  for (SubProcMap::const_iterator iter = fMap.begin(); iter!=fMap.end(); iter++) {
258  if (!iter->second->IsTDC()) continue;
259  if (indx == 0) return (TdcProcessor*) iter->second;
260  indx--;
261  }
262  return 0;
263  }
264 
265  void AddBufferToTDC(
266  hadaqs::RawSubevent* sub,
267  hadaq::SubProcessor* tdcproc,
268  unsigned ix,
269  unsigned datalen);
270 
271  TdcProcessor* FindTDC(unsigned tdcid) const;
272 
273  static void SetDefaults(unsigned numch=65, unsigned edges=0x1, bool ignore_sync = true);
274 
275  static unsigned GetDefaultNumCh();
276 
278  static void SetTDCRange(unsigned min, unsigned max)
279  {
280  gTDCMin = min;
281  gTDCMax = max;
282  }
283 
285  static void SetHUBRange(unsigned min, unsigned max)
286  {
287  gHUBMin = min;
288  gHUBMax = max;
289  }
290 
291  int CreateTDC(unsigned id1, unsigned id2 = 0, unsigned id3 = 0, unsigned id4 = 0);
292 
295 
296  void DisableCalibrationFor(unsigned firstch, unsigned lastch = 0);
297 
298  void SetAutoCalibrations(long cnt = 100000);
299 
300  void SetWriteCalibrations(const char* fileprefix, bool every_time = false, bool use_linear = false);
301 
302  bool LoadCalibrations(const char* fileprefix);
303 
304  void ConfigureCalibration(const std::string& name, long period, unsigned trigmask = 0xFFFF);
305 
306  void SetCalibrTriggerMask(unsigned trigmask = 0xFFFF);
307 
308  bool CollectMissingTDCs(hadaqs::RawSubevent *sub, std::vector<unsigned> &ids);
309 
310  void ClearFastTDCVector();
311 
312  unsigned TransformSubEvent(hadaqs::RawSubevent *sub, void *tgtbuf = nullptr, unsigned tgtlen = 0, bool only_hist = false, std::vector<unsigned> *newids = nullptr);
313 
314  unsigned EmulateTransform(hadaqs::RawSubevent *sub, int dummycnt, bool only_hist = false);
315 
316  void CreatePerTDCHistos();
317 
319  bool HasPerTDCHistos() const { return (fHitsPerBrd != nullptr) && (fToTPerBrd != nullptr); }
320 
321  void ClearDAQHistos();
322 
325 
328  };
329 }
330 
331 #endif
Memory management class.
Definition: Buffer.h:49
Abstract processor of data streams.
Definition: StreamProc.h:21
HLD processor.
Definition: HldProcessor.h:93
Abstract processor of HADAQ sub-sub-event.
Definition: SubProcessor.h:26
TDC processor.
Definition: TdcProcessor.h:32
TRB processor.
Definition: TrbProcessor.h:46
static bool gIgnoreSync
ignore sync in analysis, very rare used for sync with other data sources
Definition: TrbProcessor.h:109
void SetCompensateEpochReset(bool on=true)
When enabled, artificially create contiguous epoch value.
Definition: TrbProcessor.h:217
base::H1handle fErrPerBrd
! errors per board
Definition: TrbProcessor.h:74
void BuildFastTDCVector()
Build vector of TDCs processor for fast access.
Definition: TrbProcessor.cxx:1017
unsigned fCalibrTriggerMask
trigger mask used for calibration
Definition: TrbProcessor.h:86
bool IsPrintRawData() const
Return true if printing of raw data enabled.
Definition: TrbProcessor.h:188
virtual void CreateBranch(TTree *t)
Create branch in TTree to store hadaq::TrbMessage.
Definition: TrbProcessor.cxx:532
static unsigned gNumChannels
default number of channels
Definition: TrbProcessor.h:107
virtual void UserPostLoop()
Post loop function.
Definition: TrbProcessor.cxx:198
bool fPrintRawData
true when raw data should be printed
Definition: TrbProcessor.h:80
void AfterEventScan()
Function called after event scan - TDCs analyze data they got.
Definition: TrbProcessor.cxx:489
base::H1handle fEvSize
HADAQ event size.
Definition: TrbProcessor.h:65
void EventError(const char *msg)
Add event-related error message - adds event info.
Definition: TrbProcessor.cxx:576
void SetPrintRawData(bool on=true)
Enables printing of raw data.
Definition: TrbProcessor.h:185
TdcProcessor * GetTDCWithIndex(unsigned indx) const
Get TDC processor by index.
Definition: TrbProcessor.h:255
void SetSyncIds(unsigned mask, unsigned value)
Set sync mask and value which, should be obtained from trigger type to detect CBM sync message in CTS...
Definition: TrbProcessor.h:204
bool fUseTriggerAsSync
when true, trigger number used as sync message between TRBs
Definition: TrbProcessor.h:88
static unsigned gTDCMin
min TDC id when doing autoscan
Definition: TrbProcessor.h:111
unsigned fMinTdc
minimal id of TDC
Definition: TrbProcessor.h:99
unsigned fHadaqCTSId
identifier of CTS header in HADAQ event
Definition: TrbProcessor.h:58
hadaqs::RawSubevent fLastSubevHdr
! copy of last subevent header (without data)
Definition: TrbProcessor.h:103
bool fAutoCreate
when true, automatically crates TDC processors
Definition: TrbProcessor.h:92
HldProcessor * GetHLD() const
Returns instance of hadaq::HldProcessor to which it belongs.
Definition: TrbProcessor.h:149
void AddBufferToTDC(hadaqs::RawSubevent *sub, hadaq::SubProcessor *tdcproc, unsigned ix, unsigned datalen)
Provide buffer to sub-processor.
Definition: TrbProcessor.cxx:541
void CreateCTS_TDC()
Create TDC processor, which extracts TDC information from CTS header.
Definition: TrbProcessor.h:294
void SetCh0Enabled(bool on=true)
Enable/disable ch0 store in output event for all TDC processors.
Definition: TrbProcessor.cxx:369
TdcProcessor * FindTDC(unsigned tdcid) const
Find TDC with provided id.
Definition: TrbProcessor.cxx:129
unsigned fTakenTriggerCnt
registered trigger counts
Definition: TrbProcessor.h:63
unsigned fLostTriggerCnt
lost trigger counts
Definition: TrbProcessor.h:62
virtual bool doTriggerSelection() const
Returns true when processor used to select trigger signal TRB3 not yet able to perform trigger select...
Definition: TrbProcessor.h:119
TrbProcessor(unsigned brdid=0, HldProcessor *hld=nullptr, int hfill=-1)
Constructor, one could specify histogram fill level.
Definition: TrbProcessor.cxx:53
unsigned fMaxTdc
maximal id of TDC
Definition: TrbProcessor.h:100
hadaqs::RawSubevent & GetLastSubeventHdr()
Return reference on last subevent header.
Definition: TrbProcessor.h:324
virtual bool FirstBufferScan(const base::Buffer &buf)
First scan of buffer - main entry point for data.
Definition: TrbProcessor.cxx:423
base::H2handle fToTPerBrd
! ToT values for each TDC channel
Definition: TrbProcessor.h:77
void BeforeEventScan()
Function called before each event scan.
Definition: TrbProcessor.cxx:480
unsigned TransformSubEvent(hadaqs::RawSubevent *sub, void *tgtbuf=nullptr, unsigned tgtlen=0, bool only_hist=false, std::vector< unsigned > *newids=nullptr)
Transform (calibrate) raw data Creates output HLD structure, used in HADES DAQ.
Definition: TrbProcessor.cxx:1055
void AddHadaqHUBId(unsigned id)
Add HUB id.
Definition: TrbProcessor.h:158
void SetCalibrTriggerMask(unsigned trigmask=0xFFFF)
Set trigger ids mask which should be used for calibration Value 0x3FF enables calibration for all kin...
Definition: TrbProcessor.cxx:336
void SetHadaqCTSId(unsigned id)
Set id of CTS sub-sub event.
Definition: TrbProcessor.h:155
base::H1handle fTrigType
trigger type
Definition: TrbProcessor.h:70
base::H2handle fCalHitsPerBrd
! calibration hits per board, used only in HADES
Definition: TrbProcessor.h:76
bool IsUseTriggerAsSync() const
Returns true if trigger number should be used to sync events over all TRBs.
Definition: TrbProcessor.h:214
hadaq::TrbMessage & GetTrbMsg()
Return reference on last filled message.
Definition: TrbProcessor.h:327
unsigned EmulateTransform(hadaqs::RawSubevent *sub, int dummycnt, bool only_hist=false)
Emulate transform (calibrate) raw data - only for debugging.
Definition: TrbProcessor.cxx:1206
void SetHadaqHUBId(unsigned id1, unsigned id2=0, unsigned id3=0, unsigned id4=0)
Set up to 4 different HUB ids.
Definition: TrbProcessor.h:161
unsigned fLastTriggerId
last seen trigger id
Definition: TrbProcessor.h:61
static unsigned gHUBMin
min HUB id when doing autoscan
Definition: TrbProcessor.h:114
void ConfigureCalibration(const std::string &name, long period, unsigned trigmask=0xFFFF)
Configure calibration.
Definition: TrbProcessor.cxx:316
bool LoadCalibrations(const char *fileprefix)
Load calibrations for all existing TDCs as argument file prefix (without TDC id) should be specified.
Definition: TrbProcessor.cxx:300
base::H1handle fHitsPerBrd
! data hits per board
Definition: TrbProcessor.h:75
void AddSub(SubProcessor *tdc, unsigned id)
Way to register sub-processor, like for TDC.
Definition: TrbProcessor.cxx:350
static unsigned gTDCMax
max TDC id when doing autoscan
Definition: TrbProcessor.h:112
bool fCrossProcess
if true, cross-processing will be enabled
Definition: TrbProcessor.h:81
bool fCompensateEpochReset
when true, artificially create contiguous epoch value
Definition: TrbProcessor.h:90
SubProcessor * GetSubProc(unsigned indx) const
Returns sub-processor by its index.
Definition: TrbProcessor.h:223
void AfterEventFill()
if SetCrossProcess() enabled - fill histograms across TDCs
Definition: TrbProcessor.cxx:499
bool IsCrossProcess() const
Returns true if cross-processing enabled.
Definition: TrbProcessor.h:196
void CreatePerTDCHistos()
Create overview histograms where each TDC corresponds one bin.
Definition: TrbProcessor.cxx:139
void ClearFastTDCVector()
Clear helper vector of TDCs processor for fast access.
Definition: TrbProcessor.cxx:1045
static void SetHUBRange(unsigned min, unsigned max)
Define range for HUBs, used when auto mode is enabled.
Definition: TrbProcessor.h:285
void SetHadaqSUBId(unsigned)
deprecated, keep for backward compatibility, can be ignored
Definition: TrbProcessor.h:173
void AccountTriggerId(unsigned id)
Assign current trigger id.
Definition: TrbProcessor.cxx:393
SubProcMap fMap
map of sub-processors
Definition: TrbProcessor.h:56
bool CollectMissingTDCs(hadaqs::RawSubevent *sub, std::vector< unsigned > &ids)
Using data structure in raw event, collect ids of missing TDCs.
Definition: TrbProcessor.cxx:979
bool CheckPrintError()
Checks if error can be print out.
Definition: TrbProcessor.cxx:207
unsigned fSyncTrigValue
value from trigger type (after mask) which corresponds to sync message
Definition: TrbProcessor.h:85
base::H1handle fErrBits
error bit statistics
Definition: TrbProcessor.h:71
virtual ~TrbProcessor()
Destructor.
Definition: TrbProcessor.cxx:122
virtual void UserPreLoop()
Pre loop function.
Definition: TrbProcessor.cxx:187
int fPrintErrCnt
number of error messages, which could be printed
Definition: TrbProcessor.h:82
void SetHadaqTDCId(unsigned)
deprecated, keep for backward compatibility, can be ignored
Definition: TrbProcessor.h:171
void SetAutoCreate(bool on=true)
enable autocreation mode if necessary, works for single event
Definition: TrbProcessor.h:152
void ClearDAQHistos()
Clear all DAQ-related histograms.
Definition: TrbProcessor.cxx:1229
static void SetDefaults(unsigned numch=65, unsigned edges=0x1, bool ignore_sync=true)
Set defaults for the next creation of TDC processors.
Definition: TrbProcessor.cxx:35
virtual void ScanSubEvent(hadaqs::RawSubevent *sub, unsigned trb3runid, unsigned trb3seqid)
Scan FPGA-TDC data, distribute over sub-processors.
Definition: TrbProcessor.cxx:600
unsigned fSubevHDiv
integer division for subevent
Definition: TrbProcessor.h:67
unsigned NumSubProc() const
Returns number of sub-processors.
Definition: TrbProcessor.h:220
bool HasPerTDCHistos() const
Are there per-TDC histograms.
Definition: TrbProcessor.h:319
unsigned fCurrentRunId
! current runid
Definition: TrbProcessor.h:104
HldProcessor * fHldProc
pointer on HLD processor
Definition: TrbProcessor.h:54
virtual void SetStoreKind(unsigned kind=1)
Configure store kind.
Definition: TrbProcessor.cxx:358
void SetPrintErrors(int cnt=100)
Set number of errors which could be printed.
Definition: TrbProcessor.h:191
void SetAutoCalibrations(long cnt=100000)
Set auto calibration for all existing TDCs.
Definition: TrbProcessor.cxx:266
void SetUseTriggerAsSync(bool on=true)
Use TRB trigger number as SYNC message.
Definition: TrbProcessor.h:212
std::vector< unsigned > fHadaqHUBId
identifier of HUB header in HADQ event
Definition: TrbProcessor.h:59
void DisableCalibrationFor(unsigned firstch, unsigned lastch=0)
Disable calibration of specified channels for all existing TDCs.
Definition: TrbProcessor.cxx:277
unsigned fCurrentEventId
! current processed event id, used in log msg
Definition: TrbProcessor.h:105
static unsigned gEdgesMask
default edges mask
Definition: TrbProcessor.h:108
TrbMessage * pMsg
used for TTree store
Definition: TrbProcessor.h:95
static unsigned GetDefaultNumCh()
Retun default number of TDC channels.
Definition: TrbProcessor.cxx:45
void EventLog(const char *msg)
Add event-related log message - adds event info.
Definition: TrbProcessor.cxx:586
base::H1handle fSubevSize
HADAQ subevent size.
Definition: TrbProcessor.h:68
TrbMessage fMsg
used for TTree store
Definition: TrbProcessor.h:94
std::vector< hadaq::TdcProcessor * > fTdcsVect
array of TDCs
Definition: TrbProcessor.h:101
void SetCrossProcessAll()
Cal SetCrossProcess for all existing TRB processors.
Definition: TrbProcessor.cxx:511
int CreateTDC(unsigned id1, unsigned id2=0, unsigned id3=0, unsigned id4=0)
Create up to 4 TDC with pre-configured default parameters.
Definition: TrbProcessor.cxx:222
static unsigned gHUBMax
max HUB id when doing autoscan
Definition: TrbProcessor.h:115
unsigned fSyncTrigMask
mask which should be applied for trigger type
Definition: TrbProcessor.h:84
void SetWriteCalibrations(const char *fileprefix, bool every_time=false, bool use_linear=false)
Set write calibration for all existing TDCs.
Definition: TrbProcessor.cxx:288
void SetCrossProcess(bool on=true)
Enable Cross-processing - hits correlation between different TDCs.
Definition: TrbProcessor.cxx:522
TdcProcessor * GetTDC(unsigned tdcid, bool fullid=false) const
Returns TDC processor according to it ID.
Definition: TrbProcessor.h:233
unsigned NumberOfTDC() const
Returns number of TDC processors.
Definition: TrbProcessor.h:245
base::H1handle fMsgPerBrd
! messages per board
Definition: TrbProcessor.h:73
base::H1handle fLostRate
lost rate
Definition: TrbProcessor.h:69
virtual void SetTriggerWindow(double left, double right)
Set trigger window for all TDCs.
Definition: TrbProcessor.cxx:380
unsigned fSubevHLen
maximal length of subevent in bytes
Definition: TrbProcessor.h:66
static void SetTDCRange(unsigned min, unsigned max)
Define range for TDCs, used when auto mode is enabled.
Definition: TrbProcessor.h:278
message used for ROOT tree storage, similar to TdcMessage and AdcMessage
Definition: TrbProcessor.h:17
unsigned fTrigSyncId
sync id
Definition: TrbProcessor.h:19
void Reset()
reset
Definition: TrbProcessor.h:26
uint64_t fTrigTm
trigger time
Definition: TrbProcessor.h:21
bool fTrigSyncIdFound
is sync id found
Definition: TrbProcessor.h:18
unsigned fSyncPulsePeriod
sync pulse period
Definition: TrbProcessor.h:22
unsigned fTrigSyncIdStatus
sync id status
Definition: TrbProcessor.h:20
unsigned fSyncPulseLength
sync pulse length
Definition: TrbProcessor.h:23
Raw hades subevent.
Definition: definess.h:408