Table of Contents
Editing the control system database requires that you understand the database structure as covered in previous chapters.
To effectively edit and apply changes to the runtime system, you will need access to both the csadmin and postgres users. The actual editing is performed by the postgres user. The csadmin user is only needed to perform a restart of the control system. A restart is required for new additions and modifications to certain tables.
For the remainder of this chapter, the contract name 'sample1' will be used.
If you want to edit an existing database, skip this section.
A contract is typically cloned from an existing, similar contract. The following is how to clone a contract named source1 to sample1.
Start by making a complete copy of the contract directory.
csadmin$
cd /AccelNET
csadmin$
cp -R source1 sample1
Once this has been done, edit /AccelNET/sample1/environ. Set CONF=sample1 at the very least.
The following commands will create the runtime database directory structure.
csadmin$
cd /AccelNET/db
csadmin$
make_db_dir sample1
Next make a postgres contract directory, setup the editing tools environment, and create a default AccelNET database. The following should be executed as the postgres user.
postgres$
cd /AccelNET/pg
postgres$
make_contract sample1
postgres$
make_tools sample1
postgres$
/AccelNET/pg/sys/dbcreate/builddb/dbcreate sample1
postgres$
cd /AccelNET/pg/sample1
postgres$
cp ../source1/senvi .
You should now have the start of an AccelNET database.
After the database has been created, verify that /AccelNET/environ is linked to /AccelNET/sample1/environ and that CONF=sample1 is set in the file. Edit the senvi file to set CONF=sample1 as well. Logout and back in as the postgres user for the changes to take effect.
In order to modify entries in the database, a table or portion of a table must be retrieved from PostgreSQL. To accomplish this task, the fetch command will be used.
postgres$
cd $TOOLS
postgres$
fetch Label
A file called Label.lst containing the LabelRec table is produced. This file may be opened with any unix/linux text editor. Each line of the file contains a single entry of the table. Fields are separated by a vertical tab (|). From this point, fields can be edited and entries may be added.
Updating a table will modify existing and insert new entries. It is usually best to work from a freshly pulled table or to clone from an existing database. Once the changes have been made to the text file, save it and return to the prompt. To update/insert, use the update command from the tools directory.
postgres$
update Label
Watch the output for any errors. Errors can be caused by invalid values, incorrect field positions, or table relation conflicts. If an error occurs on an entry, the update or insertion of that entry will not occur.
Deleting entries can be one of the most frustrating tasks with an AccelNET database. This is due to the nature of using a relational database and currently available tools. A basic knowledge of SQL is required to delete entries. As the postgres user, connect to the database using the psql command.
postgres$
psql sample1
A welcome message should display giving you a list of help commands and a prompt 'sample1=>' waiting for a command.
For this example, we will delete an entry out of the DescRec table. We are going to attempt to delete the entry for label 'FC 01-1' and refname 'PosSC' from the table. This will only match one entry in the DescRec table because of the primary keys set for the table. It is important to know what is going to match your delete request to avoid unwanted removal of entries.
sample1=>
DELETE FROM DescRec WHERE Label='FC 01-1' AND RefName='PosSC';
Here is where the trouble will most likely start. The majority of the time, an error will be displayed stating that it cannot delete the entry. This is what is called a trigger. A trigger message will look much like this:
NOTICE: can't delete |FC 01-1|PosSC | it is in use by ChkPoint.CPdesc
A quick glance will tell you that you tried to delete FC 01-1|PosSC and that a reference to it exists in the ChkPoint table. To resolve this, you must delete the reference(s) to the parameter in the ChkPoint table. In addition, pay attention to where you are deleting from. In cases such as the interlock tables (ChkList, ChkPoint, ChkAct, ChkAlarm), related tables may need to be modified to refelect the deletion. See the appendix titled "Resolving PostgreSQL Trigger Errors" for a more in depth look at resolving trigger errors.
The easiest way to find which entry contains the offending parameter is to retreive the table to a text file and perform a search. To exit psql simply type \q and you will be returned to the normal shell prompt. After finding the entries, decide how they should be handled. Some entries, such as those in the crtDCpnt or crtICpnt tables may contain parameters that are still in use. In this case, it is probably best to replace the offending parameter values with NULL|NULL. Another case would be where the parameter is taking up an entry that will no longer be needed. Use psql and a DELETE statement to remove the entry. Again, pay close attention to the statement you use to delete the entry so as not to harm the rest of the table. Once you have removed the offending entries, attempt the original DELETE statement. If all of the offending entries in all of the tables have been removed, the delete will be succesful. Repeat the above process until the delete is succesful.
Once modifications to the database are complete, they need to be converted to a format the runtime system can use. To accomplish this task, the dbconvert command is used. The command dbconvert all will convert all of the tables to the runtime format. Individual tables can be converted by specifying them in the same way fetch and update are called. In general, it is best to use the dbconvert all instead of converting individual tables. This will decrease the chance of not converting a needed table. The speed of current processors is able to do the operations fast enough.
There are a few special cases that require prior preparation for conversion. The first case is with the DescRec table. The DescRec table has flags that allow for M, B, and IncVal to be calculated. To do this calculation, you can use the buildmb all command. The second case is with any Crt table. The Crt tables calculate their location coordinates based on the RecId. This is done using the convertX and convertY commands.
Now that the desired editing has been completed and the database has been converted, the runtime system must be notified of the new changes. There are two scenarios for notifying the runtime system.
The first scenario is the most reliable as well as the easiest. The disadvantage is that the control system must be halted.
Clear the runtime database and stop all of the AccelNET clients.
csadmin$
dbclear
Load in the new runtime database from the converted files.
csadmin$
dbload
Start the AccelNET clients.
csadmin$
startio
The second scenario allows modification of the runtime database without the need to stop the AccelNET clients. Be aware that this method only works on certain tables and fields in the database. As a rule of thumb, this method will not allow addition of new records, changes to primary keys, or changes to fields that are used as pointers.
Here is a fairly complete list of modifiable fields:
Fields Allowed
Name
Units, DataType, CrtKey, CtlKey, Owner, WpermD, ScaKey, SpanMin, SpanMax, PhyMin, PhyMax, IncVal, M, B, DRkey, Size, Offset, Dcomm, MBconvKey, MBsetIncKey
Although the listed fields are modifiable, it may be dangerous to change Size and Offset on a running system.
MsgText
Dflag, PgDesc
CurX, CurY, Dflag, Width, FontType, Text
CurX, CurY, Dflag, Width, FontType
CurX, CurY, Dflag, Width, FontType
CurX, CurY, CurX2, CurY2, ICrot, ICscale, Dflag
Value, TMOvalue
CPtype, Offset, LimLo, LimHi
Mask, Mask2, Value
Mask, Mask2, Message
NPtype, Scale
To perform this type of modification, the dbmodify command is used as the postgres user. The following is an example using the DescRec table.
postgres$
dbmodify Desc
In addition to the listed fields above, there are a few things to consider. For example, modifications to the interlock and numeric chains will not be evaluated immediately. Modifications will be evaluated when a watched parameter changes value in the ChkPoint or NumPoint table for the chain. It may be helpful to use the cache command within Xcrt to refresh the currently displayed page. This can fix drawing errors while moving icons around the diagramatic display.
pgEdit is a combination of server-side scripts and a Java applet designed to modify an AccelNET database graphically. The goal of pgEdit is to allow someone with less console and/or SQL experience to make simple changes to AccelNET.
Although this application is not yet complete, it is quite functional in its current state. If you encounter problems/bugs with this application, please contact NEC with a description of the problem so that it may be addressed.
All of the commonly edited tables have basic insert, update, and delete abilities. The following commands have also been implemented: dbconvert all, buildmb all, convertX, and convertY. The following reports may also be generated and viewed: Module, CAMAC, Alarms, Label, RecId, M&B, Limits, JackRec, RPrecord, and Zrecord.
Because pgEdit is still under development, it may not have been installed and/or configured on your control system. Please contact NEC if you wish to test this software.
TODO: write me!
pgEdit can be accessed using a Java[5] enabled web browser such as Mozilla, FireFox, Safari, Opera, NetScape, or Internet Explorer. The following is a set of directions on how to access the editor.
Open your Java enabled web browser.
Point the browser to the control system's hostname. If you are seated at the control system, the hostname 'localhost' will work.
You will be presented with a web page tailored for AccelNET. Across the top will be the contract name, accelerator type, and the wording "AccelNET Control System Home Page." Several menus will be lined down the left side of the page. These menus include accelerator status views, dosimetry information, documentation, and pgEdit.
Scroll down the page to the bottom so that the Database Tools menu is visible.
Single-click on "Database Editor."
You are now presented with a login form.
Fill in the fields and click the "Login" button.
The hostname should have been filled in for you. Click the dropdown menu to select the contract you wish to edit. In most cases, there will only be one option. The 'postgres' username should be used with no password.
At this point, the Java applet should load.
Single-click the "Connect" button to connect to the database.
The status bar at the bottom will display a message stating it is connected.
Single-click the "(Re)Load" button to load the database into pgEdit.
The user interface should be fairly easy to learn. The database table names are listed as a series of tabs along the left side of the applet. Across the top you will find buttons to perform global functions. The following is a list of the buttons and what they do:
Connects/Disconnects to/from the Postgres database.
Retrieves the tables and populates pgEdit with the latest values. This should be clicked after major deletions and updates.
Retrieves and populates the currently displayed screen with the latest values. This is helpful if you made a mistake and noticed it before you submit an update.
Updates the database with the currently displayed information. This should be clicked after making any changes before continuing to another parameter/table.
Removes the currently displayed record from the database permanently.
Inserts the currently displayed record to the database permanently.