From 64eb618581453292eafc71f4582a35ae957f7fec Mon Sep 17 00:00:00 2001
From: Martin Killenberg <martin.killenberg@desy.de>
Date: Mon, 27 Jul 2020 21:08:53 +0200
Subject: [PATCH] TriggerFanOut: don't drop out of testable mode when waiting
 for device initialisation

---
 include/Application.h   | 8 +++++---
 include/TriggerFanOut.h | 3 +++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/Application.h b/include/Application.h
index c255bb78..f41a7c85 100644
--- a/include/Application.h
+++ b/include/Application.h
@@ -161,7 +161,7 @@ namespace ChimeraTK {
       pthread_setname_np(pthread_self(), name.substr(0, std::min<std::string::size_type>(name.length(), 15)).c_str());
     }
 
-    void debugMakeConnections(){ enableDebugMakeConnections = true; };
+    void debugMakeConnections() { enableDebugMakeConnections = true; };
 
     ModuleType getModuleType() const override { return ModuleType::ModuleGroup; }
 
@@ -429,8 +429,10 @@ namespace ChimeraTK {
                                                 // testableMode_counter and the
                                                 // idMap
 
-    friend class TestFacility; // needs access to testableMode_variables
-    friend class DeviceModule; // needs access to testableMode_variables
+    friend class TestFacility;  // needs access to testableMode_variables
+    friend class DeviceModule;  // needs access to testableMode_variables
+    friend class DeviceModule;  // needs access to testableMode_variables
+    friend class TriggerFanOut; // needs access to testableMode_variables
 
     template<typename UserType>
     friend class DebugPrintAccessorDecorator; // needs access to the idMap
diff --git a/include/TriggerFanOut.h b/include/TriggerFanOut.h
index 24fcc3e1..7cef2f78 100644
--- a/include/TriggerFanOut.h
+++ b/include/TriggerFanOut.h
@@ -93,9 +93,12 @@ namespace ChimeraTK {
       // Wait until the device has been initialised for the first time. This means it
       // has been opened, and the check in TransferGroup::read() will not throw a logic_error
       // We don't have to store the lock. Just need it as a synchronisation point.
+      // But we have to increase the testable mode counter because we don't want to fall out of testable mode at this point already.
+      ++Application::getInstance().testableMode_deviceInitialisationCounter;
       Application::testableModeUnlock("WaitInitialValueLock");
       (void)_deviceModule.getInitialValueSharedLock();
       Application::testableModeLock("Enter while loop");
+      --Application::getInstance().testableMode_deviceInitialisationCounter;
 
       while(true) {
         transferGroup.read();
-- 
GitLab