Suppose you are interested in one component in the McXtrace library, but you would like to customize it a little. There are different ways to extend an existing component.
If you only want to add something on top of the component existing behaviour, the simplest is to work from the instrument definition TRACE section, using the EXTEND modifier (see section 6.4.2). You do not need to write a new component definition, but only add a piece of code to execute.
Copy the interesting component definition from the McXtrace library location (e.g. /usr/local/mcxtrace/1.2/... or c:\mcxtrace\1.2\...) into your working directory next to your instrument definition file. This will cause McXtrace to pick this component definition up before the one in the library. Next, modify the local component file until you ae satisfied with it. If you feel that the newly modified componennt may be of use to the McXtrace community, please do not hesitate to contact the development team concerning the options for contributing. Rest assured that copyright remains with you.
There is a heritage mechanism to create children of existing components. These are exact duplicates of the parent component, but one may override/extend original definitions of any section.
The syntax for a full component child is
DEFINE COMPONENT child_name COPY parent_name
This single line will copy all parts of the parent into the child, except for the documentation header.
As for normal component definitions, you may add other parameters, DECLARE, TRACE, ... sections. Each of them will replace or extend (be catenated to, with the COPY/EXTEND keywords, see example below) the corresponding parent definition. In practice, you could copy a component and only rewrite some of it, as in the following example:
DEFINE COMPONENT child_name COPY parent_name
SETTING PARAMETERS (newpar1, newpar2)
INITIALIZE COPY parent_name EXTEND
%{
…C code to be catenated to the parent_name INITIALIZE …
%}
SAVE
%{
…C code to replace the parent_name SAVE …
%}
where two additional parameters have been defined, and should be handled in the extension of the original INITIALIZE section.
On the other hand, if you do not derive a component as a whole from a parent, you may still use specific parts from any component:
DEFINE COMPONENT name …
DECLARE COPY parent1
INITIALIZE COPY parent2 EXTEND
%{
…C code to be catenated to the parent2 INITIALIZE …
%}
TRACE COPY parent3
This mechanism may lighten the component code, but a special care should be taken in mixing bits from different sources, specially concerning variables. This may result in difficulties to compile components.