From d87a6b00144eaa8dab1f752f81c436073b61ea69 Mon Sep 17 00:00:00 2001
From: Martin Killenberg <martin.killenberg@desy.de>
Date: Tue, 5 Sep 2017 14:46:11 +0200
Subject: [PATCH] removed direct use of CSA::ProcessArray (which is the
 implementation) and replaced it with NDRegisterAccessor (the base class) in
 the adapter. Usage in tests still pending

---
 include/DoocsProcessArray.h    | 10 ++++------
 include/DoocsProcessScalar.h   | 10 +++++-----
 include/DoocsSpectrum.h        | 10 ++++------
 src/DoocsPVFactory.cc          |  8 ++++----
 tests/src/testDoocsAdapter.cpp |  1 -
 5 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/include/DoocsProcessArray.h b/include/DoocsProcessArray.h
index 7b2013a..bddd9ff 100644
--- a/include/DoocsProcessArray.h
+++ b/include/DoocsProcessArray.h
@@ -4,7 +4,7 @@
 #include <D_spectrum.h>
 #include <boost/noncopyable.hpp>
 
-#include <ChimeraTK/ControlSystemAdapter/ProcessArray.h>
+#include <mtca4u/NDRegisterAccessor.h>
 #include <ChimeraTK/ControlSystemAdapter/ProcessVariableListener.h>
 #include <ChimeraTK/ControlSystemAdapter/ControlSystemSynchronizationUtility.h>
 
@@ -40,9 +40,7 @@ namespace ChimeraTK {
            * The notification that is executed updates of the doocs process variable
            */
           void notify(boost::shared_ptr< ProcessVariable > processVariable) {
-            // It is safe to static cast because the DoocsArrayListener is inside a 
-            // DoocsProcessArray, which always holds a ProcessArray, never a ProcessScalar
-            ProcessArray<T> & processArray = static_cast< ProcessArray<T> & >(*processVariable);
+            auto & processArray = static_cast< mtca4u::NDRegisterAccessor<T> & >(*processVariable);
             
             // Brute force implementation. Works for all data types T.
             // always get a fresh reference
@@ -59,7 +57,7 @@ namespace ChimeraTK {
 
       };
 
-      boost::shared_ptr< ProcessArray<T> > _processArray;
+      boost::shared_ptr< mtca4u::NDRegisterAccessor<T> > _processArray;
 
       // Internal function which copies the content from the DOOCS container into the 
       // ChimeraTK ProcessArray and calls the send method. Factored out to allow unit testing.
@@ -77,7 +75,7 @@ namespace ChimeraTK {
     public:
 
       DoocsProcessArray( EqFct *eqFct,
-                         boost::shared_ptr< typename ChimeraTK::ProcessArray<T> > const &processArray,
+                         boost::shared_ptr< typename mtca4u::NDRegisterAccessor<T> > const &processArray,
                          ControlSystemSynchronizationUtility & syncUtility )
       : D_spectrum( splitStringAtFirstSlash(processArray->getName()).second.c_str(),
                     processArray->getNumberOfSamples(), eqFct),
diff --git a/include/DoocsProcessScalar.h b/include/DoocsProcessScalar.h
index 8579f59..e2b1663 100644
--- a/include/DoocsProcessScalar.h
+++ b/include/DoocsProcessScalar.h
@@ -2,7 +2,7 @@
 #define __DOOCS_PROCESS_SCALAR_H__
 
 #include <string>
-#include <ChimeraTK/ControlSystemAdapter/ProcessArray.h>
+#include <mtca4u/NDRegisterAccessor.h>
 #include <ChimeraTK/ControlSystemAdapter/ProcessVariableListener.h>
 #include <ChimeraTK/ControlSystemAdapter/ControlSystemSynchronizationUtility.h>
 #include <boost/shared_ptr.hpp>
@@ -44,7 +44,7 @@ namespace ChimeraTK {
           void notify(boost::shared_ptr< ProcessVariable > processVariable) {
             // It is safe to static cast because the DoocsScalarListener is inside a 
             // DoocsProcessScalar, which always holds the right type
-            auto data = (static_cast< ProcessArray<T> & >(*processVariable)).accessData(0);
+            auto data = (static_cast< mtca4u::NDRegisterAccessor<T> & >(*processVariable)).accessData(0);
             // we must not call set_and_archive if there is no history (otherwise it will be activated), but we have to if it is there. -> Abstraction, please!
             if (_doocsVariable->get_histPointer()){
               _doocsVariable->set_and_archive(data);
@@ -58,7 +58,7 @@ namespace ChimeraTK {
           DOOCS_T * _doocsVariable;
       };
     
-      boost::shared_ptr<ProcessArray<T>> _processScalar;
+    boost::shared_ptr<mtca4u::NDRegisterAccessor<T> > _processScalar;
 
     private:
 
@@ -69,7 +69,7 @@ namespace ChimeraTK {
     public:
 
       DoocsProcessScalar( EqFct *eqFct, std::string doocsPropertyName,
-                          boost::shared_ptr< typename ChimeraTK::ProcessArray<T> > const &processScalar,
+                          boost::shared_ptr< typename mtca4u::NDRegisterAccessor<T> > const &processScalar,
                           ControlSystemSynchronizationUtility &syncUtility )
       : DOOCS_T(eqFct, doocsPropertyName.c_str()), _processScalar(processScalar)
       {
@@ -78,7 +78,7 @@ namespace ChimeraTK {
       }
 
       DoocsProcessScalar( std::string doocsPropertyName, EqFct *eqFct,
-                          boost::shared_ptr< typename ChimeraTK::ProcessArray<T> > const &processScalar,
+                          boost::shared_ptr< typename mtca4u::NDRegisterAccessor<T> > const &processScalar,
                           ControlSystemSynchronizationUtility &syncUtility )
       : DOOCS_T(doocsPropertyName.c_str(), eqFct), _processScalar(processScalar)
       {
diff --git a/include/DoocsSpectrum.h b/include/DoocsSpectrum.h
index 7352012..36d2fb1 100644
--- a/include/DoocsSpectrum.h
+++ b/include/DoocsSpectrum.h
@@ -4,7 +4,7 @@
 #include <D_spectrum.h>
 #include <boost/noncopyable.hpp>
 
-#include <ChimeraTK/ControlSystemAdapter/ProcessArray.h>
+#include <mtca4u/NDRegisterAccessor.h>
 #include <ChimeraTK/ControlSystemAdapter/ProcessVariableListener.h>
 #include <ChimeraTK/ControlSystemAdapter/ControlSystemSynchronizationUtility.h>
 
@@ -40,9 +40,7 @@ namespace ChimeraTK {
            * The notification that is executed updates of the doocs process variable
            */
           void notify(boost::shared_ptr< ProcessVariable > processVariable) {
-            // It is safe to static cast because the DoocsArrayListener is inside a 
-            // DoocsSpectrum, which always holds a ProcessArray, never a ProcessScalar
-            ProcessArray<T> & processArray = static_cast< ProcessArray<T> & >(*processVariable);
+            auto & processArray = static_cast< mtca4u::NDRegisterAccessor<T> & >(*processVariable);
             
             // Brute force implementation. Works for all data types T.
             // always get a fresh reference
@@ -59,7 +57,7 @@ namespace ChimeraTK {
 
       };
 
-      boost::shared_ptr< ProcessArray<T> > _processArray;
+      boost::shared_ptr< mtca4u::NDRegisterAccessor<T> > _processArray;
 
       // Internal function which copies the content from the DOOCS container into the 
       // ChimeraTK ProcessArray and calls the send method. Factored out to allow unit testing.
@@ -77,7 +75,7 @@ namespace ChimeraTK {
     public:
 
       DoocsSpectrum( EqFct *eqFct, std::string const & doocsPropertyName,
-                     boost::shared_ptr< typename ChimeraTK::ProcessArray<T> > const &processArray,
+                     boost::shared_ptr< typename mtca4u::NDRegisterAccessor<T> > const &processArray,
                      ControlSystemSynchronizationUtility & syncUtility )
         : D_spectrum( doocsPropertyName.c_str(),
                     processArray->getNumberOfSamples(), eqFct),
diff --git a/src/DoocsPVFactory.cc b/src/DoocsPVFactory.cc
index 847cee6..146ed2c 100644
--- a/src/DoocsPVFactory.cc
+++ b/src/DoocsPVFactory.cc
@@ -20,8 +20,8 @@ namespace ChimeraTK {
   template<class T, class DOOCS_T>
   typename boost::shared_ptr<D_fct> DoocsPVFactory::createDoocsProperty(typename ProcessVariable::SharedPtr & processVariable) {
     // the DoocsProcessArray needs the real ProcessScalar type, not just ProcessVariable
-    typename ProcessArray<T>::SharedPtr processArray
-      = boost::dynamic_pointer_cast< ProcessArray<T> >(processVariable);
+    typename boost::shared_ptr< mtca4u::NDRegisterAccessor<T> > processArray
+      = boost::dynamic_pointer_cast< mtca4u::NDRegisterAccessor<T> >(processVariable);
     if (!processArray){
       throw std::invalid_argument(std::string("DoocsPVFactory::createDoocsArray : processArray is of the wrong type ")
 				  + processVariable->getValueType().name());
@@ -71,8 +71,8 @@ namespace ChimeraTK {
   boost::shared_ptr<D_fct> DoocsPVFactory::createDoocsProperty<std::string, D_string>(
             boost::shared_ptr<ProcessVariable> & processVariable) {
     // the DoocsProcessArray needs the real ProcessScalar type, not just ProcessVariable
-    boost::shared_ptr<ProcessArray<std::string>> processArray
-      = boost::dynamic_pointer_cast< ProcessArray<std::string> >(processVariable);
+    boost::shared_ptr< mtca4u::NDRegisterAccessor<std::string> > processArray
+      = boost::dynamic_pointer_cast< mtca4u::NDRegisterAccessor<std::string> >(processVariable);
     if (!processArray){
       throw std::invalid_argument(std::string("DoocsPVFactory::createDoocsArray : processArray is of the wrong type ")
                                   + processVariable->getValueType().name());
diff --git a/tests/src/testDoocsAdapter.cpp b/tests/src/testDoocsAdapter.cpp
index 5988b5d..01bb42a 100644
--- a/tests/src/testDoocsAdapter.cpp
+++ b/tests/src/testDoocsAdapter.cpp
@@ -7,7 +7,6 @@
 #include "emptyServerFunctions.h"
 
 #include <ChimeraTK/ControlSystemAdapter/DevicePVManager.h>
-#include <ChimeraTK/ControlSystemAdapter/ProcessArray.h>
 #include <ChimeraTK/ControlSystemAdapter/SynchronizationDirection.h>
 
 using namespace boost::unit_test_framework;
-- 
GitLab