From cfb685d41f5355b41de73b793b3b4e931434e79a Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Wed, 2 Oct 2024 17:04:58 +0200 Subject: [PATCH 1/6] first compilation --- .gitignore | 9 + Makefile | 4 + README.md | 92 +-- src/ClassFactory.cpp | 53 ++ src/E2Sextupole.cpp | 996 ++++++++++++++++++++++++++++++++ src/E2Sextupole.h | 338 +++++++++++ src/E2Sextupole.xmi | 146 +++++ src/E2SextupoleClass.cpp | 873 ++++++++++++++++++++++++++++ src/E2SextupoleClass.h | 281 +++++++++ src/E2SextupoleStateMachine.cpp | 242 ++++++++ src/main.cpp | 89 +++ 11 files changed, 3034 insertions(+), 89 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 src/ClassFactory.cpp create mode 100644 src/E2Sextupole.cpp create mode 100644 src/E2Sextupole.h create mode 100644 src/E2Sextupole.xmi create mode 100644 src/E2SextupoleClass.cpp create mode 100644 src/E2SextupoleClass.h create mode 100644 src/E2SextupoleStateMachine.cpp create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..155b405 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.nse_depinfo* +bin +obj + +# Eclipse +.cproject +.project +.settings +*.launch diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..239bf2f --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +NAME_SRV = e2sextupole-srv +CXXFLAGS += -I /usr/include/eigen3 -I /runtime/include +LDFLAGS += -L /runtime/lib -lMagnetModel +include ../makefiles/Make-9.3.6.in diff --git a/README.md b/README.md index 0d53034..a4900a1 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,6 @@ # E2Sextupole +Elettra 2.0 sextupole magnet device - -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://gitlab.elettra.eu/dt/ds/e2sextupole.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.elettra.eu/dt/ds/e2sextupole/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +## +Calibration is a CSV file diff --git a/src/ClassFactory.cpp b/src/ClassFactory.cpp new file mode 100644 index 0000000..88c8da7 --- /dev/null +++ b/src/ClassFactory.cpp @@ -0,0 +1,53 @@ +/*----- PROTECTED REGION ID(E2Sextupole::ClassFactory.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : ClassFactory.cpp +// +// description : C++ source for the class_factory method of the DServer +// device class. This method is responsible for the creation of +// all class singleton for a device server. It is called +// at device server startup. +// +// project : Elettra 2.0 pure corrector 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 <tango/tango.h> +#include "E2SextupoleClass.h" + +// Add class header files if needed + + +/** + * Create E2Sextupole Class singleton and store it in DServer object. + */ + +void Tango::DServer::class_factory() +{ + // Add method class init if needed + add_class(E2Sextupole_ns::E2SextupoleClass::init("E2Sextupole")); +} +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Sextupole::ClassFactory.cpp diff --git a/src/E2Sextupole.cpp b/src/E2Sextupole.cpp new file mode 100644 index 0000000..1d78fec --- /dev/null +++ b/src/E2Sextupole.cpp @@ -0,0 +1,996 @@ +/*----- 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 +//================================================================ + +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 + + if(state_event_id) current_dev->unsubscribe_event(state_event_id); + if(current_set_event_id) current_dev->unsubscribe_event(current_set_event_id); + if(current_event_id) current_dev->unsubscribe_event(current_event_id); + if(current_cb) delete current_cb; + delete attr_Current_read; + if (current_dev) delete current_dev; + if (sextupole) delete sextupole; + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::delete_device + delete[] attr_Strength_read; + delete[] attr_CorrectionStrength_read; + delete[] attr_ResonanceStrength_read; + delete[] attr_BeamEnergy_read; + delete[] attr_DesignStrength_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::INIT); + set_status("Init"); + attr_Current_read = new Tango::DevDouble[1]; + first_read = true; + /*----- 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_BeamEnergy_read = new Tango::DevDouble[1]; + attr_DesignStrength_read = new Tango::DevDouble[1]; + // 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 */ + current_dev = nullptr; + current_cb = nullptr; + current_event_id = 0; + current_set_event_id = 0; + state_event_id = 0; + set_current.resize(1, 0.0); + set_strength.resize(1,0.0); + try{ + current_dev = new Tango::DeviceProxy(currentDevice); + } + catch (Tango::DevFailed &ex){ + ERROR_STREAM << "failed to create Tango device proxy for " + << 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 teh EBS shehme with global proprties... 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; + } + + // 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 + strengthAtt = &get_device_attr()->get_w_attr_by_name("Strength"); + correctionAtt = &get_device_attr()->get_w_attr_by_name("CorrectionStrength"); + resonanceAtt = &get_device_attr()->get_w_attr_by_name("ResonanceStrength"); + cursetAtt = &(get_device_attr()->get_w_attr_by_name("Current")); + init_strengths(); + + // register callaback for current + + try{ + current_cb = new CurrentEventCallback(this); + current_event_id = current_dev->subscribe_event("current",Tango::CHANGE_EVENT,current_cb); + current_set_event_id = current_dev->subscribe_event("currentSet",Tango::CHANGE_EVENT,current_cb); + state_event_id = current_dev->subscribe_event("State",Tango::CHANGE_EVENT,current_cb); + } + catch(Tango::DevFailed &ex){ + 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; + } + /*----- 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("CurrentDevice")); + dev_prop.push_back(Tango::DbDatum("Model")); + dev_prop.push_back(Tango::DbDatum("SerialNumber")); + dev_prop.push_back(Tango::DbDatum("MagnetName")); + dev_prop.push_back(Tango::DbDatum("CalibrationFileName")); + dev_prop.push_back(Tango::DbDatum("CalibrationPath")); + dev_prop.push_back(Tango::DbDatum("ParameterFileName")); + + // 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 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 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 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 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 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 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]); + + } + + /*----- 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]); + current_dev->write_attribute(watt); + set_strength[0] = w_val; + wValCorrStrength = w_val - wValResStrength; + correctionAtt->set_write_value(wValCorrStrength); + //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; + //resonanceAtt->get_write_value(_resStrength); + newStrength = w_val + wValResStrength; + 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]); + current_dev->write_attribute(watt); + wValCorrStrength = w_val; + set_strength[0] = newStrength; + strengthAtt->set_write_value(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 + wValCorrStrength; + 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]); + current_dev->write_attribute(watt); + wValResStrength = w_val; + set_strength[0] = newStrength; + strengthAtt->set_write_value(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); + 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; + /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_DesignStrength +} + +//-------------------------------------------------------- +/** + * 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: Reset ResonanceStrength to 0 + * + */ +//-------------------------------------------------------- +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 */ + //force to 0 resonance strength + omni_mutex_lock guardio(iomutex); + Tango::DevDouble newStrength; + newStrength = wValCorrStrength; + 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]); + current_dev->write_attribute(watt); + wValResStrength = 0.0; + set_strength[0] = newStrength; + strengthAtt->set_write_value(set_strength[0]); + resonanceAtt->set_write_value(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_current_write(const double& curr) +{ + cursetAtt->set_write_value(curr); + set_current[0] = curr; +} +// ------------------------------------------------------------ +void E2Sextupole::init_strengths(void) // initialize strengths from power supply value +{ + Tango::DeviceAttribute da; + try { + da = 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]); + sextupole->compute_strengths(magnet_rigidity_inv, _current, _strength); + + cursetAtt->set_write_value(_current[0]); + set_current[0] = _current[0]; + + strengthAtt->set_write_value(_strength[0]); + *attr_Strength_read = _strength[0]; + set_strength[0] = _strength[0]; + + correctionAtt->set_write_value(_strength[0]); + *attr_CorrectionStrength_read = _strength[0]; + wValCorrStrength = _strength[0]; + + resonanceAtt->set_write_value(0.0); // start with resonance strength always at 0! + *attr_ResonanceStrength_read = 0.0; + wValResStrength = 0.0; + + } catch (Tango::DevFailed &e) { + Tango::Except::print_exception(e); + } +} +//------------------------------------------------------------ +void E2Sextupole::update_values(void) +{ + /* + sextupole->compute_strengths(magnet_rigidity_inv, set_current, set_strength); + attr_Strength_read[0] = set_strength[0]; + attr_ResonanceStrength_read[0] = attr_Strength_read[0] - wValCorrStrength; + attr_CorrectionStrength_read[0] = attr_Strength_read[0] - attr_ResonanceStrength_read[0]; + */ + //---------------------------------------------- + if (first_read){ + INFO_STREAM << *attr_DesignStrength_read ; + first_read = false; + } + //INFO_STREAM << *attr_DesignStrength_read ; + std::vector<Tango::DevDouble> read_curr; + std::vector<Tango::DevDouble> read_strength; + 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_ResonanceStrength_read[0] = attr_Strength_read[0] - wValCorrStrength; + attr_CorrectionStrength_read[0] = attr_Strength_read[0] - wValResStrength; + + //handle state - status + 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"); + } + +} + +//------------------------------------------------------------ +//------------------------------------------------------------ +CurrentEventCallback::CurrentEventCallback(E2Sextupole* sext) //callback constructor +{ + e2_sext = sext; +} +void CurrentEventCallback::push_event(Tango::EventData* ev) //callback core method +{ + if (ev->err) { + //TODO hanlde error + 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") *(ev->attr_value) >> *(e2_sext->attr_Current_read); + if(attrname == "currentset"){ + Tango::DevDouble newcurr; + *(ev->attr_value) >> newcurr; + e2_sext->set_current_write(newcurr); + } + if(attrname == "state") { + Tango::DevState st; + *(ev->attr_value) >> st; + e2_sext->set_state(st); + } + e2_sext->update_values(); +} + +/*----- PROTECTED REGION END -----*/ // E2Sextupole::namespace_ending +} // namespace diff --git a/src/E2Sextupole.h b/src/E2Sextupole.h new file mode 100644 index 0000000..00a9bdd --- /dev/null +++ b/src/E2Sextupole.h @@ -0,0 +1,338 @@ +/*----- PROTECTED REGION ID(E2Sextupole.h) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : E2Sextupole.h +// +// description : Include file for the E2Sextupole class +// +// project : Elettra 2.0 pure corrector 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) +//============================================================================= + + +#ifndef E2Sextupole_H +#define E2Sextupole_H + +#include <tango/tango.h> +#include <PureSextupole.h> +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Sextupole.h + +#ifdef TANGO_LOG + // cppTango after c934adea (Merge branch 'remove-cout-definition' into 'main', 2022-05-23) + // nothing to do +#else + // cppTango 9.3-backports and older + #define TANGO_LOG cout + #define TANGO_LOG_INFO cout2 + #define TANGO_LOG_DEBUG cout3 +#endif // TANGO_LOG + +/** + * 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. + */ + + +namespace E2Sextupole_ns +{ +/*----- PROTECTED REGION ID(E2Sextupole::Additional Class Declarations) ENABLED START -----*/ +/* clang-format on */ +// Additional Class Declarations +const double default_beam_energy = 2.4e9; // default electron beam energy in GeV +const double E0 = 510998.94999999995; // electron rest mass in eV +const double c_light = 299792458.0; // speed of light m/s +//class Corrector; +class CurrentEventCallback; +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Sextupole::Additional Class Declarations + +class E2Sextupole : public TANGO_BASE_CLASS +{ + +/*----- PROTECTED REGION ID(E2Sextupole::Data Members) ENABLED START -----*/ +/* clang-format on */ +// Add your own data members + MagnetModel::PureSextupole* sextupole; //magnet model + double magnet_rigidity; + double magnet_rigidity_inv; + Tango::DeviceProxy *current_dev; + CurrentEventCallback *current_cb; + int current_event_id; + int current_set_event_id; + int state_event_id; + Tango::WAttribute *cursetAtt; + Tango::WAttribute *strengthAtt; + Tango::WAttribute *correctionAtt; + Tango::WAttribute *resonanceAtt; + std::vector<double> set_current; //the actual set point of the current (from the power supply) used for strength calculations + std::vector<double> set_strength; //the strength set point +public: + omni_mutex iomutex; //guard for event and write interference + Tango::DevDouble wValCorrStrength; //last CorrectionStrength write value + Tango::DevDouble wValResStrength; //last ResonanceStrength write value + bool first_read; +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Sextupole::Data Members + +// Device property data members +public: + // CurrentDevice: power supply tango device name + std::string currentDevice; + // Model: corrector model (part number) + std::string model; + // SerialNumber: serial number of the magnet + std::string serialNumber; + // MagnetName: Name of magnet + std::string magnetName; + // CalibrationFileName: name of calibration table file name + std::string calibrationFileName; + // CalibrationPath: path of calibration and parameter files + std::string calibrationPath; + // ParameterFileName: name of auxiliary parametr file name + // (EBSmagnet compatibility) + std::string parameterFileName; + + bool mandatoryNotDefined; + +// Attribute data members +public: + Tango::DevDouble *attr_Strength_read; + Tango::DevDouble *attr_CorrectionStrength_read; + Tango::DevDouble *attr_ResonanceStrength_read; + Tango::DevDouble *attr_Current_read; + Tango::DevDouble *attr_BeamEnergy_read; + Tango::DevDouble *attr_DesignStrength_read; + +// Constructors and destructors +public: + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device Name + */ + E2Sextupole(Tango::DeviceClass *cl,std::string &s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device Name + */ + E2Sextupole(Tango::DeviceClass *cl,const char *s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device name + * @param d Device description. + */ + E2Sextupole(Tango::DeviceClass *cl,const char *s,const char *d); + /** + * The device object destructor. + */ + ~E2Sextupole(); + + +// Miscellaneous methods +public: + /* + * will be called at device destruction or at init command. + */ + void delete_device(); + /* + * Initialize the device + */ + virtual void init_device(); + /* + * Read the device properties from database + */ + void get_device_property(); + /* + * Always executed method before execution command method. + */ + virtual void always_executed_hook(); + + /* + * Check if mandatory property has been set + */ + void check_mandatory_property(Tango::DbDatum &class_prop, Tango::DbDatum &dev_prop); + +// Attribute methods +public: + //-------------------------------------------------------- + /* + * Method : E2Sextupole::read_attr_hardware() + * Description: Hardware acquisition for attributes. + */ + //-------------------------------------------------------- + virtual void read_attr_hardware(std::vector<long> &attr_list); + //-------------------------------------------------------- + /* + * Method : E2Sextupole::write_attr_hardware() + * Description: Hardware writing for attributes. + */ + //-------------------------------------------------------- + virtual void write_attr_hardware(std::vector<long> &attr_list); + +/** + * Attribute Strength related methods + * Description: sextupole strength 1/m^3 ( m-3) + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_Strength(Tango::Attribute &attr); + virtual void write_Strength(Tango::WAttribute &attr); + virtual bool is_Strength_allowed(Tango::AttReqType type); +/** + * Attribute CorrectionStrength related methods + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_CorrectionStrength(Tango::Attribute &attr); + virtual void write_CorrectionStrength(Tango::WAttribute &attr); + virtual bool is_CorrectionStrength_allowed(Tango::AttReqType type); +/** + * Attribute ResonanceStrength related methods + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_ResonanceStrength(Tango::Attribute &attr); + virtual void write_ResonanceStrength(Tango::WAttribute &attr); + virtual bool is_ResonanceStrength_allowed(Tango::AttReqType type); +/** + * Attribute Current related methods + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_Current(Tango::Attribute &attr); + virtual void write_Current(Tango::WAttribute &attr); + virtual bool is_Current_allowed(Tango::AttReqType type); +/** + * Attribute BeamEnergy related methods + * Description: Electron beam energy in eV. Used to calculate magnetic rigidity in strength calculations. + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_BeamEnergy(Tango::Attribute &attr); + virtual void write_BeamEnergy(Tango::WAttribute &attr); + virtual bool is_BeamEnergy_allowed(Tango::AttReqType type); +/** + * Attribute DesignStrength related methods + * 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 + */ + virtual void read_DesignStrength(Tango::Attribute &attr); + virtual void write_DesignStrength(Tango::WAttribute &attr); + virtual bool is_DesignStrength_allowed(Tango::AttReqType type); + + + //-------------------------------------------------------- + /** + * Method : E2Sextupole::add_dynamic_attributes() + * Description: Add dynamic attributes if any. + */ + //-------------------------------------------------------- + void add_dynamic_attributes(); + + + + +// Command related methods +public: + /** + * Command Reset related method + * Description: reset the corrector + * + */ + virtual void reset(); + virtual bool is_Reset_allowed(const CORBA::Any &any); + /** + * Command ResetResonanceStrength related method + * Description: Reset ResonanceStrength to 0 + * + */ + virtual void reset_resonance_strength(); + virtual bool is_ResetResonanceStrength_allowed(const CORBA::Any &any); + /** + * Command ApplyDesignStrength related method + * Description: Apply the memorized DesignStrength strenght to the magnet. + * + */ + virtual void apply_design_strength(); + virtual bool is_ApplyDesignStrength_allowed(const CORBA::Any &any); + + + //-------------------------------------------------------- + /** + * Method : E2Sextupole::add_dynamic_commands() + * Description: Add dynamic commands if any. + */ + //-------------------------------------------------------- + void add_dynamic_commands(); + +/*----- PROTECTED REGION ID(E2Sextupole::Additional Method prototypes) ENABLED START -----*/ +/* clang-format on */ +// Additional Method prototypes + void calc_rigidity(const double& energy); + void set_current_write(const double& curr); + void update_values(void); //update internal calculated values + void init_strengths(void); // initialize strengths from power supply values +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Sextupole::Additional Method prototypes +}; + +/*----- PROTECTED REGION ID(E2Sextupole::Additional Classes Definitions) ENABLED START -----*/ +/* clang-format on */ +// Additional Classes Definitions +class CurrentEventCallback : public Tango::CallBack +{ +public: + CurrentEventCallback(E2Sextupole*); + void push_event(Tango::EventData* ev); +protected: + E2Sextupole* e2_sext; +}; +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Sextupole::Additional Classes Definitions + +} // End of namespace + +#endif // E2Sextupole_H diff --git a/src/E2Sextupole.xmi b/src/E2Sextupole.xmi new file mode 100644 index 0000000..0a7dfe9 --- /dev/null +++ b/src/E2Sextupole.xmi @@ -0,0 +1,146 @@ +<?xml version="1.0" encoding="ASCII"?> +<pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://tango.org/pogo/PogoDsl"> + <classes name="E2Sextupole" pogoRevision="9.9"> + <description 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." title="Elettra 2.0 pure corrector magnet device" sourcePath="/homelocal/claudio/src/gitlab/dt/ds/e2sextupole/src" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="Elettra - Sincrotrone Trieste S.c.p.A." hasMandatoryProperty="true" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false"> + <inheritances classname="Device_Impl" sourcePath=""/> + <identification contact="at elettra.eu - claudio.scafuri" author="claudio.scafuri" emailDomain="elettra.eu" classFamily="MagneticDevices" siteSpecific="" platform="Unix Like" bus="Not Applicable" manufacturer="none" reference=""> + <keyWords>magnet</keyWords> + <keyWords>pure corrector</keyWords> + <keyWords>fast corrector</keyWords> + <keyWords>Elettra 2.0</keyWords> + <keyWords>calibartion</keyWords> + </identification> + </description> + <classProperties name="BeamEnergy" description="default electron beam energy, in GeV.
Use to initialize all magnet istances BeamEnergy attribute."> + <type xsi:type="pogoDsl:DoubleType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <DefaultPropValue>2.4</DefaultPropValue> + </classProperties> + <classProperties name="CalibrationPath" description="path of calibration and parameter files"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </classProperties> + <deviceProperties name="CurrentDevice" description="power supply tango device name"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="Model" description="corrector model (part number)"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="SerialNumber" description="serial number of the magnet"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="MagnetName" description="Name of magnet"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="CalibrationFileName" mandatory="true" description="name of calibration table file name"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="CalibrationPath" description="path of calibration and parameter files"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="ParameterFileName" mandatory="true" description="name of auxiliary parametr file name
(EBSmagnet compatibility)"> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0"> + <argin description="none"> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description="Device state"> + <type xsi:type="pogoDsl:StateType"/> + </argout> + <status abstract="true" inherited="true" concrete="true"/> + </commands> + <commands name="Status" description="This command gets the device status (stored in its device_status data member) and returns it to the caller." execMethod="dev_status" displayLevel="OPERATOR" polledPeriod="0"> + <argin description="none"> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description="Device status"> + <type xsi:type="pogoDsl:ConstStringType"/> + </argout> + <status abstract="true" inherited="true" concrete="true"/> + </commands> + <commands name="Reset" description="reset the corrector" execMethod="reset" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="ResetResonanceStrength" description="Reset ResonanceStrength to 0" execMethod="reset_resonance_strength" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <commands name="ApplyDesignStrength" description="Apply the memorized DesignStrength strenght to the magnet." execMethod="apply_design_strength" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </commands> + <attributes name="Strength" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="sextupole strength 1/m^3 ( m-3)" label="strength" unit="m-3" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="CorrectionStrength" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="correction strength" unit="m-3" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="ResonanceStrength" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="resonance strength" unit="m-3" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="Current" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="false" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="A" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="BeamEnergy" attType="Scalar" rwType="READ_WRITE" displayLevel="EXPERT" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="Electron beam energy in eV. Used to calculate magnetic rigidity in strength calculations." label="electron beam ebergy [eV]" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <attributes name="DesignStrength" attType="Scalar" rwType="READ_WRITE" displayLevel="EXPERT" polledPeriod="0" maxX="" maxY="" memorized="true" memorizedAtInit="true" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="sextupole design strength 1/m^3 ( m-3). The strenght reqiured by the nominal optic
The attribute is memorized , expert only." label="design strength" unit="m-3" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <preferences docHome="./doc_html" makefileHome="$(TANGO_HOME)"/> + </classes> +</pogoDsl:PogoSystem> diff --git a/src/E2SextupoleClass.cpp b/src/E2SextupoleClass.cpp new file mode 100644 index 0000000..1d1b860 --- /dev/null +++ b/src/E2SextupoleClass.cpp @@ -0,0 +1,873 @@ +/*----- PROTECTED REGION ID(E2SextupoleClass.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : E2SextupoleClass.cpp +// +// description : C++ source for the E2SextupoleClass. +// A singleton class derived from DeviceClass. +// It implements the command and attribute list +// and all properties and methods required +// by the E2Sextupole once per process. +// +// project : Elettra 2.0 pure corrector 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 "E2SextupoleClass.h" +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2SextupoleClass.cpp + +//------------------------------------------------------------------- +/** + * Create E2SextupoleClass singleton and + * return it in a C function for Python usage + */ +//------------------------------------------------------------------- +extern "C" { +#ifdef _TG_WINDOWS_ + +__declspec(dllexport) + +#endif + + Tango::DeviceClass *_create_E2Sextupole_class(const char *name) { + return E2Sextupole_ns::E2SextupoleClass::init(name); + } +} + +namespace E2Sextupole_ns +{ +//=================================================================== +// Initialize pointer for singleton pattern +//=================================================================== +E2SextupoleClass *E2SextupoleClass::_instance = NULL; + +//=================================================================== +// Class constants +//=================================================================== +//-------------------------------------------------------- +/** + * method : E2SextupoleClass::E2SextupoleClass(std::string &s) + * description : constructor for the E2SextupoleClass + * + * @param s The class name + */ +//-------------------------------------------------------- +E2SextupoleClass::E2SextupoleClass(std::string &s):Tango::DeviceClass(s) +{ + TANGO_LOG_INFO << "Entering E2SextupoleClass constructor" << std::endl; + set_default_property(); + get_class_property(); + write_class_property(); + + /*----- PROTECTED REGION ID(E2SextupoleClass::constructor) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2SextupoleClass::constructor + + TANGO_LOG_INFO << "Leaving E2SextupoleClass constructor" << std::endl; +} + +//-------------------------------------------------------- +/** + * method : E2SextupoleClass::~E2SextupoleClass() + * description : destructor for the E2SextupoleClass + */ +//-------------------------------------------------------- +E2SextupoleClass::~E2SextupoleClass() +{ + /*----- PROTECTED REGION ID(E2SextupoleClass::destructor) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2SextupoleClass::destructor + + _instance = NULL; +} + + +//-------------------------------------------------------- +/** + * method : E2SextupoleClass::init + * description : Create the object if not already done. + * Otherwise, just return a pointer to the object + * + * @param name The class name + */ +//-------------------------------------------------------- +E2SextupoleClass *E2SextupoleClass::init(const char *name) +{ + if (_instance == NULL) + { + try + { + std::string s(name); + _instance = new E2SextupoleClass(s); + } + catch (std::bad_alloc &) + { + throw; + } + } + return _instance; +} + +//-------------------------------------------------------- +/** + * method : E2SextupoleClass::instance + * description : Check if object already created, + * and return a pointer to the object + */ +//-------------------------------------------------------- +E2SextupoleClass *E2SextupoleClass::instance() +{ + if (_instance == NULL) + { + std::cerr << "Class is not initialized !!" << std::endl; + exit(-1); + } + return _instance; +} + + + +//=================================================================== +// Command execution method calls +//=================================================================== +//-------------------------------------------------------- +/** + * method : ResetClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *ResetClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + TANGO_LOG_INFO << "ResetClass::execute(): arrived" << std::endl; + ((static_cast<E2Sextupole *>(device))->reset()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : ResetResonanceStrengthClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *ResetResonanceStrengthClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + TANGO_LOG_INFO << "ResetResonanceStrengthClass::execute(): arrived" << std::endl; + ((static_cast<E2Sextupole *>(device))->reset_resonance_strength()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : ApplyDesignStrengthClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *ApplyDesignStrengthClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + TANGO_LOG_INFO << "ApplyDesignStrengthClass::execute(): arrived" << std::endl; + ((static_cast<E2Sextupole *>(device))->apply_design_strength()); + return new CORBA::Any(); +} + + +//=================================================================== +// Properties management +//=================================================================== +//-------------------------------------------------------- +/** + * Method : E2SextupoleClass::get_class_property() + * Description: Get the class property for specified name. + */ +//-------------------------------------------------------- +Tango::DbDatum E2SextupoleClass::get_class_property(std::string &prop_name) +{ + for (unsigned int i=0 ; i<cl_prop.size() ; i++) + if (cl_prop[i].name == prop_name) + return cl_prop[i]; + // if not found, returns an empty DbDatum + return Tango::DbDatum(prop_name); +} + +//-------------------------------------------------------- +/** + * Method : E2SextupoleClass::get_default_device_property() + * Description: Return the default value for device property. + */ +//-------------------------------------------------------- +Tango::DbDatum E2SextupoleClass::get_default_device_property(std::string &prop_name) +{ + for (unsigned int i=0 ; i<dev_def_prop.size() ; i++) + if (dev_def_prop[i].name == prop_name) + return dev_def_prop[i]; + // if not found, return an empty DbDatum + return Tango::DbDatum(prop_name); +} + +//-------------------------------------------------------- +/** + * Method : E2SextupoleClass::get_default_class_property() + * Description: Return the default value for class property. + */ +//-------------------------------------------------------- +Tango::DbDatum E2SextupoleClass::get_default_class_property(std::string &prop_name) +{ + for (unsigned int i=0 ; i<cl_def_prop.size() ; i++) + if (cl_def_prop[i].name == prop_name) + return cl_def_prop[i]; + // if not found, return an empty DbDatum + return Tango::DbDatum(prop_name); +} + +//-------------------------------------------------------- +/** + * Method : E2SextupoleClass::get_class_property() + * Description: Read database to initialize class property data members. + */ +//-------------------------------------------------------- +void E2SextupoleClass::get_class_property() +{ + /*----- PROTECTED REGION ID(E2SextupoleClass::get_class_property_before) ENABLED START -----*/ + /* clang-format on */ + // Initialize class property data members + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2SextupoleClass::get_class_property_before + // Read class properties from database. + cl_prop.push_back(Tango::DbDatum("BeamEnergy")); + cl_prop.push_back(Tango::DbDatum("CalibrationPath")); + + // Call database and extract values + if (Tango::Util::instance()->_UseDb==true) + get_db_class()->get_property(cl_prop); + Tango::DbDatum def_prop; + int i = -1; + + // Try to extract BeamEnergy value + if (cl_prop[++i].is_empty()==false) cl_prop[i] >> beamEnergy; + else + { + // Check default value for BeamEnergy + def_prop = get_default_class_property(cl_prop[i].name); + if (def_prop.is_empty()==false) + { + def_prop >> beamEnergy; + cl_prop[i] << beamEnergy; + } + } + // Try to extract CalibrationPath value + if (cl_prop[++i].is_empty()==false) cl_prop[i] >> calibrationPath; + else + { + // Check default value for CalibrationPath + def_prop = get_default_class_property(cl_prop[i].name); + if (def_prop.is_empty()==false) + { + def_prop >> calibrationPath; + cl_prop[i] << calibrationPath; + } + } + /*----- PROTECTED REGION ID(E2SextupoleClass::get_class_property_after) ENABLED START -----*/ + /* clang-format on */ + // Check class property data members init + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2SextupoleClass::get_class_property_after + +} + +//-------------------------------------------------------- +/** + * Method : E2SextupoleClass::set_default_property() + * Description: Set default property (class and device) for wizard. + * For each property, add to wizard property name and description. + * If default value has been set, add it to wizard property and + * store it in a DbDatum. + */ +//-------------------------------------------------------- +void E2SextupoleClass::set_default_property() +{ + std::string prop_name; + std::string prop_desc; + std::string prop_def; + std::vector<std::string> vect_data; + + // Set Default Class Properties + prop_name = "BeamEnergy"; + prop_desc = "default electron beam energy, in GeV.\nUse to initialize all magnet istances BeamEnergy attribute."; + prop_def = "2.4"; + vect_data.clear(); + vect_data.push_back("2.4"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + cl_def_prop.push_back(data); + add_wiz_class_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_class_prop(prop_name, prop_desc); + prop_name = "CalibrationPath"; + prop_desc = "path of calibration and parameter files"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + cl_def_prop.push_back(data); + add_wiz_class_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_class_prop(prop_name, prop_desc); + + // Set Default device Properties + prop_name = "CurrentDevice"; + prop_desc = "power supply tango device name"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "Model"; + prop_desc = "corrector model (part number)"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "SerialNumber"; + prop_desc = "serial number of the magnet"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "MagnetName"; + prop_desc = "Name of magnet"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "CalibrationFileName"; + prop_desc = "name of calibration table file name"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "CalibrationPath"; + prop_desc = "path of calibration and parameter files"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "ParameterFileName"; + prop_desc = "name of auxiliary parametr file name\n(EBSmagnet compatibility)"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); +} + +//-------------------------------------------------------- +/** + * Method : E2SextupoleClass::write_class_property() + * Description: Set class description fields as property in database + */ +//-------------------------------------------------------- +void E2SextupoleClass::write_class_property() +{ + // First time, check if database used + if (Tango::Util::_UseDb == false) + return; + + Tango::DbData data; + std::string classname = get_name(); + std::string header; + + // Put title + Tango::DbDatum title("ProjectTitle"); + std::string str_title("Elettra 2.0 pure corrector magnet device"); + title << str_title; + data.push_back(title); + + // Put Description + Tango::DbDatum description("Description"); + std::vector<std::string> str_desc; + str_desc.push_back("Elettra 2.0 sextupole magnet device"); + str_desc.push_back("Use calibration table handle current/strgenght converstions."); + str_desc.push_back("The magnet device is connected to a power supply tango device , real or simulated."); + str_desc.push_back(""); + str_desc.push_back("Based on ESRF EBSmagnet concepts and libraries."); + description << str_desc; + data.push_back(description); + + // Put inheritance + Tango::DbDatum inher_datum("InheritedFrom"); + std::vector<std::string> inheritance; + inheritance.push_back("TANGO_BASE_CLASS"); + inher_datum << inheritance; + data.push_back(inher_datum); + + // Call database and and values + get_db_class()->put_property(data); +} + +//=================================================================== +// Factory methods +//=================================================================== + +//-------------------------------------------------------- +/** + * Method : E2SextupoleClass::device_factory() + * Description: Create the device object(s) + * and store them in the device list + */ +//-------------------------------------------------------- +void E2SextupoleClass::device_factory(const Tango::DevVarStringArray *devlist_ptr) +{ + /*----- PROTECTED REGION ID(E2SextupoleClass::device_factory_before) ENABLED START -----*/ +/* clang-format on */ +// Add your own code +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2SextupoleClass::device_factory_before + + // Create devices and add it into the device list + for (unsigned long i=0 ; i<devlist_ptr->length() ; i++) + { + TANGO_LOG_DEBUG << "Device name : " << (*devlist_ptr)[i].in() << std::endl; + device_list.push_back(new E2Sextupole(this, (*devlist_ptr)[i])); + } + + // Manage dynamic attributes if any + erase_dynamic_attributes(devlist_ptr, get_class_attr()->get_attr_list()); + + // Export devices to the outside world + for (unsigned long i=1 ; i<=devlist_ptr->length() ; i++) + { + // Add dynamic attributes if any + E2Sextupole *dev = static_cast<E2Sextupole *>(device_list[device_list.size()-i]); + dev->add_dynamic_attributes(); + + // Check before if database used. + if ((Tango::Util::_UseDb == true) && (Tango::Util::_FileDb == false)) + export_device(dev); + else + export_device(dev, dev->get_name().c_str()); + } + + /*----- PROTECTED REGION ID(E2SextupoleClass::device_factory_after) ENABLED START -----*/ +/* clang-format on */ +// Add your own code +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2SextupoleClass::device_factory_after +} +//-------------------------------------------------------- +/** + * Method : E2SextupoleClass::attribute_factory() + * Description: Create the attribute object(s) + * and store them in the attribute list + */ +//-------------------------------------------------------- +void E2SextupoleClass::attribute_factory(std::vector<Tango::Attr *> &att_list) +{ + /*----- PROTECTED REGION ID(E2SextupoleClass::attribute_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2SextupoleClass::attribute_factory_before + // Attribute : Strength + StrengthAttrib *strength = new StrengthAttrib(); + Tango::UserDefaultAttrProp strength_prop; + strength_prop.set_description("sextupole strength 1/m^3 ( m-3)"); + strength_prop.set_label("strength"); + strength_prop.set_unit("m-3"); + // standard_unit not set for Strength + // display_unit not set for Strength + // format not set for Strength + // max_value not set for Strength + // min_value not set for Strength + // max_alarm not set for Strength + // min_alarm not set for Strength + // max_warning not set for Strength + // min_warning not set for Strength + // delta_t not set for Strength + // delta_val not set for Strength + strength->set_default_properties(strength_prop); + // Not Polled + strength->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(strength); + + // Attribute : CorrectionStrength + CorrectionStrengthAttrib *correctionstrength = new CorrectionStrengthAttrib(); + Tango::UserDefaultAttrProp correctionstrength_prop; + // description not set for CorrectionStrength + correctionstrength_prop.set_label("correction strength"); + correctionstrength_prop.set_unit("m-3"); + // standard_unit not set for CorrectionStrength + // display_unit not set for CorrectionStrength + // format not set for CorrectionStrength + // max_value not set for CorrectionStrength + // min_value not set for CorrectionStrength + // max_alarm not set for CorrectionStrength + // min_alarm not set for CorrectionStrength + // max_warning not set for CorrectionStrength + // min_warning not set for CorrectionStrength + // delta_t not set for CorrectionStrength + // delta_val not set for CorrectionStrength + correctionstrength->set_default_properties(correctionstrength_prop); + // Not Polled + correctionstrength->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(correctionstrength); + + // Attribute : ResonanceStrength + ResonanceStrengthAttrib *resonancestrength = new ResonanceStrengthAttrib(); + Tango::UserDefaultAttrProp resonancestrength_prop; + // description not set for ResonanceStrength + resonancestrength_prop.set_label("resonance strength"); + resonancestrength_prop.set_unit("m-3"); + // standard_unit not set for ResonanceStrength + // display_unit not set for ResonanceStrength + // format not set for ResonanceStrength + // max_value not set for ResonanceStrength + // min_value not set for ResonanceStrength + // max_alarm not set for ResonanceStrength + // min_alarm not set for ResonanceStrength + // max_warning not set for ResonanceStrength + // min_warning not set for ResonanceStrength + // delta_t not set for ResonanceStrength + // delta_val not set for ResonanceStrength + resonancestrength->set_default_properties(resonancestrength_prop); + // Not Polled + resonancestrength->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(resonancestrength); + + // Attribute : Current + CurrentAttrib *current = new CurrentAttrib(); + Tango::UserDefaultAttrProp current_prop; + // description not set for Current + // label not set for Current + current_prop.set_unit("A"); + // standard_unit not set for Current + // display_unit not set for Current + // format not set for Current + // max_value not set for Current + // min_value not set for Current + // max_alarm not set for Current + // min_alarm not set for Current + // max_warning not set for Current + // min_warning not set for Current + // delta_t not set for Current + // delta_val not set for Current + current->set_default_properties(current_prop); + // Not Polled + current->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(current); + + // Attribute : BeamEnergy + BeamEnergyAttrib *beamenergy = new BeamEnergyAttrib(); + Tango::UserDefaultAttrProp beamenergy_prop; + beamenergy_prop.set_description("Electron beam energy in eV. Used to calculate magnetic rigidity in strength calculations."); + beamenergy_prop.set_label("electron beam ebergy [eV]"); + // unit not set for BeamEnergy + // standard_unit not set for BeamEnergy + // display_unit not set for BeamEnergy + // format not set for BeamEnergy + // max_value not set for BeamEnergy + // min_value not set for BeamEnergy + // max_alarm not set for BeamEnergy + // min_alarm not set for BeamEnergy + // max_warning not set for BeamEnergy + // min_warning not set for BeamEnergy + // delta_t not set for BeamEnergy + // delta_val not set for BeamEnergy + beamenergy->set_default_properties(beamenergy_prop); + // Not Polled + beamenergy->set_disp_level(Tango::EXPERT); + // Not Memorized + att_list.push_back(beamenergy); + + // Attribute : DesignStrength + DesignStrengthAttrib *designstrength = new DesignStrengthAttrib(); + Tango::UserDefaultAttrProp designstrength_prop; + designstrength_prop.set_description("sextupole design strength 1/m^3 ( m-3). The strenght reqiured by the nominal optic\nThe attribute is memorized , expert only."); + designstrength_prop.set_label("design strength"); + designstrength_prop.set_unit("m-3"); + // standard_unit not set for DesignStrength + // display_unit not set for DesignStrength + // format not set for DesignStrength + // max_value not set for DesignStrength + // min_value not set for DesignStrength + // max_alarm not set for DesignStrength + // min_alarm not set for DesignStrength + // max_warning not set for DesignStrength + // min_warning not set for DesignStrength + // delta_t not set for DesignStrength + // delta_val not set for DesignStrength + designstrength->set_default_properties(designstrength_prop); + // Not Polled + designstrength->set_disp_level(Tango::EXPERT); + designstrength->set_memorized(); + designstrength->set_memorized_init(true); + att_list.push_back(designstrength); + + + // Create a list of static attributes + create_static_attribute_list(get_class_attr()->get_attr_list()); + /*----- PROTECTED REGION ID(E2SextupoleClass::attribute_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2SextupoleClass::attribute_factory_after +} +//-------------------------------------------------------- +/** + * Method : E2SextupoleClass::pipe_factory() + * Description: Create the pipe object(s) + * and store them in the pipe list + */ +//-------------------------------------------------------- +void E2SextupoleClass::pipe_factory() +{ + /*----- PROTECTED REGION ID(E2SextupoleClass::pipe_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2SextupoleClass::pipe_factory_before + /*----- PROTECTED REGION ID(E2SextupoleClass::pipe_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2SextupoleClass::pipe_factory_after +} +//-------------------------------------------------------- +/** + * Method : E2SextupoleClass::command_factory() + * Description: Create the command object(s) + * and store them in the command list + */ +//-------------------------------------------------------- +void E2SextupoleClass::command_factory() +{ + /*----- PROTECTED REGION ID(E2SextupoleClass::command_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2SextupoleClass::command_factory_before + + + // Command Reset + ResetClass *pResetCmd = + new ResetClass("Reset", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pResetCmd); + + // Command ResetResonanceStrength + ResetResonanceStrengthClass *pResetResonanceStrengthCmd = + new ResetResonanceStrengthClass("ResetResonanceStrength", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pResetResonanceStrengthCmd); + + // Command ApplyDesignStrength + ApplyDesignStrengthClass *pApplyDesignStrengthCmd = + new ApplyDesignStrengthClass("ApplyDesignStrength", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pApplyDesignStrengthCmd); + + /*----- PROTECTED REGION ID(E2SextupoleClass::command_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2SextupoleClass::command_factory_after +} + +//=================================================================== +// Dynamic attributes related methods +//=================================================================== + +//-------------------------------------------------------- +/** + * method : E2SextupoleClass::create_static_attribute_list + * description : Create the a list of static attributes + * + * @param att_list the created attribute list + */ +//-------------------------------------------------------- +void E2SextupoleClass::create_static_attribute_list(std::vector<Tango::Attr *> &att_list) +{ + for (unsigned long i=0 ; i<att_list.size() ; i++) + { + std::string att_name(att_list[i]->get_name()); + std::transform(att_name.begin(), att_name.end(), att_name.begin(), ::tolower); + defaultAttList.push_back(att_name); + } + + TANGO_LOG_INFO << defaultAttList.size() << " attributes in default list" << std::endl; + + /*----- PROTECTED REGION ID(E2SextupoleClass::create_static_att_list) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2SextupoleClass::create_static_att_list +} + + +//-------------------------------------------------------- +/** + * method : E2SextupoleClass::erase_dynamic_attributes + * description : delete the dynamic attributes if any. + * + * @param devlist_ptr the device list pointer + * @param list of all attributes + */ +//-------------------------------------------------------- +void E2SextupoleClass::erase_dynamic_attributes(const Tango::DevVarStringArray *devlist_ptr, std::vector<Tango::Attr *> &att_list) +{ + Tango::Util *tg = Tango::Util::instance(); + + for (unsigned long i=0 ; i<devlist_ptr->length() ; i++) + { + Tango::DeviceImpl *dev_impl = tg->get_device_by_name(((std::string)(*devlist_ptr)[i]).c_str()); + E2Sextupole *dev = static_cast<E2Sextupole *> (dev_impl); + + std::vector<Tango::Attribute *> &dev_att_list = dev->get_device_attr()->get_attribute_list(); + std::vector<Tango::Attribute *>::iterator ite_att; + for (ite_att=dev_att_list.begin() ; ite_att != dev_att_list.end() ; ++ite_att) + { + std::string att_name((*ite_att)->get_name_lower()); + if ((att_name == "state") || (att_name == "status")) + continue; + std::vector<std::string>::iterator ite_str = find(defaultAttList.begin(), defaultAttList.end(), att_name); + if (ite_str == defaultAttList.end()) + { + TANGO_LOG_INFO << att_name << " is a UNWANTED dynamic attribute for device " << (*devlist_ptr)[i] << std::endl; + Tango::Attribute &att = dev->get_device_attr()->get_attr_by_name(att_name.c_str()); + dev->remove_attribute(att_list[att.get_attr_idx()], true, false); + --ite_att; + } + } + } + /*----- PROTECTED REGION ID(E2SextupoleClass::erase_dynamic_attributes) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2SextupoleClass::erase_dynamic_attributes +} + +//-------------------------------------------------------- +/** + * Method : E2SextupoleClass::get_attr_object_by_name() + * Description: returns Tango::Attr * object found by name + */ +//-------------------------------------------------------- +Tango::Attr *E2SextupoleClass::get_attr_object_by_name(std::vector<Tango::Attr *> &att_list, std::string attname) +{ + std::vector<Tango::Attr *>::iterator it; + for (it=att_list.begin() ; it<att_list.end() ; ++it) + if ((*it)->get_name()==attname) + return (*it); + // Attr does not exist + return NULL; +} + + +/*----- PROTECTED REGION ID(E2SextupoleClass::Additional Methods) ENABLED START -----*/ +/* clang-format on */ +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2SextupoleClass::Additional Methods +} // namespace diff --git a/src/E2SextupoleClass.h b/src/E2SextupoleClass.h new file mode 100644 index 0000000..7f31e3d --- /dev/null +++ b/src/E2SextupoleClass.h @@ -0,0 +1,281 @@ +/*----- PROTECTED REGION ID(E2SextupoleClass.h) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : E2SextupoleClass.h +// +// description : Include for the E2Sextupole root class. +// This class is the singleton class for +// the E2Sextupole device class. +// It contains all properties and methods which the +// E2Sextupole requires only once e.g. the commands. +// +// project : Elettra 2.0 pure corrector 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) +//============================================================================= + + +#ifndef E2SextupoleClass_H +#define E2SextupoleClass_H + +#include <tango/tango.h> +#include "E2Sextupole.h" + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2SextupoleClass.h + + +namespace E2Sextupole_ns +{ +/*----- PROTECTED REGION ID(E2SextupoleClass::classes for dynamic creation) ENABLED START -----*/ +/* clang-format on */ + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2SextupoleClass::classes for dynamic creation + +//========================================= +// Define classes for attributes +//========================================= +// Attribute Strength class definition +class StrengthAttrib: public Tango::Attr +{ +public: + StrengthAttrib():Attr("Strength", + Tango::DEV_DOUBLE, Tango::READ_WRITE) {} + ~StrengthAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<E2Sextupole *>(dev))->read_Strength(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<E2Sextupole *>(dev))->write_Strength(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<E2Sextupole *>(dev))->is_Strength_allowed(ty);} +}; + +// Attribute CorrectionStrength class definition +class CorrectionStrengthAttrib: public Tango::Attr +{ +public: + CorrectionStrengthAttrib():Attr("CorrectionStrength", + Tango::DEV_DOUBLE, Tango::READ_WRITE) {} + ~CorrectionStrengthAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<E2Sextupole *>(dev))->read_CorrectionStrength(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<E2Sextupole *>(dev))->write_CorrectionStrength(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<E2Sextupole *>(dev))->is_CorrectionStrength_allowed(ty);} +}; + +// Attribute ResonanceStrength class definition +class ResonanceStrengthAttrib: public Tango::Attr +{ +public: + ResonanceStrengthAttrib():Attr("ResonanceStrength", + Tango::DEV_DOUBLE, Tango::READ_WRITE) {} + ~ResonanceStrengthAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<E2Sextupole *>(dev))->read_ResonanceStrength(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<E2Sextupole *>(dev))->write_ResonanceStrength(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<E2Sextupole *>(dev))->is_ResonanceStrength_allowed(ty);} +}; + +// Attribute Current class definition +class CurrentAttrib: public Tango::Attr +{ +public: + CurrentAttrib():Attr("Current", + Tango::DEV_DOUBLE, Tango::READ_WRITE) {} + ~CurrentAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<E2Sextupole *>(dev))->read_Current(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<E2Sextupole *>(dev))->write_Current(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<E2Sextupole *>(dev))->is_Current_allowed(ty);} +}; + +// Attribute BeamEnergy class definition +class BeamEnergyAttrib: public Tango::Attr +{ +public: + BeamEnergyAttrib():Attr("BeamEnergy", + Tango::DEV_DOUBLE, Tango::READ_WRITE) {} + ~BeamEnergyAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<E2Sextupole *>(dev))->read_BeamEnergy(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<E2Sextupole *>(dev))->write_BeamEnergy(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<E2Sextupole *>(dev))->is_BeamEnergy_allowed(ty);} +}; + +// Attribute DesignStrength class definition +class DesignStrengthAttrib: public Tango::Attr +{ +public: + DesignStrengthAttrib():Attr("DesignStrength", + Tango::DEV_DOUBLE, Tango::READ_WRITE) {} + ~DesignStrengthAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<E2Sextupole *>(dev))->read_DesignStrength(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<E2Sextupole *>(dev))->write_DesignStrength(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<E2Sextupole *>(dev))->is_DesignStrength_allowed(ty);} +}; + + +//========================================= +// Define classes for commands +//========================================= +// Command Reset class definition +class ResetClass : public Tango::Command +{ +public: + ResetClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(cmd_name,in,out,in_desc,out_desc, level) {} + + ResetClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(cmd_name,in,out) {} + ~ResetClass() {} + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<E2Sextupole *>(dev))->is_Reset_allowed(any);} +}; + +// Command ResetResonanceStrength class definition +class ResetResonanceStrengthClass : public Tango::Command +{ +public: + ResetResonanceStrengthClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(cmd_name,in,out,in_desc,out_desc, level) {} + + ResetResonanceStrengthClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(cmd_name,in,out) {} + ~ResetResonanceStrengthClass() {} + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<E2Sextupole *>(dev))->is_ResetResonanceStrength_allowed(any);} +}; + +// Command ApplyDesignStrength class definition +class ApplyDesignStrengthClass : public Tango::Command +{ +public: + ApplyDesignStrengthClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(cmd_name,in,out,in_desc,out_desc, level) {} + + ApplyDesignStrengthClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(cmd_name,in,out) {} + ~ApplyDesignStrengthClass() {} + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<E2Sextupole *>(dev))->is_ApplyDesignStrength_allowed(any);} +}; + + +/** + * The E2SextupoleClass singleton definition + */ + +#ifdef _TG_WINDOWS_ +class __declspec(dllexport) E2SextupoleClass : public Tango::DeviceClass +#else +class E2SextupoleClass : public Tango::DeviceClass +#endif +{ + /*----- PROTECTED REGION ID(E2SextupoleClass::Additional DServer data members) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2SextupoleClass::Additional DServer data members + + public: + // Class properties data members + // BeamEnergy: default electron beam energy, in GeV. + // Use to initialize all magnet istances BeamEnergy attribute. + Tango::DevDouble beamEnergy; + // CalibrationPath: path of calibration and parameter files + std::string calibrationPath; + // write class properties data members + Tango::DbData cl_prop; + Tango::DbData cl_def_prop; + Tango::DbData dev_def_prop; + // Method prototypes + static E2SextupoleClass *init(const char *); + static E2SextupoleClass *instance(); + ~E2SextupoleClass(); + Tango::DbDatum get_class_property(std::string &); + Tango::DbDatum get_default_device_property(std::string &); + Tango::DbDatum get_default_class_property(std::string &); + + protected: + E2SextupoleClass(std::string &); + static E2SextupoleClass *_instance; + void command_factory(); + void attribute_factory(std::vector<Tango::Attr *> &); + void pipe_factory(); + void write_class_property(); + void set_default_property(); + void get_class_property(); + std::string get_cvstag(); + std::string get_cvsroot(); + + private: + void device_factory(TANGO_UNUSED(const Tango::DevVarStringArray *)); + void create_static_attribute_list(std::vector<Tango::Attr *> &); + void erase_dynamic_attributes(const Tango::DevVarStringArray *,std::vector<Tango::Attr *> &); + std::vector<std::string> defaultAttList; + Tango::Attr *get_attr_object_by_name(std::vector<Tango::Attr *> &att_list, std::string attname); +}; + +} // End of namespace + +#endif // E2Sextupole_H diff --git a/src/E2SextupoleStateMachine.cpp b/src/E2SextupoleStateMachine.cpp new file mode 100644 index 0000000..26ca1df --- /dev/null +++ b/src/E2SextupoleStateMachine.cpp @@ -0,0 +1,242 @@ +/*----- PROTECTED REGION ID(E2SextupoleStateMachine.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : E2SextupoleStateMachine.cpp +// +// description : State machine file for the E2Sextupole class +// +// project : Elettra 2.0 pure corrector 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" + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Sextupole::E2SextupoleStateMachine.cpp + +//================================================================ +// States | Description +//================================================================ + + +namespace E2Sextupole_ns +{ +//================================================= +// Attributes Allowed Methods +//================================================= + +//-------------------------------------------------------- +/** + * Method : E2Sextupole::is_Strength_allowed() + * Description: Execution allowed for Strength attribute + */ +//-------------------------------------------------------- +bool E2Sextupole::is_Strength_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for Strength attribute in Write access. + /*----- PROTECTED REGION ID(E2Sextupole::StrengthStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::StrengthStateAllowed_WRITE + + // Not any excluded states for Strength attribute in read access. + /*----- PROTECTED REGION ID(E2Sextupole::StrengthStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::StrengthStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Sextupole::is_CorrectionStrength_allowed() + * Description: Execution allowed for CorrectionStrength attribute + */ +//-------------------------------------------------------- +bool E2Sextupole::is_CorrectionStrength_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for CorrectionStrength attribute in Write access. + /*----- PROTECTED REGION ID(E2Sextupole::CorrectionStrengthStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::CorrectionStrengthStateAllowed_WRITE + + // Not any excluded states for CorrectionStrength attribute in read access. + /*----- PROTECTED REGION ID(E2Sextupole::CorrectionStrengthStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::CorrectionStrengthStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Sextupole::is_ResonanceStrength_allowed() + * Description: Execution allowed for ResonanceStrength attribute + */ +//-------------------------------------------------------- +bool E2Sextupole::is_ResonanceStrength_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for ResonanceStrength attribute in Write access. + /*----- PROTECTED REGION ID(E2Sextupole::ResonanceStrengthStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::ResonanceStrengthStateAllowed_WRITE + + // Not any excluded states for ResonanceStrength attribute in read access. + /*----- PROTECTED REGION ID(E2Sextupole::ResonanceStrengthStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::ResonanceStrengthStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Sextupole::is_Current_allowed() + * Description: Execution allowed for Current attribute + */ +//-------------------------------------------------------- +bool E2Sextupole::is_Current_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for Current attribute in Write access. + /*----- PROTECTED REGION ID(E2Sextupole::CurrentStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::CurrentStateAllowed_WRITE + + // Not any excluded states for Current attribute in read access. + /*----- PROTECTED REGION ID(E2Sextupole::CurrentStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::CurrentStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Sextupole::is_BeamEnergy_allowed() + * Description: Execution allowed for BeamEnergy attribute + */ +//-------------------------------------------------------- +bool E2Sextupole::is_BeamEnergy_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for BeamEnergy attribute in Write access. + /*----- PROTECTED REGION ID(E2Sextupole::BeamEnergyStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::BeamEnergyStateAllowed_WRITE + + // Not any excluded states for BeamEnergy attribute in read access. + /*----- PROTECTED REGION ID(E2Sextupole::BeamEnergyStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::BeamEnergyStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Sextupole::is_DesignStrength_allowed() + * Description: Execution allowed for DesignStrength attribute + */ +//-------------------------------------------------------- +bool E2Sextupole::is_DesignStrength_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for DesignStrength attribute in Write access. + /*----- PROTECTED REGION ID(E2Sextupole::DesignStrengthStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::DesignStrengthStateAllowed_WRITE + + // Not any excluded states for DesignStrength attribute in read access. + /*----- PROTECTED REGION ID(E2Sextupole::DesignStrengthStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::DesignStrengthStateAllowed_READ + return true; +} + + +//================================================= +// Commands Allowed Methods +//================================================= + +//-------------------------------------------------------- +/** + * Method : E2Sextupole::is_Reset_allowed() + * Description: Execution allowed for Reset attribute + */ +//-------------------------------------------------------- +bool E2Sextupole::is_Reset_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for Reset command. + /*----- PROTECTED REGION ID(E2Sextupole::ResetStateAllowed) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::ResetStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Sextupole::is_ResetResonanceStrength_allowed() + * Description: Execution allowed for ResetResonanceStrength attribute + */ +//-------------------------------------------------------- +bool E2Sextupole::is_ResetResonanceStrength_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for ResetResonanceStrength command. + /*----- PROTECTED REGION ID(E2Sextupole::ResetResonanceStrengthStateAllowed) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::ResetResonanceStrengthStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Sextupole::is_ApplyDesignStrength_allowed() + * Description: Execution allowed for ApplyDesignStrength attribute + */ +//-------------------------------------------------------- +bool E2Sextupole::is_ApplyDesignStrength_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for ApplyDesignStrength command. + /*----- PROTECTED REGION ID(E2Sextupole::ApplyDesignStrengthStateAllowed) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Sextupole::ApplyDesignStrengthStateAllowed + return true; +} + + +/*----- PROTECTED REGION ID(E2Sextupole::E2SextupoleStateAllowed.AdditionalMethods) ENABLED START -----*/ +/* clang-format on */ +// Additional Methods +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Sextupole::E2SextupoleStateAllowed.AdditionalMethods + +} // End of namespace diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..745a89e --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,89 @@ +/*----- PROTECTED REGION ID(E2Sextupole::main.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : main.cpp +// +// description : C++ source for the E2Sextupole device server main. +// The main rule is to initialise (and create) the Tango +// system and to create the DServerClass singleton. +// The main should be the same for every Tango device server. +// +// project : Elettra 2.0 pure corrector 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 <tango/tango.h> + +// Check if crash reporting is used. +#if defined(ENABLE_CRASH_REPORT) +# include <crashreporting/crash_report.h> +#else +# define DECLARE_CRASH_HANDLER +# define INSTALL_CRASH_HANDLER +#endif + +DECLARE_CRASH_HANDLER + +int main(int argc,char *argv[]) +{ + INSTALL_CRASH_HANDLER + Tango::Util *tg; + try + { + // Initialise the device server + //---------------------------------------- + tg = Tango::Util::init(argc,argv); + + // Create the device server singleton + // which will create everything + //---------------------------------------- + tg->server_init(false); + + // Run the endless loop + //---------------------------------------- + std::cout << "Ready to accept request" << std::endl; + tg->server_run(); + } + catch (std::bad_alloc &) + { + std::cout << "Can't allocate memory to store device object !!!" << std::endl; + std::cout << "Exiting" << std::endl; + } + catch (CORBA::Exception &e) + { + Tango::Except::print_exception(e); + + std::cout << "Received a CORBA_Exception" << std::endl; + std::cout << "Exiting" << std::endl; + } + + if(tg) + { + tg->server_cleanup(); + } + return(0); +} + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Sextupole::main.cpp -- GitLab From 38a76b66dd32de4ce6cac1a56da0a3c247f191bc Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Thu, 3 Oct 2024 16:55:46 +0200 Subject: [PATCH 2/6] handle correctly initial setting of design strength --- src/E2Sextupole.cpp | 63 +++++++++++++++++++++++++++++---------------- src/E2Sextupole.h | 4 ++- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/E2Sextupole.cpp b/src/E2Sextupole.cpp index 1d78fec..f45670e 100644 --- a/src/E2Sextupole.cpp +++ b/src/E2Sextupole.cpp @@ -170,7 +170,7 @@ void E2Sextupole::init_device() set_state(Tango::INIT); set_status("Init"); attr_Current_read = new Tango::DevDouble[1]; - first_read = true; + design_strength_initialized = false; /*----- PROTECTED REGION END -----*/ // E2Sextupole::init_device_before @@ -241,21 +241,9 @@ void E2Sextupole::init_device() cursetAtt = &(get_device_attr()->get_w_attr_by_name("Current")); init_strengths(); - // register callaback for current + // register callback for event subscription with a delay so the memorized variables are read dn updated from DB AFTER init_device() exit - try{ - current_cb = new CurrentEventCallback(this); - current_event_id = current_dev->subscribe_event("current",Tango::CHANGE_EVENT,current_cb); - current_set_event_id = current_dev->subscribe_event("currentSet",Tango::CHANGE_EVENT,current_cb); - state_event_id = current_dev->subscribe_event("State",Tango::CHANGE_EVENT,current_cb); - } - catch(Tango::DevFailed &ex){ - 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; - } + //delayed_subscribe(subscribeDelay); /*----- PROTECTED REGION END -----*/ // E2Sextupole::init_device } @@ -762,6 +750,11 @@ void E2Sextupole::write_DesignStrength(Tango::WAttribute &attr) // Add your own code /* clang-format off */ *attr_DesignStrength_read = w_val; + if (design_strength_initialized == false){ + subscribe_events(); + design_strength_initialized = true; + INFO_STREAM << "w design strength" << *attr_DesignStrength_read; + } /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_DesignStrength } @@ -925,18 +918,17 @@ void E2Sextupole::update_values(void) attr_CorrectionStrength_read[0] = attr_Strength_read[0] - attr_ResonanceStrength_read[0]; */ //---------------------------------------------- - if (first_read){ - INFO_STREAM << *attr_DesignStrength_read ; - first_read = false; - } - //INFO_STREAM << *attr_DesignStrength_read ; + + + //INFO_STREAM << "design strength: " << *attr_DesignStrength_read; + std::vector<Tango::DevDouble> read_curr; std::vector<Tango::DevDouble> read_strength; 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_ResonanceStrength_read[0] = attr_Strength_read[0] - wValCorrStrength; - attr_CorrectionStrength_read[0] = attr_Strength_read[0] - wValResStrength; + //attr_ResonanceStrength_read[0] = attr_Strength_read[0] - wValCorrStrength; + attr_CorrectionStrength_read[0] = attr_Strength_read[0] -( attr_DesignStrength_read[0] + attr_ResonanceStrength_read[0]); //handle state - status switch (get_state()) { @@ -961,6 +953,33 @@ void E2Sextupole::update_values(void) } +void E2Sextupole::subscribe_events(void) +{ + try{ + current_cb = new CurrentEventCallback(this); + current_event_id = current_dev->subscribe_event("current",Tango::CHANGE_EVENT,current_cb); + current_set_event_id = current_dev->subscribe_event("currentSet",Tango::CHANGE_EVENT,current_cb); + state_event_id = current_dev->subscribe_event("State",Tango::CHANGE_EVENT,current_cb); + } + catch(Tango::DevFailed &ex){ + 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; + } +} +/* 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 +} +*/ //------------------------------------------------------------ //------------------------------------------------------------ CurrentEventCallback::CurrentEventCallback(E2Sextupole* sext) //callback constructor diff --git a/src/E2Sextupole.h b/src/E2Sextupole.h index 00a9bdd..a2c777c 100644 --- a/src/E2Sextupole.h +++ b/src/E2Sextupole.h @@ -93,11 +93,11 @@ class E2Sextupole : public TANGO_BASE_CLASS Tango::WAttribute *resonanceAtt; std::vector<double> set_current; //the actual set point of the current (from the power supply) used for strength calculations std::vector<double> set_strength; //the strength set point + bool design_strength_initialized; //true whe design strenfght has been called at least one , first call is to init valude from DB public: omni_mutex iomutex; //guard for event and write interference Tango::DevDouble wValCorrStrength; //last CorrectionStrength write value Tango::DevDouble wValResStrength; //last ResonanceStrength write value - bool first_read; /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::Data Members @@ -315,6 +315,8 @@ public: void set_current_write(const double& curr); void update_values(void); //update internal calculated values void init_strengths(void); // initialize strengths from power supply values + void subscribe_events(void); //subcribe events to power supply + //void delayed_subscribe(int delayedMs); /* clang-format off */ /*----- PROTECTED REGION END -----*/ // E2Sextupole::Additional Method prototypes }; -- GitLab From 679cf8484c64c706accf652383eb7a19fb51165a Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Fri, 4 Oct 2024 17:45:54 +0200 Subject: [PATCH 3/6] seprante handling of attribute changes, improvements --- TODO | 2 + src/E2Sextupole.cpp | 132 ++++++++++++++++++++++++++++---------------- src/E2Sextupole.h | 4 +- 3 files changed, 90 insertions(+), 48 deletions(-) create mode 100644 TODO diff --git a/TODO b/TODO new file mode 100644 index 0000000..2972583 --- /dev/null +++ b/TODO @@ -0,0 +1,2 @@ +check and fix ResonanceStrength handling +fix units \ No newline at end of file diff --git a/src/E2Sextupole.cpp b/src/E2Sextupole.cpp index f45670e..eea8809 100644 --- a/src/E2Sextupole.cpp +++ b/src/E2Sextupole.cpp @@ -211,7 +211,7 @@ void E2Sextupole::init_device() } //create MagnetModel::Sextupole - handles calibration tables and interpolations - // we do not use teh EBS shehme with global proprties... yet + // we do not use teh EBS shehme with global properties... yet //TODO: fix/determine format and handling of Elettra 2.0 calibrations sextupole = nullptr; @@ -239,11 +239,6 @@ void E2Sextupole::init_device() correctionAtt = &get_device_attr()->get_w_attr_by_name("CorrectionStrength"); resonanceAtt = &get_device_attr()->get_w_attr_by_name("ResonanceStrength"); cursetAtt = &(get_device_attr()->get_w_attr_by_name("Current")); - init_strengths(); - - // register callback for event subscription with a delay so the memorized variables are read dn updated from DB AFTER init_device() exit - - //delayed_subscribe(subscribeDelay); /*----- PROTECTED REGION END -----*/ // E2Sextupole::init_device } @@ -555,7 +550,7 @@ void E2Sextupole::write_CorrectionStrength(Tango::WAttribute &attr) omni_mutex_lock guardio(iomutex); Tango::DevDouble newStrength; //resonanceAtt->get_write_value(_resStrength); - newStrength = w_val + wValResStrength; + newStrength = w_val + wValResStrength + *attr_DesignStrength_read; std::vector<double> req_strength; std::vector<double> curr_out; req_strength.push_back(newStrength); @@ -565,6 +560,7 @@ void E2Sextupole::write_CorrectionStrength(Tango::WAttribute &attr) wValCorrStrength = w_val; set_strength[0] = newStrength; strengthAtt->set_write_value(set_strength[0]); + /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_CorrectionStrength } //-------------------------------------------------------- @@ -613,7 +609,7 @@ void E2Sextupole::write_ResonanceStrength(Tango::WAttribute &attr) */ omni_mutex_lock guardio(iomutex); Tango::DevDouble newStrength; - newStrength = w_val + wValCorrStrength; + newStrength = w_val + wValCorrStrength + *attr_DesignStrength_read; std::vector<double> req_strength; std::vector<double> curr_out; req_strength.push_back(newStrength); @@ -621,6 +617,7 @@ void E2Sextupole::write_ResonanceStrength(Tango::WAttribute &attr) Tango::DeviceAttribute watt("Current", curr_out[0]); current_dev->write_attribute(watt); wValResStrength = w_val; + //*attr_ResonanceStrength_read = w_val; set_strength[0] = newStrength; strengthAtt->set_write_value(set_strength[0]); /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_ResonanceStrength @@ -751,9 +748,9 @@ void E2Sextupole::write_DesignStrength(Tango::WAttribute &attr) /* clang-format off */ *attr_DesignStrength_read = w_val; if (design_strength_initialized == false){ - subscribe_events(); design_strength_initialized = true; - INFO_STREAM << "w design strength" << *attr_DesignStrength_read; + init_strengths(); + subscribe_events(); } /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_DesignStrength } @@ -810,6 +807,7 @@ void E2Sextupole::reset_resonance_strength() /* clang-format off */ //force to 0 resonance strength omni_mutex_lock guardio(iomutex); + /* Tango::DevDouble newStrength; newStrength = wValCorrStrength; std::vector<double> req_strength; @@ -818,9 +816,12 @@ void E2Sextupole::reset_resonance_strength() sextupole->compute_currents(magnet_rigidity, req_strength, curr_out); Tango::DeviceAttribute watt("Current", curr_out[0]); current_dev->write_attribute(watt); + */ + wValCorrStrength += wValResStrength; wValResStrength = 0.0; - set_strength[0] = newStrength; - strengthAtt->set_write_value(set_strength[0]); + //set_strength[0] = newStrength; + //strengthAtt->set_write_value(set_strength[0]); + correctionAtt->set_write_value(wValCorrStrength); resonanceAtt->set_write_value(0.0); /*----- PROTECTED REGION END -----*/ // E2Sextupole::reset_resonance_strength } @@ -877,7 +878,7 @@ void E2Sextupole::set_current_write(const double& curr) set_current[0] = curr; } // ------------------------------------------------------------ -void E2Sextupole::init_strengths(void) // initialize strengths from power supply value +void E2Sextupole::init_strengths(void) // initialize strengths from power supply value TODO: separate read and set values { Tango::DeviceAttribute da; try { @@ -886,7 +887,7 @@ void E2Sextupole::init_strengths(void) // initialize strengths from power supply da >> outval; std::vector<Tango::DevDouble> _current; std::vector<Tango::DevDouble> _strength; - _current.push_back(outval[1]); + _current.push_back(outval[1]); //use set value of current sextupole->compute_strengths(magnet_rigidity_inv, _current, _strength); cursetAtt->set_write_value(_current[0]); @@ -895,10 +896,11 @@ void E2Sextupole::init_strengths(void) // initialize strengths from power supply strengthAtt->set_write_value(_strength[0]); *attr_Strength_read = _strength[0]; set_strength[0] = _strength[0]; + Tango::DevDouble corr = _strength[0] - *attr_DesignStrength_read; - correctionAtt->set_write_value(_strength[0]); - *attr_CorrectionStrength_read = _strength[0]; - wValCorrStrength = _strength[0]; + correctionAtt->set_write_value(corr); + *attr_CorrectionStrength_read = corr; + wValCorrStrength = corr; resonanceAtt->set_write_value(0.0); // start with resonance strength always at 0! *attr_ResonanceStrength_read = 0.0; @@ -909,28 +911,48 @@ void E2Sextupole::init_strengths(void) // initialize strengths from power supply } } //------------------------------------------------------------ -void E2Sextupole::update_values(void) +// handle changes poer poer supply read current (actula current) +void E2Sextupole::update_values_read(void) { - /* - sextupole->compute_strengths(magnet_rigidity_inv, set_current, set_strength); - attr_Strength_read[0] = set_strength[0]; - attr_ResonanceStrength_read[0] = attr_Strength_read[0] - wValCorrStrength; - attr_CorrectionStrength_read[0] = attr_Strength_read[0] - attr_ResonanceStrength_read[0]; - */ - //---------------------------------------------- - - - //INFO_STREAM << "design strength: " << *attr_DesignStrength_read; - + if (isnan(*attr_Current_read)){ //handle error + attr_Strength_read[0] = NAN; + return; + } + //INFO_STREAM << "update values read"; 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_ResonanceStrength_read[0] = attr_Strength_read[0] - wValCorrStrength; attr_CorrectionStrength_read[0] = attr_Strength_read[0] -( attr_DesignStrength_read[0] + attr_ResonanceStrength_read[0]); +} +//------------------------------------------------------------ +// hndle change of write set point of power supply cunnrent +void E2Sextupole::update_values_write(void) +{ + if (isnan(*attr_Current_read)){ //handle error + attr_Strength_read[0] = NAN; + return; + } + + INFO_STREAM << "update values write"; + std::vector<Tango::DevDouble> read_curr; + std::vector<Tango::DevDouble> read_strength; + omni_mutex_lock guardio(iomutex); + read_curr.push_back(set_current[0]); //must use the write value + sextupole->compute_strengths(magnet_rigidity_inv, read_curr, read_strength); + wValCorrStrength = read_strength[0] - (wValResStrength + *attr_DesignStrength_read); + correctionAtt->set_write_value(wValCorrStrength); +} + +//------------------------------------------------------------ +// handel che of power supply 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"); @@ -988,27 +1010,43 @@ CurrentEventCallback::CurrentEventCallback(E2Sextupole* sext) //callback constru } void CurrentEventCallback::push_event(Tango::EventData* ev) //callback core method { + bool update_read = false; + bool update_write = false; + bool update_state = false; if (ev->err) { - //TODO hanlde error + //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(); 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") *(ev->attr_value) >> *(e2_sext->attr_Current_read); - if(attrname == "currentset"){ - Tango::DevDouble newcurr; - *(ev->attr_value) >> newcurr; - e2_sext->set_current_write(newcurr); - } - if(attrname == "state") { - Tango::DevState st; - *(ev->attr_value) >> st; - e2_sext->set_state(st); + { + 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") { + *(ev->attr_value) >> *(e2_sext->attr_Current_read); + update_read = true; + } + if (attrname == "currentset") { + Tango::DevDouble newcurr; + *(ev->attr_value) >> newcurr; + e2_sext->set_current_write(newcurr); + update_write = true; + } + if (attrname == "state") { + Tango::DevState st; + *(ev->attr_value) >> st; + e2_sext->set_state(st); + update_state = true; + } } - e2_sext->update_values(); + if (update_read) e2_sext->update_values_read(); + if (update_write) e2_sext->update_values_write(); + if (update_state) e2_sext->update_values_state(); } /*----- PROTECTED REGION END -----*/ // E2Sextupole::namespace_ending diff --git a/src/E2Sextupole.h b/src/E2Sextupole.h index a2c777c..a938bda 100644 --- a/src/E2Sextupole.h +++ b/src/E2Sextupole.h @@ -313,7 +313,9 @@ public: // Additional Method prototypes void calc_rigidity(const double& energy); void set_current_write(const double& curr); - void update_values(void); //update internal calculated values + void update_values_write(void); //update internal calculated values when current write value is updated; + void update_values_read(void); //update internal calculated values when current read value is updated; + void update_values_state(void); //update internal calculated values when power supply state is updated; void init_strengths(void); // initialize strengths from power supply values void subscribe_events(void); //subcribe events to power supply //void delayed_subscribe(int delayedMs); -- GitLab From fbfd5fd984c05a5dd96b58d32a7e75d96027efdf Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Mon, 4 Nov 2024 11:23:50 +0100 Subject: [PATCH 4/6] add test configuration --- doc/Class.res | 11 ++++++++++ doc/test.res | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 doc/Class.res create mode 100644 doc/test.res diff --git a/doc/Class.res b/doc/Class.res new file mode 100644 index 0000000..652742d --- /dev/null +++ b/doc/Class.res @@ -0,0 +1,11 @@ +CLASS/E2Sextupole->CalibrationPath: "/homelocal/claudio/src/gitlab/dt/machine/calibration/magnetmodel" +CLASS/E2Sextupole->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." +CLASS/E2Sextupole->InheritedFrom: TANGO_BASE_CLASS +CLASS/E2Sextupole->ProjectTitle: "Elettra 2.0 pure corrector magnet device" + +# CLASS E2Sextupole attribute properties + diff --git a/doc/test.res b/doc/test.res new file mode 100644 index 0000000..91bd0a8 --- /dev/null +++ b/doc/test.res @@ -0,0 +1,56 @@ +# +# Resource backup , created Fri Oct 18 15:37:19 CEST 2024 +# + +#--------------------------------------------------------- +# SERVER e2sextupole-srv/test, E2Sextupole device declaration +#--------------------------------------------------------- + +e2sextupole-srv/test/DEVICE/E2Sextupole: "test/magnet/s16",\ + "test/magnet/s20" + + +# --- test/magnet/s16 properties + +test/magnet/s16->CalibrationFileName: Strength.csv +test/magnet/s16->CurrentDevice: "test/power_supply/pss16" +test/magnet/s16->MagnetName: 0 +test/magnet/s16->Model: no_relevant +test/magnet/s16->ParameterFileName: MAG_params.csv +test/magnet/s16->SerialNumber: 1 +test/magnet/s16->__SubDevices: "test/power_supply/pss16",\ + "dserver/simulatede2ps-srv/test" + +# --- test/magnet/s16 attribute properties + + +# --- test/magnet/s20 properties + +test/magnet/s20->CalibrationFileName: Strength.csv +test/magnet/s20->CurrentDevice: "test/power_supply/pss20" +test/magnet/s20->MagnetName: 0 +test/magnet/s20->Model: not_relevant +test/magnet/s20->ParameterFileName: MAG_params.csv +test/magnet/s20->SerialNumber: 1 +test/magnet/s20->__SubDevices: "test/power_supply/pss20",\ + "dserver/simulatede2ps-srv/test" + +# --- test/magnet/s20 attribute properties + + +#--------------------------------------------------------- +# CLASS E2Sextupole properties +#--------------------------------------------------------- + +CLASS/E2Sextupole->CalibrationPath: "/homelocal/claudio/src/gitlab/dt/machine/calibration/magnetmodel" +CLASS/E2Sextupole->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." +CLASS/E2Sextupole->InheritedFrom: TANGO_BASE_CLASS +CLASS/E2Sextupole->ProjectTitle: "Elettra 2.0 pure corrector magnet device" + +# CLASS E2Sextupole attribute properties + + -- GitLab From 22bb1464c73dd1520d34cf5d319b45cefd1bb636 Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Mon, 4 Nov 2024 14:30:13 +0100 Subject: [PATCH 5/6] fix hadling of DesignStrength --- src/E2Sextupole.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/E2Sextupole.cpp b/src/E2Sextupole.cpp index eea8809..4be02d1 100644 --- a/src/E2Sextupole.cpp +++ b/src/E2Sextupole.cpp @@ -747,11 +747,12 @@ void E2Sextupole::write_DesignStrength(Tango::WAttribute &attr) // Add your own code /* clang-format off */ *attr_DesignStrength_read = w_val; - if (design_strength_initialized == false){ + 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 } -- GitLab From e0b88a9563adf71a32c5ffc075b4044822c5a680 Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Tue, 28 Jan 2025 16:32:01 +0100 Subject: [PATCH 6/6] fix resonance strength, clarify and fix ResetResonanceStrength command --- TODO | 1 - src/E2Sextupole.cpp | 22 +++++++--------------- src/E2Sextupole.h | 2 +- src/E2Sextupole.xmi | 2 +- src/main.cpp | 2 +- 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/TODO b/TODO index 2972583..4aa68f8 100644 --- a/TODO +++ b/TODO @@ -1,2 +1 @@ -check and fix ResonanceStrength handling fix units \ No newline at end of file diff --git a/src/E2Sextupole.cpp b/src/E2Sextupole.cpp index 4be02d1..b29f69f 100644 --- a/src/E2Sextupole.cpp +++ b/src/E2Sextupole.cpp @@ -617,7 +617,7 @@ void E2Sextupole::write_ResonanceStrength(Tango::WAttribute &attr) Tango::DeviceAttribute watt("Current", curr_out[0]); current_dev->write_attribute(watt); wValResStrength = w_val; - //*attr_ResonanceStrength_read = w_val; + *attr_ResonanceStrength_read = w_val; set_strength[0] = newStrength; strengthAtt->set_write_value(set_strength[0]); /*----- PROTECTED REGION END -----*/ // E2Sextupole::write_ResonanceStrength @@ -793,7 +793,7 @@ void E2Sextupole::reset() //-------------------------------------------------------- /** * Command ResetResonanceStrength related method - * Description: Reset ResonanceStrength to 0 + * Description: Transfer ResonanceStranght to CorrectionStrength and set ResonanceStrength to 0. Strngth is not modified * */ //-------------------------------------------------------- @@ -806,24 +806,16 @@ void E2Sextupole::reset_resonance_strength() // Add your own code /* clang-format off */ - //force to 0 resonance strength + //transfer resonance strength to correction strength and than force to 0 resonance strength omni_mutex_lock guardio(iomutex); - /* - Tango::DevDouble newStrength; - newStrength = wValCorrStrength; - 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]); - current_dev->write_attribute(watt); - */ + wValCorrStrength += wValResStrength; wValResStrength = 0.0; - //set_strength[0] = newStrength; - //strengthAtt->set_write_value(set_strength[0]); + correctionAtt->set_write_value(wValCorrStrength); + *attr_CorrectionStrength_read = wValCorrStrength; resonanceAtt->set_write_value(0.0); + *attr_ResonanceStrength_read = 0.0; /*----- PROTECTED REGION END -----*/ // E2Sextupole::reset_resonance_strength } //-------------------------------------------------------- diff --git a/src/E2Sextupole.h b/src/E2Sextupole.h index a938bda..3b12b3a 100644 --- a/src/E2Sextupole.h +++ b/src/E2Sextupole.h @@ -286,7 +286,7 @@ public: virtual bool is_Reset_allowed(const CORBA::Any &any); /** * Command ResetResonanceStrength related method - * Description: Reset ResonanceStrength to 0 + * Description: Transfer ResonanceStranght to CorrectionStrength and set ResonanceStrength to 0. Strngth is not modified * */ virtual void reset_resonance_strength(); diff --git a/src/E2Sextupole.xmi b/src/E2Sextupole.xmi index 0a7dfe9..9ea46d0 100644 --- a/src/E2Sextupole.xmi +++ b/src/E2Sextupole.xmi @@ -75,7 +75,7 @@ </argout> <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> </commands> - <commands name="ResetResonanceStrength" description="Reset ResonanceStrength to 0" execMethod="reset_resonance_strength" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <commands name="ResetResonanceStrength" description="Transfer ResonanceStranght to CorrectionStrength and set ResonanceStrength to 0. Strngth is not modified" execMethod="reset_resonance_strength" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> <argin description=""> <type xsi:type="pogoDsl:VoidType"/> </argin> diff --git a/src/main.cpp b/src/main.cpp index 745a89e..f5f721e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,7 +48,7 @@ DECLARE_CRASH_HANDLER int main(int argc,char *argv[]) { INSTALL_CRASH_HANDLER - Tango::Util *tg; + Tango::Util *tg = nullptr; try { // Initialise the device server -- GitLab