2 added + 4 modified, total 6 files
lcio/config
diff -u -r1.21 -r1.22
--- aid.includes.cpp.properties 26 Apr 2005 08:39:04 -0000 1.21
+++ aid.includes.cpp.properties 27 Nov 2006 09:57:41 -0000 1.22
@@ -2,7 +2,7 @@
# Property file for includes of LCIO for the C++ generator
#
# @author Frank Gaede
-# @version $Id: aid.includes.cpp.properties,v 1.21 2005/04/26 08:39:04 gaede Exp $
+# @version $Id: aid.includes.cpp.properties,v 1.22 2006/11/27 09:57:41 gaede Exp $
#
# aid wants to include sth. coz we defined double3V - so include an empty file
double* = empty_ignore.h
@@ -34,6 +34,9 @@
#LCObject = LCObject\.h
EVENT\:\:LCObject = EVENT/LCObject\.h
+LCRTRelations = LCRTRelations\.h
+
+
#EVENT\:\:LCEventData = EVENT/LCEventData\.h
#EVENT\:\:LCCollectionData = EVENT/LCCollectionData\.h
#EVENT\:\:LCRunHeaderData = EVENT/LCRunHeaderData\.h
lcio/config
diff -u -r1.13 -r1.14
--- aid.types.java.properties 26 Apr 2005 08:39:04 -0000 1.13
+++ aid.types.java.properties 27 Nov 2006 09:57:41 -0000 1.14
@@ -2,7 +2,7 @@
# Property file for types of AID for the Java generator
#
# @author Mark Donszelmann
-# @version $Id: aid.types.java.properties,v 1.13 2005/04/26 08:39:04 gaede Exp $
+# @version $Id: aid.types.java.properties,v 1.14 2006/11/27 09:57:41 gaede Exp $
#
ITupleEntry=Object
@@ -36,4 +36,6 @@
ReadOnlyExceptions = hep.lcio.implementation.event.ReadOnlyExceptions
# need long64 for C++ - use Java build in long
-long64 = long
\ No newline at end of file
+long64 = long
+
+LCRTRelations =
\ No newline at end of file
lcio/src/aid/EVENT
diff -u -r1.10 -r1.11
--- LCObject.aid 4 Aug 2006 15:00:26 -0000 1.10
+++ LCObject.aid 27 Nov 2006 09:57:42 -0000 1.11
@@ -23,13 +23,24 @@
* @version Jun 7, 2003
* fg 20040405 moved here from hep.lcio.data
*/
-public interface LCObject extends Cloneable {
+public interface LCObject extends Cloneable, LCRTRelations{
@ifdef cpp
+
/** Returns an object id for internal (debugging) use in LCIO.
*/
public int id() const ;
@endif
+// @ifdef cpp
+// public interface LCObject extends Cloneable, LCRTRelations{
+
+// /** Returns an object id for internal (debugging) use in LCIO.
+// */
+// public int id() const ;
+// @else
+// public interface LCObject extends Cloneable {
+
+// @endif
@cpp{
/** Deep copy of the object. C++ implementations should return the
lcio/src/cpp/include
diff -N LCRTRelations.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ LCRTRelations.h 27 Nov 2006 09:57:42 -0000 1.1
@@ -0,0 +1,403 @@
+#ifndef LCRTRelations_H
+#define LCRTRelations_H 1
+
+#include <iostream>
+#include <vector>
+#include <list>
+#include <map>
+#include <sstream>
+//#include <typeinfo>
+
+using namespace std ;
+
+
+typedef void (*DeleteFPtr)(void*) ;
+
+
+struct SimplePtrInit{ static void* init() { return 0 ; } } ;
+
+struct NoDelete{ static void clean(void *v) { /* no_op */ } } ;
+
+
+template <class T>
+struct CreationPtrInit{ static void* init() { return new T ; } } ;
+
+template <class T>
+struct DeletePtr{ static void clean(void *v) { delete (T*) v ; } } ;
+
+
+template <class T>
+struct DeleteElements{
+
+ static void clean(void *v) {
+
+ T* vec = static_cast<T*>(v) ;
+
+ for( typename T::iterator it = vec->begin() ;
+ it != vec->end() ; ++it ){
+ delete *it ;
+ }
+
+ delete vec ;
+ }
+} ;
+
+
+typedef std::map< DeleteFPtr , void * > PtrMap ;
+
+
+
+template <class U, class T , class I=SimplePtrInit, class D=NoDelete >
+struct LCBaseLinkTraits{
+
+ typedef T type ;
+ typedef T* ptr ;
+ typedef T*& ext ; // return value of ext<>()
+ typedef T* cext ; // return value of to<>() and from<>()
+ typedef const T* cptr ;
+ typedef T& ref ;
+ typedef const T& cref ;
+ typedef U tag ; // this ensures that a new class instance is created for every user extension
+
+
+ typedef ptr value_type ;
+ static const bool is_container=false ;
+
+ static void clean(void *v) {
+ D::clean( v ) ;
+ }
+ static ptr init() {
+ return (ptr) I::init() ;
+ }
+ static DeleteFPtr deletePtr() { return &clean ; } ;
+};
+
+
+
+template <class U, class T , class I=CreationPtrInit<T>, class D=DeletePtr<T> >
+struct LCBaseLinkContainerTraits{
+
+ typedef T type ;
+ typedef T* ptr ;
+ typedef T& ext ; // return value of ext<>()
+ typedef const T& cext ; // return value of to<>() and from<>()
+ typedef const T* cptr ;
+ typedef T& ref ;
+ typedef const T& cref ;
+ typedef U tag ; // this ensures that a new class instance is created for every user extension
+
+ typedef typename type::value_type value_type ;
+ typedef typename type::iterator iterator ;
+ typedef typename type::const_iterator const_iterator ;
+ typedef cref container ;
+
+ static const bool is_container=true ;
+
+ static void clean(void *v) {
+ D::clean( v ) ;
+ }
+ static ptr init() {
+ return (ptr) I::init() ;
+ }
+ static DeleteFPtr deletePtr() { return &clean ; } ;
+};
+
+
+
+template <class U, class T>
+class LCLinkTraits : public LCBaseLinkTraits< U, T > {};
+
+
+template <class U, class T>
+class LCOwnedLinkTraits : public LCBaseLinkTraits< U, T , SimplePtrInit , DeletePtr<T> > {};
+
+
+template <class U, class T>
+class LCOwnedLinkVectorTraits :
+ public LCBaseLinkContainerTraits< U, std::vector<T*>,
+ CreationPtrInit< std::vector<T*> > ,
+ DeleteElements< std::vector<T*> > > {};
+
+template <class U, class T>
+class LCOwnedLinkListTraits :
+ public LCBaseLinkContainerTraits< U, std::list<T*>,
+ CreationPtrInit< std::list<T*> > ,
+ DeleteElements< std::list<T*> > > {};
+
+template <class U, class T>
+class LCLinkVectorTraits :
+ public LCBaseLinkContainerTraits< U, std::vector<T*>,
+ CreationPtrInit< std::vector<T*> > ,
+ DeletePtr<std::vector<T*> > > {};
+
+template <class U, class T>
+class LCLinkListTraits :
+ public LCBaseLinkContainerTraits< U, std::list<T*>,
+ CreationPtrInit< std::list<T*> > ,
+ DeletePtr<std::list<T*> > > {};
+
+template <class U>
+struct FromRelation{} ;
+
+template <class U>
+struct ToRelation{} ;
+
+template <class From, class To>
+struct LCRelationTraits{
+ typedef From from_traits ;
+ typedef To to_traits ;
+} ;
+
+
+template <class U, class From, class To>
+struct LC1To1Relation :
+ public LCRelationTraits<LCLinkTraits<FromRelation<U>,From>,
+ LCLinkTraits<ToRelation<U>,To> > {} ;
+
+template <class U, class From, class To>
+struct LCNToNRelation :
+ public LCRelationTraits<LCLinkListTraits<FromRelation<U>,From>,
+ LCLinkListTraits<ToRelation<U>,To> > {
+} ;
+
+
+//--------------------------------------------------------------------
+class LCRTRelations ;
+
+/** Set the 1-to-1 relation between two objects - prexisting inconsistent relations
+ involving the two objects are deleted to enforce a coinsistent set of from-to relations. */
+template <class R>
+void set_relation( typename R::from_traits::value_type f,
+ typename R::to_traits::value_type t) ;
+
+/** Unset the 1-to-1 relation from f */
+template <class R>
+void unset_relation(typename R::from_traits::value_type f );
+
+
+/** Add a link from f to t to an N-to-N relation ship */
+template <class R>
+void add_relation( typename R::from_traits::value_type f,
+ typename R::to_traits::value_type t) ;
+
+
+/** Remove the link from from f to t from the N-to-N relation ship */
+template <class R>
+void remove_relation( typename R::from_traits::value_type f,
+ typename R::to_traits::value_type t) ;
+
+
+/** Removes all relations from the given object */
+template <class R>
+void remove_relations(typename R::from_traits::value_type f );
+
+
+/** Merge the relations from f2 to f1 - after this call f1 will hold all
+ * the relations and f2 will be empty.
+ */
+template <class R>
+void merge_relations( typename R::from_traits::value_type f1,
+ typename R::from_traits::value_type f2) ;
+
+
+
+/*External helper function with partial specialization */
+template <class V, bool take_reference>
+struct ext_helper{
+ inline static typename V::ext ext( typename V::ptr& p ) { return p ;}
+};
+
+/*External helper function with partial specialization */
+template <class V>
+struct ext_helper<V,true>{
+ inline static typename V::ext ext( typename V::ptr& p ) { return *p ;}
+};
+
+
+
+/** Base class for run time extensions to and relation between objects */
+
+class LCRTRelations{
+
+ template <class R>
+ friend void set_relation( typename R::from_traits::value_type f,
+ typename R::to_traits::value_type t);
+
+ template <class R>
+ friend void unset_relation(typename R::from_traits::value_type f );
+
+
+ template <class R>
+ friend void add_relation( typename R::from_traits::value_type f,
+ typename R::to_traits::value_type t) ;
+ template <class R>
+ friend void remove_relation( typename R::from_traits::value_type f,
+ typename R::to_traits::value_type t) ;
+ template <class R>
+ friend void remove_relations(typename R::from_traits::value_type f );
+
+ template <class R>
+ friend void merge_relations( typename R::from_traits::value_type f1,
+ typename R::from_traits::value_type f2) ;
+
+public:
+
+ template <class V>
+ typename V::ext ext() {
+ return ext_helper<V,V::is_container>::ext( ptr<V>() ) ;
+ }
+
+ template <class V>
+ typename V::to_traits::cext to() {
+ return ext<typename V::to_traits>() ;
+ }
+
+ template <class V>
+ typename V::from_traits::cext from() {
+ return ext<typename V::from_traits>() ;
+ }
+
+ ~LCRTRelations() {
+
+ for( PtrMap::iterator it = _map.begin() ;
+ it != _map.end() ; ++it ){
+
+ it->first( it->second ) ; // call the delete function
+ }
+ }
+
+
+ void print(){
+
+ std::cout << " ---- LCRTRelations -- : " << std::endl ;
+
+ typedef std::map< void * , void* > MyPtrMap ;
+
+ MyPtrMap& map = *(MyPtrMap*) &_map ;
+
+ for( MyPtrMap::iterator it = map.begin() ;
+ it != map.end() ; ++it ){
+
+ std::cout << " ---- key : " << &(it->first) << " value "
+ << (void*)it->second << std::endl ;
+
+ }
+ }
+
+protected:
+
+ /** provides write access to a relation - only for friends */
+ template <class V>
+ typename V::to_traits::ext access_to() {
+ return ext<typename V::to_traits>() ;
+ }
+
+ /** provides write access to a relation - only for friends */
+ template <class V>
+ typename V::from_traits::ext access_from() {
+ return ext<typename V::from_traits>() ;
+ }
+
+ /** Returns the reference to the pointer to the extension/relation object */
+ template <class V>
+ typename V::ptr & ptr() {
+
+ typedef std::map< DeleteFPtr , typename V::ptr > MyPtrMap ;
+
+ MyPtrMap& map = *(MyPtrMap*) &_map ;
+
+ typename MyPtrMap::iterator it = map.find( V::deletePtr() ) ;
+
+ if( it == map.end() )
+ it = map.insert( map.begin(),
+ std::make_pair( V::deletePtr(), V::init() )) ;
+
+ return it->second ;
+ }
+
+private:
+
+ PtrMap _map ;
+} ;
+
+
+
+template <class R>
+void set_relation(typename R::from_traits::value_type f, typename R::to_traits::value_type t){
+
+ // clear old relations first
+ unset_relation<R>( f ) ;
+ unset_relation<R>(t->LCRTRelations::from<R>() ) ;
+
+ f->LCRTRelations::access_to<R>() = t ;
+ t->LCRTRelations::access_from<R>() = f ;
+}
+
+/** Unset the 1-to-1 relation from this object if it exists*/
+template <class R>
+void unset_relation(LCRTRelations* f){
+
+ if( f != 0 ){
+
+ LCRTRelations* t = f->LCRTRelations::to<R>() ;
+
+ if( t != 0 )
+ t->LCRTRelations::access_from<R>() = 0 ;
+
+ f->LCRTRelations::access_to<R>() = 0 ;
+ }
+}
+
+
+template <class R>
+void add_relation( typename R::from_traits::value_type f,
+ typename R::to_traits::value_type t){
+
+ f->LCRTRelations::access_to<R>().push_back( t ) ;
+ t->LCRTRelations::access_from <R>().push_back( f ) ;
+}
+
+
+template <class R>
+void remove_relation( typename R::from_traits::value_type f,
+ typename R::to_traits::value_type t ) {
+
+ f->LCRTRelations::access_to<R>().remove( t ) ;
+ t->LCRTRelations::access_from<R>().remove( f ) ;
+}
+
+
+template <class R>
+void remove_relations( typename R::from_traits::type::value_type f ) {
+
+ typename R::to_traits::ref cl = f->LCRTRelations::access_to<R>() ;
+
+ for( typename R::to_traits::iterator it = cl.begin(); it!=cl.end(); ++it){
+
+ (*it)->LCRTRelations::access_from<R>().remove( f ) ;
+ }
+ cl.clear() ;
+}
+
+template <class R>
+void merge_relations(typename R::from_traits::value_type f1,
+ typename R::from_traits::value_type f2 ) {
+
+ typename R::to_traits::ref lt2 = f2->LCRTRelations::access_to<R>() ;
+
+ for( typename R::to_traits::iterator it = lt2.begin() ;it != lt2.end() ; it++ ){
+
+ typename R::from_traits::ref lf2 = (*it)->LCRTRelations::access_from<R>() ;
+
+ lf2.remove( f2 ) ;
+
+ lf2.push_back( f1 ) ;
+ }
+
+ typename R::from_traits::ref lt1 = f1->LCRTRelations::access_to<R>() ;
+
+ lt1.merge( lt2 ) ;
+}
+
+
+#endif
lcio/src/cpp/src/EXAMPLE
diff -N lcrtrelation.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lcrtrelation.cc 27 Nov 2006 09:57:43 -0000 1.1
@@ -0,0 +1,134 @@
+#include "lcio.h"
+
+#include "IO/LCReader.h"
+#include "IMPL/LCTOOLS.h"
+#include "EVENT/LCCollection.h"
+#include "EVENT/Track.h"
+#include "EVENT/Cluster.h"
+
+//static const char* FILEN = "recjob.slcio" ; // default file name
+static std::vector<std::string> FILEN ;
+
+using namespace std ;
+using namespace lcio ;
+
+
+
+struct TrkCluLink : LCNToNRelation<TrkCluLink,Track,Cluster> {} ;
+
+struct Index : LCOwnedLinkTraits<Index,int> {} ;
+
+
+/** Example/test program for new LCIO runtime relations.
+ */
+
+int main(int argc, char** argv ){
+
+ // read file names from command line (only argument)
+ if( argc < 2) {
+ cout << " usage: anajob <input-file1> [[input-file2],...]" << endl ;
+ exit(1) ;
+ }
+ for(int i=1 ; i < argc ; i++){
+ FILEN.push_back( argv[i] ) ;
+ }
+ int nFiles = argc-1 ;
+
+ LCReader* lcReader = LCFactory::getInstance()->createLCReader() ;
+
+ cout << " will open and read from files: " << endl ;
+ for(int i=0 ; i < nFiles ; i++){
+ cout << " " << FILEN[i] << endl ;
+ }
+
+ // loop over the file and dump event data
+
+ lcReader->open( FILEN ) ;
+
+ LCEvent* evt ;
+ int nEvents = 0 ;
+
+
+ //----------- the event loop -----------
+ while( (evt = lcReader->readNextEvent()) != 0 && nEvents<10 ) {
+
+// LCTOOLS::dumpEvent( evt ) ;
+
+ const StringVec* names = evt->getCollectionNames() ;
+
+ LCCollection* trkcol = 0 ;
+ LCCollection* clucol = 0 ;
+
+ for(unsigned int i=0;i< names->size() ;++i){
+
+ LCCollection* col = evt->getCollection( (*names)[i] ) ;
+
+ if( col->getTypeName() == LCIO::TRACK )
+ trkcol = col ;
+
+ if( col->getTypeName() == LCIO::CLUSTER )
+ clucol = col ;
+ }
+
+ if( trkcol && clucol ) {
+
+ int nclu = clucol->getNumberOfElements() ;
+ int ntrk = trkcol->getNumberOfElements() ;
+
+
+ for(int j=0 ; j< ntrk ; j++ ){
+
+ Track* trk = dynamic_cast<Track*> ( trkcol->getElementAt(j) ) ;
+
+ trk->ext<Index>() = new int(j) ;
+
+ for(int k=0 ; k< nclu ; k++ ){
+
+ Cluster* clu = dynamic_cast<Cluster*> ( clucol->getElementAt(k) ) ;
+
+ if( j == 0 )
+ clu->ext<Index>() = new int(k) ;
+
+ add_relation<TrkCluLink>( trk ,clu );
+
+ }
+
+ }
+
+
+ // --- now print the relation:
+
+ for(int j=0 ; j< ntrk ; j++ ){
+
+ std::cout << " track " << j << " cluster relations: " ;
+
+ for( TrkCluLink::to_traits::const_iterator iclu =
+ trkcol->getElementAt(j)->to<TrkCluLink>().begin() ;
+
+ iclu != trkcol->getElementAt(j)->to<TrkCluLink>().end() ; ++iclu ){
+
+ std::cout << *(*iclu)->ext<Index>() << ", " ;
+ }
+ std::cout << std::endl ;
+ }
+
+
+ } else {
+ std::cout << " couldn't find Track and Cluster collection in event !" << std::endl ;
+ }
+
+ nEvents ++ ;
+ }
+ // -------- end of event loop -----------
+
+ cout << endl << " " << nEvents << " events read from files: " << endl ;
+ for(int i=0 ; i < nFiles ; i++){
+ cout << " " << FILEN[i] << endl ;
+ }
+
+ lcReader->close() ;
+ delete lcReader ;
+ return 0 ;
+}
+
+
lcio/src/cpp/src/EXAMPLE
diff -u -r1.11 -r1.12
--- GNUmakefile 21 Sep 2006 06:10:40 -0000 1.11
+++ GNUmakefile 27 Nov 2006 09:57:43 -0000 1.12
@@ -74,3 +74,6 @@
$(BINDIR)/testvtx: testvtx.cc $(INSTALL)/liblcio.a
$(CXX) -o $(BINDIR)/testvtx $(CPPFLAGS) testvtx.cc $(LIBS)
+
+$(BINDIR)/lcrtrelation: lcrtrelation.cc $(INSTALL)/liblcio.a
+ $(CXX) -o $(BINDIR)/lcrtrelation $(CPPFLAGS) lcrtrelation.cc $(LIBS)
CVSspam 0.2.8