LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LCFixedObject.h
Go to the documentation of this file.
1 #ifndef UTIL_LCFIXEDOBJECT_H
2 #define UTIL_LCFIXEDOBJECT_H 1
3 
4 #include "lcio.h"
6 
7 #include <iostream>
8 
9 namespace UTIL{
10 
24  template <int NINT, int NFLOAT, int NDOUBLE>
26 
27  public:
28 
30  LCFixedObject(const LCFixedObject&) = default ;
31 
33  LCFixedObject& operator=(const LCFixedObject&) = default ;
34 
38  _createdObject( true ) {
40  }
41 
48  LCFixedObject(LCObject* object) :
49  _createdObject(false) {
50 
51  _obj = dynamic_cast<IMPL::LCGenericObjectImpl*>( object ) ;
52 
53  if( _obj==0 ){
54 
55  // could be an instance of LCFixedObject !?
57  dynamic_cast< LCFixedObject<NINT,NFLOAT,NDOUBLE>* >( object ) ;
58 
59  if( f != 0 )
60  _obj = f->obj() ;
61 
62  }
63 
64  // do some sanity checks ...
65  if( _obj==0 ){
66  throw EVENT::Exception("Cannot create LCFixedObject from sth."
67  " that is not LCGenericObjectImpl" ) ;
68  }
69 
70  if( ( _obj->getNInt() != NINT ) ||
71  ( _obj->getNFloat() != NFLOAT ) ||
72  ( _obj->getNDouble() != NDOUBLE ) ) {
73 
74  throw EVENT::Exception("LCFixedObject(LCObject* obj): Wrong number of elements in object" ) ;
75  }
76  }
77 
81 
82 
85  virtual ~LCFixedObject() {
86  if( _createdObject ) delete _obj ;
87  }
88 
89 
91  virtual int id() const { return _obj->id() ; }
92 
93 
94  // ---- need to implement LCGenericObject interface:
95 
96  int getNInt() const { return NINT ; }
97  int getNFloat() const { return NFLOAT ; }
98  int getNDouble() const { return NDOUBLE ; }
99 
100  int getIntVal(int index) const {
101  return _obj->getIntVal( index ) ;
102  }
103  float getFloatVal(int index) const {
104  return _obj->getFloatVal( index ) ;
105  }
106  double getDoubleVal(int index) const {
107  return _obj->getDoubleVal( index ) ;
108  }
109  bool isFixedSize() const { return true ; }
110 
111  // ---- end of LCGenericObject interface
112 
113  protected:
114 
116  bool _createdObject{false} ;
117 
118  };
119 
120 } // namespace
121 #endif /* ifndef LCIO_LCFIXEDOBJECT_H */
Base exception class for LCIO - all other exceptions extend this.
Definition: Exceptions.h:21
virtual int getNFloat() const
Number of float values stored in this object.
virtual int id() const
Provide default implementation for id.
virtual int getNDouble() const
Number of double values stored in this object.
virtual int getIntVal(int index) const
Returns the integer value for the given index.
virtual float getFloatVal(int index) const
Returns the float value for the given index.
IMPL::LCGenericObjectImpl * _obj
virtual int id() const
Return the id of the underlying LCGenericObjectImpl.
Definition: LCFixedObject.h:91
LCFixedObject & operator=(const LCFixedObject &)=default
default assignment operator - use with care
int getNFloat() const
Number of float values stored in this object.
Definition: LCFixedObject.h:97
double getDoubleVal(int index) const
Returns the double value for the given index.
LCFixedObject(LCObject *object)
C&#39;tor to be used for elements of LCGenericObjects read from an LCIO file or the database.
Definition: LCFixedObject.h:48
virtual double getDoubleVal(int index) const
Returns the double value for the given index.
virtual ~LCFixedObject()
Clean up if we created a new LCGenericObjectImpl.
Definition: LCFixedObject.h:85
bool isFixedSize() const
True if objects of the implementation class have a fixed size, i.e getNInt, getNFloat and getNDouble ...
LCFixedObject()
Default c&#39;tor.
Definition: LCFixedObject.h:37
#define NFLOAT
Default LCIO implementation of the interface to store generic user data.
Simple interface to store generic user data.
int getNInt() const
Number of integer values stored in this object.
Definition: LCFixedObject.h:96
#define NDOUBLE
#define NINT
float getFloatVal(int index) const
Returns the float value for the given index.
virtual int getNInt() const
Number of integer values stored in this object.
Template class for fixed size LCGenericObject subclasses.
Definition: LCFixedObject.h:25
int getNDouble() const
Number of double values stored in this object.
Definition: LCFixedObject.h:98
int getIntVal(int index) const
Returns the integer value for the given index.
IMPL::LCGenericObjectImpl * obj()
The LCGenericObjectImpl .
Definition: LCFixedObject.h:80