lucabaldini / xpedaq

Data acquisition software for the X-ray polarimetry explorers
GNU General Public License v2.0
0 stars 0 forks source link

Data readout with the long buffer does not work #127

Open lucabaldini opened 8 years ago

lucabaldini commented 8 years ago

We should investigate this and fix it as soon as possible. Essentially the DAQ seems to be taking data just fine, but only a subset of the data buffers (e.g., 1/5) are written to disk under Windows.

Everything seems to be working correctly under Linux instead (to be confirmed).

Note that the old bug that caused half of the events to be thrown away (issue #80) and that we thought was fixed, most likely was not fixed. Fabio seems to remember that they only checked the data acquisition rate on the DAQ windows, which would explain everything.

albertomanfreda commented 8 years ago

I have found no trace of this problem running on the pcpixirad1 machine (Win 7). My test was a data acquisition in charge injection (run 002_0000453), with 133722 events acquired in large buffer mode (in 207 datablocks). They have all been correctly written in the output file and I was able to play back them succesfully on the monitor. Actually, the real number of events is 134368, so the DAQ evt counter and the runstats file both have the same, wrong, number.

albertomanfreda commented 8 years ago

It is possible that the bug is connected with a limitation of the stack size on certain systems. I have committed the following change to pDataCollector.cpp

{
   m_dataFIFO = new pDataFIFO(m_outputFilePath, m_userPreferences);
   m_numMalformedBlocks = 0;
-  unsigned long dataBufferDimension = SRAM_DIM*2;
-  unsigned char dataBuffer[SRAM_DIM*2];
+  m_running = true;
+  unsigned long dataBufferDimension = SRAM_DIM*2;  
+  unsigned char* dataBuffer = new (std::nothrow) unsigned char[dataBufferDimension];
+  if (dataBuffer == nullptr)
+  {
+    std::cout << "allocation failed" << std::endl;
+    m_running = false;    
+  }  
   int maxSize = m_detectorConfiguration->maxBufferSize();
   pDataBlock *curDataBlock;
   m_usbController->resetSequencer();
   m_usbController->startSequencer();
-  m_running = true;
   int errorCode = 0;
   while (m_running) {
     errorCode = m_usbController->readData(dataBuffer, &dataBufferDimension);
@@ -105,6 +110,7 @@ void pDataCollector::run()
   m_usbController->writeUsbSettings();
   m_usbController->readUsbSettings();
   delete m_dataFIFO;
+  delete [] dataBuffer;
 }

 /*! This is needed since the data collector needs run based information.

in an attempt to fix the bug. In principle it should change nothing of how the application works (it merely allocates the buffer on the heap rather than on the stack and release the memory at the end of the function). I have tested that the daq application still runs and writes data correctly both in large and small buffer mode on the pixirad1 machine (Win 7). However, we need to test the change on the machine where we observed the bug, in order to see if the problem is actually fixed.