readWDpp
Read binary files from DRS and WDB
Loading...
Searching...
No Matches
readWD.hh
Go to the documentation of this file.
1
12#ifndef READWD_H
13#define READWD_H
14
15#include <iostream>
16#include <fstream>
17#include <string>
18#include <vector>
19#include <map>
20#include <numeric>
21#include <algorithm>
22#include <math.h>
23#include <cstring>
24
25#define SAMPLES_PER_WAVEFORM 1024
26
27/*
28 ┌─────────────────────────────────────────────────────────────────────────┐
29 │ CLASSES │
30 └─────────────────────────────────────────────────────────────────────────┘
31 */
32
38struct TAG
39{
45 TAG() { tag[4] = '\0'; }
46 char tag[5];
47};
48
56{
57 char tag[4];
58 unsigned int serialNumber;
59 unsigned short year;
60 unsigned short month;
61 unsigned short day;
62 unsigned short hour;
63 unsigned short min;
64 unsigned short sec;
65 unsigned short ms;
66 unsigned short rangeCenter;
67};
68
69class DAQConfig;
70class DAQEvent;
71class DAQFile;
72
81{
82private:
83 DAQConfig();
84
85 void MakeConfig(DAQFile &);
86 void ShowConfig();
87
88 std::map<int, std::map<int, std::pair<int, int>>> intWindow_;
89 std::map<int, std::map<int, std::pair<int, int>>> pedInterval_;
90 std::map<int, std::map<int, float>> peakThr_;
91 std::map<int, std::map<int, bool>> user_iw_;
92
93 void SetIntWindow(std::pair<int, int>, int, int);
94 void SetIntWindow(std::pair<int, int>);
95 void SetPedInterval(std::pair<int, int>, int, int);
96 void SetPedInterval(std::pair<int, int>);
97 void SetPeakThr(float, int, int);
98 void SetPeakThr(float);
99
101
102 friend class DAQEvent;
103 friend class DAQFile;
104};
105
113{
114 using MAP = std::map<int, std::map<int, std::vector<float>>>;
115
116public:
117 DAQEvent &GetChannel(const int &, const int &);
118 void SetPedInterval(int, int);
119 void SetPeakThr(float);
120 void SetIntWindow(int, int);
121 void SetIntWindow(float, float);
122
128 void MakeConfig(DAQFile &file) { config_.MakeConfig(file); };
134
135 bool IsSaturated();
136 float GetCharge();
137 float GetAmplitude();
138 float GetTime(float);
139 float GetTimeCF(float);
140 float GetRiseTime();
141 const std::pair<float, float> &GetPedestal();
142 const std::vector<float> &GetVolts();
143 const std::vector<float> &GetTimes();
144 const std::vector<int> &GetPeakIndices();
145 const std::pair<int, int> &GetIntegrationBounds();
146 const EventHeader &GetEH() { return eh_; };
147
148 const MAP &GetVoltMap() { return volts_; };
149 const MAP &GetTimeMap() { return times_; };
150
151protected:
152 DAQEvent();
153
154 DAQEvent &TimeCalibration(const unsigned short &, const std::vector<float> &, int, int);
158
161
162 EventHeader eh_;
164
165 std::pair<float, float> ped_;
166 std::pair<float, float> peak_;
167 std::pair<int, int> ped_interval_;
168 std::pair<int, int> iw_;
169 std::pair<int, int> ch_;
170 std::vector<int> indexMin_;
171
172 bool is_init_;
174 bool is_iw_;
175 bool is_ped_;
176 bool is_peak_;
178
179 unsigned int evtserial_old_;
180 std::pair<int, int> ch_old_;
181 std::vector<bool> routine_;
183
184 friend class DAQFile;
185};
186
191class DRSEvent : public DAQEvent
192{
193public:
194 DRSEvent();
195 static const std::string type_;
196};
197
202class WDBEvent : public DAQEvent
203{
204public:
205 WDBEvent();
206 static const std::string type_;
207};
208
214{
215 using MAP = std::map<int, std::map<int, std::vector<float>>>;
216
217public:
218 DAQFile();
219 DAQFile(const std::string &);
220 ~DAQFile() { in_.close(); }
221
222 DAQFile &Close();
223 DAQFile &Open(const std::string &);
224 DAQFile &Reset();
225
226 DAQFile &GetEvent(int);
227
228 bool operator>>(DRSEvent &);
229 bool operator>>(WDBEvent &);
230
231 const MAP &GetTimeMap() { return times_; };
232
233private:
235
236 bool operator>>(TAG &);
237 bool operator>>(EventHeader &);
238 operator bool();
239 void Read(TAG &);
240 void Read(EventHeader &);
241 void Read(std::vector<float> &);
242 void Read(std::vector<float> &, const unsigned short &);
243 void ResetTag() { in_.seekg(-4, in_.cur); }
244
245 std::string filename_;
246 std::ifstream in_;
247 char o_;
248 char n_;
251 bool is_lab_;
252 std::string type_;
254
255 friend class DAQConfig;
256};
257
258/*
259 ┌─────────────────────────────────────────────────────────────────────────┐
260 │ FUNCTIONS │
261 └─────────────────────────────────────────────────────────────────────────┘
262 */
263
264std::ostream &operator<<(std::ostream &, const TAG &);
265std::ostream &operator<<(std::ostream &, const EventHeader &);
266
267#endif
Main class to hold various settings for the channels.
Definition readWD.hh:81
std::map< int, std::map< int, float > > peakThr_
Data member to hold peak threshold values of various channels.
Definition readWD.hh:90
void MakeConfig(DAQFile &)
Initialise the configuration class with the default values for any board and any channel.
Definition readWD.cc:803
bool is_makeconfig_
Flag to check if the method DAQConfig::MakeConfig() has been called at least once.
Definition readWD.hh:100
void ShowConfig()
Simple method to print on stream the current settings of the class.
Definition readWD.cc:828
std::map< int, std::map< int, std::pair< int, int > > > intWindow_
Data member to hold integration windows intervals of various channels.
Definition readWD.hh:88
std::map< int, std::map< int, std::pair< int, int > > > pedInterval_
Data member to hold pedestal intervals of various channels.
Definition readWD.hh:89
std::map< int, std::map< int, bool > > user_iw_
Data member to hold which integration windows were set by the user.
Definition readWD.hh:91
void SetPeakThr(float, int, int)
Method to set the peak threshold given the peak threshold in Volts and the board/channel IDs.
Definition readWD.cc:989
DAQConfig()
Construct a new DAQConfig::DAQConfig object.
Definition readWD.cc:788
Main class to store voltage and time values.
Definition readWD.hh:113
void SetPeakThr(float)
Set the threshold in volt by the user.
Definition readWD.cc:171
bool is_iw_
Flag to check if integration window has been evaluated once.
Definition readWD.hh:174
DAQConfig config_
Class to hold settings about pedestal and integration window intervals.
Definition readWD.hh:163
MAP volts_
Structure to hold voltage values of all boards and channels.
Definition readWD.hh:160
void SetPedInterval(int, int)
Function to set the interval where to perform pedestal evaluation.
Definition readWD.cc:149
std::pair< float, float > ped_
Pair to hold pedestal mean and pedestal std.dev..
Definition readWD.hh:165
const std::vector< float > & GetTimes()
Getter method read-only for the waveform's times selected.
Definition readWD.cc:487
DAQEvent & EvalPedestal()
Method to evaluate the pedestal of the currently selected waveform.
Definition readWD.cc:578
DAQEvent & TimeCalibration(const unsigned short &, const std::vector< float > &, int, int)
Function to perform the time calibration.
Definition readWD.cc:563
const std::pair< float, float > & GetPedestal()
Getter method read-only for the attribute DAQEvent::ped_.
Definition readWD.cc:434
std::pair< int, int > iw_
Pair to hold indices as boundary edges where integration is performed by DAQEvent::GetCharge().
Definition readWD.hh:168
bool is_init_
Flag to check if the file is initialised.
Definition readWD.hh:172
std::pair< int, int > ch_old_
Pair to store last channel on which routines were made.
Definition readWD.hh:180
DAQEvent()
Construct a new DAQEvent() object.
Definition readWD.cc:76
std::pair< int, int > ch_
Pair to hold indices of board and channel selected;.
Definition readWD.hh:169
float GetRiseTime()
Evaluate the risetime of the waveform.
Definition readWD.cc:418
const std::pair< int, int > & GetIntegrationBounds()
Definition readWD.cc:530
unsigned int evtserial_old_
Value to store last event read.
Definition readWD.hh:179
bool is_ped_
Flag to check if pedestal has been evaluated once.
Definition readWD.hh:175
float GetTimeCF(float)
Find the time at which the waveform goes under a given percentage of the waveform peak value.
Definition readWD.cc:391
float GetTime(float)
Find the time at which the waveform goes under a given threshold level.
Definition readWD.cc:338
void MakeConfig(DAQFile &file)
Method to simply call DAQConfig::MakeConfig().
Definition readWD.hh:128
DAQEvent & EvalIntegrationBounds()
Method to evaluate the integration window of the currently selected waveform.
Definition readWD.cc:619
float peak_threshold_
Value to store the threshold in volts passed by the user.
Definition readWD.hh:177
float GetCharge()
Method to evaluate charge in the integration region.
Definition readWD.cc:280
const std::vector< float > & GetVolts()
Getter method read-only for the waveform's voltages selected.
Definition readWD.cc:461
std::pair< float, float > peak_
Pair to hold value of voltage and time at the peak.
Definition readWD.hh:166
bool IsSaturated()
Check if in the selected channel there is (or not) saturation.
Definition readWD.cc:253
DAQEvent & FindPeaks()
Method to find peaks in the integration window.
Definition readWD.cc:673
std::vector< int > indexMin_
Indices of local minima found.
Definition readWD.hh:170
std::pair< int, int > ped_interval_
Pair to hold indices as boundary edges where pedestal is evaluated.
Definition readWD.hh:167
void SetIntWindow(int, int)
Set the integration window passing two indices that go from 0 to SAMPLES_PER_WAVEFORM.
Definition readWD.cc:194
DAQEvent & GetChannel(const int &, const int &)
Select the channel to analyze.
Definition readWD.cc:102
const std::vector< int > & GetPeakIndices()
Definition readWD.cc:510
void ShowConfig()
Simple method to call DAQConfig::ShowConfig().
Definition readWD.hh:133
bool is_getch_
Flag to check if the method DAQEvent::GetChannel() has been called.
Definition readWD.hh:173
std::vector< bool > routine_
Definition readWD.hh:181
std::map< int, std::map< int, std::vector< float > > > MAP
Alias for data structure.
Definition readWD.hh:114
bool is_peak_
Flag to check if peaks have been found once.
Definition readWD.hh:176
MAP times_
Structure to hold integrated times values of all boards and channels.
Definition readWD.hh:159
float GetAmplitude()
Method to evaluate amplitude in the integration region.
Definition readWD.cc:312
Class to manage the file and the outputing of data in a DAQEvent instance.
Definition readWD.hh:214
bool initialization_
Flag to store if DAQFile::Initialise() was already called.
Definition readWD.hh:249
std::string type_
Flag to store the type of the board.
Definition readWD.hh:252
DAQFile & Reset()
Method to reset the file.
Definition readWD.cc:1213
char o_
The initial letter of the previous tag read.
Definition readWD.hh:247
std::string filename_
The name of the file.
Definition readWD.hh:245
std::map< int, std::map< int, std::vector< float > > > MAP
Alias for data structure.
Definition readWD.hh:215
char n_
The initial letter of the newest tag read.
Definition readWD.hh:248
bool is_lab_
Flag to check if the board is from LAB or not.
Definition readWD.hh:251
DAQFile()
Construct a new DAQFile::DAQFile object.
Definition readWD.cc:1057
DAQFile & GetEvent(int)
Method to select what event must be read next.
Definition readWD.cc:1234
DAQFile & Open(const std::string &)
Method to open a file given the file path and name.
Definition readWD.cc:1188
DAQFile & Close()
Method to close the file.
Definition readWD.cc:1168
MAP times_
Struct to hold read from the TIMEpart of the file.
Definition readWD.hh:250
void Read(TAG &)
Read a tag.
Definition readWD.cc:1462
bool operator>>(DRSEvent &)
Read into a DRSEvent.
Definition readWD.cc:1329
DAQFile & Initialise()
Initialise the file reading the TIME block.
Definition readWD.cc:1084
int first_evt_pos_
Position of first event header.
Definition readWD.hh:253
std::ifstream in_
The input file to read.
Definition readWD.hh:246
Specialization of DAQEvent to a DRS board.
Definition readWD.hh:192
Specialization of DAQEvent to a WaveDREAM board.
Definition readWD.hh:203
ostream & operator<<(ostream &o, const TAG &tag)
Function to print a TAG istance easily on stream::cout.
Definition readWD.cc:28
Informations about the event contained in the file.
Definition readWD.hh:56
unsigned int serialNumber
The serial number of the event: starting from 1 for DRS and 0 for WDB.
Definition readWD.hh:58
unsigned short sec
The second.
Definition readWD.hh:64
char tag[4]
The tag of the event header.
Definition readWD.hh:57
unsigned short ms
The millisecond.
Definition readWD.hh:65
unsigned short month
The month.
Definition readWD.hh:60
unsigned short day
The day.
Definition readWD.hh:61
unsigned short min
The minute.
Definition readWD.hh:63
unsigned short rangeCenter
The rangeCenter (in Volts).
Definition readWD.hh:66
unsigned short hour
The hour.
Definition readWD.hh:62
unsigned short year
The year.
Definition readWD.hh:59
5 char long word ended with '\0' for simple printing.
Definition readWD.hh:39
char tag[5]
The array of char.
Definition readWD.hh:46
TAG()
Construct a new TAG object.
Definition readWD.hh:45