extensive debugging

This commit is contained in:
2025-03-18 17:20:12 +01:00
parent dd6354ff94
commit ac0394e176
4 changed files with 87 additions and 15 deletions

View File

@ -90,6 +90,8 @@ template <class dataType> class analogDetector {
ymin = 0; ymin = 0;
ymax = ny; ymax = ny;
fMode = ePedestal; fMode = ePedestal;
dMode = eInterpolating;
//std::cout << "dMode " << dMode << std::endl;
thr = 0; thr = 0;
myFile = NULL; myFile = NULL;
#ifdef ROOTSPECTRUM #ifdef ROOTSPECTRUM
@ -111,15 +113,40 @@ template <class dataType> class analogDetector {
destructor. Deletes the pdestalSubtraction array and the image destructor. Deletes the pdestalSubtraction array and the image
*/ */
virtual ~analogDetector() { virtual ~analogDetector() {
std::cout << "#### Debug: Destructing analogDetector! ####" << std::endl;
for (int i = 0; i < ny; i++) { for (int i = 0; i < ny; i++) {
delete[] stat[i]; std::cout << " # " << i;
if (stat[i]) {
if (i==0) {
std::cout << "#### Debug: Deleting analogDetector member stat[" << i << "] at " << stat[i] << " ####" << std::endl;
}
delete[] stat[i];
if (i==0) {
std::cout << "#### Debug: Deleted analogDetector member stat[" << i << "]! ####" << std::endl;
}
stat[i] = nullptr;
}
//delete[] stat[i];
/* delete [] pedMean[i]; */ /* delete [] pedMean[i]; */
/* delete [] pedVariance[i]; */ /* delete [] pedVariance[i]; */
}; }
std::cout << " #\n";
/* delete [] pedMean; */ /* delete [] pedMean; */
/* delete [] pedVariance; */ /* delete [] pedVariance; */
delete[] stat; //delete[] stat;
delete[] image; //delete[] image;
if (stat) {
std::cout << "#### Debug: Deleting analogDetector member stat at " << stat << " ####" << std::endl;
delete[] stat;
std::cout << "#### Debug: Deleted analogDetector member stat! ####" << std::endl;
stat = nullptr;
}
if (image) {
std::cout << "#### Debug: Deleting analogDetector member image at " << image << " ####" << std::endl;
delete[] image;
std::cout << "#### Debug: Deleted analogDetector member image! ####" << std::endl;
image = nullptr;
}
#ifdef ROOTSPECTRUM #ifdef ROOTSPECTRUM
delete hs; delete hs;
#ifdef ROOTCLUST #ifdef ROOTCLUST
@ -137,6 +164,7 @@ template <class dataType> class analogDetector {
*/ */
analogDetector(analogDetector *orig) { analogDetector(analogDetector *orig) {
/* copy construction from orig*/ /* copy construction from orig*/
std::cout << "#### Debug: Calling analogDetector cloning method! ####" << std::endl;
det = orig->det; det = orig->det;
nx = orig->nx; nx = orig->nx;
ny = orig->ny; ny = orig->ny;
@ -152,6 +180,8 @@ template <class dataType> class analogDetector {
thr = orig->thr; thr = orig->thr;
// nSigma=orig->nSigma; // nSigma=orig->nSigma;
fMode = orig->fMode; fMode = orig->fMode;
dMode = orig->dMode;
//std::cout << "dMode " << dMode << std::endl;
myFile = orig->myFile; myFile = orig->myFile;
stat = new pedestalSubtraction *[ny]; stat = new pedestalSubtraction *[ny];

View File

@ -362,10 +362,17 @@ int HDF5File::ReadImage (uint16_t* image, std::vector<hsize_t>& offset ) {
// Check if we reached the end of file // Check if we reached the end of file
// Compares that the offsets of frame and storage cell (Z and S) have reached the end of file // Compares that the offsets of frame and storage cell (Z and S) have reached the end of file
// Excludes X and Y indices (of the image dataset) from the comparison // Excludes X and Y indices (of the image dataset) from the comparison
// As it is now, this never triggers, because frame_offset[1] is never equals file_dims[1]=16
/*
if( std::equal( frame_offset.cbegin(), frame_offset.cend()-2, file_dims.cbegin() ) ) { if( std::equal( frame_offset.cbegin(), frame_offset.cend()-2, file_dims.cbegin() ) ) {
printf("End of file reached\n"); printf("End of file reached\n");
return -1; return -1;
} }
*/
if (frame_offset[0] == file_dims[0]) {
printf("End of file reached\n");
return -1;
}
/* //old /* //old
if (frame_offset[0] == file_dims[0]-1) { if (frame_offset[0] == file_dims[0]-1) {
printf("end of file\n"); printf("end of file\n");

View File

@ -113,11 +113,18 @@ class threadedAnalogDetector {
virtual ~threadedAnalogDetector() { virtual ~threadedAnalogDetector() {
std::cout << "#### Debug: Destructing threadedAnalogDetector! ####" << std::endl;
StopThread(); StopThread();
delete fifoFree; if (fifoFree) { delete fifoFree; fifoFree = nullptr; }
delete fifoData; if (fifoData) { delete fifoData; fifoData = nullptr; }
delete det; // Call destructor for singlePhotonDetector if (det) {
std::cout << "#### Debug: Deleting threadedAnalogDetector member det at " << det << " ####" << std::endl;
delete det; // Call destructor for singlePhotonDetector
std::cout << "#### Debug: Deleted threadedAnalogDetector member det! ####" << std::endl;
det = nullptr;
}
} }
/** Returns true if the thread was successfully started, false if there was /** Returns true if the thread was successfully started, false if there was
@ -356,11 +363,14 @@ class multiThreadedAnalogDetector {
*/ */
// Create separate detectorObjects for each SC (each owns its mutex) // Create separate detectorObjects for each SC (each owns its mutex)
std::cout << "#### Debug: Constructing vector of analogDetector objects! ####" << std::endl;
std::vector< analogDetector<uint16_t>* > sc_detectors(nSC, nullptr); std::vector< analogDetector<uint16_t>* > sc_detectors(nSC, nullptr);
sc_detectors[0] = d; // First storage cell uses the given detector sc_detectors[0] = d; // First storage cell uses the given detector
std::cout << "#### Debug: Copied analogDetector object for storage cell 0! ####" << std::endl;
for (int sc = 1; sc < nSC; ++sc) { for (int sc = 1; sc < nSC; ++sc) {
sc_detectors[sc] = d->Copy(); // Ensure unique mutex for each SC sc_detectors[sc] = d->Copy(); // Ensure unique mutex for each SC
std::cout << "#### Debug: Copied analogDetector object for storage cell " << sc << "! ####" << std::endl;
} }
// Distribute threads among storage cells // Distribute threads among storage cells
@ -409,7 +419,7 @@ class multiThreadedAnalogDetector {
} }
virtual ~multiThreadedAnalogDetector() { virtual ~multiThreadedAnalogDetector() {
//std::cout << "Destructing multiThreadedAnalogDetector..." << std::endl; std::cout << "#### Debug: Destructing multiThreadedAnalogDetector! ####" << std::endl;
//StopThreads(); // Superfluous, leads to double delete //StopThreads(); // Superfluous, leads to double delete
/* Reverse loop for destruction. /* Reverse loop for destruction.
@ -417,8 +427,10 @@ class multiThreadedAnalogDetector {
* (ensure shared mutex is deleted last). * (ensure shared mutex is deleted last).
* Optional solution: reference counting (safer but more complex) */ * Optional solution: reference counting (safer but more complex) */
for (int i = nThreads - 1; i >= 0; --i) { for (int i = nThreads - 1; i >= 0; --i) {
//std::cout << "Deleting dets[" << i << "]" << std::endl; std::cout << "#### Debug: Deleting multiThreadedAnalogDetector member dets[" << i << "] at " << dets[i] << " ####" << std::endl;
delete dets[i]; //StopThread() called by each ~threadedAnalogDetector() delete dets[i]; //StopThread() called by each ~threadedAnalogDetector()
std::cout << "#### Debug: Deleted multiThreadedAnalogDetector member dets [" << i << "]! ####" << std::endl;
dets[i] = nullptr;
} }
} }

View File

@ -89,14 +89,37 @@ class singlePhotonDetector : public analogDetector<uint16_t> {
Destructor. Deletes the cluster structure, event mask, and destroys the mutex. Destructor. Deletes the cluster structure, event mask, and destroys the mutex.
*/ */
virtual ~singlePhotonDetector() { virtual ~singlePhotonDetector() {
delete[] clusters; std::cout << "#### Debug: Destructing singlePhotonDetector! ####" << std::endl;
for (int i = 0; i < ny; i++) if (clusters) {
delete[] eventMask[i]; std::cout << "#### Debug: Deleting singlePhotonDetector member clusters at " << clusters << " ####" << std::endl;
delete[] eventMask; delete[] clusters;
std::cout << "#### Debug: Deleted singlePhotonDetector member clusters! ####" << std::endl;
clusters = nullptr;
}
for (int i = 0; i < ny; i++) {
if (eventMask[i]) {
if (i==0) {
std::cout << "#### Debug: Deleting singlePhotonDetector member eventMask[i]! ####" << std::endl;
}
delete[] eventMask[i];
if (i==0) {
std::cout << "#### Debug: Deleted singlePhotonDetector member eventMask[i]! ####" << std::endl;
}
eventMask[i] = nullptr;
}
}
if (eventMask) {
std::cout << "#### Debug: Deleting singlePhotonDetector member eventMask at " << eventMask << " ####" << std::endl;
delete[] eventMask;
std::cout << "#### Debug: Deleted singlePhotonDetector member eventMask! ####" << std::endl;
eventMask = nullptr;
}
if (ownsMutex) { if (ownsMutex) {
if (fm) { if (fm) {
//pthread_mutex_destroy(fm); // Destroy the mutex (not necessary with std::mutex) //pthread_mutex_destroy(fm); // Destroy the mutex (not necessary with std::mutex)
std::cout << "#### Debug: Deleting std::mutex singlePhotonDetector member fm at " << fm << " ####" << std::endl;
delete fm; // Free the memory allocated for the mutex delete fm; // Free the memory allocated for the mutex
std::cout << "#### Debug: Deleted std::mutex singlePhotonDetector member fm! ####" << std::endl;
fm = nullptr; // Set the pointer to nullptr to avoid dangling pointer fm = nullptr; // Set the pointer to nullptr to avoid dangling pointer
} }
} }
@ -166,7 +189,7 @@ class singlePhotonDetector : public analogDetector<uint16_t> {
eventMask = new eventType *[ny]; eventMask = new eventType *[ny];
for (int i = 0; i < ny; i++) { for (int i = 0; i < ny; i++) {
eventMask[i] = new eventType[nx]; eventMask[i] = new eventType[nx];
std::copy(other.eventMask[i], other.eventMask[i] + nx, eventMask[i]); //std::copy(other.eventMask[i], other.eventMask[i] + nx, eventMask[i]);
} }
eMin = other.eMin; eMin = other.eMin;
@ -180,7 +203,7 @@ class singlePhotonDetector : public analogDetector<uint16_t> {
c3 = sqrt(clusterSizeY * clusterSize); c3 = sqrt(clusterSizeY * clusterSize);
clusters = new single_photon_hit[nx * ny]; clusters = new single_photon_hit[nx * ny];
std::copy(other.clusters, other.clusters + (nx * ny), clusters); //std::copy(other.clusters, other.clusters + (nx * ny), clusters);
setClusterSize(clusterSize); setClusterSize(clusterSize);