MiniballSort
Loading...
Searching...
No Matches
Converter.hh
Go to the documentation of this file.
1#ifndef __CONVERTER_HH
2#define __CONVERTER_HH
3
4#include <bitset>
5#include <memory>
6#include <fstream>
7#include <iostream>
8#include <iomanip>
9#include <stdio.h>
10#include <sstream>
11#include <string>
12#include <algorithm>
13
14#include <TFile.h>
15#include <TTree.h>
16#include <TTreeIndex.h>
17#include <TH1.h>
18#include <TH2.h>
19#include <TProfile.h>
20#include <TGProgressBar.h>
21#include <TSystem.h>
22#include <TKey.h>
23#include <TROOT.h>
24
25// Settings header
26#ifndef __SETTINGS_HH
27# include "Settings.hh"
28#endif
29
30// Calibration header
31#ifndef __CALIBRATION_HH
32# include "Calibration.hh"
33#endif
34
35// Data packets header
36#ifndef __DATAPACKETS_HH
37# include "DataPackets.hh"
38#endif
39
40
42
43public:
44
45 MiniballConverter( std::shared_ptr<MiniballSettings> myset );
47
48 void MakeHists();
49 void NewBuffer();
50 void ResetHists();
51 void MakeTree();
52 void StartFile();
53 void BuildMbsIndex();
54 void SortDataVector();
55 void SortDataMap();
56 unsigned long long int SortTree( bool do_sort = true );
57 static bool TimeComparator( const std::shared_ptr<MiniballDataPackets> &lhs,
58 const std::shared_ptr<MiniballDataPackets> &rhs );
59 static bool MapComparator( const std::pair<unsigned long,double> &lhs,
60 const std::pair<unsigned long,double> &rhs );
61
62 void SetOutput( std::string output_file_name );
63 inline void SetOutputDirectory( std::string output_dir ){ output_dir_name = output_dir; };
64
65 inline void CloseOutput(){
66 std::cout << "\n Writing data and closing the file" << std::endl;
67 output_file->Write( nullptr, TObject::kOverwrite );
69 output_file->Close();
70 };
71 inline void PurgeOutput(){
72 output_file->Purge(2);
73 }
74 inline TFile* GetFile(){ return output_file; };
75 inline TTree* GetTree(){ return GetSortedTree(); };
76 inline TTree* GetMbsInfo(){ return mbsinfo_tree; };
77 inline TTree* GetSortedTree(){ return sorted_tree; };
78
79 inline void AddCalibration( std::shared_ptr<MiniballCalibration> mycal ){ cal = mycal; };
80 inline void SourceOnly(){ flag_source = true; };
81 inline void EBISOnly(){ flag_ebis = true; };
82 inline bool EBISWindow( long long int t ){
83 if( ebis_period == 0 ) return false;
84 else {
85 // Note: (a % b) is not in range 0..b-1 for negative a.
86 long long test_t = ((( t - ebis_tm_stp ) % ebis_period ) +
88 return ( test_t < 4000000 && test_t > 0 );
89 }
90 };
91
92 inline void AddProgressBar( std::shared_ptr<TGProgressBar> myprog ){
93 prog = myprog;
94 _prog_ = true;
95 };
96
97
98
99protected:
100
101 // Flags for source or EBIS run
103
104 // Logs
105 std::stringstream sslogs;
106
107 // Flag to identify Febex data words
114
115 // Interpretated variables
116 unsigned long long my_good_tm_stp = 0;
117 unsigned long long my_tm_stp = 0;
118 unsigned long long sync_tm_stp = 0;
119 long long ebis_tm_stp = 0;
120 unsigned long long my_event_id;
121 unsigned long my_tm_stp_lsb = 0;
122 unsigned long my_tm_stp_msb = 0;
123 unsigned long my_tm_stp_hsb = 0;
124 unsigned long sync_tm_stp_msb = 0;
125 unsigned long sync_tm_stp_hsb = 0;
126 unsigned int my_info_field;
127 unsigned int ebis_period = 0;
128 unsigned int ebis_first = 0;
129 unsigned char my_info_code;
130 unsigned char my_type;
131 unsigned short my_tdiff_data;
132 unsigned short my_adc_data;
133 unsigned short my_adc_data_lsb;
134 unsigned short my_adc_data_hsb;
135 unsigned int my_adc_data_int;
136 unsigned char my_tag_id;
137 unsigned char my_sfp_id;
138 unsigned char my_board_id;
139 unsigned char my_ch_id;
140 unsigned char my_data_id;
141 unsigned char my_trig_id;
147
148 // For traces
149 unsigned int nsamples;
150
151 // Flag depending on the data type
153
154 // Flag to signify this buffer or the one before is full
155 bool buffer_full = false;
156 bool buffer_part = false;
157
158 // Maximum size of the ADC value
159 unsigned long long qmax_default;
160
161 // Data types
162 std::shared_ptr<MBSInfoPackets> mbsinfo_packet = nullptr;
163 std::shared_ptr<MiniballDataPackets> write_packet = nullptr;
164 std::shared_ptr<DgfData> dgf_data;
165 std::shared_ptr<AdcData> adc_data;
166 std::shared_ptr<FebexData> febex_data;
167 std::shared_ptr<InfoData> info_data;
168
169 // Vector for storing the data packets before time ordering
170 std::vector<std::shared_ptr<MiniballDataPackets>> data_vector;
171 std::vector<std::pair<unsigned long,double>> data_map;
172
173 // Output stuff
174 std::string output_dir_name;
178
179 // Counters
180 std::vector<unsigned long int> ctr_dgf_hit; // hits on each DGF module
181 std::vector<unsigned long int> ctr_madc_hit; // hits on each Mesytec ADC module
182 std::vector<unsigned long int> ctr_caen_hit; // hits on each CAEN ADC module
183 std::vector<std::vector<unsigned long int>> ctr_febex_hit; // hits on each Febex module
184 std::vector<std::vector<unsigned long int>> ctr_febex_pause; // pause acq for module
185 std::vector<std::vector<unsigned long int>> ctr_febex_resume; // resume acq for module
186 std::vector<std::vector<unsigned long int>> ctr_febex_sync; // sync code from Exploder for each module
187 unsigned long int jump_ctr, warp_ctr, mash_ctr; // count timestamp jumps and warps
188 unsigned long int data_ctr; // total number of data counted
189 unsigned long int reject_ctr; // total number of reject buffers
190
191
192 // Histograms
193 std::vector<std::vector<TProfile*>> hfebex_hit;
194 std::vector<std::vector<TProfile*>> hfebex_pause;
195 std::vector<std::vector<TProfile*>> hfebex_resume;
196 std::vector<std::vector<TProfile*>> hfebex_sync;
197
198 std::vector<std::vector<TH1F*>> hdgf_qshort;
199 std::vector<std::vector<TH1F*>> hdgf_cal;
200 std::vector<std::vector<TH1F*>> hadc_qshort;
201 std::vector<std::vector<TH1F*>> hadc_cal;
202 std::vector<std::vector<std::vector<TH1F*>>> hfebex_qint;
203 std::vector<std::vector<std::vector<TH1F*>>> hfebex_qshort;
204 std::vector<std::vector<std::vector<TH1F*>>> hfebex_cal;
205 std::vector<std::vector<std::vector<TH1F*>>> hfebex_mwd;
206
208
209 // Timestamp tracking
210 std::vector<bool> first_data;
211 std::vector<long long int> tm_stp_read;
212 std::vector<std::vector<long long int>> tm_stp_febex;
213 std::vector<std::vector<std::vector<long long int>>> tm_stp_febex_ch;
214
215
216 // Settings file
217 std::shared_ptr<MiniballSettings> set;
218
219 // Calibrator
220 std::shared_ptr<MiniballCalibration> cal;
221
222 // Progress bar
223 bool _prog_;
224 std::shared_ptr<TGProgressBar> prog;
225
226 // List of histograms for reset later
227 TList *histlist;
228
229};
230
231
232#endif
TFile * GetFile()
Definition Converter.hh:74
std::shared_ptr< FebexData > febex_data
Definition Converter.hh:166
static bool TimeComparator(const std::shared_ptr< MiniballDataPackets > &lhs, const std::shared_ptr< MiniballDataPackets > &rhs)
Definition Converter.cc:461
unsigned long sync_tm_stp_hsb
Definition Converter.hh:125
unsigned int my_adc_data_int
Definition Converter.hh:135
std::vector< std::vector< TProfile * > > hfebex_hit
Definition Converter.hh:193
std::vector< std::vector< TProfile * > > hfebex_resume
Definition Converter.hh:195
std::vector< unsigned long int > ctr_dgf_hit
Definition Converter.hh:180
std::vector< std::vector< std::vector< long long int > > > tm_stp_febex_ch
Definition Converter.hh:213
unsigned int ebis_period
Definition Converter.hh:127
std::vector< std::vector< std::vector< TH1F * > > > hfebex_qint
Definition Converter.hh:202
unsigned long sync_tm_stp_msb
Definition Converter.hh:124
TTree * GetMbsInfo()
Definition Converter.hh:76
unsigned short my_adc_data_hsb
Definition Converter.hh:134
unsigned char my_board_id
Definition Converter.hh:138
unsigned short my_adc_data
Definition Converter.hh:132
std::vector< std::vector< TProfile * > > hfebex_pause
Definition Converter.hh:194
TTree * GetTree()
Definition Converter.hh:75
unsigned long int jump_ctr
Definition Converter.hh:187
unsigned char my_data_id
Definition Converter.hh:140
unsigned char my_type
Definition Converter.hh:130
std::vector< unsigned long int > ctr_caen_hit
Definition Converter.hh:182
std::vector< std::vector< std::vector< TH1F * > > > hfebex_mwd
Definition Converter.hh:205
std::shared_ptr< MiniballDataPackets > write_packet
Definition Converter.hh:163
long long ebis_tm_stp
Definition Converter.hh:119
std::vector< std::vector< TH1F * > > hdgf_cal
Definition Converter.hh:199
std::vector< std::vector< unsigned long int > > ctr_febex_sync
Definition Converter.hh:186
unsigned char my_info_code
Definition Converter.hh:129
unsigned long my_tm_stp_lsb
Definition Converter.hh:121
unsigned char my_ch_id
Definition Converter.hh:139
void AddCalibration(std::shared_ptr< MiniballCalibration > mycal)
Definition Converter.hh:79
std::shared_ptr< MiniballCalibration > cal
Definition Converter.hh:220
unsigned short my_adc_data_lsb
Definition Converter.hh:133
unsigned long int data_ctr
Definition Converter.hh:188
std::shared_ptr< DgfData > dgf_data
Definition Converter.hh:164
void AddProgressBar(std::shared_ptr< TGProgressBar > myprog)
Definition Converter.hh:92
std::vector< std::vector< std::vector< TH1F * > > > hfebex_cal
Definition Converter.hh:204
unsigned short my_tdiff_data
Definition Converter.hh:131
std::shared_ptr< MiniballSettings > set
Definition Converter.hh:217
std::vector< std::shared_ptr< MiniballDataPackets > > data_vector
Definition Converter.hh:170
unsigned int ebis_first
Definition Converter.hh:128
std::vector< std::vector< TH1F * > > hadc_cal
Definition Converter.hh:201
std::string output_dir_name
Definition Converter.hh:174
unsigned int nsamples
Definition Converter.hh:149
TTree * GetSortedTree()
Definition Converter.hh:77
std::vector< unsigned long int > ctr_madc_hit
Definition Converter.hh:181
std::vector< std::vector< unsigned long int > > ctr_febex_resume
Definition Converter.hh:185
unsigned long long sync_tm_stp
Definition Converter.hh:118
std::shared_ptr< InfoData > info_data
Definition Converter.hh:167
std::vector< std::pair< unsigned long, double > > data_map
Definition Converter.hh:171
std::vector< std::vector< TH1F * > > hdgf_qshort
Definition Converter.hh:198
std::vector< long long int > tm_stp_read
Definition Converter.hh:211
std::shared_ptr< AdcData > adc_data
Definition Converter.hh:165
unsigned char my_sfp_id
Definition Converter.hh:137
std::stringstream sslogs
Definition Converter.hh:105
std::vector< std::vector< long long int > > tm_stp_febex
Definition Converter.hh:212
std::vector< std::vector< unsigned long int > > ctr_febex_pause
Definition Converter.hh:184
std::shared_ptr< TGProgressBar > prog
Definition Converter.hh:224
unsigned long int reject_ctr
Definition Converter.hh:189
std::vector< std::vector< unsigned long int > > ctr_febex_hit
Definition Converter.hh:183
unsigned long long int SortTree(bool do_sort=true)
Definition Converter.cc:489
std::vector< std::vector< TH1F * > > hadc_qshort
Definition Converter.hh:200
unsigned long long qmax_default
Definition Converter.hh:159
unsigned long long my_good_tm_stp
Definition Converter.hh:116
unsigned long my_tm_stp_msb
Definition Converter.hh:122
unsigned long int mash_ctr
Definition Converter.hh:187
unsigned char my_tag_id
Definition Converter.hh:136
unsigned long int warp_ctr
Definition Converter.hh:187
bool EBISWindow(long long int t)
Definition Converter.hh:82
void SetOutput(std::string output_file_name)
Definition Converter.cc:111
std::vector< bool > first_data
Definition Converter.hh:210
unsigned long my_tm_stp_hsb
Definition Converter.hh:123
unsigned long long my_tm_stp
Definition Converter.hh:117
MiniballConverter(std::shared_ptr< MiniballSettings > myset)
Definition Converter.cc:4
unsigned int my_info_field
Definition Converter.hh:126
void SetOutputDirectory(std::string output_dir)
Definition Converter.hh:63
unsigned long long my_event_id
Definition Converter.hh:120
std::vector< std::vector< TProfile * > > hfebex_sync
Definition Converter.hh:196
static bool MapComparator(const std::pair< unsigned long, double > &lhs, const std::pair< unsigned long, double > &rhs)
Definition Converter.cc:468
std::vector< std::vector< std::vector< TH1F * > > > hfebex_qshort
Definition Converter.hh:203
std::shared_ptr< MBSInfoPackets > mbsinfo_packet
Definition Converter.hh:162
unsigned char my_trig_id
Definition Converter.hh:141
std::shared_ptr< MiniballSettings > myset
Definition mb_sort.cc:123
std::shared_ptr< MiniballCalibration > mycal
Definition mb_sort.cc:126