LCIO  "2.7.4"
 All Classes Namespaces Functions Variables Typedefs Friends Pages
LCFixedObject.h
1 #ifndef UTIL_LCFIXEDOBJECT_H
2 #define UTIL_LCFIXEDOBJECT_H 1
3 
4 #include "lcio.h"
5 #include "IMPL/LCGenericObjectImpl.h"
6 
7 #include <iostream>
8 
9 using namespace lcio ;
10 
11 namespace UTIL{
12 
26  template <int NINT, int NFLOAT, int NDOUBLE>
27  class LCFixedObject : public LCGenericObject {
28 
29  public:
30 
34  _createdObject( true ) {
35  _obj = new LCGenericObjectImpl( NINT, NFLOAT , NDOUBLE ) ;
36  }
37 
45  _createdObject(false) {
46 
47  _obj = dynamic_cast<LCGenericObjectImpl*>( obj ) ;
48 
49  if( _obj==0 ){
50 
51  // could be an instance of LCFixedObject !?
53  dynamic_cast< LCFixedObject<NINT,NFLOAT,NDOUBLE>* >( obj ) ;
54 
55  if( f != 0 )
56  _obj = f->obj() ;
57 
58  }
59 
60  // do some sanity checks ...
61  if( _obj==0 ){
62  throw Exception("Cannot create LCFixedObject from sth."
63  " that is not LCGenericObjectImpl" ) ;
64  }
65 
66  if( ( _obj->getNInt() != NINT ) ||
67  ( _obj->getNFloat() != NFLOAT ) ||
68  ( _obj->getNDouble() != NDOUBLE ) ) {
69 
70  throw Exception("LCFixedObject(LCObject* obj): Wrong number of elements in object" ) ;
71  }
72  }
73 
76  LCGenericObjectImpl* obj() { return _obj ; }
77 
78 
81  virtual ~LCFixedObject() {
82  if( _createdObject ) delete _obj ;
83  }
84 
85 
87  virtual int id() const { return _obj->id() ; }
88 
89 
90  // ---- need to implement LCGenericObject interface:
91 
92  int getNInt() const { return NINT ; }
93  int getNFloat() const { return NFLOAT ; }
94  int getNDouble() const { return NDOUBLE ; }
95 
96  int getIntVal(int index) const {
97  return _obj->getIntVal( index ) ;
98  }
99  float getFloatVal(int index) const {
100  return _obj->getFloatVal( index ) ;
101  }
102  double getDoubleVal(int index) const {
103  return _obj->getDoubleVal( index ) ;
104  }
105  bool isFixedSize() const { return true ; }
106 
107  // ---- end of LCGenericObject interface
108 
109  protected:
110 
111  LCGenericObjectImpl* _obj ;
112  bool _createdObject ;
113 
114  };
115 
116 } // namespace
117 #endif /* ifndef LCIO_LCFIXEDOBJECT_H */
The generic object that is held in an LCCollection.
Definition: LCObject.h:30
Base exception class for LCIO - all other exceptions extend this.
Definition: Exceptions.h:21
virtual int id() const
Return the id of the underlying LCGenericObjectImpl.
Definition: LCFixedObject.h:87
LCGenericObjectImpl * obj()
The LCGenericObjectImpl .
Definition: LCFixedObject.h:76
virtual ~LCFixedObject()
Clean up if we created a new LCGenericObjectImpl.
Definition: LCFixedObject.h:81
LCFixedObject(LCObject *obj)
C'tor to be used for elements of LCGenericObjects read from an LCIO file or the database.
Definition: LCFixedObject.h:44
LCFixedObject()
Default c'tor.
Definition: LCFixedObject.h:33
Default LCIO implementation of the interface to store generic user data.
Definition: LCGenericObjectImpl.h:18
Template class for fixed size LCGenericObject subclasses.
Definition: LCFixedObject.h:27