9 #include <Event/Event.h>
10 #include <Event/EventTypes.h>
11 #include <Event/packet.h>
33 std::ostream& operator << ( std::ostream& out, const std::list<T>& list )
35 if( list.empty() )
out <<
"{}";
40 for(
const auto&
value:list )
42 if( !first )
out <<
", ";
80 lvl1_bco_list.clear();
81 lvl1_count_list.clear();
111 auto event = findNode::getClass<Event>(topNode,
"PRDF");
115 if(
event->getEvtType() >= 8)
121 std::multimap<uint64_t, Sample> sample_map;
122 std::multimap<uint64_t, Waveform> waveform_map;
127 std::unique_ptr<Packet> packet(
event->getPacket(packet_id) );
132 { std::cout <<
"MicromegasRawDataEvaluation::process_event - packet " << packet_id <<
" not found." << std::endl; }
137 int n_tagger = packet->lValue(0,
"N_TAGGER");
141 const auto n_waveform = packet->iValue(0,
"NR_WF" );
145 using bco_list_t = std::list<uint64_t>;
146 bco_list_t main_bco_list;
147 for (
int t = 0;
t < n_tagger;
t++)
149 const auto is_lvl1 =
static_cast<uint8_t
>(packet->lValue(
t,
"IS_LEVEL1_TRIGGER"));
150 const auto bco =
static_cast<uint64_t
>(packet->lValue(
t,
"BCO"));
151 const auto lvl1_count =
static_cast<uint32_t
>(packet->lValue(
t,
"LEVEL1_COUNT"));
154 main_bco_list.push_back( bco );
164 std::cout <<
"MicromegasRawDataEvaluation::process_event -"
165 <<
" packet: " << packet_id
166 <<
" n_lvl1_bco: " << main_bco_list.size()
167 <<
" n_waveform: " << n_waveform
170 std::cout <<
"MicromegasRawDataEvaluation::process_event -"
171 <<
" packet: " << packet_id
172 <<
" bco: " << std::hex << main_bco_list << std::dec
178 std::map<unsigned short, bco_list_t> bco_list_map;
181 using fee_pair_t = std::pair< unsigned int, unsigned int>;
182 std::set<fee_pair_t> orphans;
184 for(
int iwf=0; iwf<n_waveform; ++iwf )
189 sample.
fee_id = packet->iValue(iwf,
"FEE" );
195 sample.
fee_bco = packet->iValue(iwf,
"BCO");
202 if( bco_matching_pair.first == sample.
fee_bco )
205 sample.
lvl1_bco = bco_matching_pair.second;
210 auto bco_list_iter = bco_list_map.lower_bound( sample.
fee_id );
211 if( bco_list_iter == bco_list_map.end() || sample.
fee_id < bco_list_iter->first )
212 { bco_list_iter = bco_list_map.insert( bco_list_iter, std::make_pair( sample.
fee_id, main_bco_list ) ); }
215 auto& bco_list = bco_list_iter->second;
216 if( !bco_list.empty() )
221 std::cout <<
"MicromegasRawDataEvaluation::process_event -"
222 <<
" fee_id: " << sample.
fee_id
223 <<
" fee_bco: 0x" << std::hex << sample.
fee_bco
224 <<
" gtm_bco: 0x" << bco_list.front()
231 const auto lvl1_bco = bco_list.front();
232 bco_matching_pair.first = sample.
fee_bco;
233 bco_matching_pair.second = lvl1_bco;
237 bco_list.pop_front();
243 std::cout <<
"MicromegasRawDataEvaluation::process_event -"
244 <<
" fee_id: " << sample.
fee_id
245 <<
" fee_bco: 0x" << std::hex << sample.
fee_bco << std::dec
252 sample.
checksum = packet->iValue(iwf,
"CHECKSUM");
259 sample.
sampa_address = packet->iValue( iwf,
"SAMPAADDRESS" );
260 sample.
sampa_channel = packet->iValue( iwf,
"SAMPACHANNEL" );
261 sample.
channel = packet->iValue( iwf,
"CHANNEL" );
271 const unsigned short samples = packet->iValue( iwf,
"SAMPLES" );
274 std::cout <<
"MicromegasRawDataEvaluation::process_event -"
275 <<
" fee: " << sample.
fee_id
276 <<
" tile: " << sample.
tile
277 <<
" layer: " << sample.
layer
278 <<
" tile: " << sample.
tile
280 <<
" fee_bco: " << sample.
fee_bco
282 <<
" channel: " << sample.
channel
283 <<
" strip: " << sample.
strip
284 <<
" samples: " << samples
289 for(
unsigned short is = 0; is < std::min<unsigned short>( samples, 100 ); ++is )
292 unsigned short adc = packet->iValue(iwf,is);
295 sample_map.emplace( sample.
lvl1_bco, sample );
297 if( sample.
adc > sample_max.
adc )
298 { sample_max = sample; }
311 waveform_map.emplace( waveform.
lvl1_bco, waveform );
316 for(
auto&& [lvl_bco, sample]:sample_map )
319 for(
auto&& [lvl1_bco, waveform]:waveform_map )
340 for(
const auto& [bco,nwaveforms]:
m_bco_map )
341 { std::cout <<
"MicromegasRawDataEvaluation::End - bco: 0x" << std::hex << bco << std::dec <<
", nwaveforms: " << nwaveforms << std::endl; }
345 std::cout <<
"const std::vector<uint64_t> lvl1_bco_list = {" << std::endl;
348 for(
const auto& [bco,nwaveforms]:m_bco_map )
350 if( !first ) std::cout <<
", ";
355 std::cout << std::endl;
357 std::cout <<
" 0x" << std::hex << bco << std::dec;
360 std::cout << std::endl <<
"};" << std::endl;