00001 #ifndef UTIL_LCFIXEDOBJECT_H 00002 #define UTIL_LCFIXEDOBJECT_H 1 00003 00004 #include "lcio.h" 00005 #include "IMPL/LCGenericObjectImpl.h" 00006 00007 #include <iostream> 00008 00009 namespace UTIL{ 00010 00024 template <int NINT, int NFLOAT, int NDOUBLE> 00025 class LCFixedObject : public EVENT::LCGenericObject { 00026 00027 public: 00028 00030 LCFixedObject(const LCFixedObject&) = default ; 00031 00033 LCFixedObject& operator=(const LCFixedObject&) = default ; 00034 00037 LCFixedObject(): 00038 _createdObject( true ) { 00039 _obj = new IMPL::LCGenericObjectImpl( NINT, NFLOAT , NDOUBLE ) ; 00040 } 00041 00048 LCFixedObject(LCObject* object) : 00049 _createdObject(false) { 00050 00051 _obj = dynamic_cast<IMPL::LCGenericObjectImpl*>( object ) ; 00052 00053 if( _obj==0 ){ 00054 00055 // could be an instance of LCFixedObject !? 00056 LCFixedObject<NINT,NFLOAT,NDOUBLE>* f = 00057 dynamic_cast< LCFixedObject<NINT,NFLOAT,NDOUBLE>* >( object ) ; 00058 00059 if( f != 0 ) 00060 _obj = f->obj() ; 00061 00062 } 00063 00064 // do some sanity checks ... 00065 if( _obj==0 ){ 00066 throw EVENT::Exception("Cannot create LCFixedObject from sth." 00067 " that is not LCGenericObjectImpl" ) ; 00068 } 00069 00070 if( ( _obj->getNInt() != NINT ) || 00071 ( _obj->getNFloat() != NFLOAT ) || 00072 ( _obj->getNDouble() != NDOUBLE ) ) { 00073 00074 throw EVENT::Exception("LCFixedObject(LCObject* obj): Wrong number of elements in object" ) ; 00075 } 00076 } 00077 00080 IMPL::LCGenericObjectImpl* obj() { return _obj ; } 00081 00082 00085 virtual ~LCFixedObject() { 00086 if( _createdObject ) delete _obj ; 00087 } 00088 00089 00091 virtual int id() const { return _obj->id() ; } 00092 00093 00094 // ---- need to implement LCGenericObject interface: 00095 00096 int getNInt() const { return NINT ; } 00097 int getNFloat() const { return NFLOAT ; } 00098 int getNDouble() const { return NDOUBLE ; } 00099 00100 int getIntVal(int index) const { 00101 return _obj->getIntVal( index ) ; 00102 } 00103 float getFloatVal(int index) const { 00104 return _obj->getFloatVal( index ) ; 00105 } 00106 double getDoubleVal(int index) const { 00107 return _obj->getDoubleVal( index ) ; 00108 } 00109 bool isFixedSize() const { return true ; } 00110 00111 // ---- end of LCGenericObject interface 00112 00113 protected: 00114 00115 IMPL::LCGenericObjectImpl* _obj{NULL} ; 00116 bool _createdObject{false} ; 00117 00118 }; 00119 00120 } // namespace 00121 #endif /* ifndef LCIO_LCFIXEDOBJECT_H */