NewAttributes - CMSROMA/MTDDB GitHub Wiki
An attribute is a value attached to a part. The actual possible values of an attribute are finite, and predefined. Examples are: the relative position of a part with respect to another, the status of a part, etc.
-
Choose a name (e.g. 'Global status'), then
INSERT INTO CMS-MTD_CORE_ATTRIBUTE.ATTR_CATALOGS (IS_RECORD_DELETED, DISPLAY_NAME) VALUES ('F', 'Global Status'); -
Get its primary key
SELECT ATTR_CATALOG_ID, DISPLAY_NAME FROM CMS_MTD_CORE_ATTRIBUTE.ATTR_CATALOGS; ATTR_CATALOG_ID DISPLAY_NAME --------------- ---------------------------------------- 1000 Global Status
- Get the primary keys of the parts to associate to this attribute (LYSO matrices and single crystals)
SELECT KIND_OF_PART_ID, DISPLAY_NAME FROM CMS_MTD_CORE_CONSTRUCT.KINDS_OF_PARTS WHERE DISPLAY_NAME LIKE 'LYSOMatrix%'; KIND_OF_PART_ID DISPLAY_NAME --------------- ---------------------------------------- 4 LYSOMatrix #1 5 LYSOMatrix #2 6 LYSOMatrix #3 SELECT KIND_OF_PART_ID, DISPLAY_NAME FROM CMS_MTD_CORE_CONSTRUCT.KINDS_OF_PARTS WHERE DISPLAY_NAME LIKE 'singleCrystal%'; KIND_OF_PART_ID DISPLAY_NAME --------------- ---------------------------------------- 3020 singleCrystal #1 3040 singleCrystal #2 3060 singleCrystal #3
- Attach the attribute to the relevant part types:
INSERT INTO CMS_MTD_CORE_CONSTRUCT.PART_TO_ATTR_RLTNSHPS (ATTR_CATALOG_ID, KIND_OF_PART_ID, IS_RECORD_DELETED, DISPLAY_NAME, COMMENT_DESCRIPTION) VALUES (1000, 4, 'F', 'Global Status', 'The global status represent the overall status of the part'); INSERT INTO CMS_MTD_CORE_CONSTRUCT.PART_TO_ATTR_RLTNSHPS (ATTR_CATALOG_ID, KIND_OF_PART_ID, IS_RECORD_DELETED, DISPLAY_NAME, COMMENT_DESCRIPTION) VALUES (1000, 5, 'F', 'Global Status', 'The global status represent the overall status of the part'); INSERT INTO CMS_MTD_CORE_CONSTRUCT.PART_TO_ATTR_RLTNSHPS (ATTR_CATALOG_ID, KIND_OF_PART_ID, IS_RECORD_DELETED, DISPLAY_NAME, COMMENT_DESCRIPTION) VALUES (1000, 6, 'F', 'Global Status', 'The global status represent the overall status of the part'); INSERT INTO CMS_MTD_CORE_CONSTRUCT.PART_TO_ATTR_RLTNSHPS (ATTR_CATALOG_ID, KIND_OF_PART_ID, IS_RECORD_DELETED, DISPLAY_NAME, COMMENT_DESCRIPTION) VALUES (1000, 3020, 'F', 'Global Status', 'The global status represent the overall status of the part'); INSERT INTO CMS_MTD_CORE_CONSTRUCT.PART_TO_ATTR_RLTNSHPS (ATTR_CATALOG_ID, KIND_OF_PART_ID, IS_RECORD_DELETED, DISPLAY_NAME, COMMENT_DESCRIPTION) VALUES (1000, 3040, 'F', 'Global Status', 'The global status represent the overall status of the part'); INSERT INTO CMS_MTD_CORE_CONSTRUCT.PART_TO_ATTR_RLTNSHPS (ATTR_CATALOG_ID, KIND_OF_PART_ID, IS_RECORD_DELETED, DISPLAY_NAME, COMMENT_DESCRIPTION) VALUES (1000, 3060, 'F', 'Global Status', 'The global status represent the overall status of the part');
- Create the connection between the attribute (key = 1000) and the table containing its values (
POSITION_SCHEMAS). In this case we have two possible values for the status: 'Rejected' and 'Skipped'. So, we need to create two hooks.
INSERT INTO CMS_MTD_CORE_ATTRIBUTE.ATTR_BASES (ATTR_CATALOG_ID, IS_RECORD_DELETED, EXTENSION_TABLE_NAME) VALUES (1000, 'F', 'POSITION_SCHEMAS'); INSERT INTO CMS_MTD_CORE_ATTRIBUTE.ATTR_BASES (ATTR_CATALOG_ID, IS_RECORD_DELETED, EXTENSION_TABLE_NAME) VALUES (1000, 'F', 'POSITION_SCHEMAS');
- Get the attribute identifier:
select ATTRIBUTE_ID, EXTENSION_TABLE_NAME from CMS_MTD_CORE_ATTRIBUTE.ATTR_BASES WHERE ATTR_CATALOG_ID = 1000; ATTRIBUTE_ID EXTENSION_TABLE_NAME ------------ ------------------------------ 1000 POSITION_SCHEMAS 1020 POSITION_SCHEMAS
- List the possible values of the attributes, and associate them to the latter:
INSERT INTO CMS_MTD_CORE_ATTRIBUTE.POSITION_SCHEMAS (ATTRIBUTE_ID, NAME, IS_RECORD_DELETED) VALUES (1000, 'Skipped', 'F'); INSERT INTO CMS_MTD_CORE_ATTRIBUTE.POSITION_SCHEMAS (ATTRIBUTE_ID, NAME, IS_RECORD_DELETED) VALUES (1020, 'Rejected', 'F');
In order to attach an attribute to (multiple) part(s), use the following XML: in the example we assign the status Good to part PRE0000000782, after the measurement of its size (the name of the attribute is Dimensions Test Status).
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ROOT xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<PARTS>
<PART>
<RECORD_INSERTION_USER>organtin</RECORD_INSERTION_USER>
<BARCODE>PRE0000000782</BARCODE>
<PREDEFINED_ATTRIBUTES>
<ATTRIBUTE>
<NAME>Dimensions Test Status</NAME>
<VALUE>Good</VALUE>
</ATTRIBUTE>
</PREDEFINED_ATTRIBUTES>
</PART>
<PART>
<RECORD_INSERTION_USER>organtin</RECORD_INSERTION_USER>
<BARCODE>PRE0000000828</BARCODE>
<PREDEFINED_ATTRIBUTES>
<ATTRIBUTE>
<NAME>Dimensions Test Status</NAME>
<VALUE>Bad</VALUE>
</ATTRIBUTE>
</PREDEFINED_ATTRIBUTES>
</PART>
</PARTS>
</ROOT>
</pre>