Skip to content
Snippets Groups Projects
Commit 7e76cd37 authored by Martin Killenberg's avatar Martin Killenberg
Browse files

IFFF: First version with instantiated DoocsIfff

- Shows up in Doocs
- Test does not check functionality yet, just that it's there
parent 6e01279e
No related branches found
No related tags found
No related merge requests found
#pragma once
#include <D_xy.h>
#include <boost/noncopyable.hpp>
#include <ChimeraTK/NDRegisterAccessor.h>
#include <ChimeraTK/DataConsistencyGroup.h>
class EqFct;
namespace ChimeraTK {
class DoocsUpdater;
class DoocsIfff : public D_ifff, public boost::noncopyable {
public:
// Constructor with history enabled
DoocsIfff(EqFct* eqFct, std::string const& doocsPropertyName,
boost::shared_ptr<NDRegisterAccessor<int>> const& i1Value,
boost::shared_ptr<NDRegisterAccessor<float>> const& f1Value,
boost::shared_ptr<NDRegisterAccessor<float>> const& f2Value,
boost::shared_ptr<NDRegisterAccessor<float>> const& f3Value, DoocsUpdater& updater);
// Constructor without history
DoocsIfff(std::string const& doocsPropertyName, EqFct* eqFct,
boost::shared_ptr<NDRegisterAccessor<int>> const& i1Value,
boost::shared_ptr<NDRegisterAccessor<float>> const& f1Value,
boost::shared_ptr<NDRegisterAccessor<float>> const& f2Value,
boost::shared_ptr<NDRegisterAccessor<float>> const& f3Value, DoocsUpdater& updater);
protected:
void updateValues(TransferElementID& elementId);
DataConsistencyGroup _consistencyGroup;
boost::shared_ptr<NDRegisterAccessor<int>> _i1Value;
boost::shared_ptr<NDRegisterAccessor<float>> _f1Value;
boost::shared_ptr<NDRegisterAccessor<float>> _f2Value;
boost::shared_ptr<NDRegisterAccessor<float>> _f3Value;
};
} // namespace ChimeraTK
......@@ -38,12 +38,13 @@ namespace ChimeraTK {
// create the DOOCS property. Note: DOOCS_T is only used for scalar
// properties, not for arrays!
template<class T, class DOOCS_T>
typename boost::shared_ptr<D_fct> createDoocsScalar(AutoPropertyDescription const& propertyDescription,
DecoratorType decoratorType);
typename boost::shared_ptr<D_fct> createDoocsScalar(
AutoPropertyDescription const& propertyDescription, DecoratorType decoratorType);
/// @todo FIXME: use SpectrumDescription here
boost::shared_ptr<D_fct> createDoocsSpectrum(SpectrumDescription const& spectrumDescription);
boost::shared_ptr<D_fct> createXy(XyDescription const& xyDescription);
boost::shared_ptr<D_fct> createIfff(IfffDescription const& ifffDescription);
boost::shared_ptr<D_fct> createDoocsArray(std::shared_ptr<AutoPropertyDescription> const& spectrumDescription);
......@@ -60,8 +61,7 @@ namespace ChimeraTK {
// specialisation for strings
template<>
typename boost::shared_ptr<D_fct> DoocsPVFactory::createDoocsScalar<std::string, D_string>(
AutoPropertyDescription const& propertyDescription,
DecoratorType decoratorType);
AutoPropertyDescription const& propertyDescription, DecoratorType decoratorType);
} // namespace ChimeraTK
......
#include "DoocsIfff.h"
#include "DoocsUpdater.h"
#include <ChimeraTK/OneDRegisterAccessor.h>
namespace ChimeraTK {
DoocsIfff::DoocsIfff(EqFct* eqFct, std::string const& doocsPropertyName,
boost::shared_ptr<NDRegisterAccessor<int>> const& i1Value,
boost::shared_ptr<NDRegisterAccessor<float>> const& f1Value,
boost::shared_ptr<NDRegisterAccessor<float>> const& f2Value,
boost::shared_ptr<NDRegisterAccessor<float>> const& f3Value, DoocsUpdater& updater)
: D_ifff(eqFct, doocsPropertyName), _i1Value(i1Value), _f1Value(f1Value), _f2Value(f2Value), _f3Value(f3Value) {
auto registerSource = [&](const ChimeraTK::TransferElementAbstractor& var) {
if(var.isReadable()) {
updater.addVariable(var, eqFct, std::bind(&DoocsIfff::updateValues, this, var.getId()));
_consistencyGroup.add(var);
}
};
registerSource(OneDRegisterAccessor<int>(_i1Value));
registerSource(OneDRegisterAccessor<float>(_f1Value));
registerSource(OneDRegisterAccessor<float>(_f2Value));
registerSource(OneDRegisterAccessor<float>(_f3Value));
}
void DoocsIfff::updateValues(TransferElementID& elementId) {
if(_consistencyGroup.update(elementId)) {
if(_i1Value->dataValidity() != ChimeraTK::DataValidity::ok ||
_f1Value->dataValidity() != ChimeraTK::DataValidity::ok ||
_f2Value->dataValidity() != ChimeraTK::DataValidity::ok ||
_f3Value->dataValidity() != ChimeraTK::DataValidity::ok) {
this->d_error(stale_data);
}
else {
this->d_error(no_error);
}
IFFF ifff;
ifff.i1_data = _i1Value->accessData(0);
ifff.f1_data = _f1Value->accessData(0);
ifff.f2_data = _f2Value->accessData(0);
ifff.f3_data = _f3Value->accessData(0);
// we must not call set_and_archive if there is no history (otherwise it
// will be activated), but we have to if it is there. -> Abstraction,
// please!
if(this->get_histPointer()) {
// Set eventId
//doocs::EventId eventId;
//if(_macroPulseNumberSource) eventId = doocs::EventId(_macroPulseNumberSource->accessData(0));
/*FIXME: The archiver also has a status code. Set it correctly.*/
/*FIXME: This set_and_archive does not support the timestamp yet (only sec and msec, and I guess m is milli?)*/
/*FIXME: This set_and_archive does not support eventIDs yet */
this->set_and_archive(&ifff, ArchiveStatus::sts_ok, 0 /*sec*/, 0 /*msec*/);
}
else {
this->set_value(&ifff);
}
}
}
} // namespace ChimeraTK
......@@ -4,6 +4,7 @@
#include "DoocsProcessScalar.h"
#include "DoocsSpectrum.h"
#include "DoocsXY.h"
#include "DoocsIfff.h"
#include "D_textUnifier.h"
#include <d_fct.h>
......@@ -257,6 +258,22 @@ namespace ChimeraTK {
return doocsPV;
}
boost::shared_ptr<D_fct> DoocsPVFactory::createIfff(IfffDescription const& ifffDescription) {
auto i1ProcessVariable = _controlSystemPVManager->getProcessVariable(ifffDescription.i1Source);
auto f1ProcessVariable = _controlSystemPVManager->getProcessVariable(ifffDescription.f1Source);
auto f2ProcessVariable = _controlSystemPVManager->getProcessVariable(ifffDescription.f2Source);
auto f3ProcessVariable = _controlSystemPVManager->getProcessVariable(ifffDescription.f3Source);
boost::shared_ptr<D_fct> doocsPV;
doocsPV.reset(new DoocsIfff(_eqFct, ifffDescription.name,
getDecorator<int>(i1ProcessVariable, DecoratorType::C_style_conversion),
getDecorator<float>(f1ProcessVariable, DecoratorType::C_style_conversion),
getDecorator<float>(f2ProcessVariable, DecoratorType::C_style_conversion),
getDecorator<float>(f3ProcessVariable, DecoratorType::C_style_conversion), _updater));
return doocsPV;
}
static std::map<std::type_index, std::function<unsigned int(ProcessVariable&)>> castingMap{
{typeid(uint8_t),
[](auto& pv) { return dynamic_cast<ChimeraTK::NDRegisterAccessor<uint8_t>&>(pv).getNumberOfSamples(); }},
......@@ -487,6 +504,9 @@ boost::shared_ptr<D_fct> DoocsPVFactory::create(std::shared_ptr<PropertyDescript
else if(requestedType == typeid(XyDescription)) {
return createXy(*std::static_pointer_cast<XyDescription>(propertyDescription));
}
else if(requestedType == typeid(IfffDescription)) {
return createIfff(*std::static_pointer_cast<IfffDescription>(propertyDescription));
}
else if(requestedType == typeid(AutoPropertyDescription)) {
return createDoocsArray(std::static_pointer_cast<AutoPropertyDescription>(propertyDescription));
}
......
......@@ -87,9 +87,13 @@ BOOST_AUTO_TEST_CASE(testIfffUpdate) {
return value;
};
sleep(2); //outch
auto value = extractValue();
// FIXME put correct vales what to expect
BOOST_CHECK_CLOSE(value.f1_data, 123., 0.0001);
BOOST_CHECK_EQUAL(value.i1_data, 0.);
BOOST_CHECK_CLOSE(value.f1_data, 0., 0.0001);
BOOST_CHECK_CLOSE(value.f2_data, 0., 0.0001);
BOOST_CHECK_CLOSE(value.f3_data, 0., 0.0001);
}
/**********************************************************************************************************************/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment