@@ -20,7 +20,7 @@ using namespace std::chrono;
2020const int event_header_words = 4 , max_channels = 16 ;
2121
2222double timespec_subtract (struct timespec & a, struct timespec & b) {
23- return (a.tv_sec - b.tv_sec )/ 1e6 + (a.tv_nsec - b.tv_nsec )/1e3 ;
23+ return (a.tv_sec - b.tv_sec )* 1e6 + (a.tv_nsec - b.tv_nsec )/1e3 ;
2424}
2525
2626StraxInserter::StraxInserter (){
@@ -74,15 +74,15 @@ StraxInserter::~StraxInserter(){
7474 fLog ->Entry (MongoLog::Message, " Still waiting for thread %lx to stop" , fThreadId );
7575 std::this_thread::sleep_for (std::chrono::seconds (2 ));
7676 }
77- long total_dps = std::accumulate (fBufferCounter .begin (), fBufferCounter .end (), 0 ,
77+ long total_dps = std::accumulate (fBufferCounter .begin (), fBufferCounter .end (), 0L ,
7878 [&](long tot, auto & p){return std::move (tot) + p.second ;});
7979 fLog ->Entry (MongoLog::Local, " Thread %lx got events %.1f%% of the time" ,
8080 fThreadId , (total_dps-fBufferCounter [0 ]+0.0 )/total_dps*100 .);
8181 std::map<std::string, long > counters {
8282 {" bytes" , fBytesProcessed },
8383 {" fragments" , fFragmentsProcessed },
8484 {" events" , fEventsProcessed },
85- {" data_packets" , total_dps}};
85+ {" data_packets" , total_dps - fBufferCounter [ 0 ] }};
8686 fOptions ->SaveBenchmarks (counters, fBufferCounter ,
8787 fProcTimeDP , fProcTimeEv , fProcTimeCh , fCompTime );
8888}
@@ -170,7 +170,7 @@ void StraxInserter::ProcessDatapacket(data_packet* dp){
170170 u_int32_t idx = 0 ;
171171 unsigned total_words = dp->size /sizeof (u_int32_t );
172172 clock_gettime (CLOCK_THREAD_CPUTIME_ID, &dp_start);
173- while (idx < total_words){
173+ while (idx < total_words && fForceQuit == false ){
174174
175175 if (buff[idx]>>28 == 0xA ){ // 0xA indicates header at those bits
176176 clock_gettime (CLOCK_THREAD_CPUTIME_ID, &ev_start);
@@ -179,7 +179,6 @@ void StraxInserter::ProcessDatapacket(data_packet* dp){
179179 fProcTimeEv += timespec_subtract (ev_end, ev_start);
180180 } else
181181 idx++;
182- if (fForceQuit ) break ;
183182 }
184183 clock_gettime (CLOCK_THREAD_CPUTIME_ID, &dp_end);
185184 fProcTimeDP += timespec_subtract (dp_end, dp_start);
@@ -196,7 +195,7 @@ uint32_t StraxInserter::ProcessEvent(uint32_t* buff, unsigned total_words, long
196195
197196 u_int32_t words_in_event = std::min (buff[0 ]&0xFFFFFFF , total_words);
198197 if (words_in_event < (buff[0 ]&0xFFFFFFF )) {
199- fLog ->Entry (MongoLog::Local, " Board %i garbled event header: %u/%u " ,
198+ fLog ->Entry (MongoLog::Local, " Board %i garbled event header: %x/%x " ,
200199 bid, buff[0 ]&0xFFFFFFF , total_words);
201200 }
202201
@@ -208,7 +207,7 @@ uint32_t StraxInserter::ProcessEvent(uint32_t* buff, unsigned total_words, long
208207
209208 if (buff[1 ]&0x4000000 ){ // board fail
210209 const std::lock_guard<std::mutex> lg (fFC_mutex );
211- GenerateArtificialDeadtime (((clock_counter<<31 ) + event_time )*fmt[" ns_per_clock" ], bid,
210+ GenerateArtificialDeadtime (((clock_counter<<31 ) + header_time )*fmt[" ns_per_clock" ], bid,
212211 event_time, clock_counter);
213212 fDataSource ->CheckError (bid);
214213 fFailCounter [bid]++;
@@ -240,8 +239,8 @@ int StraxInserter::ProcessChannel(uint32_t* buff, unsigned words_in_event, int b
240239 // These defaults are valid for 'default' firmware where all channels are the same size
241240 int channels_in_event = std::bitset<max_channels>(channel_mask).count ();
242241 u_int32_t channel_words = (words_in_event-event_header_words) / channels_in_event;
243- long channel_time = (clock_counter<< 31 ) + event_time;
244- long channel_timeMSB = 0 ;
242+ long channel_time = event_time;
243+ long channel_timeMSB = clock_counter<< 31 ;
245244 u_int16_t baseline_ch = 0 ;
246245 std::map<std::string, int > fmt = fFmt [bid];
247246
0 commit comments