Commit 2b1d36c0 authored by Jerome Locatelli's avatar Jerome Locatelli
Browse files

Merge Intrument_RC_174 branch on trunk

parent ac4d7379
......@@ -36,6 +36,7 @@ CountWithSpectro::CountWithSpectro(const std::string & name) :
spectro.init(this, "spectro");
count.init(this, "count");
spectroSwitcher.init(this, "spectroSwitcher");
integrationTime.init(this, SAVE, "integration_time"); //in microseconds!
numSpectroMeasures.init(this, SAVE, "num_spectro");
......@@ -46,9 +47,14 @@ CountWithSpectro::CountWithSpectro(const std::string & name) :
ySize.init(this, SAVE, "y_size");
zSize.init(this, SAVE, "z_size");
totalYData.init(this, NOSAVE, "total_yData");
subtitle.init(this, SAVE, "subtitle");
useSwitcher.init(this, SAVE, "use_switcher");
yDataArray.init(this, NOSAVE, "yData_array");
initialTime.init(this, NOSAVE, "initial_time");
measureDuration.init(this, NOSAVE, "measure_duration");
yDataArraySecondChannel.init(this, NOSAVE, "yDataArray_secondChannel");
}
CountWithSpectro::~CountWithSpectro() {
......@@ -59,9 +65,13 @@ void CountWithSpectro::postConfiguration() {
xSize = XSIZE;
ySize = numSpectroMeasures();
zSize = 1;
subtitle = count->subtitle();
registerRefresher(numSpectroMeasures, &CountWithSpectro::refreshNumSpectroMeasures, this);
registerUpdater(count->subtitle, &CountWithSpectro::updateSubtitle, this);
registerProgression(count, &CountWithSpectro::updateProgression, this);
// initSwitcherArrays(); //init both arrays to avoid errors
}
void CountWithSpectro::refreshNumSpectroMeasures(int32 number) {
......@@ -75,41 +85,82 @@ void CountWithSpectro::updateProgression() {
commandProgression = count->commandProgression();
}
void CountWithSpectro::updateSubtitle() {
subtitle = count->subtitle();
}
void CountWithSpectro::start() {
//Time already in microseconds!
spectro->integrationTime = integrationTime();
//check the total time of spectro measurement is smaller than the count time
float64 spectroTime = integrationTime() * 0.000001 * numSpectroMeasures(); //should be in seconds
float64 countTime = getCountTimeInSec(); //count->time.setpoint();
if (!useSwitcher()) {
if (spectroTime < countTime) {
//Time already in microseconds!
spectro->integrationTime = integrationTime();
setupCountParams();
//check the total time of spectro measurement is smaller than the count time
float64 spectroTime = integrationTime() * 0.000001 * numSpectroMeasures(); //should be in seconds
float64 countTime = getCountTimeInSec(); //count->time.setpoint();
initArray();
if (spectroTime <= countTime) {
commandStatus.setRunning();
setupCountParams();
//Launch count and spectro at the same time
// Run the threads in parallel in a group
boost::thread_group group;
initArrays(); //before initArray()
group.create_thread(boost::bind(&CountWithSpectro::startCount, this));
group.create_thread(boost::bind(&CountWithSpectro::startSpectro, this));
commandStatus.setRunning();
spectro->mode = QE65000Controller::COUNT_SINGLE;
// Wait for the termination of the threads
group.join_all();
//Launch count and spectro at the same time
// Run the threads in parallel in a group
boost::thread_group group;
//Get data
saveSpectroData();
group.create_thread(boost::bind(&CountWithSpectro::startCount, this));
group.create_thread(boost::bind(&CountWithSpectro::startSpectro, this));
commandStatus.setIdle();
// Wait for the termination of the threads
group.join_all();
//Get data
saveSpectroData();
commandStatus.setIdle();
spectro->mode = QE65000Controller::IDLE;
}
} else {
//error
}
//Suppose here we also keep the same rule as before (but now is double)
spectroSwitcher->integrationTime = integrationTime();
spectroSwitcher->numberOfCycles = 1;
//check the total time of spectro measurement is smaller than the count time
float64 spectroTime = integrationTime() * 0.000001 * numSpectroMeasures() * 2; //!!!!!!!!!!!!!!
float64 countTime = getCountTimeInSec();
if (spectroTime <= countTime) {
setupCountParams();
initArrays();
commandStatus.setRunning();
spectro->mode = QE65000Controller::COUNT_SWITCHER;
//Launch count and spectro at the same time
// Run the threads in parallel in a group
boost::thread_group group;
group.create_thread(boost::bind(&CountWithSpectro::startCount, this));
group.create_thread(boost::bind(&CountWithSpectro::startSwitcher, this));
// Wait for the termination of the threads
group.join_all();
//Get data
saveSwitcherSpectroData();
commandStatus.setIdle();
spectro->mode = QE65000Controller::IDLE;
}
}
}
void CountWithSpectro::stop() {
......@@ -121,15 +172,6 @@ void CountWithSpectro::stop() {
}
void CountWithSpectro::saveSpectroData() {
int32 totalSize = YSIZE * numSpectroMeasures();
totalYData.update(m_totalYData);
totalYData.setSize(totalSize);
int32 numor = any_cast<int32>(count->getValue("numor"));
NexusDataFile::appendTo(numor, "NxD22SpecialServerFile.xml", "NxD22SpecialClientFile.xml");
}
void CountWithSpectro::startCount() {
count->startCommand();
}
......@@ -152,7 +194,37 @@ void CountWithSpectro::startSpectro() {
int32 ySize = YSIZE;
float64* tempYData = spectro->yData();
for (int32 j = 0; j < ySize; j++) {
m_totalYData[ySize * i + j] = tempYData[j];
m_yDataArray[ySize * i + j] = tempYData[j];
}
formerTime = time;
}
}
}
void CountWithSpectro::startSwitcher() {
common::Date startTime = common::Date();
initialTime = startTime.toString("%H:%M:%S");
common::Date formerTime = startTime;
for (int i = 0; i < numSpectroMeasures(); i++) {
if (commandStatus.isRunning()) {
common::Date time = common::Date();
common::Duration duration = time - formerTime;
measureDuration.set(i, duration.getMilliseconds());
spectroSwitcher->startCommand();
int32 ySize = YSIZE;
float64* tempLeftYData = spectroSwitcher->yLeftData();
for (int32 j = 0; j < ySize; j++) {
m_yDataArray[ySize * i + j] = tempLeftYData[j];
}
float64* tempRightYData = spectroSwitcher->yRightData();
for (int32 j = 0; j < ySize; j++) {
m_yDataArraySecondChannel[ySize * i + j] = tempRightYData[j];
}
formerTime = time;
......@@ -163,19 +235,48 @@ void CountWithSpectro::startSpectro() {
void CountWithSpectro::setupCountParams() {
count->time.setpoint = countTime();
count->timeType = timeType();
count->subtitle = subtitle();
}
void CountWithSpectro::initArray() {
if (m_totalYData) {
delete[] m_totalYData;
void CountWithSpectro::initArrays() {
if (m_yDataArray) {
delete[] m_yDataArray;
} else if (m_yDataArraySecondChannel) {
delete[] m_yDataArraySecondChannel;
}
int32 totalSize = YSIZE * numSpectroMeasures();
m_totalYData = new int32[totalSize];
memset(m_totalYData, 0, totalSize * sizeof(int32)); //set to zero
totalYData.update(m_totalYData);
totalYData.setSize(totalSize);
m_yDataArray = new int32[totalSize];
memset(m_yDataArray, 0, totalSize * sizeof(int32)); //set to zero
yDataArray.update(m_yDataArray);
yDataArray.setSize(totalSize);
m_yDataArraySecondChannel = new int32[totalSize];
memset(m_yDataArraySecondChannel, 0, totalSize * sizeof(int32)); //set to zero
yDataArraySecondChannel.update(m_yDataArraySecondChannel);
yDataArraySecondChannel.setSize(totalSize);
}
void CountWithSpectro::saveSpectroData() {
int32 totalSize = YSIZE * numSpectroMeasures();
yDataArray.update(m_yDataArray);
yDataArray.setSize(totalSize);
int32 numor = any_cast<int32>(count->getValue("numor"));
NexusDataFile::appendTo(numor, "NxD22SpecialServerFile.xml", "NxD22SpecialClientFile.xml");
}
void CountWithSpectro::saveSwitcherSpectroData() {
int32 totalSize = YSIZE * numSpectroMeasures();
yDataArray.update(m_yDataArray);
yDataArray.setSize(totalSize);
yDataArraySecondChannel.update(m_yDataArraySecondChannel);
yDataArraySecondChannel.setSize(totalSize);
int32 numor = any_cast<int32>(count->getValue("numor"));
NexusDataFile::appendTo(numor, "NxD22SpecialServerFile.xml", "NxD22SpecialClientFile.xml");
}
......
......@@ -21,6 +21,7 @@
#include <Controller.h>
#include "controllers/spectrometer/QE65000Controller.h"
#include "DualSwitchSpectroController.h"
#include "controllers/common/acquisition/TimeCount.h"
namespace d22special {
......@@ -44,6 +45,7 @@ public:
virtual void stop();
ControllerPtr<QE65000Controller> spectro;
ControllerPtr<DualSwitchSpectroController> spectroSwitcher;
ControllerPtr<acquisition::TimeCount> count;
Property<int32> integrationTime;
......@@ -53,23 +55,33 @@ public:
Property<int32> xSize;
Property<int32> ySize;
Property<int32> zSize;
Property<std::string> subtitle;
Property<bool> useSwitcher;
ArrayProperty<int32> totalYData;
ArrayProperty<int32> yDataArray;
ArrayProperty<int32> yDataArraySecondChannel;
DynamicProperty<int32> measureDuration;
Property<std::string> initialTime;
DynamicProperty<int32> measureDuration;
Property<std::string> initialTime;
void refreshNumSpectroMeasures(int32 number);
void updateProgression();
void updateSubtitle();
private:
void saveSpectroData();
void saveSwitcherSpectroData();
void startCount();
void startSpectro();
void initArray();
void startSwitcher();
void initArrays();
void setupCountParams();
float64 getCountTimeInSec();
int32* m_totalYData;
int32* m_yDataArray;
int32* m_yDataArraySecondChannel;
};
......
......@@ -35,6 +35,8 @@ D22SampleSequencer::D22SampleSequencer(const std::string& name) :
scansToAverage.init(this, SAVE, "scan_average");
useSpectro.init(this, SAVE, "useSpectro");
spectroController.init(this, "spectro");
m_started = false;
}
D22SampleSequencer::~D22SampleSequencer() {
......@@ -44,75 +46,65 @@ void D22SampleSequencer::postConfiguration() {
SampleSequencer::postConfiguration();
}
void D22SampleSequencer::execute(const string& command, bool blocking, bool logging) { //necessary?
void D22SampleSequencer::execute(const string& command, bool blocking, bool logging) {
spectroController->mode = QE65000Controller::SEQUENCE;
if (command == START_COMMAND) {
m_started = true;
} else if (command == STOP_COMMAND) {
m_started = false;
}
SampleSequencer::execute(command, blocking, logging);
//Once the last count is done force to do another spectro measure
if (command == START_COMMAND) {
doLastMeasure();
m_started = false;
}
spectroController->mode = QE65000Controller::ALONE;
// spectroController->mode = QE65000Controller::ALONE;
}
void D22SampleSequencer::updateProperty(ChangeAspect* aChangeAspect) {
SampleSequencer::updateProgress(aChangeAspect);
string propertyName = aChangeAspect->getStringParam();
if (propertyName == "actual_cha") {
int32 actualSlot = any_cast<int32>(m_sampleChanger->getValue(propertyName));
spectroController->setPlotName(actualSlot);
actualSlotNumber = actualSlot;
} else if (propertyName == "status_message") {
std::string countStatus = any_cast<std::string>(m_Count->getValue(propertyName));
if (countStatus == "Idle") {
if (countStatus == "Idle" && m_started == true) { // only save spectro if count has been started from this controller
getSpectro();
}
} else if (propertyName == "numor") {
lastNumor = any_cast<int32>(m_Count->getValue(propertyName));
}
}
void D22SampleSequencer::refreshSetValue(string propertyName, const boost::any aValue) throw (CannotSetValue) {
SampleSequencer::refreshSetValue(propertyName, aValue);
}
void D22SampleSequencer::getSpectro() {
spectroController->start();
//Copy data in nexus file (remember it is delayed in one position)
if (actualSlotNumber > 1) {
int32 numor = any_cast<int32>(m_Count->getValue("numor"));
NexusDataFile::appendTo(numor - 1, "NxD22SpecialServerFile.xml", "NxD22SpecialClientFile.xml");
}
}
void D22SampleSequencer::doLastMeasure() {
//Last measure = move sample (using sampleChanger) + get spectro + save data in nexus file
Sender<ClientCommand>::begin();
Sender<ClientCommand>::post(ClientCommand(m_sampleChanger, START_COMMAND));
Sender<ClientCommand>::endIf();
......@@ -124,7 +116,6 @@ void D22SampleSequencer::doLastMeasure() {
NexusDataFile::appendTo(numor, "NxD22SpecialServerFile.xml", "NxD22SpecialClientFile.xml");
// cout << "adding new data (theoretically) in data file: " << numor << " value of last numor: " << lastNumor << endl;
}
}
......
......@@ -21,7 +21,6 @@
#include "InstrumentAbstraction/Lss/SampleSequencer.h"
#include "controllers/spectrometer/QE65000Controller.h"
using namespace spectrometer;
......@@ -73,6 +72,7 @@ private:
int32 actualSlotNumber;
int32 lastNumor;
bool m_started;
};
}
......
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include <Controller.h>
#include "DualSwitchSpectroController.h"
#include "controllers/common/family/Families.h"
#include "InstrumentAbstraction/Base/AbstractIOController.h"
#include "Utilities/Counter.h"
#include "ics/DeviceContainer/Def/IODef.h"
namespace d22special {
const std::string DualSwitchSpectroController::TYPE = "dualSwitchSpectro";
DualSwitchSpectroController::DualSwitchSpectroController(const std::string& name) :
ExperimentController(name), controller::Stoppable(this) {
setFamily(family::SAMPLE_ENVIRONMENT);
//init properties
integrationTime.init(this, SAVE, "integration_time");
numberOfCycles.init(this, SAVE, "number_cycles");
executionStatus.init(this, SAVE, "execution_status");
xData.init(this, SAVE, "x_data");
xLeftData.init(this, SAVE, "x_left_data");
yLeftData.init(this, SAVE, "y_leftData");
yRightData.init(this, SAVE, "y_rightData");
m_StopActivated = false;
//It has attached one module (QE65000 controller) and one controller (switcher)
spectroController.init(this, "spectro");
switcherController.init(this, "swicther");
}
DualSwitchSpectroController::~DualSwitchSpectroController() {
}
void DualSwitchSpectroController::postConfiguration() {
registerProgression(spectroController, &DualSwitchSpectroController::updateProgression, this);
}
void DualSwitchSpectroController::start() {
m_StopActivated = false;
commandProgression = 0;
//spectroController->mode = QE65000Controller::SWITCH;
//Before measuring spectrum check if the spectrometer is plugged in
// if (spectroController->isConnected()) {
executionStatus.update("idle");
//Set up values of spectro
spectroController->integrationTime = integrationTime();
int32 cyclesNumber = numberOfCycles();
while (cyclesNumber > 0 && !m_StopActivated) {
commandProgression = (numberOfCycles() - cyclesNumber) * 100 / numberOfCycles();
// First: start switcher -> we begin for OPEN position (== IN)
executionStatus.update("Measuring Left");
switcherController->setOpen();
switcherController->startCommand();
//Second: start spectro
spectroController->start();
updateData();
//Again same process: start switcher (now to CLOSE == OUT) and then spectro
executionStatus.update("Measuring Right");
switcherController->setClose();
switcherController->startCommand();
spectroController->start();
updateData();
cyclesNumber = cyclesNumber - 1;
}
commandProgression = 99;
executionStatus.update("finished");
// } else {
// cout << "spectro disconnected" << endl;
// executionStatus.update("disconnected");
// }
}
void DualSwitchSpectroController::stop() {
m_StopActivated = true;
commandProgression = 100;
}
void DualSwitchSpectroController::updateProgression() {
// int32 progression = 0;
// commandProgression = progression;
}
void DualSwitchSpectroController::updateData() {
//should be done with an updater...
if (executionStatus() == "Measuring Right") {
int32 xSize = spectroController->xData.getSize();
xData.update(spectroController->xData());
xData.setSize(xSize);
xData.sendEvent();
int32 yRightSize = spectroController->yData.getSize();
yRightData.update(spectroController->yData());
yRightData.setSize(yRightSize);
yRightData.sendEvent();
} else {
//testing two x arrays of data
int32 xSize = spectroController->xData.getSize();
xLeftData.update(spectroController->xData());
xLeftData.setSize(xSize);
xLeftData.sendEvent();
int32 yLeftSize = spectroController->yData.getSize();
yLeftData.update(spectroController->yData());
yLeftData.setSize(yLeftSize);
yLeftData.sendEvent();
}
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef DUALSWITCHSPECTROCONTROLLER_H_
#define DUALSWITCHSPECTROCONTROLLER_H_
#include "controllers/spectrometer/QE65000Controller.h"
#include "controllers/common/state/stateio/ShutterController.h"
using namespace spectrometer;
namespace d22special {
class DualSwitchSpectroController : public ExperimentController, public controller::Stoppable {