<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to JavaEngine</title><link>https://sourceforge.net/p/commondatamodel/wiki/JavaEngine/</link><description>Recent changes to JavaEngine</description><atom:link href="https://sourceforge.net/p/commondatamodel/wiki/JavaEngine/feed" rel="self"/><language>en</language><lastBuildDate>Wed, 02 Sep 2015 08:16:22 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/commondatamodel/wiki/JavaEngine/feed" rel="self" type="application/rss+xml"/><item><title>JavaEngine modified by Anonymous</title><link>https://sourceforge.net/p/commondatamodel/wiki/JavaEngine/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="content"&gt;Content&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Main parts of an engine&lt;ul&gt;
&lt;li&gt;Handle the data source&lt;/li&gt;
&lt;li&gt;Navigation&lt;/li&gt;
&lt;li&gt;Data description and manipulation&lt;/li&gt;
&lt;li&gt;Data description&lt;/li&gt;
&lt;li&gt;Data manipulation&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id="introduction"&gt;Introduction&lt;/h1&gt;
&lt;hr/&gt;
&lt;p&gt;A CDMA engine is used to access on a particular data format like NeXus, NetCDF, a data base or what ever. Indeed it manages data source handle, navigation, and access to data. It can't be instantiated, as it is, by the Core API: it's not a plug-in at all. The engine only cares about: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;handling the data source (opening and closing its target URI) &lt;/li&gt;
&lt;li&gt;navigation &lt;/li&gt;
&lt;li&gt;data loading &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The interest of developing engines is that several plug-ins can share the same one. It reduces a lot the development cost. To prevent the plug-in reimplementing every methods of each class, items created by the engine must respect the CDMA interfaces. Indeed a plug-in above an engine can then directly drive the engine or even return engine's objects. &lt;/p&gt;
&lt;p&gt;The engine developer should focus on efficiency and memory usage. &lt;/p&gt;
&lt;h1 id="main-parts-of-an-engine"&gt;Main parts of an engine&lt;/h1&gt;
&lt;hr/&gt;
&lt;p&gt;All the things an engine should implement are stored in the Core package &lt;em&gt;interfaces&lt;/em&gt;: &lt;code&gt;org.cdma.interfaces&lt;/code&gt;. &lt;/p&gt;
&lt;p&gt;Notice that one particular interface shouldn't be implemented directly because it is inherited yet from other interfaces : &lt;em&gt;IContainer&lt;/em&gt;. Its role is to give the property of a physical node of the data source to prevent rewriting many methods many times. &lt;/p&gt;
&lt;p&gt;Below an example of the CDMA NeXus engine structure: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" rel="nofollow" src="http://cdma.googlecode.com/svn/wiki/images/java_engine_nexus_structure.png"/&gt;&lt;/p&gt;
&lt;p&gt;The engine is split among 3 main packages: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;fr.soleil.nexus&lt;/em&gt; which is the NeXus API by this engine (it enhances array loading, memory and disk usage) &lt;/li&gt;
&lt;li&gt;&lt;em&gt;navigation&lt;/em&gt; that regroups all concerning the navigation and data source handling &lt;/li&gt;
&lt;li&gt;&lt;em&gt;array&lt;/em&gt; that manages matrices loading and description &lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="handle-the-data-source"&gt;Handle the data source&lt;/h2&gt;
&lt;p&gt;The data source is manipulated using a CDMA engine. According so that's the engine whose handles it and ask for read / write access. The data source handler is done by implementing the &lt;em&gt;IDataset&lt;/em&gt; interface. It provides open and close methods, a generic write methods. &lt;/p&gt;
&lt;p&gt;Above all, it's the &lt;em&gt;IDataset&lt;/em&gt; interface which give access to the navigation part using the &lt;em&gt;getRootGroup&lt;/em&gt; method. That call returns the entry point of the data source which is mandatory a &lt;em&gt;IGroup&lt;/em&gt; implementation. &lt;/p&gt;
&lt;h2 id="navigation"&gt;Navigation&lt;/h2&gt;
&lt;p&gt;The data source is considered as a tree. But it's not mandatory: if you can do the big things, you can do the little things as well. &lt;/p&gt;
&lt;p&gt;The aim is to be able to browse the data source and get nodes' informations, location, name, properties... &lt;/p&gt;
&lt;p&gt;Here 5 classes need to be implemented: &lt;code&gt;IDataset, IGroup, IDataItem, IAttribute&lt;/code&gt;. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;IDataset&lt;/code&gt; is the one that handles the data source it permits to have a location on it, to open or close an access on it, &lt;/li&gt;
&lt;li&gt;&lt;code&gt;IGroup&lt;/code&gt; which is a container for IDataItem or other &lt;code&gt;IGroup&lt;/code&gt;. It's the one that let you exploring the tree &lt;/li&gt;
&lt;li&gt;&lt;code&gt;IDataItem&lt;/code&gt; which are considered as the leaves of our tree. They wear the physical data (more often a matrix), so it should be able to give some informations on it like type, size... &lt;/li&gt;
&lt;li&gt;&lt;code&gt;IAttribute&lt;/code&gt; are attribute or contextual data of nodes (&lt;code&gt;IGroup&lt;/code&gt; or &lt;code&gt;IDataItem&lt;/code&gt;). For instance, an &lt;code&gt;IDataItem&lt;/code&gt; has timestamps which tells at what time it was recorded. &lt;/li&gt;
&lt;li&gt;&lt;code&gt;IDimension&lt;/code&gt; they are the axis of a data item. For instance, it should store motor positions when a detector that produced a stack of spectrum has been translated while acquiring it. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With such a structure we should be able to explore almost all (to not say all) data sources. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Take care to share references on object.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Example 1: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;IDataset dataset = Factory.createDatasetInstance(URI);
IGroup root = dataset.getRootGroup();
IDataItem item = root.findDataItem( key );
IGroup root2 = item.getRootGroup();
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The code above should lead to “root” and “root2” to be 2 references of the same instance. &lt;/p&gt;
&lt;p&gt;Example 2: &lt;/p&gt;
&lt;p&gt;Let suppose the following structure the root group has 1 group item called my_group. And my_group as one data item called my_data. Then: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;IDataset dataset = Factory.openDataset(URI);
IGroup root = dataset.getRootGroup();
IDataItem item = root.findDataItem( "my_data" );
IGroup group1 = item.getParent();
IGroup group2 = root.getGroup( "my_group" );
IGroup group3 = root.findGroup( "my_group" );
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Same as before, the above code should lead to have &lt;code&gt;group1&lt;/code&gt;, &lt;code&gt;group2&lt;/code&gt; and &lt;code&gt;group3&lt;/code&gt; to be 3 references of the same instance. Only one call to the &lt;code&gt;IGroup&lt;/code&gt; constructor should be done. &lt;/p&gt;
&lt;h2 id="data-description-and-manipulation"&gt;Data description and manipulation&lt;/h2&gt;
&lt;h3 id="data-description"&gt;Data description&lt;/h3&gt;
&lt;p&gt;Physical data are seen as matrices. Even when they are a scalar, they are always described using the IArray interface. Below the main methods provided by the array interface: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;IArray&lt;/span&gt; &lt;span class="kr"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;IModelObject&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;IArrayUtils&lt;/span&gt; &lt;span class="nx"&gt;getArrayUtils&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;IArrayMath&lt;/span&gt; &lt;span class="nx"&gt;getArrayMath&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="nx"&gt;Class&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;getElementType&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nx"&gt;getRank&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;int&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="nx"&gt;getShape&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;IIndex&lt;/span&gt; &lt;span class="nx"&gt;getIndex&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;ISliceIterator&lt;/span&gt; &lt;span class="nx"&gt;getSliceIterator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt; &lt;span class="nx"&gt;rank&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;IArrayIterator&lt;/span&gt; &lt;span class="nx"&gt;getIterator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nx"&gt;IArrayIterator&lt;/span&gt; &lt;span class="nx"&gt;getRegionIterator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="nx"&gt;reference&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;int&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;IArray&lt;/code&gt; interface is the entry point of data access and manipulation, it give all necessary informations to process, copy... matrices &lt;/p&gt;
&lt;p&gt;Classes used to described matrices are the following: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;IArray&lt;/code&gt; that holds and manages the memory storage &lt;/li&gt;
&lt;li&gt;&lt;code&gt;IIndex&lt;/code&gt; defines the viewable part of an &lt;code&gt;IArray&lt;/code&gt;, “independently” of it's storage. More exactly it does all cell index calculation when accessing the storage. For instance, when changing the IIndex of an array without reloading data, we can be able to iterate over it by scanning one cell on two. &lt;/li&gt;
&lt;li&gt;&lt;code&gt;IRange&lt;/code&gt; defines each dimension of the &lt;code&gt;IIndex&lt;/code&gt;. It means its length, offset, stride. It tells on one dimension of the storage how many cells should be avoided between two cells that are seen as contiguous by the user. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;They work as following: &lt;code&gt;IArray&lt;/code&gt; uses an &lt;code&gt;IIndex&lt;/code&gt; to do all its calculation of cell offset and position. &lt;code&gt;IIndex&lt;/code&gt; uses &lt;code&gt;IRange&lt;/code&gt; to define each dimension of the represented array. &lt;/p&gt;
&lt;p&gt;Below how they are structured in the NeXus engine: &lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;public class NxsArray implements IArray {
    private IIndex m_index;   // Viewable part of the array
    private Object m_oData;   // Array of primitive
    private int[]  m_shape;   // Shape of the backing storage
...
}

public class NxsIndex implements IIndex {
    private int   m_rank;        // rank of the view
    private int[] m_iCurPos;     // Current position
    private NxsRange[] m_ranges; // View in each dimension
...
}

public class NxsRange implements IRange {
    private long      m_last;     // number of elements
    private long      m_first;    // first value in range
    private long      m_stride;   // stride, must be &amp;gt;= 1
    private String    m_name;     // optional name
    private boolean   m_reduced;  // range reduced or not i.e is the range visible outside the index
...
}
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;At this point the engine should be able to browse and load data from the data source. &lt;/p&gt;
&lt;h3 id="data-manipulation"&gt;Data manipulation&lt;/h3&gt;
&lt;p&gt;The manipulation of matrices is processed with following items: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;IArrayIterator&lt;/code&gt; permits to iterate over the array and get each value according to the defined view (of the &lt;code&gt;IArray&lt;/code&gt;). &lt;/li&gt;
&lt;li&gt;&lt;code&gt;ISliceIterator&lt;/code&gt; permits to slice the IArray into several parts and to get a new &lt;code&gt;IArray&lt;/code&gt; (smaller than the original one) that shares the same backing storage. &lt;/li&gt;
&lt;li&gt;&lt;code&gt;IArrayMath&lt;/code&gt; is implemented by default in the “Core” but it uses &lt;code&gt;IArray&lt;/code&gt; methods to apply its algorithms so it isn't the most efficient: see class &lt;code&gt;ArrayMath&lt;/code&gt; in math package. &lt;/li&gt;
&lt;li&gt;&lt;code&gt;IArrayUtils&lt;/code&gt; is implemented by default in the “Core” but it uses &lt;code&gt;IArray&lt;/code&gt; methods to apply its algorithms so it isn't the most efficient: see class &lt;code&gt;ArrayUtils&lt;/code&gt; in utils package. &lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Wed, 02 Sep 2015 08:16:22 -0000</pubDate><guid>https://sourceforge.net8e14d02def5c33a9d1a50fb96a6354fbc77f6b12</guid></item></channel></rss>