From eed0809a8f0b37b93d827f95ab708e2e6c1d85fc Mon Sep 17 00:00:00 2001
From: Martin Killenberg <martin.killenberg@desy.de>
Date: Mon, 30 Oct 2017 23:06:32 +0100
Subject: [PATCH] separated DoocsSpectrum into header and cc file, as it should
 be. It was still header only from the time where it was a tempates class.

---
 include/DoocsSpectrum.h | 69 +++++----------------------------
 src/DoocsSpectrum.cc    | 85 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+), 60 deletions(-)
 create mode 100644 src/DoocsSpectrum.cc

diff --git a/include/DoocsSpectrum.h b/include/DoocsSpectrum.h
index 7fc3afc..f326ec2 100644
--- a/include/DoocsSpectrum.h
+++ b/include/DoocsSpectrum.h
@@ -27,64 +27,24 @@ namespace ChimeraTK {
                      boost::shared_ptr<  mtca4u::NDRegisterAccessor<float> > const &processArray,
                      DoocsUpdater & updater,
                      boost::shared_ptr<  mtca4u::NDRegisterAccessor<float> > const &startAccessor,
-                     boost::shared_ptr<  mtca4u::NDRegisterAccessor<float> > const &incrementAccessor)
-       : D_spectrum( doocsPropertyName.c_str(), processArray->getNumberOfSamples(), eqFct),
-      _processArray( processArray ), _startAccessor(startAccessor), _incrementAccessor(incrementAccessor)
-      {
-        if (processArray->isReadable()){
-          updater.addVariable( *processArray , std::bind(&DoocsSpectrum::updateDoocsBuffer, this));
-        }
-        if (startAccessor && startAccessor->isReadable()){
-          updater.addVariable( *startAccessor, std::bind(&DoocsSpectrum::updateParameters, this));
-        }
-        if (incrementAccessor && incrementAccessor->isReadable()){
-          updater.addVariable( *incrementAccessor, std::bind(&DoocsSpectrum::updateParameters, this));
-        }
-      }
+                     boost::shared_ptr<  mtca4u::NDRegisterAccessor<float> > const &incrementAccessor);
 
       /**
        * Overload the set function which is called by DOOCS to inject sending to the device.
        */
-      void set(EqAdr *eqAdr, EqData *data1, EqData *data2, EqFct *eqFct) override{
-        D_spectrum::set(eqAdr, data1, data2, eqFct);
-        sendToDevice();
-      }
-      
-      /**
+      void set(EqAdr *eqAdr, EqData *data1, EqData *data2, EqFct *eqFct) override;
+
+        /**
        * Override the Doocs auto_init() method, which is called after initialising the value of
        *  the property from the config file.
        */
-      void auto_init (void) override{
-        D_spectrum::auto_init();
-        // send the current value to the device
-        if (_processArray->isWriteable()){
-          sendToDevice();
-        }
-      }
+      void auto_init (void) override;
 
       // call this function after a tranfer element has requested it.
-      void updateDoocsBuffer(){
-       // FIXME: find the efficient memcopying implementation for float
-        std::vector<float> & processVector = _processArray->accessChannel(0); 
-        for(size_t i=0; i < processVector.size(); ++i) {
-          fill_spectrum(i, processVector[i]);
-        }
-      }
+      void updateDoocsBuffer();
 
-      void updateParameters(){
-        float start, increment;
-        if (_startAccessor){
-          start=_startAccessor->accessData(0);
-        }else{
-          start=this->spec_start();
-        }
-        if (_incrementAccessor){
-          increment=_incrementAccessor->accessData(0);
-        }else{
-          increment=this->spec_inc();
-        }
-        spectrum_parameter( this->spec_time(), start, increment, this->spec_status() );
-      }
+      // callback function after the start or increment variables have changed
+      void updateParameters();
 
   protected:
       boost::shared_ptr< mtca4u::NDRegisterAccessor<float> > _processArray;
@@ -93,18 +53,7 @@ namespace ChimeraTK {
 
       // 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.
-      void sendToDevice() {
-        // Brute force implementation with a loop. Works for all data types.
-        // FIXME: find the efficient, memcopying function for float
-        // always get a fresh reference
-        std::vector<float> &processVector = _processArray->accessChannel(0); 
-        size_t arraySize = processVector.size();
-        for (size_t i=0; i < arraySize; ++i){
-          processVector[i] = read_spectrum(i);
-        }
-        _processArray->write();
-      }
-
+      void sendToDevice();
   };
 
 } // namespace ChimeraTK
diff --git a/src/DoocsSpectrum.cc b/src/DoocsSpectrum.cc
new file mode 100644
index 0000000..c4a89f2
--- /dev/null
+++ b/src/DoocsSpectrum.cc
@@ -0,0 +1,85 @@
+#include "DoocsSpectrum.h"
+
+#include <eq_fct.h>
+
+namespace ChimeraTK {
+  
+  DoocsSpectrum::DoocsSpectrum( EqFct *eqFct, std::string const & doocsPropertyName,
+    boost::shared_ptr<  mtca4u::NDRegisterAccessor<float> > const &processArray,
+    DoocsUpdater & updater,
+    boost::shared_ptr<  mtca4u::NDRegisterAccessor<float> > const &startAccessor,
+    boost::shared_ptr<  mtca4u::NDRegisterAccessor<float> > const &incrementAccessor)
+
+    : D_spectrum( doocsPropertyName.c_str(), processArray->getNumberOfSamples(), eqFct),
+      _processArray( processArray ), _startAccessor(startAccessor), _incrementAccessor(incrementAccessor)
+  {
+    if (processArray->isReadable()){
+      updater.addVariable( *processArray , std::bind(&DoocsSpectrum::updateDoocsBuffer, this));
+    }
+    if (startAccessor && startAccessor->isReadable()){
+      updater.addVariable( *startAccessor, std::bind(&DoocsSpectrum::updateParameters, this));
+    }
+    if (incrementAccessor && incrementAccessor->isReadable()){
+      updater.addVariable( *incrementAccessor, std::bind(&DoocsSpectrum::updateParameters, this));
+    }
+  }
+  
+  void DoocsSpectrum::set(EqAdr *eqAdr, EqData *data1, EqData *data2, EqFct *eqFct){
+    D_spectrum::set(eqAdr, data1, data2, eqFct);
+    sendToDevice();
+  }
+      
+  void DoocsSpectrum::auto_init (void){
+    D_spectrum::auto_init();
+    // send the current value to the device
+    if (_processArray->isWriteable()){
+      sendToDevice();
+    }
+  }
+
+  void DoocsSpectrum::updateDoocsBuffer(){
+    // FIXME: find the efficient memcopying implementation for float
+    std::vector<float> & processVector = _processArray->accessChannel(0); 
+    
+    for(size_t i=0; i < processVector.size(); ++i) {
+      fill_spectrum(i, processVector[i]);
+    }
+  }
+
+  void DoocsSpectrum::updateParameters(){
+    float start, increment;
+    if (_startAccessor){
+      start=_startAccessor->accessData(0);
+    }else{
+      start=this->spec_start();
+    }
+    if (_incrementAccessor){
+      increment=_incrementAccessor->accessData(0);
+    }else{
+      increment=this->spec_inc();
+    }
+    
+    if (this->get_eqfct()){
+      this->get_eqfct()->lock();
+    }
+    spectrum_parameter( this->spec_time(), start, increment, this->spec_status() );
+    if (this->get_eqfct()){
+      this->get_eqfct()->unlock();
+    }
+  }
+  
+  void DoocsSpectrum::sendToDevice() {
+    // Brute force implementation with a loop. Works for all data types.
+    // FIXME: find the efficient, memcopying function for float
+    // always get a fresh reference
+    std::vector<float> &processVector = _processArray->accessChannel(0); 
+    size_t arraySize = processVector.size();
+    for (size_t i=0; i < arraySize; ++i){
+      processVector[i] = read_spectrum(i);
+    }
+    _processArray->write();
+  }
+  
+} // namespace ChimeraTK
+
+
-- 
GitLab