Print

Print


Commit in lcio/src/cpp on MAIN
CMakeLists.txt+61.38 -> 1.39
include/UTIL/LCFourVector.h+5-51.9 -> 1.10
            /LCFourVector.icc+9-91.10 -> 1.11
src/TESTS/test_fourvector.cc+54added 1.1
+74-14
1 added + 3 modified, total 4 files
fixed class LCFourVector (constness etc.) - added simple test

lcio/src/cpp
CMakeLists.txt 1.38 -> 1.39
diff -u -r1.38 -r1.39
--- CMakeLists.txt	28 Jun 2010 12:57:14 -0000	1.38
+++ CMakeLists.txt	13 Mar 2011 12:42:19 -0000	1.39
@@ -494,5 +494,11 @@
 ADD_LCIO_CTEST( test_trackerhit )
 ADD_LCIO_CTEST( test_trackerpulse )
 ADD_LCIO_CTEST( test_randomaccess) 
+
+FIND_PACKAGE( CLHEP REQUIRED) 
+IF( CLHEP_FOUND )
+ADD_LCIO_CTEST( test_fourvector) 
+INCLUDE_DIRECTORIES( ${CLHEP_INCLUDE_DIRS} ) 
+ENDIF( CLHEP_FOUND )
 # ==================================================
 

lcio/src/cpp/include/UTIL
LCFourVector.h 1.9 -> 1.10
diff -u -r1.9 -r1.10
--- LCFourVector.h	17 Jan 2011 13:11:11 -0000	1.9
+++ LCFourVector.h	13 Mar 2011 12:42:19 -0000	1.10
@@ -30,7 +30,7 @@
   class LCFourVector :  public HepLorentzVector {
 
   protected: 
-    TT* _lcObj ;
+    const TT* _lcObj ;
     
   public: 
     virtual ~LCFourVector() { /*no_op*/; } 
@@ -45,9 +45,9 @@
      *  Can be used to save the dynamic_cast to the explicit type from an LCCollection element,
      *  e.g. LCFourVector<MCParticle>( col->getElement(i) ).
      */
-    LCFourVector(EVENT::LCObject* lcObj){
+    LCFourVector(const EVENT::LCObject* lcObj){
       
-      _lcObj = dynamic_cast< TT* >( lcObj ) ;
+      _lcObj = dynamic_cast< const TT* >( lcObj ) ;
       
       if( _lcObj == 0 )
 	throw EVENT::Exception("Dynamic cast failed for LCFourVector() !") ;
@@ -62,14 +62,14 @@
      *    particle4V->getMomentum()    //  LCIO object   <br>
      *    particle4V.m()               // mass from HepLorentzVector  <br>
      */
-    TT* operator->() { return _lcObj ; } 
+    const TT* operator->() const { return _lcObj ; } 
 
 
     /** Pointer to the LCObject that has been used to create the four vector.
      *  To be used when the object is needed as a function argument or optionally
      *  to call methods of the object, e.g. particle4V.lcObj()->getMomentum() ;
      */
-    TT* lcObj() { return _lcObj ; } 
+    const TT* lcObj() const { return _lcObj ; } 
 
 
     

lcio/src/cpp/include/UTIL
LCFourVector.icc 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- LCFourVector.icc	12 Mar 2011 17:00:26 -0000	1.10
+++ LCFourVector.icc	13 Mar 2011 12:42:19 -0000	1.11
@@ -20,17 +20,17 @@
 
   template<>
   inline LCFourVector<MCParticle>::LCFourVector( const MCParticle* mcPart ) : 
-     _lcObj( mcPart ),
      HepLorentzVector(mcPart->getMomentum()[0],
 		     mcPart->getMomentum()[1],
 		     mcPart->getMomentum()[2],
-		     mcPart->getEnergy() )  
+		     mcPart->getEnergy() )  ,
+     _lcObj( mcPart )
   {
   }
   template<>
-  inline LCFourVector<MCParticle>::LCFourVector(LCObject* lcObj){
+  inline LCFourVector<MCParticle>::LCFourVector(const LCObject* lcObj){
     
-    _lcObj = dynamic_cast<MCParticle* >( lcObj ) ;
+    _lcObj = dynamic_cast<const MCParticle* >( lcObj ) ;
 
     if( _lcObj == 0 )
       throw Exception("Dynamic cast failed for LCFourVector() !") ;
@@ -45,18 +45,18 @@
   }
 
   template<>
-  inline LCFourVector<ReconstructedParticle>::LCFourVector( const ReconstructedParticle* part ): 
-    _lcObj( part ),
+  inline LCFourVector<ReconstructedParticle>::LCFourVector(const ReconstructedParticle* part ): 
     HepLorentzVector(part->getMomentum()[0],
 		     part->getMomentum()[1],
 		     part->getMomentum()[2],
-		     part->getEnergy() )  
+		     part->getEnergy() ) , 
+    _lcObj( part )
   {
   }
   template<>
-  inline LCFourVector<ReconstructedParticle>::LCFourVector(LCObject* lcObj){
+  inline LCFourVector<ReconstructedParticle>::LCFourVector(const LCObject* lcObj){
     
-    _lcObj = dynamic_cast<ReconstructedParticle* >( lcObj ) ;
+    _lcObj = dynamic_cast<const ReconstructedParticle* >( lcObj ) ;
 
     if( _lcObj == 0 )
       throw Exception("Dynamic cast failed for LCFourVector() !") ;

lcio/src/cpp/src/TESTS
test_fourvector.cc added at 1.1
diff -N test_fourvector.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ test_fourvector.cc	13 Mar 2011 12:42:20 -0000	1.1
@@ -0,0 +1,54 @@
+////////////////////////////////////////
+// example for LCIO tests
+////////////////////////////////////////
+
+#include "tutil.h"
+#include "lcio.h"
+
+#include "EVENT/LCIO.h"
+//#include "IO/LCWriter.h"
+//#include "IMPL/LCEventImpl.h" 
+//#include "IMPL/LCCollectionVec.h"
+#include "IMPL/MCParticleImpl.h"
+#include "IMPL/ReconstructedParticleImpl.h"
+#include "UTIL/LCFourVector.h"
+
+
+#include <iostream>
+
+using namespace std ;
+using namespace lcio ;
+
+// replace mytest with the name of your test
+const static string testname="test_fourvector";
+
+//=============================================================================
+
+int main(int argc, char** argv ){
+    
+    // this should be the first line in your test
+    TEST MYTEST=TEST( testname, std::cout );
+    
+    MCParticleImpl* mcp = new MCParticleImpl ;
+    
+    float p[3] ;
+    p[0] = 1.0 ;
+    p[1] = 2.0 ;
+    p[2] = 3.0 ;
+
+    mcp->setMomentum( p ) ;
+    mcp->setMass( 42. ) ;
+
+    LCFourVector<MCParticle> mcp4v( mcp ) ;
+    
+    MYTEST( mcp4v.px()  , 1.0 ,  "px != 1.0 "   ) ;
+    MYTEST( mcp4v.py()  , 2.0 ,  "py != 2.0 "   ) ;
+    MYTEST( mcp4v.pz()  , 3.0 ,  "pz != 3.0 "   ) ;
+   
+    MYTEST( mcp4v.m()  , 42.0 ,  " e != 42.0 "   ) ;
+    
+    return 0;
+}
+
+//=============================================================================
+
CVSspam 0.2.8