lucabaldini / xpedaq

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

Implement a lock-file mechanism for stopping the data acquisition #153

Closed lucabaldini closed 7 years ago

lucabaldini commented 7 years ago

The basic idea being: 1\ the UPS can write a lock file in a given folder 2\ the daq check for the presence of the lock file and, if found, stops the data acquisition.

lucabaldini commented 7 years ago

Getting started on this

diff --git a/daq/pRunController.cpp b/daq/pRunController.cpp
index 573b933..5be15a6 100644
--- a/daq/pRunController.cpp
+++ b/daq/pRunController.cpp
@@ -60,10 +60,12 @@ pRunController::pRunController(std::string configFilePath,
   if (!xpedaqos::fileExists(m_trgMaskFilePath)) {
     xpedaqos::copyFile(m_trgMaskFilePath + ".sample", m_trgMaskFilePath);
   }
+  m_lockFilePath = xpedaqos::rjoin(".ups.lock");
   setupRun();
   m_timer = new QTimer();
   m_timer->setInterval(1000);
   connect(m_timer, SIGNAL(timeout()), this, SLOT(updateRunInfo()));
+  connect(m_timer, SIGNAL(timeout()), this, SLOT(checkLockFile()));
   m_usbController = new pUsbController();
   m_xpolFpga = new pXpolFpga(m_usbController);
   m_dataCollector = new pDataCollector(m_xpolFpga, m_emitBlocks);
@@ -289,6 +291,19 @@ void pRunController::resetRunInfo()
 }

+/*!
+ */
+void pRunController::checkLockFile()
+{
+  if (FILE *file = fopen(m_lockFilePath.c_str(), "r")) {
+    *xpollog::kError << "Lock file " << m_lockFilePath
+                    << " found, stopping run..." << endline;
+    fclose(file);    
+    setStopped();
+  }
+}
+
+
 /*! Nothing to do here.
  */
 void pRunController::fsmSetup()
diff --git a/daq/pRunController.h b/daq/pRunController.h
index eb44649..d671a9c 100644
--- a/daq/pRunController.h
+++ b/daq/pRunController.h
@@ -297,12 +297,21 @@ class pRunController : public pFiniteStateMachine

   /// Flag for requiring the dataCollector to emit data blocks on reading
   bool m_emitBlocks;
+
+  /// Path to the lock file.
+  std::string m_lockFilePath;

  private slots:
-   

+  /// Check the presence of a lock file and stop the DAQ if needed.
+  virtual void checkLockFile();
+
 };

 #endif //PRUNCONTROLLER_H
lucabaldini commented 7 years ago

It goes without saying, this needs to be tested.

csgro commented 7 years ago

In today weekly meeting Fabio said it works, This issue can be closed.