From c15c47e5729f2636cd70c829fb0aaa17b3e4bf2a Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Wed, 9 Oct 2024 16:06:15 +0200 Subject: [PATCH 1/7] imported and modified from e2sextupole --- .gitignore | 9 + LICENSE | 674 +++++++++++++++++++ Makefile | 4 + README.md | 93 +-- TODO | 2 + src/ClassFactory.cpp | 53 ++ src/E2Quadrupole.cpp | 1053 ++++++++++++++++++++++++++++++ src/E2Quadrupole.h | 342 ++++++++++ src/E2Quadrupole.xmi | 146 +++++ src/E2QuadrupoleClass.cpp | 873 +++++++++++++++++++++++++ src/E2QuadrupoleClass.h | 281 ++++++++ src/E2QuadrupoleStateMachine.cpp | 242 +++++++ src/main.cpp | 89 +++ 13 files changed, 3771 insertions(+), 90 deletions(-) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 TODO create mode 100644 src/ClassFactory.cpp create mode 100644 src/E2Quadrupole.cpp create mode 100644 src/E2Quadrupole.h create mode 100644 src/E2Quadrupole.xmi create mode 100644 src/E2QuadrupoleClass.cpp create mode 100644 src/E2QuadrupoleClass.h create mode 100644 src/E2QuadrupoleStateMachine.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/LICENSE b/LICENSE new file mode 100644 index 0000000..98a3700 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + E2Sextupole + Copyright (C) 2024 dt / ds + + This program 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. + + This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) 2024 dt / ds + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<https://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<https://www.gnu.org/licenses/why-not-lgpl.html>. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..919f763 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +NAME_SRV = e2quadrupole-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 7fba3d2..1e70059 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,6 @@ # E2Quadrupole +Elettra 2.0 quadrupole 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/e2quadrupole.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.elettra.eu/dt/ds/e2quadrupole/-/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/) -- [ ] [Set auto-merge](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!). Thanks 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/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/ClassFactory.cpp b/src/ClassFactory.cpp new file mode 100644 index 0000000..a28ef6d --- /dev/null +++ b/src/ClassFactory.cpp @@ -0,0 +1,53 @@ +/*----- PROTECTED REGION ID(E2Quadrupole::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 "E2QuadrupoleClass.h" + +// Add class header files if needed + + +/** + * Create E2Quadrupole Class singleton and store it in DServer object. + */ + +void Tango::DServer::class_factory() +{ + // Add method class init if needed + add_class(E2Quadrupole_ns::E2QuadrupoleClass::init("E2Quadrupole")); +} +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Quadrupole::ClassFactory.cpp diff --git a/src/E2Quadrupole.cpp b/src/E2Quadrupole.cpp new file mode 100644 index 0000000..fac1da0 --- /dev/null +++ b/src/E2Quadrupole.cpp @@ -0,0 +1,1053 @@ +/*----- PROTECTED REGION ID(E2Quadrupole.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : E2Quadrupole.cpp +// +// description : C++ source for the E2Quadrupole 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 +// E2Quadrupole are implemented in this file. +// +// project : Elettra 2.0 pure quadrupole 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 "E2Quadrupole.h" +#include "E2QuadrupoleClass.h" +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Quadrupole.cpp + +/** + * E2Quadrupole class description: + * Elettra 2.0 quadrupole 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 E2Quadrupole_ns +{ +/*----- PROTECTED REGION ID(E2Quadrupole::namespace_starting) ENABLED START -----*/ +/* clang-format on */ +// static initializations +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Quadrupole::namespace_starting + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::E2Quadrupole() + * Description: Constructors for a Tango device + * implementing the classE2Quadrupole + */ +//-------------------------------------------------------- +E2Quadrupole::E2Quadrupole(Tango::DeviceClass *cl, std::string &s) + : TANGO_BASE_CLASS(cl, s.c_str()) +{ + /*----- PROTECTED REGION ID(E2Quadrupole::constructor_1) ENABLED START -----*/ + /* clang-format on */ + init_device(); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::constructor_1 +} +//-------------------------------------------------------- +E2Quadrupole::E2Quadrupole(Tango::DeviceClass *cl, const char *s) + : TANGO_BASE_CLASS(cl, s) +{ + /*----- PROTECTED REGION ID(E2Quadrupole::constructor_2) ENABLED START -----*/ + /* clang-format on */ + init_device(); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::constructor_2 +} +//-------------------------------------------------------- +E2Quadrupole::E2Quadrupole(Tango::DeviceClass *cl, const char *s, const char *d) + : TANGO_BASE_CLASS(cl, s, d) +{ + /*----- PROTECTED REGION ID(E2Quadrupole::constructor_3) ENABLED START -----*/ + /* clang-format on */ + init_device(); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::constructor_3 +} +//-------------------------------------------------------- +E2Quadrupole::~E2Quadrupole() +{ + delete_device(); +} + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::delete_device() + * Description: will be called at device destruction or at init command + */ +//-------------------------------------------------------- +void E2Quadrupole::delete_device() +{ + DEBUG_STREAM << "E2Quadrupole::delete_device() " << device_name << std::endl; + /*----- PROTECTED REGION ID(E2Quadrupole::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 (quadrupole) delete quadrupole; + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::delete_device + delete[] attr_Strength_read; + delete[] attr_CorrectionStrength_read; + delete[] attr_ResonanceStrength_read; + delete[] attr_BeamEnergy_read; + delete[] attr_DesignStrength_read; +} + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::init_device() + * Description: will be called at device initialization. + */ +//-------------------------------------------------------- +void E2Quadrupole::init_device() +{ + DEBUG_STREAM << "E2Quadrupole::init_device() create device " << device_name << std::endl; + /*----- PROTECTED REGION ID(E2Quadrupole::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]; + design_strength_initialized = false; + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::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(E2Quadrupole::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::Quadrupole - handles calibration tables and interpolations + // we do not use teh EBS shehme with global properties... yet + //TODO: fix/determine format and handling of Elettra 2.0 calibrations + + quadrupole = nullptr; + try { + std::string meas_strength_file_name = calibrationPath + "/" + calibrationFileName; + std::string param_file_name = calibrationPath + "/" + parameterFileName; + quadrupole = new MagnetModel::Quadrupole(); + quadrupole->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 quadrupole model " << currentDevice; + set_state(Tango::UNKNOWN); + set_status("failed to create quadrupole 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")); + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::init_device +} + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::get_device_property() + * Description: Read database to initialize property data members. + */ +//-------------------------------------------------------- +void E2Quadrupole::get_device_property() +{ + /*----- PROTECTED REGION ID(E2Quadrupole::get_device_property_before) ENABLED START -----*/ + /* clang-format on */ + // Initialize property data members + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::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 E2QuadrupoleClass to get class property + Tango::DbDatum def_prop, cl_prop; + E2QuadrupoleClass *ds_class = + (static_cast<E2QuadrupoleClass *>(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(E2Quadrupole::get_device_property_after) ENABLED START -----*/ + /* clang-format on */ + // Check device property data members init + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::get_device_property_after +} +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::check_mandatory_property() + * Description: For mandatory properties check if defined in database. + */ +//-------------------------------------------------------- +void E2Quadrupole::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(E2Quadrupole::check_mandatory_property) ENABLED START -----*/ + /* clang-format on */ + std::cerr << tms.str() << " for " << device_name << std::endl; + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::check_mandatory_property + } +} + + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::always_executed_hook() + * Description: method always executed before any command is executed + */ +//-------------------------------------------------------- +void E2Quadrupole::always_executed_hook() +{ + DEBUG_STREAM << "E2Quadrupole::always_executed_hook() " << device_name << std::endl; + if (mandatoryNotDefined) + { + Tango::Except::throw_exception( + (const char *)"PROPERTY_NOT_SET", + get_status().c_str(), + (const char *)"E2Quadrupole::always_executed_hook()"); + } + /*----- PROTECTED REGION ID(E2Quadrupole::always_executed_hook) ENABLED START -----*/ + /* clang-format on */ + // code always executed before all requests + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::always_executed_hook +} + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::read_attr_hardware() + * Description: Hardware acquisition for attributes + */ +//-------------------------------------------------------- +void E2Quadrupole::read_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_list)) +{ + DEBUG_STREAM << "E2Quadrupole::read_attr_hardware(std::vector<long> &attr_list) entering... " << std::endl; + /*----- PROTECTED REGION ID(E2Quadrupole::read_attr_hardware) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::read_attr_hardware +} +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::write_attr_hardware() + * Description: Hardware writing for attributes + */ +//-------------------------------------------------------- +void E2Quadrupole::write_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_list)) +{ + DEBUG_STREAM << "E2Quadrupole::write_attr_hardware(std::vector<long> &attr_list) entering... " << std::endl; + /*----- PROTECTED REGION ID(E2Quadrupole::write_attr_hardware) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::write_attr_hardware +} + +//-------------------------------------------------------- +/** + * Read attribute Strength related method + * Description: quadrupole strength 1/m^3 ( m-3) + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void E2Quadrupole::read_Strength(Tango::Attribute &attr) +{ + DEBUG_STREAM << "E2Quadrupole::read_Strength(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(E2Quadrupole::read_Strength) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + attr.set_value(attr_Strength_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::read_Strength +} +//-------------------------------------------------------- +/** + * Write attribute Strength related method + * Description: quadrupole strength 1/m^3 ( m-3) + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void E2Quadrupole::write_Strength(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "E2Quadrupole::write_Strength(Tango::WAttribute &attr) entering... " << std::endl; + // Retrieve write value + Tango::DevDouble w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(E2Quadrupole::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); + quadrupole->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 -----*/ // E2Quadrupole::write_Strength +} +//-------------------------------------------------------- +/** + * Read attribute CorrectionStrength related method + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void E2Quadrupole::read_CorrectionStrength(Tango::Attribute &attr) +{ + DEBUG_STREAM << "E2Quadrupole::read_CorrectionStrength(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(E2Quadrupole::read_CorrectionStrength) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + attr.set_value(attr_CorrectionStrength_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::read_CorrectionStrength +} +//-------------------------------------------------------- +/** + * Write attribute CorrectionStrength related method + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void E2Quadrupole::write_CorrectionStrength(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "E2Quadrupole::write_CorrectionStrength(Tango::WAttribute &attr) entering... " << std::endl; + // Retrieve write value + Tango::DevDouble w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(E2Quadrupole::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 + *attr_DesignStrength_read; + std::vector<double> req_strength; + std::vector<double> curr_out; + req_strength.push_back(newStrength); + quadrupole->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 -----*/ // E2Quadrupole::write_CorrectionStrength +} +//-------------------------------------------------------- +/** + * Read attribute ResonanceStrength related method + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void E2Quadrupole::read_ResonanceStrength(Tango::Attribute &attr) +{ + DEBUG_STREAM << "E2Quadrupole::read_ResonanceStrength(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(E2Quadrupole::read_ResonanceStrength) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + attr.set_value(attr_ResonanceStrength_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::read_ResonanceStrength +} +//-------------------------------------------------------- +/** + * Write attribute ResonanceStrength related method + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void E2Quadrupole::write_ResonanceStrength(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "E2Quadrupole::write_ResonanceStrength(Tango::WAttribute &attr) entering... " << std::endl; + // Retrieve write value + Tango::DevDouble w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(E2Quadrupole::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 + *attr_DesignStrength_read; + std::vector<double> req_strength; + std::vector<double> curr_out; + req_strength.push_back(newStrength); + quadrupole->compute_currents(magnet_rigidity, req_strength, curr_out); + 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 -----*/ // E2Quadrupole::write_ResonanceStrength +} +//-------------------------------------------------------- +/** + * Read attribute Current related method + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void E2Quadrupole::read_Current(Tango::Attribute &attr) +{ + DEBUG_STREAM << "E2Quadrupole::read_Current(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(E2Quadrupole::read_Current) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + attr.set_value(attr_Current_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::read_Current +} +//-------------------------------------------------------- +/** + * Write attribute Current related method + * + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void E2Quadrupole::write_Current(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "E2Quadrupole::write_Current(Tango::WAttribute &attr) entering... " << std::endl; + // Retrieve write value + Tango::DevDouble w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(E2Quadrupole::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 -----*/ // E2Quadrupole::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 E2Quadrupole::read_BeamEnergy(Tango::Attribute &attr) +{ + DEBUG_STREAM << "E2Quadrupole::read_BeamEnergy(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(E2Quadrupole::read_BeamEnergy) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + attr.set_value(attr_BeamEnergy_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::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 E2Quadrupole::write_BeamEnergy(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "E2Quadrupole::write_BeamEnergy(Tango::WAttribute &attr) entering... " << std::endl; + // Retrieve write value + Tango::DevDouble w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(E2Quadrupole::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 -----*/ // E2Quadrupole::write_BeamEnergy +} +//-------------------------------------------------------- +/** + * Read attribute DesignStrength related method + * Description: quadrupole 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 E2Quadrupole::read_DesignStrength(Tango::Attribute &attr) +{ + DEBUG_STREAM << "E2Quadrupole::read_DesignStrength(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(E2Quadrupole::read_DesignStrength) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + attr.set_value(attr_DesignStrength_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::read_DesignStrength +} +//-------------------------------------------------------- +/** + * Write attribute DesignStrength related method + * Description: quadrupole 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 E2Quadrupole::write_DesignStrength(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "E2Quadrupole::write_DesignStrength(Tango::WAttribute &attr) entering... " << std::endl; + // Retrieve write value + Tango::DevDouble w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(E2Quadrupole::write_DesignStrength) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + *attr_DesignStrength_read = w_val; + if (design_strength_initialized == false){ + design_strength_initialized = true; + init_strengths(); + subscribe_events(); + } + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::write_DesignStrength +} + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::add_dynamic_attributes() + * Description: Create the dynamic attributes if any + * for specified device. + */ +//-------------------------------------------------------- +void E2Quadrupole::add_dynamic_attributes() +{ + /*----- PROTECTED REGION ID(E2Quadrupole::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 -----*/ // E2Quadrupole::add_dynamic_attributes +} + +//-------------------------------------------------------- +/** + * Command Reset related method + * Description: reset the corrector + * + */ +//-------------------------------------------------------- +void E2Quadrupole::reset() +{ + DEBUG_STREAM << "E2Quadrupole::Reset() - " << device_name << std::endl; + /*----- PROTECTED REGION ID(E2Quadrupole::reset) ENABLED START -----*/ + /* clang-format on */ + + // Add your own code + + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::reset +} +//-------------------------------------------------------- +/** + * Command ResetResonanceStrength related method + * Description: Reset ResonanceStrength to 0 + * + */ +//-------------------------------------------------------- +void E2Quadrupole::reset_resonance_strength() +{ + DEBUG_STREAM << "E2Quadrupole::ResetResonanceStrength() - " << device_name << std::endl; + /*----- PROTECTED REGION ID(E2Quadrupole::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); + quadrupole->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); + resonanceAtt->set_write_value(0.0); + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::reset_resonance_strength +} +//-------------------------------------------------------- +/** + * Command ApplyDesignStrength related method + * Description: Apply the memorized DesignStrength strenght to the magnet. + * + */ +//-------------------------------------------------------- +void E2Quadrupole::apply_design_strength() +{ + DEBUG_STREAM << "E2Quadrupole::ApplyDesignStrength() - " << device_name << std::endl; + /*----- PROTECTED REGION ID(E2Quadrupole::apply_design_strength) ENABLED START -----*/ + /* clang-format on */ + + // Add your own code + + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::apply_design_strength +} +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::add_dynamic_commands() + * Description: Create the dynamic commands if any + * for specified device. + */ +//-------------------------------------------------------- +void E2Quadrupole::add_dynamic_commands() +{ + /*----- PROTECTED REGION ID(E2Quadrupole::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 -----*/ // E2Quadrupole::add_dynamic_commands +} + +/*----- PROTECTED REGION ID(E2Quadrupole::namespace_ending) ENABLED START -----*/ +/* clang-format on */ +// Additional Methods +/* clang-format off */ +//-------------------------------------------------------- +void E2Quadrupole::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 E2Quadrupole::set_current_write(const double& curr) +{ + cursetAtt->set_write_value(curr); + set_current[0] = curr; +} +// ------------------------------------------------------------ +void E2Quadrupole::init_strengths(void) // initialize strengths from power supply value TODO: separate read and set values +{ + 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]); //use set value of current + quadrupole->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]; + Tango::DevDouble corr = _strength[0] - *attr_DesignStrength_read; + + 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; + wValResStrength = 0.0; + + } catch (Tango::DevFailed &e) { + Tango::Except::print_exception(e); + } +} +//------------------------------------------------------------ +// handle changes poer poer supply read current (actula current) +void E2Quadrupole::update_values_read(void) +{ + 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); + quadrupole->compute_strengths(magnet_rigidity_inv, read_curr, read_strength); + attr_Strength_read[0] = read_strength[0]; + attr_CorrectionStrength_read[0] = attr_Strength_read[0] -( attr_DesignStrength_read[0] + attr_ResonanceStrength_read[0]); +} + +//------------------------------------------------------------ +// hndle change of write set point of power supply cunnrent +void E2Quadrupole::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 + quadrupole->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 E2Quadrupole::update_values_state(void) +{ + //handle state - status + //INFO_STREAM << "update values state"; + switch (get_state()) { + case Tango::ON: + set_status("On"); + break; + case Tango::OFF: + set_status("Off"); + break; + case Tango::FAULT: + set_status("Fault"); + break; + case Tango::RUNNING: + set_status("Running"); + break; + case Tango::MOVING: + set_status("Moving"); + break; + default: + set_status("Unknown"); + } + +} + +void E2Quadrupole::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 E2Quadrupole::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(E2Quadrupole* quad) //callback constructor +{ + e2_quad = quad; +} +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) { + //std::cerr << ev->err << " " << ev->attr_name << std::endl; + e2_quad->set_state(Tango::FAULT); + e2_quad->set_status("event error"); + *e2_quad->attr_Current_read = NAN; + e2_quad->update_values_read(); + return; + } + { + omni_mutex_lock guardio(e2_quad->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_quad->attr_Current_read); + update_read = true; + } + if (attrname == "currentset") { + Tango::DevDouble newcurr; + *(ev->attr_value) >> newcurr; + e2_quad->set_current_write(newcurr); + update_write = true; + } + if (attrname == "state") { + Tango::DevState st; + *(ev->attr_value) >> st; + e2_quad->set_state(st); + update_state = true; + } + } + if (update_read) e2_quad->update_values_read(); + if (update_write) e2_quad->update_values_write(); + if (update_state) e2_quad->update_values_state(); +} + +/*----- PROTECTED REGION END -----*/ // E2Quadrupole::namespace_ending +} // namespace diff --git a/src/E2Quadrupole.h b/src/E2Quadrupole.h new file mode 100644 index 0000000..6291359 --- /dev/null +++ b/src/E2Quadrupole.h @@ -0,0 +1,342 @@ +/*----- PROTECTED REGION ID(E2Quadrupole.h) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : E2Quadrupole.h +// +// description : Include file for the E2Quadrupole 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 E2Quadrupole_H +#define E2Quadrupole_H + +#include <tango/tango.h> +#include <Quadrupole.h> +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Quadrupole.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 + +/** + * E2Quadrupole class description: + * Elettra 2.0 quadrupole 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 E2Quadrupole_ns +{ +/*----- PROTECTED REGION ID(E2Quadrupole::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 -----*/ // E2Quadrupole::Additional Class Declarations + +class E2Quadrupole : public TANGO_BASE_CLASS +{ + +/*----- PROTECTED REGION ID(E2Quadrupole::Data Members) ENABLED START -----*/ +/* clang-format on */ +// Add your own data members + MagnetModel::Quadrupole* quadrupole; //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 + 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 +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Quadrupole::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 + */ + E2Quadrupole(Tango::DeviceClass *cl,std::string &s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device Name + */ + E2Quadrupole(Tango::DeviceClass *cl,const char *s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device name + * @param d Device description. + */ + E2Quadrupole(Tango::DeviceClass *cl,const char *s,const char *d); + /** + * The device object destructor. + */ + ~E2Quadrupole(); + + +// 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 : E2Quadrupole::read_attr_hardware() + * Description: Hardware acquisition for attributes. + */ + //-------------------------------------------------------- + virtual void read_attr_hardware(std::vector<long> &attr_list); + //-------------------------------------------------------- + /* + * Method : E2Quadrupole::write_attr_hardware() + * Description: Hardware writing for attributes. + */ + //-------------------------------------------------------- + virtual void write_attr_hardware(std::vector<long> &attr_list); + +/** + * Attribute Strength related methods + * Description: quadrupole 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: quadrupole 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 : E2Quadrupole::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 : E2Quadrupole::add_dynamic_commands() + * Description: Add dynamic commands if any. + */ + //-------------------------------------------------------- + void add_dynamic_commands(); + +/*----- PROTECTED REGION ID(E2Quadrupole::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_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); +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Quadrupole::Additional Method prototypes +}; + +/*----- PROTECTED REGION ID(E2Quadrupole::Additional Classes Definitions) ENABLED START -----*/ +/* clang-format on */ +// Additional Classes Definitions +class CurrentEventCallback : public Tango::CallBack +{ +public: + CurrentEventCallback(E2Quadrupole*); + void push_event(Tango::EventData* ev); +protected: + E2Quadrupole* e2_quad; +}; +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Quadrupole::Additional Classes Definitions + +} // End of namespace + +#endif // E2Quadrupole_H diff --git a/src/E2Quadrupole.xmi b/src/E2Quadrupole.xmi new file mode 100644 index 0000000..32b78ae --- /dev/null +++ b/src/E2Quadrupole.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="E2Quadrupole" pogoRevision="9.9"> + <description description="Elettra 2.0 quadrupole 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/e2quadrupole/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="quadrupole 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="quadrupole 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/E2QuadrupoleClass.cpp b/src/E2QuadrupoleClass.cpp new file mode 100644 index 0000000..d0c990c --- /dev/null +++ b/src/E2QuadrupoleClass.cpp @@ -0,0 +1,873 @@ +/*----- PROTECTED REGION ID(E2QuadrupoleClass.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : E2QuadrupoleClass.cpp +// +// description : C++ source for the E2QuadrupoleClass. +// A singleton class derived from DeviceClass. +// It implements the command and attribute list +// and all properties and methods required +// by the E2Quadrupole 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 "E2QuadrupoleClass.h" +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass.cpp + +//------------------------------------------------------------------- +/** + * Create E2QuadrupoleClass singleton and + * return it in a C function for Python usage + */ +//------------------------------------------------------------------- +extern "C" { +#ifdef _TG_WINDOWS_ + +__declspec(dllexport) + +#endif + + Tango::DeviceClass *_create_E2Quadrupole_class(const char *name) { + return E2Quadrupole_ns::E2QuadrupoleClass::init(name); + } +} + +namespace E2Quadrupole_ns +{ +//=================================================================== +// Initialize pointer for singleton pattern +//=================================================================== +E2QuadrupoleClass *E2QuadrupoleClass::_instance = NULL; + +//=================================================================== +// Class constants +//=================================================================== +//-------------------------------------------------------- +/** + * method : E2QuadrupoleClass::E2QuadrupoleClass(std::string &s) + * description : constructor for the E2QuadrupoleClass + * + * @param s The class name + */ +//-------------------------------------------------------- +E2QuadrupoleClass::E2QuadrupoleClass(std::string &s):Tango::DeviceClass(s) +{ + TANGO_LOG_INFO << "Entering E2QuadrupoleClass constructor" << std::endl; + set_default_property(); + get_class_property(); + write_class_property(); + + /*----- PROTECTED REGION ID(E2QuadrupoleClass::constructor) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::constructor + + TANGO_LOG_INFO << "Leaving E2QuadrupoleClass constructor" << std::endl; +} + +//-------------------------------------------------------- +/** + * method : E2QuadrupoleClass::~E2QuadrupoleClass() + * description : destructor for the E2QuadrupoleClass + */ +//-------------------------------------------------------- +E2QuadrupoleClass::~E2QuadrupoleClass() +{ + /*----- PROTECTED REGION ID(E2QuadrupoleClass::destructor) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::destructor + + _instance = NULL; +} + + +//-------------------------------------------------------- +/** + * method : E2QuadrupoleClass::init + * description : Create the object if not already done. + * Otherwise, just return a pointer to the object + * + * @param name The class name + */ +//-------------------------------------------------------- +E2QuadrupoleClass *E2QuadrupoleClass::init(const char *name) +{ + if (_instance == NULL) + { + try + { + std::string s(name); + _instance = new E2QuadrupoleClass(s); + } + catch (std::bad_alloc &) + { + throw; + } + } + return _instance; +} + +//-------------------------------------------------------- +/** + * method : E2QuadrupoleClass::instance + * description : Check if object already created, + * and return a pointer to the object + */ +//-------------------------------------------------------- +E2QuadrupoleClass *E2QuadrupoleClass::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<E2Quadrupole *>(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<E2Quadrupole *>(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<E2Quadrupole *>(device))->apply_design_strength()); + return new CORBA::Any(); +} + + +//=================================================================== +// Properties management +//=================================================================== +//-------------------------------------------------------- +/** + * Method : E2QuadrupoleClass::get_class_property() + * Description: Get the class property for specified name. + */ +//-------------------------------------------------------- +Tango::DbDatum E2QuadrupoleClass::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 : E2QuadrupoleClass::get_default_device_property() + * Description: Return the default value for device property. + */ +//-------------------------------------------------------- +Tango::DbDatum E2QuadrupoleClass::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 : E2QuadrupoleClass::get_default_class_property() + * Description: Return the default value for class property. + */ +//-------------------------------------------------------- +Tango::DbDatum E2QuadrupoleClass::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 : E2QuadrupoleClass::get_class_property() + * Description: Read database to initialize class property data members. + */ +//-------------------------------------------------------- +void E2QuadrupoleClass::get_class_property() +{ + /*----- PROTECTED REGION ID(E2QuadrupoleClass::get_class_property_before) ENABLED START -----*/ + /* clang-format on */ + // Initialize class property data members + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::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(E2QuadrupoleClass::get_class_property_after) ENABLED START -----*/ + /* clang-format on */ + // Check class property data members init + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::get_class_property_after + +} + +//-------------------------------------------------------- +/** + * Method : E2QuadrupoleClass::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 E2QuadrupoleClass::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 : E2QuadrupoleClass::write_class_property() + * Description: Set class description fields as property in database + */ +//-------------------------------------------------------- +void E2QuadrupoleClass::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 quadrupole 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 : E2QuadrupoleClass::device_factory() + * Description: Create the device object(s) + * and store them in the device list + */ +//-------------------------------------------------------- +void E2QuadrupoleClass::device_factory(const Tango::DevVarStringArray *devlist_ptr) +{ + /*----- PROTECTED REGION ID(E2QuadrupoleClass::device_factory_before) ENABLED START -----*/ +/* clang-format on */ +// Add your own code +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::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 E2Quadrupole(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 + E2Quadrupole *dev = static_cast<E2Quadrupole *>(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(E2QuadrupoleClass::device_factory_after) ENABLED START -----*/ +/* clang-format on */ +// Add your own code +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::device_factory_after +} +//-------------------------------------------------------- +/** + * Method : E2QuadrupoleClass::attribute_factory() + * Description: Create the attribute object(s) + * and store them in the attribute list + */ +//-------------------------------------------------------- +void E2QuadrupoleClass::attribute_factory(std::vector<Tango::Attr *> &att_list) +{ + /*----- PROTECTED REGION ID(E2QuadrupoleClass::attribute_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::attribute_factory_before + // Attribute : Strength + StrengthAttrib *strength = new StrengthAttrib(); + Tango::UserDefaultAttrProp strength_prop; + strength_prop.set_description("quadrupole 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("quadrupole 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(E2QuadrupoleClass::attribute_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::attribute_factory_after +} +//-------------------------------------------------------- +/** + * Method : E2QuadrupoleClass::pipe_factory() + * Description: Create the pipe object(s) + * and store them in the pipe list + */ +//-------------------------------------------------------- +void E2QuadrupoleClass::pipe_factory() +{ + /*----- PROTECTED REGION ID(E2QuadrupoleClass::pipe_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::pipe_factory_before + /*----- PROTECTED REGION ID(E2QuadrupoleClass::pipe_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::pipe_factory_after +} +//-------------------------------------------------------- +/** + * Method : E2QuadrupoleClass::command_factory() + * Description: Create the command object(s) + * and store them in the command list + */ +//-------------------------------------------------------- +void E2QuadrupoleClass::command_factory() +{ + /*----- PROTECTED REGION ID(E2QuadrupoleClass::command_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::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(E2QuadrupoleClass::command_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::command_factory_after +} + +//=================================================================== +// Dynamic attributes related methods +//=================================================================== + +//-------------------------------------------------------- +/** + * method : E2QuadrupoleClass::create_static_attribute_list + * description : Create the a list of static attributes + * + * @param att_list the created attribute list + */ +//-------------------------------------------------------- +void E2QuadrupoleClass::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(E2QuadrupoleClass::create_static_att_list) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::create_static_att_list +} + + +//-------------------------------------------------------- +/** + * method : E2QuadrupoleClass::erase_dynamic_attributes + * description : delete the dynamic attributes if any. + * + * @param devlist_ptr the device list pointer + * @param list of all attributes + */ +//-------------------------------------------------------- +void E2QuadrupoleClass::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()); + E2Quadrupole *dev = static_cast<E2Quadrupole *> (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(E2QuadrupoleClass::erase_dynamic_attributes) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::erase_dynamic_attributes +} + +//-------------------------------------------------------- +/** + * Method : E2QuadrupoleClass::get_attr_object_by_name() + * Description: returns Tango::Attr * object found by name + */ +//-------------------------------------------------------- +Tango::Attr *E2QuadrupoleClass::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(E2QuadrupoleClass::Additional Methods) ENABLED START -----*/ +/* clang-format on */ +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::Additional Methods +} // namespace diff --git a/src/E2QuadrupoleClass.h b/src/E2QuadrupoleClass.h new file mode 100644 index 0000000..6a2c1d9 --- /dev/null +++ b/src/E2QuadrupoleClass.h @@ -0,0 +1,281 @@ +/*----- PROTECTED REGION ID(E2QuadrupoleClass.h) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : E2QuadrupoleClass.h +// +// description : Include for the E2Quadrupole root class. +// This class is the singleton class for +// the E2Quadrupole device class. +// It contains all properties and methods which the +// E2Quadrupole 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 E2QuadrupoleClass_H +#define E2QuadrupoleClass_H + +#include <tango/tango.h> +#include "E2Quadrupole.h" + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass.h + + +namespace E2Quadrupole_ns +{ +/*----- PROTECTED REGION ID(E2QuadrupoleClass::classes for dynamic creation) ENABLED START -----*/ +/* clang-format on */ + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::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<E2Quadrupole *>(dev))->read_Strength(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<E2Quadrupole *>(dev))->write_Strength(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<E2Quadrupole *>(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<E2Quadrupole *>(dev))->read_CorrectionStrength(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<E2Quadrupole *>(dev))->write_CorrectionStrength(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<E2Quadrupole *>(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<E2Quadrupole *>(dev))->read_ResonanceStrength(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<E2Quadrupole *>(dev))->write_ResonanceStrength(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<E2Quadrupole *>(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<E2Quadrupole *>(dev))->read_Current(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<E2Quadrupole *>(dev))->write_Current(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<E2Quadrupole *>(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<E2Quadrupole *>(dev))->read_BeamEnergy(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<E2Quadrupole *>(dev))->write_BeamEnergy(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<E2Quadrupole *>(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<E2Quadrupole *>(dev))->read_DesignStrength(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<E2Quadrupole *>(dev))->write_DesignStrength(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<E2Quadrupole *>(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<E2Quadrupole *>(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<E2Quadrupole *>(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<E2Quadrupole *>(dev))->is_ApplyDesignStrength_allowed(any);} +}; + + +/** + * The E2QuadrupoleClass singleton definition + */ + +#ifdef _TG_WINDOWS_ +class __declspec(dllexport) E2QuadrupoleClass : public Tango::DeviceClass +#else +class E2QuadrupoleClass : public Tango::DeviceClass +#endif +{ + /*----- PROTECTED REGION ID(E2QuadrupoleClass::Additional DServer data members) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2QuadrupoleClass::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 E2QuadrupoleClass *init(const char *); + static E2QuadrupoleClass *instance(); + ~E2QuadrupoleClass(); + Tango::DbDatum get_class_property(std::string &); + Tango::DbDatum get_default_device_property(std::string &); + Tango::DbDatum get_default_class_property(std::string &); + + protected: + E2QuadrupoleClass(std::string &); + static E2QuadrupoleClass *_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 // E2Quadrupole_H diff --git a/src/E2QuadrupoleStateMachine.cpp b/src/E2QuadrupoleStateMachine.cpp new file mode 100644 index 0000000..dd1dbed --- /dev/null +++ b/src/E2QuadrupoleStateMachine.cpp @@ -0,0 +1,242 @@ +/*----- PROTECTED REGION ID(E2QuadrupoleStateMachine.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : E2QuadrupoleStateMachine.cpp +// +// description : State machine file for the E2Quadrupole 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 "E2Quadrupole.h" + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Quadrupole::E2QuadrupoleStateMachine.cpp + +//================================================================ +// States | Description +//================================================================ + + +namespace E2Quadrupole_ns +{ +//================================================= +// Attributes Allowed Methods +//================================================= + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::is_Strength_allowed() + * Description: Execution allowed for Strength attribute + */ +//-------------------------------------------------------- +bool E2Quadrupole::is_Strength_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for Strength attribute in Write access. + /*----- PROTECTED REGION ID(E2Quadrupole::StrengthStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::StrengthStateAllowed_WRITE + + // Not any excluded states for Strength attribute in read access. + /*----- PROTECTED REGION ID(E2Quadrupole::StrengthStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::StrengthStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::is_CorrectionStrength_allowed() + * Description: Execution allowed for CorrectionStrength attribute + */ +//-------------------------------------------------------- +bool E2Quadrupole::is_CorrectionStrength_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for CorrectionStrength attribute in Write access. + /*----- PROTECTED REGION ID(E2Quadrupole::CorrectionStrengthStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::CorrectionStrengthStateAllowed_WRITE + + // Not any excluded states for CorrectionStrength attribute in read access. + /*----- PROTECTED REGION ID(E2Quadrupole::CorrectionStrengthStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::CorrectionStrengthStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::is_ResonanceStrength_allowed() + * Description: Execution allowed for ResonanceStrength attribute + */ +//-------------------------------------------------------- +bool E2Quadrupole::is_ResonanceStrength_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for ResonanceStrength attribute in Write access. + /*----- PROTECTED REGION ID(E2Quadrupole::ResonanceStrengthStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::ResonanceStrengthStateAllowed_WRITE + + // Not any excluded states for ResonanceStrength attribute in read access. + /*----- PROTECTED REGION ID(E2Quadrupole::ResonanceStrengthStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::ResonanceStrengthStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::is_Current_allowed() + * Description: Execution allowed for Current attribute + */ +//-------------------------------------------------------- +bool E2Quadrupole::is_Current_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for Current attribute in Write access. + /*----- PROTECTED REGION ID(E2Quadrupole::CurrentStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::CurrentStateAllowed_WRITE + + // Not any excluded states for Current attribute in read access. + /*----- PROTECTED REGION ID(E2Quadrupole::CurrentStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::CurrentStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::is_BeamEnergy_allowed() + * Description: Execution allowed for BeamEnergy attribute + */ +//-------------------------------------------------------- +bool E2Quadrupole::is_BeamEnergy_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for BeamEnergy attribute in Write access. + /*----- PROTECTED REGION ID(E2Quadrupole::BeamEnergyStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::BeamEnergyStateAllowed_WRITE + + // Not any excluded states for BeamEnergy attribute in read access. + /*----- PROTECTED REGION ID(E2Quadrupole::BeamEnergyStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::BeamEnergyStateAllowed_READ + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::is_DesignStrength_allowed() + * Description: Execution allowed for DesignStrength attribute + */ +//-------------------------------------------------------- +bool E2Quadrupole::is_DesignStrength_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Not any excluded states for DesignStrength attribute in Write access. + /*----- PROTECTED REGION ID(E2Quadrupole::DesignStrengthStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::DesignStrengthStateAllowed_WRITE + + // Not any excluded states for DesignStrength attribute in read access. + /*----- PROTECTED REGION ID(E2Quadrupole::DesignStrengthStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::DesignStrengthStateAllowed_READ + return true; +} + + +//================================================= +// Commands Allowed Methods +//================================================= + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::is_Reset_allowed() + * Description: Execution allowed for Reset attribute + */ +//-------------------------------------------------------- +bool E2Quadrupole::is_Reset_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for Reset command. + /*----- PROTECTED REGION ID(E2Quadrupole::ResetStateAllowed) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::ResetStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::is_ResetResonanceStrength_allowed() + * Description: Execution allowed for ResetResonanceStrength attribute + */ +//-------------------------------------------------------- +bool E2Quadrupole::is_ResetResonanceStrength_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for ResetResonanceStrength command. + /*----- PROTECTED REGION ID(E2Quadrupole::ResetResonanceStrengthStateAllowed) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::ResetResonanceStrengthStateAllowed + return true; +} + +//-------------------------------------------------------- +/** + * Method : E2Quadrupole::is_ApplyDesignStrength_allowed() + * Description: Execution allowed for ApplyDesignStrength attribute + */ +//-------------------------------------------------------- +bool E2Quadrupole::is_ApplyDesignStrength_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Not any excluded states for ApplyDesignStrength command. + /*----- PROTECTED REGION ID(E2Quadrupole::ApplyDesignStrengthStateAllowed) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // E2Quadrupole::ApplyDesignStrengthStateAllowed + return true; +} + + +/*----- PROTECTED REGION ID(E2Quadrupole::E2QuadrupoleStateAllowed.AdditionalMethods) ENABLED START -----*/ +/* clang-format on */ +// Additional Methods +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // E2Quadrupole::E2QuadrupoleStateAllowed.AdditionalMethods + +} // End of namespace diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..ef1d82b --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,89 @@ +/*----- PROTECTED REGION ID(E2Quadrupole::main.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : main.cpp +// +// description : C++ source for the E2Quadrupole 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 -----*/ // E2Quadrupole::main.cpp -- GitLab From f3f3d2ec657a6f2b1d930ac0204e248588c24958 Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Wed, 9 Oct 2024 16:59:15 +0200 Subject: [PATCH 2/7] init to nullptr --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ef1d82b..bfa572d 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 From 41fea2f7fc178e815c0be8ad385548117e34a007 Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Wed, 16 Oct 2024 17:35:35 +0200 Subject: [PATCH 3/7] tango DB test devices --- doc/test.res | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 doc/test.res diff --git a/doc/test.res b/doc/test.res new file mode 100644 index 0000000..3b0ec37 --- /dev/null +++ b/doc/test.res @@ -0,0 +1,40 @@ +# +# Resource backup , created Wed Oct 16 17:35:04 CEST 2024 +# + +#--------------------------------------------------------- +# SERVER e2quadrupole-srv/test, E2Quadrupole device declaration +#--------------------------------------------------------- + +e2quadrupole-srv/test/DEVICE/E2Quadrupole: "test/magnet/q13" + + +# --- test/magnet/q13 properties + +test/magnet/q13->CalibrationFileName: Q13_strength.csv +test/magnet/q13->CurrentDevice: "test/power_supply/psq13" +test/magnet/q13->MagnetName: Q13-test +test/magnet/q13->Model: Q13-test +test/magnet/q13->ParameterFileName: Q13_params.csv +test/magnet/q13->SerialNumber: Q13-test + +# --- test/magnet/q13 attribute properties + +test/magnet/q13/DesignStrength->__value: 0 + +#--------------------------------------------------------- +# CLASS E2Quadrupole properties +#--------------------------------------------------------- + +CLASS/E2Quadrupole->CalibrationPath: "/homelocal/claudio/src/gitlab/dt/machine/calibration/magnetmodel" +CLASS/E2Quadrupole->Description: "Elettra 2.0 quadrupole 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/E2Quadrupole->InheritedFrom: TANGO_BASE_CLASS +CLASS/E2Quadrupole->ProjectTitle: "Elettra 2.0 pure corrector magnet device" + +# CLASS E2Quadrupole attribute properties + + -- GitLab From 390ef7167392c7bf8da895e0698573f506175c45 Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Mon, 4 Nov 2024 11:10:57 +0100 Subject: [PATCH 4/7] test config saved --- doc/Class.res | 11 +++++++++++ doc/test.res | 14 ++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 doc/Class.res diff --git a/doc/Class.res b/doc/Class.res new file mode 100644 index 0000000..c45621b --- /dev/null +++ b/doc/Class.res @@ -0,0 +1,11 @@ +CLASS/E2Quadrupole->CalibrationPath: "/homelocal/claudio/src/gitlab/dt/machine/calibration/magnetmodel" +CLASS/E2Quadrupole->Description: "Elettra 2.0 quadrupole 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/E2Quadrupole->InheritedFrom: TANGO_BASE_CLASS +CLASS/E2Quadrupole->ProjectTitle: "Elettra 2.0 pure corrector magnet device" + +# CLASS E2Quadrupole attribute properties + diff --git a/doc/test.res b/doc/test.res index 3b0ec37..0fc66f5 100644 --- a/doc/test.res +++ b/doc/test.res @@ -1,5 +1,5 @@ # -# Resource backup , created Wed Oct 16 17:35:04 CEST 2024 +# Resource backup , created Fri Oct 18 15:36:31 CEST 2024 # #--------------------------------------------------------- @@ -11,12 +11,14 @@ e2quadrupole-srv/test/DEVICE/E2Quadrupole: "test/magnet/q13" # --- test/magnet/q13 properties -test/magnet/q13->CalibrationFileName: Q13_strength.csv +test/magnet/q13->CalibrationFileName: Qstrength.csv test/magnet/q13->CurrentDevice: "test/power_supply/psq13" -test/magnet/q13->MagnetName: Q13-test -test/magnet/q13->Model: Q13-test -test/magnet/q13->ParameterFileName: Q13_params.csv -test/magnet/q13->SerialNumber: Q13-test +test/magnet/q13->MagnetName: 0 +test/magnet/q13->Model: not_relevant +test/magnet/q13->ParameterFileName: MAG_params.csv +test/magnet/q13->SerialNumber: 1 +test/magnet/q13->__SubDevices: "test/power_supply/psq13",\ + "dserver/simulatede2ps-srv/test" # --- test/magnet/q13 attribute properties -- GitLab From e9df249d0b0c89e010593f38b191b4fb57c6bcbe Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Mon, 4 Nov 2024 12:25:49 +0100 Subject: [PATCH 5/7] fix hadling of DesignStrength handling --- TODO | 3 +-- src/E2Quadrupole.cpp | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 2972583..b117ade 100644 --- a/TODO +++ b/TODO @@ -1,2 +1 @@ -check and fix ResonanceStrength handling -fix units \ No newline at end of file +fix units diff --git a/src/E2Quadrupole.cpp b/src/E2Quadrupole.cpp index fac1da0..a011036 100644 --- a/src/E2Quadrupole.cpp +++ b/src/E2Quadrupole.cpp @@ -747,11 +747,12 @@ void E2Quadrupole::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 valu of Design strength init process can be completed design_strength_initialized = true; init_strengths(); subscribe_events(); } + else init_strengths(); /*----- PROTECTED REGION END -----*/ // E2Quadrupole::write_DesignStrength } -- GitLab From 60f51deaf39d2b01751d693c1526fa18b381e6e6 Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Mon, 4 Nov 2024 14:44:47 +0100 Subject: [PATCH 6/7] typo in comment --- src/E2Quadrupole.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/E2Quadrupole.cpp b/src/E2Quadrupole.cpp index a011036..5526978 100644 --- a/src/E2Quadrupole.cpp +++ b/src/E2Quadrupole.cpp @@ -747,7 +747,7 @@ void E2Quadrupole::write_DesignStrength(Tango::WAttribute &attr) // Add your own code /* clang-format off */ *attr_DesignStrength_read = w_val; - if (design_strength_initialized == false){ // only with a valu of Design strength init process can be completed + if (design_strength_initialized == false){ // only with a value of DesignStrength init process can be completed design_strength_initialized = true; init_strengths(); subscribe_events(); -- GitLab From ea803df1e431e00732d8411d35e1b8c6add9d2d6 Mon Sep 17 00:00:00 2001 From: Claudio Scafuri <claudio.scafuri@elettra.eu> Date: Tue, 28 Jan 2025 16:14:22 +0100 Subject: [PATCH 7/7] fix resonance strength, clarify and fix ResetResonanceStrength command --- src/E2Quadrupole.cpp | 20 +++++--------------- src/E2Quadrupole.h | 2 +- src/E2Quadrupole.xmi | 2 +- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/E2Quadrupole.cpp b/src/E2Quadrupole.cpp index 5526978..4159dd2 100644 --- a/src/E2Quadrupole.cpp +++ b/src/E2Quadrupole.cpp @@ -617,7 +617,7 @@ void E2Quadrupole::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 -----*/ // E2Quadrupole::write_ResonanceStrength @@ -793,7 +793,7 @@ void E2Quadrupole::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,14 @@ void E2Quadrupole::reset_resonance_strength() // Add your own code /* clang-format off */ - //force to 0 resonance strength + //transfer resonance strngth to correction strength and 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); - quadrupole->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 -----*/ // E2Quadrupole::reset_resonance_strength } //-------------------------------------------------------- diff --git a/src/E2Quadrupole.h b/src/E2Quadrupole.h index 6291359..6f8c812 100644 --- a/src/E2Quadrupole.h +++ b/src/E2Quadrupole.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/E2Quadrupole.xmi b/src/E2Quadrupole.xmi index 32b78ae..35c566a 100644 --- a/src/E2Quadrupole.xmi +++ b/src/E2Quadrupole.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> -- GitLab