Commit c137ef6c authored by Cristina Cocho's avatar Cristina Cocho
Browse files

Added CountWithSpectrp module. Improved other D22 "special" modules.

parent 2ef472d6
......@@ -519,5 +519,13 @@
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Release">
<resource resourceType="PROJECT" workspacePath="/NomadSpecialModules"/>
</configuration>
<configuration configurationName="Debug">
<resource resourceType="PROJECT" workspacePath="/NomadSpecialModules"/>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
</cproject>
......@@ -3,6 +3,7 @@
<name>NomadSpecialModules</name>
<comment></comment>
<projects>
<project>NomadModules</project>
<project>NomadServer</project>
</projects>
<buildSpec>
......
/*
* 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 "CountWithSpectro.h"
#include "controllers/common/family/Families.h"
#include "PersistenceServices/DataFile/NexusDataFile.h"
namespace d22special {
const std::string CountWithSpectro::TYPE = "count_with_spectro";
const int32 CountWithSpectro::XSIZE = 1044; //should be retrieved directly from the driver...
const int32 CountWithSpectro::YSIZE = 1044;
CountWithSpectro::CountWithSpectro(const std::string & name) :
ExperimentController(name), controller::Stoppable(this) {
setFamily(family::SAMPLE_ENVIRONMENT);
registerFunction(TYPE);
spectro.init(this, "spectro");
count.init(this, "count");
integrationTime.init(this, SAVE, "integration_time"); //It is in seconds!
numSpectroMeasures.init(this, SAVE, "num_spectro");
timeType.init(this, SAVE, "time_type");
countTime.init(this, SAVE, "count_time");
xSize.init(this, SAVE, "x_size");
ySize.init(this, SAVE, "y_size");
zSize.init(this, SAVE, "z_size");
totalYData.init(this, NOSAVE, "total_yData");
}
CountWithSpectro::~CountWithSpectro() {
}
void CountWithSpectro::postConfiguration() {
xSize = XSIZE;
ySize = numSpectroMeasures();
zSize = 1;
registerRefresher(numSpectroMeasures, &CountWithSpectro::refreshNumSpectroMeasures, this);
registerProgression(count, &CountWithSpectro::updateProgression, this);
}
void CountWithSpectro::refreshNumSpectroMeasures(int32 number) {
ySize = number; //This property is only used to save the data in nexus file
}
void CountWithSpectro::updateProgression() {
commandProgression = count->commandProgression();
}
void CountWithSpectro::start() {
//Important! convert the time (seconds) into microseconds -> the driver needs it in that unit
float64 timeInMicrosec = integrationTime() * 1000000;
spectro->integrationTime = timeInMicrosec;
//check the total time of spectro measurement is smaller than the count time
float64 spectroTime = integrationTime() * numSpectroMeasures();
float64 countTime = getCountTimeInSec(); //count->time.setpoint();
if (spectroTime < countTime) {
setupCountParams();
initArray();
commandStatus.setRunning();
//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::startSpectro, this));
// Wait for the termination of the threads
group.join_all();
//Get data
saveSpectroData();
commandStatus.setIdle();
} else {
//error
}
}
void CountWithSpectro::stop() {
if (commandStatus.isRunning()) {
count->stopCommand();
spectro->stopCommand();
}
commandStatus.setWarning();
}
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();
}
void CountWithSpectro::startSpectro() {
for (int i = 0; i < numSpectroMeasures(); i++) {
spectro->startCommand();
int32 ySize = spectro->yData.getSize(); //be careful, maybe the driver gives us a different size
float64* tempYData = spectro->yData();
for (int32 j = 0; j < ySize; j++) {
m_totalYData[ySize * i + j] = tempYData[j];
}
}
}
void CountWithSpectro::setupCountParams() {
count->time.setpoint = countTime();
count->timeType = timeType();
}
void CountWithSpectro::initArray() {
if (m_totalYData) {
delete[] m_totalYData;
}
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);
}
float64 CountWithSpectro::getCountTimeInSec() {
float64 time;
if (timeType() == "h") {
time = countTime() * 3600.;
} else if (timeType() == "m") {
time = countTime() * 60.;
} else if (timeType() == "s") {
time = countTime();
}
return time;
}
}
/*
* 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 COUNTWITHSPECTRO_H_
#define COUNTWITHSPECTRO_H_
#include <Controller.h>
#include "controllers/spectrometer/QE65000Controller.h"
#include "controllers/common/acquisition/TimeCount.h"
namespace d22special {
using namespace spectrometer;
class CountWithSpectro: public ExperimentController, public controller::Stoppable {
public:
static const std::string TYPE;
static const int32 XSIZE;
static const int32 YSIZE;
CountWithSpectro(const std::string & name);
virtual ~CountWithSpectro();
virtual void postConfiguration();
virtual void start();
virtual void stop();
ControllerPtr<QE65000Controller> spectro;
ControllerPtr<acquisition::TimeCount> count;
Property<int32> integrationTime;
Property<int32> numSpectroMeasures;
Property<std::string> timeType;
Property<float64> countTime;
Property<int32> xSize;
Property<int32> ySize;
Property<int32> zSize;
ArrayProperty<int32> totalYData;
void refreshNumSpectroMeasures(int32 number);
void updateProgression();
private:
void saveSpectroData();
void startCount();
void startSpectro();
void initArray();
void setupCountParams();
float64 getCountTimeInSec();
int32* m_totalYData;
};
}
#endif /* COUNTWITHSPECTRO_H_ */
......@@ -17,6 +17,7 @@
*/
#include <Controller.h>
#include "D22SampleSequencer.h"
#include "controllers/common/family/Families.h"
#include "PersistenceServices/DataFile/NexusDataFile.h"
namespace d22special {
......@@ -24,10 +25,14 @@ namespace d22special {
const string D22SampleSequencer::TYPE = "d22_sample_sequencer";
D22SampleSequencer::D22SampleSequencer(const std::string& name) :
::SampleSequencer(name, "") {
d22::SampleSequencer(name) {
registerFunction(TYPE);
setFamily(family::SAMPLE_ENVIRONMENT);
//init properties
integrationTime.init(this, SAVE, "integration_time");
scansToAverage.init(this, SAVE, "scan_average");
useSpectro.init(this, SAVE, "useSpectro");
spectroController.init(this, "spectro");
}
......@@ -35,76 +40,78 @@ D22SampleSequencer::D22SampleSequencer(const std::string& name) :
D22SampleSequencer::~D22SampleSequencer() {
}
void D22SampleSequencer::execute(const string& command, bool blocking, bool logging) { //necessary?
void D22SampleSequencer::postConfiguration() {
SampleSequencer::postConfiguration();
//Set up measuring mode in spectro controller
// spectroController->mode = QE65000Controller::SEQUENCE;
registerUpdater(sampleChanger->slot, &D22SampleSequencer::updateActualSlot, this);
registerUpdater(count->statusMessage, &D22SampleSequencer::updateStatusMessage, this);
registerUpdater(count->numor, &D22SampleSequencer::updateNumor, this);
registerUpdater(spectroController->integrationTime, &D22SampleSequencer::updateIntegrationTime, this);
registerUpdater(spectroController->scansToAverage, &D22SampleSequencer::updateScansToAverage, this);
//temporary until sampleSequencer is migrated
if (command == START_COMMAND) {
m_StartActivated = true;
spectroController->mode = QE65000Controller::SEQUENCE;
SampleSequencer::execute(command, blocking, logging);
}
//Once the last count is done force to do another spectro measure
doLastMeasure();
m_StartActivated = false;
spectroController->mode = QE65000Controller::ALONE;
void D22SampleSequencer::updateActualSlot() {
spectroController->setPlotName(sampleChanger->slot());
actualSlotNumber = sampleChanger->slot();
}
} else if (command == STOP_COMMAND) {
m_StartActivated = false;
SampleSequencer::execute(command, blocking, logging);
void D22SampleSequencer::updateStatusMessage() {
std::string countStatus = count->statusMessage();
if (countStatus == "Idle") {
getSpectro();
}
}
void D22SampleSequencer::postConfiguration() {
SampleSequencer::postConfiguration();
//Set up measuring mode in spectro controller
// spectroController->mode = QE65000Controller::SEQUENCE;
void D22SampleSequencer::updateNumor() {
lastNumor = count->numor();
}
void D22SampleSequencer::updateIntegrationTime() {
integrationTime = spectroController->integrationTime();
}
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") {
getSpectro();
}
void D22SampleSequencer::updateScansToAverage() {
scansToAverage = spectroController->scansToAverage();
}
} else if (propertyName == "numor") {
lastNumor = any_cast<int32>(m_Count->getValue(propertyName));
}
void D22SampleSequencer::start() {
commandStatus.setRunning();
spectroController->mode = QE65000Controller::SEQUENCE;
d22::SampleSequencer::start();
//Once the last count is done force to do another spectro measure
doLastMeasure();
commandStatus.setIdle();
spectroController->mode = QE65000Controller::ALONE;
}
void D22SampleSequencer::refreshSetValue(string propertyName, const boost::any aValue) throw (CannotSetValue) {
SampleSequencer::refreshSetValue(propertyName, aValue);
void D22SampleSequencer::stop() {
commandStatus.setWarning();
d22::SampleSequencer::stop();
}
void D22SampleSequencer::getSpectro() {
spectroController->start();
//Copy data in nexus file (remember it is delayed in one position)
if (actualSlotNumber > 1 && m_StartActivated) {
int32 numor = any_cast<int32>(m_Count->getValue("numor"));
cout << "appending data to nexus file! (1)" << endl;
NexusDataFile::appendTo(numor - 1, "NxD22SpecialServerFile.xml", "NxD22SpecialClientFile.xml");
//Check the sampleSequencer is running
if (commandStatus.isRunning()) {
spectroController->start();
//Copy data in nexus file (remember it is delayed in one position)
if (actualSlotNumber > 1 && commandStatus.isRunning()) {
int32 numor = any_cast<int32>(count->getValue("numor"));
cout << "appending data to nexus file! (1)" << numor - 1 << endl;
NexusDataFile::appendTo(numor - 1, "NxD22SpecialServerFile.xml", "NxD22SpecialClientFile.xml");
}
}
}
void D22SampleSequencer::doLastMeasure() {
if (m_StartActivated) {
if (commandStatus.isRunning()) {
//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();
sampleChanger->start();
spectroController->start();
int32 numor = any_cast<int32>(m_Count->getValue("numor"));
int32 numor = any_cast<int32>(count->getValue("numor"));
cout << "appending data to nexus file! (2) " << numor << endl;
NexusDataFile::appendTo(numor, "NxD22SpecialServerFile.xml", "NxD22SpecialClientFile.xml");
// cout << "adding new data (theoretically) in data file: " << numor << " value of last numor: " << lastNumor << endl;
......
......@@ -19,15 +19,15 @@
#ifndef IN16BSAMPLESEQUENCER_H_
#define IN16BSAMPLESEQUENCER_H_
#include "InstrumentAbstraction/Lss/SampleSequencer.h"
#include "controllers/lss/d22/sampleControl/SampleSequencer.h"
#include "controllers/spectrometer/QE65000Controller.h"
using namespace spectrometer;
using namespace d22;
namespace d22special {
class D22SampleSequencer: public ::SampleSequencer{
class D22SampleSequencer : public d22::SampleSequencer {
public:
......@@ -38,16 +38,21 @@ public:
virtual ~D22SampleSequencer();
DynamicProperty<int32> useSpectro;
Property<int32> integrationTime;
Property<int32> scansToAverage;
ControllerPtr<QE65000Controller> spectroController;
virtual void execute(const string& command, bool blocking, bool logging = false);
virtual void updateProperty(ChangeAspect* aChangeAspect);
virtual void postConfiguration();
virtual void refreshSetValue(string propertyName, const boost::any aValue) throw (CannotSetValue);
virtual void start();
virtual void stop();
virtual void updateActualSlot();
virtual void updateStatusMessage();
virtual void updateNumor();
virtual void updateIntegrationTime();
virtual void updateScansToAverage();
private:
......@@ -57,8 +62,6 @@ private:
int32 actualSlotNumber;
int32 lastNumor;
bool m_StartActivated;
};
}
......
<module name="d22special">
<include path="$(NOMAD_HOME)/../NomadModules/src"/>
<controller class="d22special::D22SampleSequencer"/>
<controller class="d22special::CountWithSpectro"/>
</module>
\ No newline at end of file
count_with_spectro.integration_timePrefix=Integration time
count_with_spectro.integration_timeSuffix=s
count_with_spectro.numSpectro=Num. Spectros
count_with_spectro.countTime=Count time
# Radio buttons h/m/s
count_with_spectro.hValue=h
count_with_spectro.hLabel=h
count_with_spectro.mValue=m
count_with_spectro.mLabel=m
count_with_spectro.sValue=s
count_with_spectro.sLabel=s
\ No newline at end of file
<controller_plugin_config type="count_with_spectro">
<image key="SPECTRO"/>
<settings view="count_with_spectroView.xml"/>
</controller_plugin_config>
\ No newline at end of file
<controller type="count_with_spectro">
</controller>
\ No newline at end of file
<plugin>
<controller type="count_with_spectro" role="count_with_spectro1" />
<text role="count_with_spectro1" property="count_time" prefix="count_with_spectro.countTime"/>
<radio role="count_with_spectro1" property="time_type" valuesAndLabels="count_with_spectro.h,count_with_spectro.m,count_with_spectro.s" spaceBefore="false" />
<newline />
<text role="count_with_spectro1" property="integration_time" prefix="count_with_spectro.integration_timePrefix" suffix="count_with_spectro.integration_timeSuffix"/>
<text role="count_with_spectro1" property="num_spectro" prefix="count_with_spectro.numSpectro"/>
</plugin>
\ No newline at end of file
d22_sample_sequencer.changer_numberPrefix=Changer name
d22_sample_sequencer.slotPrefix=Slot
d22_sample_sequencer.acquisitionTimePrefix=Duration
d22_sample_sequencer.titlePrefix=Run Title
d22_sample_sequencer.transmissionPrefix=Transmission
d22_sample_sequencer.thicknessPrefix=Thickness
d22_sample_sequencer.shortSlotPrefix=Slot
d22_sample_sequencer.shortAcquisitionTimePrefix=Time
d22_sample_sequencer.shortTitlePrefix=Title
d22_sample_sequencer.shortTransmissionPrefix=Trans
d22_sample_sequencer.shortThicknessPrefix=Thick
d22_sample_sequencer.samplechangerGroup=Sample Changer
d22_sample_sequencer.acquisitionGroup=Acquisition
d22_sample_sequencer.slotLabel=Used Slots
d22_sample_sequencer.maxSlotLabel=Max Slots
d22_sample_sequencer.totalTimeLabel=Total Time
d22_sample_sequencer.changer_numberPrefix=Changer #
d22_sample_sequencer.wanted_nbpositionLabel=Wanted number of positions
# Radio buttons h/m/s
d22_sample_sequencer.hValue=h
d22_sample_sequencer.hLabel=h
d22_sample_sequencer.mValue=m
d22_sample_sequencer.mLabel=m
d22_sample_sequencer.sValue=s
d22_sample_sequencer.sLabel=s
# Time-Monitor switcher
d22_sample_sequencer.timeValue=time
d22_sample_sequencer.timeLabel=Time
d22_sample_sequencer.timeImage=MODE_TIME
d22_sample_sequencer.countsImage=MODE_COUNTS
d22_sample_sequencer.countsValue=counts
d22_sample_sequencer.countsLabel=Monitor
#values and labels
d22_sample_sequencer.changer1Value=1
d22_sample_sequencer.changer1Label=Changer#1
d22_sample_sequencer.changer2Value=2
d22_sample_sequencer.changer2Label=Changer#2
d22_sample_sequencer.changer3Value=3
d22_sample_sequencer.changer3Label=Changer#3
d22_sample_sequencer.changer4Value=4
d22_sample_sequencer.changer4Label=Changer#4
d22_sample_sequencer.changer5Value=5
d22_sample_sequencer.changer5Label=Changer#5
d22_sample_sequencer.changer6Value=6
d22_sample_sequencer.changer6Label=Changer#6
d22_sample_sequencer.changer7Value=7
d22_sample_sequencer.changer7Label=Changer#7
d22_sample_sequencer.setFollowingValuesMessage=Set following values to current one
d22_sample_sequencer.incrementFollowingValuesMessage=Autofill following incrementally
\ No newline at end of file
d22_sample_sequencer.changer_numberPrefix=Changer #
d22_sample_sequencer.wanted_slotLabel=Wanted number of positions
d22_sample_sequencer.maxSlotLabel= Max Slots
d22_sample_sequencer.totalTimeLabel=Total Time
d22_sample_sequencer.integration_time=Integration Time
d22_sample_sequencer.scan_average=Scans to average
# Groups
d22_sample_sequencer.acquisitionGroup=Acquisition
d22_sample_sequencer.samplechangerGroup=Sample Changer
d22_sample_sequencer.spectroGroup=Spectro