From 144fa05e6a2ce87068dabbd6d279a2268474f89d Mon Sep 17 00:00:00 2001
From: Giulio Gaio <giulio.gaio@elettra.eu>
Date: Fri, 20 Oct 2023 14:10:35 +0200
Subject: [PATCH] Enabled strict control on bunchnumber lost

---
 src/DataVampire.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/DataVampire.cpp b/src/DataVampire.cpp
index b06b77d..67b0576 100644
--- a/src/DataVampire.cpp
+++ b/src/DataVampire.cpp
@@ -2907,6 +2907,8 @@ int32_t DataVampire::get_start_index(int32_t mode, int32_t num_samples, int32_t
 {
 	int32_t last_idx, start = -1, end = -1;
 	bool bn_found = false;
+	int32_t bn_samples = 0;
+	
 	
 	// last valid sample index stored in circular buffer
 	last_idx = (array_idx - 1 + DATAVAMPIRE_MAX_SIZE) % DATAVAMPIRE_MAX_SIZE;
@@ -2925,10 +2927,20 @@ int32_t DataVampire::get_start_index(int32_t mode, int32_t num_samples, int32_t
 			if (acq_array[idx].bn == bn_start) {
 				start = idx;
 			}	
+			if (end != -1) {
+				//printf("INCREMENT bn_samples=%d\n",bn_samples);
+				bn_samples++;
+			}				
 			if ((end != -1) && (start != -1)) {
 				bn_found = true; break;		
 			}	
 		}	
+		if ((bn_end - bn_start + 1) != bn_samples) {
+			Tango::Except::throw_exception(
+				(const char *) "Failed to find buffer indexes",
+				(const char *) "Data missing",
+				__FUNCTION__, Tango::ERR);		
+		}
 			
 		if (bn_found) {
 			return start;
-- 
GitLab