lcio/src/cpp/include
diff -u -r1.11 -r1.12
--- LCRTRelations.h 21 Jan 2010 16:26:11 -0000 1.11
+++ LCRTRelations.h 5 Oct 2010 16:04:44 -0000 1.12
@@ -242,10 +242,11 @@
/** Special Extension that allows to write int extensions directly (not through a pointer !). */
template <class U >
- struct LCIntExtension{ // FIXME: need to check on 64 bit architecture...
-
- typedef int ptr ; // base pointer type
+ struct LCIntExtension{
+ typedef long ptr ; // base pointer type - use long to work for 64 bit (long is 32 on 32-bit systems/64 on 64bit systems)
+ typedef long& ext_type ;
+
typedef U tag ; // this ensures that a new class instance is created for every user extension
static const int allowed_to_call_ext = 1 ;
@@ -257,25 +258,31 @@
}
static DeleteFPtr deletePtr() { return &clean ; } ;
- typedef int& ext_type ;
};
- /** Special Extension that allows to write float extensions directly (not through a pointer !). */
- template <class U >
+ template <class U >
+
struct LCFloatExtension{// FIXME: need to check on 64 bit architecture...
+#ifdef __i386__
typedef float ptr ; // base pointer type
- typedef U tag ; // this ensures that a new class instance is created for every user extension
typedef float& ext_type ; // return value of ext<>()
-
+
+#else // use double on 64bit systems
+ typedef double ptr ; // base pointer type
+ typedef double& ext_type ; // return value of ext<>()
+#endif
+
+ typedef U tag ; // this ensures that a new class instance is created for every user extension
+
static const int allowed_to_call_ext = 1 ;
static void clean(void *v) { }
static ptr init() { return 0 ; }
static DeleteFPtr deletePtr() { return &clean ; } ;
};
-
+
//--------------------------------------------------------------------
lcio/src/cpp/src/EXAMPLE
diff -u -r1.6 -r1.7
--- lcrtrelation.cc 8 Dec 2006 14:28:59 -0000 1.6
+++ lcrtrelation.cc 5 Oct 2010 16:04:44 -0000 1.7
@@ -18,6 +18,9 @@
// a simple int extension
struct Index : LCIntExtension<Index> {} ;
+// a simple float extension
+struct Mass : LCFloatExtension<Mass> {} ;
+
// a vector of strings (pointers) that are owned by the object that is extended
struct ParticleIDs : LCOwnedExtensionVector<ParticleIDs,std::string> {};
@@ -75,6 +78,7 @@
// make every particle know it's index in the collection
mcp->ext<Index>() = i ;
+ mcp->ext<Mass>() = mcp->getMass() ;
// assign a user object to each particle:
@@ -301,7 +305,7 @@
MCParticle* mcp = dynamic_cast<MCParticle*>( mcpcol->getElementAt(i) ) ;
- std::cout << " --- particle " << mcp->ext<Index>()
+ std::cout << " --- particle " << mcp->ext<Index>() << " ( mass: " << mcp->ext<Mass>() << ") "
<< " daughters after merging : " ;