From adams@bonner-ibm1.rice.edu Wed Apr  1 13:55:36 1998
Date: Wed, 1 Apr 1998 13:53:23 -0600 (CST)
From: David Adams <adams@bonner-ibm1.rice.edu>
To: Brent May <may@fnald0.fnal.gov>, Marc Paterno <paterno@fnal.gov>
Cc: David Adams <adams@bonner-ibm1.rice.edu>, Wyatt Merritt <wyatt@fnal.gov>,
    John Womersley <womersley@fnald0.fnal.gov>,
    Jim Kowalkowski <jbk@fnal.gov>, Michael Aivazis <aivazis@fnal.gov>
Subject: chunk object pointers II

Brent and Marc:

The chunk object pointer class I released yesterday did not provide
the desired physical decoupling.  I now have a better understanding of
the problem and have a solution.

The problem is to construct a pointer class containing an index
specifying an object inside a chunk.  The pointer class should provide
behavior similar to that of a bare pointer to the referenced object,
in particular, one should be able to dereference (*px) and perform
member selection (px->method()).  One should be able to construct this
pointer with only the type names of the referenced object and chunk
(name-only coupling).  However, using the pointer-like methods
(dereference, member selection, ...) will require use of the chunk class
to extract the object from the chunk.

For example, I should be able to construct an electron made up of
"pointers" to a track and EM cluster and be able to fetch and copy
the track pointer with name-only coupling to the track class.  Only
when I dereference the pointer to access the track object, do I need
to have the the track chunk header or library.

Can this be done?  My first attempt was to define the chunk object
pointer as a template ChunkObjkectPtr<T,C,OID> where T is the object
type, C is the chunk type and OID is the index type.  The constructor
has name-only reference to T and C but pointer-like operations require
the chunk header.  I was assuming the compiler would only instantiate
the utilized methods so that a program which constructed such a 
pointer but did not use it would have name-only coupling.

Unfortunately this did not work.  The KAI compiler wants to instantiate
every member function, not just the ones that are used.  I do not know
what, if anthing, the language standard has to say on this matter.

My solution is to have all pointer-like operations call a method 
pointer() which in turn calls the template
 const T* get_object_pointer<T,C,OID>(const T* pobj, THandle<C> pchk,
                                      const OID& idx)
to extract the bare object pointer from the chunk.  The generic
implementation of this template simply returns null.

Chunk designers are expected to provide a specialization of this
template.  Code which includes the header defining that specialization
will call the specialization and code that does not will pick up the
generic implementation.

The code and tests verifying the above behavior may be found in version
00.01.05 of gtrbase.  It is the current head version and has been
tagged v00-01-05.

da

----------------------------------------------------------------------
David Adams                 Rice: (713)285-5316  fax: (713)285-5215
Bonner Lab                  FNAL: (630)840-2406
Rice University             adams@physics.rice.edu
Houston, TX 77005           http://www.bonner.rice.edu/adams
----------------------------------------------------------------------