This is a collection of thoughts on AIDA Styles and on their use in the new plotter.

Style Store

This is an object that can save and retrieve styles from a store (xml file on disk, database table). The basic xml style definition is the AIDA one. Next to the style itself we also identified the need to define Style Rules that should also be saved/retrieved to/from the store:

<styleStore>
   <styles>
       <style>
          .......
          <rules>
             <rule>
                .......
             </rule>
          </rules>
       </style>
   </styles>
</styleStore>

Multiple stores might be loaded at once: System Store, Personal Store, Group Store, Experiment Store. Their information is grouped and managed by a Style Registry

Style Rules

It should be possible to define rules on how to attach a style to a particular plot object. Multiple rules might be applied to a given style. It should be possible to apply rules to:

Style Registry

A style registry combines the styles and rules from different style stores and provides the right set of styles (with the appropriate Style Order) for a given plot object.

Style Order

We have to define the order in which the styles are applied to an object:

Style Editor

GUI front end for viewing and editing individual styles or combinations of styles.
We already have a first version of the style editor. We need to add the possibility to view the information contained in a style registry, i.e. the chain of styles contributing to a given object and the set of rules that have contributed to it.

Comments to AIDA Styles

 

Ideas for Implementation

 Let's leave Style Store out of this discussion just for the moment.

So Style Registry is created and is getting populated by (or just acts as a manager/façade for) the Style Stores, but it has access to Style/Rules information.

Just before object is plotted/printed and we know the object's path in a Tree, object's type, order of the object in particular IPlotterRegion, etc. All this information is used to query the Style Registry and create a cumulative IPlotterStyle for the implicit parameters.

Information that we need:

If any styles are passed explicitly to the plotter, this implicit cumulative style will be set as parent (or merged in as a lower priority Style).

I've set three interfaces that might do the job (below), have a look.

IStyleRegistry interface:

IPlotterStore in StyleRegistry is identified by a name (storeName). Store names have to be unique.

Also StyleRegistry can manage the Categories: list of all available keys and set of current values.

public interface IStyleRegistry {

    // To work with Style Stores
   
    String[] getAvailableStoreNames();
   
    IStyleStore getStore(String storeName);
   
   
    // To work with categories, this can be a separate service
    // Available category keys are filled from Rules of all available Stores
   
    String[] getAvailableCategoryKeys();
   
    String getCategoryValue(String categoryKey);
   
    void setCategoryCurrentValue(String categoryKey, String categoryValue);
   
    // Following methods are used to obtain cumulative IPlotterStyle
    // for particular region, object, action, and (possibly) categories
   
    IPlotterStyle getStyleForState(IPlotterState state);
}

IStyleStore interface:

Style Rule has type and value.  Rule applies to the IPlotterState if state has approptiate type, and rule value is compatible with the state value.  

import hep.aida.IPlotterStyle;

/**
 * This interface can be implemented as "In-Memory" copy of persistent
 * facility, or as keeping live connections and committing any change
 * immediately.
 */public interface IStyleStore {
   
    String getStoreName();
   
    String getStoreType();
   
    boolean isReadOnly();
   
   
    void addStyle(String styleName, IPlotterStyle style);
   
    boolean hasStyle(String styleName);
   
    IPlotterStyle getStyle(String styleName);
   
    /**
     * Remove Style and all Rules associated with it from the Store
     */
    IPlotterStyle removeStyle(String styleName);
   
    String[] getAllStyleNames();
   
    IStyleRule[] getRulesForStyle(String styleName);
   
    void addRuleForStyle(String styleName, IStyleRule rule);
   
    void setRuleForStyle(String styleName, IStyleRule rule);
   
    void removeRuleForStyle(String styleName, IStyleRule rule);
   
    void removeAllRulesForStyle(String styleName);
   
    /**
     * Write all information from Store to the undelying persistent
     * facility: XML file, database, etc.
     */
    void commit();
          
    /**
     * Close all connections and free all resources.
     * Store is not usable after this method is executed.
     */
    void close();
          
}

IStyleRule interface:

Style Rule has type and value.  Rule applies to the IPlotterState if state has approptiate type, and rule value is compatible with the state value.Rules can be logically groupped together with "OR" or "AND" operation.

Also Rule has a priority - defines the order in which Style that corresponds to this Rule will be used if Rule does apply.

public interface IStyleRule {
&nbsp;&nbsp;&nbsp; // Possible types of Style Rules
&nbsp;&nbsp;&nbsp; static int CLASS&nbsp;&nbsp;&nbsp;&nbsp; = 0;&nbsp; // Class of the object: hep.aida.IHistogram1D
&nbsp;&nbsp;&nbsp; static int PATH&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1;&nbsp; // Position of the object in a Tree
&nbsp;&nbsp;&nbsp; static int ORDER&nbsp;&nbsp;&nbsp;&nbsp; = 2;&nbsp; // Order in the IPlotterRegion: specific number, or cyclical
&nbsp;&nbsp;&nbsp; static int ATTRIBUTE = 3;&nbsp; // Arbitrary "key=value" pair, evalyated by the Rule
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // From AIDA object's annotation any entry with "plotterState." prefix in key
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // will be stripped of this prefix and put into PlotterState with ATTRIBUTE
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // type before obtaining Style from the StyleRegistry
&nbsp;&nbsp;&nbsp; static int ACTION&nbsp;&nbsp;&nbsp; = 4;&nbsp; // What is going to happen with the object: plotting, printing
&nbsp;&nbsp;&nbsp; static int CATEGORY&nbsp; = 5;&nbsp; // "experiment=GLAST", "quality=preliminary"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ACTION seems like a sub-type of CATEGORY: "printing=true"
&nbsp;&nbsp;&nbsp; // Operations that chain rules together
&nbsp;&nbsp;&nbsp; static int AND = 0;
&nbsp;&nbsp;&nbsp; static int OR&nbsp; = 1;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; int getType();
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; /*\*
&nbsp;&nbsp;&nbsp;&nbsp; * Priority determines the order in which corresponding IPlotterStyle
&nbsp;&nbsp;&nbsp;&nbsp; * should be used when assembling the cumulative IPlotterStyle
&nbsp;&nbsp;&nbsp;&nbsp; \*/
&nbsp;&nbsp;&nbsp; int getPriority();
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; String getDescription();
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; void addRule(IStyleRule rule, int operation);
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; /*\*
&nbsp;&nbsp;&nbsp;&nbsp; * Determines if this rule should be used.
&nbsp;&nbsp;&nbsp;&nbsp; *
&nbsp;&nbsp;&nbsp;&nbsp; * If type=CATEGORY, same rule as for AIDA options should be applied:
&nbsp;&nbsp;&nbsp;&nbsp; * have to pass "key=value" pair as value, for only "key" \-> "key=true",
&nbsp;&nbsp;&nbsp;&nbsp; \*/
&nbsp;&nbsp;&nbsp; boolean ruleApplies(int type, String value);
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; /*\*
&nbsp;&nbsp;&nbsp;&nbsp; * Or maybe it is better to hide this type/"key=value" complexity and do this:
&nbsp;&nbsp;&nbsp;&nbsp; \*/
&nbsp;&nbsp;&nbsp; boolean ruleApplies(IPlotterState state);
}

How to Evaluate Style Rules

IPlotterState interface:

/*\*
&nbsp;\* This object encapsulates information about relevant
&nbsp;\* IPlotterRegion, object, and actions.
&nbsp;\* It is used for obtaining implicit IPlotterStyle
&nbsp;*/
public interface IPlotterState {
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; // IStyleRule types are used here
&nbsp;&nbsp;&nbsp; String getValueForType(int styleRuleType);
&nbsp;&nbsp;&nbsp;
}