From ea288a1939b009772beecdffeb64e8d5f4774754 Mon Sep 17 00:00:00 2001 From: vhinger Date: Mon, 10 Feb 2025 16:10:53 +0100 Subject: [PATCH] Globally implement Copy() function for deep copy of detector objects --- slsDetectorCalibration/analogDetector.h | 9 ++++++++ .../interpolatingDetector.h | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/slsDetectorCalibration/analogDetector.h b/slsDetectorCalibration/analogDetector.h index 0bd28a73e..f0e560cb9 100644 --- a/slsDetectorCalibration/analogDetector.h +++ b/slsDetectorCalibration/analogDetector.h @@ -222,6 +222,15 @@ template class analogDetector { */ virtual analogDetector *Clone() = 0; + /** + Deep copy. Must be virtual! + This is a new addition because of multithreaded storage cell data (where each sc has its own mutex). + If the pure virtual function exists here, EVERY derived class has to overwrite it! + That means a Copy() function must also be implemented in any derived class. + \returns a deep copy of the original analog detector + */ + virtual analogDetector *Copy() = 0; + /** Gives an id to the structure. For debugging purposes in case of multithreading. \param i is to be set \returns current id diff --git a/slsDetectorCalibration/interpolatingDetector.h b/slsDetectorCalibration/interpolatingDetector.h index 81fdaf5c4..ecfd3428e 100644 --- a/slsDetectorCalibration/interpolatingDetector.h +++ b/slsDetectorCalibration/interpolatingDetector.h @@ -54,6 +54,10 @@ class interpolatingDetector : public singlePhotonDetector { pthread_mutex_init(fi, NULL); }; + /** + pointer-based copy constructor (cloner) + \param orig detector to be copied + */ interpolatingDetector(interpolatingDetector *orig) : singlePhotonDetector(orig) { // if (orig->interp) @@ -66,10 +70,28 @@ class interpolatingDetector : public singlePhotonDetector { fi = orig->fi; } + /** + * copy constructor (deep copy) + * stricly, TODO: Implement Rule of Five! + * (copy op=, move ctor, and move op= would need to be defined) + */ + interpolatingDetector(interpolatingDetector const& other) + : singlePhotonDetector(other) { + + interp = other.interp; + + id = other.id; + fi = other.fi; + } + virtual interpolatingDetector *Clone() { return new interpolatingDetector(this); } + virtual interpolatingDetector *Copy() { + return new interpolatingDetector(*this); + } + virtual int setId(int i) { id = i; // interp->setId(id);