/*----- PROTECTED REGION ID(E2Sextupole.cpp) ENABLED START -----*/ /* clang-format on */ //============================================================================= // // file : E2Sextupole.cpp // // description : C++ source for the E2Sextupole class and its commands. // The class is derived from Device. It represents the // CORBA servant object which will be accessed from the // network. All commands which can be executed on the // E2Sextupole are implemented in this file. // // project : Elettra 2.0 pure sextupole magnet device // // This file is part of Tango device class. // // Tango is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Tango is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Tango. If not, see <http://www.gnu.org/licenses/>. // // // Elettra - Sincrotrone Trieste S.c.p.A. // //============================================================================= // This file is generated by POGO // (Program Obviously used to Generate tango Object) //============================================================================= #include "E2Sextupole.h" #include "E2SextupoleClass.h" /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole.cpp /** * E2Sextupole class description: * Elettra 2.0 sextupole magnet device * Use calibration table handle current/strgenght converstions. * The magnet device is connected to a power supply tango device , real or simulated. * * Based on ESRF EBSmagnet concepts and libraries. */ //================================================================ // The following table gives the correspondence // between command and method names. // // Command name | Method name //================================================================ // State | Inherited (no method) // Status | Inherited (no method) // Reset | reset // ResetResonanceStrength | reset_resonance_strength // ApplyDesignStrength | apply_design_strength //================================================================ //================================================================ // Attributes managed are: //================================================================ // Strength | Tango::DevDouble Scalar // CorrectionStrength | Tango::DevDouble Scalar // ResonanceStrength | Tango::DevDouble Scalar // Current | Tango::DevDouble Scalar // BeamEnergy | Tango::DevDouble Scalar // DesignStrength | Tango::DevDouble Scalar // bbaEnable | Tango::DevBoolean Scalar // CEHStrength | Tango::DevDouble Scalar // CEHCorrectionStrength | Tango::DevDouble Scalar // CEHResonanceStrength | Tango::DevDouble Scalar // CEVStrength | Tango::DevDouble Scalar // CEVCorrectionStrength | Tango::DevDouble Scalar // CEVResonanceStrength | Tango::DevDouble Scalar // SQStrength | Tango::DevDouble Scalar // SQCorrectionStrength | Tango::DevDouble Scalar // SQResonanceStrength | Tango::DevDouble Scalar // CEHCurrent | Tango::DevDouble Scalar // CEVCurrent | Tango::DevDouble Scalar // PolynomA | Tango::DevDouble Spectrum ( max = 3) // PolynomB | Tango::DevDouble Spectrum ( max = 3) //================================================================ namespace E2Sextupole_ns { /*----- PROTECTED REGION ID(E2Sextupole::namespace_starting) ENABLED START -----*/ /* clang-format on */ // static initializations /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::namespace_starting //-------------------------------------------------------- /** * Method : E2Sextupole::E2Sextupole() * Description: Constructors for a Tango device * implementing the classE2Sextupole */ //-------------------------------------------------------- E2Sextupole::E2Sextupole(Tango::DeviceClass *cl, std::string &s) : TANGO_BASE_CLASS(cl, s.c_str()) { /*----- PROTECTED REGION ID(E2Sextupole::constructor_1) ENABLED START -----*/ /* clang-format on */ init_device(); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::constructor_1 } //-------------------------------------------------------- E2Sextupole::E2Sextupole(Tango::DeviceClass *cl, const char *s) : TANGO_BASE_CLASS(cl, s) { /*----- PROTECTED REGION ID(E2Sextupole::constructor_2) ENABLED START -----*/ /* clang-format on */ init_device(); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::constructor_2 } //-------------------------------------------------------- E2Sextupole::E2Sextupole(Tango::DeviceClass *cl, const char *s, const char *d) : TANGO_BASE_CLASS(cl, s, d) { /*----- PROTECTED REGION ID(E2Sextupole::constructor_3) ENABLED START -----*/ /* clang-format on */ init_device(); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::constructor_3 } //-------------------------------------------------------- E2Sextupole::~E2Sextupole() { delete_device(); } //-------------------------------------------------------- /** * Method : E2Sextupole::delete_device() * Description: will be called at device destruction or at init command */ //-------------------------------------------------------- void E2Sextupole::delete_device() { DEBUG_STREAM << "E2Sextupole::delete_device() " << device_name << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::delete_device) ENABLED START -----*/ /* clang-format on */ // Delete device allocated objects // cev current and cv model if (cev_state_event_id) cev_current_dev->unsubscribe_event(cev_state_event_id); if (cev_current_set_event_id) cev_current_dev->unsubscribe_event(cev_current_set_event_id); if (cev_current_event_id) cev_current_dev->unsubscribe_event(cev_current_event_id); if (cev_current_cb) delete cev_current_cb; if (cev_current_dev) delete cev_current_dev; if (cev) delete cev; // ceh/v current and ceh/v model and skew quad model if (ceh_state_event_id) ceh_current_dev->unsubscribe_event(ceh_state_event_id); if (ceh_current_set_event_id) ceh_current_dev->unsubscribe_event(ceh_current_set_event_id); if (ceh_current_event_id) ceh_current_dev->unsubscribe_event(ceh_current_event_id); if (ceh_current_cb) delete ceh_current_cb; if (ceh_current_dev) delete ceh_current_dev; if (ceh) delete ceh; if(skewquadrupole) delete skewquadrupole; if (bba_switch_dev) delete bba_switch_dev; // main current and sextupole model if (main_state_event_id) main_current_dev->unsubscribe_event(main_state_event_id); if (main_current_set_event_id) main_current_dev->unsubscribe_event(main_current_set_event_id); if (main_current_event_id) main_current_dev->unsubscribe_event(main_current_event_id); if (main_current_cb) delete main_current_cb; if (main_current_dev) delete main_current_dev; if (sextupole) delete sextupole; if(ceh) delete ceh; if(cev) delete cev; if(skewquadrupole) delete skewquadrupole; /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::delete_device delete[] attr_Strength_read; delete[] attr_CorrectionStrength_read; delete[] attr_ResonanceStrength_read; delete[] attr_Current_read; delete[] attr_BeamEnergy_read; delete[] attr_DesignStrength_read; delete[] attr_bbaEnable_read; delete[] attr_CEHStrength_read; delete[] attr_CEHCorrectionStrength_read; delete[] attr_CEHResonanceStrength_read; delete[] attr_CEVStrength_read; delete[] attr_CEVCorrectionStrength_read; delete[] attr_CEVResonanceStrength_read; delete[] attr_SQStrength_read; delete[] attr_SQCorrectionStrength_read; delete[] attr_SQResonanceStrength_read; delete[] attr_CEHCurrent_read; delete[] attr_CEVCurrent_read; delete[] attr_PolynomA_read; delete[] attr_PolynomB_read; } //-------------------------------------------------------- /** * Method : E2Sextupole::init_device() * Description: will be called at device initialization. */ //-------------------------------------------------------- void E2Sextupole::init_device() { DEBUG_STREAM << "E2Sextupole::init_device() create device " << device_name << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::init_device_before) ENABLED START -----*/ /* clang-format on */ // Initialization before get_device_property() call /* clang-format off */ set_state(Tango::UNKNOWN); set_status("Init"); design_strength_initialized = false; pure_sext = false; ceh_cev = false; bba_ready = false; sext_with_skew = false; /*----- PROTECTED REGION END -----*/ // E2Sextupole::init_device_before // Get the device properties from database get_device_property(); attr_Strength_read = new Tango::DevDouble[1]; attr_CorrectionStrength_read = new Tango::DevDouble[1]; attr_ResonanceStrength_read = new Tango::DevDouble[1]; attr_Current_read = new Tango::DevDouble[1]; attr_BeamEnergy_read = new Tango::DevDouble[1]; attr_DesignStrength_read = new Tango::DevDouble[1]; attr_bbaEnable_read = new Tango::DevBoolean[1]; attr_CEHStrength_read = new Tango::DevDouble[1]; attr_CEHCorrectionStrength_read = new Tango::DevDouble[1]; attr_CEHResonanceStrength_read = new Tango::DevDouble[1]; attr_CEVStrength_read = new Tango::DevDouble[1]; attr_CEVCorrectionStrength_read = new Tango::DevDouble[1]; attr_CEVResonanceStrength_read = new Tango::DevDouble[1]; attr_SQStrength_read = new Tango::DevDouble[1]; attr_SQCorrectionStrength_read = new Tango::DevDouble[1]; attr_SQResonanceStrength_read = new Tango::DevDouble[1]; attr_CEHCurrent_read = new Tango::DevDouble[1]; attr_CEVCurrent_read = new Tango::DevDouble[1]; attr_PolynomA_read = new Tango::DevDouble[3]; attr_PolynomB_read = new Tango::DevDouble[3]; // No longer if mandatory property not set. if (mandatoryNotDefined) return; /*----- PROTECTED REGION ID(E2Sextupole::init_device) ENABLED START -----*/ /* clang-format on */ // Initialize device /* clang-format off */ //examine EmbbeddedConfiguration and set the configration flags if (embeddedConfiguration == "pure_sext") pure_sext = true; if (embeddedConfiguration == "ceh_cev") ceh_cev = true; if (embeddedConfiguration == "bba_ready") bba_ready = true; if (embeddedConfiguration == "sext_with_skew") sext_with_skew = true; if (!(pure_sext || ceh_cev || bba_ready || sext_with_skew)) { set_state(Tango::UNKNOWN); set_status("wrong EmebddedConfiguration property"); ERROR_STREAM << "wrong EmbeddedConfiguration property: " << embeddedConfiguration << " [ pure_sext | ceh_cev | bba_ready | sect_with_skew ]"; return; //init failed! } bba_switch_dev = nullptr; main_current_dev = nullptr; main_current_cb = nullptr; main_current_event_id = 0; main_current_set_event_id = 0; main_state_event_id = 0; main_set_current.resize(1, 0.0); main_set_strength.resize(1,0.0); main_current_state = Tango::OFF; //safe guess ceh_current_dev = nullptr; ceh_current_cb = nullptr; ceh_current_event_id = 0; ceh_current_set_event_id = 0; ceh_state_event_id = 0; ceh_set_current.resize(1, 0.0); ceh_set_strength.resize(1,0.0); ceh_current_state = Tango::OFF; //safe guess ceh_design_strength = 0.0; //safe guess cev_current_dev = nullptr; cev_current_cb = nullptr; cev_current_event_id = 0; cev_current_set_event_id = 0; cev_state_event_id = 0; cev_set_current.resize(1, 0.0); cev_set_strength.resize(1,0.0); cev_current_state = Tango::OFF; //safe guess cev_design_strength = 0.0; // creat proxy for main sextupole coil power supply try{ main_current_dev = new Tango::DeviceProxy(currentDevice); } catch (Tango::DevFailed &ex){ ERROR_STREAM << "failed to create Tango device proxy for main current device: " << currentDevice; set_state(Tango::UNKNOWN); std::string st = get_status(); st += "\nfailed to create Tango device proxy for CurrentDevice"; set_status(st); return; } //create MagnetModel::Sextupole - handles calibration tables and interpolations // we do not use the EBS scheme with global properties... yet //TODO: fix/determine format and handling of Elettra 2.0 calibrations sextupole = nullptr; try { std::string meas_strength_file_name = calibrationPath + "/" + calibrationFileName; std::string param_file_name = calibrationPath + "/" + parameterFileName; sextupole = new MagnetModel::PureSextupole(); sextupole->init(true,1.0, meas_strength_file_name, param_file_name, magnetName); } catch (std::exception &e) { std::cerr << "fatalerror "<< e.what() << std::endl; ERROR_STREAM << "failed to create sextupole model " << currentDevice; set_state(Tango::UNKNOWN); set_status("failed to create sextupole model CurrentDevice"); return; } //create MagnetModel::Corrector - handles calibration tables and interpolations // we do not use the EBS scheme with global properties... yet //TODO: fix/determine format and handling of Elettra 2.0 calibrations ceh = nullptr; try { std::string meas_strength_file_name = calibrationPath + "/" + cEHCalibrationFileName; std::string param_file_name = calibrationPath + "/" + parameterFileName; ceh = new MagnetModel::Corrector(); ceh->init(true,1.0, meas_strength_file_name, param_file_name, cEHName); } catch (std::exception &e) { std::cerr << "fatalerror "<< e.what() << std::endl; ERROR_STREAM << "failed to create CEH corrector model " << currentDevice; set_state(Tango::UNKNOWN); set_status("failed to create CEH corrector model CurrentDevice"); return; } cev = nullptr; try { std::string meas_strength_file_name = calibrationPath + "/" + cEVCalibrationFileName; std::string param_file_name = calibrationPath + "/" + parameterFileName; cev = new MagnetModel::Corrector(); cev->init(true,1.0, meas_strength_file_name, param_file_name, cEVName); } catch (std::exception &e) { std::cerr << "fatalerror "<< e.what() << std::endl; ERROR_STREAM << "failed to create CEV corrector model " << currentDevice; set_state(Tango::UNKNOWN); set_status("failed to create CEV corrector model CurrentDevice"); return; } //create MagnetModel::Quadrupole - handles calibration tables and interpolations // we do not use the EBS scheme with global properties... yet //TODO: fix/determine format and handling of Elettra 2.0 calibrations // check also for congruent configuration of properties skewquadrupole = nullptr; try { std::string meas_strength_file_name = calibrationPath + "/" + sQCalibrationFileName; std::string param_file_name = calibrationPath + "/" + parameterFileName; skewquadrupole = new MagnetModel::Quadrupole(); skewquadrupole->init(true,1.0, meas_strength_file_name, param_file_name, magnetName); } catch (std::exception &e) { std::cerr << "fatalerror "<< e.what() << std::endl; ERROR_STREAM << "failed to create embedded skew quadrupole model " << sQCalibrationFileName; set_state(Tango::UNKNOWN); set_status("failed to create sembedded skew quadrupole model"); return; } if (!pure_sext){ //pure sextupole are not connected to psceh and pscev! try{ ceh_current_dev = new Tango::DeviceProxy(psCehDeviceName); } catch (Tango::DevFailed &ex){ ERROR_STREAM << "failed to create Tango device proxy for CEH device: " << psCehDeviceName; set_state(Tango::UNKNOWN); std::string st = get_status(); st += "\nfailed to create Tango device proxy for psCehDeviceName"; set_status(st); return; } try{ cev_current_dev = new Tango::DeviceProxy(psCevDeviceName); } catch (Tango::DevFailed &ex){ ERROR_STREAM << "failed to create Tango device proxy for CEV device: " << psCevDeviceName; set_state(Tango::UNKNOWN); std::string st = get_status(); st += "\nfailed to create Tango device proxy for psCevDeviceName"; set_status(st); return; } } if(bba_ready){ try{ bba_switch_dev = new Tango::DeviceProxy(bbaSwitchDeviceName); } catch (Tango::DevFailed &ex){ ERROR_STREAM << "failed to create Tango device proxy for main BBA switch device: " << bbaSwitchDeviceName; set_state(Tango::UNKNOWN); std::string st = get_status(); st += "\nfailed to create Tango device proxy for bbaSwitchDeviceName"; set_status(st); return; } } // init energy *attr_BeamEnergy_read = default_beam_energy; Tango::WAttribute &cat = get_device_attr()->get_w_attr_by_name("BeamEnergy"); cat.set_write_value(default_beam_energy); calc_rigidity(default_beam_energy); //get WAtrirbute for handling cross dependencies mainStrengthAtt = &get_device_attr()->get_w_attr_by_name("Strength"); mainCorrectionAtt = &get_device_attr()->get_w_attr_by_name("CorrectionStrength"); mainResonanceAtt = &get_device_attr()->get_w_attr_by_name("ResonanceStrength"); mainCursetAtt = &(get_device_attr()->get_w_attr_by_name("Current")); cehStrengthAtt = &get_device_attr()->get_w_attr_by_name("CehStrength"); cehCorrectionAtt = &get_device_attr()->get_w_attr_by_name("CehCorrectionStrength"); cehResonanceAtt = &get_device_attr()->get_w_attr_by_name("CehResonanceStrength"); cehCursetAtt = &(get_device_attr()->get_w_attr_by_name("CeHCurrent")); cevStrengthAtt = &get_device_attr()->get_w_attr_by_name("CevStrength"); cevCorrectionAtt = &get_device_attr()->get_w_attr_by_name("CevCorrectionStrength"); cevResonanceAtt = &get_device_attr()->get_w_attr_by_name("CevResonanceStrength"); cevCursetAtt = &(get_device_attr()->get_w_attr_by_name("CeVCurrent")); // force state to OFF, it will be update by the power supplies set_state(Tango::OFF); set_status("init device ok"); /*----- PROTECTED REGION END -----*/ // E2Sextupole::init_device } //-------------------------------------------------------- /** * Method : E2Sextupole::get_device_property() * Description: Read database to initialize property data members. */ //-------------------------------------------------------- void E2Sextupole::get_device_property() { /*----- PROTECTED REGION ID(E2Sextupole::get_device_property_before) ENABLED START -----*/ /* clang-format on */ // Initialize property data members /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::get_device_property_before mandatoryNotDefined = false; // Read device properties from database. Tango::DbData dev_prop; dev_prop.push_back(Tango::DbDatum("BbaSwitchAttribute")); dev_prop.push_back(Tango::DbDatum("BbaSwitchDeviceName")); dev_prop.push_back(Tango::DbDatum("CEHCalibrationFileName")); dev_prop.push_back(Tango::DbDatum("CEHDeviceName")); dev_prop.push_back(Tango::DbDatum("CEHName")); dev_prop.push_back(Tango::DbDatum("CEVCalibrationFileName")); dev_prop.push_back(Tango::DbDatum("CEVDeviceName")); dev_prop.push_back(Tango::DbDatum("CEVName")); dev_prop.push_back(Tango::DbDatum("CalibrationFileName")); dev_prop.push_back(Tango::DbDatum("CalibrationPath")); dev_prop.push_back(Tango::DbDatum("CurrentDevice")); dev_prop.push_back(Tango::DbDatum("EmbeddedConfiguration")); dev_prop.push_back(Tango::DbDatum("MagnetName")); dev_prop.push_back(Tango::DbDatum("Model")); dev_prop.push_back(Tango::DbDatum("ParameterFileName")); dev_prop.push_back(Tango::DbDatum("PsCehDeviceName")); dev_prop.push_back(Tango::DbDatum("PsCevDeviceName")); dev_prop.push_back(Tango::DbDatum("SQCalibrationFileName")); dev_prop.push_back(Tango::DbDatum("SerialNumber")); dev_prop.push_back(Tango::DbDatum("SkewQuad")); // is there at least one property to be read ? if (dev_prop.size()>0) { // Call database and extract values if (Tango::Util::instance()->_UseDb==true) get_db_device()->get_property(dev_prop); // get instance on E2SextupoleClass to get class property Tango::DbDatum def_prop, cl_prop; E2SextupoleClass *ds_class = (static_cast<E2SextupoleClass *>(get_device_class())); int i = -1; // Try to initialize BbaSwitchAttribute from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> bbaSwitchAttribute; else { // Try to initialize BbaSwitchAttribute from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> bbaSwitchAttribute; } // And try to extract BbaSwitchAttribute value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> bbaSwitchAttribute; // Try to initialize BbaSwitchDeviceName from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> bbaSwitchDeviceName; else { // Try to initialize BbaSwitchDeviceName from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> bbaSwitchDeviceName; } // And try to extract BbaSwitchDeviceName value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> bbaSwitchDeviceName; // Try to initialize CEHCalibrationFileName from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> cEHCalibrationFileName; else { // Try to initialize CEHCalibrationFileName from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> cEHCalibrationFileName; } // And try to extract CEHCalibrationFileName value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> cEHCalibrationFileName; // Property StartDsPath is mandatory, check if has been defined in database. check_mandatory_property(cl_prop, dev_prop[i]); // Try to initialize CEHDeviceName from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> cEHDeviceName; else { // Try to initialize CEHDeviceName from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> cEHDeviceName; } // And try to extract CEHDeviceName value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> cEHDeviceName; // Try to initialize CEHName from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> cEHName; else { // Try to initialize CEHName from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> cEHName; } // And try to extract CEHName value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> cEHName; // Try to initialize CEVCalibrationFileName from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> cEVCalibrationFileName; else { // Try to initialize CEVCalibrationFileName from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> cEVCalibrationFileName; } // And try to extract CEVCalibrationFileName value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> cEVCalibrationFileName; // Property StartDsPath is mandatory, check if has been defined in database. check_mandatory_property(cl_prop, dev_prop[i]); // Try to initialize CEVDeviceName from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> cEVDeviceName; else { // Try to initialize CEVDeviceName from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> cEVDeviceName; } // And try to extract CEVDeviceName value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> cEVDeviceName; // Try to initialize CEVName from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> cEVName; else { // Try to initialize CEVName from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> cEVName; } // And try to extract CEVName value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> cEVName; // Try to initialize CalibrationFileName from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> calibrationFileName; else { // Try to initialize CalibrationFileName from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> calibrationFileName; } // And try to extract CalibrationFileName value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> calibrationFileName; // Property StartDsPath is mandatory, check if has been defined in database. check_mandatory_property(cl_prop, dev_prop[i]); // Try to initialize CalibrationPath from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> calibrationPath; else { // Try to initialize CalibrationPath from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> calibrationPath; } // And try to extract CalibrationPath value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> calibrationPath; // Try to initialize CurrentDevice from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> currentDevice; else { // Try to initialize CurrentDevice from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> currentDevice; } // And try to extract CurrentDevice value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> currentDevice; // Try to initialize EmbeddedConfiguration from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> embeddedConfiguration; else { // Try to initialize EmbeddedConfiguration from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> embeddedConfiguration; } // And try to extract EmbeddedConfiguration value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> embeddedConfiguration; // Property StartDsPath is mandatory, check if has been defined in database. check_mandatory_property(cl_prop, dev_prop[i]); // Try to initialize MagnetName from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> magnetName; else { // Try to initialize MagnetName from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> magnetName; } // And try to extract MagnetName value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> magnetName; // Try to initialize Model from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> model; else { // Try to initialize Model from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> model; } // And try to extract Model value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> model; // Try to initialize ParameterFileName from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> parameterFileName; else { // Try to initialize ParameterFileName from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> parameterFileName; } // And try to extract ParameterFileName value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> parameterFileName; // Property StartDsPath is mandatory, check if has been defined in database. check_mandatory_property(cl_prop, dev_prop[i]); // Try to initialize PsCehDeviceName from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> psCehDeviceName; else { // Try to initialize PsCehDeviceName from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> psCehDeviceName; } // And try to extract PsCehDeviceName value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> psCehDeviceName; // Try to initialize PsCevDeviceName from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> psCevDeviceName; else { // Try to initialize PsCevDeviceName from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> psCevDeviceName; } // And try to extract PsCevDeviceName value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> psCevDeviceName; // Try to initialize SQCalibrationFileName from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> sQCalibrationFileName; else { // Try to initialize SQCalibrationFileName from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> sQCalibrationFileName; } // And try to extract SQCalibrationFileName value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> sQCalibrationFileName; // Property StartDsPath is mandatory, check if has been defined in database. check_mandatory_property(cl_prop, dev_prop[i]); // Try to initialize SerialNumber from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> serialNumber; else { // Try to initialize SerialNumber from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> serialNumber; } // And try to extract SerialNumber value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> serialNumber; // Try to initialize SkewQuad from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); if (cl_prop.is_empty()==false) cl_prop >> skewQuad; else { // Try to initialize SkewQuad from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); if (def_prop.is_empty()==false) def_prop >> skewQuad; } // And try to extract SkewQuad value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> skewQuad; } /*----- PROTECTED REGION ID(E2Sextupole::get_device_property_after) ENABLED START -----*/ /* clang-format on */ // Check device property data members init /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::get_device_property_after } //-------------------------------------------------------- /** * Method : E2Sextupole::check_mandatory_property() * Description: For mandatory properties check if defined in database. */ //-------------------------------------------------------- void E2Sextupole::check_mandatory_property(Tango::DbDatum &class_prop, Tango::DbDatum &dev_prop) { // Check if all properties are empty if (class_prop.is_empty() && dev_prop.is_empty()) { TangoSys_OMemStream tms; tms << std::endl <<"Property \'" << dev_prop.name; if (Tango::Util::instance()->_UseDb==true) tms << "\' is mandatory but not defined in database"; else tms << "\' is mandatory but cannot be defined without database"; append_status(tms.str()); mandatoryNotDefined = true; /*----- PROTECTED REGION ID(E2Sextupole::check_mandatory_property) ENABLED START -----*/ /* clang-format on */ std::cerr << tms.str() << " for " << device_name << std::endl; /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::check_mandatory_property } } //-------------------------------------------------------- /** * Method : E2Sextupole::always_executed_hook() * Description: method always executed before any command is executed */ //-------------------------------------------------------- void E2Sextupole::always_executed_hook() { DEBUG_STREAM << "E2Sextupole::always_executed_hook() " << device_name << std::endl; if (mandatoryNotDefined) { Tango::Except::throw_exception( (const char *)"PROPERTY_NOT_SET", get_status().c_str(), (const char *)"E2Sextupole::always_executed_hook()"); } /*----- PROTECTED REGION ID(E2Sextupole::always_executed_hook) ENABLED START -----*/ /* clang-format on */ // code always executed before all requests /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::always_executed_hook } //-------------------------------------------------------- /** * Method : E2Sextupole::read_attr_hardware() * Description: Hardware acquisition for attributes */ //-------------------------------------------------------- void E2Sextupole::read_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_list)) { DEBUG_STREAM << "E2Sextupole::read_attr_hardware(std::vector<long> &attr_list) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_attr_hardware) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_attr_hardware } //-------------------------------------------------------- /** * Method : E2Sextupole::write_attr_hardware() * Description: Hardware writing for attributes */ //-------------------------------------------------------- void E2Sextupole::write_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_list)) { DEBUG_STREAM << "E2Sextupole::write_attr_hardware(std::vector<long> &attr_list) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::write_attr_hardware) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_attr_hardware } //-------------------------------------------------------- /** * Read attribute Strength related method * Description: sextupole strength 1/m^3 ( m-3) * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_Strength(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_Strength(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_Strength) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_Strength_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_Strength } //-------------------------------------------------------- /** * Write attribute Strength related method * Description: sextupole strength 1/m^3 ( m-3) * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_Strength(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_Strength(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_Strength) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ omni_mutex_lock guardio(iomutex); std::vector<double> req_strength; std::vector<double> curr_out; req_strength.push_back(w_val); sextupole->compute_currents(magnet_rigidity, req_strength, curr_out); Tango::DeviceAttribute watt("Current",curr_out[0]); main_current_dev->write_attribute(watt); main_set_strength[0] = w_val; wValMainCorrStrength = w_val - wValMainResStrength; mainCorrectionAtt->set_write_value(wValMainCorrStrength); //catch(std::excpetion &ex){} /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_Strength } //-------------------------------------------------------- /** * Read attribute CorrectionStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_CorrectionStrength(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_CorrectionStrength(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_CorrectionStrength) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_CorrectionStrength_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_CorrectionStrength } //-------------------------------------------------------- /** * Write attribute CorrectionStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_CorrectionStrength(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_CorrectionStrength(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_CorrectionStrength) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ /* TODO : implement is_set_point valid and exploit it! if(!is_setpoint_valid(w_val)) { attr.rollback(); return; } */ omni_mutex_lock guardio(iomutex); Tango::DevDouble newStrength; //mainResonanceAtt->get_write_value(_resStrength); newStrength = w_val + wValMainResStrength + *attr_DesignStrength_read; std::vector<double> req_strength; std::vector<double> curr_out; req_strength.push_back(newStrength); sextupole->compute_currents(magnet_rigidity, req_strength, curr_out); Tango::DeviceAttribute watt("Current", curr_out[0]); main_current_dev->write_attribute(watt); wValMainCorrStrength = w_val; main_set_strength[0] = newStrength; mainStrengthAtt->set_write_value(main_set_strength[0]); /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_CorrectionStrength } //-------------------------------------------------------- /** * Read attribute ResonanceStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_ResonanceStrength(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_ResonanceStrength(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_ResonanceStrength) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_ResonanceStrength_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_ResonanceStrength } //-------------------------------------------------------- /** * Write attribute ResonanceStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_ResonanceStrength(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_ResonanceStrength(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_ResonanceStrength) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ /* TODO : implement is_set_point valid and exploit it! if(!is_setpoint_valid(w_val)) { attr.rollback(); return; } */ omni_mutex_lock guardio(iomutex); Tango::DevDouble newStrength; newStrength = w_val + wValMainCorrStrength + *attr_DesignStrength_read; std::vector<double> req_strength; std::vector<double> curr_out; req_strength.push_back(newStrength); sextupole->compute_currents(magnet_rigidity, req_strength, curr_out); Tango::DeviceAttribute watt("Current", curr_out[0]); main_current_dev->write_attribute(watt); wValMainResStrength = w_val; *attr_ResonanceStrength_read = w_val; main_set_strength[0] = newStrength; mainStrengthAtt->set_write_value(main_set_strength[0]); /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_ResonanceStrength } //-------------------------------------------------------- /** * Read attribute Current related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_Current(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_Current(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_Current) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_Current_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_Current } //-------------------------------------------------------- /** * Write attribute Current related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_Current(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_Current(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_Current) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ Tango::DeviceAttribute watt("Current",w_val); main_current_dev->write_attribute(watt); /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_Current } //-------------------------------------------------------- /** * Read attribute BeamEnergy related method * Description: Electron beam energy in eV. Used to calculate magnetic rigidity in strength calculations. * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_BeamEnergy(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_BeamEnergy(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_BeamEnergy) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_BeamEnergy_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_BeamEnergy } //-------------------------------------------------------- /** * Write attribute BeamEnergy related method * Description: Electron beam energy in eV. Used to calculate magnetic rigidity in strength calculations. * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_BeamEnergy(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_BeamEnergy(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_BeamEnergy) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ *attr_BeamEnergy_read = w_val; calc_rigidity(w_val); /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_BeamEnergy } //-------------------------------------------------------- /** * Read attribute DesignStrength related method * Description: sextupole design strength 1/m^3 ( m-3). The strenght reqiured by the nominal optic * The attribute is memorized , expert only. * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_DesignStrength(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_DesignStrength(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_DesignStrength) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_DesignStrength_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_DesignStrength } //-------------------------------------------------------- /** * Write attribute DesignStrength related method * Description: sextupole design strength 1/m^3 ( m-3). The strenght reqiured by the nominal optic * The attribute is memorized , expert only. * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_DesignStrength(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_DesignStrength(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_DesignStrength) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ *attr_DesignStrength_read = w_val; if (design_strength_initialized == false){ // only with a value of DesignStrength init process can be completed design_strength_initialized = true; init_strengths(); subscribe_events(); } else init_strengths(); /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_DesignStrength } //-------------------------------------------------------- /** * Read attribute bbaEnable related method * Description: Read / and set the rele that modfy the sestupole cabling. If true the skew quadrupole QS is enabled, If fals the embedded horizontal corrector CEH is enabled. * If the magnet is permanetly cabled with the embedded skew quadrupole, the aiitrbute is always true nd is not writable. * * Data type: Tango::DevBoolean * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_bbaEnable(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_bbaEnable(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_bbaEnable) ENABLED START -----*/ /* clang-format on */ // Set the attribute value if (bba_switch_dev){ Tango::DeviceAttribute da; da=bba_switch_dev->read_attribute(bbaSwitchAttribute); da >> *attr_bbaEnable_read; } attr.set_value(attr_bbaEnable_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_bbaEnable } //-------------------------------------------------------- /** * Write attribute bbaEnable related method * Description: Read / and set the rele that modfy the sestupole cabling. If true the skew quadrupole QS is enabled, If fals the embedded horizontal corrector CEH is enabled. * If the magnet is permanetly cabled with the embedded skew quadrupole, the aiitrbute is always true nd is not writable. * * Data type: Tango::DevBoolean * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_bbaEnable(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_bbaEnable(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevBoolean w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_bbaEnable) ENABLED START -----*/ /* clang-format on */ if (bba_switch_dev){ Tango::DeviceAttribute watt(bbaSwitchAttribute,w_val); bba_switch_dev->write_attribute(watt); } // Add your own code /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_bbaEnable } //-------------------------------------------------------- /** * Read attribute CEHStrength related method * Description: embbeded corrector horizontal kick * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_CEHStrength(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_CEHStrength(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_CEHStrength) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_CEHStrength_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_CEHStrength } //-------------------------------------------------------- /** * Write attribute CEHStrength related method * Description: embbeded corrector horizontal kick * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_CEHStrength(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_CEHStrength(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_CEHStrength) ENABLED START -----*/ /* clang-format on */ // Add your own code omni_mutex_lock guardio(iomutex); std::vector<double> req_strength; std::vector<double> curr_out; req_strength.push_back(w_val); ceh->compute_currents(magnet_rigidity, req_strength, curr_out); Tango::DeviceAttribute watt("Current",curr_out[0]); ceh_current_dev->write_attribute(watt); ceh_set_strength[0] = w_val; wValCehCorrStrength = w_val - wValCehResStrength; /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_CEHStrength } //-------------------------------------------------------- /** * Read attribute CEHCorrectionStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_CEHCorrectionStrength(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_CEHCorrectionStrength(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_CEHCorrectionStrength) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_CEHCorrectionStrength_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_CEHCorrectionStrength } //-------------------------------------------------------- /** * Write attribute CEHCorrectionStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_CEHCorrectionStrength(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_CEHCorrectionStrength(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_CEHCorrectionStrength) ENABLED START -----*/ /* clang-format on */ // Add your own code omni_mutex_lock guardio(iomutex); Tango::DevDouble newStrength; //resonanceAtt->get_write_value(_resStrength); newStrength = w_val + wValCehResStrength + ceh_design_strength; std::vector<double> req_strength; std::vector<double> curr_out; req_strength.push_back(newStrength); ceh->compute_currents(magnet_rigidity, req_strength, curr_out); Tango::DeviceAttribute watt("Current", curr_out[0]); ceh_current_dev->write_attribute(watt); wValCehCorrStrength = w_val; ceh_set_strength[0] = newStrength; cehStrengthAtt->set_write_value(ceh_set_strength[0]); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_CEHCorrectionStrength } //-------------------------------------------------------- /** * Read attribute CEHResonanceStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_CEHResonanceStrength(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_CEHResonanceStrength(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_CEHResonanceStrength) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_CEHResonanceStrength_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_CEHResonanceStrength } //-------------------------------------------------------- /** * Write attribute CEHResonanceStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_CEHResonanceStrength(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_CEHResonanceStrength(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_CEHResonanceStrength) ENABLED START -----*/ /* clang-format on */ // Add your own code omni_mutex_lock guardio(iomutex); Tango::DevDouble newStrength; newStrength = w_val + wValCehCorrStrength + ceh_design_strength; std::vector<double> req_strength; std::vector<double> curr_out; req_strength.push_back(newStrength); ceh->compute_currents(magnet_rigidity, req_strength, curr_out); Tango::DeviceAttribute watt("Current", curr_out[0]); ceh_current_dev->write_attribute(watt); wValCehResStrength = w_val; *attr_CEHResonanceStrength_read = w_val; ceh_set_strength[0] = newStrength; cehStrengthAtt->set_write_value(ceh_set_strength[0]); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_CEHResonanceStrength } //-------------------------------------------------------- /** * Read attribute CEVStrength related method * Description: embbeded corrector vertical kick * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_CEVStrength(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_CEVStrength(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_CEVStrength) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_CEVStrength_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_CEVStrength } //-------------------------------------------------------- /** * Write attribute CEVStrength related method * Description: embbeded corrector vertical kick * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_CEVStrength(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_CEVStrength(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_CEVStrength) ENABLED START -----*/ /* clang-format on */ // Add your own code omni_mutex_lock guardio(iomutex); std::vector<double> req_strength; std::vector<double> curr_out; req_strength.push_back(w_val); cev->compute_currents(magnet_rigidity, req_strength, curr_out); Tango::DeviceAttribute watt("Current",curr_out[0]); cev_current_dev->write_attribute(watt); cev_set_strength[0] = w_val; wValCevCorrStrength = w_val - wValCevResStrength; /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_CEVStrength } //-------------------------------------------------------- /** * Read attribute CEVCorrectionStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_CEVCorrectionStrength(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_CEVCorrectionStrength(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_CEVCorrectionStrength) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_CEVCorrectionStrength_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_CEVCorrectionStrength } //-------------------------------------------------------- /** * Write attribute CEVCorrectionStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_CEVCorrectionStrength(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_CEVCorrectionStrength(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_CEVCorrectionStrength) ENABLED START -----*/ /* clang-format on */ // Add your own code omni_mutex_lock guardio(iomutex); Tango::DevDouble newStrength; //resonanceAtt->get_write_value(_resStrength); newStrength = w_val + wValCevResStrength + cev_design_strength; std::vector<double> req_strength; std::vector<double> curr_out; req_strength.push_back(newStrength); cev->compute_currents(magnet_rigidity, req_strength, curr_out); Tango::DeviceAttribute watt("Current", curr_out[0]); cev_current_dev->write_attribute(watt); wValCevCorrStrength = w_val; cev_set_strength[0] = newStrength; cevStrengthAtt->set_write_value(cev_set_strength[0]); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_CEVCorrectionStrength } //-------------------------------------------------------- /** * Read attribute CEVResonanceStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_CEVResonanceStrength(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_CEVResonanceStrength(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_CEVResonanceStrength) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_CEVResonanceStrength_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_CEVResonanceStrength } //-------------------------------------------------------- /** * Write attribute CEVResonanceStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_CEVResonanceStrength(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_CEVResonanceStrength(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_CEVResonanceStrength) ENABLED START -----*/ /* clang-format on */ // Add your own code omni_mutex_lock guardio(iomutex); Tango::DevDouble newStrength; newStrength = w_val + wValCevCorrStrength + cev_design_strength; std::vector<double> req_strength; std::vector<double> curr_out; req_strength.push_back(newStrength); cev->compute_currents(magnet_rigidity, req_strength, curr_out); Tango::DeviceAttribute watt("Current", curr_out[0]); cev_current_dev->write_attribute(watt); wValCevResStrength = w_val; *attr_CEVResonanceStrength_read = w_val; cev_set_strength[0] = newStrength; cevStrengthAtt->set_write_value(cev_set_strength[0]); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_CEVResonanceStrength } //-------------------------------------------------------- /** * Read attribute SQStrength related method * Description: embbeded skew quadrupole strength * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_SQStrength(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_SQStrength(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_SQStrength) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_SQStrength_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_SQStrength } //-------------------------------------------------------- /** * Write attribute SQStrength related method * Description: embbeded skew quadrupole strength * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_SQStrength(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_SQStrength(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_SQStrength) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_SQStrength } //-------------------------------------------------------- /** * Read attribute SQCorrectionStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_SQCorrectionStrength(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_SQCorrectionStrength(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_SQCorrectionStrength) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_SQCorrectionStrength_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_SQCorrectionStrength } //-------------------------------------------------------- /** * Write attribute SQCorrectionStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_SQCorrectionStrength(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_SQCorrectionStrength(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_SQCorrectionStrength) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_SQCorrectionStrength } //-------------------------------------------------------- /** * Read attribute SQResonanceStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_SQResonanceStrength(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_SQResonanceStrength(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_SQResonanceStrength) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_SQResonanceStrength_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_SQResonanceStrength } //-------------------------------------------------------- /** * Write attribute SQResonanceStrength related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_SQResonanceStrength(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_SQResonanceStrength(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_SQResonanceStrength) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_SQResonanceStrength } //-------------------------------------------------------- /** * Read attribute CEHCurrent related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_CEHCurrent(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_CEHCurrent(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_CEHCurrent) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_CEHCurrent_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_CEHCurrent } //-------------------------------------------------------- /** * Write attribute CEHCurrent related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_CEHCurrent(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_CEHCurrent(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_CEHCurrent) ENABLED START -----*/ /* clang-format on */ // Add your own code Tango::DeviceAttribute watt("Current",w_val); ceh_current_dev->write_attribute(watt); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_CEHCurrent } //-------------------------------------------------------- /** * Read attribute CEVCurrent related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::read_CEVCurrent(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_CEVCurrent(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_CEVCurrent) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_CEVCurrent_read); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_CEVCurrent } //-------------------------------------------------------- /** * Write attribute CEVCurrent related method * * * Data type: Tango::DevDouble * Attr type: Scalar */ //-------------------------------------------------------- void E2Sextupole::write_CEVCurrent(Tango::WAttribute &attr) { DEBUG_STREAM << "E2Sextupole::write_CEVCurrent(Tango::WAttribute &attr) entering... " << std::endl; // Retrieve write value Tango::DevDouble w_val; attr.get_write_value(w_val); /*----- PROTECTED REGION ID(E2Sextupole::write_CEVCurrent) ENABLED START -----*/ /* clang-format on */ // Add your own code Tango::DeviceAttribute watt("Current",w_val); cev_current_dev->write_attribute(watt); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_CEVCurrent } //-------------------------------------------------------- /** * Read attribute PolynomA related method * Description: array of normal multipole components * * Data type: Tango::DevDouble * Attr type: Spectrum max = 3 */ //-------------------------------------------------------- void E2Sextupole::read_PolynomA(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_PolynomA(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_PolynomA) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_PolynomA_read, PolynomAAttrib::X_DATA_SIZE); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_PolynomA } //-------------------------------------------------------- /** * Read attribute PolynomB related method * Description: array of skew multipole components * * Data type: Tango::DevDouble * Attr type: Spectrum max = 3 */ //-------------------------------------------------------- void E2Sextupole::read_PolynomB(Tango::Attribute &attr) { DEBUG_STREAM << "E2Sextupole::read_PolynomB(Tango::Attribute &attr) entering... " << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::read_PolynomB) ENABLED START -----*/ /* clang-format on */ // Set the attribute value attr.set_value(attr_PolynomB_read, PolynomBAttrib::X_DATA_SIZE); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::read_PolynomB } //-------------------------------------------------------- /** * Method : E2Sextupole::add_dynamic_attributes() * Description: Create the dynamic attributes if any * for specified device. */ //-------------------------------------------------------- void E2Sextupole::add_dynamic_attributes() { /*----- PROTECTED REGION ID(E2Sextupole::add_dynamic_attributes) ENABLED START -----*/ /* clang-format on */ // Add your own code to create and add dynamic attributes if any /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::add_dynamic_attributes } //-------------------------------------------------------- /** * Command Reset related method * Description: reset the corrector * */ //-------------------------------------------------------- void E2Sextupole::reset() { DEBUG_STREAM << "E2Sextupole::Reset() - " << device_name << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::reset) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::reset } //-------------------------------------------------------- /** * Command ResetResonanceStrength related method * Description: Transfer ResonanceStranght to CorrectionStrength and set ResonanceStrength to 0. Strngth is not modified * */ //-------------------------------------------------------- void E2Sextupole::reset_resonance_strength() { DEBUG_STREAM << "E2Sextupole::ResetResonanceStrength() - " << device_name << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::reset_resonance_strength) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ //transfer resonance strength to correction strength and than force to 0 resonance strength omni_mutex_lock guardio(iomutex); wValMainCorrStrength += wValMainResStrength; wValMainResStrength = 0.0; mainCorrectionAtt->set_write_value(wValMainCorrStrength); *attr_CorrectionStrength_read = wValMainCorrStrength; mainResonanceAtt->set_write_value(0.0); *attr_ResonanceStrength_read = 0.0; /*----- PROTECTED REGION END -----*/ // E2Sextupole::reset_resonance_strength } //-------------------------------------------------------- /** * Command ApplyDesignStrength related method * Description: Apply the memorized DesignStrength strenght to the magnet. * */ //-------------------------------------------------------- void E2Sextupole::apply_design_strength() { DEBUG_STREAM << "E2Sextupole::ApplyDesignStrength() - " << device_name << std::endl; /*----- PROTECTED REGION ID(E2Sextupole::apply_design_strength) ENABLED START -----*/ /* clang-format on */ // Add your own code /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::apply_design_strength } //-------------------------------------------------------- /** * Method : E2Sextupole::add_dynamic_commands() * Description: Create the dynamic commands if any * for specified device. */ //-------------------------------------------------------- void E2Sextupole::add_dynamic_commands() { /*----- PROTECTED REGION ID(E2Sextupole::add_dynamic_commands) ENABLED START -----*/ /* clang-format on */ // Add your own code to create and add dynamic commands if any /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::add_dynamic_commands } /*----- PROTECTED REGION ID(E2Sextupole::namespace_ending) ENABLED START -----*/ /* clang-format on */ // Additional Methods /* clang-format off */ //-------------------------------------------------------- void E2Sextupole::calc_rigidity(const double& energy) { //claculate magnet ridity for electrons at energy (a.k.a. Brho) magnet_rigidity = sqrt(energy*energy - E0*E0)/c_light; magnet_rigidity_inv = 1.0/magnet_rigidity; //std::cout << magnet_rigidity << " simplified:" << (energy/1e9)*3.3356 << std::endl; } void E2Sextupole::set_main_current_write(const double& curr) { mainCursetAtt->set_write_value(curr); main_set_current[0] = curr; } void E2Sextupole::set_ceh_current_write(const double& curr) { cehCursetAtt->set_write_value(curr); ceh_set_current[0] = curr; } void E2Sextupole::set_cev_current_write(const double& curr) { cevCursetAtt->set_write_value(curr); cev_set_current[0] = curr; } // ------------------------------------------------------------ void E2Sextupole::init_strengths(void) // initialize strengths from power supply value TODO: separate read and set values { Tango::DeviceAttribute da; try { da = main_current_dev->read_attribute("Current"); vector<Tango::DevDouble> outval; da >> outval; std::vector<Tango::DevDouble> _current; std::vector<Tango::DevDouble> _strength; _current.push_back(outval[1]); //use set value of current sextupole->compute_strengths(magnet_rigidity_inv, _current, _strength); mainCursetAtt->set_write_value(_current); main_set_current[0] = _current[0]; mainStrengthAtt->set_write_value(_strength[0]); *attr_Strength_read = _strength[0]; main_set_strength[0] = _strength[0]; Tango::DevDouble corr = _strength[0] - *attr_DesignStrength_read; mainCorrectionAtt->set_write_value(corr); *attr_CorrectionStrength_read = corr; wValMainCorrStrength = corr; mainResonanceAtt->set_write_value(0.0); // start with resonance strength always at 0! *attr_ResonanceStrength_read = 0.0; wValMainResStrength = 0.0; } catch (Tango::DevFailed &e) { Tango::Except::print_exception(e); } try { da = ceh_current_dev->read_attribute("Current"); vector<Tango::DevDouble> outval; da >> outval; std::vector<Tango::DevDouble> _current; std::vector<Tango::DevDouble> _strength; _current.push_back(outval[1]); //use set value of current ceh->compute_strengths(magnet_rigidity_inv, _current, _strength); cehCursetAtt->set_write_value(_current); ceh_set_current[0] = _current[0]; cehStrengthAtt->set_write_value(_strength[0]); *attr_CEHStrength_read = _strength[0]; ceh_set_strength[0] = _strength[0]; Tango::DevDouble corr = _strength[0]; cehCorrectionAtt->set_write_value(corr); *attr_CEHCorrectionStrength_read = corr; wValCehCorrStrength = corr; cehResonanceAtt->set_write_value(0.0); // start with resonance strength always at 0! *attr_CEHResonanceStrength_read = 0.0; wValCehResStrength = 0.0; } catch (Tango::DevFailed &e) { Tango::Except::print_exception(e); } try { da = cev_current_dev->read_attribute("Current"); vector<Tango::DevDouble> outval; da >> outval; std::vector<Tango::DevDouble> _current; std::vector<Tango::DevDouble> _strength; _current.push_back(outval[1]); //use set value of current cev->compute_strengths(magnet_rigidity_inv, _current, _strength); cevCursetAtt->set_write_value(_current); cev_set_current[0] = _current[0]; cevStrengthAtt->set_write_value(_strength[0]); *attr_CEVStrength_read = _strength[0]; cev_set_strength[0] = _strength[0]; Tango::DevDouble corr = _strength[0]; cevCorrectionAtt->set_write_value(corr); *attr_CEHCorrectionStrength_read = corr; wValCevCorrStrength = corr; cevResonanceAtt->set_write_value(0.0); // start with resonance strength always at 0! *attr_CEVResonanceStrength_read = 0.0; wValCevResStrength = 0.0; } catch (Tango::DevFailed &e) { Tango::Except::print_exception(e); } } //------------------------------------------------------------ // handle changes of power supplies read current (actual current) void E2Sextupole::update_values_read_main(void) { if (isnan(*attr_Current_read)){ //handle error attr_Strength_read[0] = NAN; return; } INFO_STREAM << "update values read main"; std::vector<Tango::DevDouble> read_curr; std::vector<Tango::DevDouble> read_strength; omni_mutex_lock guardio(iomutex); read_curr.push_back(*attr_Current_read); sextupole->compute_strengths(magnet_rigidity_inv, read_curr, read_strength); attr_Strength_read[0] = read_strength[0]; attr_CorrectionStrength_read[0] = attr_Strength_read[0] -( attr_DesignStrength_read[0] + attr_ResonanceStrength_read[0]); } void E2Sextupole::update_values_read_ceh(void) { if (isnan(*attr_CEHCurrent_read)){ //handle error attr_CEHStrength_read[0] = NAN; return; } INFO_STREAM << "update values read ceh"; std::vector<Tango::DevDouble> read_curr; std::vector<Tango::DevDouble> read_strength; omni_mutex_lock guardio(iomutex); read_curr.push_back(*attr_CEHCurrent_read); ceh->compute_strengths(magnet_rigidity_inv, read_curr, read_strength); attr_CEHStrength_read[0] = read_strength[0]; attr_CEHCorrectionStrength_read[0] = attr_CEHStrength_read[0] - ( ceh_design_strength + attr_CEHResonanceStrength_read[0]); } void E2Sextupole::update_values_read_cev(void) { if (isnan(*attr_CEVCurrent_read)){ //handle error attr_CEHStrength_read[0] = NAN; return; } INFO_STREAM << "update values read cev"; std::vector<Tango::DevDouble> read_curr; std::vector<Tango::DevDouble> read_strength; omni_mutex_lock guardio(iomutex); read_curr.push_back(*attr_CEVCurrent_read); cev->compute_strengths(magnet_rigidity_inv, read_curr, read_strength); attr_CEVStrength_read[0] = read_strength[0]; attr_CEVCorrectionStrength_read[0] = attr_CEVStrength_read[0] - ( cev_design_strength + attr_CEVResonanceStrength_read[0]); } //------------------------------------------------------------ // handle change of write set point of power supplies current void E2Sextupole::update_values_write_main(void) { if (isnan(*attr_Current_read)){ //handle error attr_Strength_read[0] = NAN; return; } INFO_STREAM << "update values write main"; std::vector<Tango::DevDouble> read_curr; std::vector<Tango::DevDouble> read_strength; omni_mutex_lock guardio(iomutex); read_curr.push_back(main_set_current[0]); //must use the write value sextupole->compute_strengths(magnet_rigidity_inv, read_curr, read_strength); wValMainCorrStrength = read_strength[0] - (wValMainResStrength + *attr_DesignStrength_read); mainCorrectionAtt->set_write_value(wValMainCorrStrength); } // handle change of write set point of ceh power supply current void E2Sextupole::update_values_write_ceh(void) { INFO_STREAM << "update values write ceh"; std::vector<Tango::DevDouble> read_curr; std::vector<Tango::DevDouble> read_strength; omni_mutex_lock guardio(iomutex); read_curr.push_back(ceh_set_current[0]); //must use the write value ceh->compute_strengths(magnet_rigidity_inv, read_curr, read_strength); wValCehCorrStrength = read_strength[0] - (wValCehResStrength + ceh_design_strength); cehCorrectionAtt->set_write_value(wValCehCorrStrength); } // handle change of write set point of cev power supply current void E2Sextupole::update_values_write_cev(void) { INFO_STREAM << "update values write cev"; std::vector<Tango::DevDouble> read_curr; std::vector<Tango::DevDouble> read_strength; omni_mutex_lock guardio(iomutex); read_curr.push_back(cev_set_current[0]); //must use the write value cev->compute_strengths(magnet_rigidity_inv, read_curr, read_strength); wValCevCorrStrength = read_strength[0] - (wValCevResStrength + cev_design_strength); cevCorrectionAtt->set_write_value(wValCevCorrStrength); } //------------------------------------------------------------ // handles change of power supples state - may just filter values void E2Sextupole::update_values_state(void) { //handle state - status //INFO_STREAM << "update values state"; switch (get_state()) { case Tango::ON: set_status("On"); break; case Tango::OFF: set_status("Off"); break; case Tango::FAULT: set_status("Fault"); break; case Tango::RUNNING: set_status("Running"); break; case Tango::MOVING: set_status("Moving"); break; default: set_status("Unknown"); } } void E2Sextupole::subscribe_events(void) { try{ EventSource evsrc= MainPS; main_current_cb = new MainCurrentEventCallback(this, evsrc); main_current_event_id = main_current_dev->subscribe_event("current",Tango::CHANGE_EVENT,main_current_cb); main_current_set_event_id = main_current_dev->subscribe_event("currentSet",Tango::CHANGE_EVENT,main_current_cb); main_state_event_id = main_current_dev->subscribe_event("State",Tango::CHANGE_EVENT,main_current_cb); } catch(Tango::DevFailed &ex){ main_current_cb = nullptr; ERROR_STREAM << "failed to subscribe Tango events for " << currentDevice; set_state(Tango::UNKNOWN); set_status("failed to subscribe Tango events for CurrentDevice"); return; } try{ EventSource evsrc= CeHPS; ceh_current_cb = new MainCurrentEventCallback(this, evsrc); ceh_current_event_id = ceh_current_dev->subscribe_event("current",Tango::CHANGE_EVENT, ceh_current_cb); ceh_current_set_event_id = ceh_current_dev->subscribe_event("currentSet",Tango::CHANGE_EVENT, ceh_current_cb); ceh_state_event_id = ceh_current_dev->subscribe_event("State",Tango::CHANGE_EVENT, ceh_current_cb); } catch(Tango::DevFailed &ex){ ceh_current_cb = nullptr; ERROR_STREAM << "failed to subscribe Tango events for " << cEHDeviceName; set_state(Tango::UNKNOWN); set_status("failed to subscribe Tango events for cehDeviceName"); return; } try{ EventSource evsrc= CeVPS; cev_current_cb = new MainCurrentEventCallback(this, evsrc); cev_current_event_id = cev_current_dev->subscribe_event("current",Tango::CHANGE_EVENT, cev_current_cb); cev_current_set_event_id = cev_current_dev->subscribe_event("currentSet",Tango::CHANGE_EVENT, cev_current_cb); cev_state_event_id = cev_current_dev->subscribe_event("State",Tango::CHANGE_EVENT,cev_current_cb); } catch(Tango::DevFailed &ex){ ceh_current_cb = nullptr; ERROR_STREAM << "failed to subscribe Tango events for " << cEVDeviceName; set_state(Tango::UNKNOWN); set_status("failed to subscribe Tango events for cevDeviceName"); return; } } /* trick to start sunbscrition afetr some delay void E2Sextupole::delayed_subscribe(int delayMs) #include <thread> #include <chrono> { std::thread([this, delayMs]() { std::this_thread::sleep_for(std::chrono::milliseconds(delayMs)); this->subscribe_events(); // Call the method after the delay }).detach(); // Detach the thread to run independently } */ //------------------------------------------------------------ //------------------------------------------------------------ MainCurrentEventCallback::MainCurrentEventCallback(E2Sextupole* sext, EventSource evsrc) //callback constructor { e2_sext = sext; source = evsrc; } void MainCurrentEventCallback::push_event(Tango::EventData* ev) //callback core method { bool update_read_main = false; bool update_write_main = false; bool update_read_ceh = false; bool update_write_ceh = false; bool update_read_cev = false; bool update_write_cev = false; bool update_state = false; if (ev->err) { //std::cerr << ev->err << " " << ev->attr_name << std::endl; e2_sext->set_state(Tango::FAULT); e2_sext->set_status("event error"); *e2_sext->attr_Current_read = NAN; e2_sext->update_values_read_main(); return; } { omni_mutex_lock guardio(e2_sext->iomutex); //TODO add method to update the corrector when on value changes std::string fullattrname = ev->attr_name; std::size_t pos = fullattrname.find_last_of("/"); std::string attrname = fullattrname.substr(pos + 1); if (attrname == "current") { switch (source){ case MainPS: *(ev->attr_value) >> *(e2_sext->attr_Current_read); update_read_main = true;break; case CeHPS: *(ev->attr_value) >> *(e2_sext->attr_CEHCurrent_read); update_read_ceh = true; break; case CeVPS: *(ev->attr_value) >> *(e2_sext->attr_CEVCurrent_read); update_read_cev = true; break; } } if (attrname == "currentset") { Tango::DevDouble newcurr; *(ev->attr_value) >> newcurr; switch (source){ case MainPS: e2_sext->set_main_current_write(newcurr); update_write_main = true; break; case CeHPS: e2_sext->set_ceh_current_write(newcurr); update_write_ceh = true; break; case CeVPS: e2_sext->set_cev_current_write(newcurr); update_write_cev = true; break; } } if (attrname == "state") { Tango::DevState st; *(ev->attr_value) >> st; switch (source){ case MainPS: e2_sext->main_current_state = st; e2_sext->set_state(st); break; case CeHPS: e2_sext->ceh_current_state = st; break; case CeVPS: e2_sext->cev_current_state = st; break; } update_state = true; } } if (update_read_main) e2_sext->update_values_read_main(); if (update_write_main) e2_sext->update_values_write_main(); if (update_read_ceh) e2_sext->update_values_read_ceh(); if (update_write_ceh) e2_sext->update_values_write_ceh(); if (update_read_cev) e2_sext->update_values_read_cev(); if (update_write_cev) e2_sext->update_values_write_cev(); if (update_state) e2_sext->update_values_state(); } //-------------------------------------------------------- /*----- PROTECTED REGION END -----*/ // E2Sextupole::namespace_ending } // namespace