Commit bac99534 authored by Cristina Cocho's avatar Cristina Cocho

Added local copy data file when HPLC measures are long in time

parent 63aedfa3
......@@ -201,6 +201,7 @@ void HplcController::postConfiguration() {
registerUpdater(m_collector->actualTube, &HplcController::updateActualTubePosition, this);
registerUpdater(m_detector->conditionIsReached, &HplcController::updateConditionIsReached, this);
registerUpdater(m_count->statusMessage, &HplcController::updateDetectorStatus, this);
registerUpdater(m_count->numor, &HplcController::updateDetectorNumor, this);
// Initialize dynamic properties and enumerated labels&values
numberValvePositions = NUMBER_VALVE_POSITIONS;
......@@ -330,6 +331,11 @@ void HplcController::updateDetectorStatus() {
}
}
void HplcController::updateDetectorNumor() {
// Pass info to UVUSB detector
m_detector->m_actualNumor = m_count->numor();
}
void HplcController::start() {
log(Level::s_Info) << name << " start measuring " << endlog;
commandStatus.setRunning();
......@@ -563,14 +569,21 @@ void HplcController::doDataAcquisition() {
m_collector->start();
}
// (2) Do measure
// (2) Establish the criteria used to save spectra data from UVUSBDetector
m_detector->saveSpetrumData = true;
if (exposureTime() > 1800) { // validate this requirement, up to now we use half an hour as requirement
m_detector->saveInLocalDataFile = true;
} else {
m_detector->saveInLocalDataFile = false;
}
// (3) Do measure
boost::thread_group group;
group.create_thread(boost::bind(&HplcController::startCount, this));
group.create_thread(boost::bind(&HplcController::startDetector, this));
// Wait for the termination of the threads
group.join_all();
}
void HplcController::startCount() {
......
......@@ -134,6 +134,7 @@ private:
virtual void updateActualTubePosition();
virtual void updateConditionIsReached();
virtual void updateDetectorStatus();
virtual void updateDetectorNumor();
static const int32 VALVE_LOAD_POS;
static const int32 VALVE_INJECT_POS;
......
......@@ -17,6 +17,7 @@
*/
#include "UVUsbDetectorController.h"
#include <common/base/ServerProperties.h>
namespace d22 {
......@@ -89,6 +90,11 @@ UVUsbDetectorController::UVUsbDetectorController(const std::string& controllerNa
// Initialize class members
m_hasBeenStopped = false;
m_conditionReached = false;
saveSpetrumData = false;
saveInLocalDataFile = false;
m_isFirstEntry = false;
m_actualNumor = 0;
m_initialNumor = 0;
intensity0 = nullptr;
measuredYData = nullptr;
chromato1 = nullptr;
......@@ -179,6 +185,10 @@ void UVUsbDetectorController::start() {
// Retrieve size of data from detector (the cleanData method sets it up to zero)
size = m_detectorDriver->size();
// Do not check condition
useThreshold = false;
saveSpetrumData = false;
calculateI0();
doAcqWithDataSaving();
}
......@@ -244,6 +254,8 @@ void UVUsbDetectorController::doAcqWithDataSaving() {
common::Duration iterationTime;
m_initialNumor = m_actualNumor; // The initialNumor is used as name for dataFile
m_isFirstEntry = true;
while ((m_totalDuration.getSeconds() < timeOfMeasure()) && (!m_hasBeenStopped)) {
common::Date startTime = common::Date();
......@@ -275,8 +287,8 @@ void UVUsbDetectorController::doAcqWithDataSaving() {
iterationTime = endTime - startTime;
sleep(1);
}
stop();
}
......@@ -334,12 +346,12 @@ void UVUsbDetectorController::processData() {
if (resultInAbsorbance()) {
for (int32 j = 0; j < yDataSize; j++) {
absorptionData[j] = ::log((intensity0[j] / measuredYData[j]));
vectorForYData.push_back(absorptionData[j]);
// vectorForYData.push_back(absorptionData[j]); // used when storing data directly in nexus file
}
} else {
for (int32 j = 0; j < yDataSize; j++) {
absorptionData[j] = measuredYData[j];
vectorForYData.push_back(absorptionData[j]);
// vectorForYData.push_back(absorptionData[j]); // used when storing data directly in nexus file
}
}
......@@ -485,8 +497,14 @@ void UVUsbDetectorController::processData() {
xDataInFlowRate.update(xDataToSaveInFlowRate);
xDataInFlowRate.setSize(chromatoSize);
// Mutex block
storeDataBlock();
if (saveSpetrumData) {
if (saveInLocalDataFile) {
saveSpectraInLocalDataFile(absorptionData, size());
} else {
// Mutex block
saveSpectraInNexusFile();
}
}
//Free memory here
delete[] absorptionData;
......@@ -601,9 +619,16 @@ void UVUsbDetectorController::getActualLambdaValueForSlope() {
}
}
void UVUsbDetectorController::storeDataBlock() {
void UVUsbDetectorController::saveSpectraInNexusFile() {
std::lock_guard<std::mutex> lock(*m_mutex);
// Fill first the vector
int32 yDataSize = m_detectorDriver->size();
for (int32 j = 0; j < yDataSize; j++) {
vectorForYData.push_back(absorptionData[j]); // used when storing data directly in nexus file
}
// Store spectrum data which will be used in data file
int32 vectorSize = vectorForYData.size();
float64* tempYBlockData = new float64[vectorSize];
......@@ -617,6 +642,37 @@ void UVUsbDetectorController::storeDataBlock() {
}
void UVUsbDetectorController::saveSpectraInLocalDataFile(float64* dataBlock, int32 dataBlockSize) {
if (m_isFirstEntry) {
m_initialNumor = m_actualNumor;
m_isFirstEntry = false;
}
std::ostringstream filename;
filename << common::ServerProperties::getInstance()->getNomadDataPath() << "spectraData_" << m_initialNumor << ".txt";
std::ofstream dataFile;
// Open data file
dataFile.open(filename.str().c_str(), std::ios::app);
std::string dataString;
if (dataFile) {
// Convert data into a string in order to make it readable
for (int32 i = 0; i < dataBlockSize; i++) {
std::ostringstream ss;
ss << boost::format("%1%") % dataBlock[i];
dataString = dataString + " " + ss.str();
}
dataString = dataString + "\n";
std::cout << "Copying data in file " << filename.str() << " of size " << dataBlockSize << std::endl;
dataFile << dataString;
dataFile.close();
}
}
}
......
......@@ -119,9 +119,15 @@ public:
DriverPtr<UVDetectorCommon> m_detectorDriver;
int32 m_actualNumor;
int32 m_initialNumor;
bool saveSpetrumData;
bool saveInLocalDataFile;
private:
bool m_hasBeenStopped;
bool m_conditionReached;
bool m_isFirstEntry;
float64* intensity0;
float64* measuredYData;
......@@ -161,7 +167,8 @@ private:
void getActualLambdaValueForSlope();
virtual void makeAutozero();
void storeDataBlock();
void saveSpectraInNexusFile();
void saveSpectraInLocalDataFile(float64* dataBlock, int32 dataBlockSize);
static const int32 ABSORBANCE_THRESHOLD_MODE;
static const int32 SLOPE_THRESHOLD_MODE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment