Commit f3f0c04c authored by Franck Cecillon's avatar Franck Cecillon

Pol sum (calculate Fillping Ratio)

parent e393f3b9
......@@ -3,4 +3,6 @@
<controller class="d7::D7FlipperScan"/>
<controller class="d7::D7VirtualBank"/>
<controller class="d7::D7MonochromatorSetting"/>
<controller class="d7::PolarizationSummarise"/>
</module>
/*
* 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 <controllers/tof/d7/PolarizationSummarise.h>
#include "InstrumentAbstraction/CommandNames.h"
#include "DeviceContainer/Def/CommandDef.h"
#include "controllers/common/family/Families.h"
#include "controllers/common/acquisition/Count.h"
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
using namespace boost;
using namespace std;
namespace d7 {
const string PolarizationSummarise::TYPE = "pol_sum";
/*
* Constantes
*/
/*
* Constructor
*/
PolarizationSummarise::PolarizationSummarise(const string& name) :
ExperimentController(name) {
setFamily(family::BEAM_PARAMETERS);
nDetectors.init(this, SAVE, "nDetectors");
refreshTime.init(this, SAVE, "refresh_time");
isEnable.init(this, SAVE, "is_enable");
controlAcquisition.init(this, SAVE, "control_acquisition");
count.init(this, "count");
countSpy.init(this, "spy");
scanRepeater.init(this, "repeater");
// m_DetectorElement.init(this, "detector");
nPhasePol.init(this, NOSAVE, "nPhasePol");
detSum.init(this, NOSAVE, "detSum");
mon1Sum.init(this, NOSAVE, "mon1Sum");
mon2Sum.init(this, NOSAVE, "mon2Sum");
statePol.init(this, NOSAVE, "statePol");
stateB1B2.init(this, NOSAVE, "stateB1B2");
nPhaseFlip.init(this, NOSAVE, "nPhaseFlip");
flipLabel.init(this, NOSAVE, "flipLabel");
flipOnInd.init(this, NOSAVE, "flipOnInd");
flipOffInd.init(this, NOSAVE, "flipOffInd");
flipRatioDet.init(this, NOSAVE, "flipRatioDet");
flipRatioM2.init(this, NOSAVE, "flipRatioM2");
m_Counting = false;
m_GateStatus = 0;
m_threadActive = false;
m_StopRequested = false;
registerFunction(TYPE);
/*float64* ic_sum = new float64[newSize];
float64* ic_rate = new float64[newSize];
*/
}
/*
* Destructor
*/
PolarizationSummarise::~PolarizationSummarise() {
// Empty
}
/*
* postConfiguration
*/
void PolarizationSummarise::postConfiguration() {
registerUpdater(countSpy->counting, &PolarizationSummarise::updateStatus, this);
}
/*
* updateStatus
*/
void PolarizationSummarise::updateStatus() {
//cout << " PolarizationSummarise::updateStatus 01" << endl;
if (isEnable() == true) {
/*if (countSpy->counting()) {
cout << " PolarizationSummarise::updateStatus 02 isCounting" << endl;
} else {
cout << " PolarizationSummarise::updateStatus 02 Finish Counting" << endl;
}*/
if ((countSpy->counting()) && (!m_Counting)) {
//cout << " PolarizationSummarise::updateStatus 03 START THREAD " << endl;
m_Counting = true;
scan::CountIterator* citer = scanRepeater->getCountIterator();
m_IndStep = citer->getActualStep();
m_TotalStep = citer->getNumberOfSteps();
//cout << "11111111111111111111" << citer->getPropertyValuesLog() << endl;
if (m_IndStep == 1) {
initArraySum(m_IndStep, m_TotalStep);
}
//cout << " m_TotalStep " << m_TotalStep << "m_IndStep " << m_IndStep << endl;
//boost::thread td(boost::bind(&PolarizationSummarise::startPolarizationSummariseControl, this));
} else if ((!countSpy->counting()) && (m_Counting)) {
//cout << " PolarizationSummarise::updateStatus 04 STOP THREAD " << endl;
if (m_IndStep < m_TotalStep) {
StoreArraySum(m_IndStep, m_TotalStep);
} else {
StoreArraySum(m_IndStep, m_TotalStep);
FinalizeArraySum(m_IndStep, m_TotalStep);
}
m_StopRequested = true;
m_Counting = false;
}
}
}
/*
* updateProperty
*/
void PolarizationSummarise::updateProperty(ChangeAspect* aChangeAspect) {
// cout << "CountSummary updateProperty " << aChangeAspect->getControllerName() << " " << aChangeAspect->getStringParam() << endl;
}
/*
* startPolarizationSummariseControl
*/
void PolarizationSummarise::startPolarizationSummariseControl() {
}
void PolarizationSummarise::initArraySum(int32 indStep, int32 totalStep) {
cout << "PolarizationSummarise::initArraySum " << indStep << "/" << totalStep << endl;
nPhasePol = totalStep;
detSum.resize(totalStep);
mon1Sum.resize(totalStep);
mon2Sum.resize(totalStep);
statePol.resize(totalStep);
stateB1B2.resize(totalStep);
nPhaseFlip = totalStep / 2;
flipLabel.resize(totalStep / 2);
flipOnInd.resize(totalStep / 2);
flipOffInd.resize(totalStep / 2);
flipRatioDet.resize(totalStep / 2);
flipRatioM2.resize(totalStep / 2);
for (int32 kk = 0; kk < totalStep / 2; kk++) {
flipLabel.set(kk, "NO");
flipOnInd.set(kk, -1);
flipOffInd.set(kk, -1);
}
int32 lstep = 0;
scan::CountIterator* citer = scanRepeater->getCountIterator();
int32 loopPh = 0;
int32 maxPh = 0;
for (int32 kk = 0; kk < totalStep; kk++) {
string val1 = any_cast<string>(citer->getActionProperty(kk, 0));
string val2 = any_cast<string>(citer->getActionValue(kk, 0));
string val3 = any_cast<string>(citer->getActionProperty(kk, 1));
string val4 = any_cast<string>(citer->getActionValue(kk, 1));
//cout << " val2 " << val2 << " val4 " << val4 << endl<< endl;
if (kk == 0) {
flipLabel.set(loopPh, val2);
if (val4 == "ON") {
flipOnInd.set(loopPh, kk);
} else {
flipOffInd.set(loopPh, kk);
}
loopPh++;
maxPh++;
} else {
int32 indP = -1;
int32 ki = 0;
while ((indP == -1) && (ki < loopPh)) {
//cout << "TEST " << ki << " val2 " << val2 << " flipLabel " << flipLabel.get(ki) << endl;
if (val2 == flipLabel.get(ki)) {
//cout << " TROUVE " << endl;
indP = ki;
}
ki++;
}
//cout << " Indice globale kk " << kk << " found indP "<< indP << endl;
if (indP == -1) {
//cout << " Add new Phase at indice " << loopPh << endl;
flipLabel.set(loopPh, val2);
if (val4 == "ON") {
flipOnInd.set(maxPh, kk);
} else {
flipOffInd.set(maxPh, kk);
}
loopPh++;
maxPh++;
} else {
//cout << " Phase exist at indice " << loopPh << endl;
if (val4 == "ON") {
flipOnInd.set(indP, kk);
} else {
flipOffInd.set(indP, kk);
}
loopPh++;
}
}
}
m_coherentPol = true;
//cout << "loopPh " << loopPh << endl;
for (int32 kk = 0; kk < totalStep / 2; kk++) {
//cout << " Label " << flipLabel.get(kk) << " Indice ON " << flipOnInd.get(kk) << " Indice Off " << flipOffInd.get(kk)<< endl;
if (flipOnInd.get(kk) == -1) {
m_coherentPol = false;
//cout << "Prb with " << flipLabel.get(kk) << " not indice for phase ON" << endl;
}
if (flipOffInd.get(kk) == -1) {
m_coherentPol = false;
//cout << "Prb with " << flipLabel.get(kk) << " not indice for phase OFF" << endl;
}
}
}
void PolarizationSummarise::StoreArraySum(int32 indStep, int32 totalStep) {
/*cout << "PolarizationSummarise::StoreArraySum " << indStep << "/" << totalStep << endl;
cout << "PolarizationSummarise:: count->detSum() " << count->detSum() << "count->mon1Sum() " << count->mon1Sum()
<< "count->mon2Sum() " << count->mon2Sum() << endl;*/
int32 lstep = indStep - 1;
detSum.set(lstep, count->detSum());
mon1Sum.set(lstep, count->mon1Sum());
mon2Sum.set(lstep, count->mon2Sum());
statePol.set(lstep, "AA");
stateB1B2.set(lstep, "BB");
scan::CountIterator* citer = scanRepeater->getCountIterator();
string val1 = any_cast<string>(citer->getActionProperty(lstep, 0));
string val2 = any_cast<string>(citer->getActionValue(lstep, 0));
//cout << " val1" << val1 << " val2" << val2 << endl;
string val3 = any_cast<string>(citer->getActionProperty(lstep, 1));
string val4 = any_cast<string>(citer->getActionValue(lstep, 1));
//cout << " val3" << val3 << " val4" << val4 << endl;
statePol.set(lstep, val2);
stateB1B2.set(lstep, val4);
}
void PolarizationSummarise::FinalizeArraySum(int32 indStep, int32 totalStep) {
//cout << "PolarizationSummarise::FinalizeArraySum " << indStep << "/" << totalStep << endl;
float64 lres;
for (int32 kk = 0; kk < nPhaseFlip(); kk++) {
lres = (mon2Sum.get(flipOffInd.get(kk)) / mon2Sum.get(flipOnInd.get(kk)))
* (mon1Sum.get(flipOffInd.get(kk)) / mon1Sum.get(flipOnInd.get(kk)));
//cout << "lres M2 " << lres << endl;
flipRatioM2.set(kk, lres);
lres = (detSum.get(flipOffInd.get(kk)) / detSum.get(flipOnInd.get(kk)))
* (mon1Sum.get(flipOffInd.get(kk)) / mon1Sum.get(flipOnInd.get(kk)));
//cout << "lres DET " << lres << endl;
flipRatioDet.set(kk, lres);
//cout << flipLabel.get(kk) << " RatioMonitor2 " << flipRatioM2.get(kk) << endl;
//cout << flipLabel.get(kk) << " RatioDetector " << flipRatioDet.get(kk) << endl;
}
// Exemple
// 18:21:39 info Flipping Ratios - M2: ZPO 0.92
// 18:21:39 info Flipping Ratios - Detector: ZPO 16.82
stringstream messM2;
messM2 << "Flipping Ratios - Monitor2 ";
stringstream messDet;
messDet << "Flipping Ratios - Detector ";
for (int32 kk = 0; kk < nPhaseFlip(); kk++) {
messM2 << boost::format("%10s (%6.2e /s)") % flipLabel.get(kk) % flipRatioM2.get(kk);
messDet << boost::format("%10s (%6.2e /s)") % flipLabel.get(kk) % flipRatioDet.get(kk);
}
//cout << messM2.str() << endl;
cout << messDet.str() << endl;
usleep(50000); // ? avant la fin du TofCount ?
log(Level::s_Info) << messM2.str() << endlog;
log(Level::s_Info) << messDet.str() << endlog;
}
}
/*
* 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 POL_SUM_H
#define POL_SUM_H
#include <vector>
#include <Controller.h>
#include "controllers/common/utilities/CountSpy.h"
#include "controllers/common/acquisition/detector/DetectorController.h"
#include "controllers/common/scanlegacy/GenericScan1D.h"
#include "controllers/common/acquisition/TimeCount.h"
#include "controllers/common/scanlegacy/CountController.h"
namespace d7 {
class PolarizationSummarise : public ExperimentController {
public:
//! Type of controller
static const std::string TYPE;
/*!
* \brief Constructor
* \param[in] name the name of controller
*/
PolarizationSummarise(const std::string& name);
/*!
*\brief Destructor
* PolarizationSummarise Class destructor
*/
~PolarizationSummarise();
/*
* Properties
*/
Property<int32> nDetectors;
Property<float64> refreshTime;
Property<bool> isEnable;
Property<bool> controlAcquisition;
Property<int32> nPhasePol;
DynamicProperty <float64> detSum;
DynamicProperty <float64> mon1Sum;
DynamicProperty <float64> mon2Sum;
DynamicProperty <std::string> statePol;
DynamicProperty <std::string> stateB1B2;
Property<int32> nPhaseFlip;
DynamicProperty <std::string> flipLabel;
DynamicProperty <int32 > flipOnInd;
DynamicProperty <int32 > flipOffInd;
DynamicProperty <float64 > flipRatioDet;
DynamicProperty <float64 > flipRatioM2;
/*
ArrayProperty<float64> ic_sum;
ArrayProperty<float64> ic_rate;
Property<float64> actualTime;
Property<std::string, SETPOINT> beamMessage;*/
/*!
*\sa ExperimentController::postConfiguration
*/
virtual void postConfiguration();
protected:
virtual void updateProperty(ChangeAspect* aChangeAspect);
private:
/*!
*\brief update gate status
* When the current controller change of status, if a new count is starting,
* we start a new thread for the startPolarizationSummariseControl procedure
* If the current count finish the flag m_counting is assign to false
*/
void updateStatus();
/*!
*\brief startPolarizationSummariseControl
*/
void startPolarizationSummariseControl();
ControllerPtr<acquisition::TimeCount> count;
ControllerPtr<utilities::CountSpy> countSpy;
ControllerPtr<scan::ScanRepeater> scanRepeater;
/* std::vector<ControllerPtr<acquisition::DetectorController> > m_Detectors; //! Pointers on the detector controllers
ControllerPtr<scan::ParameterizableScan1D> m_ContrScanOmega;
ControllerPtr<scan::ParameterizableScan1D> m_ContrSom;
ControllerPtr<d19::D19ScanSequencer> m_ContrD19ScanSequencer ;
ControllerPtr<axis::AxisController> m_Omega ;
*/
void initArraySum(int32 indStep, int32 totalStep);
void StoreArraySum(int32 indStep, int32 totalStep);
void FinalizeArraySum(int32 indStep, int32 totalStep);
int32 m_Counting;
int32 m_GateStatus;
bool m_threadActive;
bool m_StopRequested;
int32 m_IndStep;
int32 m_TotalStep;
bool m_coherentPol;;
};
}
#endif //POL_SUM_H
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